You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.0 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "protocolMastBaum.h"
  2. #include "../../hardware/uart/serialPort.h"
  3. #define LOG( X ) m_pLog->Log( "MastBaumPoroto", this, X )
  4. #define LOG_ERROR( X ) m_pLog->Log( "MastBaumPoroto", this, _LOG_ERROR, X )
  5. protocolMastBaum::protocolMastBaum( config_setting_t *Settings ): protocolParser( Settings ){
  6. m_pDataTransport = NULL;
  7. m_bDeviceID = 0; // Broadcast or Future use
  8. };
  9. protocolMastBaum::~protocolMastBaum(){
  10. if (m_pDataTransport != NULL) delete((serialPort*)m_pDataTransport);
  11. };
  12. bool protocolMastBaum::completePackage( U8 *Buffer, size_t BufferSize ){
  13. if( BufferSize > ( 0xFF - 3 ) ) return false;
  14. Buffer[0] = MASTBAUM_PACKAGE_START_TAG;
  15. Buffer[1] = MASTBAUM_MASTER_TAG | m_bDeviceID;
  16. Buffer[2] = ( BufferSize - 3 ) & 0xFF;
  17. Buffer[BufferSize] = checksumLGS( Buffer, BufferSize );
  18. return true;
  19. };
  20. int protocolMastBaum::packetChecker( unsigned char *Buffer, size_t BufferSize ){
  21. if( Buffer[0] == 0xAA ) {
  22. if( BufferSize > 1 ) {
  23. if( BufferSize < 16 ) {
  24. for( U8 i=1; i< BufferSize; i++ ){
  25. if( Buffer[i] == 0xFF ) {
  26. #ifdef DEBUG
  27. LOG("PacketChecker: Packet Is Recognized");
  28. #endif
  29. return 0;
  30. };
  31. };
  32. } else {
  33. for( U8 i=1; i< 16; i++ ){
  34. if( Buffer[i] == 0xFF ) {
  35. #ifdef DEBUG
  36. LOG("PacketChecker: Packet Is Recognized");
  37. #endif
  38. return 0;
  39. };
  40. };
  41. };
  42. };
  43. };
  44. #ifdef DEBUG
  45. LOG("PacketChecker: Packet Not Recognized");
  46. #endif
  47. return 1;
  48. };
  49. //int protocolPTZ_VISCA::packetExtractor(unsigned char *Buffer, size_t BufferSize)
  50. protocolPackage *protocolMastBaum::packetExtractor(unsigned char *Buffer, size_t BufferSize){
  51. U8 i;
  52. protocolPackage *RetVal;
  53. RetVal = (protocolPackage*)malloc(sizeof(protocolPackage));
  54. if (RetVal != NULL){
  55. RetVal->m_pData = (unsigned char *) malloc(16);
  56. for (i = 0; i < 16; i++){
  57. RetVal->m_pData[i] = Buffer[i];
  58. if (Buffer[i] == 0xFF) {
  59. LOG("PacketExtractor: Packet Is Extracted");
  60. break;
  61. };
  62. };
  63. RetVal->m_nSize = i + 1;
  64. }
  65. LOG("PacketExtractor: Packet Not Extracted");
  66. return RetVal;
  67. };
  68. bool protocolMastBaum::packetHandler(protocolPackage *Package){
  69. U8 Com_Mode;
  70. U8 Cat_Code;
  71. LOG("PacketHandler: Packet Is Handling");
  72. Com_Mode = Package->m_pData[1];
  73. Cat_Code = Package->m_pData[2];
  74. free( Package->m_pData );
  75. free( Package );
  76. return true;
  77. };
  78. bool protocolMastBaum::create(void){
  79. config_setting_t *pSetting;
  80. int tPort, tSpeed;
  81. if (!protocolParser::create()) return false;
  82. pSetting = config_setting_get_member(m_pSettings, MASTBAUM_TAG_COM_PORT);
  83. if (pSetting == NULL) return false;
  84. tPort = config_setting_get_int(pSetting);
  85. pSetting = config_setting_get_member(m_pSettings, MASTBAUM_TAG_COM_SPEED);
  86. if (pSetting == NULL) return false;
  87. tSpeed = config_setting_get_int(pSetting);
  88. char tBuf[16];
  89. #ifdef __linux__
  90. sprintf( tBuf,"/dev/ttyS%d",tPort);
  91. #else
  92. sprintf(tBuf, "com%d", tPort);
  93. #endif
  94. m_pDataTransport = new serialPort(tBuf,tSpeed);
  95. if (m_pDataTransport != NULL){
  96. if (m_pDataTransport->addRecipient(this)){
  97. return true;
  98. };
  99. };
  100. return false;
  101. };
  102. #undef LOG
  103. #undef LOG_ERROR