diff --git a/tracker/software/Makefile b/tracker/software/Makefile index 14b689af..9c4e7b23 100644 --- a/tracker/software/Makefile +++ b/tracker/software/Makefile @@ -123,11 +123,11 @@ CSRC = $(STARTUPSRC) \ $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(CHIBIOS)/os/various/fatfs_bindings/fatfs_diskio.c \ - threads/tracking.c \ - threads/position.c \ - threads/image.c \ - threads/log.c \ - threads/radio/radio.c \ + threads/collector.c \ + threads/rxtx/position.c \ + threads/rxtx/image.c \ + threads/rxtx/log.c \ + threads/rxtx/radio.c \ protocols/ssdv/ssdv.c \ protocols/ssdv/rs8.c \ pkt/protocols/aprs2/ax25_pad.c \ @@ -270,7 +270,7 @@ UADEFS = # List all user directories here UINCDIR = threads/ drivers/ drivers/wrapper/ pkt/protocols/aprs2 \ protocols/ssdv math/ drivers/flash/ drivers/usb/ \ - protocols/packet fatfs/src/ threads/radio/ \ + protocols/packet fatfs/src/ threads/rxtx/ \ pkt pkt/channels pkt/managers pkt/devices pkt/protocols \ pkt/diagnostics pkt/filters pkt/decoders pkt/sys CMSIS/include \ pkt/sys/regex/ diff --git a/tracker/software/math/geofence.c b/tracker/software/math/geofence.c index 852b3eb1..5077a807 100644 --- a/tracker/software/math/geofence.c +++ b/tracker/software/math/geofence.c @@ -5,7 +5,7 @@ #include "ch.h" #include "hal.h" #include "geofence.h" -#include "tracking.h" +#include "collector.h" static const coord_t america[] = { // Latitude Longitude (in deg*10000000) @@ -653,7 +653,7 @@ static bool isPointInBrazil(int32_t lat, int32_t lon) { * been received. */ uint32_t getAPRSRegionFrequency(void) { - trackPoint_t *point = getLastTrackPoint(); + dataPoint_t *point = getLastDataPoint(); // Position unknown if(point == NULL || (point->gps_lat == 0 && point->gps_lon == 0)) diff --git a/tracker/software/protocols/packet/aprs.c b/tracker/software/protocols/packet/aprs.c index 035c53d7..a7f7346f 100644 --- a/tracker/software/protocols/packet/aprs.c +++ b/tracker/software/protocols/packet/aprs.c @@ -201,10 +201,10 @@ void aprs_debug_getPacket(packet_t pp, char* buf, uint32_t len) * - Number of satellites being used * - Number of cycles where GPS has been lost (if applicable in cycle) */ -packet_t aprs_encode_position(const char *callsign, const char *path, uint16_t symbol, trackPoint_t *trackPoint) +packet_t aprs_encode_position(const char *callsign, const char *path, uint16_t symbol, dataPoint_t *dataPoint) { // Latitude - uint32_t y = 380926 * (90 - trackPoint->gps_lat/10000000.0); + uint32_t y = 380926 * (90 - dataPoint->gps_lat/10000000.0); uint32_t y3 = y / 753571; uint32_t y3r = y % 753571; uint32_t y2 = y3r / 8281; @@ -213,7 +213,7 @@ packet_t aprs_encode_position(const char *callsign, const char *path, uint16_t s uint32_t y1r = y2r % 91; // Longitude - uint32_t x = 190463 * (180 + trackPoint->gps_lon/10000000.0); + uint32_t x = 190463 * (180 + dataPoint->gps_lon/10000000.0); uint32_t x3 = x / 753571; uint32_t x3r = x % 753571; uint32_t x2 = x3r / 8281; @@ -222,11 +222,11 @@ packet_t aprs_encode_position(const char *callsign, const char *path, uint16_t s uint32_t x1r = x2r % 91; // Altitude - uint32_t a = logf(METER_TO_FEET(trackPoint->gps_alt)) / logf(1.002f); + uint32_t a = logf(METER_TO_FEET(dataPoint->gps_alt)) / logf(1.002f); uint32_t a1 = a / 91; uint32_t a1r = a % 91; - uint8_t gpsFix = trackPoint->gps_lock == GPS_LOCKED1 || trackPoint->gps_lock == GPS_LOCKED2 ? GSP_FIX_CURRENT : GSP_FIX_OLD; + uint8_t gpsFix = dataPoint->gps_lock == GPS_LOCKED1 || dataPoint->gps_lock == GPS_LOCKED2 ? GSP_FIX_CURRENT : GSP_FIX_OLD; uint8_t src = NMEA_SRC_GGA; uint8_t origin = ORIGIN_PICO; @@ -248,23 +248,23 @@ packet_t aprs_encode_position(const char *callsign, const char *path, uint16_t s xmit[len+12] = ((gpsFix << 5) | (src << 3) | origin) + 33; // Comments - uint32_t len2 = base91_encode((uint8_t*)trackPoint, (uint8_t*)&xmit[len+13], sizeof(trackPoint_t)); + uint32_t len2 = base91_encode((uint8_t*)dataPoint, (uint8_t*)&xmit[len+13], sizeof(dataPoint_t)); xmit[len+len2+13] = '|'; // Sequence ID - uint32_t t = trackPoint->id & 0x1FFF; + uint32_t t = dataPoint->id & 0x1FFF; xmit[len+len2+14] = t/91 + 33; xmit[len+len2+15] = t%91 + 33; // Telemetry parameter for(uint8_t i=0; i<5; i++) { switch(i) { - case 0: t = trackPoint->adc_vbat; break; - case 1: t = trackPoint->adc_vsol; break; - case 2: t = trackPoint->pac_pbat+4096; break; - case 3: t = trackPoint->sen_i1_temp/10 + 1000; break; - case 4: t = trackPoint->sen_i1_press/125 - 40; break; + case 0: t = dataPoint->adc_vbat; break; + case 1: t = dataPoint->adc_vsol; break; + case 2: t = dataPoint->pac_pbat+4096; break; + case 3: t = dataPoint->sen_i1_temp/10 + 1000; break; + case 4: t = dataPoint->sen_i1_press/125 - 40; break; } xmit[len+len2+16+i*2] = t/91 + 33; @@ -388,8 +388,8 @@ static bool aprs_decode_message(packet_t pp) } else if(!strcmp(command, "?aprsp")) { // Transmit position TRACE_INFO("RX > Message: Position query"); - trackPoint_t* trackPoint = getLastTrackPoint(); - packet_t pp = aprs_encode_position(conf_sram.rx.call, conf_sram.rx.path, conf_sram.rx.symbol, trackPoint); + dataPoint_t* dataPoint = getLastDataPoint(); + packet_t pp = aprs_encode_position(conf_sram.rx.call, conf_sram.rx.path, conf_sram.rx.symbol, dataPoint); transmitOnRadio(pp, conf_sram.rx.radio_conf.freq, conf_sram.rx.radio_conf.step, diff --git a/tracker/software/protocols/packet/aprs.h b/tracker/software/protocols/packet/aprs.h index 429e1a3e..daa5addd 100644 --- a/tracker/software/protocols/packet/aprs.h +++ b/tracker/software/protocols/packet/aprs.h @@ -21,7 +21,7 @@ #include "config.h" #include "si446x.h" #include "ax25_pad.h" -#include "tracking.h" +#include "collector.h" #define GSP_FIX_OLD 0x0 #define GSP_FIX_CURRENT 0x1 @@ -52,7 +52,7 @@ void aprs_debug_getPacket(packet_t pp, char* buf, uint32_t len); -packet_t aprs_encode_position(const char *callsign, const char *path, uint16_t symbol, trackPoint_t *trackPoint); +packet_t aprs_encode_position(const char *callsign, const char *path, uint16_t symbol, dataPoint_t *dataPoint); packet_t aprs_encode_telemetry_configuration(const char *callsign, const char *path, uint8_t type); packet_t aprs_encode_message(const char *callsign, const char *path, const char *receiver, const char *text, const bool noCounter); packet_t aprs_encode_data_packet(const char *callsign, const char *path, char packetType, uint8_t *data); diff --git a/tracker/software/sleep.c b/tracker/software/sleep.c index 6ab18ab4..98a8c7ce 100644 --- a/tracker/software/sleep.c +++ b/tracker/software/sleep.c @@ -2,7 +2,7 @@ #include "hal.h" #include "sleep.h" #include "padc.h" -#include "tracking.h" +#include "collector.h" #include "debug.h" #include "padc.h" #include "pac1720.h" @@ -41,8 +41,8 @@ sysinterval_t waitForTrigger(sysinterval_t prev, sysinterval_t timeout) { /*switch(config->type) { - case TRIG_NEW_POINT: // Wait for new tracking point - waitForNewTrackPoint(); + case TRIG_NEW_POINT: // Wait for new data point + waitForNewDataPoint(); return chVTGetSystemTimeX(); case TRIG_TIMEOUT: // Wait for specified timeout @@ -60,13 +60,13 @@ sysinterval_t waitForTrigger(sysinterval_t prev, sysinterval_t timeout) return chThdSleepUntilWindowed(prev, prev + timeout); } -void trigger_new_tracking_point(void) +void trigger_new_data_point(void) { - uint32_t oldID = getLastTrackPoint()->id; - trackPoint_t *newtp; + uint32_t oldID = getLastDataPoint()->id; + dataPoint_t *newtp; do { // Wait for new serial ID to be deployed chThdSleep(TIME_MS2I(100)); - newtp = getLastTrackPoint(); + newtp = getLastDataPoint(); } while(newtp->id == oldID); } diff --git a/tracker/software/sleep.h b/tracker/software/sleep.h index 4a534dd5..6f37fb2c 100644 --- a/tracker/software/sleep.h +++ b/tracker/software/sleep.h @@ -5,12 +5,12 @@ #include "hal.h" #include "types.h" -#define WAIT_FOR_TRACKING_POINT trigger_new_tracking_point -#define TX_CONTINUOSLY trigger_immediately +#define WAIT_FOR_DATA_POINT trigger_new_data_point +#define TX_CONTINUOSLY trigger_immediately bool p_sleep(const sleep_conf_t *config); sysinterval_t waitForTrigger(sysinterval_t prev, sysinterval_t timeout); -void trigger_new_tracking_point(void); +void trigger_new_data_point(void); void trigger_immediately(void); #endif diff --git a/tracker/software/threads/tracking.c b/tracker/software/threads/collector.c similarity index 69% rename from tracker/software/threads/tracking.c rename to tracker/software/threads/collector.c index cb7b0450..30cf6ab6 100644 --- a/tracker/software/threads/tracking.c +++ b/tracker/software/threads/collector.c @@ -1,7 +1,7 @@ #include "ch.h" #include "hal.h" -#include "tracking.h" +#include "collector.h" #include "debug.h" #include "config.h" #include "ublox.h" @@ -16,28 +16,27 @@ #include "si446x.h" #include "log.h" -static trackPoint_t trackPoints[2]; -static trackPoint_t* lastTrackPoint; +static dataPoint_t dataPoints[2]; +static dataPoint_t* lastDataPoint; static bool threadStarted = false; -static bool tracking_useGPS = false; /** - * Returns most recent track point witch is complete. + * Returns most recent data point witch is complete. */ -trackPoint_t* getLastTrackPoint(void) +dataPoint_t* getLastDataPoint(void) { - return lastTrackPoint; + return lastDataPoint; } -void waitForNewTrackPoint(void) +void waitForNewDataPoint(void) { - uint32_t old_id = getLastTrackPoint()->id; - while(old_id == getLastTrackPoint()->id) + uint32_t old_id = getLastDataPoint()->id; + while(old_id == getLastDataPoint()->id) chThdSleep(TIME_S2I(1)); } -static void aquirePosition(trackPoint_t* tp, trackPoint_t* ltp, sysinterval_t timeout) +static void aquirePosition(dataPoint_t* tp, dataPoint_t* ltp, sysinterval_t timeout) { sysinterval_t start = chVTGetSystemTime(); @@ -46,9 +45,7 @@ static void aquirePosition(trackPoint_t* tp, trackPoint_t* ltp, sysinterval_t ti // Switch on GPS if enough power is available and GPS is needed by any position thread uint16_t batt = stm32_get_vbat(); - if(!tracking_useGPS) { // No position thread running - tp->gps_lock = GPS_OFF; - } else if(batt < conf_sram.gps_on_vbat) { + if(batt < conf_sram.gps_on_vbat) { tp->gps_lock = GPS_LOWBATT1; } else { @@ -129,7 +126,7 @@ static void aquirePosition(trackPoint_t* tp, trackPoint_t* ltp, sysinterval_t ti } } -static void measureVoltage(trackPoint_t* tp) +static void measureVoltage(dataPoint_t* tp) { tp->adc_vbat = stm32_get_vbat(); tp->adc_vsol = stm32_get_vsol(); @@ -139,7 +136,7 @@ static void measureVoltage(trackPoint_t* tp) static uint8_t bme280_error; -static void getSensors(trackPoint_t* tp) +static void getSensors(dataPoint_t* tp) { // Measure BME280 bme280_error = 0; @@ -196,7 +193,7 @@ static void getSensors(trackPoint_t* tp) tp->light_intensity = OV5640_getLastLightIntensity() & 0xFFFF; } -static void setSystemStatus(trackPoint_t* tp) { +static void setSystemStatus(dataPoint_t* tp) { // Set system errors tp->sys_error = 0; @@ -212,56 +209,56 @@ static void setSystemStatus(trackPoint_t* tp) { } /** - * Tracking Module (Thread) + * Data Collector (Thread) */ -THD_FUNCTION(trackingThread, arg) { +THD_FUNCTION(collectorThread, arg) { (void)arg; uint32_t id = 0; - lastTrackPoint = &trackPoints[0]; + lastDataPoint = &dataPoints[0]; // Read time from RTC ptime_t time; getTime(&time); - lastTrackPoint->gps_time = date2UnixTimestamp(&time); + lastDataPoint->gps_time = date2UnixTimestamp(&time); - // Get last tracking point from memory - TRACE_INFO("TRAC > Read last track point from flash memory"); - trackPoint_t* lastLogPoint = getNewestLogEntry(); + // Get last data point from memory + TRACE_INFO("TRAC > Read last data point from flash memory"); + dataPoint_t* lastLogPoint = getNewestLogEntry(); - if(lastLogPoint != NULL) { // If there has been stored a trackpoint, then get the last know GPS fix - trackPoints[0].reset = lastLogPoint->reset+1; - trackPoints[1].reset = lastLogPoint->reset+1; - lastTrackPoint->gps_lat = lastLogPoint->gps_lat; - lastTrackPoint->gps_lon = lastLogPoint->gps_lon; - lastTrackPoint->gps_alt = lastLogPoint->gps_alt; - lastTrackPoint->gps_sats = lastLogPoint->gps_sats; - lastTrackPoint->gps_ttff = lastLogPoint->gps_ttff; + if(lastLogPoint != NULL) { // If there has been stored a data point, then get the last know GPS fix + dataPoints[0].reset = lastLogPoint->reset+1; + dataPoints[1].reset = lastLogPoint->reset+1; + lastDataPoint->gps_lat = lastLogPoint->gps_lat; + lastDataPoint->gps_lon = lastLogPoint->gps_lon; + lastDataPoint->gps_alt = lastLogPoint->gps_alt; + lastDataPoint->gps_sats = lastLogPoint->gps_sats; + lastDataPoint->gps_ttff = lastLogPoint->gps_ttff; TRACE_INFO( - "TRAC > Last track point (from memory)\r\n" + "TRAC > Last data point (from memory)\r\n" "%s Reset %d ID %d\r\n" "%s Latitude: %d.%07ddeg\r\n" "%s Longitude: %d.%07ddeg\r\n" "%s Altitude: %d Meter", TRACE_TAB, lastLogPoint->reset, lastLogPoint->id, - TRACE_TAB, lastTrackPoint->gps_lat/10000000, (lastTrackPoint->gps_lat > 0 ? 1:-1)*lastTrackPoint->gps_lat%10000000, - TRACE_TAB, lastTrackPoint->gps_lon/10000000, (lastTrackPoint->gps_lon > 0 ? 1:-1)*lastTrackPoint->gps_lon%10000000, - TRACE_TAB, lastTrackPoint->gps_alt + TRACE_TAB, lastDataPoint->gps_lat/10000000, (lastDataPoint->gps_lat > 0 ? 1:-1)*lastDataPoint->gps_lat%10000000, + TRACE_TAB, lastDataPoint->gps_lon/10000000, (lastDataPoint->gps_lon > 0 ? 1:-1)*lastDataPoint->gps_lon%10000000, + TRACE_TAB, lastDataPoint->gps_alt ); } else { - TRACE_INFO("TRAC > No track point found in flash memory"); + TRACE_INFO("TRAC > No data point found in flash memory"); } - lastTrackPoint->gps_lock = GPS_LOG; // Mark trackPoint as LOG packet + lastDataPoint->gps_lock = GPS_LOG; // Mark dataPoint as LOG packet // Measure telemetry - measureVoltage(lastTrackPoint); - getSensors(lastTrackPoint); - setSystemStatus(lastTrackPoint); + measureVoltage(lastDataPoint); + getSensors(lastDataPoint); + setSystemStatus(lastDataPoint); - // Write Trackpoint to Flash memory - writeLogTrackPoint(lastTrackPoint); + // Write data point to Flash memory + writeLogDataPoint(lastDataPoint); // Wait for position threads to start chThdSleep(TIME_MS2I(500)); @@ -269,25 +266,25 @@ THD_FUNCTION(trackingThread, arg) { sysinterval_t cycle_time = chVTGetSystemTime(); while(true) { - TRACE_INFO("TRAC > Do module TRACKING MANAGER cycle"); + TRACE_INFO("TRAC > Do module DATA COLLECTOR cycle"); - trackPoint_t* tp = &trackPoints[(id+1) % 2]; // Current track point (the one which is processed now) - trackPoint_t* ltp = &trackPoints[ id % 2]; // Last track point + dataPoint_t* tp = &dataPoints[(id+1) % 2]; // Current data point (the one which is processed now) + dataPoint_t* ltp = &dataPoints[ id % 2]; // Last data point // Determine cycle time - sysinterval_t track_cycle_time = TIME_S2I(600); + sysinterval_t data_cycle_time = TIME_S2I(600); if(conf_sram.pos_pri.thread_conf.active && conf_sram.pos_sec.thread_conf.active) { // Both position threads are active - track_cycle_time = conf_sram.pos_pri.thread_conf.cycle < conf_sram.pos_sec.thread_conf.cycle ? conf_sram.pos_pri.thread_conf.cycle : conf_sram.pos_sec.thread_conf.cycle; // Choose the smallest cycle + data_cycle_time = conf_sram.pos_pri.thread_conf.cycle < conf_sram.pos_sec.thread_conf.cycle ? conf_sram.pos_pri.thread_conf.cycle : conf_sram.pos_sec.thread_conf.cycle; // Choose the smallest cycle } else if(conf_sram.pos_pri.thread_conf.active) { // Only primary position thread is active - track_cycle_time = conf_sram.pos_pri.thread_conf.cycle; + data_cycle_time = conf_sram.pos_pri.thread_conf.cycle; } else if(conf_sram.pos_sec.thread_conf.active) { // Only secondary position thread is active - track_cycle_time = conf_sram.pos_pri.thread_conf.cycle; + data_cycle_time = conf_sram.pos_pri.thread_conf.cycle; } else { // There must be an error - TRACE_ERROR("TRAC > Tracking manager started but no position thread is active"); + TRACE_ERROR("TRAC > Data collector started but no position thread is active"); } // Get GPS position - aquirePosition(tp, ltp, track_cycle_time - TIME_S2I(3)); + aquirePosition(tp, ltp, data_cycle_time - TIME_S2I(3)); tp->id = ++id; // Serial ID @@ -298,7 +295,7 @@ THD_FUNCTION(trackingThread, arg) { // Trace data unixTimestamp2Date(&time, tp->gps_time); - TRACE_INFO( "TRAC > New tracking point available (ID=%d)\r\n" + TRACE_INFO( "TRAC > New data point available (ID=%d)\r\n" "%s Time %04d-%02d-%02d %02d:%02d:%02d\r\n" "%s Pos %d.%05d %d.%05d Alt %dm\r\n" "%s Sats %d TTFF %dsec\r\n" @@ -312,33 +309,30 @@ THD_FUNCTION(trackingThread, arg) { TRACE_TAB, tp->sen_i1_press/10, tp->sen_i1_press%10, tp->sen_i1_temp/100, tp->sen_i1_temp%100, tp->sen_i1_hum/10, tp->sen_i1_hum%10 ); - // Write Trackpoint to Flash memory - writeLogTrackPoint(tp); + // Write data point to Flash memory + writeLogDataPoint(tp); - // Switch last track point - lastTrackPoint = tp; + // Switch last data point + lastDataPoint = tp; // Wait until cycle - cycle_time = chThdSleepUntilWindowed(cycle_time, cycle_time + track_cycle_time); + cycle_time = chThdSleepUntilWindowed(cycle_time, cycle_time + data_cycle_time); } } -void init_tracking_manager(bool useGPS) +void init_data_collector(void) { - if(useGPS) - tracking_useGPS = true; - if(!threadStarted) { threadStarted = true; - TRACE_INFO("TRAC > Startup tracking thread"); - thread_t *th = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(2*1024), "TRA", NORMALPRIO+1, trackingThread, NULL); + TRACE_INFO("TRAC > Startup data collector thread"); + thread_t *th = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(2*1024), "TRA", NORMALPRIO+1, collectorThread, NULL); if(!th) { // Print startup error, do not start watchdog for this thread TRACE_ERROR("TRAC > Could not startup thread (not enough memory available)"); } else { - chThdSleep(TIME_MS2I(300)); // Wait a little bit until tracking manager has initialized first dataset + chThdSleep(TIME_MS2I(300)); // Wait a little bit until data collector has initialized first dataset } } } diff --git a/tracker/software/threads/tracking.h b/tracker/software/threads/collector.h similarity index 93% rename from tracker/software/threads/tracking.h rename to tracker/software/threads/collector.h index e88de95a..ffa2f63a 100644 --- a/tracker/software/threads/tracking.h +++ b/tracker/software/threads/collector.h @@ -1,5 +1,5 @@ -#ifndef __TRACKING_H__ -#define __TRACKING_H__ +#ifndef __COLLECTOR_H__ +#define __COLLECTOR_H__ #include "ch.h" #include "hal.h" @@ -68,12 +68,12 @@ typedef struct { // Bit 5: I2C_E BME280_E2 // Bit 6: UART EVA7M // Bit 7: -} trackPoint_t; +} dataPoint_t; -void waitForNewTrackPoint(void); -trackPoint_t* getLastTrackPoint(void); +void waitForNewDataPoint(void); +dataPoint_t* getLastDataPoint(void); -void init_tracking_manager(bool useGPS); +void init_data_collector(void); #endif diff --git a/tracker/software/threads/image.c b/tracker/software/threads/rxtx/image.c similarity index 99% rename from tracker/software/threads/image.c rename to tracker/software/threads/rxtx/image.c index d37e4c81..51d40e86 100644 --- a/tracker/software/threads/image.c +++ b/tracker/software/threads/rxtx/image.c @@ -16,7 +16,7 @@ #include "watchdog.h" #include "flash.h" #include "sd.h" -#include "tracking.h" +#include "collector.h" #include "image.h" const uint8_t noCameraFound[4071] = { @@ -583,7 +583,7 @@ THD_FUNCTION(imgThread, arg) if(initSD()) { char filename[32]; - chsnprintf(filename, sizeof(filename), "r%02xi%04x.jpg", getLastTrackPoint()->reset % 0xFF, (gimage_id-1) % 0xFFFF); + chsnprintf(filename, sizeof(filename), "r%02xi%04x.jpg", getLastDataPoint()->reset % 0xFF, (gimage_id-1) % 0xFFFF); // Find SOI uint32_t soi; diff --git a/tracker/software/threads/image.h b/tracker/software/threads/rxtx/image.h similarity index 100% rename from tracker/software/threads/image.h rename to tracker/software/threads/rxtx/image.h diff --git a/tracker/software/threads/log.c b/tracker/software/threads/rxtx/log.c similarity index 78% rename from tracker/software/threads/log.c rename to tracker/software/threads/rxtx/log.c index 92246ece..65f3e45b 100644 --- a/tracker/software/threads/log.c +++ b/tracker/software/threads/rxtx/log.c @@ -16,7 +16,7 @@ #include "log.h" -#define LOG_POINTS_IN_SECTOR (0x20000 / sizeof(trackPoint_t)) +#define LOG_POINTS_IN_SECTOR (0x20000 / sizeof(dataPoint_t)) #define LOG_POS_IN_SECTOR(id) ((id) % LOG_POINTS_IN_SECTOR) #define LOG_SECTOR_ID(id) ((id) / LOG_POINTS_IN_SECTOR) #define LOG_RSTandID(tp) (((uint64_t)(tp)->reset << 32) & (tp)->id) @@ -24,11 +24,11 @@ static uint16_t log_id = 0; -static trackPoint_t* getLogBuffer(uint16_t id) +static dataPoint_t* getLogBuffer(uint16_t id) { - uint32_t addr = LOG_FLASH_ADDR + LOG_SECTOR_ID(id) * 0x20000 + LOG_POS_IN_SECTOR(id) * sizeof(trackPoint_t); - if(addr >= LOG_FLASH_ADDR && addr <= LOG_FLASH_ADDR+LOG_FLASH_SIZE-sizeof(trackPoint_t)) - return (trackPoint_t*)addr; + uint32_t addr = LOG_FLASH_ADDR + LOG_SECTOR_ID(id) * 0x20000 + LOG_POS_IN_SECTOR(id) * sizeof(dataPoint_t); + if(addr >= LOG_FLASH_ADDR && addr <= LOG_FLASH_ADDR+LOG_FLASH_SIZE-sizeof(dataPoint_t)) + return (dataPoint_t*)addr; else return NULL; // Outside of memory address allocation } @@ -37,9 +37,9 @@ static trackPoint_t* getLogBuffer(uint16_t id) * Returns next free log entry address in memory. Returns 0 if all cells are * filled with data */ -static trackPoint_t* getNextFreeLogAddress(void) +static dataPoint_t* getNextFreeLogAddress(void) { - trackPoint_t* tp; + dataPoint_t* tp; for(uint32_t i=0; (tp = getLogBuffer(i)) != NULL; i++) if(LOG_IS_EMPTY(tp)) return tp; @@ -47,11 +47,11 @@ static trackPoint_t* getNextFreeLogAddress(void) return NULL; } -trackPoint_t* getNewestLogEntry(void) +dataPoint_t* getNewestLogEntry(void) { - trackPoint_t* last_tp = NULL; + dataPoint_t* last_tp = NULL; uint64_t last_id = 0x0; - trackPoint_t* tp; + dataPoint_t* tp; for(uint32_t i=0; (tp = getLogBuffer(i)) != NULL; i++) { if(!LOG_IS_EMPTY(tp) && last_id <= LOG_RSTandID(tp)) { last_id = LOG_RSTandID(tp); @@ -61,11 +61,11 @@ trackPoint_t* getNewestLogEntry(void) return last_tp; } -trackPoint_t* getOldestLogEntry(void) +dataPoint_t* getOldestLogEntry(void) { - trackPoint_t* first_tp = NULL; + dataPoint_t* first_tp = NULL; uint64_t first_id = 0xFFFFFFFFFFFFFFFF; - trackPoint_t* tp; + dataPoint_t* tp; for(uint32_t i=0; (tp = getLogBuffer(i)) != NULL; i++) { if(!LOG_IS_EMPTY(tp) && first_id >= LOG_RSTandID(tp)) { first_id = LOG_RSTandID(tp); @@ -90,10 +90,10 @@ static void eraseOldestLogData(void) } } -void writeLogTrackPoint(trackPoint_t* tp) +void writeLogDataPoint(dataPoint_t* tp) { // Get address to write on - trackPoint_t* address = getNextFreeLogAddress(); + dataPoint_t* address = getNextFreeLogAddress(); if(address == NULL) // Memory completly used, erase oldest data { eraseOldestLogData(); @@ -108,21 +108,21 @@ void writeLogTrackPoint(trackPoint_t* tp) // Write data into flash TRACE_INFO("LOG > Flash write (ADDR=%08x)", address); flashSectorBegin(flashSectorAt((uint32_t)address)); - flashWrite((uint32_t)address, (char*)tp, sizeof(trackPoint_t)); + flashWrite((uint32_t)address, (char*)tp, sizeof(dataPoint_t)); flashSectorEnd(flashSectorAt((uint32_t)address)); // Verify - if(flashCompare((uint32_t)address, (char*)tp, sizeof(trackPoint_t))) { + if(flashCompare((uint32_t)address, (char*)tp, sizeof(dataPoint_t))) { TRACE_INFO("LOG > Flash write OK"); } else { TRACE_ERROR("LOG > Flash write failed"); } } -static trackPoint_t* getNextLogTrackPoint(uint8_t density) +static dataPoint_t* getNextLogDataPoint(uint8_t density) { // Determine sector - trackPoint_t *tp; + dataPoint_t *tp; uint32_t i = 0; do { if((tp = getLogBuffer(log_id))) { @@ -131,7 +131,7 @@ static trackPoint_t* getNextLogTrackPoint(uint8_t density) log_id = 0; tp = getLogBuffer(0); } - } while(LOG_IS_EMPTY(tp) && i++ < LOG_FLASH_SIZE / sizeof(trackPoint_t)); + } while(LOG_IS_EMPTY(tp) && i++ < LOG_FLASH_SIZE / sizeof(dataPoint_t)); return LOG_IS_EMPTY(tp) ? NULL : tp; } @@ -151,12 +151,12 @@ THD_FUNCTION(logThread, arg) if(!p_sleep(&conf->thread_conf.sleep_conf)) { // Get log from memory - trackPoint_t *log = getNextLogTrackPoint(conf->density); + dataPoint_t *log = getNextLogDataPoint(conf->density); if(log) { // Encode Base91 - uint8_t pkt_base91[BASE91LEN(sizeof(trackPoint_t))]; - base91_encode((uint8_t*)log, pkt_base91, sizeof(trackPoint_t)); + uint8_t pkt_base91[BASE91LEN(sizeof(dataPoint_t))]; + base91_encode((uint8_t*)log, pkt_base91, sizeof(dataPoint_t)); // Encode and transmit log packet packet_t packet = aprs_encode_data_packet(conf->call, conf->path, 'L', pkt_base91); // Encode packet diff --git a/tracker/software/threads/log.h b/tracker/software/threads/rxtx/log.h similarity index 61% rename from tracker/software/threads/log.h rename to tracker/software/threads/rxtx/log.h index 3a92e87f..ce667319 100644 --- a/tracker/software/threads/log.h +++ b/tracker/software/threads/rxtx/log.h @@ -1,16 +1,16 @@ #ifndef __LOG_H__ #define __LOG_H__ -#include "tracking.h" +#include "collector.h" #define LOG_FLASH_ADDR 0x08080000 /* Log flash memory address */ #define LOG_FLASH_SIZE 0x100000 /* Log flash memory size */ void start_logging_thread(thd_log_conf_t *conf); -trackPoint_t* getNewestLogEntry(void); -trackPoint_t* getOldestLogEntry(void); -void writeLogTrackPoint(trackPoint_t* tp); +dataPoint_t* getNewestLogEntry(void); +dataPoint_t* getOldestLogEntry(void); +void writeLogDataPoint(dataPoint_t* tp); #endif diff --git a/tracker/software/threads/position.c b/tracker/software/threads/rxtx/position.c similarity index 93% rename from tracker/software/threads/position.c rename to tracker/software/threads/rxtx/position.c index acdb02a9..259e68fe 100644 --- a/tracker/software/threads/position.c +++ b/tracker/software/threads/rxtx/position.c @@ -19,8 +19,8 @@ THD_FUNCTION(posThread, arg) // Wait if(conf->thread_conf.init_delay) chThdSleep(conf->thread_conf.init_delay); - // Start tracking manager (if not running yet) - init_tracking_manager(true); + // Start data collector (if not running yet) + init_data_collector(); // Start position thread TRACE_INFO("POS > Startup position thread"); @@ -33,15 +33,15 @@ THD_FUNCTION(posThread, arg) { TRACE_INFO("POS > Do module POSITION cycle"); - TRACE_INFO("POS > Get last track point"); - trackPoint_t* trackPoint = getLastTrackPoint(); + TRACE_INFO("POS > Get last data point"); + dataPoint_t* dataPoint = getLastDataPoint(); if(!p_sleep(&conf->thread_conf.sleep_conf)) { TRACE_INFO("POS > Transmit position"); // Encode/Transmit position packet - packet_t packet = aprs_encode_position(conf->call, conf->path, conf->symbol, trackPoint); + packet_t packet = aprs_encode_position(conf->call, conf->path, conf->symbol, dataPoint); transmitOnRadio(packet, conf->radio_conf.freq, conf->radio_conf.step, diff --git a/tracker/software/threads/position.h b/tracker/software/threads/rxtx/position.h similarity index 100% rename from tracker/software/threads/position.h rename to tracker/software/threads/rxtx/position.h diff --git a/tracker/software/threads/radio/radio.c b/tracker/software/threads/rxtx/radio.c similarity index 100% rename from tracker/software/threads/radio/radio.c rename to tracker/software/threads/rxtx/radio.c diff --git a/tracker/software/threads/radio/radio.h b/tracker/software/threads/rxtx/radio.h similarity index 100% rename from tracker/software/threads/radio/radio.h rename to tracker/software/threads/rxtx/radio.h