|
楼主 |
发表于 2020-12-21 18:45:01
|
显示全部楼层
汗颜,项目赶工期,没时间整理贴上来.
下面的代码没有整理,大体能说明一下思路.
interface IStateSender
{
virtual BOOL InitSender() = 0;
virtual void OnReportState() = 0;
virtual void OnReportStateWithMsg(DeviceMsg devMsg, /*OUT*/ void* data) = 0;
virtual void RegStateCollector(IStatesCollector* pCollector) =0;
virtual int ToDoWork(DeviceMsg devMsg, /*IN*/ void* data) = 0;
virtual DevType SenderType() = 0;
};
interface IStatesCollector
{
virtual int OnRecvedDevMsg(DeviceMsg devMsg, void* pParam) = 0;
virtual void RegStateSender(IStateSender* pSender) = 0;
virtual void RegStatesCollector(IStatesCollector* pCollecter) = 0;
};
class CDispatchCenter : public IStatesCollector //it's CWhat.
{
public:
static CDispatchCenter* Instance();
static void Release();
virtual int OnRecvedDevMsg(DeviceMsg devMsg, void* pParam) ;
virtual void RegStateSender(IStateSender* pSender);
virtual void RegStatesCollector(IStatesCollector* pCollector);
protected:
CDispatchCenter();
virtual ~CDispatchCenter();
void OnSocketMsg(_tagCommuCmd* pParam);
void DispatchMsg(DeviceMsg devMsg, void* pParam);
protected:
static CDispatchCenter* _instance;
IStateSender* _arrSender[Dev_Count];
list<IStatesCollector*> _lstCollector;
CRealTimeStates* _rts;
typedef list<IStateSender*>::iterator SenderIterator;
typedef list<IStatesCollector*>::iterator CollectorIterator;
};
enum MotorDeviceMsg
{
MDMsg_Nothing =-1,
MDMsg_AutoRun =0,
MDMsg_ManuRun,
MDMsg_Stop,
MDMsg_ArrivedStation,
MDMsg_IncSpeed,
MDMsg_DecSpeed,
MDMsg_TurningByAngle,
MDMsg_Count,
};
typedef struct _tagMotor_A2D_Msg //A2D: application to device
{
MotorDeviceMsg msg;
BOOL isStation;
MovedControl mc;
MotorStatues ms[M_Count];
} MotorMsgArg;
class CMotorProxy : public IStateSender
{
public:
CMotorProxy();
virtual ~CMotorProxy();
virtual BOOL InitSender() ;
virtual void OnReportState();
virtual void OnReportStateWithMsg(DeviceMsg devMsg, void* data);
virtual void RegStateCollector(IStatesCollector* pCollector) ;
virtual int ToDoWork(DeviceMsg devMsg, /*IN*/ void* data) ;
virtual DevType SenderType();
protected:
CMotor* _motor;
IStatesCollector* _collecter;
};
class CCmdProxy : public IStatesCollector
{
public:
static CCmdProxy* Instance();
static void Release();
void OnSocketMsg(INT nCmd, const char* data, int len);
virtual int OnRecvedDevMsg(DeviceMsg devMsg, void* pParam);
virtual void RegStateSender(IStateSender* pSender){}
virtual void RegStatesCollector(IStatesCollector* pCollecter);
protected:
CCmdProxy();
virtual ~CCmdProxy();
void AutoRunTask(const char* data, int len);
void ManualRunTask(const char* data, int len);
void PantiltTask(const char* data, int len);
void IOCtrlTask(const char* data, int len);
void CameraTask(const char* data, int len);
void AudioTask(const char* data, int len);
protected:
static CCmdProxy* _instance;
IStatesCollector* _dispCenter;
};
|
|