[Firebug-cvs] fireboard/beta/apps/GPStest TestMTS400M.nc,NONE,1.1
Brought to you by:
doolin
From: Michael N. <mne...@us...> - 2005-09-08 23:57:26
|
Update of /cvsroot/firebug/fireboard/beta/apps/GPStest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22553 Added Files: TestMTS400M.nc Log Message: Created --- NEW FILE: TestMTS400M.nc --- /****************************************************************************** * Controls GPS for testing purposes. This is an isolated test of the * GPS. * * NOTES: * -Intersema pressure sensor control lines are shared with gps control lines * -Cannot enable gps rx/tx and intersema at same time * * Strategy: * 1. Turn on gps power and leave on * 2. Continuously report GPS packets as they come from the GPS. * 3. A timer fires periodically. When a counted number of timer events * occurs reconfigure the GPS by sending a message to the GPS. After an * additional counted number of timer events reconfigure the GPS back. * * "Copyright (c) 2005 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Author: Michael Newman * * Modification History: * 8Sep05 MJNewman: Created. *****************************************************************************/ #include "appFeatures.h" module TestMTS400M { provides interface StdControl; uses { //communication interface StdControl as CommControl; #ifdef MTS420 //gps // interface I2CSwitchCmds as GpsCmd; interface GpsCmd; interface StdControl as GpsControl; interface SendVarLenPacket as GpsSend; interface ReceiveMsg as GpsReceive; #endif interface NMEA as nmea; interface Timer; interface Leds; } } implementation { #define TIMER_PERIOD 1000 // timer period in msec // Turn on to send a message every Minute or so that tell the GPS to // turn on or off one of the GPS messages. This allows testing to see // if messages are making it out to the GPS. #ifndef NMEA_MESSAGE_TESTING #define NMEA_MESSAGE_TESTING 0 #endif #define MIN(_a,_b) ((_a < _b) ? _a : _b) #include "SODebug.h" #include "gps.h" #include "NMEA.h" enum { GPSstateUnknown, GPSstateStart, GPSstatePowerOn, GPSstateReady, } GPSstate; static void dumpGPSstate() { switch (GPSstate) { default: case GPSstateUnknown: SODbg(DBG_USR2, "?GPSstate %d?\n",GPSstate); break; case GPSstateStart: SODbg(DBG_USR2,"GPSstateStart\n"); break; case GPSstatePowerOn: SODbg(DBG_USR2,"GPSstatePowerOn\n"); break; case GPSstateReady: SODbg(DBG_USR2,"GPSstateReady\n"); break; } return; } #if NMEA_MESSAGE_TESTING // Test code to determine if messages can be sent to the GPS. MJNewman // 15Aug05 //#define NMEA_ENABLE "$PSRF103,05,00,01,01*20\r\n" //VTG on //#define NMEA_DISABLE "$PSRF103,05,00,00,01*21\r\n" //VTG off //#define NMEA_ENABLE "$PSRF103,00,00,02,01*26\r\n" //GGA on 2 sec //#define NMEA_ENABLE "$PSRF103,00,00,08,01*2C\r\n" //GGA on 8 sec #define NMEA_ENABLE "\r\n\r\n$PSRF103,01,00,01,01*24\r\n" //GLL on #define NMEA_ENABLE_LENGTH strlen(NMEA_ENABLE) #define NMEA_DISABLE "\r\n\r\n$PSRF103,01,00,00,01*25\r\n" //GLL off #define NMEA_DISABLE_LENGTH strlen(NMEA_DISABLE) #if 0 #define CHANGE_TO_SIRF_MODE "$PSRF100,0,4800,8,1,0*0F\r\n" #define CHANGE_TO_SIRF_LENGTH strlen(CHANGE_TO_SIRF_MODE) static const uint8_t const CHANGE_TO_NMEA_MODE[] = { 0xA0, 0xA2, 0x00, 0x18, 0x81, 0x02, 0x01, 0x01, 0x00, 0x01, 0x05, 0x01, 0x05, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x12, 0xC0, 0x01, 0x6A, 0xB0, 0xB3 }; #define CHANGE_TO_NMEA_LENGTH sizeof(CHANGE_TO_NMEA_MODE) #define NMEA_ENABLE CHANGE_TO_NMEA_MODE #define NMEA_ENABLE_LENGTH CHANGE_TO_NMEA_LENGTH #define NMEA_DISABLE CHANGE_TO_SIRF_MODE #define NMEA_DISABLE_LENGTH strlen(CHANGE_TO_SIRF_MODE) #endif // send message to the GPS to enable VTG messages on a 1 second cycle task void enableNMEAmessage() { #if 0 readStep_t localStep; atomic localStep = readStep; if (localStep != GPS_REQUESTED) { // Wait until GPS is safely on post enableNMEAmessage(); return; }; #endif if ( call GpsSend.send((char *)NMEA_ENABLE , NMEA_ENABLE_LENGTH) == SUCCESS) { SODbg(DBG_USR2,"GPS ENable NMEA\n"); return; }; post enableNMEAmessage(); return; } #endif event result_t GpsSend.sendDone(uint8_t *sendPtr, result_t status) { #if NMEA_MESSAGE_TESTING // SODbg(DBG_USR2, "GPS %s commanded: %s",((status == SUCCESS) ? "OK" : "FAIL"),(char *)sendPtr); #endif return SUCCESS; } #if NMEA_MESSAGE_TESTING task void disableNMEAmessage() { #if 0 readStep_t localStep; atomic localStep = readStep; if (localStep != GPS_REQUESTED) { // Wait until GPS is safely on post enableNMEAmessage(); return; }; #endif if ( call GpsSend.send(NMEA_DISABLE, NMEA_DISABLE_LENGTH) == SUCCESS) { SODbg(DBG_USR2,"GPS DISable NMEA\n"); return; } post disableNMEAmessage(); return; } #endif command result_t StdControl.init() { atomic { GPSstate = GPSstateStart; } call Leds.init(); call Leds.greenOn(); #ifdef MTS420 call GpsControl.init(); #endif SODbg(DBG_USR2,"InitComplete\n"); return SUCCESS; } command result_t StdControl.start() { SODbg(DBG_USR2,"Starting GPS\n"); #ifdef MTS420 call GpsControl.start(); #endif call Timer.start(TIMER_REPEAT, TIMER_PERIOD); //start up sensor measurements return SUCCESS; } static void dumpGPSmsg(char *string,int length) { #if 1 if (string[0] == '$') { // echo the GPS message int i; for (i=0;i < length;i += 1) { SODbg(DBG_USR2, "%c",string[i]); if (string[i] == '*') break; }; SODbg(DBG_USR2, "\n"); }; #endif return; } command result_t StdControl.stop() { #ifdef MTS420 call GpsControl.stop(); call GpsCmd.TxRxSwitch(0); // ???timing of switch setting call GpsCmd.PowerSwitch(0); #endif call Timer.stop(); call CommControl.stop(); return SUCCESS; } /****************************************************************************** * Timer fired, test GPS, humidity/temp * async for test only *****************************************************************************/ event result_t Timer.fired() { switch (GPSstate) { default: case GPSstateUnknown: dumpGPSstate(); GPSstate = GPSstateStart; //... case GPSstateStart: SODbg(DBG_USR2, "Turn GPS power ON\n"); if (call GpsCmd.PowerSwitch(1) != SUCCESS) { SODbg(DBG_USR2, "PowerSwitch failed wait for retry\n"); }; return SUCCESS; case GPSstatePowerOn: SODbg(DBG_USR2, "Turn GPS switches ON\n"); if (call GpsCmd.TxRxSwitch(1) != SUCCESS) { SODbg(DBG_USR2, "TxRxSwitch failed wait for retry\n"); }; return SUCCESS; case GPSstateReady: break; }; call Leds.redToggle(); #if NMEA_MESSAGE_TESTING { static uint8_t cycleCount; cycleCount += 1; if (cycleCount == 5) { SODbg(DBG_USR2, "Trying NMEA On\n"); post enableNMEAmessage(); return SUCCESS; }; if (cycleCount == 30) { SODbg(DBG_USR2, "Trying NMEA OFF\n"); post disableNMEAmessage(); return SUCCESS; }; if (cycleCount >= 60) { cycleCount = 0; }; } #endif // NMEA_MESSAGE_TESTING return SUCCESS; } #ifdef MTS420 // When a packet is received from the GPS we retain a pointer to // that packet and hand a pointer to another buffer back to the // lower level. Each sucessive message swaps buffers, establishing // a double buffering scheme. static GPS_Msg gpsData; // contributed buffer for double buffering static GPS_Msg *pGPSdata = &gpsData; // buffer to dump // Report and handle the content of a message that came in from the // GPS and is stored inpGGAdata. task void handleGPSmessage() { char * leadtek_string; // if gps have been scaned then stop receiving gps uart packet leadtek_string = pGPSdata->data; if (leadtek_string[0] == '$') { dumpGPSmsg(leadtek_string,MIN(sizeof(pGPSdata->data),pGPSdata->length)); #if 0 if (is_gga_string_m(leadtek_string)) { call nmea.gga_parse(gga_data_ptr, leadtek_string); } else if (is_gsa_string(pGPSdata->data)) { call nmea.gsa_parse(gsa_data_ptr, leadtek_string); } else if (is_gva_string(data)) { call nmea.gsv_parse(gsv_data_ptr, leadtek_string); } else if (is_gll_string(data)) { call nmea.gll_parse(gll_data_ptr, leadtek_string); } else if (is_rmc_string(data)) { call nmea.rmc_parse(rmc_data_ptr, leadtek_string); } else if (is_vtg_string(data)) { call nmea.vtg_parse(vtg_data_ptr, leadtek_string); } else if (is_mss_string(data)) { call nmea.mss_parse(mss_data_ptr, leadtek_string); } else if (is_ltc_string(data)) { call nmea.ltc_parse(ltc_data_ptr, leadtek_string); } else { // signal error }; #endif }; if (leadtek_string[0] == (char)0xA0) { #if 1 //??? remove when the rest of the Sirf code is available SODbg(DBG_USR2,"SIRF Packet\n"); #else uint8_t sirftype; sirftype = sirf.get_type(data); switch sirftype { case SIRF2: call sirf.id2_parse(leadtek_string); break; case SIRF28: call sirf.id28_parse(leadtek_string); break; default: // Unexpected SIRF type, this might be normal it // also might want to signal an error. break; }; #endif }; } // A gps message has been collected from the receiver. Log it and // set off a task to report it. // // Inputs: // pData really a pointer to a GGA_data block // Returns: // new buffer for lower level to use event TOS_MsgPtr GpsReceive.receive(TOS_MsgPtr pData) { GPS_Msg *pTemp; pTemp = pGPSdata; pGPSdata = (GPS_Msg *)pData; post handleGPSmessage(); return (TOS_MsgPtr)pTemp; } // Log the power condition reported by the GPS so we can test it // later. event result_t GpsCmd.PowerSet(uint8_t PowerState){ SODbg(DBG_USR2,"GPS power %s\n",(PowerState) ? "ON" : "OFF"); if (PowerState) { GPSstate += 1; }; dumpGPSstate(); return SUCCESS; } event result_t GpsCmd.TxRxSet(uint8_t rtstate) { // gps tx/rx switches set to on or off SODbg(DBG_USR2,"GPS switches %s\n",(rtstate) ? "ON" : "OFF"); if (rtstate) { GPSstate += 1; }; dumpGPSstate(); return SUCCESS; } #endif // defined(MTS420) } |