[Firebug-cvs] fireboard/beta/tools/src/xlisten/ucb Makefile, NONE, 1.1 linkmsg.c, NONE, 1.1 sirf_id
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2006-07-10 18:20:23
|
Update of /cvsroot/firebug/fireboard/beta/tools/src/xlisten/ucb In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv12490 Added Files: Makefile linkmsg.c sirf_id7.c ucb.c ucbtest.c Log Message: . --- NEW FILE: sirf_id7.c --- /** * This class is automatically generated by mig. DO NOT EDIT THIS FILE. * This code implements C interface to the 'SiRF_ID7P' * message type. */ #include <stdio.h> #include <stdlib.h> #include <memory.h> /** Private header is programmer specified for handling * conversion functions, etc. */ //#include "SiRF_ID7P_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_ID7P SiRF_ID7P; #ifndef TELOS_MOTE typedef struct _XbowSensorboardPacket XbowSensorboardPacket; #endif /** The Active Message type associated with this message. */ //static const int AM_TYPE = 158; //#define AM_TYPE 158 // 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_ID7P { uint8_t header_mote_id; uint8_t header_seqno; uint8_t header_am_type; uint8_t header_blockcount; uint32_t clock_bias; uint8_t SV; }; void SiRF_ID7P_set_header_mote_id(SiRF_ID7P * userdata, uint8_t header_mote_id) { userdata->header_mote_id = header_mote_id; } uint8_t SiRF_ID7P_get_header_mote_id(SiRF_ID7P * userdata) { return userdata->header_mote_id; } void SiRF_ID7P_set_header_seqno(SiRF_ID7P * userdata, uint8_t header_seqno) { userdata->header_seqno = header_seqno; } uint8_t SiRF_ID7P_get_header_seqno(SiRF_ID7P * userdata) { return userdata->header_seqno; } void SiRF_ID7P_set_header_am_type(SiRF_ID7P * userdata, uint8_t header_am_type) { userdata->header_am_type = header_am_type; } uint8_t SiRF_ID7P_get_header_am_type(SiRF_ID7P * userdata) { return userdata->header_am_type; } void SiRF_ID7P_set_header_blockcount(SiRF_ID7P * userdata, uint8_t header_blockcount) { userdata->header_blockcount = header_blockcount; } uint8_t SiRF_ID7P_get_header_blockcount(SiRF_ID7P * userdata) { return userdata->header_blockcount; } void SiRF_ID7P_set_clock_bias(SiRF_ID7P * userdata, uint32_t clock_bias) { userdata->clock_bias = clock_bias; } uint32_t SiRF_ID7P_get_clock_bias(SiRF_ID7P * userdata) { return userdata->clock_bias; } void SiRF_ID7P_set_SV(SiRF_ID7P * userdata, uint8_t SV) { userdata->SV = SV; } uint8_t SiRF_ID7P_get_SV(SiRF_ID7P * userdata) { return userdata->SV; } //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 SiRF_ID7P (" "result_time," "header_mote_id," "header_seqno," "header_am_type," "header_blockcount," "clock_bias," "SV) values (now(), %i, %i, %i, %i, %i, %i)"; void SiRF_ID7P_pg_log(XbowSensorboardPacket * userdata) { char pg_command[255]; SiRF_ID7P * data = (SiRF_ID7P*)userdata; sprintf(pg_command,insert_stmt, data->header_mote_id, data->header_seqno, data->header_am_type, data->header_blockcount, data->clock_bias, data->SV); #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 clock_bias_convert(uint32_t clock_bias) { return clock_bias; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint8_t SV_convert(uint8_t SV) { return SV; } void SiRF_ID7P_cook_packet(SiRF_ID7P * 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->clock_bias = clock_bias_convert(userdata->clock_bias); userdata->SV = SV_convert(userdata->SV); } /** User has to fill in any conversion code * necessary for processing. */ SiRF_ID7P * SiRF_ID7P_convert(char * data) { // Just to keep gcc happy. return (SiRF_ID7P*)data; } /** Print the bytes of the packet. */ void SiRF_ID7P_print_raw (XbowSensorboardPacket *packet) { printf("SiRF_ID7P print raw.\n"); } /** Print cooked output. */ void SiRF_ID7P_print_cooked (XbowSensorboardPacket * userdata) { SiRF_ID7P * data = (SiRF_ID7P*)userdata; printf("SiRF_ID7P 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(" clock_bias: %i,\n",data->clock_bias); printf(" SV: %i,\n",data->SV); } #ifdef TELOS_MOTE XPacketHandler SiRF_ID7P_packet_handler = { // This should be replaced with the AM_TYPE 158, "$Id: sirf_id7.c,v 1.1 2006/07/10 18:20:20 doolin Exp $", SiRF_ID7P_print_raw, SiRF_ID7P_print_cooked, SiRF_ID7P_print_raw, SiRF_ID7P_print_cooked, SiRF_ID7P_pg_log, {0} }; void SiRF_ID7P_initialize() { xpacket_add_type(&SiRF_ID7P_packet_handler); } #endif /** The default size of this message type in bytes. */ //static int DEFAULT_MESSAGE_SIZE = 9; /** If incomplete types are used, we need to provide a way * to manage memory. */ SiRF_ID7P * SiRF_ID7P_new() { SiRF_ID7P * userdata = (SiRF_ID7P*)malloc(sizeof(SiRF_ID7P)); memset((void*)userdata,0xda,sizeof(SiRF_ID7P)); return userdata; } void SiRF_ID7P_delete(SiRF_ID7P * userdata) { memset((void*)userdata,0xdd,sizeof(SiRF_ID7P)); free(userdata); } --- NEW FILE: ucb.c --- /** Code in this file represents "plugins" * to the xlisten code produced by xbow. */ #include <stdio.h> #include "../xsensors.h" #include "ucb.h" #define AM_SURGEMSG 17 #define AM_LINKESTIMATORMSG 20 #define AM_PINGMSG 21 static PacketHandler * dispatch_table[256]; void ucb_initialize() { /** TODO: Change this code such that the * each message handling module is queried for * the appropriate handler, which is added to the * xpacket type here. This redudes the dependency * on xbow code in the modules. * Example: * handler = sirfid2_get_handlers(); * xpacket_add_type(handler); */ //fireboard_initialize(); //LinkMsgP_initialize(); //SurgeMsgP_initialize(); //LinkEstimatorMsgP_initialize(); } PacketHandler * fb_get_packet_handler(uint8_t am_type) { return dispatch_table[am_type]; } --- NEW FILE: Makefile --- SRCS = ucb.c LIBSRCS = sirf_id2.c \ sirf_id28.c \ ucbtest: gcc -o ucbtest ucbtest.c $(SRCS) -L../../../gps/SiRF -lsirftest libsirf: gcc -c $(LIBSRCS) ar -q libsirf.a sirf_*.o clean: rm -rf *.exe *.o *~ --- NEW FILE: ucbtest.c --- #include <stdio.h> #include "/home/dave/sf.net/firebug/fireboard/beta/tos/lib/SiRF/sirf.h" // From telos/AM.h. Can't include directly because // bool types aren't supported in C. typedef struct TOS_Msg { /* The following fields are transmitted/received on the radio. */ uint8_t length; uint8_t fcfhi; uint8_t fcflo; uint8_t dsn; uint16_t destpan; uint16_t addr; uint8_t type; uint8_t group; int8_t data[TOSH_DATA_LENGTH]; /* The following fields are not actually transmitted or received * on the radio! They are used for internal accounting only. * The reason they are in this structure is that the AM interface * requires them to be part of the TOS_Msg that is passed to * send/receive operations. */ uint8_t strength; uint8_t lqi; char crc; char ack; uint16_t time; } __attribute((packed)) TOS_Msg; // From MultuHop.h in MultiHopLQI. Can't // include the header file directly because it // includes AM.h, which won't compile in C. typedef struct MultihopMsg { uint16_t sourceaddr; uint16_t originaddr; int16_t seqno; int16_t originseqno; uint16_t hopcount; uint8_t data[(TOSH_DATA_LENGTH - 10)]; } TOS_MHopMsg; #define AM_MULTIHOPMSG 250 #define AM_FRAGMENT 251 /** General outline: * * 1. Create a TOS Msg with a regular payload, parse that * successfully. * * 2. Create a MultiHopMsg with a payload, and parse that successfully. * * 3. Parse a TOS msg that contains a MH msg with a payload. * * 4. Add fragments to the above. */ static TOS_Msg tosmsg = {0x0}; typedef struct payload { int int1; int int2; } payload_t; void parse_tos_message() { tosmsg.length = sizeof(TOS_Msg); tosmsg.fcfhi = 1; tosmsg.fcflo = 2; tosmsg.dsn = 3; tosmsg.destpan = 4; tosmsg.addr = 5; tosmsg.type = 6; tosmsg.group = 7; //tosmsg.data; // already zeroed. /* The following fields are not actually transmitted or received * on the radio! They are used for internal accounting only. * The reason they are in this structure is that the AM interface * requires them to be part of the TOS_Msg that is passed to * send/receive operations. */ tosmsg.strength = 100; tosmsg.lqi = 101; tosmsg.crc = 0; tosmsg.ack = 0; tosmsg.time = 103; // Grab the AM_TYPE // Invoke the print handler callback. } void parse_mh_message() { } void parse_tos_mh_message() { } void parse_tos_mh_frag_message() { } void print_surge_message() { } void print_payload_message() { } /** TODO: Next test: fill a struct, then pack that struct * and unpack a copy of it, then compare the two structs * for field-wise equality. We will need field-wise testing * testing to make sure that the bytes line up between * a struct packed on a mote and a struct unpacked on * a pc using a typedef. */ int main() { uint8_t * sirfid2; SiRF_ID2_t * sid2; printf("TOSH_DATA_LENGTH: %d\n", TOSH_DATA_LENGTH); sirfid2 = get_sirfid2_example(); sid2 = parse_sirfid2 (sirfid2); //SiRF_ID2P_print_cooked(sid2); return 0; } --- 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 18:20:20 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); } |