[Firebug-cvs] fireboard/beta/tos/sensorboards/mts400 GpsPacket.nc,1.2,1.3
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2005-05-28 00:09:51
|
Update of /cvsroot/firebug/fireboard/beta/tos/sensorboards/mts400 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6481 Modified Files: GpsPacket.nc Log Message: Cleaned up some gps driver code. Index: GpsPacket.nc =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tos/sensorboards/mts400/GpsPacket.nc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GpsPacket.nc 27 May 2005 00:38:32 -0000 1.2 --- GpsPacket.nc 28 May 2005 00:09:40 -0000 1.3 *************** *** 68,73 **** /* This component handles the gps control and packet abstraction */ includes sensorboard; module GpsPacket { ! provides { interface StdControl as Control; interface BareSendMsg as Send; --- 68,75 ---- /* This component handles the gps control and packet abstraction */ includes sensorboard; + module GpsPacket { ! ! provides { interface StdControl as Control; interface BareSendMsg as Send; *************** *** 78,83 **** command result_t txBytes(uint8_t *bytes, uint8_t numBytes); /* Effects: start sending 'numBytes' bytes from 'bytes' */ ! // command result_t GpsPower(uint8_t PowerState); ! // /* 0 => gps power off; 1 => gps power on */ } uses { --- 80,85 ---- command result_t txBytes(uint8_t *bytes, uint8_t numBytes); /* Effects: start sending 'numBytes' bytes from 'bytes' */ ! // command result_t GpsPower(uint8_t PowerState); ! // /* 0 => gps power off; 1 => gps power on */ } uses { *************** *** 96,108 **** #include "gps.h" ! GPS_Msg buffer; ! //GPS_Msg* bufferPtr; ! TOS_MsgPtr bufferPtr; //really a GPS_Msg pointer ! enum {GPS_SWITCH_IDLE, //GPS I2C switches are not using the I2C bus ! GPS_PWR_SWITCH_WAIT, //Waiting for GPS I2C power switch to set ! GPS_EN_SWITCH_WAIT, //Waiting for GPS I2C enable switch to set ! GPS_TX_SWITCH_WAIT, //Waiting for GPS I2C tx switch to set ! GPS_RX_SWITCH_WAIT, //Waiting for GPS I2C rx switch to set ! }; uint8_t state_gps; //state of I2C switches --- 98,110 ---- #include "gps.h" ! GPS_Msg buffer; ! //GPS_Msg* bufferPtr; ! TOS_MsgPtr bufferPtr; //really a GPS_Msg pointer ! enum {GPS_SWITCH_IDLE, //GPS I2C switches are not using the I2C bus ! GPS_PWR_SWITCH_WAIT, //Waiting for GPS I2C power switch to set ! GPS_EN_SWITCH_WAIT, //Waiting for GPS I2C enable switch to set ! GPS_TX_SWITCH_WAIT, //Waiting for GPS I2C tx switch to set ! GPS_RX_SWITCH_WAIT, //Waiting for GPS I2C rx switch to set ! }; uint8_t state_gps; //state of I2C switches *************** *** 121,127 **** PACKET, BYTES, ! NO_GPS_START_BYTE = 0, ! GPS_START_BYTE = 1, ! GPS_BUF_NOT_AVAIL = 2 }; uint8_t state; --- 123,129 ---- PACKET, BYTES, ! NO_GPS_START_BYTE = 0, ! GPS_START_BYTE = 1, ! GPS_BUF_NOT_AVAIL = 2 }; uint8_t state; *************** *** 137,145 **** --- 139,152 ---- packet abstraction. One such example is the UART. + 27 May 2005: This is fine, but why not abstract those functionalities + into different modules to make the code easier to maintain + and debug? -dmd */ + /* Initialization of this component */ command result_t Control.init() { + atomic recPtr = (uint8_t *)&buffer; bufferIndex = 0; *************** *** 158,166 **** command result_t Control.start() { // apply your power management algorithm ! call SwitchControl.start(); ! return call ByteControl.start(); ! } ! /* Command to control the power of the network stack */ command result_t Control.stop() { // apply your power management algorithm --- 165,173 ---- command result_t Control.start() { // apply your power management algorithm ! call SwitchControl.start(); ! return call ByteControl.start(); ! } ! /* Command to control the power of the network stack */ command result_t Control.stop() { // apply your power management algorithm *************** *** 171,182 **** if (txCount == 0) { ! txCount = 1; ! txLength = numBytes; ! sendPtr = bytes; /* send the first byte */ ! if (call ByteComm.txByte(sendPtr[0])) ! return SUCCESS; else ! txCount = 0; } return FAIL; --- 178,189 ---- if (txCount == 0) { ! txCount = 1; ! txLength = numBytes; ! sendPtr = bytes; /* send the first byte */ ! if (call ByteComm.txByte(sendPtr[0])) ! return SUCCESS; else ! txCount = 0; } return FAIL; *************** *** 199,203 **** task void sendDoneFailTask() { atomic{ ! txCount = 0; state = IDLE; } --- 206,210 ---- task void sendDoneFailTask() { atomic{ ! txCount = 0; state = IDLE; } *************** *** 207,211 **** task void sendDoneSuccessTask() { atomic{ ! txCount = 0; state = IDLE; } --- 214,218 ---- task void sendDoneSuccessTask() { atomic{ ! txCount = 0; state = IDLE; } *************** *** 215,219 **** task void sendVarLenFailTask() { atomic{ ! txCount = 0; state = IDLE; } --- 222,226 ---- task void sendVarLenFailTask() { atomic{ ! txCount = 0; state = IDLE; } *************** *** 230,257 **** void sendComplete(result_t success) { ! atomic{ ! if (state == PACKET){ ! TOS_MsgPtr msg = (TOS_MsgPtr)sendPtr; if (success) { /* This is a non-ack based layer */ ! msg->ack = TRUE; ! post sendDoneSuccessTask(); ! } ! else { ! post sendDoneFailTask(); ! } } ! else if (state == BYTES) { ! if (success) { ! post sendVarLenSuccessTask(); } else { ! post sendVarLenFailTask(); } ! } ! else { ! txCount = 0; ! state = IDLE; ! } ! } //atomic } --- 237,265 ---- void sendComplete(result_t success) { ! ! atomic{ ! if (state == PACKET){ ! TOS_MsgPtr msg = (TOS_MsgPtr)sendPtr; if (success) { /* This is a non-ack based layer */ ! msg->ack = TRUE; ! post sendDoneSuccessTask(); ! } ! else { ! post sendDoneFailTask(); ! } } ! else if (state == BYTES) { ! if (success) { ! post sendVarLenSuccessTask(); ! } ! else { ! post sendVarLenFailTask(); ! } } else { ! txCount = 0; ! state = IDLE; } ! } //atomic } *************** *** 268,326 **** /* Byte level component signals it is ready to accept the next byte. Send the next byte if there are data pending to be sent */ ! async event result_t ByteComm.txByteReady(bool success) { ! atomic{ ! if (txCount > 0){ ! if (!success){ ! dbg(DBG_ERROR, "TX_packet failed, TX_byte_failed"); ! sendComplete(FAIL); ! } ! else if (txCount < txLength){ ! dbg(DBG_PACKET, "PACKET: byte sent: %x, COUNT: %d\n", ! sendPtr[txCount], txCount); ! if (!call ByteComm.txByte(sendPtr[txCount++])) sendComplete(FAIL); ! } ! } ! } //atomic return SUCCESS; } ! async event result_t ByteComm.txDone() { ! atomic{ ! if (txCount == txLength) ! sendComplete(TRUE); } return SUCCESS; } ! /****************************************************************************** ! * Signal gps buffer avail ! * Only one buffer ! *****************************************************************************/ task void receiveTask() { ! bufferPtr = signal Receive.receive(bufferPtr); //no pointer change on return ! atomic state_gps_pkt = NO_GPS_START_BYTE; ! } ! /****************************************************************************** ! * Byte received from GPS ! * First byte in gps packet is reserved to count number of bytes rcvd. ! * Gps messages start with '$' (0x24) and end with <cr><lf> (0x0D, 0x0A) ! *****************************************************************************/ async event result_t ByteComm.rxByteReady(uint8_t data, bool error, ! uint16_t strength) { ! // SODbg(DBG_USR2, "PACKET: byte arrived: %x, COUNT: %i\n", data, rxCount); ! if (error){ ! rxCount = 0; ! return FAIL; ! } ! //if gps buffer not avail if (state_gps_pkt == GPS_BUF_NOT_AVAIL) return SUCCESS; ! if ((state_gps_pkt == NO_GPS_START_BYTE) && (data != GPS_PACKET_START)){ ! rxCount = 1; ! return SUCCESS; } else{ ! state_gps_pkt = GPS_START_BYTE; } --- 276,334 ---- /* Byte level component signals it is ready to accept the next byte. Send the next byte if there are data pending to be sent */ ! async event result_t ByteComm.txByteReady(bool success) { ! atomic{ ! if (txCount > 0){ ! if (!success){ ! dbg(DBG_ERROR, "TX_packet failed, TX_byte_failed"); ! sendComplete(FAIL); ! } ! else if (txCount < txLength){ ! dbg(DBG_PACKET, "PACKET: byte sent: %x, COUNT: %d\n", ! sendPtr[txCount], txCount); ! if (!call ByteComm.txByte(sendPtr[txCount++])) sendComplete(FAIL); ! } ! } ! } //atomic return SUCCESS; } ! async event result_t ByteComm.txDone() { ! atomic{ ! if (txCount == txLength) ! sendComplete(TRUE); } return SUCCESS; } ! /****************************************************************************** ! * Signal gps buffer avail ! * Only one buffer ! *****************************************************************************/ task void receiveTask() { ! bufferPtr = signal Receive.receive(bufferPtr); //no pointer change on return ! atomic state_gps_pkt = NO_GPS_START_BYTE; ! } ! /****************************************************************************** ! * Byte received from GPS ! * First byte in gps packet is reserved to count number of bytes rcvd. ! * Gps messages start with '$' (0x24) and end with <cr><lf> (0x0D, 0x0A) ! *****************************************************************************/ async event result_t ByteComm.rxByteReady(uint8_t data, bool error, ! uint16_t strength) { ! // SODbg(DBG_USR2, "PACKET: byte arrived: %x, COUNT: %i\n", data, rxCount); ! if (error){ ! rxCount = 0; ! return FAIL; ! } ! //if gps buffer not avail if (state_gps_pkt == GPS_BUF_NOT_AVAIL) return SUCCESS; ! if ((state_gps_pkt == NO_GPS_START_BYTE) && (data != GPS_PACKET_START)){ ! rxCount = 1; ! return SUCCESS; } else{ ! state_gps_pkt = GPS_START_BYTE; } *************** *** 328,351 **** recPtr[0] = rxCount; ! if (rxCount == GPS_DATA_LENGTH ){ ! SODbg(DBG_USR2, "gps packet too large- flushed \n"); state_gps_pkt = NO_GPS_START_BYTE; ! return SUCCESS; } ! if (data == GPS_PACKET_END2 ){ ! state_gps_pkt = GPS_BUF_NOT_AVAIL; rxCount = 1; ! post receiveTask(); ! return SUCCESS; } ! // bufferIndex = bufferIndex ^ 1; ! // recPtr = (uint8_t*)bufferPtr; ping pong buffers !!!!!!!!!!!!!!!!!! ! // SODbg(DBG_USR2, "got gps packet; # of bytes = %i \n", rxCount); ! // rxCount = 0; ! // post receiveTask(); ! // return FAIL; //} --- 336,359 ---- recPtr[0] = rxCount; ! if (rxCount == GPS_DATA_LENGTH ){ ! SODbg(DBG_USR2, "gps packet too large- flushed \n"); state_gps_pkt = NO_GPS_START_BYTE; ! return SUCCESS; } ! if (data == GPS_PACKET_END2 ){ ! state_gps_pkt = GPS_BUF_NOT_AVAIL; rxCount = 1; ! post receiveTask(); ! return SUCCESS; } ! // bufferIndex = bufferIndex ^ 1; ! // recPtr = (uint8_t*)bufferPtr; ping pong buffers !!!!!!!!!!!!!!!!!! ! // SODbg(DBG_USR2, "got gps packet; # of bytes = %i \n", rxCount); ! // rxCount = 0; ! // post receiveTask(); ! // return FAIL; //} *************** *** 353,365 **** } ! /****************************************************************************** ! * Turn Gps on/off ! * PowerState = 0 then GPS power off, GPS enable off ! * = 1 then GPS power on, GPS enable on ! * NOTE - GPS switching power supply is enabled by a lo, disabled by a hi ! *****************************************************************************/ ! command result_t GpsCmd.PowerSwitch(uint8_t PowerState){ if (state_gps == GPS_SWITCH_IDLE){ ! power_gps = PowerState; if (power_gps){ if (call Switch1.set(MICAWB_GPS_POWER,0) == SUCCESS) state_gps = GPS_PWR_SWITCH_WAIT; --- 361,373 ---- } ! /****************************************************************************** ! * Turn Gps on/off ! * PowerState = 0 then GPS power off, GPS enable off ! * = 1 then GPS power on, GPS enable on ! * NOTE - GPS switching power supply is enabled by a lo, disabled by a hi ! *****************************************************************************/ ! command result_t GpsCmd.PowerSwitch(uint8_t PowerState){ if (state_gps == GPS_SWITCH_IDLE){ ! power_gps = PowerState; if (power_gps){ if (call Switch1.set(MICAWB_GPS_POWER,0) == SUCCESS) state_gps = GPS_PWR_SWITCH_WAIT; *************** *** 371,387 **** } return FAIL; ! } ! // Power or Enabled switch set event result_t Switch1.setDone(bool local_result) { if (state_gps == GPS_PWR_SWITCH_WAIT) { ! if (call Switch1.set(MICAWB_GPS_ENABLE ,power_gps) == SUCCESS) { ! state_gps = GPS_EN_SWITCH_WAIT; } } else if (state_gps == GPS_EN_SWITCH_WAIT) { ! signal GpsCmd.PowerSet(power_gps); ! state_gps = GPS_SWITCH_IDLE; } --- 379,395 ---- } return FAIL; ! } ! // Power or Enabled switch set event result_t Switch1.setDone(bool local_result) { if (state_gps == GPS_PWR_SWITCH_WAIT) { ! if (call Switch1.set(MICAWB_GPS_ENABLE ,power_gps) == SUCCESS) { ! state_gps = GPS_EN_SWITCH_WAIT; } } else if (state_gps == GPS_EN_SWITCH_WAIT) { ! signal GpsCmd.PowerSet(power_gps); ! state_gps = GPS_SWITCH_IDLE; } *************** *** 390,427 **** } ! event result_t Switch1.getDone(char value) { return SUCCESS; } ! /****************************************************************************** ! * Turn Gps Rx,Tx signals on/off ! * state = 0 then tx and rx disabled ! * = 1 then tx and rx enabled ! * NOTE - rx,tx share pressure lines. ! *****************************************************************************/ ! command result_t GpsCmd.TxRxSwitch(uint8_t rtstate){ power_gps = rtstate; if (state_gps == GPS_SWITCH_IDLE){ if (call SwitchI2W.set( MICAWB_GPS_TX_SELECT ,power_gps) == SUCCESS) { ! state_gps = GPS_TX_SWITCH_WAIT; return SUCCESS; } } ! return FAIL; ! } ! // Tx or Rx switch set event result_t SwitchI2W.setDone(bool local_result) { if (state_gps == GPS_TX_SWITCH_WAIT) { if (call SwitchI2W.set( MICAWB_GPS_RX_SELECT ,power_gps) == SUCCESS) { ! state_gps = GPS_RX_SWITCH_WAIT; } } else if (state_gps == GPS_RX_SWITCH_WAIT) { ! SODbg(DBG_USR2, "GpsPacket: all switches set \n"); ! state_gps = GPS_SWITCH_IDLE; ! signal GpsCmd.TxRxSet(power_gps); } --- 398,435 ---- } ! event result_t Switch1.getDone(char value) { return SUCCESS; } ! /****************************************************************************** ! * Turn Gps Rx,Tx signals on/off ! * state = 0 then tx and rx disabled ! * = 1 then tx and rx enabled ! * NOTE - rx,tx share pressure lines. ! *****************************************************************************/ ! command result_t GpsCmd.TxRxSwitch(uint8_t rtstate){ power_gps = rtstate; if (state_gps == GPS_SWITCH_IDLE){ if (call SwitchI2W.set( MICAWB_GPS_TX_SELECT ,power_gps) == SUCCESS) { ! state_gps = GPS_TX_SWITCH_WAIT; return SUCCESS; } } ! return FAIL; ! } ! // Tx or Rx switch set event result_t SwitchI2W.setDone(bool local_result) { if (state_gps == GPS_TX_SWITCH_WAIT) { if (call SwitchI2W.set( MICAWB_GPS_RX_SELECT ,power_gps) == SUCCESS) { ! state_gps = GPS_RX_SWITCH_WAIT; } } else if (state_gps == GPS_RX_SWITCH_WAIT) { ! SODbg(DBG_USR2, "GpsPacket: all switches set \n"); ! state_gps = GPS_SWITCH_IDLE; ! signal GpsCmd.TxRxSet(power_gps); } |