|
@@ -14,13 +14,13 @@
|
|
|
#include "MsgQueue.h"
|
|
|
#include <list>
|
|
|
|
|
|
-#include <sys/time.h> // 添加Linux时间头文件
|
|
|
-#include <pthread.h> // 添加Linux线程头文件
|
|
|
-#include <unistd.h> // 添加unistd头文件
|
|
|
-#include <semaphore.h> // 添加信号量头文件
|
|
|
+#include <sys/time.h> // 娣诲姞Linux鏃堕棿澶存枃浠�
|
|
|
+#include <pthread.h> // 娣诲姞Linux绾跨▼澶存枃浠�
|
|
|
+#include <unistd.h> // 娣诲姞unistd澶存枃浠�
|
|
|
+#include <semaphore.h> // 娣诲姞淇″彿閲忓ご鏂囦欢
|
|
|
|
|
|
|
|
|
-// 添加 GUID 类型定义(如果未定义)
|
|
|
+// 娣诲姞 GUID 绫诲瀷瀹氫箟锛堝�鏋滄湭瀹氫箟锛�
|
|
|
#ifndef GUID_DEFINED
|
|
|
#define GUID_DEFINED
|
|
|
typedef struct _GUID {
|
|
@@ -65,11 +65,11 @@ using ccos_mqtt_connection = std::tuple<
|
|
|
void*, // MSG_HOOK_ID (ccos_mqtt_msg_filter*)
|
|
|
std::string, // CLINET_ID_ID
|
|
|
ccos_mqtt_callback, // USER_MSG_CAKBCK_ID
|
|
|
- pthread_t, // CONNECTED_THREAD_ID (Linux使用pthread_t)
|
|
|
+ pthread_t, // CONNECTED_THREAD_ID (Linux浣跨敤pthread_t)
|
|
|
CcosLock*, // CONN_SEND_LOCK_ID
|
|
|
mqtt_msg_list*, // MSG_LIST_ID
|
|
|
- sem_t* , // SEMAPHORE_HANDLE_ID (Linux使用sem_t*)
|
|
|
- std::atomic<bool> //线程运行状态标志
|
|
|
+ sem_t* , // SEMAPHORE_HANDLE_ID (Linux浣跨敤sem_t*)
|
|
|
+ std::atomic<bool> //绾跨▼杩愯�鐘舵€佹爣蹇�
|
|
|
>;
|
|
|
const int MQTT_CLT_ID = 0;
|
|
|
const int MQTT_TIPIC_LIST_ID = 1;
|
|
@@ -87,7 +87,7 @@ const int THREAD_RUNNING_ID = 9;
|
|
|
using ccos_mqtt_msg_filter_func = std::function<bool(ResDataObject*)>;
|
|
|
using ccos_mqtt_msg_filter = std::tuple<
|
|
|
ccos_mqtt_msg_filter_func, // FILTER_FUNC_ID
|
|
|
- std::shared_ptr<LinuxEvent>, // LinuxEvent (替代 HANDLE)
|
|
|
+ std::shared_ptr<LinuxEvent>, // LinuxEvent (鏇夸唬 HANDLE)
|
|
|
ResDataObject*, // FILTER_RES_OBJ_ID
|
|
|
ResDataObject* // FILTER_RESPONS_OBJ_ID
|
|
|
>;
|
|
@@ -99,7 +99,7 @@ const int FILTER_RESPONS_OBJ_ID = 3;
|
|
|
static std::vector<std::string> m_subscribedTopics;
|
|
|
static std::recursive_mutex g_subscribedTopicsMutex;
|
|
|
/// <summary>
|
|
|
-/// 逻辑设备命令收发接口
|
|
|
+/// 閫昏緫璁惧�鍛戒护鏀跺彂鎺ュ彛
|
|
|
/// </summary>
|
|
|
class LOGICDEVICE_API LogicDeviceSysIF
|
|
|
{
|
|
@@ -115,7 +115,7 @@ public:
|
|
|
//Command In and Out
|
|
|
//notify from lower layer
|
|
|
/// <summary>
|
|
|
- /// notify from lower layer,设备上行命令,发送端为逻辑设备
|
|
|
+ /// notify from lower layer锛岃�澶囦笂琛屽懡浠わ紝鍙戦€佺�涓洪€昏緫璁惧�
|
|
|
/// </summary>
|
|
|
/// <param name="pCmd"></param>
|
|
|
/// <returns></returns>
|
|
@@ -123,7 +123,7 @@ public:
|
|
|
|
|
|
//notify to lower layer
|
|
|
/// <summary>
|
|
|
- /// notify to lower layer,设备命令下行,接收端为逻辑设备
|
|
|
+ /// notify to lower layer锛岃�澶囧懡浠や笅琛岋紝鎺ユ敹绔�负閫昏緫璁惧�
|
|
|
/// </summary>
|
|
|
/// <param name="pCmd"></param>
|
|
|
/// <returns></returns>
|
|
@@ -147,37 +147,37 @@ protected:
|
|
|
ccos_topic_filter m_topicFilter;
|
|
|
DWORD m_dwLastPacket;
|
|
|
|
|
|
- // int m_bAbstractOnline; //抽象设备是否在线,初始化启动是在线,可以通过Close下线
|
|
|
- ResDataObject m_rsOnlineGroup; //在线设备组,在线状态,对应工作位
|
|
|
+ // int m_bAbstractOnline; //鎶借薄璁惧�鏄�惁鍦ㄧ嚎锛屽垵濮嬪寲鍚�姩鏄�湪绾匡紝鍙�互閫氳繃Close涓嬬嚎
|
|
|
+ ResDataObject m_rsOnlineGroup; //鍦ㄧ嚎璁惧�缁�,鍦ㄧ嚎鐘舵€侊紝瀵瑰簲宸ヤ綔浣�
|
|
|
|
|
|
- string m_strClientID; //MQTT 的客户端连接的ID,一般用DEVICE的逻辑ID来表示 VendorID_ProductID_SerialID_LogicID;
|
|
|
- std::vector<string> m_strSubTopics; //要订阅的主题列表
|
|
|
+ string m_strClientID; //MQTT 鐨勫�鎴风�杩炴帴鐨処D锛屼竴鑸�敤DEVICE鐨勯€昏緫ID鏉ヨ〃绀� VendorID_ProductID_SerialID_LogicID;
|
|
|
+ std::vector<string> m_strSubTopics; //瑕佽�闃呯殑涓婚�鍒楄〃
|
|
|
bool m_bIsTreeRoot;
|
|
|
string m_strEBusRoot;
|
|
|
|
|
|
- std::vector<LogicDevice*> m_subDevices; //按照原有Ebus组织形式的树
|
|
|
- string m_strCCOSDevicePath; //设备完整CCOS路径 CCOS/DEVICE/Detector/RF/ecomdemo/demo/1234
|
|
|
- string m_strAbstractPath; //抽象设备路径:CCOS/DEVICE/Generator,可以被Open,可以执行Action和通知等各种CCOS消息
|
|
|
- string m_strCCOSRoot; //设备根 ,CCOS/DEVICE ,CCOS/Driver , CCOS/Host,只可以被Open
|
|
|
+ std::vector<LogicDevice*> m_subDevices; //鎸夌収鍘熸湁Ebus缁勭粐褰㈠紡鐨勬爲
|
|
|
+ string m_strCCOSDevicePath; //璁惧�瀹屾暣CCOS璺�緞 CCOS/DEVICE/Detector/RF/ecomdemo/demo/1234
|
|
|
+ string m_strAbstractPath; //鎶借薄璁惧�璺�緞锛欳COS/DEVICE/Generator锛屽彲浠ヨ�Open锛屽彲浠ユ墽琛孉ction鍜岄€氱煡绛夊悇绉岰COS娑堟伅
|
|
|
+ string m_strCCOSRoot; //璁惧�鏍� 锛孋COS/DEVICE 锛孋COS/Driver , CCOS/Host锛屽彧鍙�互琚玂pen
|
|
|
|
|
|
- std::vector<LogicDevice*> m_subCcosDevices; //按照新的树形结构的树
|
|
|
- LogicDevice* m_pParent; //父节点
|
|
|
- string m_strDevicePath; //相对CCOS root 根节点的 当前设备的名称,用于构建主题URI,必须以/开头
|
|
|
+ std::vector<LogicDevice*> m_subCcosDevices; //鎸夌収鏂扮殑鏍戝舰缁撴瀯鐨勬爲
|
|
|
+ LogicDevice* m_pParent; //鐖惰妭鐐�
|
|
|
+ string m_strDevicePath; //鐩稿�CCOS root 鏍硅妭鐐圭殑 褰撳墠璁惧�鐨勫悕绉帮紝鐢ㄤ簬鏋勫缓涓婚�URI锛屽繀椤讳互/寮€澶�
|
|
|
|
|
|
ResDataObject m_Actions;
|
|
|
MsgQueue<ResDataObject>* m_pPacketReceivedQue;
|
|
|
- MsgQueue<ResDataObject>* m_pPacketSendingQue; //发送队列
|
|
|
+ MsgQueue<ResDataObject>* m_pPacketSendingQue; //鍙戦€侀槦鍒�
|
|
|
|
|
|
string m_strCurTransaction;
|
|
|
|
|
|
//Logger *m_pLogger;
|
|
|
char *m_pDevInstance;
|
|
|
ResDataObject *m_pResErrorList;
|
|
|
- std::shared_ptr<LinuxEvent> m_EvtNotify;//此事件的目的是当本地有事件发生,而这事件需要要往上传递,需要驱动线程主动下来GET.
|
|
|
- sem_t m_SemphRequest; //请求到了
|
|
|
- sem_t m_SemphPublish; //有包要发送
|
|
|
+ std::shared_ptr<LinuxEvent> m_EvtNotify;//姝や簨浠剁殑鐩�殑鏄�綋鏈�湴鏈変簨浠跺彂鐢燂紝鑰岃繖浜嬩欢闇€瑕佽�寰€涓婁紶閫掞紝闇€瑕侀┍鍔ㄧ嚎绋嬩富鍔ㄤ笅鏉�ET.
|
|
|
+ sem_t m_SemphRequest; //璇锋眰鍒颁簡
|
|
|
+ sem_t m_SemphPublish; //鏈夊寘瑕佸彂閫�
|
|
|
|
|
|
- DriverDPC *m_pDrvDPC;//设备对象的HOST
|
|
|
+ DriverDPC *m_pDrvDPC;//璁惧�瀵硅薄鐨凥OST
|
|
|
|
|
|
|
|
|
RET_STATUS SystemLog(SYSLOGLEVEL Level, const char *pCode, const char* fmt, ...);
|
|
@@ -223,18 +223,18 @@ public:
|
|
|
DriverDPC *GetDrvDPC();
|
|
|
|
|
|
|
|
|
- void SetClientRootID(const char* pszEBusRoot, const char* pszCCOSRoot); //设置 设备URI根 路径 ,包括EBUS和CCOS两个
|
|
|
+ void SetClientRootID(const char* pszEBusRoot, const char* pszCCOSRoot); //璁剧疆 璁惧�URI鏍� 璺�緞 锛屽寘鎷珽BUS鍜孋COS涓や釜
|
|
|
virtual void OnSetClientID();
|
|
|
void SetTopicFilter(ccos_topic_filter filter);
|
|
|
|
|
|
- virtual void SubscribeSelf(); //所有子类必须使用 SubscribeTopic 订阅自身topic及资源topic,如果不知道需要DPC代订阅
|
|
|
+ virtual void SubscribeSelf(); //鎵€鏈夊瓙绫诲繀椤讳娇鐢� SubscribeTopic 璁㈤槄鑷�韩topic鍙婅祫婧恡opic锛屽�鏋滀笉鐭ラ亾闇€瑕丏PC浠h�闃�
|
|
|
void SubScribeTopic(const char* pszTopic, bool bSubscribe = true);
|
|
|
- void HelpSubscribeTopic(const char* pszTopic); //代注册接口,注册在主MQTT连接上
|
|
|
+ void HelpSubscribeTopic(const char* pszTopic); //浠f敞鍐屾帴鍙o紝娉ㄥ唽鍦ㄤ富MQTT杩炴帴涓�
|
|
|
ccos_mqtt_connection* CreateConnection(const char* pszClientID, ccos_mqtt_callback onmsg);
|
|
|
|
|
|
std::shared_ptr<LinuxEvent> GetEvtHandle();
|
|
|
void NotifyDrvThread();
|
|
|
- virtual RET_STATUS SYSTEM_CALL EvtProcedure();//m_EvtNotify事件发生后,由上层驱动线程进行调入.
|
|
|
+ virtual RET_STATUS SYSTEM_CALL EvtProcedure();//m_EvtNotify浜嬩欢鍙戠敓鍚庯紝鐢变笂灞傞┍鍔ㄧ嚎绋嬭繘琛岃皟鍏�.
|
|
|
|
|
|
virtual int SYSTEM_CALL GetDevice_Thread_Priority();//return THREAD_PRIORITY_NONE
|
|
|
|
|
@@ -246,7 +246,7 @@ public:
|
|
|
|
|
|
//get device resource
|
|
|
/// <summary>
|
|
|
- /// 获取设备资源 get device resource
|
|
|
+ /// 鑾峰彇璁惧�璧勬簮 get device resource
|
|
|
/// </summary>
|
|
|
/// <param name="pDeviceResource"></param>
|
|
|
/// <returns></returns>
|
|
@@ -256,7 +256,7 @@ public:
|
|
|
//normal sync routine,Request to device and response from device
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 设备的命令响应接口 normal sync routine,Request to device and response from device
|
|
|
+ /// 璁惧�鐨勫懡浠ゅ搷搴旀帴鍙� normal sync routine,Request to device and response from device
|
|
|
/// </summary>
|
|
|
/// <param name="pRequest"></param>
|
|
|
/// <param name="pResponse"></param>
|
|
@@ -268,25 +268,25 @@ public:
|
|
|
|
|
|
//notify to lower layer
|
|
|
/// <summary>
|
|
|
- /// 发送给设备的命令 只是通知吗?notify to lower layer
|
|
|
+ /// 鍙戦€佺粰璁惧�鐨勫懡浠� 鍙�槸閫氱煡鍚楋紵notify to lower layer
|
|
|
/// </summary>
|
|
|
/// <param name="pCmd"></param>
|
|
|
/// <returns></returns>
|
|
|
virtual RET_STATUS SYSTEM_CALL CmdToLogicDev(ResDataObject PARAM_IN *pCmd) = 0;
|
|
|
|
|
|
- //处理来自客户的请求
|
|
|
+ //澶勭悊鏉ヨ嚜瀹㈡埛鐨勮�姹�
|
|
|
virtual RET_STATUS ProcessSubscribeMsg(ResDataObject* pCmd);
|
|
|
virtual RET_STATUS ProcessSubscribeRequest(ResDataObject* pCmd);
|
|
|
|
|
|
virtual RET_STATUS ProcessRequest(ResDataObject* pCmd, PACKET_CMD cmd);
|
|
|
virtual RET_STATUS ProcessResponse(ResDataObject* pCmd, PACKET_CMD cmd);
|
|
|
|
|
|
- //需要子类自己实现自己的订阅处理
|
|
|
+ //闇€瑕佸瓙绫昏嚜宸卞疄鐜拌嚜宸辩殑璁㈤槄澶勭悊
|
|
|
virtual RET_STATUS ProcessNotify(ResDataObject* pCmd, PACKET_CMD cmd);
|
|
|
|
|
|
//notify from lower layer
|
|
|
/// <summary>
|
|
|
- /// 设备侧 来的 命令?只可能是通知吗?notify from lower layer
|
|
|
+ /// 璁惧�渚� 鏉ョ殑 鍛戒护锛熷彧鍙�兘鏄�€氱煡鍚楋紵notify from lower layer
|
|
|
/// </summary>
|
|
|
/// <param name="pCmd"></param>
|
|
|
/// <returns></returns>
|
|
@@ -318,26 +318,30 @@ public:
|
|
|
|
|
|
|
|
|
|
|
|
-//创建额外连接,需要提供回调函数
|
|
|
+//鍒涘缓棰濆�杩炴帴锛岄渶瑕佹彁渚涘洖璋冨嚱鏁�
|
|
|
LOGICDEVICE_API ccos_mqtt_connection* NewConnection(const char* pszClientID, ccos_mqtt_callback onmsg, DWORD dwOpenTimeout = 10000, bool async = false);
|
|
|
LOGICDEVICE_API void CloseConnection(ccos_mqtt_connection* hConnection);
|
|
|
LOGICDEVICE_API void ResetConnection(ccos_mqtt_connection* hConnection);
|
|
|
-//主动订阅主题
|
|
|
+//涓诲姩璁㈤槄涓婚�
|
|
|
LOGICDEVICE_API int SubscribeTopic(ccos_mqtt_connection* hConnection, const char* pszTopic, bool isShare = false);
|
|
|
-//主题订阅取消
|
|
|
+//绛夊緟璁㈤槄瀹屾垚锛圫UBACK鏀跺埌锛�- 杩斿洖true琛ㄧず鎴愬姛锛宖alse琛ㄧず瓒呮椂
|
|
|
+LOGICDEVICE_API bool WaitForSubscriptionComplete(ccos_mqtt_connection* hConnection, DWORD timeoutMs = 5000);
|
|
|
+//绛夊緟Broker瀹屾垚璺�敱琛ㄦ洿鏂� - 鍙�€氳繃鐜��鍙橀噺MQTT_BROKER_ROUTING_DELAY_MS閰嶇疆锛岄粯璁�500ms
|
|
|
+LOGICDEVICE_API DWORD WaitForBrokerRouting(const char* clientId = nullptr);
|
|
|
+//涓婚�璁㈤槄鍙栨秷
|
|
|
LOGICDEVICE_API int UnSubscribe(ccos_mqtt_connection* hConnection, const char* pszTopic);
|
|
|
-//往指定主题发送CCOS协议包整包,使用临时创建连接,仅发送,不接收
|
|
|
+//寰€鎸囧畾涓婚�鍙戦€丆COS鍗忚�鍖呮暣鍖咃紝浣跨敤涓存椂鍒涘缓杩炴帴锛屼粎鍙戦€侊紝涓嶆帴鏀�
|
|
|
LOGICDEVICE_API int PublishMsg(ResDataObject* pCmd, const char* pszTopic, const char* pszSenderName, DWORD dwTimeout = 3);
|
|
|
-//往指定主题发送CCOS协议包整包,使用已创建的连接发送
|
|
|
+//寰€鎸囧畾涓婚�鍙戦€丆COS鍗忚�鍖呮暣鍖咃紝浣跨敤宸插垱寤虹殑杩炴帴鍙戦€�
|
|
|
LOGICDEVICE_API int PublishAction(ResDataObject* pAction, const char* pszTopic, ccos_mqtt_connection* hConnection = nullptr, DWORD dwTimeout = 3);
|
|
|
|
|
|
-//使用现有连接 往指定主题发送Action包,携带参数,并指定答复的Topic,同步等待resp,超时没收到应答返回失败,复用链接时须小心,该函数会
|
|
|
+//浣跨敤鐜版湁杩炴帴 寰€鎸囧畾涓婚�鍙戦€丄ction鍖咃紝鎼哄甫鍙傛暟锛屽苟鎸囧畾绛斿�鐨凾opic锛屽悓姝ョ瓑寰卹esp锛岃秴鏃舵病鏀跺埌搴旂瓟杩斿洖澶辫触锛屽�鐢ㄩ摼鎺ユ椂椤诲皬蹇冿紝璇ュ嚱鏁颁細
|
|
|
//LOGICDEVICE_API int ActionAndRespWithConnection(ccos_mqtt_connection* hConnection, const char* pAction, ResDataObject& req, ResDataObject* pContext, const char* pszTopic, const char* pszRespTopic, ResDataObject& resObj,
|
|
|
// DWORD dwWaitTime);
|
|
|
|
|
|
-//使用现有连接 往指定主题发送Action包,携带参数,复用连接订阅的默认Topic,通过提供的消息钩子 等待resp,超时没收到应答返回失败,
|
|
|
+//浣跨敤鐜版湁杩炴帴 寰€鎸囧畾涓婚�鍙戦€丄ction鍖咃紝鎼哄甫鍙傛暟锛屽�鐢ㄨ繛鎺ヨ�闃呯殑榛樿�Topic锛岄€氳繃鎻愪緵鐨勬秷鎭�挬瀛� 绛夊緟resp锛岃秴鏃舵病鏀跺埌搴旂瓟杩斿洖澶辫触锛�
|
|
|
LOGICDEVICE_API int ActionAndRespWithConnDefalt(ccos_mqtt_connection* hConnection, const char* pAction, ResDataObject& req, ResDataObject* pContext, const char* pszTopic, ResDataObject& resObj, DWORD dwWaitTime);
|
|
|
|
|
|
-//往指定主题发送Action包,携带参数,并指定答复的Topic,同步等待resp,临时创建连接,并等待应答,超时没收到应答返回失败
|
|
|
+//寰€鎸囧畾涓婚�鍙戦€丄ction鍖咃紝鎼哄甫鍙傛暟锛屽苟鎸囧畾绛斿�鐨凾opic锛屽悓姝ョ瓑寰卹esp锛屼复鏃跺垱寤鸿繛鎺ワ紝骞剁瓑寰呭簲绛旓紝瓒呮椂娌℃敹鍒板簲绛旇繑鍥炲け璐�
|
|
|
LOGICDEVICE_API int ActionAndResp(const char* pAction, ResDataObject* pContext, const char* pszTopic, const char* pszRespTopic, ResDataObject& resObj,
|
|
|
DWORD dwWaitTime, const char* pszSenderName);
|