Skip to content

Commit

Permalink
Fix for vbat and amps values in decoder and render tool
Browse files Browse the repository at this point in the history
  • Loading branch information
basdelfos committed Feb 27, 2018
1 parent 3c0b9ea commit 58885d2
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 117 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
/.cproject
/.project
/dist/

/.vscode/

/visual-studio/.vs/
/.vs/
54 changes: 14 additions & 40 deletions src/blackbox_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,24 +176,22 @@ static bool fprintfMainFieldInUnit(flightLog_t *log, FILE *file, int fieldIndex,
* for a well-known field that corresponds to the given fieldIndex.)
*/
switch (unit) {
case UNIT_VOLTS:
if (fieldIndex == log->mainFieldIndexes.vbatLatest) {
fprintf(file, "%.3f", flightLogVbatADCToMillivolts(log, (uint16_t)fieldValue) / 1000.0);
return true;
}
break;
case UNIT_MILLIVOLTS:
if (fieldIndex == log->mainFieldIndexes.vbatLatest) {
fprintf(file, "%u", flightLogVbatADCToMillivolts(log, (uint16_t)fieldValue));
return true;
}
break;
case UNIT_AMPS:
// Betaflight already does the ADC conversion
fprintf(file, "%3u", (int32_t) fieldValue * 100);
return true;
case UNIT_VOLTS:
// Betaflight already does the ADC conversion
fprintf(file, "%.1f", (double) fieldValue / 10);
return true;
case UNIT_MILLIAMPS:
if (fieldIndex == log->mainFieldIndexes.amperageLatest) {
fprintfMilliampsInUnit(file, flightLogAmperageADCToMilliamps(log, (uint16_t)fieldValue), unit);
return true;
}
// Betaflight already does the ADC conversion
fprintf(file, "%3u", (int32_t) fieldValue * 10);
return true;
case UNIT_AMPS:
// Betaflight already does the ADC conversion
fprintf(file, "%.2f", (double) fieldValue / 100);
return true;
break;
case UNIT_CENTIMETERS:
if (fieldIndex == log->mainFieldIndexes.BaroAlt) {
Expand Down Expand Up @@ -284,30 +282,6 @@ void onEvent(flightLog_t *log, flightLogEvent_t *event)
case FLIGHT_LOG_EVENT_SYNC_BEEP:
fprintf(eventFile, "{\"name\":\"Sync beep\", \"time\":%" PRId64 "}\n", event->data.syncBeep.time);
break;
case FLIGHT_LOG_EVENT_AUTOTUNE_CYCLE_START:
fprintf(eventFile, "{\"name\":\"Autotune cycle start\", \"time\":%" PRId64 ", \"data\":{\"phase\":%d,\"cycle\":%d,\"p\":%u,\"i\":%u,\"d\":%u,\"rising\":%d}}\n", lastFrameTime,
event->data.autotuneCycleStart.phase, event->data.autotuneCycleStart.cycle & 0x7F /* Top bit used for "rising: */,
event->data.autotuneCycleStart.p, event->data.autotuneCycleStart.i, event->data.autotuneCycleStart.d,
event->data.autotuneCycleStart.cycle >> 7);
break;
case FLIGHT_LOG_EVENT_AUTOTUNE_CYCLE_RESULT:
fprintf(eventFile, "{\"name\":\"Autotune cycle result\", \"time\":%" PRId64 ", \"data\":{\"overshot\":%s,\"timedout\":%s,\"p\":%u,\"i\":%u,\"d\":%u}}\n", lastFrameTime,
event->data.autotuneCycleResult.flags & FLIGHT_LOG_EVENT_AUTOTUNE_FLAG_OVERSHOT ? "true" : "false",
event->data.autotuneCycleResult.flags & FLIGHT_LOG_EVENT_AUTOTUNE_FLAG_TIMEDOUT ? "true" : "false",
event->data.autotuneCycleResult.p, event->data.autotuneCycleResult.i, event->data.autotuneCycleResult.d);
break;
case FLIGHT_LOG_EVENT_AUTOTUNE_TARGETS:
fprintf(eventFile, "{\"name\":\"Autotune cycle targets\", \"time\":%" PRId64 ", \"data\":{\"currentAngle\":%.1f,\"targetAngle\":%d,\"targetAngleAtPeak\":%d,\"firstPeakAngle\":%.1f,\"secondPeakAngle\":%.1f}}\n", lastFrameTime,
event->data.autotuneTargets.currentAngle / 10.0,
event->data.autotuneTargets.targetAngle, event->data.autotuneTargets.targetAngleAtPeak,
event->data.autotuneTargets.firstPeakAngle / 10.0, event->data.autotuneTargets.secondPeakAngle / 10.0);
break;
case FLIGHT_LOG_EVENT_GTUNE_CYCLE_RESULT:
fprintf(eventFile, "{\"name\":\"Gtune result\", \"time\":%" PRId64 ", \"data\":{\"axis\":%d,\"gyroAVG\":%d,\"newP\":%d}}\n", lastFrameTime,
event->data.gtuneCycleResult.axis,
event->data.gtuneCycleResult.gyroAVG,
event->data.gtuneCycleResult.newP);
break;
case FLIGHT_LOG_EVENT_INFLIGHT_ADJUSTMENT:
fprintf(eventFile, "{\"name\":\"Inflight adjustment\", \"time\":%" PRId64 ", \"data\":{\"adjustmentFunction\":\"%s\",\"value\":", lastFrameTime,
INFLIGHT_ADJUSTMENT_FUNCTIONS[event->data.inflightAdjustment.adjustmentFunction & 127]);
Expand Down
7 changes: 5 additions & 2 deletions src/blackbox_fielddefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ const char * const FLIGHT_LOG_FLIGHT_MODE_NAME[] = {
"GPS_HOME",
"GPS_HOLD",
"HEADFREE",
"AUTOTUNE",
"UNUSED",
"PASSTHRU",
"SONAR"
"RANGEFINDER_MODE",
"FAILSAFE_MODE"
};

const char * const FLIGHT_LOG_FLIGHT_STATE_NAME[] = {
Expand All @@ -26,4 +27,6 @@ const char * const FLIGHT_LOG_FAILSAFE_PHASE_NAME[] = {
"RX_LOSS_DETECTED",
"LANDING",
"LANDED"
"FAILSAFE_RX_LOSS_MONITORING",
"FAILSAFE_RX_LOSS_RECOVERED"
};
49 changes: 7 additions & 42 deletions src/blackbox_fielddefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ typedef enum {
GPS_HOME_MODE = (1 << 4),
GPS_HOLD_MODE = (1 << 5),
HEADFREE_MODE = (1 << 6),
AUTOTUNE_MODE = (1 << 7),
UNUSED_MODE = (1 << 7), // old autotune
PASSTHRU_MODE = (1 << 8),
SONAR_MODE = (1 << 9),
RANGEFINDER_MODE= (1 << 9),
FAILSAFE_MODE = (1 << 10)
} flightModeFlags_e;

#define FLIGHT_LOG_FLIGHT_MODE_COUNT 10
Expand All @@ -128,7 +129,9 @@ typedef enum {
FAILSAFE_IDLE = 0,
FAILSAFE_RX_LOSS_DETECTED,
FAILSAFE_LANDING,
FAILSAFE_LANDED
FAILSAFE_LANDED,
FAILSAFE_RX_LOSS_MONITORING,
FAILSAFE_RX_LOSS_RECOVERED
} failsafePhase_e;

extern const char * const FLIGHT_LOG_FAILSAFE_PHASE_NAME[];
Expand All @@ -137,50 +140,16 @@ extern const char * const FLIGHT_LOG_FAILSAFE_PHASE_NAME[];

typedef enum FlightLogEvent {
FLIGHT_LOG_EVENT_SYNC_BEEP = 0,
FLIGHT_LOG_EVENT_AUTOTUNE_CYCLE_START = 10,
FLIGHT_LOG_EVENT_AUTOTUNE_CYCLE_RESULT = 11,
FLIGHT_LOG_EVENT_AUTOTUNE_TARGETS = 12,
FLIGHT_LOG_EVENT_INFLIGHT_ADJUSTMENT = 13,
FLIGHT_LOG_EVENT_LOGGING_RESUME = 14,
FLIGHT_LOG_EVENT_GTUNE_CYCLE_RESULT = 20,
FLIGHT_LOG_EVENT_FLIGHTMODE = 30, // Add new event type for flight mode status.
FLIGHT_LOG_EVENT_LOG_END = 255
} FlightLogEvent;

typedef struct flightLogEvent_syncBeep_t {
int64_t time;
} flightLogEvent_syncBeep_t;

typedef struct flightLogEvent_autotuneCycleStart_t {
uint8_t phase;
uint8_t cycle;
uint8_t p;
uint8_t i;
uint8_t d;
uint8_t rising;
} flightLogEvent_autotuneCycleStart_t;

#define FLIGHT_LOG_EVENT_AUTOTUNE_FLAG_OVERSHOT 1
#define FLIGHT_LOG_EVENT_AUTOTUNE_FLAG_TIMEDOUT 2

typedef struct flightLogEvent_autotuneCycleResult_t {
uint8_t flags;
uint8_t p;
uint8_t i;
uint8_t d;
} flightLogEvent_autotuneCycleResult_t;

typedef struct flightLogEvent_autotuneTargets_t {
int16_t currentAngle; // in decidegrees
int8_t targetAngle, targetAngleAtPeak; // in degrees
int16_t firstPeakAngle, secondPeakAngle; // in decidegrees
} flightLogEvent_autotuneTargets_t;

typedef struct flightLogEvent_gtuneCycleResult_t {
uint8_t axis;
int32_t gyroAVG;
int16_t newP;
} flightLogEvent_gtuneCycleResult_t;

typedef struct flightLogEvent_inflightAdjustment_t {
uint8_t adjustmentFunction;
int32_t newValue;
Expand All @@ -195,10 +164,6 @@ typedef struct flightLogEvent_loggingResume_t {
typedef union flightLogEventData_t
{
flightLogEvent_syncBeep_t syncBeep;
flightLogEvent_autotuneCycleStart_t autotuneCycleStart;
flightLogEvent_autotuneCycleResult_t autotuneCycleResult;
flightLogEvent_autotuneTargets_t autotuneTargets;
flightLogEvent_gtuneCycleResult_t gtuneCycleResult;
flightLogEvent_inflightAdjustment_t inflightAdjustment;
flightLogEvent_loggingResume_t loggingResume;
} flightLogEventData_t;
Expand Down
6 changes: 3 additions & 3 deletions src/blackbox_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -935,12 +935,12 @@ void drawAccelerometerData(cairo_t *cr, int64_t *frame)
}

if (flightLog->mainFieldIndexes.vbatLatest > -1) {
lastVoltage = (lastVoltage * 2 + flightLogVbatADCToMillivolts(flightLog, frame[flightLog->mainFieldIndexes.vbatLatest]) / (1000.0 * fieldMeta.numCells)) / 3;
lastVoltage = (lastVoltage * 2 + frame[flightLog->mainFieldIndexes.vbatLatest]) / 3;

cairo_move_to(cr, X_POS_LABEL, options.imageHeight - 8 - (extent.height + 8));
cairo_show_text(cr, "Batt. cell");
cairo_show_text(cr, "Batt.");

snprintf(labelBuf, sizeof(labelBuf), "%.2f V", lastVoltage);
snprintf(labelBuf, sizeof(labelBuf), "%.2f V", lastVoltage / 10);

cairo_move_to(cr, X_POS_VALUE, options.imageHeight - 8 - (extent.height + 8));
cairo_show_text(cr, labelBuf);
Expand Down
25 changes: 0 additions & 25 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,31 +807,6 @@ static void parseEventFrame(flightLog_t *log, mmapStream_t *stream, bool raw)
case FLIGHT_LOG_EVENT_SYNC_BEEP:
data->syncBeep.time = streamReadUnsignedVB(stream) + log->private->timeRolloverAccumulator;
break;
case FLIGHT_LOG_EVENT_AUTOTUNE_CYCLE_START:
data->autotuneCycleStart.phase = streamReadByte(stream);
data->autotuneCycleStart.cycle = streamReadByte(stream);
data->autotuneCycleStart.p = streamReadByte(stream);
data->autotuneCycleStart.i = streamReadByte(stream);
data->autotuneCycleStart.d = streamReadByte(stream);
break;
case FLIGHT_LOG_EVENT_AUTOTUNE_CYCLE_RESULT:
data->autotuneCycleResult.flags = streamReadByte(stream);
data->autotuneCycleResult.p = streamReadByte(stream);
data->autotuneCycleResult.i = streamReadByte(stream);
data->autotuneCycleResult.d = streamReadByte(stream);
break;
case FLIGHT_LOG_EVENT_AUTOTUNE_TARGETS:
data->autotuneTargets.currentAngle = streamReadS16(stream);
data->autotuneTargets.targetAngle = (int8_t) streamReadByte(stream);
data->autotuneTargets.targetAngleAtPeak = (int8_t) streamReadByte(stream);
data->autotuneTargets.firstPeakAngle = streamReadS16(stream);
data->autotuneTargets.secondPeakAngle = streamReadS16(stream);
break;
case FLIGHT_LOG_EVENT_GTUNE_CYCLE_RESULT:
data->gtuneCycleResult.axis = streamReadByte(stream);
data->gtuneCycleResult.gyroAVG = streamReadSignedVB(stream);
data->gtuneCycleResult.newP = streamReadS16(stream);
break;
case FLIGHT_LOG_EVENT_INFLIGHT_ADJUSTMENT:
data->inflightAdjustment.adjustmentFunction = streamReadByte(stream);
if (data->inflightAdjustment.adjustmentFunction > 127) {
Expand Down
1 change: 0 additions & 1 deletion visual-studio/.gitignore

This file was deleted.

5 changes: 3 additions & 2 deletions visual-studio/blackbox_decode/blackbox_decode.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
Expand All @@ -11,12 +11,13 @@
<Keyword>Win32Proj</Keyword>
<RootNamespace>Baseflightblackboxtools</RootNamespace>
<ProjectName>blackbox_decode</ProjectName>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion visual-studio/blackbox_render/blackbox_render.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
<ProjectGuid>{9FA8381C-1218-496B-AE19-030734EAEC42}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>w</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion visual-studio/encoder_testbed/encoder_testbed.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
<ProjectGuid>{50E54D2A-4259-459A-94E0-679BD64080DD}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>encoder_testbed</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down

0 comments on commit 58885d2

Please sign in to comment.