From 5bee3876e1c7f506504b48ce264d49aea90aa94e Mon Sep 17 00:00:00 2001 From: James Coxon Date: Sat, 20 Mar 2010 18:19:16 +0000 Subject: [PATCH 1/4] set so --hab uses 100 for the size of the rxBox which means that it'll start the correct size --- src/misc/status.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/misc/status.cxx b/src/misc/status.cxx index 2396ff2f..ad5acca7 100644 --- a/src/misc/status.cxx +++ b/src/misc/status.cxx @@ -393,6 +393,8 @@ void status::initLastState() if (bWF_only) fl_digi_main->resize(mainX, mainY, mainW, Hmenu + Hwfall + Hstatus + 4); +else if (bHAB) + fl_digi_main->resize(mainX, mainY, mainW, Hmenu + Hwfall + 100 + Hstatus + 4); else { fl_digi_main->resize(mainX, mainY, mainW, mainH); if (!(RxTextHeight > 0 && RxTextHeight < TiledGroup->h())) From 32001f0ede4750dd0a8f550e597f31fb09fab1d2 Mon Sep 17 00:00:00 2001 From: James Coxon Date: Sat, 20 Mar 2010 18:35:13 +0000 Subject: [PATCH 2/4] split extra.h into dlpipe.h which contains the curl bits and extra for the little helpful functions such as uppercase. Have also added section to trx.cxx to start sending status data though is missing some variables - needs testing --- src/main.cxx | 5 +-- src/misc/dlpipe.h | 102 +++++++++++++++++++++++++++++++++++++++++++++ src/misc/extra.h | 103 ++++------------------------------------------ src/trx/trx.cxx | 79 +++++++++++++++++++++++++++++++++++ 4 files changed, 191 insertions(+), 98 deletions(-) create mode 100644 src/misc/dlpipe.h diff --git a/src/main.cxx b/src/main.cxx index 7a297a07..6a6c2561 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -113,10 +113,7 @@ using namespace std; //jcoxon include files -#include -#include -#include -#include "misc/extra.h" +#include "misc/dlpipe.h" // string appname; diff --git a/src/misc/dlpipe.h b/src/misc/dlpipe.h new file mode 100644 index 00000000..1cd2d197 --- /dev/null +++ b/src/misc/dlpipe.h @@ -0,0 +1,102 @@ +#ifndef _EXTRA_H_ +#define _EXTRA_H_ +#include +#include +#include +#include + +//-------------------------------------// +/* RJH Pipe vars */ +int rjh_pfds[2]; +pid_t rjh_cpid; + + // This is the writer call back function used by curl + static int writer(char *data, size_t size, size_t nmemb, std::string *buffer) + { + // What we will return + int result = 0; + + // Is there anything in the buffer? + if (buffer != NULL) + { + // Append the data to the buffer + buffer->append(data, size * nmemb); + + // How much did we write? + result = size * nmemb; + } + + return result; + } + +void serverCommunicator() +{ + if (pipe(rjh_pfds) == -1) { perror("pipe"); exit(EXIT_FAILURE); } + + rjh_cpid = fork(); + + if (rjh_cpid == -1) { perror("fork"); exit(EXIT_FAILURE); } + if (rjh_cpid == 0) { + + char c; + char buffer [2000]; + int charpos = 0; + + CURL *easyhandle_status; + CURLcode result; + + // ofstream fout; + + // fout.clear(); + // fout.open ("log.txt"); + // if (fout.fail()) { + // cout << "Failed to open log.txt\n"; + // } + + /* Close the write side of the pipe */ + close(rjh_pfds[1]); + + buffer[0] ='\0'; + + while (read(rjh_pfds[0], &c, 1) > 0) + { + buffer[charpos] = c; + if (charpos <1999) charpos ++; + + if (c == '\n') + { + + if (charpos > 0) + buffer[charpos-1] = '\0'; + else + buffer[0] = '\0'; + + charpos=0; + + printf(" CHILD: received \"%s\"\n", buffer); + + // fout << "Buffer string : '" << buffer << "'" << endl; + + if (strlen(buffer) > 0) + { + easyhandle_status = curl_easy_init(); + if(easyhandle_status) { + curl_easy_setopt(easyhandle_status, CURLOPT_POSTFIELDS, buffer); + curl_easy_setopt(easyhandle_status, CURLOPT_URL, "http://www.robertharrison.org/listen/listen.php"); + result = curl_easy_perform(easyhandle_status); /* post away! */ + cout << "result: " << result << "\n"; + curl_easy_cleanup(easyhandle_status); + } + } + buffer[0] = '\0'; + } + } + close(rjh_pfds[0]); + _exit (0); + } + + /* Close the read side of the pipe */ + close(rjh_pfds[0]); +} +//----------------------------------- +#endif \ No newline at end of file diff --git a/src/misc/extra.h b/src/misc/extra.h index 7e98e839..211fc9fd 100644 --- a/src/misc/extra.h +++ b/src/misc/extra.h @@ -1,100 +1,15 @@ #ifndef _EXTRA_H_ #define _EXTRA_H_ +#include -//void UpperCase(string& str); - -//-------------------------------------// -/* RJH Pipe vars */ -int rjh_pfds[2]; -pid_t rjh_cpid; - - // This is the writer call back function used by curl - static int writer(char *data, size_t size, size_t nmemb, std::string *buffer) - { - // What we will return - int result = 0; - - // Is there anything in the buffer? - if (buffer != NULL) - { - // Append the data to the buffer - buffer->append(data, size * nmemb); - - // How much did we write? - result = size * nmemb; - } - - return result; - } - -void serverCommunicator() +//jcoxon +void UpperCase(string& str) { - if (pipe(rjh_pfds) == -1) { perror("pipe"); exit(EXIT_FAILURE); } - - rjh_cpid = fork(); - - if (rjh_cpid == -1) { perror("fork"); exit(EXIT_FAILURE); } - if (rjh_cpid == 0) { - - char c; - char buffer [2000]; - int charpos = 0; - - CURL *easyhandle_status; - CURLcode result; - - // ofstream fout; - - // fout.clear(); - // fout.open ("log.txt"); - // if (fout.fail()) { - // cout << "Failed to open log.txt\n"; - // } - - /* Close the write side of the pipe */ - close(rjh_pfds[1]); - - buffer[0] ='\0'; - - while (read(rjh_pfds[0], &c, 1) > 0) - { - buffer[charpos] = c; - if (charpos <1999) charpos ++; - - if (c == '\n') - { - - if (charpos > 0) - buffer[charpos-1] = '\0'; - else - buffer[0] = '\0'; - - charpos=0; - - printf(" CHILD: received \"%s\"\n", buffer); - - // fout << "Buffer string : '" << buffer << "'" << endl; - - if (strlen(buffer) > 0) - { - easyhandle_status = curl_easy_init(); - if(easyhandle_status) { - curl_easy_setopt(easyhandle_status, CURLOPT_POSTFIELDS, buffer); - curl_easy_setopt(easyhandle_status, CURLOPT_URL, "http://www.robertharrison.org/listen/listen.php"); - result = curl_easy_perform(easyhandle_status); /* post away! */ - cout << "result: " << result << "\n"; - curl_easy_cleanup(easyhandle_status); - } - } - buffer[0] = '\0'; - } - } - close(rjh_pfds[0]); - _exit (0); - } - - /* Close the read side of the pipe */ - close(rjh_pfds[0]); + for(int i = 0; i < str.length(); i++) + { + str[i] = toupper(str[i]); + } + return; } -//----------------------------------- +// #endif \ No newline at end of file diff --git a/src/trx/trx.cxx b/src/trx/trx.cxx index cdc44d3f..ae1afe51 100644 --- a/src/trx/trx.cxx +++ b/src/trx/trx.cxx @@ -51,6 +51,21 @@ LOG_FILE_SOURCE(debug::LOG_MODEM); using namespace std; +//New stuff added by jcoxon +#include +#include +#include "misc/extra.h"; + +time_t rawtime; +struct tm * timeinfo; + +time_t seconds; +int status_count = 901; //Why 1001? well as it'll trigger the status update to be sent when fldigi starts +int old_seconds = 0; + +char date_time [80]; +// + void trx_reset_loop(); void trx_start_modem_loop(); void trx_receive_loop(); @@ -89,6 +104,10 @@ void trx_trx_receive_loop() { size_t numread; int current_samplerate; + + //jcoxon + extern int rjh_pfds[2]; + // assert(powerof2(SCBLOCKSIZE)); if (unlikely(!active_modem)) { @@ -126,6 +145,66 @@ void trx_trx_receive_loop() active_modem->rx_init(); while (1) { + //New stuff added by jcoxon + if (status_count >= 1000) { + seconds = time (NULL); +#if !defined(__CYGWIN__) + cout << seconds << "\n"; +#endif + if (int(seconds) > old_seconds + 900) { + //Send status update +#if !defined(__CYGWIN__) + cout << "Send status update\n"; +#endif + + string identity_callsign = (progdefaults.myCall.empty() ? "UNKNOWN" : progdefaults.myCall.c_str()); + UpperCase (identity_callsign); + //string string_lat = (progdefaults.myLat.empty() ? "UNKNOWN" : progdefaults.myLat.c_str()); + string string_lat = "52.0"; + UpperCase (string_lat); + //string string_lon = (progdefaults.myLon.empty() ? "UNKNOWN" : progdefaults.myLon.c_str()); + string string_lon = "0.0"; + UpperCase (string_lon); + //string string_radio = (progdefaults.myRadio.empty() ? "UNKNOWN" : progdefaults.myRadio.c_str()); + string string_radio = "radio"; + UpperCase (string_radio); + string string_antenna = (progdefaults.myAntenna.empty() ? "UNKNOWN" : progdefaults.myAntenna.c_str()); + UpperCase (string_antenna); + //string string_payload = (progdefaults.flight_sel.empty() ? "UNKNOWN" : progdefaults.flight_sel.c_str()); + string string_payload = "Test"; + UpperCase (string_payload); + + time ( &rawtime ); + timeinfo = gmtime ( &rawtime ); + strftime(date_time,80,"%Y-%m-%d %H:%M:%S",timeinfo); +#if !defined(__CYGWIN__) + cout << date_time << "\n"; +#endif +//-------------------------------------------------------- + string dlfldigi_version = "r100"; //Please update with revision number +//------------------------------------------------------- + //ZZ,Callsign,Date Time,Lat,Lon,Radio,Antenna + string rx_data ="ZZ," + identity_callsign + "," + date_time + "," + string_lat + "," + string_lon + "," + string_radio + "," + string_antenna + "," + dlfldigi_version + "," + string_payload; + string postData = "string=" + rx_data + "&identity=" + identity_callsign + "\n"; + + //We really don't want people sending status updates from UNKNOWN - somehow need to remind people to change their callsign + if (identity_callsign != "UNKNOWN") { + const char* data = postData.c_str(); + write (rjh_pfds[1],data,strlen(data)); + } + else { +#if !defined(__CYGWIN__) + cout << "Need to enter a callsign, please go to 'Configure' then 'Operator' and add a callsign/nickname.\n"; +#endif + } + old_seconds = seconds; + } + status_count = 0; + } + else { + status_count++; + } + //-------------------------- try { numread = 0; while (numread < SCBLOCKSIZE && trx_state == STATE_RX) From 2afabaa451d15343aa9ffce40f9f0e3316310a73 Mon Sep 17 00:00:00 2001 From: James Coxon Date: Sat, 20 Mar 2010 22:01:34 +0000 Subject: [PATCH 3/4] fixed extra.h and also ported code to detect and upload data strings up to the server - still needs to have the xml downloading and parsing rewritten so currently running on default values --- src/dialogs/fl_digi.cxx | 6 ++- src/include/configuration.h | 5 +- src/logger/rx_extract.cxx | 98 +++++++++++++++++++++++++++++++++++-- src/misc/extra.h | 15 ------ src/trx/trx.cxx | 2 +- 5 files changed, 105 insertions(+), 21 deletions(-) delete mode 100644 src/misc/extra.h diff --git a/src/dialogs/fl_digi.cxx b/src/dialogs/fl_digi.cxx index 98704a71..79e71c5b 100644 --- a/src/dialogs/fl_digi.cxx +++ b/src/dialogs/fl_digi.cxx @@ -3858,7 +3858,9 @@ void noop_controls() // create and then hide all controls not being used btnMacroTimer = new Fl_Button(defwidget); btnMacroTimer->hide(); - ReceiveText = new FTextRX(0,0,100,100); ReceiveText->hide(); + if(bWF_only) { + ReceiveText = new FTextRX(0,0,100,100); ReceiveText->hide(); + } TransmitText = new FTextTX(0,0,100,100); TransmitText->hide(); FHdisp = new Raster(0,0,10,100); FHdisp->hide(); @@ -4184,6 +4186,8 @@ int HAB_height = 0; void create_fl_digi_main_dl_fldigi() { + progdefaults.autoextract == true; + int fnt = fl_font(); int fsize = fl_size(); int freqheight = Hentry + 2 * pad; diff --git a/src/include/configuration.h b/src/include/configuration.h index 38980b4e..148d619a 100644 --- a/src/include/configuration.h +++ b/src/include/configuration.h @@ -1079,7 +1079,10 @@ "report.pskreporter.info") \ ELEM_(std::string, pskrep_port, "PSKREPPORT", \ "Reception report server port", \ - "4739") + "4739") \ + ELEM_(std::string, xmlFields, "", "", "7") \ + ELEM_(std::string, xmlField_delimiter, "", "", ",") \ + ELEM_(std::string, xmlSentence_delimiter, "", "", "$$") // declare the struct diff --git a/src/logger/rx_extract.cxx b/src/logger/rx_extract.cxx index f76a985d..e0629448 100644 --- a/src/logger/rx_extract.cxx +++ b/src/logger/rx_extract.cxx @@ -31,10 +31,40 @@ #include "fl_digi.h" #include "configuration.h" +//jcoxon +#include "extra.h" +// + using namespace std; -const char *beg = "[WRAP:beg]"; -const char *end = "[WRAP:end]"; +//jcoxon +void UpperCase(string& str) +{ + for(int i = 0; i < str.length(); i++) + { + str[i] = toupper(str[i]); + } + return; +} +// + +void TrimSpaces( string& str) +{ + + // Trim Both leading and trailing spaces + size_t startpos = str.find_first_not_of(" "); // Find the first character position after excluding leading blank spaces + size_t endpos = str.find_last_not_of("\r\n"); // Find the first character position from reverse af + + // if all spaces or empty return an empty string + if(( string::npos == startpos ) || ( string::npos == endpos)) + { + str = ""; + } + else + str = str.substr( startpos, endpos-startpos+1 ); +} + +const char *end = "\n"; #ifdef __WIN32__ const char *txtWrapInfo = "\ Detect the occurance of [WRAP:beg] and [WRAP:end]\n\ @@ -56,6 +86,20 @@ bool bInit = false; char dttm[64]; +//jcoxon +//Default rules +int total_string_length = 100; +int min_number_fields = 10; +int field_length = 10; + +int dodge_data = 0; +bool validate_output; +int number_commas; +int old_i = 0, field_number = 0; +string rx_buff_edit; +string tmpfield; +// + void rx_extract_reset() { rx_buff.clear(); @@ -66,6 +110,8 @@ void rx_extract_reset() void rx_extract_add(int c) { + extern int rjh_pfds[2]; + if (!c) return; if (!bInit) { @@ -76,7 +122,11 @@ void rx_extract_add(int c) memmove(rx_extract_buff, &rx_extract_buff[1], bufsize - 1); rx_extract_buff[bufsize - 1] = ch; - +//jcoxon + //Reads the stentence delimter previously read from the xml file. + //const char* beg = (progdefaults.xmlSentence_delimiter.empty() ? "UNKNOWN" : progdefaults.xmlSentence_delimiter.c_str()); + const char* beg = "$$"; +// if ( strstr(rx_extract_buff, beg) != NULL ) { rx_buff = beg; rx_extract_msg = "Extracting"; @@ -107,6 +157,48 @@ void rx_extract_add(int c) rx_extract_msg.append(WRAP_recv_dir); put_status(rx_extract_msg.c_str(), 20, STATUS_CLEAR); +//jcoxon + //Trim Spaces + TrimSpaces(rx_buff); + + // Find the sentence start marker and remove up to the end of it + // dkjhdskdkfdakhd $$icarus,... -> icarus,... + + rx_buff = rx_buff.substr( + rx_buff.find(progdefaults.xmlSentence_delimiter)+ + progdefaults.xmlSentence_delimiter.length()); + //I've removed the old swap callsign function as its not needed any longer. + + //Counts number of fields + number_commas = count(rx_buff.begin(), rx_buff.end(), progdefaults.xmlField_delimiter.at(0)); + + //Gets info for number of fields + //min_number_fields = atoi(progdefaults.xmlFields.c_str()); + + //Check rules - telem string length and number of fields and whether each field has been validated + if ((rx_buff.length() < total_string_length) and (number_commas == min_number_fields - 1)) { + string identity_callsign = (progdefaults.myCall.empty() ? "UNKNOWN" : progdefaults.myCall.c_str()); + UpperCase (identity_callsign); + + string postData = "string=" + rx_buff + "&identity=" + identity_callsign + "\n"; + + //We really don't want people sending status updates from UNKNOWN - somehow need to remind people to change their callsign + if (identity_callsign != "UNKNOWN") { +#if !defined(__CYGWIN__) + cout << "PARENT: sent " + postData ; +#endif + const char* data = postData.c_str(); + write (rjh_pfds[1],data,strlen(data)); + rx_extract_msg = "Data uploaded to server"; + put_status(rx_extract_msg.c_str(), 20, STATUS_CLEAR); + } + else { +#if !defined(__CYGWIN__) + cout << "Need to enter a callsign, please go to 'Configure' then 'Operator' and add a callsign/nickname.\n"; +#endif + } + } +// rx_extract_reset(); } else if (rx_buff.length() > 16384) { rx_extract_msg = "Extract length exceeded 16384 bytes"; diff --git a/src/misc/extra.h b/src/misc/extra.h deleted file mode 100644 index 211fc9fd..00000000 --- a/src/misc/extra.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _EXTRA_H_ -#define _EXTRA_H_ -#include - -//jcoxon -void UpperCase(string& str) -{ - for(int i = 0; i < str.length(); i++) - { - str[i] = toupper(str[i]); - } - return; -} -// -#endif \ No newline at end of file diff --git a/src/trx/trx.cxx b/src/trx/trx.cxx index ae1afe51..1428b37c 100644 --- a/src/trx/trx.cxx +++ b/src/trx/trx.cxx @@ -54,7 +54,7 @@ using namespace std; //New stuff added by jcoxon #include #include -#include "misc/extra.h"; +#include "extra.h"; time_t rawtime; struct tm * timeinfo; From 1a26d2a0b2f12312f7cc2e81adb149bb8adfcc2e Mon Sep 17 00:00:00 2001 From: James Coxon Date: Sat, 20 Mar 2010 22:04:39 +0000 Subject: [PATCH 4/4] missed out new extra.h --- src/include/extra.h | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/include/extra.h diff --git a/src/include/extra.h b/src/include/extra.h new file mode 100644 index 00000000..f3418e4b --- /dev/null +++ b/src/include/extra.h @@ -0,0 +1,10 @@ +#ifndef _EXTRA_H_ +#define _EXTRA_H_ + +#include + +void UpperCase(std::string& str); + +//void TrimSpaces( string& str); + +#endif \ No newline at end of file