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.

143 lines
4.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "rgooseNode2D.h"
  2. #include "../hardware/uart/serialPort.h"
  3. #include "../hardware/uart/serialSOL.h"
  4. #define LOG( X ) m_pLog->Log( "2DNODE", this, X )
  5. #ifdef DEBUG
  6. #define LOG_ERROR( X ) {\
  7. char _tBfrErrMSG2w34[256];\
  8. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  9. m_pLog->Log( "2DNODE", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  10. }
  11. #else
  12. #define LOG_ERROR( X ) m_pLog->Log( "2DNODE", this, _LOG_ERROR, X );
  13. #endif
  14. ARGUS_2DSensor::ARGUS_2DSensor( uint32_t id ):argusNetNode( id ), basicThread(), protocolLGS_2D(){
  15. m_pLog = basicLogCollection::getInstance();
  16. DBC_LRF_DATA *tDATA = m_pDBC->getLRFData( m_sNodeData.aux_id );
  17. m_bWM = 0;
  18. if( tDATA != NULL ) {
  19. memcpy( &m_sLRF_DATA, tDATA, sizeof(DBC_LRF_DATA));
  20. } else {
  21. memset( &m_sLRF_DATA, 0, sizeof(DBC_LRF_DATA));
  22. };
  23. };
  24. ARGUS_2DSensor::~ARGUS_2DSensor(){
  25. stopService();
  26. };
  27. bool ARGUS_2DSensor::startService() {
  28. if( m_sLRF_DATA.id == 0 ){
  29. LOG_ERROR("No DATA From Database!");
  30. return false;
  31. };
  32. if( setDeviceID( m_sLRF_DATA.device_id ) ){
  33. DBC_UART_DATA *tData = NULL;
  34. tData = m_pDBC->getUartData( m_sLRF_DATA.uart_id );
  35. if( tData!= NULL ) {
  36. basicTransport *tTransport = NULL;
  37. switch( tData->type ) {
  38. case 1:{ // Hardware
  39. #ifdef DEBUG
  40. LOG("HW Port");
  41. #endif
  42. serialPort *tT = NULL;
  43. tT = new serialPort();
  44. if( tT!= NULL ){
  45. if( tT->create( tData->path, tData->speed ) ){
  46. tTransport = (basicTransport *) tT;
  47. } else {
  48. delete( tT );
  49. };
  50. };
  51. break;
  52. };
  53. case 2:{ // E2S
  54. #ifdef DEBUG
  55. LOG("SOL Port");
  56. #endif
  57. serialSOL *tT = NULL;
  58. tT = new serialSOL( (SOL_TYPE)tData->mode );
  59. if( tT!= NULL ){
  60. if( tT->create( tData->path, tData->port, tData->speed ) ){
  61. tTransport = (basicTransport *) tT;
  62. } else {
  63. delete( tT );
  64. };
  65. };
  66. break;
  67. };
  68. #ifdef DEBUG
  69. default: LOG_ERROR("Unknown Port Type!");
  70. #endif
  71. };
  72. if( tTransport!= NULL ) {
  73. LOG( "Bind Transport Port!" );
  74. if( setTransport( tTransport )){
  75. if( create() ){
  76. LOG_ERROR("Protocol <<< Create >>> Failure!");
  77. };
  78. } else {
  79. LOG_ERROR("Binding Port Failure!");
  80. };
  81. } else LOG_ERROR("Transport Creation Failure!");
  82. free( tData );
  83. };
  84. };
  85. return init();
  86. };
  87. bool ARGUS_2DSensor::stopService() {
  88. waitThreadEnd( true );
  89. return true;
  90. };
  91. bool ARGUS_2DSensor::validate(){
  92. return true;
  93. };
  94. void ARGUS_2DSensor::m_fThreadProc( void ){
  95. m_bThreadStatus = TH_WORKING;
  96. while (m_bThreadStatus < TH_ENDED) {
  97. switch( m_bWM ) {
  98. // Physical Connection Channel
  99. case 0: if( getConnectionStatus() == CS_CONNECTED ) m_bWM = 1;
  100. // Logical Connection Checking
  101. case 1: if( !getState() ) m_bWM = 0;
  102. // Update Parameters
  103. case 2:
  104. // Idle Work
  105. case 128: if( !getState2() ) m_bWM = 0;
  106. };
  107. SLEEP(300);
  108. };
  109. };
  110. #define SIZE_IDX 1
  111. #define DEV_ID_IDX 2
  112. #define CMD_IDX 3
  113. #define SUB_CMD_IDX 4
  114. #define DATA_BEGIN_IDX 5
  115. bool ARGUS_2DSensor::packetHandler( protocolPackage *Package ){
  116. return true;
  117. };
  118. #undef SIZE_IDX
  119. #undef DEV_ID_IDX
  120. #undef CMD_IDX
  121. #undef SUB_CMD_IDX
  122. #undef DATA_BEGIN_IDX
  123. #undef LOG
  124. #undef LOG_ERROR