From 1b7de403432a292b2a4962f7b9f88d76f897df9e Mon Sep 17 00:00:00 2001 From: Gagua on MyIR master Date: Mon, 19 Aug 2019 15:41:23 +0000 Subject: [PATCH] 3D Server - Corrected CAN Bus object to start communication thread --- Projects/LRF_Server/Debug/3DLRF.conf | 4 +- lib/App/3dSERVER/LRF_DefenderHandler.cpp | 6 +- lib/data/protocol/protocolDefender.cpp | 168 +++++++++++------- lib/data/protocol/protocolDefender.h | 62 ++++--- lib/data/transport/transportSerial.cpp | 5 +- lib/hardware/can/canbus.cpp | 6 +- lib/hardware/soc/classSOC.cpp | 211 +++++++++++++++++++---- lib/hardware/soc/classSOC.h | 2 + lib/hardware/soc/general/3DLRF.h | 21 ++- lib/hardware/uart/serialPort.cpp | 94 ++++++---- put_to_git | 2 +- 11 files changed, 410 insertions(+), 171 deletions(-) diff --git a/Projects/LRF_Server/Debug/3DLRF.conf b/Projects/LRF_Server/Debug/3DLRF.conf index 9ad1a179..fcb205b1 100644 --- a/Projects/LRF_Server/Debug/3DLRF.conf +++ b/Projects/LRF_Server/Debug/3DLRF.conf @@ -44,7 +44,7 @@ KERNEL : { SCANNER_NAME = "LRF_LIBERMAN_MASTER"; SCANNER_DIMENTIONS = 3; - LCU_IP_ADDRESS = "192.168.200.204"; + LCU_IP_ADDRESS = "192.168.200.125"; LCU_IP_PORT = 80; CURL_POST_CONTENT_TYPE = "application/xml"; }; @@ -54,7 +54,7 @@ KERNEL : { SCANNER_NAME = "LRF_3D_001"; SCANNER_DIMENTIONS = 3; - CEP_IP_ADDRESS = "192.168.200.204"; + CEP_IP_ADDRESS = "192.168.200.125"; CEP_IP_PORT = 80; CURL_POST_CONTENT_TYPE = "application/json"; }; diff --git a/lib/App/3dSERVER/LRF_DefenderHandler.cpp b/lib/App/3dSERVER/LRF_DefenderHandler.cpp index 5d00bc1e..34d8e9cb 100644 --- a/lib/App/3dSERVER/LRF_DefenderHandler.cpp +++ b/lib/App/3dSERVER/LRF_DefenderHandler.cpp @@ -64,11 +64,11 @@ void LRF_DefenderHandler::dispatchEvent( basicEvent *Evt ){ if( tCEVT != NULL ){ float Az, El; uint32_t cRange; - cRange = (uint32_t)(((float) tCEVT->range ) * 0.732421875f ) ; // To Decimeters + cRange = (uint32_t)(((float) tCEVT->range ) * 0.0732421875f ) ; // To meters #ifdef PRU_SLAVE - make3Dmildeg( tCEVT->th_id, Az, El, false ); + make3Ddeg( tCEVT->th_id, Az, El, false ); #else - make3Dmildeg( tCEVT->th_id, Az, El, true ); + make3Ddeg( tCEVT->th_id, Az, El, true ); #endif Alarm3D( (int)Az, (int)El, cRange , tCEVT->k_id ); }; diff --git a/lib/data/protocol/protocolDefender.cpp b/lib/data/protocol/protocolDefender.cpp index 7da5ff6e..edf09e70 100644 --- a/lib/data/protocol/protocolDefender.cpp +++ b/lib/data/protocol/protocolDefender.cpp @@ -15,14 +15,16 @@ CSTR defenderFaultCode[] = { "Info" }; CSTR defenderCategories[] = { - "STATUS", - "ALARM", - "ERROR" + DFSL_CATEGORY_ERROR, + DFSL_CATEGORY_STATUS, + DFSL_CATEGORY_ALARM_2D, + DFSL_CATEGORY_ALARM_3D }; CSTR defenderTypeDescription[] = { - "Status Message", - "Target Detection Event", - "Fault Event" + "Fault Event", + "Status Message", + "Target Detection Event", + "Target Detection Event" }; CSTR defenderTypeSeverity[] = { "very-low", @@ -134,8 +136,9 @@ CSTR protocolDefender::buildURL( CSTR templ, int dim, CSTR devID ){ CSTR RetVal; char tpl[256]; RetVal = (CSTR) malloc( 256 ); - sprintf( tpl, "http://%s:%d%s", m_pServerIP, m_nServerPort, templ ); - sprintf( RetVal, tpl, dim, devID ); + //sprintf( tpl, "http://%s:%d%s", m_pServerIP, m_nServerPort, templ ); + //sprintf( RetVal, tpl, dim, devID ); + sprintf( RetVal, DFSL_DEFENDER_DEFAULT_URL, m_pServerIP, m_nServerPort ); return RetVal; }; @@ -162,7 +165,27 @@ protocolDefender::protocolDefender( config_setting_t *Settings ): protocolHTTP( memset( m_pServerIP, 0 , OS_CEP_ADDRESS_SIZE); m_bCurrentStatus = false; - + if( Settings != NULL ) { + double tVal = 0; + config_setting_t * pSetting; + if (!config_setting_lookup_float(Settings, "LOCATION_LON", &tVal )){ + tVal = 35.0938962; + pSetting = config_setting_add(Settings, "LOCATION_LON", CONFIG_TYPE_FLOAT); + config_setting_set_float(pSetting, tVal); + basicSettingsProvider::getInstance()->compromise(); + }; + m_fLon = tVal; + if (!config_setting_lookup_float(Settings, "LOCATION_LAT", &tVal )){ + tVal = 32.904208; + pSetting = config_setting_add(Settings, "LOCATION_LAT", CONFIG_TYPE_FLOAT); + config_setting_set_float(pSetting, tVal); + basicSettingsProvider::getInstance()->compromise(); + }; + m_fLat = tVal; + } else { + m_fLon = 35.0938962;// 35.095278 + m_fLat = 32.904208; // 32.904167 + } if( m_pSettings != NULL ){ config_setting_t *pSetting; @@ -245,50 +268,50 @@ void protocolDefender::setProtocolType( bool DeviceIs3D ){ }; CSTR protocolDefender::assembleStatusData( bool StatusOK ){ CSTR RetVal; - CSTR tBuf; + CSTR TIME_STAMP; CSTR tSRC; CSTR tTARGET; CSTR tID; RetVal = (CSTR) malloc(CLOG); if ( RetVal != NULL ) { - tBuf = getSHDTimeStamp(); - if( tBuf != NULL ) { + TIME_STAMP = getSHDTimeStamp(); + if( TIME_STAMP != NULL ) { tTARGET = (CSTR) malloc(128); if( tTARGET!= NULL) { tSRC = (CSTR) malloc(128); if( tSRC ) { tID = (CSTR) malloc(64); if( tID != NULL ) { - sprintf( tID, "%s", MD5String( tBuf ) ); - sprintf( tSRC, DFSL_SensorSourceDto, DFSL_HARDWARE_TYPE, DFSL_SOURCE_NAME, m_pScannerName ); - sprintf( tTARGET, "{ \"status\": \"%s\" }", defenderStatusMode[((StatusOK)?1:0)] ); + sprintf( tID, "%s", MD5String( TIME_STAMP ) ); + sprintf( tSRC, DFSL_SENSOR_SOURCE_DTO, DFSL_HARDWARE_TYPE, DFRL_PROVIDER_ID, m_pScannerName ); + sprintf( tTARGET, DFSL_STATUS_DTO, TIME_STAMP , defenderStatusMode[((StatusOK)?1:0)] ); sprintf( RetVal, - PACKAGE_SE_DATA_STATUS_ELEMENT, + PACKAGE_SE_STATUS_DATA_ELEMENT, defenderTypeDescription[DC_STATUS], - tBuf, + TIME_STAMP, tSRC, - "DFSL_STATUS_DATA", - "EventLidarStatus", + "DFSL_LIDAR_SENSOR_STATUS", + DFSL_DATA_TYPE_STATUS, tID, tTARGET ); free( tID ); free( tSRC ); free( tTARGET ); - free( tBuf ); + free( TIME_STAMP ); } else { free( tSRC ); free( tTARGET ); - free( tBuf ); + free( TIME_STAMP ); free( RetVal ); } } else { free( tTARGET ); - free( tBuf ); + free( TIME_STAMP ); free( RetVal ); }; } else { - free( tBuf ); + free( TIME_STAMP ); free( RetVal ); }; } else { @@ -300,50 +323,50 @@ CSTR protocolDefender::assembleStatusData( bool StatusOK ){ }; CSTR protocolDefender::assembleFaultData( uint8_t Code, CSTR Desc ){ CSTR RetVal; - CSTR tBuf; + CSTR TIME_STAMP; CSTR tSRC; CSTR tTARGET; CSTR tID; RetVal = (CSTR) malloc(CLOG); if ( RetVal != NULL ) { - tBuf = getSHDTimeStamp(); - if( tBuf != NULL ) { + TIME_STAMP = getSHDTimeStamp(); + if( TIME_STAMP != NULL ) { tTARGET = (CSTR) malloc(128); if( tTARGET!= NULL) { tSRC = (CSTR) malloc(128); if( tSRC ) { tID = (CSTR) malloc(64); if( tID != NULL ) { - sprintf( tID, "%s", MD5String( tBuf ) ); - sprintf( tSRC, DFSL_SensorSourceDto, DFSL_HARDWARE_TYPE, DFSL_SOURCE_NAME, m_pScannerName ); - sprintf( tTARGET, "{ \"code\": %d, \"description\": \"%s\" }", Code, Desc ); + sprintf( tID, "%s", MD5String( TIME_STAMP ) ); + sprintf( tSRC, DFSL_SENSOR_SOURCE_DTO, DFSL_HARDWARE_TYPE, DFRL_PROVIDER_ID, m_pScannerName ); + sprintf( tTARGET, DFSL_ERROR_DTO, Code, TIME_STAMP ); sprintf( RetVal, - PACKAGE_SE_DATA_STATUS_ELEMENT, - defenderTypeDescription[DC_ERROR], - tBuf, + PACKAGE_SE_STATUS_DATA_ELEMENT, + Desc, + TIME_STAMP, tSRC, - "DFSL_FAULT_DATA", - "EventLidarFault", + "DFSL_LIDARE_SENSOR_FAULT_DATA", + DFSL_DATA_TYPE_ERROR, tID, tTARGET ); free( tID ); free( tSRC ); free( tTARGET ); - free( tBuf ); + free( TIME_STAMP ); } else { free( tSRC ); free( tTARGET ); - free( tBuf ); + free( TIME_STAMP ); free( RetVal ); } } else { free( tTARGET ); - free( tBuf ); + free( TIME_STAMP ); free( RetVal ); }; } else { - free( tBuf ); + free( TIME_STAMP ); free( RetVal ); }; } else { @@ -355,50 +378,54 @@ CSTR protocolDefender::assembleFaultData( uint8_t Code, CSTR Desc ){ }; CSTR protocolDefender::assembleTargetData( int targetID, int Range, int Width, int Azimuth, int Elevation ){ CSTR RetVal; - CSTR tBuf; + CSTR TIME_STAMP; CSTR tSRC; CSTR tTARGET; CSTR tID; RetVal = (CSTR) malloc(CLOG); if ( RetVal != NULL ) { - tBuf = getSHDTimeStamp(); - if( tBuf != NULL ) { + TIME_STAMP = getSHDTimeStamp(); + if( TIME_STAMP != NULL ) { tTARGET = (CSTR) malloc(128); if( tTARGET!= NULL) { tSRC = (CSTR) malloc(128); if( tSRC ) { tID = (CSTR) malloc(64); if( tID != NULL ) { - sprintf( tID, "%s", MD5String( tBuf ) ); - sprintf( tSRC, DFSL_SensorSourceDto, DFSL_HARDWARE_TYPE, DFSL_SOURCE_NAME, m_pScannerName ); - sprintf( tTARGET, DFSL_LidarTargetDto, targetID, Azimuth, Elevation, Range, Width ); + sprintf( tID, "%s", MD5String( TIME_STAMP ) ); + sprintf( tSRC, DFSL_SENSOR_SOURCE_DTO, DFSL_HARDWARE_TYPE, DFRL_PROVIDER_ID, m_pScannerName ); + if( m_nScannerDimentions > 2 ) { + sprintf( tTARGET, DFSL_3D_TARGET_DTO, Azimuth, Elevation, Range ); + } else { + sprintf( tTARGET, DFSL_2D_TARGET_DTO, Azimuth, Range, Width ); + }; sprintf( RetVal, - PACKAGE_SE_DATA_ELEMENT, + PACKAGE_SE_TARGET_DATA_ELEMENT, defenderTypeDescription[DC_ALARM], - tBuf, + TIME_STAMP, tSRC, "DFSL_TARGET_DATA", - "EventLidarTarget", + DFSL_DATA_TYPE_TARGET, tID, tTARGET ); free( tID ); free( tSRC ); free( tTARGET ); - free( tBuf ); + free( TIME_STAMP ); } else { free( tSRC ); free( tTARGET ); - free( tBuf ); + free( TIME_STAMP ); free( RetVal ); } } else { free( tTARGET ); - free( tBuf ); + free( TIME_STAMP ); free( RetVal ); }; } else { - free( tBuf ); + free( TIME_STAMP ); free( RetVal ); }; } else { @@ -433,12 +460,13 @@ size_t protocolDefender::assembleDefenderJSON( CSTR Buffer, defenderCategoryType Severity = 2; }; //sprintf( ID, "%s", MD5String( tBuf ) ); + if( (m_nScannerDimentions > 2) && ( Type == DC_ALARM ) ) Type = DC_ALARM_3D; sprintf( tBuffer, DFSL_SE_ENVELOPE, - DEFENDER_MESSAGE_ID, + //DEFENDER_MESSAGE_ID, defenderCategories[Type], defenderTypeSeverity[Severity], - tBuf, tBuf, tBuf, tBuf, + tBuf, tBuf, Location, Data ); @@ -455,10 +483,12 @@ bool protocolDefender::buildStatusPackage( unsigned char *Buffer, int &BufferSiz CSTR tBuf; tBuf = assembleStatusData( Status ); #ifdef DEBUG - LOG(tBuf); + //LOG(tBuf); #endif if( tBuf != NULL ) { - BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_STATUS, ((Status)?0:2), DFSL_DEFAULT_LOCATION, tBuf ); + char DFSL_LOCATION[256]; + sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat ); + BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_STATUS, ((Status)?0:2), DFSL_LOCATION, tBuf ); #ifdef DEBUG LOG((CSTR)Buffer); #endif @@ -475,7 +505,9 @@ bool protocolDefender::buildFaultPackage( unsigned char *Buffer, int &BufferSize CSTR tBuf; tBuf = assembleFaultData( Type, Description ); if( tBuf != NULL ){ - BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_ERROR, 3, DFSL_DEFAULT_LOCATION, tBuf ); + char DFSL_LOCATION[256]; + sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat ); + BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_ERROR, 3, DFSL_LOCATION, tBuf ); free( tBuf ); return true; }; @@ -483,12 +515,14 @@ bool protocolDefender::buildFaultPackage( unsigned char *Buffer, int &BufferSize return false; }; -bool protocolDefender::buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, int Angle, int Range, int Width){ +bool protocolDefender::buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle, float Range, float Width){ if( Buffer!= NULL ){ CSTR tBuf; tBuf = assembleTargetData( targetID, Range, Width, Angle, 0 ); if( tBuf != NULL ){ - BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_ALARM, 3, DFSL_DEFAULT_LOCATION, tBuf ); + char DFSL_LOCATION[256]; + sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat ); + BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_ALARM, 3, DFSL_LOCATION, tBuf ); free( tBuf ); return true; }; @@ -496,15 +530,17 @@ bool protocolDefender::buildEvent2DPackage( unsigned char *Buffer, int &BufferSi return false; }; -bool protocolDefender::buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, int Angle1, int Angle2, int Range ){ +bool protocolDefender::buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle1, float Angle2, float Range ){ if( Buffer!= NULL ){ CSTR tBuf; tBuf = assembleTargetData( targetID, Range, 0, Angle1, Angle2 ); #ifdef DEBUG - LOG(tBuf); + //LOG(tBuf); #endif if( tBuf != NULL ){ - BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_ALARM, 3, DFSL_DEFAULT_LOCATION, tBuf ); + char DFSL_LOCATION[256]; + sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat ); + BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_ALARM, 3, DFSL_LOCATION, tBuf ); #ifdef DEBUG LOG((CSTR)Buffer); #endif @@ -547,7 +583,7 @@ bool protocolDefender::buildCallBackPackage( unsigned char *Buffer, int &BufferS }; -bool protocolDefender::Alarm2D( int Angle, int Range, int Width, int ID ){ +bool protocolDefender::Alarm2D( float Angle, float Range, float Width, int ID ){ bool RetVal= false; char Buffer[1024]; int BufferSize = 0; @@ -566,7 +602,7 @@ bool protocolDefender::Alarm2D( int Angle, int Range, int Width, int ID ){ return RetVal; }; -bool protocolDefender::Alarm3D( int Angle1, int Angle2, int Range, int ID ){ +bool protocolDefender::Alarm3D( float Angle1, float Angle2, float Range, int ID ){ bool RetVal= false; char Buffer[1024]; int BufferSize = 0; @@ -641,7 +677,7 @@ bool protocolDefender::ErrorReporting( int lvl, CSTR Descr ){ bool protocolDefender::StartTimeSynch( void ){ bool RetVal= false; - LOG("TimeSYnc"); + //LOG("TimeSYnc"); /*char Buffer[1024]; int BufferSize = 0; CSTR URL = NULL; @@ -661,11 +697,11 @@ bool protocolDefender::packetHandler( protocolPackage *Package ){ if( Package->m_nSize == 0 ) return false; if( Package->m_pData == NULL ) return false; if( Package->m_nCode != 200 ) return false; - try{ + try{ XMLNode node1 = XMLNode::parseString( (const char *)Package->m_pData, "root"); if( node1.isEmpty() ){ char BUBU[128]; - sprintf( BUBU, "The package[%d:%d] XML data is not a valid XML data. Cann't find root element.", strlen((CSTR)Package->m_pData), Package->m_nSize ); + sprintf( BUBU, "The package[%d:%d] XML data is not a valid XML data. Cann't find root element. Code[%d]", strlen((CSTR)Package->m_pData), Package->m_nSize, Package->m_nCode ); LOG_ERROR(BUBU); } else { LOG( node1.getName() ); diff --git a/lib/data/protocol/protocolDefender.h b/lib/data/protocol/protocolDefender.h index d6e2fa35..c14ecc96 100644 --- a/lib/data/protocol/protocolDefender.h +++ b/lib/data/protocol/protocolDefender.h @@ -29,41 +29,54 @@ #define SERVICE_URL_TEMPLATE_CALLBACK "/sensors/lidar%dd/%s/httpcallback" #define SERVICE_URL_TEMPLATE_CLOCKSYNC "/sensors/lidar%dd/%s/clocksync" -#define DFSL_HARDWARE_TYPE "DFSL_3D_LIDAR" +#define DFSL_HARDWARE_TYPE "SensorNode" #ifdef PRU_SLAVE - #define DFSL_SOURCE_NAME "SLAVE_SENSOR" + #define DFSL_SOURCE_NAME_ "SLAVE_SENSOR" #else - #define DFSL_SOURCE_NAME "MASTER_SENSOR" + #define DFSL_SOURCE_NAME_ "MASTER_SENSOR" #endif +#define DFSL_CATEGORY_ALARM_3D "dfsl#intruder-drone-detected" +#define DFSL_CATEGORY_ALARM_2D "dfsl#intruder-human-detected" +#define DFSL_CATEGORY_STATUS "dfsl#sensor-status-message" +#define DFSL_CATEGORY_ERROR "dfsl#sensor-error-message" +#define DFRL_PROVIDER_ID "DFSL" +#define DFSL_DATA_TYPE_TARGET "EventLidarTarget" +#define DFSL_DATA_TYPE_STATUS "EventLidarStatus" +#define DFSL_DATA_TYPE_ERROR "EventLidarFault" +//defender-eps.eng.it +#define DFSL_DEFENDER_DEFAULT_URL "http://%s:%d/defender-eps/rest/simple-event/notify" + typedef enum E_DEFENDER_CATEGORY{ - DC_STATUS = 0, - DC_ALARM = 1, - DC_ERROR = 2 + DC_ERROR = 0, + DC_STATUS = 1, + DC_ALARM = 2, + DC_ALARM_3D = 3 } defenderCategoryTypes; -#define DFSL_DEVICE "DFSL Lidar Sensor" -#define DFSL_DEFAULT_LOCATION "{\"point\": [ 32.878, 35.999 ], \"heading\": 128, \"area\": [] }" -#define DFSL_SensorSourceDto "{ \"providerId\": \"%s\", \"sensorNodeId\" : \"%s\", \"sensorId\": \"%s\" }" - -#define DFSL_LidarTargetDto "{ \"id\": %d, \"AZ\": %d, \"EL\": %d, \"Range\": %d, \"Width\": %d }" +#define DFSL_DEVICE_ "DFSL Lidar Sensor" +#define DFSL_LOCATION_DTO "{\"point\": [ %2.5f, %2.5f ] }" +#define DFSL_SENSOR_SOURCE_DTO "{ \"type\": \"%s\", \"providerId\": \"%s\", \"sensorNodeId\" : \"%s\" }" -#define DFSL_LocationDto "{\"point\": [ %s ],\"area\": [ %s ] }" +#define DFSL_2D_TARGET_DTO "{ \"AZ\": %d, \"Range\": %d, \"Width\": %d }" +#define DFSL_3D_TARGET_DTO "{ \"AZ\": %d, \"EL\": %d, \"Range\": %d }" +#define DFSL_STATUS_DTO "{ \"created\": \"%s\", \"name\": \"status\", \"value\": \"%s\" }" +#define DFSL_ERROR_DTO "{ \"created\": \"%s\", \"name\": \"code\", \"value\": \"%d\", \"description\": \"%s\" }" -#define DFSL_SE_ENVELOPE "{\"id\": %d,\"category\": \"%s\",\"severity\": \"%s\"," \ - "\"receivedTS\": \"%s\",\"lastChangeTS\": \"%s\"," \ +#define DFSL_SE_ENVELOPE "{\"category\": \"%s\",\"severity\": \"%s\"," \ + "\"ceiId\": \"ENGIE_CEI\"," \ "\"startTime\": \"%s\",\"endTime\": \"%s\", \"location\": %s, " \ "\"radius\": 0, \"data\": [ %s ]}" -#define PACKAGE_SE_DATA_ELEMENT "{\"description\": \"%s\", \"created\": \"%s\", \"source\": %s," \ - " \"name\": \"%s\", \"type\": \"%s\", \"eventId\": \"%s\", \"targets\": [%s] }" +#define PACKAGE_SE_TARGET_DATA_ELEMENT "{\"description\": \"%s\", \"created\": \"%s\", \"source\": %s," \ + " \"name\": \"%s\", \"type\": \"%s\", \"lidarSensorEventId\": \"%s\", \"targets\": [%s] }" -#define PACKAGE_SE_DATA_STATUS_ELEMENT "{\"description\": \"%s\", \"created\": \"%s\", \"source\": %s, " \ - " \"name\": \"%s\", \"type\": \"%s\", \"eventId\": \"%s\", \"payload\": [%s] }" +#define PACKAGE_SE_STATUS_DATA_ELEMENT "{\"description\": \"%s\", \"created\": \"%s\", \"source\": %s, " \ + " \"name\": \"%s\", \"type\": \"%s\", \"lidarSensorEventId\": \"%s\", \"measurements\": [%s] }" #define OS_SCANNER_NAME_SIZE 128 -#define OS_CEP_ADDRESS_SIZE 16 +#define OS_CEP_ADDRESS_SIZE 128 /** * TODO: Add class description @@ -77,6 +90,8 @@ private: int m_nScannerDimentions; CSTR m_pScannerName; CSTR m_pServerIP; + float m_fLon; + float m_fLat; int m_nServerPort; bool m_bCurrentStatus; CSTR buildURL( CSTR templ, int dim, CSTR devID ); @@ -85,8 +100,8 @@ private: bool buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath ); bool buildStatusPackage( unsigned char *Buffer, int &BufferSize, bool Status ); bool buildFaultPackage( unsigned char *Buffer, int &BufferSize, unsigned char Type, CSTR Description ); - bool buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, int Angle, int Range, int Width ); - bool buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, int Angle1, int Angle2, int Range ); + bool buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle, float Range, float Width ); + bool buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle1, float Angle2, float Range ); CSTR assembleStatusData( bool StatusOK ); CSTR assembleFaultData( uint8_t Code, CSTR Desc ); @@ -102,8 +117,8 @@ public: // Destructor virtual ~protocolDefender(); virtual bool init(){ return true; }; - bool Alarm2D( int Angle, int Range, int Width, int ID=0 ); - bool Alarm3D( int Angle1, int Angle2, int Range, int ID=0 ); + bool Alarm2D( float Angle, float Range, float Width, int ID=0 ); + bool Alarm3D( float Angle1, float Angle2, float Range, int ID=0 ); bool VisibilityChanged( bool Worsened ); bool StatusUpdate( void ); void SetStatus( bool A ){ m_bCurrentStatus = A; }; @@ -117,6 +132,7 @@ public: bool SetupCallBack( CSTR CallBackPath ); void setProtocolType( bool DeviceIs3D ); void setScannerName( CSTR Name ); + void setScannerPosition( float Lat, float Lon ){ m_fLon = Lon; m_fLat = Lat; }; }; #ifdef __linux__ diff --git a/lib/data/transport/transportSerial.cpp b/lib/data/transport/transportSerial.cpp index 18393723..1ee24849 100644 --- a/lib/data/transport/transportSerial.cpp +++ b/lib/data/transport/transportSerial.cpp @@ -1,9 +1,10 @@ #include "transportSerial.h" -#define LOG( X ) basicTransport::m_pLog->Log( "TransportSerial", this, X ) -#define LOG_ERROR( X ) basicTransport::m_pLog->Log( "TransportSerial", this, _LOG_ERROR, X ) +#define LOG( X ) m_pLog->Log( "TransportSerial", this, X ) +#define LOG_ERROR( X ) m_pLog->Log( "TransportSerial", this, _LOG_ERROR, X ) transportSerial::transportSerial() :basicTransport(), basicDualThread(){ + m_pLog = basicLogCollection::getInstance(); m_nInputBufferSize = -1; m_nOutputBufferSize = -1; m_pInputBuffer = ( U8 * ) malloc ( MAXIMAL_SERIAL_PACKET_LENGTH ); diff --git a/lib/hardware/can/canbus.cpp b/lib/hardware/can/canbus.cpp index 2ca51091..421e0c50 100644 --- a/lib/hardware/can/canbus.cpp +++ b/lib/hardware/can/canbus.cpp @@ -45,9 +45,13 @@ canBus::canBus(CSTR Device, int NodeID, int FilterID=0 ):transportSerial(){ }; m_bInitComplete = HW_init(); if( m_bInitComplete ) { +#ifdef DEBUG char MsgBuffer[CLOG]; - sprintf( MsgBuffer,"Init %s [%d] OK", m_sDevice, m_iNodeID ); + sprintf( MsgBuffer,"Init %s [0x%X] OK", m_sDevice, m_iNodeID ); LOG( MsgBuffer ); + LOG("Starting"); +#endif + init(); }; }; diff --git a/lib/hardware/soc/classSOC.cpp b/lib/hardware/soc/classSOC.cpp index 91684c2a..0104044e 100644 --- a/lib/hardware/soc/classSOC.cpp +++ b/lib/hardware/soc/classSOC.cpp @@ -110,7 +110,6 @@ inline classSOC::classSOC(){ m_bTH_OK = false; m_pLog = basicLogCollection::getInstance(); - LOG("Press F1 to exit"); long pageSize; pageSize = sysconf( _SC_PAGE_SIZE ); sprintf( Buffer, "System Page Size: %ld %X",pageSize ); @@ -1397,235 +1396,368 @@ bool classSOC::enable_SYSTEM_BUSSES( void ){ volatile uint32_t* CREG = NULL; uint32_t CC; if( m_bPRMCM_OK ) { - LOG("enable L3 module clock"); +#ifdef DEBUG + LOG("Enable L3 module clock"); +#endif enable_module (CM_PER_REGS(L3_CLKCTRL)); - LOG("1"); +#ifdef DEBUG + LOG("Done"); + LOG("Enable L3 instruction clock"); +#endif enable_module (CM_PER_REGS(L3_INSTR_CLKCTRL)); - LOG("2"); +#ifdef DEBUG + LOG("Done"); + LOG("Wake Up L3_CLKSTCTRL"); +#endif wkup_module (CM_PER_REGS(L3_CLKSTCTRL)); - LOG("3"); +#ifdef DEBUG + LOG("Done"); + LOG("Wake Up OCPWP_L3_CLKSTCTRL"); +#endif wkup_module (CM_PER_REGS(OCPWP_L3_CLKSTCTRL)); - LOG("4"); +#ifdef DEBUG + LOG("Done"); + LOG("Wake Up L3S_CLKSTCTRL"); +#endif wkup_module (CM_PER_REGS(L3S_CLKSTCTRL)); - LOG("5"); - LOG("wait until modules are active"); +#ifdef DEBUG + LOG("Done"); + LOG("Wait until modules are active"); +#endif wait4bit (CM_PER_REGS(L3_CLKSTCTRL), L3_CLKSTCTRL_CLKACTIVITY_L3_GCLK); - LOG("6"); +#ifdef DEBUG + LOG("Done"); LOG("GAC wait4bit (CM_PER_REGS(OCPWP_L3_CLKSTCTRL), OCPWP_L3_CLKSTCTRL_CLKACTIVITY_OCPWP_L3_GCLK)"); +#endif wait4bit (CM_PER_REGS(L3S_CLKSTCTRL), L3S_CLKSTCTRL_CLKACTIVITY_L3S_GCLK); - LOG("7"); - LOG( "wake-up regions" ); +#ifdef DEBUG + LOG("Done"); + LOG( "Wake-up CLK CTRL Regions" ); +#endif enable_module (CM_WKUP_REGS(CTRL_CLKCTRL)); - LOG("8"); +#ifdef DEBUG + LOG("Done"); + LOG("Wake-up CLKST CTRL Regions"); +#endif wkup_module (CM_WKUP_REGS(WKUP_CLKSTCTRL)); - LOG("9"); +#ifdef DEBUG + LOG("Done"); + LOG("Wake-up L3 AON CLKST CTRL Regions"); +#endif wkup_module (CM_WKUP_REGS(L3_AON_CLKSTCTRL)); - LOG("10"); - LOG("wait until region are waked-up"); +#ifdef DEBUG + LOG("Done"); + LOG("Wait until region are waked-up"); +#endif wait4bit (CM_WKUP_REGS(L3_AON_CLKSTCTRL), L3_AON_CLKSTCTRL_CLKACTIVITY_L3_AON_GCLK); - LOG("11"); +#ifdef DEBUG + LOG("Done"); + LOG("Wake-up L4 CLK CTRL Regions"); +#endif wait4mode (CM_WKUP_REGS(WKUP_L4WKUP_CLKCTRL)); - LOG("12"); +#ifdef DEBUG + LOG("Done"); + LOG("Wait until region are waked-up"); +#endif wait4bit (CM_WKUP_REGS(WKUP_CLKSTCTRL), WKUP_CLKSTCTRL_CLKACTIVITY_L4_WKUP_GCLK); - LOG("13"); +#ifdef DEBUG + LOG("Done"); + LOG("Wait some more until region are waked-up"); +#endif wait4bit (CM_WKUP_REGS(L4_WKUP_AON_CLKSTCTRL), L4_WKUP_AON_CLKSTCTRL_CLKACTIVITY_L4_WKUP_AON_GCLK); - LOG("14"); +#ifdef DEBUG + LOG("Done"); +#endif //am335x_clock_enable_l3_l4wkup(); CREG = ( volatile uint32_t * ) PM_PER_REGS(PER_PWRSTCTRL); CC = *CREG; +#ifdef DEBUG sprintf( Buffer, "Power Status PER_PWRSTCTRL: \t0x%08X", CC ); LOG( Buffer ); +#endif CREG = ( volatile uint32_t * ) PM_PER_REGS(PER_PWRSTST); CC = *CREG; +#ifdef DEBUG sprintf( Buffer, "Power Status PER_PWRSTST: \t0x%08X", CC ); LOG(Buffer); - +#endif CREG = ( volatile uint32_t * ) PM_PER_REGS(PER_RSTCTRL); CC = *CREG; +#ifdef DEBUG sprintf( Buffer, "Power Status PER_RSTCTRL: \t0x%08X", CC ); LOG( Buffer ); - +#endif if( CC > 1 ) *CREG = 0; CC = *CREG; +#ifdef DEBUG sprintf( Buffer, "Power Status PER_RSTCTRL: \t0x%08X", CC ); LOG( Buffer ); - +#endif CREG = ( volatile uint32_t * ) CM_MPU_REGS(MPU_CLKCTRL); CC = *CREG; +#ifdef DEBUG sprintf( Buffer, "MPU Status MPU_CLKCTRL: \t\t0x%08X", CC ); LOG( Buffer ); - +#endif CREG = ( volatile uint32_t * ) CM_MPU_REGS(MPU_CLKSTCTRL); CC = *CREG; +#ifdef DEBUG sprintf( Buffer, "MPU Status MPU_CLKSTCTRL: \t0x%08X", CC ); LOG( Buffer ); - +#endif CREG = ( volatile uint32_t * ) CM_DPLL_REGS(CLKSEL_PRU_ICSS_OCP_CLK); CC = *CREG; +#ifdef DEBUG sprintf( Buffer, "DPLL Status CLKSEL_PRU_ICSS_OCP_CLK: \t0x%08X", CC ); LOG( Buffer ); +#endif *CREG = 1; CREG = ( volatile uint32_t * ) CM_PER_REGS(L4HS_CLKCTRL); CC = *CREG; +#ifdef DEBUG sprintf( Buffer, "PER Status L4HS_CLKCTRL: \t0x%08X", CC ); - LOG( Buffer ); - + LOG( Buffer ); LOG("Checking L3S_CLKSTCTRL Module"); +#endif CREG = ( volatile uint32_t * ) CM_PER_REGS( L3_INSTR_CLKCTRL ); CC = *CREG; - if( (CC & CLOCK_MASK) != ST_CLK_MODE_SW_WAKEUP ){ + if( (CC & CLOCK_MASK) != ST_CLK_MODE_SW_WAKEUP ){ +#ifdef DEBUG LOG("Wakeing Up Module"); +#endif *CREG = CC | SE_CLK_MODE_SW_WAKEUP; while( (*CREG & CLOCK_MASK) != ST_CLK_MODE_SW_WAKEUP ); +#ifdef DEBUG LOG("Done"); +#endif } else { +#ifdef DEBUG sprintf( Buffer, "\t%08X OK", CC); LOG( Buffer ); +#endif }; - +#ifdef DEBUG LOG("Checking L3_CLKCTRL Module"); +#endif CREG = ( volatile uint32_t * ) CM_PER_REGS( L3_CLKCTRL ); CC = *CREG; if( (CC & IDLEST_MASK) != 0 || (CC & MODULE_MASK) != ST_MODULE_ENABLED ){ if( (CC & MODULE_MASK) != ST_MODULE_ENABLED ){ +#ifdef DEBUG LOG("Module is disabled"); +#endif *CREG = CC | SE_MODULE_ENABLED; +#ifdef DEBUG LOG("Enabling Module"); +#endif }; CREG = ( uint32_t * ) CM_PER_REGS( L3_CLKSTCTRL ); CC = *CREG; +#ifdef DEBUG LOG("Wakeing Up Module"); +#endif *CREG = CC | SE_CLK_MODE_SW_WAKEUP; CREG = ( volatile uint32_t * ) CM_PER_REGS( L3_CLKCTRL ); while( (*CREG & IDLEST_MASK) != 0 ); +#ifdef DEBUG LOG("Done"); +#endif } else { +#ifdef DEBUG sprintf( Buffer,"\t%08X OK", CC); LOG( Buffer ); +#endif }; - +#ifdef DEBUG LOG("Checking L3_INSTR_CLKCTRL Module"); +#endif CREG = ( volatile uint32_t * ) CM_PER_REGS( L3_INSTR_CLKCTRL ); CC = *CREG; if( (CC & IDLEST_MASK) != 0 || (CC & MODULE_MASK) != ST_MODULE_ENABLED ){ if( (CC & MODULE_MASK) != ST_MODULE_ENABLED ){ +#ifdef DEBUG LOG("Module is disabled"); +#endif *CREG = CC | SE_MODULE_ENABLED; +#ifdef DEBUG LOG("Enabling Module"); +#endif }; while( (*CREG & IDLEST_MASK) != 0 ); +#ifdef DEBUG LOG("Done"); +#endif } else { +#ifdef DEBUG sprintf( Buffer,"\t%08X OK", CC); LOG( Buffer ); +#endif }; - +#ifdef DEBUG LOG("Checking L4HS_CLKCTRL Module"); +#endif CREG = ( volatile uint32_t * ) CM_PER_REGS( L4HS_CLKCTRL ); CC = *CREG; if( ( CC & MODULE_MASK ) != ST_MODULE_ENABLED ){ if( (CC & MODULE_MASK) != ST_MODULE_ENABLED ){ +#ifdef DEBUG LOG("Module is disabled"); +#endif *CREG = CC | SE_MODULE_ENABLED; +#ifdef DEBUG LOG("Enabling Module"); +#endif }; while( (*CREG & IDLEST_MASK) != 0 ); +#ifdef DEBUG sprintf( Buffer,"Done %08X", *CREG); LOG( Buffer ); +#endif } else { +#ifdef DEBUG sprintf( Buffer,"\t%08X OK", CC); LOG( Buffer ); +#endif }; - +#ifdef DEBUG LOG("Checking L3S_CLKSTCTRL Module"); +#endif CREG = ( volatile uint32_t * ) CM_PER_REGS( L3S_CLKSTCTRL ); CC = *CREG; if( ( CC & MODULE_MASK ) != ST_MODULE_ENABLED ){ if( (CC & MODULE_MASK) != ST_MODULE_ENABLED ){ +#ifdef DEBUG LOG("Module is disabled"); +#endif *CREG = CC | SE_MODULE_ENABLED; +#ifdef DEBUG LOG("Enabling Module"); +#endif }; while( (*CREG & IDLEST_MASK) != 0 ); +#ifdef DEBUG sprintf( Buffer,"Done %08X", *CREG); LOG( Buffer ); +#endif } else { +#ifdef DEBUG sprintf( Buffer,"\t%08X OK", CC); LOG( Buffer ); +#endif }; - +#ifdef DEBUG LOG("Checking GPMC_CLKCTRL Module"); +#endif CREG = ( volatile uint32_t * ) CM_PER_REGS( GPMC_CLKCTRL ); CC = *CREG; if( ( CC & MODULE_MASK ) != ST_MODULE_ENABLED ){ if( (CC & MODULE_MASK) != ST_MODULE_ENABLED ){ +#ifdef DEBUG LOG("Module is disabled"); +#endif *CREG = CC | SE_MODULE_ENABLED; +#ifdef DEBUG LOG("Enabling Module"); +#endif }; while( (*CREG & IDLEST_MASK) != 0 ); +#ifdef DEBUG sprintf( Buffer,"Done %08X", *CREG); LOG( Buffer ); +#endif } else { +#ifdef DEBUG sprintf( Buffer,"\t%08X OK", CC); LOG( Buffer ); +#endif }; - +#ifdef DEBUG LOG("Checking L4LS_CLKCTRL Module"); +#endif CREG = ( volatile uint32_t * ) CM_PER_REGS( L4LS_CLKCTRL ); CC = *CREG; if( (CC & IDLEST_MASK) != 0 || (CC & MODULE_MASK) != ST_MODULE_ENABLED ) { if( (CC & MODULE_MASK) != ST_MODULE_ENABLED ){ +#ifdef DEBUG LOG("Module is disabled"); +#endif *CREG = CC | SE_MODULE_ENABLED; +#ifdef DEBUG LOG("Enabling Module"); +#endif }; CREG = ( volatile uint32_t * ) CM_PER_REGS( L4LS_CLKSTCTRL ); CC = *CREG; +#ifdef DEBUG LOG("Wakeing Up Module"); +#endif *CREG = CC | SE_CLK_MODE_SW_WAKEUP; CREG = ( volatile uint32_t * ) CM_PER_REGS( L4LS_CLKCTRL ); while( (*CREG & IDLEST_MASK) != 0 ); +#ifdef DEBUG LOG("Done"); +#endif } else { +#ifdef DEBUG sprintf( Buffer, "\t%08X OK", CC); LOG( Buffer ); +#endif }; - +#ifdef DEBUG LOG("Checking OCPWP_L3_CLKSTCTRL Module"); +#endif CREG = ( volatile uint32_t * ) CM_PER_REGS( OCPWP_L3_CLKSTCTRL ); CC = *CREG; if( (CC & CLOCK_MASK) != ST_CLK_MODE_SW_WAKEUP ){ +#ifdef DEBUG LOG("Module is disabled"); +#endif *CREG = CC | SE_CLK_MODE_SW_WAKEUP; +#ifdef DEBUG LOG("Enabling Module"); +#endif while( (*CREG & CLOCK_MASK) != ST_CLK_MODE_SW_WAKEUP ); +#ifdef DEBUG LOG("Done"); +#endif } else { +#ifdef DEBUG sprintf( Buffer,"\t%08X OK", CC); LOG( Buffer ); +#endif }; - +#ifdef DEBUG LOG("Checking OCPWP_CLKCTRL Module"); +#endif CREG = ( volatile uint32_t * ) CM_PER_REGS( OCPWP_CLKCTRL ); CC = *CREG; if( (CC & IDLEST_MASK) != 0 || (CC & MODULE_MASK) != ST_MODULE_ENABLED ){ if( (CC & MODULE_MASK) != ST_MODULE_ENABLED ){ +#ifdef DEBUG LOG("Module is disabled"); +#endif *CREG = CC | SE_MODULE_ENABLED; +#ifdef DEBUG LOG("Enabling Module"); +#endif }; CREG = ( volatile uint32_t * ) CM_PER_REGS( OCPWP_L3_CLKSTCTRL ); CC = *CREG; +#ifdef DEBUG LOG("Wakeing Up Module"); +#endif *CREG = CC | SE_CLK_MODE_SW_WAKEUP; CREG = ( volatile uint32_t * ) CM_PER_REGS( OCPWP_CLKCTRL ); while( ( *CREG & IDLEST_MASK ) != 0 ); +#ifdef DEBUG LOG("Done"); +#endif } else { +#ifdef DEBUG sprintf( Buffer,"\t%08X OK", CC); LOG( Buffer ); +#endif }; return true; }; @@ -2219,6 +2351,15 @@ uint32_t *classSOC::getEVT_MEMORY( void ){ return (uint32_t *)m_pEVT_ZONE_MMAP; }; +uint32_t classSOC::getMirrorPRF( void ){ + uint32_t RetVal = 0; + return RetVal; +}; + +uint32_t classSOC::getBasePRF( void ){ + uint32_t RetVal = 0; + return RetVal; +}; bool classSOC::access_ADC_MODULE( uint32_t MODID ){ char Buffer[256]; diff --git a/lib/hardware/soc/classSOC.h b/lib/hardware/soc/classSOC.h index 9ccf8f80..2bb06276 100644 --- a/lib/hardware/soc/classSOC.h +++ b/lib/hardware/soc/classSOC.h @@ -164,6 +164,8 @@ class classSOC { uint32_t getPRU_TYPE( uint8_t coreID ); bool resetThDetector( bool FullReset ); + uint32_t getMirrorPRF( void ); + uint32_t getBasePRF( void ); /* SOC-OS Specific */ diff --git a/lib/hardware/soc/general/3DLRF.h b/lib/hardware/soc/general/3DLRF.h index 82200c1a..032e7732 100644 --- a/lib/hardware/soc/general/3DLRF.h +++ b/lib/hardware/soc/general/3DLRF.h @@ -81,7 +81,7 @@ extern SOFTWARE_INFO gsSOFT_INFO; #define MINIMAL_DISTANCE_ADC 400 //~30 meters //#define NO_MOTORS -#define PRU_SLAVE +//#define PRU_SLAVE #ifndef ENCODER_8192 #define ENCODER_7200 @@ -527,7 +527,7 @@ enum { #define TH_2ZONES_SIZE_BYTES 0x1440000 */ -#define TH_PER_MIRROR +//#define TH_PER_MIRROR #define TH_FULL_PER_LRF #ifndef TH_FULL_PER_LRF @@ -615,7 +615,7 @@ enum { #ifndef am4378 inline void make3Drad(uint32_t sid, float &az, float &el, bool master = true ){ - if(1){ //(master){ + if( master ){ el = (float)(sid / TH_LINE_NODES) * (Q_RADIAN_FOV / Q_SCAN_COUNT) - Q_RADIAN_SHIFT_DOWN_FOV; } else { el = (Q_SCAN_COUNT - (float)(sid / TH_LINE_NODES)) * (Q_RADIAN_FOV / Q_BLOCK_COUNT) - Q_RADIAN_SHIFT_DOWN_FOV; @@ -624,16 +624,21 @@ enum { }; inline void make3Ddeg(uint32_t sid, float &az, float &el, bool master = true ){ - if (1){//master){ - el = (float)(sid / TH_LINE_NODES) * (Q_DEGREE_FOV / Q_SCAN_COUNT) - Q_SHIFT_DOWN_FOV; + az = ((float)(TH_LINE_NODES - (sid % TH_LINE_NODES))) * (B_DEGREE_FOV / (float)M_SCAN_POINTS); + if ( master ){ + el = 90.0 - (float)(sid / TH_LINE_NODES) * (Q_DEGREE_FOV / Q_SCAN_COUNT) - Q_SHIFT_DOWN_FOV; } else { - el = (Q_SCAN_COUNT - (float)(sid / TH_LINE_NODES)) * (Q_DEGREE_FOV / Q_BLOCK_COUNT) - Q_SHIFT_DOWN_FOV; + el = 90.0 - (Q_SCAN_COUNT - (float)(sid / TH_LINE_NODES)) * (Q_DEGREE_FOV / Q_BLOCK_COUNT) - Q_SHIFT_DOWN_FOV; }; - az = ((float)(TH_LINE_NODES - (sid % TH_LINE_NODES))) * (B_DEGREE_FOV / (float)M_SCAN_POINTS); + if( el < 0 ) { + el *= -1.0; + az = az + 180.0; + if( az > 360.0 ) az = az - 360.0; + }; }; inline void make3Dmildeg(uint32_t sid, float &az, float &el, bool master = true ){ - if(1){// master ){ + if( master ){ el = 1000.f * ( ((float)Q_DEGREE_FOV) - (float)(sid / TH_LINE_NODES) * (Q_DEGREE_FOV / Q_SCAN_COUNT) - Q_SHIFT_DOWN_FOV ); } else { el = 1000.f * ( ((float)Q_DEGREE_FOV) - (Q_SCAN_COUNT - (float)(sid / TH_LINE_NODES)) * (Q_DEGREE_FOV / Q_BLOCK_COUNT) - Q_SHIFT_DOWN_FOV ); diff --git a/lib/hardware/uart/serialPort.cpp b/lib/hardware/uart/serialPort.cpp index 2e308890..b69716ca 100644 --- a/lib/hardware/uart/serialPort.cpp +++ b/lib/hardware/uart/serialPort.cpp @@ -59,7 +59,7 @@ serialPort::~serialPort(){ if (result == 0) { #endif char MsgBuffer[CLOG]; - sprintf( MsgBuffer, "Error %d closing [%s]: %s", errno, m_sDevicePath, strerror (errno) ); + sprintf( MsgBuffer, "Error %d closing input [%s]: %s", errno, m_sDevicePath, strerror (errno) ); LOG_ERROR( MsgBuffer ); }; }; @@ -199,14 +199,14 @@ bool serialPort::HW_init( CSTR DevicePath, int Speed ){ PortDCB.DCBlength = sizeof(DCB); COMMTIMEOUTS CommTimeouts; m_ioFID = CreateFile(m_sDevicePath, // Name of the port - FILE_GENERIC_READ | GENERIC_WRITE, // Access (read-write) mode + GENERIC_WRITE | GENERIC_READ, // Access (read-write) mode 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (m_ioFID == INVALID_HANDLE_VALUE){ - sprintf(MsgBuffer, "Port [%s] Out Open Failed", m_sDevicePath); + sprintf(MsgBuffer, "Port [%s] Open Failed", m_sDevicePath); LOG_ERROR(MsgBuffer); return false; }; @@ -226,10 +226,10 @@ bool serialPort::HW_init( CSTR DevicePath, int Speed ){ PortDCB.StopBits = ONESTOPBIT; // Retrieve the time-out parameters for all read and write operations - GetCommTimeouts(m_ioFID, &CommTimeouts); - CommTimeouts.ReadIntervalTimeout = 0; - CommTimeouts.ReadTotalTimeoutMultiplier = 0; - CommTimeouts.ReadTotalTimeoutConstant = 10; + GetCommTimeouts(m_ioFID, &CommTimeouts); + CommTimeouts.ReadIntervalTimeout = 20; + CommTimeouts.ReadTotalTimeoutMultiplier = 10; + CommTimeouts.ReadTotalTimeoutConstant = 100; CommTimeouts.WriteTotalTimeoutMultiplier = 10; CommTimeouts.WriteTotalTimeoutConstant = 100; @@ -262,7 +262,12 @@ bool serialPort::HW_init( CSTR DevicePath, int Speed ){ int serialPort::sendBlock( unsigned char *Data, int DataSize ){ - if(!m_bInitComplete) return -1; + if(!m_bInitComplete) { +#ifdef DEBUG + LOG( "Port is not Ready to Send" ); +#endif + return -1; + }; #ifdef __linux__ int RetVal; do{ @@ -277,15 +282,16 @@ int serialPort::sendBlock( unsigned char *Data, int DataSize ){ // RetVal = 0; // }; #endif - -#ifdef _DEBUG_SERIAL_COMMUNICATION_ +#ifdef DEBUG char MsgBuffer[CLOG]; sprintf( MsgBuffer, "Sent %d byte(s) of %d", RetVal, DataSize ); LOG( MsgBuffer ); - for( int i = 0; i < DataSize; i++ ){ - sprintf( MsgBuffer, "0x%02X", Data[i] ); - LOG( MsgBuffer ); - }; + #ifdef _DEBUG_SERIAL_COMMUNICATION_ + for( int i = 0; i < DataSize; i++ ){ + sprintf( MsgBuffer, "0x%02X", Data[i] ); + LOG( MsgBuffer ); + }; + #endif #endif return RetVal; //*/ @@ -328,7 +334,12 @@ int serialPort::sendBlock( unsigned char *Data, int DataSize ){ }; int serialPort::recptBlock( unsigned char *Buffer, int *BufferLength ){ - if( !m_bInitComplete ) return 0; + if( !m_bInitComplete ) { +#ifdef DEBUG + LOG("Port is Not Ready to Read" ); +#endif + return 0; + } /* int n_read = read( m_iInFID, Buffer, sizeof(Buffer) ); @@ -357,27 +368,50 @@ int serialPort::recptBlock( unsigned char *Buffer, int *BufferLength ){ usleep(100); } while (RetVal == -1 && errno == EINTR); #else - DWORD RetVal; - //OVERLAPPED ov; - if (!ReadFile(m_ioFID, Buffer, MAXIMAL_SERIAL_PACKET_LENGTH, &RetVal, NULL)){ - *BufferLength = 0; - return -1; - }; -#endif + DWORD RetVal; + OVERLAPPED osReader; + if (!ReadFile(m_ioFID, Buffer, MAXIMAL_SERIAL_PACKET_LENGTH, &RetVal, &osReader)) { + if (GetLastError() != ERROR_IO_PENDING){ // read not delayed? + // Error in communications; report it. + return RetVal; + }else{ + //fWaitingOnRead = TRUE; + }; + } else { + // read completed immediately + } +#endif #ifdef _DEBUG_SERIAL_COMMUNICATION_ - if (RetVal > 0){ - char MsgBuffer[256]; - if( RetVal > 1 ) { - sprintf(MsgBuffer, "Received %d bytes", RetVal); + if( RetVal > -1 ){ + char MsgBuffer[CLOG]; + if( RetVal > 1 || RetVal == 0 ) { + sprintf( MsgBuffer, "Received %d bytes", RetVal ); } else { - sprintf(MsgBuffer, "Received 1 byte"); + sprintf( MsgBuffer, "Received 1 byte"); }; - LOG(MsgBuffer); + LOG( MsgBuffer ); }; #endif - *BufferLength = RetVal; - return (int) RetVal; + + if( RetVal > 0) { + *BufferLength = RetVal; + return RetVal; + }; + + *BufferLength = 0; + + if( RetVal == -1) return 0; + + if( RetVal == 0 ){ + errno = 0; + return 0; + }; + + /* r < -1, should never happen. */ + errno = EIO; + + return 0; }; #undef LOG diff --git a/put_to_git b/put_to_git index 20767913..8227865a 100755 --- a/put_to_git +++ b/put_to_git @@ -1,4 +1,4 @@ #!/bin/bash #git commit -a -m '$1' -git commit -a -m 'LRF_Kernel to make Flip with 32 TH zones' +git commit -a -m '3D Server - Corrected CAN Bus object to start communication thread'