[Firebug-cvs] firebug/project/src/FireBug .cvsignore,NONE,1.1 FireBug.nc,NONE,1.1 FireBugM.nc,NONE,1
Brought to you by:
doolin
From: <do...@us...> - 2003-12-17 13:07:59
|
Update of /cvsroot/firebug/firebug/project/src/FireBug In directory sc8-pr-cvs1:/tmp/cvs-serv4212 Added Files: .cvsignore FireBug.nc FireBugM.nc Makefile Log Message: Added firebug files for rewriting application. --- NEW FILE: .cvsignore --- build --- NEW FILE: FireBug.nc --- /* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */ /** * Author: Terence Tong, Alec Woo, Max Min Chen, David M. Doolin */ includes RoutingStack; configuration FireBug { } implementation { components Main, FireBugM, MHSender, LedsC, MicaWbSwitch, VirtualComm, ParentSelection, UARTGpsPacket, TimerWrapper; //Accel; Main.StdControl -> FireBugM.StdControl; FireBugM.MultiHopSend -> MHSender.MultiHopSend[RS_DATA_TYPE]; ParentSelection.InForwardReceive -> VirtualComm.ReceiveMsg[RS_DATA_TYPE]; FireBugM.Timer1 -> TimerWrapper.Timer[unique("Timer")]; FireBugM.Timer2 -> TimerWrapper.Timer[unique("Timer")]; FireBugM.Leds -> LedsC; Main.StdControl -> MHSender.StdControl; // Wiring for gps FireBugM.GpsControl -> UARTGpsPacket; FireBugM.GpsSend -> UARTGpsPacket; FireBugM.GpsReceive -> UARTGpsPacket; FireBugM.GpsCmd -> UARTGpsPacket.GpsCmd; // Wiring for Accelerometer, not yet dealt with in Makelocal #if 0 FireBugM.AccelControl -> Accel.StdControl; FireBugM.AccelCmd -> Accel.AccelCmd; #endif } --- NEW FILE: FireBugM.nc --- /* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil; font-lock-mode: t -*- */ /** * This is an example of a general application using the * Routing Stack to send message to * basestation. It store a message in its frame, * call getUsablePortion to get the right location * to add in its own data. passed the data down * the stack with the send command. A Send done * command will come back. A recomment way to send * another message is to have a one shot * Time. When the clock fired, we make another * attempt to send again. * * @author: Terence Tong, Alec Woo, Max Min Chen */ includes RoutingStack; includes gps; /** FIXME: Move these to the gps.h file. */ #define GPS_MSG_LENGTH 100 #define GPS_CHAR 11 #define GPS_FIELDS 8 #define GPS_CHAR_PER_FIELD 10 #define GPS_DELIMITER ',' #define GPS_END_MSG '*' module FireBugM { provides { interface StdControl; command result_t parseGPS(int8_t gga_string[GPS_MSG_LENGTH], uint8_t length); command result_t logGPS(char gga_fields[GPS_FIELDS][GPS_CHAR_PER_FIELD]); } uses { interface Send as MultiHopSend; interface Timer as Timer1; interface Timer as Timer2; interface Leds; interface I2CSwitchCmds as GpsCmd; interface StdControl as GpsControl; interface BareSendMsg as GpsSend; interface ReceiveMsg as GpsReceive; //Accels #if 0 interface StdControl as AccelControl; interface I2CSwitchCmds as AccelCmd; #endif } } #define DATA_FREQ 10000 implementation { #include "SODebug.h" #include "gps.h" TOS_Msg msgToSend; //GPS_MsgPtr gps_data; struct DataFormat_t { uint16_t addr; uint16_t cnt; float temp; float rel_hum; float baro_pres; }; uint16_t counter; uint8_t sending; char count; bool gps_active; //true if gps is active command result_t StdControl.init() { gps_active = TRUE; init_debug(); call Leds.init(); call GpsControl.init(); //call AccelControl.init(); //initialize accelerometer return SUCCESS; } command result_t StdControl.start() { int i; counter = 0; call GpsControl.start(); SODbg(DBG_USR2, "FireBugM.GpsControl.start() called\n"); call Timer1.start(TIMER_REPEAT, 5000); //if (! call GpsCmd.PowerSwitch(1)) { //turn on GPS power // call Leds.yellowToggle(); // SODbg(DBG_USR2, "Failed to power on gps \n"); //} call Leds.redToggle(); for (i = 0; i < 29; i++) { msgToSend.data[i] = 0; } return SUCCESS; } command result_t StdControl.stop() { return SUCCESS; } event result_t Timer1.fired() { //call GpsCmd.GpsPower(1); SODbg(DBG_USR2, "FireBugM.Timer1.fired()\n"); if (! call GpsCmd.PowerSwitch(1)) { //turn on GPS power call Leds.yellowToggle(); SODbg(DBG_USR2, "Failed to power on gps \n"); } return SUCCESS; } /** * When the clock fired we are ready to send, CollectData ask the stack * where in the data payload we can safely put our data. We then call * Multihop passed the pointer down the stack * * @author: terence * @param: void * @return: always return success */ event result_t Timer2.fired() { uint8_t *dataPortion; uint16_t availableLength = 0; struct DataFormat_t *df; SODbg(DBG_USR2, "FireBugM.Timer2.fired()\n"); if (sending == 1) { return SUCCESS; } dataPortion = call MultiHopSend.getBuffer(&msgToSend, &availableLength); df = (struct DataFormat_t *) dataPortion; df->addr = TOS_LOCAL_ADDRESS; df->cnt = counter++; //df->temp = gps_data->data[0]; //df->rel_hum = gps_data->data[1]; //df->baro_pres = gps_data->data[2]; sending = call MultiHopSend.send(&msgToSend, sizeof(struct DataFormat_t)); return SUCCESS; } /** * When a message is sent, send done event is trigger. We then schedule the * time to generate another message to send * * @author: terence * @param: void * @return: void */ event result_t MultiHopSend.sendDone(TOS_MsgPtr msg, uint8_t success) { sending = 0; call Timer2.stop(); return SUCCESS; } // ************************** //*Packet received from GPS* //************************** // //*The following should be executed in GpsPacket event TOS_MsgPtr GpsReceive.receive(TOS_MsgPtr data) { int8_t gga_string[GPS_MSG_LENGTH]; bool gga_read = FALSE; bool gga_read_done = FALSE; uint16_t i = 0; uint8_t j = 0; uint8_t k = 0; GPS_MsgPtr gps_data = (GPS_MsgPtr)data; SODbg(DBG_USR2, "gps_data:%i,\n", gps_data->length); for (k = 0; k <= gps_data->length ; k++) UARTPutChar(gps_data->data[k]); SODbg(DBG_USR2, "\n"); while (!gga_read_done) { if(gps_data->data[i] == 'G') { if(gps_data->data[i+1] == 'G') { if(gps_data->data[i+2] == 'A') { gga_read = TRUE; } } } if(gps_data->data[i] == GPS_END_MSG) { if(gga_read) { if(call GpsCmd.PowerSwitch(0)) { SODbg(DBG_USR2, "GPS Power Off\n"); } call parseGPS(gga_string, j); gga_read = FALSE; gga_read_done = TRUE; } } if(gga_read) { gga_string[j] = gps_data->data[i]; j++; } i++; } call Leds.greenToggle(); return data; } //**************** //*Parse GPS Data* //**************** //* //* Fields are comma delimited //* NMEA string parsed by field and stored into //* gga_fields array command result_t parseGPS(int8_t gga_string[GPS_MSG_LENGTH], uint8_t length) { char gga_fields[GPS_FIELDS][GPS_CHAR_PER_FIELD]; bool end_of_field = FALSE; uint8_t i=0; uint8_t j,m; uint16_t k=0; //***DEBUG: Output NMEA message*** uint16_t q; SODbg(DBG_USR2, "parse GPS: \n"); for(q=0; q<length; q++) UARTPutChar(gga_string[q]); SODbg(DBG_USR2, "\n"); //******************************** // Parse and store comma delimited fields into EEPROM while (i < GPS_FIELDS) { // assemble gga_fields array end_of_field = FALSE; j = 0; while (!end_of_field & k < length) { if (gga_string[k] == GPS_DELIMITER) { end_of_field = TRUE; } else { gga_fields[i][j] = gga_string[k]; } j++; k++; } // two commas (,,) indicate empty field // if field is empty, set it equal to 0 if (j <= 1) { for (m=0; m<10; m++) gga_fields[i][m] = '0'; } i++; } //call logGPS(gga_fields); return SUCCESS; } // ************** //*Log GGA data* //************** //* //* Assemble GGA message structure from gga_fields //* Store GGA data into line 25 of EEPROM command result_t logGPS(char gga_fields[GPS_FIELDS][GPS_CHAR_PER_FIELD]) { #if 0 GGA_Msg *pGGA; char gga_log_array[GPS_CHAR]; char NS; char EW; uint8_t j; uint8_t nos; // number of satellites // Assemble GGA_Msg pGGA->hours = 10*(gga_fields[1][0]-'0') + (gga_fields[1][1]-'0'); gga_log_array[0] = pGGA->hours; pGGA->minutes = 10*(gga_fields[1][2]-'0') + (gga_fields[1][3]-'0'); gga_log_array[1] = pGGA->minutes; pGGA->dec_sec = 10000*(gga_fields[1][4]-'0') + 1000*(gga_fields[1][5]-'0') + 100*(gga_fields[1][7]-'0') + 10*(gga_fields[1][8]-'0') + (gga_fields[1][9]-'0'); gga_log_array[2] = (pGGA->dec_sec)>>8; // MSB gga_log_array[3] = pGGA->dec_sec; // LSB pGGA->Lat_deg = 10*(gga_fields[2][0]-'0') + (gga_fields[2][1]-'0'); gga_log_array[4] = pGGA->Lat_deg; pGGA->Lat_dec_min = 100000*(gga_fields[2][2]-'0') + 10000*(gga_fields[2][3]-'0') + 1000*(gga_fields[2][4]-'0') + 100*(gga_fields[2][5]-'0') + 10*(gga_fields[2][6]-'0') + (gga_fields[2][7]-'0'); gga_log_array[5] = (pGGA->Lat_dec_min)>>8; gga_log_array[6] = pGGA->Lat_dec_min; pGGA->Long_deg = 100*(gga_fields[4][0]-'0') + 10*(gga_fields[4][1]-'0') + (gga_fields[4][2]-'0'); gga_log_array[7] = pGGA->Long_deg; pGGA->Long_dec_min = 100000*(gga_fields[4][3]-'0') + 10000*(gga_fields[4][4]-'0') + 1000*(gga_fields[4][5]-'0') + 100*(gga_fields[4][6]-'0') + 10*(gga_fields[4][7]-'0') + (gga_fields[4][8]-'0'); gga_log_array[8] = (pGGA->Long_dec_min)>>8; gga_log_array[9] = pGGA->Long_dec_min; NS = (gga_fields[3][0] == 'N') ? 1 : 0; EW = (gga_fields[5][0] == 'W') ? 1 : 0; pGGA->NSEWind = EW | (NS<<4); // eg. Status = 000N000E = 00010000 gga_log_array[10] = pGGA->NSEWind; nos = 10*(gga_fields[7][0]-'0') + (gga_fields[7][1]-'0'); //***DEBUG: Output GGA data before gga_fields*** SODbg(DBG_USR2, "LOGGER GPS:\n"); for(j=0; j<11; j++) UARTPutChar(gga_log_array[j]); SODbg(DBG_USR2, "\n"); //***************************************** #endif return SUCCESS; } /****************************************************************************** * Packet received from GPS - ASCII msg * 1st byte in pkt is number of ascii bytes * async used only for testing *****************************************************************************/ //((((((((((((((This is a alternative way from the above)))))))))))))) /* event TOS_MsgPtr GpsReceive.receive(TOS_MsgPtr data) { //change to GPS packet!! uint8_t i; GPS_MsgPtr gps_data = (GPS_MsgPtr)data; //gps_data = (GPS_MsgPtr)data; call Leds.greenToggle(); //for (i = 0; i <= gps_data->data[0] ; i++) UARTPutChar(gps_data->data[i]); for (i = 0; i <= gps_data->length ; i++) UARTPutChar(gps_data->data[i]); SODbg(DBG_USR2, "\n"); call Timer2.start(TIMER_ONE_SHOT,300); return data; } */ event result_t GpsSend.sendDone(TOS_MsgPtr msg, result_t success) { return SUCCESS; } event result_t GpsCmd.SwitchesSet(uint8_t PowerState){ gps_active = TRUE; call Leds.yellowToggle(); SODbg(DBG_USR2, "Gps power on \n"); return SUCCESS; } #if 0 event result_t AccelCmd.SwitchesSet(uint8_t PowerState){ return SUCCESS; } #endif } --- NEW FILE: Makefile --- COMPONENT=FireBug SENSORBOARD=leadtek9546 include ../Makelocal include $(TOSROOT)/apps/Makerules |