[Firebug-cvs] fireboard/tools/src/xlisten/boards LinkEstimatorMsg.c, NONE, 1.1 Makefile, NONE, 1.1
Brought to you by:
doolin
Update of /cvsroot/firebug/fireboard/tools/src/xlisten/boards In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv19309 Added Files: LinkEstimatorMsg.c Makefile SurgeMsg.c fireboard.c ggbacltst.c linkmsg.c mica2.c mica2dot.c micaz.c msp410.c pg_test.c sirf_id2.c sirf_id28.c sirf_id28_1.c sirf_id28_2.c sirf_id28_3.c sirf_id2_1.c sirf_id2_2.c testlink.c xtutorial.c Log Message: updating from beta. --- NEW FILE: micaz.c --- /** * Handles parsing of micaz packets. * * @file micaz.c * @author Hu Siquan * @version 2004/4/12 husq Initial version * * Refer to: * - Xbow MTS/MDA Sensor and DataAcquistion Manual * * Copyright (c) 2004 Crossbow Technology, Inc. All rights reserved. * * $Id: micaz.c,v 1.1 2006/07/10 17:16:11 doolin Exp $ */ #include <math.h> #include "../xsensors.h" /** micaz XMesh packet 1 -- contains serialID information */ typedef struct SerialIDData { uint8_t id[8]; } __attribute__ ((packed)) SerialIDData; typedef struct ConfigData { uint16_t nodeid; uint8_t group; uint8_t rf_power; uint8_t rf_channel; } __attribute__ ((packed)) ConfigData; int table_micaz_power[8][2] ={{31,0},{27,-1},{23,-3},{19,-5},{15,-7},{11,-10},{7,-15},{3,-25}}; int getDBMfromRTP(int table[][2], int index) { int i; for(i=0;i<8;i++){ if (table[i][0] == index) return table[i][1]; } return 0xff; } extern XPacketHandler micaz_packet_handler; /** micaz Specific outputs of raw readings within an XBowSensorboardPacket */ void micaz_print_raw(XbowSensorboardPacket *packet) { switch(packet->packet_id){ case 1:{ SerialIDData *data = (SerialIDData *)packet->data; printf("micaz id=%02x SerialID = %02x%02x%02x%02x%02x%02x%02x%02x\n", packet->node_id, data->id[0], data->id[1],data->id[2],data->id[3], data->id[4],data->id[5], data->id[6],data->id[7]); break; } case 2:{ ConfigData *data = (ConfigData *)packet->data; printf("micaz config parameters: nodeid=%04x groupid=%02x rf_power=%02x rf_channel=%02x\n", data->nodeid, data->group,data->rf_power,data->rf_channel); break; } default: break; } } /** micaz specific display of converted readings from XBowSensorboardPacket */ void micaz_print_cooked(XbowSensorboardPacket *packet) { switch(packet->packet_id){ case 1:{ SerialIDData *data = (SerialIDData *)packet->data; printf("MicaZ id=%02x SerialID information: \n" " CRC code = %02x\n" " Serial Number = %02x%02x%02x%02x%02x%02x\n" " Family Code = %02x\n", packet->node_id, data->id[7],data->id[6],data->id[5], data->id[4], data->id[3],data->id[2],data->id[1],data->id[0]); break; } case 2:{ ConfigData *data = (ConfigData *)packet->data; printf("MicaZ Config parameters: \n" " nodeid=%d groupid=%d " " RF Power=%ddbm; RF Channel=%dMHz\n", data->nodeid, data->group, getDBMfromRTP(table_micaz_power,data->rf_power),2405+5*(data->rf_channel-11)); break; } default: break; } printf("\n"); } /** * Logs raw readings to a Postgres database. * * @author Martin Turon * * @version 2004/7/28 mturon Initial revision * */ void micaz_log_raw(XbowSensorboardPacket *packet) { } XPacketHandler micaz_packet_handler = { XTYPE_MICAZ, "$Id: micaz.c,v 1.1 2006/07/10 17:16:11 doolin Exp $", micaz_print_raw, micaz_print_cooked, micaz_print_raw, micaz_print_cooked, micaz_log_raw }; void micaz_initialize() { xpacket_add_type(&micaz_packet_handler); } --- NEW FILE: SurgeMsg.c --- /** * This class is automatically generated by mig. DO NOT EDIT THIS FILE. * This code implements C interface to the 'SurgeMsgP' * message type. */ #include <stdio.h> #include <stdlib.h> #include <memory.h> /** Private header is programmer specified for handling * conversion functions, etc. */ //#include "SurgeMsgP_private.h" /** Not the best way to handle xbow dependencies. */ #ifdef TELOS_MOTE #include "../xdb.h" #include "../xsensors.h" #endif /** These need to be moved to a header file. */ typedef struct _SurgeMsgP SurgeMsgP; #ifndef TELOS_MOTE typedef struct _XbowSensorboardPacket XbowSensorboardPacket; #endif /** The Active Message type associated with this message. */ //static const int AM_TYPE = 17; //#define AM_TYPE 17 // This struct is defined to keep gcc happy while the module // is under development. At some point in the near future, a // a convention for passing arguments into the functions will // have to be defined. struct _XbowSensorboardPacket { unsigned char data[29]; }; struct _SurgeMsgP { uint16_t type; uint16_t reading; uint16_t parentaddr; uint16_t seq_no; }; void SurgeMsgP_set_type(SurgeMsgP * userdata, uint16_t type) { userdata->type = type; } uint16_t SurgeMsgP_get_type(SurgeMsgP * userdata) { return userdata->type; } void SurgeMsgP_set_reading(SurgeMsgP * userdata, uint16_t reading) { userdata->reading = reading; } uint16_t SurgeMsgP_get_reading(SurgeMsgP * userdata) { return userdata->reading; } void SurgeMsgP_set_parentaddr(SurgeMsgP * userdata, uint16_t parentaddr) { userdata->parentaddr = parentaddr; } uint16_t SurgeMsgP_get_parentaddr(SurgeMsgP * userdata) { return userdata->parentaddr; } void SurgeMsgP_set_seq_no(SurgeMsgP * userdata, uint16_t seq_no) { userdata->seq_no = seq_no; } uint16_t SurgeMsgP_get_seq_no(SurgeMsgP * userdata) { return userdata->seq_no; } //Format string generated automatically, //static char formatstring[] = "%i, %i, %i, %i"; //static char formatstring[] = "%i, %i, %i, %i"; static char insert_stmt[] = "INSERT into SurgeMsgP (" "result_time," "type," "reading," "parentaddr," "seq_no) values (now(), %i, %i, %i, %i)"; void SurgeMsgP_pg_log(XbowSensorboardPacket * userdata) { char pg_command[255]; SurgeMsgP * data = (SurgeMsgP*)userdata; sprintf(pg_command,insert_stmt, data->type, data->reading, data->parentaddr, data->seq_no); #ifdef TELOS_MOTE xdb_execute(pg_command); #endif } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t type_convert(uint16_t type) { return type; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t reading_convert(uint16_t reading) { return reading; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t parentaddr_convert(uint16_t parentaddr) { return parentaddr; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t seq_no_convert(uint16_t seq_no) { return seq_no; } void SurgeMsgP_cook_packet(SurgeMsgP * userdata) { userdata->type = type_convert(userdata->type); userdata->reading = reading_convert(userdata->reading); userdata->parentaddr = parentaddr_convert(userdata->parentaddr); userdata->seq_no = seq_no_convert(userdata->seq_no); } /** User has to fill in any conversion code * necessary for processing. */ SurgeMsgP * SurgeMsgP_convert(char * data) { // Just to keep gcc happy. return (SurgeMsgP*)data; } /** Print the bytes of the packet. */ void SurgeMsgP_print_raw (XbowSensorboardPacket *packet) { printf("SurgeMsgP print raw.\n"); } /** Print cooked output. */ void SurgeMsgP_print_cooked (XbowSensorboardPacket * userdata) { SurgeMsgP * data = (SurgeMsgP*)userdata; printf("SurgeMsgP print cooked:\n"); printf(" type: %i,\n",data->type); printf(" reading: %i,\n",data->reading); printf(" parentaddr: %i,\n",data->parentaddr); printf(" seq_no: %i,\n",data->seq_no); } #ifdef TELOS_MOTE XPacketHandler SurgeMsgP_packet_handler = { // This should be replaced with the AM_TYPE 17, "$Id: SurgeMsg.c,v 1.1 2006/07/10 17:16:11 doolin Exp $", SurgeMsgP_print_raw, SurgeMsgP_print_cooked, SurgeMsgP_print_raw, SurgeMsgP_print_cooked, SurgeMsgP_pg_log, {0} }; void SurgeMsgP_initialize() { xpacket_add_type(&SurgeMsgP_packet_handler); } #endif /** The default size of this message type in bytes. */ //static int DEFAULT_MESSAGE_SIZE = 8; /** If incomplete types are used, we need to provide a way * to manage memory. */ SurgeMsgP * SurgeMsgP_new() { SurgeMsgP * userdata = (SurgeMsgP*)malloc(sizeof(SurgeMsgP)); memset((void*)userdata,0xda,sizeof(SurgeMsgP)); return userdata; } void SurgeMsgP_delete(SurgeMsgP * userdata) { memset((void*)userdata,0xdd,sizeof(SurgeMsgP)); free(userdata); } --- NEW FILE: ggbacltst.c --- /** * Handles conversion to engineering units of ggbacltst packets. * * Copyright (c) 2004 Crossbow Technology, Inc. All rights reserved. * * $Id: ggbacltst.c,v 1.1 2006/07/10 17:16:11 doolin Exp $ */ #include "../xdb.h" #include "../xsensors.h" typedef struct { uint16_t vref; uint16_t high_vertical; uint16_t high_horizontal; uint16_t low_vertical; uint16_t low_horizontal; uint16_t temperature; } XSensorGGBACLTSTData; extern XPacketHandler ggbacltst_packet_handler; void ggbacltst_print_raw(XbowSensorboardPacket *packet) { XSensorGGBACLTSTData *data = (XSensorGGBACLTSTData *)packet->data; printf("ggbacltst id=%02x vref=%4x\n" " acl_high_vertical=%04x acl_high_horizontal=%04x\n" " acl_low_vertical=%04x acl_low_horizontal=%04x\n" " temperature=%04x\n", packet->node_id, data->vref, data->high_vertical, data->high_horizontal, data->low_vertical, data->low_horizontal, data->temperature); } void ggbacltst_print_cooked(XbowSensorboardPacket *packet) { XSensorGGBACLTSTData *data = (XSensorGGBACLTSTData *)packet->data; uint16_t tmpr = data->temperature; int i; for (i = 0; i < 3; i++) { tmpr >>= 1; if (tmpr & 0x4000) tmpr |= 0x8000; } printf("GGBACLTST [sensor data converted to engineering units]:\n" " health: node id=%i parent=%i\n" " battery: = %i mv \n" " acl high vertical: = %f g, horizontal: = %f g\n" " acl low vertical: = %f g, horizontal: = %f g\n" " temperature=%0.2f degC\n", packet->node_id, packet->parent, xconvert_battery_mica2(data->vref), (double)data->high_vertical / (double) 65536 * 0.2 - 0.1 + 1, (double)data->high_horizontal / (double) 65536 * 0.2 - 0.1, (double)data->low_vertical / (double) 16384 - 2, (double)data->low_horizontal / (double) 16384 - 2, (double)(short)tmpr * (double)125 / (double)(0x3e87 >> 3) ); printf("\n"); } const char *ggbacltst_db_create_table = "CREATE TABLE %s%s ( result_time timestamp without time zone, " "epoch integer, nodeid integer, parent integer, " "voltage integer, acl_high_vertical integer, acl_high_horizontal integer," "acl_low_vertical integer, acl_low_horizontal integer, temperature integer)"; const char *ggbacltst_db_create_rule = "CREATE RULE cache_%s AS ON INSERT TO %s DO ( " "DELETE FROM %s_L WHERE nodeid = NEW.nodeid; " "INSERT INTO %s_L VALUES (NEW.*); )"; void ggbacltst_log_raw(XbowSensorboardPacket *packet) { XSensorGGBACLTSTData *data = (XSensorGGBACLTSTData *)packet->data; char command[512]; char *table = xdb_get_table(); if (!*table) table = "ggbacltst_results"; if (!ggbacltst_packet_handler.flags.table_init) { int exists = xdb_table_exists(table); if (!exists) { // Create results table. sprintf(command, ggbacltst_db_create_table, table, ""); xdb_execute(command); // Create last result cache sprintf(command, ggbacltst_db_create_table, table, "_L"); xdb_execute(command); // Add rule to populate last result table sprintf(command, ggbacltst_db_create_rule, table, table, table, table); xdb_execute(command); // Add results table to query log. int q_id = XTYPE_GGBACLTST, sample_time = 99000; sprintf(command, "INSERT INTO task_query_log " "(query_id, tinydb_qid, query_text, query_type, " "table_name) VALUES (%i, %i, 'SELECT nodeid,parent,voltage," "acl_high_vertical,acl_high_horizontal,acl_low_vertical,acl_low_horizontal,temperature " "SAMPLE PERIOD %i', 'sensor', '%s')", q_id, q_id, sample_time, table); xdb_execute(command); // Log start time of query in time log. sprintf(command, "INSERT INTO task_query_time_log " "(query_id, start_time) VALUES (%i, now())", q_id); xdb_execute(command); } ggbacltst_packet_handler.flags.table_init = 1; } sprintf(command, "INSERT into %s " "(result_time,nodeid,parent,voltage,acl_high_vertical,acl_high_horizontal," "acl_low_vertical,acl_low_horizontal,temperature)" " values (now(),%u,%u,%u,%u,%u,%u,%u,%u)", table, //timestring, packet->node_id, packet->parent, data->vref, data->high_vertical, data->high_horizontal, data->low_vertical, data->low_horizontal, data->temperature ); xdb_execute(command); } XPacketHandler ggbacltst_packet_handler = { XTYPE_GGBACLTST, "$Id: ggbacltst.c,v 1.1 2006/07/10 17:16:11 doolin Exp $", ggbacltst_print_raw, ggbacltst_print_cooked, ggbacltst_print_raw, ggbacltst_print_cooked, ggbacltst_log_raw }; void ggbacltst_initialize() { xpacket_add_type(&ggbacltst_packet_handler); } --- NEW FILE: linkmsg.c --- /** * This class is automatically generated by mig. DO NOT EDIT THIS FILE. * This code implements C interface to the 'LinkMsgP' * message type. */ #include <stdio.h> #include <stdlib.h> #include <memory.h> /** Private header is programmer specified for handling * conversion functions, etc. */ //#include "LinkMsgP_private.h" /** Not the best way to handle xbow dependencies. */ #ifdef TELOS_MOTE #include "../xdb.h" #include "../xsensors.h" #endif /** These need to be moved to a header file. */ typedef struct _LinkMsgP LinkMsgP; #ifndef TELOS_MOTE typedef struct _XbowSensorboardPacket XbowSensorboardPacket; #endif /** The Active Message type associated with this message. */ //static const int AM_TYPE = 200; //#define AM_TYPE 200 // This struct is defined to keep gcc happy while the module // is under development. At some point in the near future, a // a convention for passing arguments into the functions will // have to be defined. struct _XbowSensorboardPacket { unsigned char data[29]; }; struct _LinkMsgP { uint16_t header_am_type; uint16_t header_seqno; uint32_t tstamp; uint16_t moteid; uint16_t RSSI; uint16_t LQI; }; void LinkMsgP_set_header_am_type(LinkMsgP * userdata, uint16_t header_am_type) { userdata->header_am_type = header_am_type; } uint16_t LinkMsgP_get_header_am_type(LinkMsgP * userdata) { return userdata->header_am_type; } void LinkMsgP_set_header_seqno(LinkMsgP * userdata, uint16_t header_seqno) { userdata->header_seqno = header_seqno; } uint16_t LinkMsgP_get_header_seqno(LinkMsgP * userdata) { return userdata->header_seqno; } void LinkMsgP_set_tstamp(LinkMsgP * userdata, uint32_t tstamp) { userdata->tstamp = tstamp; } uint32_t LinkMsgP_get_tstamp(LinkMsgP * userdata) { return userdata->tstamp; } void LinkMsgP_set_moteid(LinkMsgP * userdata, uint16_t moteid) { userdata->moteid = moteid; } uint16_t LinkMsgP_get_moteid(LinkMsgP * userdata) { return userdata->moteid; } void LinkMsgP_set_RSSI(LinkMsgP * userdata, uint16_t RSSI) { userdata->RSSI = RSSI; } uint16_t LinkMsgP_get_RSSI(LinkMsgP * userdata) { return userdata->RSSI; } void LinkMsgP_set_LQI(LinkMsgP * userdata, uint16_t LQI) { userdata->LQI = LQI; } uint16_t LinkMsgP_get_LQI(LinkMsgP * userdata) { return userdata->LQI; } //Format string generated automatically, //static char formatstring[] = "%i, %i, %i, %i, %i, %i"; //static char formatstring[] = "%i, %i, %i, %i, %i, %i"; static char insert_stmt[] = "INSERT into LinkMsgP (" "result_time," "header_am_type," "header_seqno," "tstamp," "moteid," "RSSI," "LQI) values (now(), %i, %i, %i, %i, %i, %i)"; void LinkMsgP_pg_log(XbowSensorboardPacket * userdata) { char pg_command[255]; LinkMsgP * data = (LinkMsgP*)userdata; sprintf(pg_command,insert_stmt, data->header_am_type, data->header_seqno, data->tstamp, data->moteid, data->RSSI, data->LQI); #ifdef TELOS_MOTE xdb_execute(pg_command); #endif } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t header_am_type_convert(uint16_t header_am_type) { return header_am_type; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t header_seqno_convert(uint16_t header_seqno) { return header_seqno; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint32_t tstamp_convert(uint32_t tstamp) { return tstamp; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t moteid_convert(uint16_t moteid) { return moteid; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t RSSI_convert(uint16_t RSSI) { return RSSI; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t LQI_convert(uint16_t LQI) { return LQI; } void LinkMsgP_cook_packet(LinkMsgP * userdata) { userdata->header_am_type = header_am_type_convert(userdata->header_am_type); userdata->header_seqno = header_seqno_convert(userdata->header_seqno); userdata->tstamp = tstamp_convert(userdata->tstamp); userdata->moteid = moteid_convert(userdata->moteid); userdata->RSSI = RSSI_convert(userdata->RSSI); userdata->LQI = LQI_convert(userdata->LQI); } /** User has to fill in any conversion code * necessary for processing. */ LinkMsgP * LinkMsgP_convert(char * data) { // Just to keep gcc happy. return (LinkMsgP*)data; } /** Print the bytes of the packet. */ void LinkMsgP_print_raw (XbowSensorboardPacket *packet) { printf("LinkMsgP print raw.\n"); } /** Print cooked output. */ void LinkMsgP_print_cooked (XbowSensorboardPacket * userdata) { LinkMsgP * data = (LinkMsgP*)userdata; printf("LinkMsgP print cooked:\n"); printf(" header_am_type: %i,\n",data->header_am_type); printf(" header_seqno: %i,\n",data->header_seqno); printf(" tstamp: %i,\n",data->tstamp); printf(" moteid: %i,\n",data->moteid); printf(" RSSI: %i,\n",data->RSSI); printf(" LQI: %i,\n",data->LQI); } #ifdef TELOS_MOTE XPacketHandler LinkMsgP_packet_handler = { // This should be replaced with the AM_TYPE 200, "$Id: linkmsg.c,v 1.1 2006/07/10 17:16:11 doolin Exp $", LinkMsgP_print_raw, LinkMsgP_print_cooked, LinkMsgP_print_raw, LinkMsgP_print_cooked, LinkMsgP_pg_log, {0} }; void LinkMsgP_initialize() { xpacket_add_type(&LinkMsgP_packet_handler); } #endif /** The default size of this message type in bytes. */ //static int DEFAULT_MESSAGE_SIZE = 14; /** If incomplete types are used, we need to provide a way * to manage memory. */ LinkMsgP * LinkMsgP_new() { LinkMsgP * userdata = (LinkMsgP*)malloc(sizeof(LinkMsgP)); memset((void*)userdata,0xda,sizeof(LinkMsgP)); return userdata; } void LinkMsgP_delete(LinkMsgP * userdata) { memset((void*)userdata,0xdd,sizeof(LinkMsgP)); free(userdata); } --- NEW FILE: sirf_id2_2.c --- /** * This class is automatically generated by mig. DO NOT EDIT THIS FILE. * This code implements C interface to the 'SiRF_ID2_2P' * message type. */ #include <stdio.h> #include <stdlib.h> #include <memory.h> /** Private header is programmer specified for handling * conversion functions, etc. */ //#include "SiRF_ID2_2P_private.h" /** Not the best way to handle xbow dependencies. */ #ifdef TELOS_MOTE #include "../xdb.h" #include "../xsensors.h" #endif /** These need to be moved to a header file. */ typedef struct _SiRF_ID2_2P SiRF_ID2_2P; #ifndef TELOS_MOTE typedef struct _XbowSensorboardPacket XbowSensorboardPacket; #endif /** The Active Message type associated with this message. */ //static const int AM_TYPE = 151; //#define AM_TYPE 151 // This struct is defined to keep gcc happy while the module // is under development. At some point in the near future, a // a convention for passing arguments into the functions will // have to be defined. struct _XbowSensorboardPacket { unsigned char data[29]; }; struct _SiRF_ID2_2P { uint8_t header_mote_id; uint8_t header_seqno; uint8_t header_am_type; uint8_t header_blockcount; uint32_t gps_tow; uint8_t sv_in_fix; uint8_t ch1; uint8_t ch2; uint8_t ch3; uint8_t ch4; uint8_t ch5; uint8_t ch6; uint8_t ch7; uint8_t ch8; uint8_t ch9; uint8_t ch10; uint8_t ch11; uint8_t ch12; }; void SiRF_ID2_2P_set_header_mote_id(SiRF_ID2_2P * userdata, uint8_t header_mote_id) { userdata->header_mote_id = header_mote_id; } uint8_t SiRF_ID2_2P_get_header_mote_id(SiRF_ID2_2P * userdata) { return userdata->header_mote_id; } void SiRF_ID2_2P_set_header_seqno(SiRF_ID2_2P * userdata, uint8_t header_seqno) { userdata->header_seqno = header_seqno; } uint8_t SiRF_ID2_2P_get_header_seqno(SiRF_ID2_2P * userdata) { return userdata->header_seqno; } void SiRF_ID2_2P_set_header_am_type(SiRF_ID2_2P * userdata, uint8_t header_am_type) { userdata->header_am_type = header_am_type; } uint8_t SiRF_ID2_2P_get_header_am_type(SiRF_ID2_2P * userdata) { return userdata->header_am_type; } void SiRF_ID2_2P_set_header_blockcount(SiRF_ID2_2P * userdata, uint8_t header_blockcount) { userdata->header_blockcount = header_blockcount; } uint8_t SiRF_ID2_2P_get_header_blockcount(SiRF_ID2_2P * userdata) { return userdata->header_blockcount; } void SiRF_ID2_2P_set_gps_tow(SiRF_ID2_2P * userdata, uint32_t gps_tow) { userdata->gps_tow = gps_tow; } uint32_t SiRF_ID2_2P_get_gps_tow(SiRF_ID2_2P * userdata) { return userdata->gps_tow; } void SiRF_ID2_2P_set_sv_in_fix(SiRF_ID2_2P * userdata, uint8_t sv_in_fix) { userdata->sv_in_fix = sv_in_fix; } uint8_t SiRF_ID2_2P_get_sv_in_fix(SiRF_ID2_2P * userdata) { return userdata->sv_in_fix; } void SiRF_ID2_2P_set_ch1(SiRF_ID2_2P * userdata, uint8_t ch1) { userdata->ch1 = ch1; } uint8_t SiRF_ID2_2P_get_ch1(SiRF_ID2_2P * userdata) { return userdata->ch1; } void SiRF_ID2_2P_set_ch2(SiRF_ID2_2P * userdata, uint8_t ch2) { userdata->ch2 = ch2; } uint8_t SiRF_ID2_2P_get_ch2(SiRF_ID2_2P * userdata) { return userdata->ch2; } void SiRF_ID2_2P_set_ch3(SiRF_ID2_2P * userdata, uint8_t ch3) { userdata->ch3 = ch3; } uint8_t SiRF_ID2_2P_get_ch3(SiRF_ID2_2P * userdata) { return userdata->ch3; } void SiRF_ID2_2P_set_ch4(SiRF_ID2_2P * userdata, uint8_t ch4) { userdata->ch4 = ch4; } uint8_t SiRF_ID2_2P_get_ch4(SiRF_ID2_2P * userdata) { return userdata->ch4; } void SiRF_ID2_2P_set_ch5(SiRF_ID2_2P * userdata, uint8_t ch5) { userdata->ch5 = ch5; } uint8_t SiRF_ID2_2P_get_ch5(SiRF_ID2_2P * userdata) { return userdata->ch5; } void SiRF_ID2_2P_set_ch6(SiRF_ID2_2P * userdata, uint8_t ch6) { userdata->ch6 = ch6; } uint8_t SiRF_ID2_2P_get_ch6(SiRF_ID2_2P * userdata) { return userdata->ch6; } void SiRF_ID2_2P_set_ch7(SiRF_ID2_2P * userdata, uint8_t ch7) { userdata->ch7 = ch7; } uint8_t SiRF_ID2_2P_get_ch7(SiRF_ID2_2P * userdata) { return userdata->ch7; } void SiRF_ID2_2P_set_ch8(SiRF_ID2_2P * userdata, uint8_t ch8) { userdata->ch8 = ch8; } uint8_t SiRF_ID2_2P_get_ch8(SiRF_ID2_2P * userdata) { return userdata->ch8; } void SiRF_ID2_2P_set_ch9(SiRF_ID2_2P * userdata, uint8_t ch9) { userdata->ch9 = ch9; } uint8_t SiRF_ID2_2P_get_ch9(SiRF_ID2_2P * userdata) { return userdata->ch9; } void SiRF_ID2_2P_set_ch10(SiRF_ID2_2P * userdata, uint8_t ch10) { userdata->ch10 = ch10; } uint8_t SiRF_ID2_2P_get_ch10(SiRF_ID2_2P * userdata) { return userdata->ch10; } void SiRF_ID2_2P_set_ch11(SiRF_ID2_2P * userdata, uint8_t ch11) { userdata->ch11 = ch11; } uint8_t SiRF_ID2_2P_get_ch11(SiRF_ID2_2P * userdata) { return userdata->ch11; } void SiRF_ID2_2P_set_ch12(SiRF_ID2_2P * userdata, uint8_t ch12) { userdata->ch12 = ch12; } uint8_t SiRF_ID2_2P_get_ch12(SiRF_ID2_2P * userdata) { return userdata->ch12; } //Format string generated automatically, //static char formatstring[] = "%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i"; //static char formatstring[] = "%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i"; static char insert_stmt[] = "INSERT into SiRF_ID2_2P (" "result_time," "header_mote_id," "header_seqno," "header_am_type," "header_blockcount," "gps_tow," "sv_in_fix," "ch1," "ch2," "ch3," "ch4," "ch5," "ch6," "ch7," "ch8," "ch9," "ch10," "ch11," "ch12) values (now(), %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"; void SiRF_ID2_2P_pg_log(XbowSensorboardPacket * userdata) { char pg_command[255]; SiRF_ID2_2P * data = (SiRF_ID2_2P*)userdata; sprintf(pg_command,insert_stmt, data->header_mote_id, data->header_seqno, data->header_am_type, data->header_blockcount, data->gps_tow, data->sv_in_fix, data->ch1, data->ch2, data->ch3, data->ch4, data->ch5, data->ch6, data->ch7, data->ch8, data->ch9, data->ch10, data->ch11, data->ch12); #ifdef TELOS_MOTE xdb_execute(pg_command); #endif } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t header_mote_id_convert(uint8_t header_mote_id) { return header_mote_id; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t header_seqno_convert(uint8_t header_seqno) { return header_seqno; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t header_am_type_convert(uint8_t header_am_type) { return header_am_type; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t header_blockcount_convert(uint8_t header_blockcount) { return header_blockcount; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint32_t gps_tow_convert(uint32_t gps_tow) { return gps_tow; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t sv_in_fix_convert(uint8_t sv_in_fix) { return sv_in_fix; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch1_convert(uint8_t ch1) { return ch1; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch2_convert(uint8_t ch2) { return ch2; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch3_convert(uint8_t ch3) { return ch3; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch4_convert(uint8_t ch4) { return ch4; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch5_convert(uint8_t ch5) { return ch5; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch6_convert(uint8_t ch6) { return ch6; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch7_convert(uint8_t ch7) { return ch7; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch8_convert(uint8_t ch8) { return ch8; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch9_convert(uint8_t ch9) { return ch9; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch10_convert(uint8_t ch10) { return ch10; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch11_convert(uint8_t ch11) { return ch11; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch12_convert(uint8_t ch12) { return ch12; } void SiRF_ID2_2P_cook_packet(SiRF_ID2_2P * userdata) { userdata->header_mote_id = header_mote_id_convert(userdata->header_mote_id); userdata->header_seqno = header_seqno_convert(userdata->header_seqno); userdata->header_am_type = header_am_type_convert(userdata->header_am_type); userdata->header_blockcount = header_blockcount_convert(userdata->header_blockcount); userdata->gps_tow = gps_tow_convert(userdata->gps_tow); userdata->sv_in_fix = sv_in_fix_convert(userdata->sv_in_fix); userdata->ch1 = ch1_convert(userdata->ch1); userdata->ch2 = ch2_convert(userdata->ch2); userdata->ch3 = ch3_convert(userdata->ch3); userdata->ch4 = ch4_convert(userdata->ch4); userdata->ch5 = ch5_convert(userdata->ch5); userdata->ch6 = ch6_convert(userdata->ch6); userdata->ch7 = ch7_convert(userdata->ch7); userdata->ch8 = ch8_convert(userdata->ch8); userdata->ch9 = ch9_convert(userdata->ch9); userdata->ch10 = ch10_convert(userdata->ch10); userdata->ch11 = ch11_convert(userdata->ch11); userdata->ch12 = ch12_convert(userdata->ch12); } /** User has to fill in any conversion code * necessary for processing. */ SiRF_ID2_2P * SiRF_ID2_2P_convert(char * data) { // Just to keep gcc happy. return (SiRF_ID2_2P*)data; } /** Print the bytes of the packet. */ void SiRF_ID2_2P_print_raw (XbowSensorboardPacket *packet) { printf("SiRF_ID2_2P print raw.\n"); } /** Print cooked output. */ void SiRF_ID2_2P_print_cooked (XbowSensorboardPacket * userdata) { SiRF_ID2_2P * data = (SiRF_ID2_2P*)userdata; printf("SiRF_ID2_2P print cooked:\n"); printf(" header_mote_id: %i,\n",data->header_mote_id); printf(" header_seqno: %i,\n",data->header_seqno); printf(" header_am_type: %i,\n",data->header_am_type); printf(" header_blockcount: %i,\n",data->header_blockcount); printf(" gps_tow: %i,\n",data->gps_tow); printf(" sv_in_fix: %i,\n",data->sv_in_fix); printf(" ch1: %i,\n",data->ch1); printf(" ch2: %i,\n",data->ch2); printf(" ch3: %i,\n",data->ch3); printf(" ch4: %i,\n",data->ch4); printf(" ch5: %i,\n",data->ch5); printf(" ch6: %i,\n",data->ch6); printf(" ch7: %i,\n",data->ch7); printf(" ch8: %i,\n",data->ch8); printf(" ch9: %i,\n",data->ch9); printf(" ch10: %i,\n",data->ch10); printf(" ch11: %i,\n",data->ch11); printf(" ch12: %i,\n",data->ch12); } #ifdef TELOS_MOTE XPacketHandler SiRF_ID2_2P_packet_handler = { // This should be replaced with the AM_TYPE 151, "$Id: sirf_id2_2.c,v 1.1 2006/07/10 17:16:11 doolin Exp $", SiRF_ID2_2P_print_raw, SiRF_ID2_2P_print_cooked, SiRF_ID2_2P_print_raw, SiRF_ID2_2P_print_cooked, SiRF_ID2_2P_pg_log, {0} }; void SiRF_ID2_2P_initialize() { xpacket_add_type(&SiRF_ID2_2P_packet_handler); } #endif /** The default size of this message type in bytes. */ //static int DEFAULT_MESSAGE_SIZE = 21; /** If incomplete types are used, we need to provide a way * to manage memory. */ SiRF_ID2_2P * SiRF_ID2_2P_new() { SiRF_ID2_2P * userdata = (SiRF_ID2_2P*)malloc(sizeof(SiRF_ID2_2P)); memset((void*)userdata,0xda,sizeof(SiRF_ID2_2P)); return userdata; } void SiRF_ID2_2P_delete(SiRF_ID2_2P * userdata) { memset((void*)userdata,0xdd,sizeof(SiRF_ID2_2P)); free(userdata); } --- NEW FILE: sirf_id2.c --- /** * This class is automatically generated by mig. DO NOT EDIT THIS FILE. * This code implements C interface to the 'SiRF_ID2P' * message type. */ #include <stdio.h> #include <stdlib.h> #include <memory.h> /** Private header is programmer specified for handling * conversion functions, etc. */ //#include "SiRF_ID2P_private.h" /** Not the best way to handle xbow dependencies. */ #ifdef TELOS_MOTE #include "../xdb.h" #include "../xsensors.h" #endif /** These need to be moved to a header file. */ typedef struct _SiRF_ID2P SiRF_ID2P; #ifndef TELOS_MOTE typedef struct _XbowSensorboardPacket XbowSensorboardPacket; #endif /** The Active Message type associated with this message. */ //static const int AM_TYPE = 155; //#define AM_TYPE 155 // This struct is defined to keep gcc happy while the module // is under development. At some point in the near future, a // a convention for passing arguments into the functions will // have to be defined. struct _XbowSensorboardPacket { unsigned char data[29]; }; struct _SiRF_ID2P { uint8_t header_mote_id; uint8_t header_seqno; uint8_t header_am_type; uint8_t header_blockcount; int xpos; int ypos; int zpos; uint16_t xvel; uint16_t yvel; uint16_t zvel; uint8_t mode1; uint8_t dop; uint8_t mode2; uint16_t gps_week; uint32_t gps_tow; uint8_t sv_in_fix; uint8_t ch1; uint8_t ch2; uint8_t ch3; uint8_t ch4; uint8_t ch5; uint8_t ch6; uint8_t ch7; uint8_t ch8; uint8_t ch9; uint8_t ch10; uint8_t ch11; uint8_t ch12; }; void SiRF_ID2P_set_header_mote_id(SiRF_ID2P * userdata, uint8_t header_mote_id) { userdata->header_mote_id = header_mote_id; } uint8_t SiRF_ID2P_get_header_mote_id(SiRF_ID2P * userdata) { return userdata->header_mote_id; } void SiRF_ID2P_set_header_seqno(SiRF_ID2P * userdata, uint8_t header_seqno) { userdata->header_seqno = header_seqno; } uint8_t SiRF_ID2P_get_header_seqno(SiRF_ID2P * userdata) { return userdata->header_seqno; } void SiRF_ID2P_set_header_am_type(SiRF_ID2P * userdata, uint8_t header_am_type) { userdata->header_am_type = header_am_type; } uint8_t SiRF_ID2P_get_header_am_type(SiRF_ID2P * userdata) { return userdata->header_am_type; } void SiRF_ID2P_set_header_blockcount(SiRF_ID2P * userdata, uint8_t header_blockcount) { userdata->header_blockcount = header_blockcount; } uint8_t SiRF_ID2P_get_header_blockcount(SiRF_ID2P * userdata) { return userdata->header_blockcount; } void SiRF_ID2P_set_xpos(SiRF_ID2P * userdata, int xpos) { userdata->xpos = xpos; } int SiRF_ID2P_get_xpos(SiRF_ID2P * userdata) { return userdata->xpos; } void SiRF_ID2P_set_ypos(SiRF_ID2P * userdata, int ypos) { userdata->ypos = ypos; } int SiRF_ID2P_get_ypos(SiRF_ID2P * userdata) { return userdata->ypos; } void SiRF_ID2P_set_zpos(SiRF_ID2P * userdata, int zpos) { userdata->zpos = zpos; } int SiRF_ID2P_get_zpos(SiRF_ID2P * userdata) { return userdata->zpos; } void SiRF_ID2P_set_xvel(SiRF_ID2P * userdata, uint16_t xvel) { userdata->xvel = xvel; } uint16_t SiRF_ID2P_get_xvel(SiRF_ID2P * userdata) { return userdata->xvel; } void SiRF_ID2P_set_yvel(SiRF_ID2P * userdata, uint16_t yvel) { userdata->yvel = yvel; } uint16_t SiRF_ID2P_get_yvel(SiRF_ID2P * userdata) { return userdata->yvel; } void SiRF_ID2P_set_zvel(SiRF_ID2P * userdata, uint16_t zvel) { userdata->zvel = zvel; } uint16_t SiRF_ID2P_get_zvel(SiRF_ID2P * userdata) { return userdata->zvel; } void SiRF_ID2P_set_mode1(SiRF_ID2P * userdata, uint8_t mode1) { userdata->mode1 = mode1; } uint8_t SiRF_ID2P_get_mode1(SiRF_ID2P * userdata) { return userdata->mode1; } void SiRF_ID2P_set_dop(SiRF_ID2P * userdata, uint8_t dop) { userdata->dop = dop; } uint8_t SiRF_ID2P_get_dop(SiRF_ID2P * userdata) { return userdata->dop; } void SiRF_ID2P_set_mode2(SiRF_ID2P * userdata, uint8_t mode2) { userdata->mode2 = mode2; } uint8_t SiRF_ID2P_get_mode2(SiRF_ID2P * userdata) { return userdata->mode2; } void SiRF_ID2P_set_gps_week(SiRF_ID2P * userdata, uint16_t gps_week) { userdata->gps_week = gps_week; } uint16_t SiRF_ID2P_get_gps_week(SiRF_ID2P * userdata) { return userdata->gps_week; } void SiRF_ID2P_set_gps_tow(SiRF_ID2P * userdata, uint32_t gps_tow) { userdata->gps_tow = gps_tow; } uint32_t SiRF_ID2P_get_gps_tow(SiRF_ID2P * userdata) { return userdata->gps_tow; } void SiRF_ID2P_set_sv_in_fix(SiRF_ID2P * userdata, uint8_t sv_in_fix) { userdata->sv_in_fix = sv_in_fix; } uint8_t SiRF_ID2P_get_sv_in_fix(SiRF_ID2P * userdata) { return userdata->sv_in_fix; } void SiRF_ID2P_set_ch1(SiRF_ID2P * userdata, uint8_t ch1) { userdata->ch1 = ch1; } uint8_t SiRF_ID2P_get_ch1(SiRF_ID2P * userdata) { return userdata->ch1; } void SiRF_ID2P_set_ch2(SiRF_ID2P * userdata, uint8_t ch2) { userdata->ch2 = ch2; } uint8_t SiRF_ID2P_get_ch2(SiRF_ID2P * userdata) { return userdata->ch2; } void SiRF_ID2P_set_ch3(SiRF_ID2P * userdata, uint8_t ch3) { userdata->ch3 = ch3; } uint8_t SiRF_ID2P_get_ch3(SiRF_ID2P * userdata) { return userdata->ch3; } void SiRF_ID2P_set_ch4(SiRF_ID2P * userdata, uint8_t ch4) { userdata->ch4 = ch4; } uint8_t SiRF_ID2P_get_ch4(SiRF_ID2P * userdata) { return userdata->ch4; } void SiRF_ID2P_set_ch5(SiRF_ID2P * userdata, uint8_t ch5) { userdata->ch5 = ch5; } uint8_t SiRF_ID2P_get_ch5(SiRF_ID2P * userdata) { return userdata->ch5; } void SiRF_ID2P_set_ch6(SiRF_ID2P * userdata, uint8_t ch6) { userdata->ch6 = ch6; } uint8_t SiRF_ID2P_get_ch6(SiRF_ID2P * userdata) { return userdata->ch6; } void SiRF_ID2P_set_ch7(SiRF_ID2P * userdata, uint8_t ch7) { userdata->ch7 = ch7; } uint8_t SiRF_ID2P_get_ch7(SiRF_ID2P * userdata) { return userdata->ch7; } void SiRF_ID2P_set_ch8(SiRF_ID2P * userdata, uint8_t ch8) { userdata->ch8 = ch8; } uint8_t SiRF_ID2P_get_ch8(SiRF_ID2P * userdata) { return userdata->ch8; } void SiRF_ID2P_set_ch9(SiRF_ID2P * userdata, uint8_t ch9) { userdata->ch9 = ch9; } uint8_t SiRF_ID2P_get_ch9(SiRF_ID2P * userdata) { return userdata->ch9; } void SiRF_ID2P_set_ch10(SiRF_ID2P * userdata, uint8_t ch10) { userdata->ch10 = ch10; } uint8_t SiRF_ID2P_get_ch10(SiRF_ID2P * userdata) { return userdata->ch10; } void SiRF_ID2P_set_ch11(SiRF_ID2P * userdata, uint8_t ch11) { userdata->ch11 = ch11; } uint8_t SiRF_ID2P_get_ch11(SiRF_ID2P * userdata) { return userdata->ch11; } void SiRF_ID2P_set_ch12(SiRF_ID2P * userdata, uint8_t ch12) { userdata->ch12 = ch12; } uint8_t SiRF_ID2P_get_ch12(SiRF_ID2P * userdata) { return userdata->ch12; } //Format string generated automatically, //static char formatstring[] = "%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i"; //static char formatstring[] = "%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i"; static char insert_stmt[] = "INSERT into SiRF_ID2P (" "result_time," "header_mote_id," "header_seqno," "header_am_type," "header_blockcount," "xpos," "ypos," "zpos," "xvel," "yvel," "zvel," "mode1," "dop," "mode2," "gps_week," "gps_tow," "sv_in_fix," "ch1," "ch2," "ch3," "ch4," "ch5," "ch6," "ch7," "ch8," "ch9," "ch10," "ch11," "ch12) values (now(), %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"; void SiRF_ID2P_pg_log(XbowSensorboardPacket * userdata) { char pg_command[255]; SiRF_ID2P * data = (SiRF_ID2P*)userdata; sprintf(pg_command,insert_stmt, data->header_mote_id, data->header_seqno, data->header_am_type, data->header_blockcount, data->xpos, data->ypos, data->zpos, data->xvel, data->yvel, data->zvel, data->mode1, data->dop, data->mode2, data->gps_week, data->gps_tow, data->sv_in_fix, data->ch1, data->ch2, data->ch3, data->ch4, data->ch5, data->ch6, data->ch7, data->ch8, data->ch9, data->ch10, data->ch11, data->ch12); #ifdef TELOS_MOTE xdb_execute(pg_command); #endif } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t header_mote_id_convert(uint8_t header_mote_id) { return header_mote_id; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t header_seqno_convert(uint8_t header_seqno) { return header_seqno; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t header_am_type_convert(uint8_t header_am_type) { return header_am_type; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t header_blockcount_convert(uint8_t header_blockcount) { return header_blockcount; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static int xpos_convert(int xpos) { return xpos; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static int ypos_convert(int ypos) { return ypos; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static int zpos_convert(int zpos) { return zpos; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t xvel_convert(uint16_t xvel) { return xvel; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t yvel_convert(uint16_t yvel) { return yvel; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t zvel_convert(uint16_t zvel) { return zvel; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t mode1_convert(uint8_t mode1) { return mode1; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t dop_convert(uint8_t dop) { return dop; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t mode2_convert(uint8_t mode2) { return mode2; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t gps_week_convert(uint16_t gps_week) { return gps_week; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint32_t gps_tow_convert(uint32_t gps_tow) { return gps_tow; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t sv_in_fix_convert(uint8_t sv_in_fix) { return sv_in_fix; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch1_convert(uint8_t ch1) { return ch1; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch2_convert(uint8_t ch2) { return ch2; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch3_convert(uint8_t ch3) { return ch3; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch4_convert(uint8_t ch4) { return ch4; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch5_convert(uint8_t ch5) { return ch5; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch6_convert(uint8_t ch6) { return ch6; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch7_convert(uint8_t ch7) { return ch7; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch8_convert(uint8_t ch8) { return ch8; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch9_convert(uint8_t ch9) { return ch9; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch10_convert(uint8_t ch10) { return ch10; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch11_convert(uint8_t ch11) { return ch11; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t ch12_convert(uint8_t ch12) { return ch12; } void SiRF_ID2P_cook_packet(SiRF_ID2P * userdata) { userdata->header_mote_id = header_mote_id_convert(userdata->header_mote_id); userdata->header_seqno = header_seqno_convert(userdata->header_seqno); userdata->header_am_type = header_am_type_convert(userdata->header_am_type); userdata->header_blockcount = header_blockcount_convert(userdata->header_blockcount); userdata->xpos = xpos_convert(userdata->xpos); userdata->ypos = ypos_convert(userdata->ypos); userdata->zpos = zpos_convert(userdata->zpos); userdata->xvel = xvel_convert(userdata->xvel); userdata->yvel = yvel_convert(userdata->yvel); userdata->zvel = zvel_convert(userdata->zvel); userdata->mode1 = mode1_convert(userdata->mode1); userdata->dop = dop_convert(userdata->dop); userdata->mode2 = mode2_convert(userdata->mode2); userdata->gps_week = gps_week_convert(userdata->gps_week); userdata->gps_tow = gps_tow_convert(userdata->gps_tow); userdata->sv_in_fix = sv_in_fix_convert(userdata->sv_in_fix); userdata->ch1 = ch1_convert(userdata->ch1); userdata->ch2 = ch2_convert(userdata->ch2); userdata->ch3 = ch3_convert(userdata->ch3); userdata->ch4 = ch4_convert(userdata->ch4); userdata->ch5 = ch5_convert(userdata->ch5); userdata->ch6 = ch6_convert(userdata->ch6); userdata->ch7 = ch7_convert(userdata->ch7); userdata->ch8 = ch8_convert(userdata->ch8); userdata->ch9 = ch9_convert(userdata->ch9); userdata->ch10 = ch10_convert(userdata->ch10); userdata->ch11 = ch11_convert(userdata->ch11); userdata->ch12 = ch12_convert(userdata->ch12); } /** User has to fill in any conversion code * necessary for processing. */ SiRF_ID2P * SiRF_ID2P_convert(char * data) { // Just to keep gcc happy. return (SiRF_ID2P*)data; } /** Print the bytes of the packet. */ void SiRF_ID2P_print_raw (XbowSensorboardPacket *packet) { printf("SiRF_ID2P print raw.\n"); } /** Print cooked output. */ void SiRF_ID2P_print_cooked (XbowSensorboardPacket * userdata) { SiRF_ID2P * data = (SiRF_ID2P*)userdata; printf("SiRF_ID2P print cooked:\n"); printf(" header_mote_id: %i,\n",data->header_mote_id); printf(" header_seqno: %i,\n",data->header_seqno); printf(" header_am_type: %i,\n",data->header_am_type); printf(" header_blockcount: %i,\n",data->header_blockcount); printf(" xpos: %i,\n",data->xpos); printf(" ypos: %i,\n",data->ypos); printf(" zpos: %i,\n",data->zpos); printf(" xvel: %i,\n",data->xvel); printf(" yvel: %i,\n",data->yvel); printf(" zvel: %i,\n",data->zvel); printf(" mode1: %i,\n",data->mode1); printf(" dop: %i,\n",data->dop); printf(" mode2: %i,\n",data->mode2); printf(" gps_week: %i,\n",data->gps_week); printf(" gps_tow: %i,\n",data->gps_tow); printf(" sv_in_fix: %i,\n",data->sv_in_fix); printf(" ch1: %i,\n",data->ch1); printf(" ch2: %i,\n",data->ch2); printf(" ch3: %i,\n",data->ch3); printf(" ch4: %i,\n",data->ch4); printf(" ch5: %i,\n",data->ch5); printf(" ch6: %i,\n",data->ch6); printf(" ch7: %i,\n",data->ch7); printf(" ch8: %i,\n",data->ch8); printf(" ch9: %i,\n",data->ch9); printf(" ch10: %i,\n",data->ch10); printf(" ch11: %i,\n",data->ch11); printf(" ch12: %i,\n",data->ch12); } #ifdef TELOS_MOTE XPacketHandler SiRF_ID2P_packet_handler = { // This should be replaced with the AM_TYPE 155, "$Id: sirf_id2.c,v 1.1 2006/07/10 17:16:11 doolin Exp $", SiRF_ID2P_print_raw, SiRF_ID2P_print_cooked, SiRF_ID2P_print_raw, SiRF_ID2P_print_cooked, SiRF_ID2P_pg_log, {0} }; void SiRF_ID2P_initialize() { xpacket_add_type(&SiRF_ID2P_packet_handler); } #endif /** The default size of this message type in bytes. */ //static int DEFAULT_MESSAGE_SIZE = 44; /** If incomplete types are used, we need to provide a way * to manage memory. */ SiRF_ID2P * SiRF_ID2P_new() { SiRF_ID2P * userdata = (SiRF_ID2P*)malloc(sizeof(SiRF_ID2P)); memset((void*)userdata,0xda,sizeof(SiRF_ID2P)); return userdata; } void SiRF_ID2P_delete(SiRF_ID2P * userdata) { memset((void*)userdata,0xdd,sizeof(SiRF_ID2P)); free(userdata); } --- NEW FILE: mica2.c --- /** * Handles parsing of mica2 packets. * * @file mica2.c * @author Hu Siquan * @version 2004/4/12 husq Initial version * * Refer to: * - Xbow MTS/MDA Sensor and DataAcquistion Manual * * Copyright (c) 2004 Crossbow Technology, Inc. All rights reserved. * * $Id: mica2.c,v 1.1 2006/07/10 17:16:11 doolin Exp $ */ #include <math.h> #include "../xsensors.h" /** mica2 XMesh packet 1 -- contains serialID information */ typedef struct SerialIDData { uint8_t id[8]; } __attribute__ ((packed)) SerialIDData; typedef struct ConfigData { uint16_t nodeid; uint8_t group; uint8_t rf_power; uint8_t rf_channel; } __attribute__ ((packed)) ConfigData; struct bandItem{ int channel; int band; double freq; } table_cc1k_band[35] ={{0,433,433.002},{1,916,914.998},{2,433,434.845}, {3,916,914.077},{4,315,315.179},{5,433,433.113}, {6,433,433.616},{7,433,434.108},{8,433,434.618}, {9,916,903.018},{10,916,904.023},{11,916,905.003}, {12,916,905.967},{13,916,907.231},{14,916,908.045}, {15,916,908.973},{16,916,909.981},{17,916,911.005}, {18,916,911.971},{19,916,913.024},{20,916,914.077}, {21,916,914.999},{22,916,915.920},{23,916,917.026}, {24,916,918.047},{25,916,918.992},{26,916,919.975}, {27,916,920.923},{28,916,922.017},{29,916,923.030}, {30,916,924.083},{31,916,925.136},{32,916,925.987}, {33,916,926.980},{34,315,315.179}}; int table_433MHz_power[23][2] = {{1,-20},{2,-17},{3,-14},{4,-11},{5,-9},{6,-8},{7,-7},{8,-6},{9,-5}, {10,-4},{11,-3},{12,-2},{14,-1},{15,0},{64,1},{80,2},{96,4},{112,5},{128,6}, {144,7},{192,8},{224,9},{255,10}} ; int table_916MHz_power[21][2] = {{2,-20},{4,-16},{5,-14},{6,-13},{7,-12},{8,-11},{9,-10},{11,-9},{12,-8}, {13,-7},{15,-6},{64,-5},{80,-4},{96,-2},{112,-1},{128,0}, {144,1},{176,2},{192,3},{240,4},{255,5}} ; double getCC1KFreq(int rf_channel){ int i; for(i=0;i<35;i++){ if (table_cc1k_band[i].channel == rf_channel) return table_cc1k_band[i].freq; } return -1.0; // error } int getCC1KDBMfromRTP(int rf_channel,int rf_power) { int i,j,band; band = 0; for(i=0;i<35;i++){ if (table_cc1k_band[i].channel == rf_channel) band = table_cc1k_band[i].band; } if(band==433 || band ==315){ for(j=1;j<23;j++){if(table_433MHz_power[j][0]<rf_power) continue; else {if(j>0) j--;return table_433MHz_power[j][1];}} } if(band==916){ for(j=1;j<21;j++){if(table_916MHz_power[j][0]<rf_power) continue; else {if(j>0) j--;return table_916MHz_power[j][1];}} } return 0xff; } extern XPacketHandler mica2_packet_handler; /** mica2 Specific outputs of raw readings within an XBowSensorboardPacket */ void mica2_print_raw(XbowSensorboardPacket *packet) { switch(packet->packet_id){ case 1:{ SerialIDData *data = (SerialIDData *)packet->data; printf("mica2 id=%02x SerialID = %02x%02x%02x%02x%02x%02x%02x%02x\n", packet->node_id, data->id[0], data->id[1],data->id[2],data->id[3], data->id[4],data->id[5], data->id[6],data->id[7]); break; } case 2:{ ConfigData *data = (ConfigData *)packet->data; printf("mica2 config parameters: nodeid=%04x groupid=%02x rf_power=%02x rf_channel=%02x\n", data->nodeid, data->group,data->rf_power,data->rf_channel); break; } default: break; } } /** mica2 specific display of converted readings from XBowSensorboardPacket */ void mica2_print_cooked(XbowSensorboardPacket *packet) { switch(packet->packet_id){ case 1:{ SerialIDData *data = (SerialIDData *)packet->data; printf("Mica2 id=%02x SerialID information: \n" " CRC code = %02x\n" " Serial Number = %02x%02x%02x%02x%02x%02x\n" " Family Code = %02x\n", packet->node_id, data->id[7],data->id[6],data->id[5], data->id[4], data->id[3],data->id[2],data->id[1],data->id[0]); break; } case 2:{ ConfigData *data = (ConfigData *)packet->data; printf("Mica2 Config parameters: \n" " nodeid=%d groupid=%d " " RF Power=%ddbm; RF Channel=%8.3fMHz\n", data->nodeid, data->group, getCC1KDBMfromRTP(data->rf_channel,data->rf_power),getCC1KFreq(data->rf_channel)); break; } default: break; } printf("\n"); } /** * Logs raw readings to a Postgres database. * * @author Martin Turon * * @version 2004/7/28 mturon Initial revision * */ void mica2_log_raw(XbowSensorboardPacket *packet) { } XPacketHandler mica2_packet_handler = { XTYPE_MICA2, "$Id: mica2.c,v 1.1 2006/07/10 17:16:11 doolin Exp $", mica2_print_raw, mica2_print_cooked, mica2_print_raw, mica2_print_cooked, mica2_log_raw }; void mica2_initialize() { xpacket_add_type(&mica2_packet_handler); } --- NEW FILE: testlink.c --- #include "fireboard.h" void LinkMsg_print_raw(XbowSensorboardPacket *packet); void LinkMsg_print_cooked(XbowSensorboardPacket *packet); void testlink_print_raw(XbowSensorboardPacket *packet) { } void testlink_print_cooked(XbowSensorboardPacket *packet) { } void testlink_log_raw(XbowSensorboardPacket *packet) { } XPacketHandler testlink_packet_handler = { AM_LINKMSG, "$Id: testlink.c,v 1.1 2006/07/10 17:16:11 doolin Exp $", LinkMsg_print_raw, LinkMsg_print_cooked, testlink_print_raw, testlink_print_cooked, testlink_log_raw }; void testlink_initialize() { xpacket_add_type(&testlink_packet_handler); } --- NEW FILE: sirf_id28.c --- /** * This class is automatically generated by mig. DO NOT EDIT THIS FILE. * This code implements C interface to the 'SiRF_ID28P' * message type. */ #include <stdio.h> #include <stdlib.h> #include <memory.h> /** Private header is programmer specified for handling * conversion functions, etc. */ //#include "SiRF_ID28P_private.h" /** Not the best way to handle xbow dependencies. */ #ifdef TELOS_MOTE #include "../xdb.h" #include "../xsensors.h" #endif /** These need to be moved to a header file. */ typedef struct _SiRF_ID28P SiRF_ID28P; #ifndef TELOS_MOTE typedef struct _XbowSensorboardPacket XbowSensorboardPacket; #endif /** The Active Message type associated with this message. */ //static const int AM_TYPE = 156; //#define AM_TYPE 156 // This struct is defined to keep gcc happy while the module // is under development. At some point in the near future, a // a convention for passing arguments into the functions will // have to be defined. struct _XbowSensorboardPacket { unsigned char data[29]; }; struct _SiRF_ID28P { uint8_t header_mote_id; uint8_t header_seqno; uint8_t header_am_type; uint8_t header_blockcount; uint8_t channel; uint32_t time_tag; uint8_t sat_id; uint64_t gps_sw_time; uint64_t pseudo_range; uint32_t carrier_freq; uint64_t carrier_phase; uint16_t time_in_track; uint8_t sync_flags; uint8_t cno1; uint8_t cno2; uint8_t cno3; uint8_t cno4; uint8_t cno5; uint8_t cno6; uint8_t cno7; uint8_t cno8; uint8_t cno9; uint8_t cno10; uint16_t delta_range_interval; uint16_t mean_delta_range_time; uint16_t extrapolation_time; uint8_t phase_error_count; uint8_t low_power_count; }; void SiRF_ID28P_set_header_mote_id(SiRF_ID28P * userdata, uint8_t header_mote_id) { userdata->header_mote_id = header_mote_id; } uint8_t SiRF_ID28P_get_header_mote_id(SiRF_ID28P * userdata) { return userdata->header_mote_id; } void SiRF_ID28P_set_header_seqno(SiRF_ID28P * userdata, uint8_t header_seqno) { userdata->header_seqno = header_seqno; } uint8_t SiRF_ID28P_get_header_seqno(SiRF_ID28P * userdata) { return userdata->header_seqno; } void SiRF_ID28P_set_header_am_type(SiRF_ID28P * userdata, uint8_t header_am_type) { userdata->header_am_type = header_am_type; } uint8_t SiRF_ID28P_get_header_am_type(SiRF_ID28P * userdata) { return userdata->header_am_type; } void SiRF_ID28P_set_header_blockcount(SiRF_ID28P * userdata, uint8_t header_blockcount) { userdata->header_blockcount = header_blockcount; } uint8_t SiRF_ID28P_get_header_blockcount(SiRF_ID28P * userdata) { return userdata->header_blockcount; } void SiRF_ID28P_set_channel(SiRF_ID28P * userdata, uint8_t channel) { userdata->channel = channel; } uint8_t SiRF_ID28P_get_channel(SiRF_ID28P * userdata) { return userdata->channel; } void SiRF_ID28P_set_time_tag(SiRF_ID28P * userdata, uint32_t time_tag) { userdata->time_tag = time_tag; } uint32_t SiRF_ID28P_get_time_tag(SiRF_ID28P * userdata) { return userdata->time_tag; } void SiRF_ID28P_set_sat_id(SiRF_ID28P * userdata, uint8_t sat_id) { userdata->sat_id = sat_id; } uint8_t SiRF_ID28P_get_sat_id(SiRF_ID28P * userdata) { return userdata->sat_id; } void SiRF_ID28P_set_gps_sw_time(SiRF_ID28P * userdata, uint64_t gps_sw_time) { userdata->gps_sw_time = gps_sw_time; } uint64_t SiRF_ID28P_get_gps_sw_time(SiRF_ID28P * userdata) { return userdata->gps_sw_time; } void SiRF_ID28P_set_pseudo_range(SiRF_ID28P * userdata, uint64_t pseudo_range) { userdata->pseudo_range = pseudo_range; } uint64_t SiRF_ID28P_get_pseudo_range(SiRF_ID28P * userdata) { return userdata->pseudo_range; } void SiRF_ID28P_set_carrier_freq(SiRF_ID28P * userdata, uint32_t carrier_freq) { userdata->carrier_freq = carrier_freq; } uint32_t SiRF_ID28P_get_carrier_freq(SiRF_ID28P * userdata) { return userdata->carrier_freq; } void SiRF_ID28P_set_carrier_phase(SiRF_ID28P * userdata, uint64_t carrier_phase) { userdata->carrier_phase = carrier_phase; } uint64_t SiRF_ID28P_get_carrier_phase(SiRF_ID28P * userdata) { return userdata->carrier_phase; } void SiRF_ID28P_set_time_in_track(SiRF_ID28P * userdata, uint16_t time_in_track) { userdata->time_in_track = time_in_track; } uint16_t SiRF_ID28P_get_time_in_track(SiRF_ID28P * userdata) { return userdata->time_in_track; } void SiRF_ID28P_set_sync_flags(SiRF_ID28P * userdata, uint8_t sync_flags) { userdata->sync_flags = sync_flags; } uint8_t SiRF_ID28P_get_sync_flags(SiRF_ID28P * userdata) { return userdata->sync_flags; } void SiRF_ID28P_set_cno1(SiRF_ID28P * userdata, uint8_t cno1) { userdata->cno1 = cno1; } uint8_t SiRF_ID28P_get_cno1(SiRF_ID28P * userdata) { return userdata->cno1; } void SiRF_ID28P_set_cno2(SiRF_ID28P * userdata, uint8_t cno2) { userdata->cno2 = cno2; } uint8_t SiRF_ID28P_get_cno2(SiRF_ID28P * userdata) { return userdata->cno2; } void SiRF_ID28P_set_cno3(SiRF_ID28P * userdata, uint8_t cno3) { userdata->cno3 = cno3; } uint8_t SiRF_ID28P_get_cno3(SiRF_ID28P * userdata) { return userdata->cno3; } void SiRF_ID28P_set_cno4(SiRF_ID28P * userdata, uint8_t cno4) { userdata->cno4 ... [truncated message content] |