gps_data gps_get_data(void) { gps_data data = gps_init_data(); gps_data status = gps_get_status(); if(status.data_valid) { data.lock_valid = status.lock_valid; } else { return data; } gps_data time = gps_get_time(); if(time.data_valid) { data.hour = time.hour; data.minute = time.minute; data.second = time.second; } else { return data; } gps_data position = gps_get_position(); if(position.data_valid) { data.latitude = position.latitude; data.longitude = position.longitude; data.altitude = position.altitude; } else { return data; } data.data_valid = 1; return data; }
int main() { // Disable, configure, and start the watchdog timer wdt_disable(); wdt_reset(); wdt_enable(WDTO_8S); // Start and configure all hardware peripherals sei(); led_init(); radio_init(); gps_init(); radio_enable(); // Set the radio shift and baud rate _radio_dac_write(RADIO_COARSE, RADIO_CENTER_FREQ); _radio_dac_write(RADIO_FINE, 0); radio_set_shift(RADIO_SHIFT_425); radio_set_baud(RADIO_BAUD_50); // Radio chatter for(uint8_t i = 0; i < 5; i++) { radio_chatter(); wdt_reset(); } int32_t lat = 0, lon = 0, alt = 0; uint8_t hour = 0, minute = 0, second = 0, lock = 0, sats = 0; while(true) { led_set(LED_GREEN, 1); // Get the current system tick and increment uint32_t tick = eeprom_read_dword(&ticks) + 1; // Check that we're in airborne <1g mode if( gps_check_nav() != 0x06 ) led_set(LED_RED, 1); // Get information from the GPS gps_check_lock(&lock, &sats); if( lock == 0x02 || lock == 0x03 || lock == 0x04 ) { gps_get_position(&lat, &lon, &alt); gps_get_time(&hour, &minute, &second); } led_set(LED_GREEN, 0); // Format the telemetry string & transmit double lat_fmt = (double)lat / 10000000.0; double lon_fmt = (double)lon / 10000000.0; alt /= 1000; sprintf(s, "$$" CALLSIGN ",%lu,%02u:%02u:%02u,%02.7f,%03.7f,%ld,%u,%x", tick, hour, minute, second, lat_fmt, lon_fmt, alt, sats, lock); radio_chatter(); radio_transmit_sentence(s); radio_chatter(); led_set(LED_RED, 0); eeprom_update_dword(&ticks, tick); wdt_reset(); _delay_ms(500); } return 0; }
int main(void) { uint32_t count = 0; int32_t lat, lon, alt, temp; uint8_t hour, minute, second; uint16_t mv; char msg[100]; uint8_t i, r; /* Set the LED pin for output */ DDRB |= _BV(DDB7); adc_init(); rtx_init(); gps_setup(); /* Enable the radio and let it settle */ rtx_enable(1); _delay_ms(1000); sei(); rtx_string_P(PSTR(RTTY_CALLSIGN " starting up\n")); rtx_string_P(PSTR("Scanning 1-wire bus:\n")); for(i = 0; i < 3; i++) { r = ds_search_rom(id[i], i); if(r == DS_OK || r == DS_MORE) { rtx_wait(); snprintf(msg, 100, "%i> %02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", i, id[i][0], id[i][1], id[i][2], id[i][3], id[i][4], id[i][5], id[i][6], id[i][7]); rtx_string(msg); } else { rtx_wait(); snprintf(msg, 100, "%i> Error %i\n", i, r); rtx_string(msg); } if(r != DS_MORE) break; } rtx_string_P(PSTR("Done\n")); while(1) { if(!gps_get_pos(&lat, &lon, &alt)) { rtx_string_P(PSTR("$$" RTTY_CALLSIGN ",No or invalid GPS response\n")); continue; } if(!gps_get_time(&hour, &minute, &second)) { rtx_string_P(PSTR("$$" RTTY_CALLSIGN ",No or invalid GPS response\n")); continue; } /* Read the battery voltage */ mv = adc_read(); /* Read the temperature from sensor 0 */ ds_read_temperature(&temp, id[0]); rtx_wait(); snprintf(msg, 100, "$$%s,%li,%02i:%02i:%02i,%s%li.%05li,%s%li.%05li,%li,%i.%02i,%li.%01li,%c", RTTY_CALLSIGN, count++, hour, minute, second, (lat < 0 ? "-" : ""), labs(lat) / 10000000, labs(lat) % 10000000 / 100, (lon < 0 ? "-" : ""), labs(lon) / 10000000, labs(lon) % 10000000 / 100, alt / 1000, mv / 1000, mv / 10 % 100, temp / 10000, labs(temp) / 1000 % 10, (geofence_uk(lat, lon) ? '1' : '0')); crccat(msg + 2); rtx_string(msg); } }
int main(void) { uint32_t count = 0; int32_t lat, lon, alt, temp1, temp2, pressure; uint8_t hour, minute, second; uint16_t mv; char msg[100]; uint8_t i, r; bmp085_t bmp; /* Set the LED pin for output */ DDRB |= _BV(DDB7); adc_init(); rtx_init(); bmp085_init(&bmp); #ifdef APRS_ENABLED ax25_init(); #endif #ifdef SSDV_ENABLED c3_init(); #endif sei(); gps_setup(); /* Enable the radio and let it settle */ rtx_enable(1); _delay_ms(1000); rtx_string_P(PSTR(RTTY_CALLSIGN " starting up\n")); /* Scan the 1-wire bus, up to 16 devices */ rtx_string_P(PSTR("Scanning 1-wire bus:\n")); for(i = 0; i < 16; i++) { r = ds_search_rom(id[i], i); if(r == DS_OK || r == DS_MORE) { /* A device was found, display the address */ rtx_wait(); snprintf_P(msg, 100, PSTR("%i> %02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n"), i, id[i][0], id[i][1], id[i][2], id[i][3], id[i][4], id[i][5], id[i][6], id[i][7]); rtx_string(msg); } else { /* Device not responding or no devices found */ rtx_wait(); snprintf_P(msg, 100, PSTR("%i> Error %i\n"), i, r); rtx_string(msg); } /* No more devices? */ if(r != DS_MORE) break; } rtx_string_P(PSTR("Done\n")); while(1) { /* Set the GPS navmode every 10 strings */ if(count % 10 == 0) { /* Mode 6 is "Airborne with <1g Acceleration" */ if(gps_set_nav(6) != GPS_OK) { rtx_string_P(PSTR("$$" RTTY_CALLSIGN ",Error setting GPS navmode\n")); } } /* Get the latitude and longitude */ if(gps_get_pos(&lat, &lon, &alt) != GPS_OK) { rtx_string_P(PSTR("$$" RTTY_CALLSIGN ",No or invalid GPS response\n")); lat = lon = alt = 0; } /* Get the GPS time */ if(gps_get_time(&hour, &minute, &second) != GPS_OK) { rtx_string_P(PSTR("$$" RTTY_CALLSIGN ",No or invalid GPS response\n")); hour = minute = second = 0; } /* Read the battery voltage */ mv = adc_read(); /* Read the temperature from sensor 0 */ ds_read_temperature(&temp1, id[0]); /* Read the temperature from sensor 1 */ ds_read_temperature(&temp2, id[1]); /* Read the pressure from the BMP085 */ if(bmp085_sample(&bmp, 3) != BMP_OK) pressure = 0; else pressure = bmp085_calc_pressure(&bmp); /* Build up the string */ rtx_wait(); snprintf_P(msg, 100, PSTR("$$%s,%li,%02i:%02i:%02i,%s%li.%04li,%s%li.%04li,%li,%i.%01i,%li,%li,%li,%c"), RTTY_CALLSIGN, count++, hour, minute, second, (lat < 0 ? "-" : ""), labs(lat) / 10000000, labs(lat) % 10000000 / 1000, (lon < 0 ? "-" : ""), labs(lon) / 10000000, labs(lon) % 10000000 / 1000, alt / 1000, mv / 1000, mv / 100 % 10, temp1 / 10000, temp2 / 10000, pressure, (geofence_test(lat, lon) ? '1' : '0')); crccat(msg); rtx_string(msg); #ifdef APRS_ENABLED tx_aprs(lat, lon, alt); { int i; for(i = 0; i < 60; i++) _delay_ms(1000); } #endif #ifdef SSDV_ENABLED if(tx_image() == -1) { /* The camera goes to sleep while transmitting telemetry, * sync'ing here seems to prevent it. */ c3_sync(); } #endif } }
int main() { char state; int nlock_count = 0, n; setup(); for (;;) { wdt.kick(); ftdi.printf("Entering Loop.\r\n"); status_led = !status_led; write_rfm868(0x07, 0x01); // turn tx off - needed for below code write_rfm434(0x07, 0x01); // If GPS does not have lock for > 8 loops, restart it. if (nlock_count>8) { gpsPower(0); wait(2); gpsPower(1); nlock_count = 0; } wait(0.1); // wait for tx to turn off // Get temp while radio off temperature = (int16_t)((temp.read_u16()-9930)/19.9); battery_voltage = (int16_t)(battery.read()*BATT_MUL); rssi = ((int)read_rfm868(26)*51 - 12400)/100; // returned in dBm if (rssi > -50) { // if 868 channel is busy enable_868 = 0; } else { enable_868 = 1; write_rfm868(0x07, 0x08); // turn tx on } write_rfm434(0x07, 0x08); // turn tx on // Check for GPS lock gps_check_lock(); if (lock==0) { state='L'; nlock_count++; } else if (!enable_868) { state='O'; } else { nlock_count = 0; state='F'; } gps_get_position(); gps_get_time(); // Process triggers here if (config_err == 0) { ftdi.printf("Running triggers... "); runTrigger(0); runTrigger(1); runTrigger(2); ftdi.printf("Finished. \r\n"); } // Cutdown check if (cutdown_enabled && (alt>CUTDOWN_ALT)) { // Double check the altitude! gps_get_position(); if (alt>CUTDOWN_ALT) { ftdi.printf("Cutting wire!!!! \r\n"); cutdown = 1; // burn that wire!!!!!. .. ! wait(3); cutdown = 0; cutdown_enabled = 0; state = 'C'; } } // Do TX (always true, triggers not quite working) //if (send_gps) { if (1) { n = sprintf (buffer434, "$$VERTIGO,%d,%02d%02d%02d,%ld,%ld,%ld,%d,%c", count434, hour, minute, second, lat, lon, alt, sats, state); n = sprintf (buffer434, "%s*%04X\n", buffer434, (CRC16_checksum(buffer434) & 0xFFFF)); rtty_434_txstring(buffer434); save_434id(count434++); send_gps = 0; } // And for 868 if enabled if(enable_868) { ftdi.printf("Doing 868 now \r\n"); for (int count=0; count<10; count++) { ftdi.printf("\t loop %d\r\n", count); last_lon = lon; last_lat = lat; last_alt = alt; gps_get_position(); gps_get_time(); if ((lat==last_lat)&&(lon==last_lon)&&(alt==last_alt)) { gps_check_lock(); } else { state = 'F'; // cheat a second here. } n = sprintf (buffer868, "$$8VERTIGO,%d,%02d%02d%02d,%ld,%ld,%ld,%d,%c,%d,%d,%d", count868, hour, minute, second, lat, lon, alt, sats, state, temperature, battery_voltage, rssi); n = sprintf (buffer868, "%s*%04X\n", buffer868, (CRC16_checksum(buffer868) & 0xFFFF)); rtty_868_txstring(buffer868); save_868id(count868++); } } } return 0; }