stdafx.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // pch.h: 这是预编译标头文件。
  2. // 下方列出的文件仅编译一次,提高了将来生成的生成性能。
  3. // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
  4. // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
  5. // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
  6. #pragma once
  7. #ifndef PCH_H
  8. #define PCH_H
  9. // C++ 标准库头文件
  10. #include <mutex>
  11. #include <map>
  12. #include <thread>
  13. #include <atomic>
  14. #include <condition_variable>
  15. #include <chrono>
  16. //V3需要用到的公共定义
  17. #include "CcosGeneralDefine_V3.h"
  18. #include "CcosMouldGenerator_V3.h"
  19. #include "CcosUnitComm_V3.h"
  20. #include "DeliverModule.h"
  21. #include "PlatformInteraction.h"
  22. //日志类
  23. #include "Log4CPP.Logger.hpp"
  24. #include "Log4CPP.TLSLog.Tracing.hpp"
  25. #include "mLog.Log4CPP.hpp"
  26. // Linux兼容的导出定义
  27. #define _CCOS_GEN_IDETEC_Almax_API __attribute__((visibility("default")))
  28. // Linux兼容的数据类型定义
  29. using DWORD = unsigned long;
  30. using LPVOID = void*;
  31. using BOOL = int;
  32. using HANDLE = void*;
  33. #define TRUE 1
  34. #define FALSE 0
  35. // Sleep函数的兼容实现
  36. inline void Sleep(unsigned int milliseconds) {
  37. std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
  38. }
  39. //设置相关常量
  40. #define msTimeOut_Lock 500 //通讯接口锁定时间
  41. #define TIMEOUTVALUE 100
  42. #define Almax_Com_HeadLen 3
  43. #define Almax_Com_ReSendLen 64
  44. #define Almax_STX 0x02
  45. #define Almax_ETX 0x03
  46. #define Almax_ACK 0x06
  47. #define Almax_NAK 0x15
  48. //callBackFun define
  49. using callBackFun = std::function <void(std::string, std::string)>;
  50. namespace nsSerialGPM = CCOS::Dev::MODLE::SerialGPM;
  51. //响应操作对照表
  52. using tbFun = std::function <void(char*, int)>;
  53. struct tFrameMapItem
  54. {
  55. tbFun m_fFun; //与指令id绑定的处理函数
  56. tFrameMapItem();
  57. tFrameMapItem(tbFun f);
  58. tFrameMapItem& operator =(const tFrameMapItem& value);
  59. };
  60. //map比较函数
  61. #if 0 //有的设备指令ID并非统一长度,所以自定义map的key的比较规则
  62. template <>
  63. struct less<std::string>
  64. {
  65. public:
  66. bool operator()(const std::string& p1, const std::string& p2) const
  67. {
  68. if (p1.at(0) == Almax_STX)
  69. {
  70. int smallLengh = p1.length() <= p2.length() ? p1.length() : p2.length();
  71. int res = p1.compare(1, smallLengh, p2, 0, smallLengh);
  72. if (res < 0)
  73. return true;
  74. else
  75. return false;
  76. }
  77. else if (p2.at(0) == Almax_STX)
  78. {
  79. int smallLengh = p1.length() <= p2.length() ? p1.length() : p2.length();
  80. int res = p1.compare(0, smallLengh, p2, 1, smallLengh);
  81. if (res < 0)
  82. return true;
  83. else
  84. return false;
  85. }
  86. else
  87. {
  88. return p1 < p2;
  89. }
  90. }
  91. };
  92. #endif
  93. extern nsSCF::CcosConnect glo_obCommObj; //公共的设备连接通信对象
  94. extern std::map <string, tFrameMapItem> glo_arFrame; //响应操作对照表
  95. extern nsSerialGPM::CDeliverModule glo_tDelivermodule; //统一的串口指令处理类
  96. extern int glo_nCMDType_WaitTime; //指令类型1:发送后等待固定时间
  97. extern int glo_nCMDType_HB; //指令类型2:心跳
  98. extern int glo_nCMDType_WaitACK; //指令类型3:发送后等待ACK返回
  99. #endif //PCH_H