Telemetry refactoring - Fixes #1634

This commit is contained in:
bsongis
2014-11-08 12:06:42 +01:00
parent 7d8ca6931b
commit 88d9691d16
105 changed files with 5789 additions and 3449 deletions
+84 -41
View File
@@ -109,41 +109,7 @@ const pm_char * openLogs()
}
if (f_size(&g_oLogFile) == 0) {
#if defined(RTCLOCK)
f_puts("Date,Time,", &g_oLogFile);
#else
f_puts("Time,", &g_oLogFile);
#endif
#if defined(FRSKY)
#if defined(CPUARM) && defined(SWR)
f_puts("SWR,RSSI,A1,A2,A3,A4,", &g_oLogFile);
#elif defined(CPUARM)
f_puts("RSSI,A1,A2,A3,A4,", &g_oLogFile);
#else
f_puts("Buffer,RX,TX,A1,A2,", &g_oLogFile);
#endif
#endif
#if defined(FRSKY_HUB)
if (IS_USR_PROTO_FRSKY_HUB()) {
f_puts("GPS Date,GPS Time,Long,Lat,Course,GPS Speed(kts),GPS Alt,Baro Alt(", &g_oLogFile);
f_puts(TELEMETRY_BARO_ALT_UNIT, &g_oLogFile);
f_puts("),Vertical Speed,Air Speed(kts),Temp1,Temp2,RPM,Fuel," TELEMETRY_CELLS_LABEL "Current,Consumption,Vfas,AccelX,AccelY,AccelZ,", &g_oLogFile);
}
#endif
#if defined(WS_HOW_HIGH)
if (IS_USR_PROTO_WS_HOW_HIGH()) {
f_puts("WSHH Alt,", &g_oLogFile);
}
#endif
#if defined(PCBTARANIS)
f_puts("Rud,Ele,Thr,Ail,S1,S2,S3,LS,RS,SA,SB,SC,SD,SE,SF,SG,SH\n", &g_oLogFile);
#else
f_puts("Rud,Ele,Thr,Ail,P1,P2,P3,THR,RUD,ELE,3POS,AIL,GEA,TRN\n", &g_oLogFile);
#endif
writeHeader();
}
else {
result = f_lseek(&g_oLogFile, f_size(&g_oLogFile)); // append
@@ -166,11 +132,68 @@ void closeLogs()
lastLogTime = 0;
}
#if !defined(CPUARM)
getvalue_t getConvertedTelemetryValue(getvalue_t val, uint8_t unit)
{
convertUnit(val, unit);
return val;
}
#endif
void writeHeader()
{
#if defined(RTCLOCK)
f_puts("Date,Time,", &g_oLogFile);
#else
f_puts("Time,", &g_oLogFile);
#endif
#if defined(FRSKY)
#if defined(CPUARM) && defined(SWR)
f_puts("SWR,RSSI,", &g_oLogFile);
#elif defined(CPUARM)
f_puts("RSSI,", &g_oLogFile);
#else
f_puts("Buffer,RX,TX,A1,A2,", &g_oLogFile);
#if defined(FRSKY_HUB)
if (IS_USR_PROTO_FRSKY_HUB()) {
f_puts("GPS Date,GPS Time,Long,Lat,Course,GPS Speed(kts),GPS Alt,Baro Alt(", &g_oLogFile);
f_puts(TELEMETRY_BARO_ALT_UNIT, &g_oLogFile);
f_puts("),Vertical Speed,Air Speed(kts),Temp1,Temp2,RPM,Fuel," TELEMETRY_CELLS_LABEL "Current,Consumption,Vfas,AccelX,AccelY,AccelZ,", &g_oLogFile);
}
#endif
#if defined(WS_HOW_HIGH)
if (IS_USR_PROTO_WS_HOW_HIGH()) {
f_puts("WSHH Alt,", &g_oLogFile);
}
#endif
#endif
#if defined(CPUARM)
char label[TELEM_LABEL_LEN+7];
for (int i=0; i<TELEM_VALUES_MAX; i++) {
TelemetrySensor & sensor = g_model.telemetrySensors[i];
if (sensor.logs) {
memset(label, 0, sizeof(label));
zchar2str(label, sensor.label, TELEM_LABEL_LEN);
if (sensor.unit != UNIT_RAW) {
strcat(label, "(");
strncat(label, STR_VTELEMUNIT+1+3*sensor.unit, 3);
strcat(label, ")");
}
strcat(label, ",");
f_puts(label, &g_oLogFile);
}
}
#endif
#endif
#if defined(PCBTARANIS)
f_puts("Rud,Ele,Thr,Ail,S1,S2,S3,LS,RS,SA,SB,SC,SD,SE,SF,SG,SH\n", &g_oLogFile);
#else
f_puts("Rud,Ele,Thr,Ail,P1,P2,P3,THR,RUD,ELE,3POS,AIL,GEA,TRN\n", &g_oLogFile);
#endif
}
// TODO test when disk full
void writeLogs()
@@ -204,23 +227,21 @@ void writeLogs()
}
f_printf(&g_oLogFile, "%4d-%02d-%02d,%02d:%02d:%02d.%02d0,", utm.tm_year+1900, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100);
}
#else // #if defined(RTCLOCK)
#else
f_printf(&g_oLogFile, "%d,", tmr10ms);
#endif // #if defined(RTCLOCK)
#endif
#if defined(FRSKY)
#if defined(CPUARM) && defined(SWR)
f_printf(&g_oLogFile, "%d,%d,", RAW_FRSKY_MINMAX(frskyData.swr), RAW_FRSKY_MINMAX(frskyData.rssi[0]));
f_printf(&g_oLogFile, "%d,%d,", RAW_FRSKY_MINMAX(frskyData.swr), RAW_FRSKY_MINMAX(frskyData.rssi));
#elif defined(CPUARM)
f_printf(&g_oLogFile, "%d,", RAW_FRSKY_MINMAX(frskyData.rssi[0]));
f_printf(&g_oLogFile, "%d,", RAW_FRSKY_MINMAX(frskyData.rssi));
#else
f_printf(&g_oLogFile, "%d,%d,%d,", frskyStreaming, RAW_FRSKY_MINMAX(frskyData.rssi[0]), RAW_FRSKY_MINMAX(frskyData.rssi[1]));
#endif
for (uint8_t i=0; i<MAX_FRSKY_A_CHANNELS; i++) {
int16_t converted_value = applyChannelRatio(i, RAW_FRSKY_MINMAX(frskyData.analog[i]));
f_printf(&g_oLogFile, "%d.%02d,", converted_value/100, converted_value%100);
}
#endif
#if defined(FRSKY_HUB)
TELEMETRY_BARO_ALT_PREPARE();
@@ -264,6 +285,28 @@ void writeLogs()
if (IS_USR_PROTO_WS_HOW_HIGH()) {
f_printf(&g_oLogFile, "%d,", TELEMETRY_RELATIVE_BARO_ALT_BP);
}
#endif
#endif
#if defined(CPUARM)
for (int i=0; i<TELEM_VALUES_MAX; i++) {
TelemetrySensor & sensor = g_model.telemetrySensors[i];
TelemetryItem & telemetryItem = telemetryItems[i];
if (sensor.logs) {
if (sensor.prec == 2) {
div_t qr = div(telemetryItem.value, 100);
f_printf(&g_oLogFile, "%d.%02d,", qr.quot, qr.rem);
}
else if (sensor.prec == 1) {
div_t qr = div(telemetryItem.value, 10);
f_printf(&g_oLogFile, "%d.%d,", qr.quot, qr.rem);
}
else {
f_printf(&g_oLogFile, "%d,", telemetryItem.value);
}
}
}
#endif
#endif
for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) {