68 lines
1.3 KiB
C++
68 lines
1.3 KiB
C++
#ifndef __TinyServer_H__
|
|
#define __TinyServer_H__
|
|
|
|
#include "Sys.h"
|
|
#include "Config.h"
|
|
|
|
#include "TinyMessage.h"
|
|
|
|
#include "TinyNet\Device.h"
|
|
|
|
/******************************** TinyServer ********************************/
|
|
|
|
// 微网客户端
|
|
class TinyServer
|
|
{
|
|
private:
|
|
|
|
public:
|
|
TinyController* Control;
|
|
TConfig* Config;
|
|
|
|
ushort DeviceType; // 设备类型。两个字节可做二级分类
|
|
|
|
TinyServer(TinyController* control);
|
|
|
|
// 发送消息
|
|
bool Send(Message& msg);
|
|
bool Reply(Message& msg);
|
|
// 收到本地无线网消息
|
|
bool OnReceive(TinyMessage& msg);
|
|
// 分发外网过来的消息。返回值表示是否有响应
|
|
bool Dispatch(TinyMessage& msg);
|
|
|
|
// 收到功能消息时触发
|
|
MessageHandler Received;
|
|
void* Param;
|
|
|
|
List<Device*> Devices;
|
|
Device* FindDevice(byte id);
|
|
Device* FindDevice(const ByteArray& hardid);
|
|
bool DeleteDevice(byte id);
|
|
|
|
// 当前设备
|
|
Device* Current;
|
|
|
|
// 常用系统级消息
|
|
public:
|
|
// 设置默认系统消息
|
|
void Start();
|
|
|
|
// 组网
|
|
bool OnJoin(const TinyMessage& msg);
|
|
|
|
bool OnDisjoin(const TinyMessage& msg);
|
|
|
|
// 心跳
|
|
bool OnPing(const TinyMessage& msg);
|
|
|
|
// 读取
|
|
bool OnRead(TinyMessage& msg, Device& dv);
|
|
bool OnReadReply(const TinyMessage& msg, Device& dv);
|
|
|
|
// 写入
|
|
bool OnWrite(TinyMessage& msg, Device& dv);
|
|
};
|
|
|
|
#endif
|