Update of /cvsroot/playerstage/code/player/server/drivers/shell
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16952/shell

Modified Files:
        readlog.cc writelog.cc 
Log Message:
commited patch 1722668 AIO, DIO and RFID logging


Index: writelog.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/server/drivers/shell/writelog.cc,v
retrieving revision 1.76
retrieving revision 1.77
diff -C2 -d -r1.76 -r1.77
*** writelog.cc 14 Mar 2007 16:47:13 -0000      1.76
--- writelog.cc 9 Jun 2007 01:28:26 -0000       1.77
***************
*** 229,232 ****
--- 229,242 ----
    // Write Actarray data to file
    private: int WriteActarray (player_msghdr_t* hdr, void *data);
+ 
+   // Write AIO data to file
+   private: int WriteAIO(player_msghdr_t* hdr, void *data);
+ 
+   // Write AIO data to file
+   private: int WriteDIO(player_msghdr_t* hdr, void *data);
+ 
+   // Write RFID data to file
+   private: int WriteRFID(player_msghdr_t* hdr, void *data);
+ 
  #if 0
    // Write blobfinder data to file
***************
*** 778,781 ****
--- 788,800 ----
        retval = this->WriteActarray (hdr, data);
        break;
+     case PLAYER_AIO_CODE:
+       retval = this->WriteAIO(hdr, data);
+       break;
+     case PLAYER_DIO_CODE:
+       retval = this->WriteDIO(hdr, data);
+       break;
+     case PLAYER_RFID_CODE:
+       retval = this->WriteRFID(hdr, data);
+       break;
      /* HHAA 15-02-2007 */
      case PLAYER_BUMPER_CODE:
***************
*** 1513,1516 ****
--- 1532,1685 ----
  }
  
+ /** @ingroup tutorial_datalog
+  * @defgroup player_driver_writelog_aio aio format
+ 
+ @brief AIO log format
+ 
+ The format for each @ref interface_aio message is:
+   - voltages_count (int): the numer of analog input voltages
+   - list of inputs; for each input:
+     - voltage (float): the voltage on that input
+ 
+  */
+ int
+ WriteLog::WriteAIO(player_msghdr_t* hdr, void* data)
+ {
+   // Check the type
+   switch (hdr->type) {
+     case PLAYER_MSGTYPE_DATA:
+       // Check the subtype
+       switch (hdr->subtype) {
+         case PLAYER_AIO_DATA_STATE: {
+             player_aio_data_t* inputs(static_cast<player_aio_data_t*>(data));
+ 
+             // check for buffer overrun
+             if (inputs->voltages_count > PLAYER_AIO_MAX_INPUTS) {
+                 // this shouldn't happen
+                 PLAYER_ERROR("count too big for buffer");
+                 return -1;
+             }
+ 
+             fprintf(this->file, "%04d ", inputs->voltages_count);
+ 
+             for (float *v(inputs->voltages);
+                  v != inputs->voltages + inputs->voltages_count; ++v)
+               fprintf(this->file, "%.3f ", *v);
+ 
+             return 0;
+           }
+         default:
+           PLAYER_WARN1("cannot log unknown aio data subtype '%d'",
+                        hdr->subtype);
+           return -1;
+       }
+     default:
+       PLAYER_WARN1("cannot log unknown aio message type '%d'", hdr->type);
+       return -1;
+   }
+ }
+ 
+ /** @ingroup tutorial_datalog
+  * @defgroup player_driver_writelog_dio dio format
+ 
+ @brief DIO log format
+ 
+ The format for each @ref interface_dio message is:
+   - count (int): the numer of digital inputs
+   - list of input signals; for each input:
+       state (string): '0' or '1'
+ 
+  */
+ int
+ WriteLog::WriteDIO(player_msghdr_t* hdr, void* data)
+ {
+   // Check the type
+   switch (hdr->type) {
+     case PLAYER_MSGTYPE_DATA:
+       // Check the subtype
+       switch (hdr->subtype) {
+         case PLAYER_DIO_DATA_VALUES: {
+             player_dio_data_t* inputs(static_cast<player_dio_data_t*>(data));
+ 
+             // check for buffer overrun
+             if (inputs->count > /* MAX_INPUTS */ 32) {
+                 // this shouldn't happen
+                 PLAYER_ERROR("count too big for bitfield");
+                 return -1;
+             }
+ 
+             fprintf(this->file, "%04d ", inputs->count);
+ 
+             for (uint32_t mask(1); mask != (1ul << inputs->count); mask <<= 1)
+               fprintf(this->file, "%d ", !!(mask & inputs->digin));
+ 
+             return 0;
+           }
+         default:
+           PLAYER_WARN1("cannot log unknown dio data subtype '%d'",
+                        hdr->subtype);
+           return -1;
+       }
+     default:
+       PLAYER_WARN1("cannot log unknown dio message type '%d'", hdr->type);
+       return -1;
+   }
+ }
+ 
+ /** @ingroup tutorial_datalog
+  * @defgroup player_driver_writelog_rfid rfid format
+ 
+ @brief RFID log format
+ 
+ The format for each @ref interface_rfid message is:
+   - tags_count (int): the numer of tags found
+   - list of tags; for each tag:
+     - guid (string): tag guid in hex
+ 
+  */
+ int
+ WriteLog::WriteRFID(player_msghdr_t* hdr, void* data)
+ {
+   // Check the type
+   switch (hdr->type) {
+     case PLAYER_MSGTYPE_DATA:
+       // Check the subtype
+       switch (hdr->subtype) {
+         case PLAYER_RFID_DATA: {
+             player_rfid_data_t* rdata(static_cast<player_rfid_data_t*>(data));
+ 
+             if (rdata->tags_count > PLAYER_RFID_MAX_TAGS) {
+                 // this shouldn't happen
+                 PLAYER_ERROR("count too big for buffer");
+                 return -1;
+             }
+ 
+             fprintf(file, "%04d ", rdata->tags_count);
+ 
+             for (player_rfid_tag_t *t(rdata->tags);
+                  t != rdata->tags + rdata->tags_count; ++t) {
+               if (t->guid_count > PLAYER_RFID_MAX_GUID) {
+                 PLAYER_ERROR("guid count too big for buffer");
+                 return -1;
+               }
+               char str[PLAYER_RFID_MAX_GUID * 2 + 1];
+               memset(str, '\0', sizeof(str));
+               EncodeHex(str, sizeof(str), t->guid, t->guid_count);
+               fprintf(file, "%s ", str);
+             }
+ 
+             return 0;
+           }
+         default:
+           PLAYER_WARN1("cannot log unknown rfid data subtype '%d'",
+                        hdr->subtype);
+           return -1;
+       }
+     default:
+       PLAYER_WARN1("cannot log unknown rfid message type '%d'", hdr->type);
+       return -1;
+   }
+ }
+ 
  int
  WriteLog::WriteIR(player_msghdr_t* hdr, void *data)

Index: readlog.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/server/drivers/shell/readlog.cc,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** readlog.cc  20 Nov 2006 12:25:18 -0000      1.46
--- readlog.cc  9 Jun 2007 01:28:26 -0000       1.47
***************
*** 302,305 ****
--- 302,323 ----
                                int linenum,
                                int token_count, char **tokens, double time);
+ 
+   // Parse AIO data
+   private: int ParseAIO(player_devaddr_t id,
+                         unsigned short type, unsigned short subtype,
+                         int linenum, int token_count, char **tokens,
+                         double time);
+ 
+   // Parse DIO data
+   private: int ParseDIO(player_devaddr_t id,
+                         unsigned short type, unsigned short subtype,
+                         int linenum, int token_count, char **tokens,
+                         double time);
+ 
+   // Parse RFID data
+   private: int ParseRFID(player_devaddr_t id,
+                          unsigned short type, unsigned short subtype,
+                          int linenum, int token_count, char **tokens,
+                          double time);
  #if 0
  
***************
*** 1180,1183 ****
--- 1198,1210 ----
        return this->ParseActarray (id, type, subtype, linenum,
                                    token_count, tokens, time);
+   else if (id.interf == PLAYER_AIO_CODE)
+       return this->ParseAIO(id, type, subtype, linenum, token_count, tokens,
+                             time);
+   else if (id.interf == PLAYER_DIO_CODE)
+       return this->ParseDIO(id, type, subtype, linenum, token_count, tokens,
+                             time);
+   else if (id.interf == PLAYER_RFID_CODE)
+       return this->ParseRFID(id, type, subtype, linenum, token_count, tokens,
+                             time);
  #if 0
    else if (id.interf == PLAYER_POSITION3D_CODE)
***************
*** 2127,2130 ****
--- 2154,2320 ----
  }
  
+ ////////////////////////////////////////////////////////////////////////////
+ // Parse AIO data
+ int ReadLog::ParseAIO(player_devaddr_t id, unsigned short type,
+                       unsigned short subtype, int linenum, int token_count,
+                       char **tokens, double time)
+ {
+   switch (type) {
+     case PLAYER_MSGTYPE_DATA:
+       switch (subtype) {
+         case PLAYER_AIO_DATA_STATE: {
+             player_aio_data_t inputs;
+ 
+             if (token_count < 8) {
+               PLAYER_ERROR2("invalid line at %s:%d: count missing", filename,
+                             linenum);
+               return -1;
+             }
+ 
+             inputs.voltages_count = atoi(tokens[7]);
+ 
+             if (token_count - 8 != (int)inputs.voltages_count) {
+               PLAYER_ERROR2("invalid line at %s:%d: number of tokens does not 
"
+                             "match count", filename, linenum);
+               return -1;
+             }
+ 
+             if (inputs.voltages_count > PLAYER_AIO_MAX_INPUTS) {
+               PLAYER_ERROR2("invalid line at %s:%d: too much data for buffer",
+                             filename, linenum);
+               return -1;
+             }
+ 
+             char **t(tokens + 8);
+             for (float *v(inputs.voltages);
+                  v != inputs.voltages + inputs.voltages_count; ++v, ++t)
+               *v = atof(*t);
+ 
+             Publish(id, NULL, type, subtype, (void *)&inputs, sizeof(inputs),
+                     &time);
+             return 0;
+           }
+         default:
+           PLAYER_WARN3("cannot parse log of unknown aio data subtype '%d' at "
+                        "%s:%d", subtype, filename, linenum);
+           return -1;
+       }
+       default:
+         PLAYER_WARN3("cannot parse log unknown of aio message type '%d' at "
+                      "%s:%d", type, filename, linenum);
+         return -1;
+   }
+ }
+ 
+ ////////////////////////////////////////////////////////////////////////////
+ // Parse DIO data
+ int ReadLog::ParseDIO(player_devaddr_t id, unsigned short type,
+                       unsigned short subtype, int linenum, int token_count,
+                       char **tokens, double time)
+ {
+   switch (type) {
+     case PLAYER_MSGTYPE_DATA:
+       switch (subtype) {
+         case PLAYER_DIO_DATA_VALUES: {
+             player_dio_data_t inputs;
+ 
+             if (token_count < 8) {
+               PLAYER_ERROR2("invalid line at %s:%d: count missing", filename,
+                             linenum);
+               return -1;
+             }
+ 
+             inputs.count = atoi(tokens[7]);
+             inputs.digin = 0;
+ 
+             if (token_count - 8 != static_cast<int>(inputs.count)) {
+               PLAYER_ERROR2("invalid line at %s:%d: number of tokens does not 
"
+                             "match count", filename, linenum);
+               return -1;
+             }
+ 
+             if (inputs.count > 32 /* MAX_INPUTS */) {
+               PLAYER_ERROR2("invalid line at %s:%d: too much data for buffer",
+                             filename, linenum);
+               return -1;
+             }
+ 
+             char **t(tokens + 8);
+             for (uint32_t mask(1); mask != (1ul << inputs.count);
+                  mask <<=1, ++t) {
+               if (strcmp(*t, "1") == 0) inputs.digin |= mask;
+             }
+ 
+             Publish(id, NULL, type, subtype, (void *)&inputs, sizeof(inputs),
+                     &time);
+             return 0;
+           }
+         default:
+           PLAYER_WARN3("cannot parse log of unknown dio data subtype '%d' at "
+                        "%s:%d", subtype, filename, linenum);
+           return -1;
+       }
+       default:
+         PLAYER_WARN3("cannot parse log of unknown dio message type '%d' at "
+                      "%s:%d", type, filename, linenum);
+         return -1;
+   }
+ }
+ 
+ ////////////////////////////////////////////////////////////////////////////
+ // Parse RFID data
+ int ReadLog::ParseRFID(player_devaddr_t id, unsigned short type,
+                       unsigned short subtype, int linenum, int token_count,
+                       char **tokens, double time)
+ {
+   switch (type) {
+     case PLAYER_MSGTYPE_DATA:
+       switch (subtype) {
+         case PLAYER_RFID_DATA: {
+             player_rfid_data_t rdata;
+ 
+             if (token_count < 8) {
+               PLAYER_ERROR2("invalid line at %s:%d: count missing",
+                             this->filename, linenum);
+               return -1;
+             }
+ 
+             rdata.tags_count = atoi(tokens[7]);
+ 
+             if (token_count - 8 != static_cast<int>(rdata.tags_count)) {
+               PLAYER_ERROR2("invalid line at %s:%d: number of tokens does not 
"
+                             "match count", this->filename, linenum);
+               return -1;
+             }
+ 
+             if (rdata.tags_count > PLAYER_RFID_MAX_TAGS) {
+               PLAYER_ERROR2("invalid line at %s:%d: too much data for buffer",
+                             this->filename, linenum);
+               return -1;
+             }
+ 
+             char **t(tokens + 8);
+             for (player_rfid_tag_t *r(rdata.tags);
+                  r != rdata.tags + rdata.tags_count; ++r, ++t) {
+               r->guid_count = strlen(*t) / 2;
+               DecodeHex(r->guid, PLAYER_RFID_MAX_GUID, *t, strlen(*t));
+             }
+ 
+             Publish(id, NULL, type, subtype, (void *)&rdata, sizeof(rdata),
+                     &time);
+             return 0;
+           }
+         default:
+           PLAYER_WARN3("cannot parse log of unknown rfid data subtype '%d' at 
"
+                        "%s:%d", subtype, filename, linenum);
+           return -1;
+       }
+       default:
+         PLAYER_WARN3("cannot parse log of unknown rfid message type '%d' at "
+                      "%s:%d", type, filename, linenum);
+         return -1;
+   }
+ }
+ 
  #if 0
  ////////////////////////////////////////////////////////////////////////////


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to