Пример #1
0
int main() {
	
	printf("Testing conversions.c. All errors will be reported as failed assertions.\n");
	
	printf("Testing hexchar2int()\n");
	
	/** Testing hexchar2int() **/
	assert(hexchar2int('!') == -1);
	assert(hexchar2int('0') == 0);
	assert(hexchar2int('9') == 9);
	assert(hexchar2int(':') == -1);
	
	assert(hexchar2int('@') == -1);
	assert(hexchar2int('A') == 10);
	assert(hexchar2int('F') == 15);
	assert(hexchar2int('G') == -1);
	
	assert(hexchar2int('`') == -1);
	assert(hexchar2int('a') == 10);
	assert(hexchar2int('f') == 15);
	assert(hexchar2int('g') == -1);
	
	/** Testing degMinToDeg() **/
	printf("Testing degMinToDeg()\n");
	
	// 40 degrees, 41 arc minutes = 40.68
	assert(degMinToDeg(40, 41) - 40.68333 < .001);
	
	// 0 degrees, 0 arc minutes = 0
	assert(degMinToDeg(0, 0) - 0 < .001);
	
	// 122 degrees, 24 arc minutes = 122.4
	assert(degMinToDeg(122, 24) - (122.4) < .001);
	
	return 0;
}
Пример #2
0
Файл: gps.c Проект: mdunne/ANIMA
void parseGGA(char* stream) {
    // declare the local vars
    char token[15]; // Declare a token to be 15 characters in length
    char tmp [3] = {0, 0, '\0'}, tmp3[4] = {0, 0, 0, '\0'};
    unsigned char chTmp = 0;

    // initialize tokenizer, let go first token which holds the msg type
    myTokenizer(stream, ',', token);

    // 1.- hhmmss.ssss
    myTokenizer(NULL, ',', token);
    if (strlen(token) > 5) {
        tmp[0] = token[0];
        tmp[1] = token[1];
        gpsControlData.hour = (unsigned char) atoi(tmp);
        tmp[0] = token[2];
        tmp[1] = token[3];
        gpsControlData.min = (unsigned char) atoi(tmp);
        tmp[0] = token[4];
        tmp[1] = token[5];
        gpsControlData.sec = (unsigned char) atoi(tmp);
    }
    // 2.- Latitude
    // ddmm.mmmmmm
    myTokenizer(NULL, ',', token);
    //printf("token %s", token);
    if (strlen(token) > 0) {
        // get the first two values
        tmp[0] = token[0];
        tmp[1] = token[1];
        // get the degrees
        chTmp = (unsigned char) atoi(tmp);
        printf("\r\ntmp: %s\r\nchtmp: %d\r\n", tmp, chTmp);
        // make the degrees zero for minutes conversion
        token[0] = '0';
        token[1] = '0';
        //printf("token: %s\r\n", token);
        //printf("atof(token): %f\r\n", atof(token));
        // get the float
        gpsControlData.lat = degMinToDeg(chTmp, atof(token));
        //printf("\r\nLatittude: %f", gpsControlData.lat);
        // 3.- Latitude Sector
        myTokenizer(NULL, ',', token);
        if (strlen(token) == 1) {
            // Set the sign of the float value.
            // South & west are negative, so we invert the sign in
            // those cases. North/East don't change the value so no
            // need to check those.
            if (token[0] == 'S' || token[1] == 'W') {
                gpsControlData.lat = -gpsControlData.lat;
            }
        }
    }
    //printf("\r\nLatittude: %f", gpsControlData.lat);
    // 4.- Longitude
    // ddmm.mmmmmm
    myTokenizer(NULL, ',', token);
    if (strlen(token) > 0) {
        // get the first two values
        tmp3[0] = token[0];
        tmp3[1] = token[1];
        tmp3[2] = token[2];
        // get the degrees
        chTmp = (unsigned char) atoi(tmp3);
        // make the degrees zero for minutes conversion
        token[0] = '0';
        token[1] = '0';
        token [2] = '0';
        // get the float
        gpsControlData.lon = degMinToDeg(chTmp, atof(token));

        // 5.- Longitude Sector
        myTokenizer(NULL, ',', token);

        if (strlen(token) > 0) {
            // set the sign of the float value
            if (token[0] == 'S' || token[0] == 'W') {
                gpsControlData.lon = -gpsControlData.lon;
            }
        }
    }

    // 6.- Quality Indicator
    myTokenizer(NULL, ',', token);
    if (strlen(token) == 1) {
        gpsControlData.fix = (char) atoi(token);
    }

    // 7.- Sats used in solution
    // xx
    myTokenizer(NULL, ',', token);
    if (strlen(token) > 0) {
        gpsControlData.sats = (unsigned char) atoi(token);
    }

    // 8.- Horizontal dilution of solution given from 0 to 99.99 but
    // stored from 0 - 990
    //in integers, i.e HDOP = HDOP_stored/100 CAUTION
    // xx.xx
    myTokenizer(NULL, ',', token);
    if (strlen(token) > 0) {
        gpsControlData.hdop.usData = (unsigned short) (atof(token)*10.0);
    }

    // 9.- Altitude above mean sea level given in meters
    // xxx.xxx
    myTokenizer(NULL, ',', token);
    if (strlen(token) > 0) {
        gpsControlData.height = atof(token);
    }

    // turn the flag on of new data
    gpsControlData.newData = 1;
}
Пример #3
0
Файл: gps.c Проект: mdunne/ANIMA
void parseRMC(char* stream) {
    // declare the local vars
    char token[15]; // Tokens set to 15 characters in length
    char tmp [3] = {0, 0, '\0'}, tmp3[4] = {0, 0, 0, '\0'}, tmp4[5] = {0, 0, 0, 0, '\0'};
    unsigned char chTmp = 0;


    // initialize tokenizer, let go first token which holds the msg type
    // token = strtok(stream, ",");
    myTokenizer(stream, ',', token);

    // 1.- hhmmss.ssss
    myTokenizer(NULL, ',', token);
    //printf("Token for time: %s\t",token);
    if (strlen(token) > 5) {
        tmp[0] = token[0];
        tmp[1] = token[1];
        gpsControlData.hour = (unsigned char) atoi(tmp);
        tmp[0] = token[2];
        tmp[1] = token[3];
        gpsControlData.min = (unsigned char) atoi(tmp);
        tmp[0] = token[4];
        tmp[1] = token[5];
        gpsControlData.sec = (unsigned char) atoi(tmp);
        tmp4[0] = token[7];
        tmp4[1] = token[8];
        tmp4[2] = token[9];
        tmp4[3] = token[10];
        //printf("%s\t",tmp4);
        gpsControlData.millisec = (unsigned short) atoi(tmp4);

    }

    // 2.- Status of position Fix
    myTokenizer(NULL, ',', token);
    if (strlen(token) == 1) {
        if (token[0] == 'A' || token[0] == 'D') {
            gpsControlData.fix = 1;
        } else {
            gpsControlData.fix = 0;
        }
    }

    // 3.- Latitude
    // ddmm.mmmmmm
    myTokenizer(NULL, ',', token);
    if (strlen(token) > 0) {
        // get the first two values
        tmp[0] = token[0];
        tmp[1] = token[1];
        // get the degrees
        chTmp = (unsigned char) atoi(tmp);
        // make the degrees zero for minutes conversion
        token[0] = '0';
        token[1] = '0';
        // get the float
        gpsControlData.lat = degMinToDeg(chTmp, atof(token));

        // 4.- Latitude Sector
        myTokenizer(NULL, ',', token);
        if (strlen(token) == 1) {
            // set the sign of the float value
            if (token[0] == 'S' || token[0] == 'W') {
                gpsControlData.lat = -gpsControlData.lat;
            }
        }
    }

    // 5.- Longitude
    // dddmm.mmmmmm
    myTokenizer(NULL, ',', token);
    if (strlen(token) > 0) {
        // get the first two values
        tmp3[0] = token[0];
        tmp3[1] = token[1];
        tmp3[2] = token[2];
        // get the degrees
        chTmp = (unsigned char) atoi(tmp3);
        // make the degrees zero for minutes conversion
        token[0] = '0';
        token[1] = '0';
        token [2] = '0';
        // get the float
        gpsControlData.lon = degMinToDeg(chTmp, atof(token));

        // 6.- Longitude Sector
        myTokenizer(NULL, ',', token);
        if (strlen(token) == 1) {
            // set the sign of the float value
            if (token[0] == 'S' || token[0] == 'W') {
                gpsControlData.lon = -gpsControlData.lon;
            }
        }
    }

    // 7.- SOG in knots but gets stored in cm/s CAUTION
    // xx.xx
    myTokenizer(NULL, ',', token);
    if (strlen(token) > 0) {
        gpsControlData.sog.usData = (unsigned short) (atof(token) * KTS2MPS * 100.0);
    }

    // 8.- COG in degrees
    // xxx.xxx
    myTokenizer(NULL, ',', token);
    if (strlen(token) > 0) {
        gpsControlData.cog.usData = (unsigned short) atof(token);
    }

    // 9.- UTC Date
    // ddmmyy
    myTokenizer(NULL, ',', token);
    if (strlen(token) > 5) {
        // get day
        tmp[0] = token[0];
        tmp[1] = token[1];
        gpsControlData.day = (unsigned char) atoi(tmp);
        // get month
        tmp[0] = token[2];
        tmp[1] = token[3];
        gpsControlData.month = (unsigned char) atoi(tmp);
        // get year
        tmp[0] = token[4];
        tmp[1] = token[5];
        gpsControlData.year = (unsigned char) atoi(tmp);
    }

    // turn the flag on of new data
    gpsControlData.newData = 1;
}