[Firebug-cvs] fireboard/sensors/leadtek9546 GpsPacketM.nc,1.2,1.3 Makefile,1.1,1.2 gps_driverM.nc,1.
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2004-08-30 16:58:27
|
Update of /cvsroot/firebug/fireboard/sensors/leadtek9546 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5882 Modified Files: GpsPacketM.nc Makefile gps_driverM.nc leadtek_9546.c leadtek_9546.h Log Message: Moving in code from outside of tree. Index: leadtek_9546.h =================================================================== RCS file: /cvsroot/firebug/fireboard/sensors/leadtek9546/leadtek_9546.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** leadtek_9546.h 26 Mar 2004 00:39:27 -0000 1.6 --- leadtek_9546.h 30 Aug 2004 16:58:15 -0000 1.7 *************** *** 1,2 **** --- 1,8 ---- + + #ifndef LEADTEK_9546_H + #define LEADTEK_9546_H + + #include <inttypes.h> + /* tab:4 * *************** *** 77,84 **** - #ifndef LEADTEK_9546_H - #define LEADTEK_9546_H ! const uint8_t LEADTEK_POWER_ON = 1; --- 83,88 ---- ! //const uint8_t LEADTEK_POWER_ON = 1; *************** *** 93,101 **** #define GPS_END_MSG '*' #define GPS_DATA_LENGTH 128 - #define GPS_PACKET_START 0x24 //start of gps packet #define GPS_PACKET_END1 0x0D //penultimate byte of NMEA string #define GPS_PACKET_END2 0x0A //ultimate byte of NMEA string // Carriage return, ASCII 13 --- 97,107 ---- #define GPS_END_MSG '*' + #ifndef GPS_DATA_LENGTH #define GPS_DATA_LENGTH 128 #define GPS_PACKET_START 0x24 //start of gps packet #define GPS_PACKET_END1 0x0D //penultimate byte of NMEA string #define GPS_PACKET_END2 0x0A //ultimate byte of NMEA string + #endif + // Carriage return, ASCII 13 *************** *** 127,131 **** #define GPS_POWER_ON 1 ! const uint8_t gps_power_on = 0; --- 133,137 ---- #define GPS_POWER_ON 1 ! //const uint8_t gps_power_on = 0; *************** *** 135,138 **** --- 141,145 ---- * FIXME: Find out what leadtek uses for a proprietary header string. */ + /* const uint8_t gps_gga_mask[] = {"$LTC,NMEA," NMEA_GGA_MASK NMEA_END1 NMEA_END2}; const uint8_t gps_rmc_mask[] = {"$LTC,NMEA," NMEA_RMC_MASK NMEA_END1 NMEA_END2}; *************** *** 145,184 **** const uint8_t vtg_disable[] = {" ""$PSRF103,05,00,00,01*21" NMEA_END1 NMEA_END2}; - //typedef struct _gga_msg GGA_Msg; - typedef struct _gps_msg GPS_Msg; typedef GPS_Msg * GPS_MsgPtr; - struct _gps_msg { - - /* The following fields are received on the gps. */ uint8_t length; int8_t data[GPS_DATA_LENGTH]; uint16_t crc; }; - // 18 bytes. typedef struct GGAMsg { uint16_t mote_id; uint8_t hours; uint8_t minutes; - float dec_sec; uint8_t Lat_deg; - float Lat_dec_min; uint8_t Long_deg; - float Long_dec_min; uint8_t NSEWind; uint8_t num_sats; } GGAMsg; enum { ! AM_GGAMSG = 129 }; #endif /* LEADTEK_9546_H */ --- 152,243 ---- const uint8_t vtg_disable[] = {" ""$PSRF103,05,00,00,01*21" NMEA_END1 NMEA_END2}; + */ + // xbow has their own stuff for this. + #ifdef GPS_DATA_LENGTH + typedef struct _gps_msg GPS_Msg; typedef GPS_Msg * GPS_MsgPtr; struct _gps_msg { uint8_t length; int8_t data[GPS_DATA_LENGTH]; uint16_t crc; }; + #endif + // Some useful macros. + #define extract_num_sats_m(data) (10*(data[0]-'0') + (data[1]-'0')) + #define extract_hours_m(data) (10*(data[0]-'0') + (data[1]-'0')) + #define extract_minutes_m(data) (10*(data[2]-'0') + (data[3]-'0')) + #define extract_dec_sec_m(data) (10*(data[4]-'0') + (data[5]-'0') + 0.1*(data[7]-'0') \ + + 0.01*(data[8]-'0') \ + + 0.001*(data[9]-'0')) + #define extract_Lat_deg_m(data) (10*(data[0]-'0') + (data[1]-'0')) + #define extract_Lat_dec_min_m(data) (10*(data[2]-'0') + (data[3]-'0') + 0.1*(data[5]-'0') \ + + 0.01*(data[6]-'0') + 0.001*(data[7]-'0') + 0.0001*(data[8]-'0')) + #define extract_Long_deg_m(data) (100*(data[0]-'0') + 10*(data[1]-'0') + (data[2]-'0')) + #define extract_Long_dec_min_m(data) (10*(data[3]-'0') + (data[4]-'0') + 0.1*(data[6]-'0') \ + + 0.01*(data[7]-'0') + 0.001*(data[8]-'0') + 0.0001*(data[9]-'0')) typedef struct GGAMsg { + uint8_t magic; uint16_t mote_id; uint8_t hours; + uint8_t minutes; uint8_t Lat_deg; uint8_t Long_deg; uint8_t NSEWind; + + float dec_sec; + float Lat_dec_min; + float Long_dec_min; uint8_t num_sats; + } GGAMsg; enum { ! AM_GGAMSG = 130 ! }; ! ! ! typedef struct fbheader { ! uint8_t node_id; ! uint8_t am_type; ! uint8_t seq_num; ! uint8_t rsvd; ! } FBHeader; ! ! enum { ! AM_FBHEADERMSG = 228 ! }; ! ! typedef struct GGAMsg1 { ! FBHeader fbh; ! uint8_t hours; ! uint8_t minutes; ! uint8_t Lat_deg; ! uint8_t Long_deg; ! float dec_sec; ! float Lat_dec_min; ! float Long_dec_min; ! struct { ! uint8_t NS : 1; ! uint8_t EW : 1; ! uint8_t numsats : 4; ! uint8_t rsvd : 2; ! } bits; ! ! } GGAMsg1; ! ! ! enum { ! AM_GGAMSG1 = 229 }; + #endif /* LEADTEK_9546_H */ Index: leadtek_9546.c =================================================================== RCS file: /cvsroot/firebug/fireboard/sensors/leadtek9546/leadtek_9546.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** leadtek_9546.c 26 Mar 2004 00:39:27 -0000 1.2 --- leadtek_9546.c 30 Aug 2004 16:58:15 -0000 1.3 *************** *** 9,13 **** unsigned char ! crc(char * data, int size) { unsigned char cs = 0; --- 9,13 ---- unsigned char ! crc(const char * data, int size) { unsigned char cs = 0; *************** *** 37,41 **** } ! int main(int argc, char ** argv) { char data[] = {"$LTC,1000,0"}; --- 37,44 ---- } ! static char data2[] = {"$GPGGA,023129.762,3754.1755,N,12218.2682,W,1,08,1.1,-19.4,M,,,,0000"}; ! ! int ! main(int argc, char ** argv) { char data[] = {"$LTC,1000,0"}; *************** *** 52,58 **** ///////////////////////////// ! const uint8_t gps_gga_mask_crc[] = {"$LTC,NMEA," NMEA_GGA_MASK}; ! const uint8_t gps_rmc_mask_crc[] = {"$LTC,NMEA," NMEA_RMC_MASK}; ! const uint8_t gps_syncmode_on_crc[] = {"$LTC,SYNCMODE,1"}; const uint8_t gps_syncmode_off_crc[] = {"$LTC,SYNCMODE,0"}; --- 55,61 ---- ///////////////////////////// ! //const uint8_t gps_gga_mask_crc[] = {"$LTC,NMEA," NMEA_GGA_MASK}; ! //const uint8_t gps_rmc_mask_crc[] = {"$LTC,NMEA," NMEA_RMC_MASK}; ! //const uint8_t gps_syncmode_on_crc[] = {"$LTC,SYNCMODE,1"}; const uint8_t gps_syncmode_off_crc[] = {"$LTC,SYNCMODE,0"}; Index: gps_driverM.nc =================================================================== RCS file: /cvsroot/firebug/fireboard/sensors/leadtek9546/gps_driverM.nc,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** gps_driverM.nc 26 Mar 2004 00:39:27 -0000 1.9 --- gps_driverM.nc 30 Aug 2004 16:58:15 -0000 1.10 *************** *** 11,14 **** --- 11,29 ---- + #define extract_num_sats_m(data) (10*(data[0]-'0') + (data[1]-'0')) + #define extract_hours_m(data) (10*(data[0]-'0') + (data[1]-'0')) + #define extract_minutes_m(data) (10*(data[2]-'0') + (data[3]-'0')) + #define extract_dec_sec_m(data) (10*(data[4]-'0') + (data[5]-'0') + 0.1*(data[7]-'0') \ + + 0.01*(data[8]-'0') \ + + 0.001*(data[9]-'0')) + #define extract_Lat_deg_m(data) (10*(data[0]-'0') + (data[1]-'0')) + #define extract_Lat_dec_min_m(data) (10*(data[2]-'0') + (data[3]-'0') + 0.1*(data[5]-'0') \ + + 0.01*(data[6]-'0') + 0.001*(data[7]-'0') + 0.0001*(data[8]-'0')) + #define extract_Long_deg_m(data) (100*(data[0]-'0') + 10*(data[1]-'0') + (data[2]-'0')) + #define extract_Long_dec_min_m(data) (10*(data[3]-'0') + (data[4]-'0') + 0.1*(data[6]-'0') \ + + 0.01*(data[7]-'0') + 0.001*(data[8]-'0') + 0.0001*(data[9]-'0')) + + + module gps_driverM { *************** *** 19,24 **** command void readGps(); ! command uint8_t extract_hours(char * data); command uint8_t extract_minutes(char * data); --- 34,41 ---- command void readGps(); + command void count_commas(char * data); ! // Get rid of these. ! #if 0 command uint8_t extract_hours(char * data); command uint8_t extract_minutes(char * data); *************** *** 30,33 **** --- 47,51 ---- command uint8_t extract_NSEWind(char * data); command uint8_t extract_num_sats(char * data); + #endif command result_t isGGA(uint8_t * data); *************** *** 66,69 **** --- 84,91 ---- uint8_t state; uint8_t gps_state; + uint8_t parse_state; + uint8_t count = 0; + float alpha = 0.35; + static uint8_t sat_count = 0; GGAMsg gga_msg = {0}; *************** *** 74,88 **** */ norace bool have_gps_fix = 0; enum {IDLE, BUSY, BUSY_0, BUSY_1, GET_SAMPLE_0, GET_SAMPLE_1, POWEROFF, TIMER, GPS_WORKING, GPS_FINISHED}; command result_t StdControl.init() { ! //init_debug(); call Leds.init(); /** Control.init in GpsPacket.nc */ call GpsControl.init(); //SODbg(DBG_USR2, "gps_driverM.StdControl.init()\r\n"); return SUCCESS; --- 96,119 ---- */ norace bool have_gps_fix = 0; + bool have_gps_sats = FALSE; + uint8_t numsats = 0; + /* Average number of satellites is computed using EWMA. */ + float avg_sats = 0; enum {IDLE, BUSY, BUSY_0, BUSY_1, GET_SAMPLE_0, GET_SAMPLE_1, POWEROFF, TIMER, GPS_WORKING, GPS_FINISHED}; + enum {NMEA_GGA=1, NMEA_RMC}; + unsigned char nmea_type = 0; command result_t StdControl.init() { ! #if DBG_USER2 ! init_debug(); ! #endif call Leds.init(); /** Control.init in GpsPacket.nc */ call GpsControl.init(); + parse_state = IDLE; //SODbg(DBG_USR2, "gps_driverM.StdControl.init()\r\n"); return SUCCESS; *************** *** 107,110 **** --- 138,142 ---- + #if 1 /** Ok, this function turns on the gps unit for reading, * which is turned of elsewhere when the read is finished. *************** *** 127,130 **** --- 159,163 ---- } } + #endif *************** *** 184,213 **** command result_t log_gga_data_to_eeprom(GGAMsg * pGGA) { - #if 0 - int j; - char gga_log_array[GPS_CHAR]; - - gga_log_array[0] = pGGA->hours; - gga_log_array[1] = pGGA->minutes; - gga_log_array[2] = (pGGA->dec_sec)>>8; // MSB - gga_log_array[3] = pGGA->dec_sec; // LSB - gga_log_array[4] = pGGA->Lat_deg; - gga_log_array[5] = (pGGA->Lat_dec_min)>>8; - gga_log_array[6] = pGGA->Lat_dec_min; - gga_log_array[7] = pGGA->Long_deg; - gga_log_array[8] = (pGGA->Long_dec_min)>>8; - gga_log_array[9] = pGGA->Long_dec_min; - gga_log_array[10] = pGGA->NSEWind; - - - //SODbg(DBG_USR2, "LOGGER GPS:\n"); - for(j=0; j<11; j++) { - UARTPutChar(gga_log_array[j]); - } - SODbg(DBG_USR2, "\n"); - - // Write into eeprom here. - - #endif return SUCCESS; } --- 217,220 ---- *************** *** 227,230 **** --- 234,261 ---- } + // Change this to examine the field after the + // the time. + command void count_commas(char * data) { + + uint8_t i = 0; + uint8_t numcommas = 0; + + while (numcommas < 6) { + if (data[i] == ',') { + numcommas++; + } + i++; + } + + if (data[i] == '0' || data[i] == ',') { + have_gps_fix = FALSE; + parse_state = IDLE; + return; + } else { + data += 2; + numsats = extract_num_sats_m(data); + have_gps_fix = TRUE; + } + } *************** *** 243,246 **** --- 274,292 ---- GPS_MsgPtr gps_data = (GPS_MsgPtr)data; + + //call spew_to_uart(gps_data); + call spew_to_uart(data); + goto finish; + + if (count < 50) { + count++; + return data; + } + + if (parse_state == BUSY) { + return data; + } + + #if DBG_USR2 signal HLSensor.dataReady(gps_data); *************** *** 249,261 **** if ((call isGGA(gps_data->data))) { ! call parse_gga(gps_data); if (have_gps_fix) { //call spew_to_uart(gps_data); signal HLSensor.dataReady(&gga_msg); } } #endif return data; } --- 295,330 ---- if ((call isGGA(gps_data->data))) { ! parse_state = BUSY; ! ! //Count commas right here to determine if we ! //have a fix. ! call count_commas((char*)gps_data); ! ! if (sat_count < 50) { ! call Leds.yellowToggle(); ! avg_sats = alpha*avg_sats + (1-alpha)*numsats; ! sat_count++; ! goto finish; //break; //return data; ! } if (have_gps_fix) { //call spew_to_uart(gps_data); + if (numsats >= (int)avg_sats) { + call Leds.greenToggle(); + call parse_gga(gps_data); signal HLSensor.dataReady(&gga_msg); + // Send the bad reading anyway, but reset + // the application to try to do better next time. + // if (avg_sats < 5) { + // signal HLSensor.error("Too few satellites"); + // sat_count = 0; + // } + } } } #endif + finish: + parse_state = IDLE; return data; } *************** *** 293,303 **** char EW; ! gga_msg.hours = call extract_hours(gga_fields[1]); ! gga_msg.minutes = call extract_minutes(gga_fields[1]); ! gga_msg.dec_sec = call extract_dec_sec(gga_fields[1]); ! gga_msg.Lat_deg = call extract_Lat_deg(gga_fields[2]); ! gga_msg.Lat_dec_min = call extract_Lat_dec_min(gga_fields[2]); ! gga_msg.Long_deg = call extract_Long_deg(gga_fields[4]); ! gga_msg.Long_dec_min = call extract_Long_dec_min(gga_fields[4]); NS = (gga_fields[3][0] == 'N') ? 1 : 0; --- 362,372 ---- char EW; ! gga_msg.hours = extract_hours_m(gga_fields[1]); ! gga_msg.minutes = extract_minutes_m(gga_fields[1]); ! gga_msg.dec_sec = extract_dec_sec_m(gga_fields[1]); ! gga_msg.Lat_deg = extract_Lat_deg_m(gga_fields[2]); ! gga_msg.Lat_dec_min = extract_Lat_dec_min_m(gga_fields[2]); ! gga_msg.Long_deg = extract_Long_deg_m(gga_fields[4]); ! gga_msg.Long_dec_min = extract_Long_dec_min_m(gga_fields[4]); NS = (gga_fields[3][0] == 'N') ? 1 : 0; *************** *** 305,309 **** gga_msg.NSEWind = EW | (NS<<4); // eg. Status = 000N000E = 00010000 ! gga_msg.num_sats = call extract_num_sats(gga_fields[7]); return SUCCESS; --- 374,381 ---- gga_msg.NSEWind = EW | (NS<<4); // eg. Status = 000N000E = 00010000 ! //atomic { ! //numsats = call extract_num_sats(gga_fields[7]); ! gga_msg.num_sats = numsats; ! //} return SUCCESS; *************** *** 319,323 **** //SODbg(DBG_USR2, "gps_new.GpsCmd.SwitchesSet(): PowerState: %i \n\n", PowerState); ! char gga_fields[GGA_FIELDS][GPS_CHAR_PER_FIELD]; // = {{0}}; bool end_of_field = FALSE; --- 391,395 ---- //SODbg(DBG_USR2, "gps_new.GpsCmd.SwitchesSet(): PowerState: %i \n\n", PowerState); ! char gga_fields[GGA_FIELDS][GPS_CHAR_PER_FIELD]; bool end_of_field = FALSE; *************** *** 327,331 **** uint8_t length = gps_data->length; ! // Parse and store comma delimited fields into EEPROM while (i < GGA_FIELDS) { --- 399,403 ---- uint8_t length = gps_data->length; ! while (i < GGA_FIELDS) { *************** *** 333,336 **** --- 405,409 ---- end_of_field = FALSE; j = 0; + while (!end_of_field & k < length) { if (gps_data->data[k] == GPS_DELIMITER) { *************** *** 354,367 **** // Finding the gps fix should probably done somewhere else. ! have_gps_fix = call get_gps_fix(gga_fields[6]); //SODbg(DBG_USR2, "gps_new.parse_gga(): gps_fix %i \r\n", gps_fix); ! if (have_gps_fix) { call load_gga_struct(gga_fields); } return SUCCESS; } ! command uint8_t extract_hours(char * data) { return (10*(data[0]-'0') + (data[1]-'0')); --- 427,442 ---- // Finding the gps fix should probably done somewhere else. ! //have_gps_fix = call get_gps_fix(gga_fields[6]); //SODbg(DBG_USR2, "gps_new.parse_gga(): gps_fix %i \r\n", gps_fix); ! /* if (have_gps_fix) { call load_gga_struct(gga_fields); } + */ + call load_gga_struct(gga_fields); return SUCCESS; } ! #if 0 command uint8_t extract_hours(char * data) { return (10*(data[0]-'0') + (data[1]-'0')); *************** *** 430,433 **** --- 505,509 ---- return (10*(data[0]-'0') + (data[1]-'0')); } + #endif Index: Makefile =================================================================== RCS file: /cvsroot/firebug/fireboard/sensors/leadtek9546/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile 29 Jan 2004 14:53:36 -0000 1.1 --- Makefile 30 Aug 2004 16:58:15 -0000 1.2 *************** *** 1,2 **** clean: ! rm -rf *~ *.exe *.bak --- 1,12 ---- + + cfiles: + # gcc -Wall -o ggaparse -DSTANDALONE ggaparse.c nmea_parse.c + gcc -Wall -o gllparse -DSTANDALONE gllparse.c nmea_parse.c + gcc -Wall -o leadtek leadtek_9546.c + gcc -Wall -c nmea_parse.c + gcc -Wall -g -o nmea_parse_test nmea_parse_test.c \ + ggaparse.c gllparse.c gsaparse.c gsvparse.c \ + mssparse.c vtgparse.c rmcparse.c nmea_parse.c + clean: ! rm -rf *~ *.exe *.bak *.o Index: GpsPacketM.nc =================================================================== RCS file: /cvsroot/firebug/fireboard/sensors/leadtek9546/GpsPacketM.nc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GpsPacketM.nc 3 Feb 2004 20:06:44 -0000 1.2 --- GpsPacketM.nc 30 Aug 2004 16:58:15 -0000 1.3 *************** *** 1,5 **** - /* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */ - - /** * "Copyright (c) 2000-2002 The Regents of the University of California. --- 1,2 ---- *************** *** 191,197 **** command result_t Control.start() { // apply your power management algorithm ! call SwitchControl.start(); ! return call ByteControl.start(); } --- 188,196 ---- command result_t Control.start() { + result_t ok1, ok2; // apply your power management algorithm ! ok1 = call SwitchControl.start(); ! ok2 = call ByteControl.start(); ! return rcombine(ok1,ok2); } |