[Firebug-cvs] fireboard/beta/tools/src/xlisten/boards LinkEstimatorMsg.c,NONE,1.1 SurgeMsg.c,NONE,1.
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2005-08-08 17:37:55
|
Update of /cvsroot/firebug/fireboard/beta/tools/src/xlisten/boards In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv403/boards Added Files: LinkEstimatorMsg.c SurgeMsg.c Log Message: Handlers for multihop link estimation. --- NEW FILE: LinkEstimatorMsg.c --- /** * This class is automatically generated by mig. DO NOT EDIT THIS FILE. * This code implements C interface to the 'LinkEstimatorMsgP' * message type. */ #include <stdio.h> #include <stdlib.h> #include <memory.h> /** Private header is programmer specified for handling * conversion functions, etc. */ //#include "LinkEstimatorMsgP_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 _LinkEstimatorMsgP LinkEstimatorMsgP; #ifndef TELOS_MOTE typedef struct _XbowSensorboardPacket XbowSensorboardPacket; #endif /** The Active Message type associated with this message. */ //static const int AM_TYPE = 18; //#define AM_TYPE 18 // 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 _LinkEstimatorMsgP { uint32_t seqno; uint16_t source; uint16_t dest; uint16_t RSSI; uint16_t LQI; uint32_t source_seqno; }; void LinkEstimatorMsgP_set_seqno(LinkEstimatorMsgP * userdata, uint32_t seqno) { userdata->seqno = seqno; } uint32_t LinkEstimatorMsgP_get_seqno(LinkEstimatorMsgP * userdata) { return userdata->seqno; } void LinkEstimatorMsgP_set_source(LinkEstimatorMsgP * userdata, uint16_t source) { userdata->source = source; } uint16_t LinkEstimatorMsgP_get_source(LinkEstimatorMsgP * userdata) { return userdata->source; } void LinkEstimatorMsgP_set_dest(LinkEstimatorMsgP * userdata, uint16_t dest) { userdata->dest = dest; } uint16_t LinkEstimatorMsgP_get_dest(LinkEstimatorMsgP * userdata) { return userdata->dest; } void LinkEstimatorMsgP_set_RSSI(LinkEstimatorMsgP * userdata, uint16_t RSSI) { userdata->RSSI = RSSI; } uint16_t LinkEstimatorMsgP_get_RSSI(LinkEstimatorMsgP * userdata) { return userdata->RSSI; } void LinkEstimatorMsgP_set_LQI(LinkEstimatorMsgP * userdata, uint16_t LQI) { userdata->LQI = LQI; } uint16_t LinkEstimatorMsgP_get_LQI(LinkEstimatorMsgP * userdata) { return userdata->LQI; } void LinkEstimatorMsgP_set_source_seqno(LinkEstimatorMsgP * userdata, uint32_t source_seqno) { userdata->source_seqno = source_seqno; } uint32_t LinkEstimatorMsgP_get_source_seqno(LinkEstimatorMsgP * userdata) { return userdata->source_seqno; } //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 LinkEstimatorMsgP (" "result_time," "seqno," "source," "dest," "RSSI," "LQI," "source_seqno) values (now(), %i, %i, %i, %i, %i, %i)"; void LinkEstimatorMsgP_pg_log(XbowSensorboardPacket * userdata) { char pg_command[255]; LinkEstimatorMsgP * data = (LinkEstimatorMsgP*)userdata; sprintf(pg_command,insert_stmt, data->seqno, data->source, data->dest, data->RSSI, data->LQI, data->source_seqno); #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 uint32_t seqno_convert(uint32_t seqno) { return seqno; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t source_convert(uint16_t source) { return source; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint16_t dest_convert(uint16_t dest) { return dest; } /** @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; } /** @brief Default behavior is to return the input as output. * User is responsible for "cooking" the data. */ static uint32_t source_seqno_convert(uint32_t source_seqno) { return source_seqno; } void LinkEstimatorMsgP_cook_packet(LinkEstimatorMsgP * userdata) { userdata->seqno = seqno_convert(userdata->seqno); userdata->source = source_convert(userdata->source); userdata->dest = dest_convert(userdata->dest); userdata->RSSI = RSSI_convert(userdata->RSSI); userdata->LQI = LQI_convert(userdata->LQI); userdata->source_seqno = source_seqno_convert(userdata->source_seqno); } /** User has to fill in any conversion code * necessary for processing. */ LinkEstimatorMsgP * LinkEstimatorMsgP_convert(char * data) { // Just to keep gcc happy. return (LinkEstimatorMsgP*)data; } /** Print the bytes of the packet. */ void LinkEstimatorMsgP_print_raw (XbowSensorboardPacket *packet) { printf("LinkEstimatorMsgP print raw.\n"); } /** Print cooked output. */ void LinkEstimatorMsgP_print_cooked (XbowSensorboardPacket * userdata) { LinkEstimatorMsgP * data = (LinkEstimatorMsgP*)userdata; printf("LinkEstimatorMsgP print cooked:\n"); printf(" seqno: %i,\n",data->seqno); printf(" source: %i,\n",data->source); printf(" dest: %i,\n",data->dest); printf(" RSSI: %i,\n",data->RSSI); printf(" LQI: %i,\n",data->LQI); printf(" source_seqno: %i,\n",data->source_seqno); } #ifdef TELOS_MOTE XPacketHandler LinkEstimatorMsgP_packet_handler = { // This should be replaced with the AM_TYPE 18, "$Id: LinkEstimatorMsg.c,v 1.1 2005/08/08 17:37:46 doolin Exp $", LinkEstimatorMsgP_print_raw, LinkEstimatorMsgP_print_cooked, LinkEstimatorMsgP_print_raw, LinkEstimatorMsgP_print_cooked, LinkEstimatorMsgP_pg_log, {0} }; void LinkEstimatorMsgP_initialize() { xpacket_add_type(&LinkEstimatorMsgP_packet_handler); } #endif /** The default size of this message type in bytes. */ //static int DEFAULT_MESSAGE_SIZE = 16; /** If incomplete types are used, we need to provide a way * to manage memory. */ LinkEstimatorMsgP * LinkEstimatorMsgP_new() { LinkEstimatorMsgP * userdata = (LinkEstimatorMsgP*)malloc(sizeof(LinkEstimatorMsgP)); memset((void*)userdata,0xda,sizeof(LinkEstimatorMsgP)); return userdata; } void LinkEstimatorMsgP_delete(LinkEstimatorMsgP * userdata) { memset((void*)userdata,0xdd,sizeof(LinkEstimatorMsgP)); free(userdata); } --- 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; uint32_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, uint32_t seq_no) { userdata->seq_no = seq_no; } uint32_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 uint32_t seq_no_convert(uint32_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 2005/08/08 17:37:46 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 = 10; /** 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); } |