// Simple initialization function. static void init(void) { // Enable interrupts IRQ_ENABLE; // Initialize hardware timers timer_init(); // Initialize serial comms on UART0, // which is the hardware serial on arduino ser_init(&ser, SER_UART0); ser_setbaudrate(&ser, 9600); // For some reason BertOS sets the serial // to 7 bit characters by default. We set // it to 8 instead. UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); // Create a modem context afsk_init(&afsk, ADC_CH); // ... and a protocol context with the modem ax25_init(&ax25, &afsk.fd, message_callback); // Init SimpleSerial ss_init(&ax25); // That's all! }
int afsk_testSetup(void) { kdbg_init(); kfiledebug_init(&dbg); fp_adc = afsk_fileOpen("test/afsk_test.au"); #if CPU_AVR #warning TODO: open the file? #else fp_dac = fopen("test/afsk_test_out.au", "w+b"); #endif ASSERT(fp_dac); #define FS_HH (((uint32_t)CONFIG_AFSK_DAC_SAMPLERATE) >> 24) #define FS_HL ((((uint32_t)CONFIG_AFSK_DAC_SAMPLERATE) >> 16) & 0xff) #define FS_LH ((((uint32_t)CONFIG_AFSK_DAC_SAMPLERATE) >> 8) & 0xff) #define FS_LL (((uint32_t)CONFIG_AFSK_DAC_SAMPLERATE) & 0xff) uint8_t snd_header[] = { '.','s','n','d', 0,0,0,24, 0,0,0,0, 0,0,0,2, FS_HH,FS_HL,FS_LH,FS_LL, 0,0,0,1}; ASSERT(fwrite(snd_header, 1, sizeof(snd_header), fp_dac) == sizeof(snd_header)); timer_init(); afsk_init(&afsk_fd, 0 ,0); ax25_init(&ax25, &afsk_fd.fd, message_hook); return 0; }
static void init(void) { /* Enable all the interrupts */ IRQ_ENABLE; /* Initialize debugging module (allow kprintf(), etc.) */ kdbg_init(); /* Initialize system timer */ timer_init(); /* Initialize LED driver */ LED_INIT(); ser_init(&ser_port, SER_UART2); ser_setbaudrate(&ser_port, 115200L); afsk_init(&afsk, 0, 0); // timer period = 24000000 hz /100/25 = 9600hz AD_Init(&afsk); AD_SetTimer(100, 25); AD_Start(); DA_Init(&afsk); DA_SetTimer(100, 25); kiss_init(&ser_port, &ax25, &afsk); ax25_init(&ax25, &afsk.fd, 1, ax25_message_callback); }
void init(void) { sei(); AFSK_init(&modem); ax25_init(&AX25, &modem.fd, ax25_callback); digipeater_init(&AX25, &modem, &serial); serial_init(&serial); stdout = &serial.uart0; stdin = &serial.uart0; }
int afsk_testRun(void) { int c; while ((c = fgetc(fp_adc)) != EOF) { afsk_adc_isr (&afsk_fd, (uint8_t) c); ax25_poll(&ax25); } kprintf("Messages correctly received: %d\n", msg_cnt); ASSERT(msg_cnt >= 15); char buf[256]; // start from 1 and then wrap round to 0 otherwise null termination prevents display of data for (unsigned i = 0; i < sizeof (buf); i++) buf[i] = i + 1; ax25_send(&ax25, AX25_CALL("abcdef", 0), AX25_CALL("123456", 1), buf, sizeof(buf)); do { int8_t val = afsk_dac_isr(&afsk_fd) - 128; ASSERT(fwrite(&val, 1, sizeof(val), fp_dac) == sizeof(val)); data_written++; } while (afsk_fd.sending); #define SND_DATASIZE_OFF 8 #if CPU_AVR #warning TODO: fseek? #else ASSERT(fseek(fp_dac, SND_DATASIZE_OFF, SEEK_SET) == 0); #endif data_written = cpu_to_be32(data_written); ASSERT(fwrite(&data_written, 1, sizeof(data_written), fp_dac) == sizeof(data_written)); ASSERT(fclose(fp_adc) + fclose(fp_dac) == 0); fp_adc = afsk_fileOpen("test/afsk_test_out.au"); ax25_init(&ax25, &afsk_fd.fd, messageout_hook); while ((c = fgetc(fp_adc)) != EOF) { afsk_adc_isr(&afsk_fd, (int8_t)c); ax25_poll(&ax25); } return 0; }
void init(void) { sei(); AFSK_init(&modem); ax25_init(&AX25, &modem.fd, ax25_callback); serial_init(&serial); stdout = &serial.uart0; stdin = &serial.uart0; #if SERIAL_PROTOCOL == PROTOCOL_KISS kiss_init(&AX25, &modem, &serial); #endif #if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL ss_init(&AX25); #endif }
static void init(void) { IRQ_ENABLE; kdbg_init(); timer_init(); /* * Init afsk demodulator. We need to implement the macros defined in hw_afsk.h, which * is the hardware abstraction layer. * We do not need transmission for now, so we set transmission DAC channel to 0. */ afsk_init(&afsk, ADC_CH, 0); /* * Here we initialize AX25 context, the channel (KFile) we are going to read messages * from and the callback that will be called on incoming messages. */ ax25_init(&ax25, &afsk.fd, message_callback); /* Initialize serial port, we are going to use it to show APRS messages*/ ser_init(&ser, SER_UART0); ser_setbaudrate(&ser, 115200L); }
static void init(void) { IRQ_ENABLE; kdbg_init(); timer_init(); /* Initialize serial port, we are going to use it to show APRS messages*/ ser_init(&g_serial, SER_UART0); ser_setbaudrate(&g_serial, SER_DEFAULT_BAUD_RATE); // For some reason BertOS sets the serial // to 7 bit characters by default. We set // it to 8 instead. UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); // see ATMEGA328P datasheet P197, Table 20-11. UCSZn Bits Settings // initialize the reader that wraps the serial serialreader_init(&g_serialreader, &g_serial); // Load settings first settings_load(); /* * Init afsk demodulator. We need to implement the macros defined in hw_afsk.h, which * is the hardware abstraction layer. * We do not need transmission for now, so we set transmission DAC channel to 0. */ afsk_init(&g_afsk, ADC_CH, DAC_CH); /* * Here we initialize AX25 context, the channel (KFile) we are going to read messages * from and the callback that will be called on incoming messages. */ ax25_init(&g_ax25, &g_afsk.fd, ax25_msg_callback); g_ax25.pass_through = false; // Initialize the kiss module // NOTE - use shared memory buffer #if MOD_KISS kiss_init(&g_serialreader,&g_ax25); #endif #if MOD_BEACON // Initialize the beacon module beacon_init(beacon_mode_exit_callback); #endif // Initialize the digi module #if MOD_DIGI digi_init(); #endif #if MOD_RADIO // Initialize the soft serial and radio radio_init(4310400); //TODO read from settings #endif // Initialize GPS NMEA/GPRMC parser #if MOD_TRACKER tracker_init(); #endif #if MOD_CONSOLE ////////////////////////////////////////////////////////////// // Initialize the console & commands console_init(); console_add_command(PSTR("MODE"),cmd_switch_mode); // setup tnc run mode #if MOD_KISS console_add_command(PSTR("KISS"),cmd_enter_kiss_mode); // enable KISS mode #endif #endif }
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 } }