diff options
author | philippe colliot <philippe.colliot@mpsa.com> | 2014-04-29 17:51:01 +0200 |
---|---|---|
committer | philippe colliot <philippe.colliot@mpsa.com> | 2014-04-29 17:51:01 +0200 |
commit | a71bd06789c11c848d7c2f415c5a7ac2fa8e2331 (patch) | |
tree | c13614912d0b838170c927f8445eb178c5810f4c | |
parent | 183d134e734e157c498f6cff367d104e4c5ad670 (diff) | |
download | positioning-log-replayer-extension.tar.gz |
extend to FSA data, add a silent feature, add .gitignorelog-replayer-extension
-rw-r--r-- | .gitignore | 3 | ||||
-rwxr-xr-x | build-all.sh | 5 | ||||
-rw-r--r-- | log-replayer/CMakeLists.txt | 3 | ||||
-rw-r--r-- | log-replayer/src/CMakeLists.txt | 6 | ||||
-rw-r--r-- | log-replayer/src/log-replayer.c | 122 | ||||
-rw-r--r-- | log-replayer/src/log.h | 20 |
6 files changed, 111 insertions, 48 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c05fab7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ +*~ +*.user diff --git a/build-all.sh b/build-all.sh index b007fa1..f3efff6 100755 --- a/build-all.sh +++ b/build-all.sh @@ -14,6 +14,9 @@ # Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with # this file, You can obtain one at http://mozilla.org/MPL/2.0/. # +# List of changes: +# +# 29-04-2014, Philippe Colliot, add a -DWITH_MESSAGES option to the logreplayer # @licence end@ ########################################################################### @@ -24,7 +27,7 @@ GNSS_SERVICE_FLAGS='-DWITH_DLT=OFF -DWITH_GPSD=OFF -DWITH_REPLAYER=ON -DWITH_TESTS=ON' SENSORS_SERVICE_FLAGS='-DWITH_DLT=OFF -DWITH_REPLAYER=ON -DWITH_IPHONE=OFF -DWITH_TESTS=ON' ENHANCED_POSITION_SERVICE_FLAGS='-DWITH_DLT=OFF -DWITH_GPSD=OFF -DWITH_REPLAYER=ON -DWITH_TESTS=ON' -LOG_REPLAYER_FLAGS='-DWITH_DLT=OFF -DWITH_TESTS=ON' +LOG_REPLAYER_FLAGS='-DWITH_DLT=OFF -DWITH_TESTS=ON -DWITH_MESSAGES=OFF' #-------------------------------------------------------------------------- TOP_SRC_DIR=$PWD diff --git a/log-replayer/CMakeLists.txt b/log-replayer/CMakeLists.txt index f13e1ec..d29df32 100644 --- a/log-replayer/CMakeLists.txt +++ b/log-replayer/CMakeLists.txt @@ -24,6 +24,9 @@ option(WITH_DLT option(WITH_TESTS "Compile test applications" OFF) + +option(WITH_MESSAGES + "Enable the build to print messages" OFF) message(STATUS) message(STATUS "---------------------------------------------------------") diff --git a/log-replayer/src/CMakeLists.txt b/log-replayer/src/CMakeLists.txt index 7ba2aaf..3c8d55d 100644 --- a/log-replayer/src/CMakeLists.txt +++ b/log-replayer/src/CMakeLists.txt @@ -19,6 +19,8 @@ message(STATUS "LOG-REPLAYER") message(STATUS "WITH_DLT = ${WITH_DLT}") message(STATUS "WITH_TESTS = ${WITH_TESTS}") +message(STATUS "WITH_MESSAGES = ${WITH_MESSAGES}") + find_package(PkgConfig) @@ -34,6 +36,10 @@ if(WITH_DLT) set(LIBRARIES ${LIBRARIES} ${DLT_LIBRARIES}) endif() +if(WITH_MESSAGES) + add_definitions("-DMESSAGES=1") +endif() + add_executable(log-replayer ${LIB_SRCS}) target_link_libraries(log-replayer ${LIBRARIES}) diff --git a/log-replayer/src/log-replayer.c b/log-replayer/src/log-replayer.c index bf24c60..d8f61c4 100644 --- a/log-replayer/src/log-replayer.c +++ b/log-replayer/src/log-replayer.c @@ -13,6 +13,11 @@ * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * +* Update (2014/01/14) : Fabien Hernandez <fabien.hernandez@mpsa.com>, +* - add vehicle data +* - loops exit conditions improvment +* - add comments +* * @licence end@ **************************************************************************/ @@ -32,48 +37,47 @@ #define BUFLEN 256 #define PORT1 9930 //port used for GNSS data #define PORT2 9931 //port used for sensor data +#define PORT3 9932 //port used for vehicle data #define IPADDR "127.0.0.1" DLT_DECLARE_CONTEXT(gContext); +// process a line from the log file bool getStrToSend(FILE* file, char* line, int dim) { static long unsigned int lastTimestamp = 0; long unsigned int timestamp = 0; long unsigned int delta = 0; + // exit if the size of the line buffer is null or negative if(dim <= 0) { LOG_ERROR_MSG(gContext,"dim <= 0"); return false; } + // extract the line from the file and insert newline caracter at buffer end char* ptrStr = fgets(line, dim, file); - line[dim -1] = '\0'; - //LOG_DEBUG(gContext, "read line %s", line); + LOG_DEBUG(gContext, "read line %s", line); - //TODO handle comments in log file - - if(ptrStr == NULL || feof(file)) + // test if a line has been read + if(ptrStr == NULL) { - //error or end of file return false; } + //skip comment line - no impact on delta times if(strchr(line, '#') != 0) - { - line[0] = '\0'; - return true; //skip comment line + { + return true; } - if (!sscanf(line, "%lu", ×tamp)) - { - line[0] = '\0'; - return true; //skip lines without timestamp - } + // read the timestamp + sscanf(line, "%lu", ×tamp); + // process the delta time between two messages if(!lastTimestamp) { delta = 0; @@ -87,7 +91,8 @@ bool getStrToSend(FILE* file, char* line, int dim) LOG_DEBUG(gContext,"Waiting %lu ms", delta); LOG_DEBUG_MSG(gContext,"------------------------------------------------"); - if(timestamp >= lastTimestamp) + // check if delta is valid and wait this time before next step + if(delta >= 0) { usleep(delta*1000); // TODO time drift issues } @@ -117,8 +122,6 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; } - filename = argv[1]; - DLT_REGISTER_APP("RPLY", "LOG-REPLAYER"); DLT_REGISTER_CONTEXT(gContext,"RSRV", "Global Context"); @@ -126,56 +129,54 @@ int main(int argc, char* argv[]) LOG_INFO_MSG(gContext,"LOG REPLAYER STARTED"); LOG_INFO_MSG(gContext,"------------------------------------------------"); + // socket initialization if((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { LOG_ERROR_MSG(gContext,"socket() failed!"); return EXIT_FAILURE; } - memset((char *) &si_other, 0, sizeof(si_other)); si_other.sin_family = AF_INET; - //si_other.sin_port = htons(<port number>); - if(inet_aton(IPADDR, &si_other.sin_addr) == 0) + + if(inet_aton(IPADDR, &si_other.sin_addr) == 0) { LOG_ERROR_MSG(gContext,"inet_aton() failded!"); return EXIT_FAILURE; } + // open the log file (name passed as a parameter to the main fonction) + filename = argv[1]; logfile = fopen(filename, "r"); - - if(logfile == NULL) + + if(logfile == NULL) { LOG_ERROR(gContext,"error trying to open file %s",filename); return EXIT_FAILURE; } - LOG_INFO(gContext,"Started reading log file %s",filename); + LOG_INFO(gContext,"Start reading log file %s",filename); - while(1) + // loop until the end the file or error + while(getStrToSend(logfile,buf,BUFLEN) && !feof(logfile)) { - if(!getStrToSend(logfile,buf,BUFLEN)) - { - //error or end of file - return EXIT_FAILURE; - } - - if (strlen(buf) < 3) - { - //skip empty lines (includes comments) - continue; - } - + // extract the Message ID sscanf(buf, "%*[^'$']$%[^',']", msgId); - //GNSS: list of supported message IDs - char* gnssstr = "GVGNSP,GVGNSC,GVGNSAC,GVGNSSAT"; - if(strstr(gnssstr, msgId) != NULL) + LOG_INFO(gContext, "read line %s", buf); + + //GNSS: list of supported message IDs + char* gnssstr = "GVGNSVER,GVGNSP,GVGNSC,GVGNSSAC,GVGNSC3D,GVGNSSSAT," + "GVGNSSUTCT,GVGNSSUTCD"; + // Messages identifiers in the GNSS list are sent on PORT1 + // Comment lines are not treated + if(strstr(gnssstr, msgId) != NULL && buf[0] != '#') { LOG_DEBUG(gContext,"Sending Packet to %s:%d",IPADDR,PORT1); LOG_DEBUG(gContext,"MsgID:%s", msgId); LOG_DEBUG(gContext,"Len:%d", (int)strlen(buf)); LOG_DEBUG(gContext,"Data:%s", buf); + // set the socket port and send the message si_other.sin_port = htons(PORT1); if(sendto(s, buf, strlen(buf)+1, 0, (struct sockaddr *)&si_other, slen) == -1) { @@ -183,17 +184,22 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; } } - + //SNS: list of supported message IDs - //char* snsstr = "GVVEHSP,GVGYRO,GVGYROCONF,GVDRVDIR,GVODO,GVWHTK,GVWHTKCONF"; - char* snsstr = "GVSNSVEHSP,GVSNSGYRO,GVSNSWHTK"; //subset currently supported for new log format - if(strstr(snsstr, msgId) != NULL) + char* snsstr = "GVSNSVER,GVSNSACC,GVSNSACCCONF,GVSNSGYRO,GVSNSGYROCONF," + "GVSNSINCL,GVSNSODO,GVSNSREV,GVSNSSLIP,GVSTEER,GVSNSVEHCONF," + "GVSNSVEHSP,GVSNSVEHST,GVSNSWHTK,GVSNSWHTKCONF,GVSNSWHA,GVSNSWHS," + "GVSNSDRVDIR,"; + // Message identifiers in the SNS list are sent on PORT2 + // Comment lines are not treated + if(strstr(snsstr, msgId) != NULL && buf[0] != '#') { LOG_DEBUG(gContext,"Sending Packet to %s:%d",IPADDR,PORT2); LOG_DEBUG(gContext,"MsgID:%s", msgId); LOG_DEBUG(gContext,"Len:%d", (int)strlen(buf)); LOG_DEBUG(gContext,"Data:%s", buf); + // change the socket port and send the message si_other.sin_port = htons(PORT2); if(sendto(s, buf, strlen(buf)+1, 0, (struct sockaddr *)&si_other, slen) == -1) { @@ -201,11 +207,35 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; } } - } - close(s); + //VHL: list of supported message IDs + char* vhlstr = "GVVEHVER,GVVEHENGSPEED,GVVEHFUELLEVEL,GVVEHFUELCONS," + "GVVEHTOTALODO,GVVEHWHRDCONF,GVVEHFRTKWDCONF,GVVEHRRTKWDCONF," + "GVVEHFRWHBSCONF,GVVEHRRWHBSCONF"; + // Message identifiers in the VHL list are sent on PORT3 + // Comment lines are not treated + if(strstr(vhlstr, msgId) != NULL && buf[0] != '#') + { + LOG_DEBUG(gContext,"Sending Packet to %s:%d",IPADDR,PORT3); + LOG_DEBUG(gContext,"MsgID:%s", msgId); + LOG_DEBUG(gContext,"Len:%d", (int)strlen(buf)); + LOG_DEBUG(gContext,"Data:%s", buf); + + // change the socket port and send the message + si_other.sin_port = htons(PORT3); + if(sendto(s, buf, strlen(buf)+1, 0, (struct sockaddr *)&si_other, slen) == -1) + { + LOG_ERROR_MSG(gContext,"sendto() failed!"); + return EXIT_FAILURE; + } + } + } - return EXIT_SUCCESS; + // check why the loop exit to adjust return value + if(feof(logfile)) + return EXIT_SUCCESS; + else + return EXIT_FAILURE; } diff --git a/log-replayer/src/log.h b/log-replayer/src/log.h index a683b6f..024cf41 100644 --- a/log-replayer/src/log.h +++ b/log-replayer/src/log.h @@ -45,6 +45,22 @@ typedef const char* NoDltContext; #define DLT_UNREGISTER_APP() ; #define dlt_free() ; +#if (!MESSAGES) + +#define LOG_VERBOSE_MSG(context, msg) +#define LOG_VERBOSE(context, fmt, ...) +#define LOG_DEBUG_MSG(context, msg) +#define LOG_DEBUG(context, fmt, ...) +#define LOG_INFO_MSG(context, msg) +#define LOG_INFO(context, fmt, ...) +#define LOG_WARNING_MSG(context, msg) +#define LOG_WARNING(context, fmt, ...) +#define LOG_ERROR_MSG(context, msg) +#define LOG_ERROR(context, fmt, ...) +#define LOG_FATAL_MSG(context, msg) +#define LOG_FATAL(context, fmt, ...) + +#else /* with messages */ // log calls #define LOG_VERBOSE_MSG(context, msg) \ fprintf(stderr, "[VERBO][%4s] " msg "\n", context) @@ -53,9 +69,9 @@ typedef const char* NoDltContext; #define LOG_DEBUG_MSG(context, msg) \ fprintf(stderr, "[DEBUG][%4s] " msg "\n", context) + #define LOG_DEBUG(context, fmt, ...) \ fprintf(stderr, "[DEBUG][%4s] " fmt "\n", context, __VA_ARGS__) - #define LOG_INFO_MSG(context, msg) \ fprintf(stderr, "[INFO ][%4s] " msg "\n", context) #define LOG_INFO(context, fmt, ...) \ @@ -76,6 +92,8 @@ typedef const char* NoDltContext; #define LOG_FATAL(context, fmt, ...) \ fprintf(stderr, "[FATAL][%4s] " fmt "\n", context, __VA_ARGS__) +#endif /* MESSAGES */ + #else /* DLT_ENABLED */ /*****************************************************************************/ // use DLT |