[Firebug-cvs] fireboard/beta/tos/lib/SiRF SiRFM.nc,1.3,1.4 sirf.h,1.3,1.4
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2005-08-19 00:18:04
|
Update of /cvsroot/firebug/fireboard/beta/tos/lib/SiRF In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4249 Modified Files: SiRFM.nc sirf.h Log Message: Filled in parsing code. Index: SiRFM.nc =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tos/lib/SiRF/SiRFM.nc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SiRFM.nc 17 Aug 2005 01:56:47 -0000 1.3 --- SiRFM.nc 17 Aug 2005 22:51:56 -0000 1.4 *************** *** 13,16 **** --- 13,20 ---- */ + + /** TODO: These came from the GGA code, and + * need to be rearranged/renamed for sirf data. + */ #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')) *************** *** 34,38 **** module SiRFM { ! provides interface SiRF; } --- 38,51 ---- module SiRFM { ! provides { ! ! interface SiRF; ! /** These will all be turned into macros later. */ ! command int convert_4_bytes_to_int(char * bytes); ! command float convert_2_bytes_to_float(char * bytes); ! command float convert_4_bytes_to_float(char * bytes); ! command double convert_8_bytes_to_double(char * bytes); ! command uint16_t convert_2_bytes_to_uint16(char * bytes); ! } } *************** *** 50,67 **** command uint8_t SiRF.get_type (const char * sirfstring) { ! return 0; } ! command result_t SiRF.id2_parse(const char * sirf_string) { ! return FAIL; } ! command result_t SiRF.id28_parse(const char * sirf_string) { ! return FAIL; } } --- 63,222 ---- command uint8_t SiRF.get_type (const char * sirfstring) { ! return sirfstring[0]; } ! command result_t SiRF.id2_parse(SiRF_ID2_t * sid2, char * sirf_string) { ! sid2->xpos = call convert_4_bytes_to_int(&sirf_string[1]); ! sid2->ypos = call convert_4_bytes_to_int(&sirf_string[5]); ! sid2->zpos = call convert_4_bytes_to_int(&sirf_string[9]); ! sid2->xvel = call convert_2_bytes_to_uint16(&sirf_string[13]); ! sid2->yvel = call convert_2_bytes_to_uint16(&sirf_string[15]); ! sid2->zvel = call convert_2_bytes_to_uint16(&sirf_string[17]); ! sid2->mode1 = sirf_string[19]; ! sid2->dop = sirf_string[20]; ! sid2->mode2 = sirf_string[21]; ! sid2->gps_week = call convert_2_bytes_to_uint16(&sirf_string[22]); ! sid2->gps_tow = call convert_4_bytes_to_int(&sirf_string[24]); ! sid2->sv_in_fix = sirf_string[28]; ! sid2->ch1 = sirf_string[29]; ! sid2->ch2 = sirf_string[30]; ! sid2->ch3 = sirf_string[31]; ! sid2->ch4 = sirf_string[32]; ! sid2->ch5 = sirf_string[33]; ! sid2->ch6 = sirf_string[34]; ! sid2->ch7 = sirf_string[35]; ! sid2->ch8 = sirf_string[36]; ! sid2->ch9 = sirf_string[37]; ! sid2->ch10 = sirf_string[38]; ! sid2->ch11 = sirf_string[39]; ! sid2->ch12 = sirf_string[40]; ! ! return SUCCESS; } ! command result_t SiRF.id28_parse(SiRF_ID28_t * sid28, char * sirf_string) { ! sid28->channel = sirf_string[1]; ! sid28->time_tag = call convert_4_bytes_to_int(&sirf_string[2]); ! sid28->sat_id = sirf_string[6]; ! sid28->gps_sw_time = (uint64_t)call convert_8_bytes_to_double(&sirf_string[7]); ! sid28->pseudo_range = (uint64_t)call convert_8_bytes_to_double(&sirf_string[15]); ! sid28->carrier_freq = call convert_4_bytes_to_int(&sirf_string[23]); ! sid28->carrier_phase = (uint64_t)call convert_8_bytes_to_double(&sirf_string[27]); ! sid28->time_in_track = call convert_2_bytes_to_uint16(&sirf_string[35]); ! sid28->sync_flags = sirf_string[37]; ! sid28->cno1 = sirf_string[38]; ! sid28->cno2 = sirf_string[39]; ! sid28->cno3 = sirf_string[40]; ! sid28->cno4 = sirf_string[41]; ! sid28->cno5 = sirf_string[42]; ! sid28->cno6 = sirf_string[43]; ! sid28->cno7 = sirf_string[44]; ! sid28->cno8 = sirf_string[45]; ! sid28->cno9 = sirf_string[46]; ! sid28->cno10 = sirf_string[47]; ! sid28->delta_range_interval = call convert_2_bytes_to_uint16(&sirf_string[48]); ! sid28->mean_delta_range_time = call convert_2_bytes_to_uint16(&sirf_string[50]); ! sid28->extrapolation_time = call convert_2_bytes_to_uint16(&sirf_string[52]); ! sid28->phase_error_count = sirf_string[54]; ! sid28->low_power_count = sirf_string[55]; ! ! return SUCCESS; } + + + // TODO: Make a macro for this. + command int convert_4_bytes_to_int(char * bytes) { + + int val = 0; + val |= bytes[0] & 0xFF; + val <<= 8; + val |= bytes[1] & 0xFF; + val <<= 8; + val |= bytes[2] & 0xFF; + val <<= 8; + val |= bytes[3] & 0xFF; + return val; + } + + /* + command static int + convert_4_bytes_to_uint32(char * bytes) { + + int val = 0; + val |= bytes[0] & 0xFF; + val <<= 8; + val |= bytes[1] & 0xFF; + val <<= 8; + val |= bytes[2] & 0xFF; + val <<= 8; + val |= bytes[3] & 0xFF; + return val; + } + */ + + + // TODO: Make a macro for this. + command float convert_2_bytes_to_float(char * bytes) { + + int16_t val = 0; + val |= bytes[0] & 0xFF; + val <<= 8; + val |= bytes[1] & 0xFF; + return (float)val; + } + + + // TODO: Make a macro for this. + command float convert_4_bytes_to_float(char * bytes) { + + int32_t val = 0; + val |= bytes[0] & 0xFF; + val <<= 8; + val |= bytes[1] & 0xFF; + val <<= 8; + val |= bytes[2] & 0xFF; + val <<= 8; + val |= bytes[3] & 0xFF; + return (float)val; + } + + + // FIXME: Get rid of locally defined variable + // so that this can be turned into a macro. + command double convert_8_bytes_to_double(char * bytes) { + + int64_t val = 0; + val |= bytes[0] & 0xFF; + val <<= 8; + val |= bytes[1] & 0xFF; + val <<= 8; + val |= bytes[2] & 0xFF; + val <<= 8; + val |= bytes[3] & 0xFF; + val <<= 8; + val |= bytes[4] & 0xFF; + val <<= 8; + val |= bytes[5] & 0xFF; + val <<= 8; + val |= bytes[6] & 0xFF; + val <<= 8; + val |= bytes[7] & 0xFF; + return (double)val; + } + + // TODO: Make a macro for this. + command uint16_t convert_2_bytes_to_uint16(char * bytes) { + + uint16_t val = 0; + val |= bytes[0] & 0xFF; + val <<= 8; + val |= bytes[1] & 0xFF; + return val; + } + } Index: sirf.h =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tos/lib/SiRF/sirf.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** sirf.h 17 Aug 2005 21:46:00 -0000 1.3 --- sirf.h 17 Aug 2005 22:51:56 -0000 1.4 *************** *** 8,12 **** #define FB_SIRF_H ! //#include <sys/types.h> /** Enums for dispatching sirf messages. */ --- 8,34 ---- #define FB_SIRF_H ! ! ! // Header used in packets that make up a long message. ! typedef struct fragmentHeader { ! uint8_t mote_id; ! uint8_t sequenceNumber; ! uint8_t blockNumber; ! uint8_t blockCount; ! } FragmentHeader_t; ! ! #ifndef TOSH_DATA_LENGTH ! #define TOSH_DATA_LENGTH 29 ! #endif ! ! #define FRAGMENT_PAYLOAD_LENGTH (TOSH_DATA_LENGTH - sizeof(FragmentHeader_t)) ! ! // Packet to transport variable length (and long) messages in a fixed ! // length radio message. ! typedef struct messageFragment { ! FragmentHeader_t h; ! uint8_t data[FRAGMENT_PAYLOAD_LENGTH]; ! } MessageFragment_t; ! /** Enums for dispatching sirf messages. */ *************** *** 31,36 **** - - typedef struct SiRF_ID2_1 { --- 53,56 ---- |