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) { // Initialise the GPIO block gpioInit(); #ifdef GPS // Initialise the UART0 block for printf output uart0Init(9600); #else // Initialise the UART0 block for printf output uart0Init(115200); #endif // Configure the multi-rate timer for 1ms ticks mrtInit(__SYSTEM_CLOCK/1000); // Configure the switch matrix (setup pins for UART0 and SPI) configurePins(); //Seed random number generator, we can use our 'unique' ID random_output = NODE_ID[0] + NODE_ID[1] + NODE_ID[2]; //printf("random: %d\r\n", random_output); RFM69_init(); #ifdef GPS int navmode = 9; setupGPS(); #endif #ifdef DEBUG printf("Node initialized, version %s\r\n",GIT_VER); #endif while(1) { #ifdef GPS mrtDelay(5000); navmode = gps_check_nav(); if (navmode != 6){ setupGPS(); } mrtDelay(500); gps_get_position(); mrtDelay(500); gps_check_lock(); mrtDelay(500); //printf("Data: %d,%d,%d,%d,%d,%d\r\n", lat, lon, alt, navmode, lock, sats); //printf("Errors: %d,%d\r\n", GPSerror, serialBuffer_write); #endif incrementPacketCount(); //Clear buffer data_temp[0] = '\0'; uint8_t n; //Create the packet int int_temp = RFM69_readTemp(); // Read transmitter temperature rx_rssi = RFM69_lastRssi(); floor_rssi = RFM69_sampleRssi(); #ifdef GPS n = sprintf(data_temp, "%d%cL%d,%d,%dT%dR%d[%s]", NUM_REPEATS, data_count, lat, lon, alt, int_temp, rx_rssi, NODE_ID); #else if(data_count == 97) { n = sprintf(data_temp, "%d%cL%s[%s]", NUM_REPEATS, data_count, LOCATION_STRING, NODE_ID); } else { n = sprintf(data_temp, "%d%cT%dR%d,%dC%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, floor_rssi, rx_packets, NODE_ID); } #endif transmitData(n); awaitData(TX_GAP); } }