Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Add decoding for failsafePhase field
Browse files Browse the repository at this point in the history
  • Loading branch information
thenickdude committed May 18, 2015
1 parent e5a09bc commit bd6944a
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/blackbox_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ void outputGPSFrame(flightLog_t *log, int32_t *frame)

void outputSlowFrameFields(flightLog_t *log, int32_t *frame)
{
enum {
BUFFER_LEN = 1024
};
char buffer[BUFFER_LEN];

bool needComma = false;

for (int i = 0; i < log->frameDefs['S'].fieldCount; i++) {
Expand All @@ -471,17 +476,17 @@ void outputSlowFrameFields(flightLog_t *log, int32_t *frame)

if ((i == log->slowFieldIndexes.flightModeFlags || i == log->slowFieldIndexes.stateFlags)
&& options.unitFlags == UNIT_FLAGS) {
enum {
BUFFER_LEN = 1024
};
char buffer[BUFFER_LEN];

if (i == log->slowFieldIndexes.flightModeFlags) {
flightlogFlightModeToString(frame[i], buffer, BUFFER_LEN);
} else {
flightlogFlightStateToString(frame[i], buffer, BUFFER_LEN);
}

fprintf(csvFile, "%s", buffer);
} else if (i == log->slowFieldIndexes.failsafePhase && options.unitFlags == UNIT_FLAGS) {
flightlogFailsafePhaseToString(frame[i], buffer, BUFFER_LEN);

fprintf(csvFile, "%s", buffer);
} else {
//Print raw
Expand Down Expand Up @@ -769,10 +774,17 @@ void applyFieldUnits(flightLog_t *log)
}
}

// Slow frame fields:
if (log->slowFieldIndexes.flightModeFlags > -1) {
slowFieldUnit[log->slowFieldIndexes.flightModeFlags] = options.unitFlags;
}
if (log->slowFieldIndexes.stateFlags > -1) {
slowFieldUnit[log->slowFieldIndexes.stateFlags] = options.unitFlags;
}
if (log->slowFieldIndexes.failsafePhase > -1) {
slowFieldUnit[log->slowFieldIndexes.failsafePhase] = options.unitFlags;
}

}

void writeMainCSVHeader(flightLog_t *log)
Expand Down
7 changes: 7 additions & 0 deletions src/blackbox_fielddefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ const char * const FLIGHT_LOG_FLIGHT_STATE_NAME[] = {
"SMALL_ANGLE",
"FIXED_WING"
};

const char * const FLIGHT_LOG_FAILSAFE_PHASE_NAME[] = {
"IDLE",
"RX_LOSS_DETECTED",
"LANDING",
"LANDED"
};
11 changes: 11 additions & 0 deletions src/blackbox_fielddefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ extern const char * const FLIGHT_LOG_FLIGHT_STATE_NAME[];

#define FLIGHT_LOG_FLIGHT_STATE_COUNT 5

typedef enum {
FAILSAFE_IDLE = 0,
FAILSAFE_RX_LOSS_DETECTED,
FAILSAFE_LANDING,
FAILSAFE_LANDED
} failsafePhase_e;

extern const char * const FLIGHT_LOG_FAILSAFE_PHASE_NAME[];

#define FLIGHT_LOG_FAILSAFE_PHASE_COUNT 4

typedef enum FlightLogEvent {
FLIGHT_LOG_EVENT_SYNC_BEEP = 0,
FLIGHT_LOG_EVENT_AUTOTUNE_CYCLE_START = 10,
Expand Down
27 changes: 27 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>

#include "platform.h"
#include "parser.h"
Expand Down Expand Up @@ -296,6 +297,8 @@ static void identifySlowFields(flightLog_t *log, flightLogFrameDef_t *frameDef)
log->slowFieldIndexes.flightModeFlags = i;
} else if (strcmp(fieldName, "stateFlags") == 0) {
log->slowFieldIndexes.stateFlags = i;
} else if (strcmp(fieldName, "failsafePhase") == 0) {
log->slowFieldIndexes.failsafePhase = i;
}
}
}
Expand Down Expand Up @@ -895,6 +898,25 @@ static void flightlogDecodeFlagsToString(uint32_t flags, int numFlags, const cha
}
}

void flightlogDecodeEnumToString(uint32_t value, unsigned numEnums, const char * const *enumNames, char *dest, unsigned destLen)
{
assert(destLen > 1);

if (value < numEnums) {
const char *name = enumNames[value];

if (strlen(name) < destLen) {
strcpy(dest, name);
} else {
dest[0] = '\0';
}
} else {
// Since we don't have a name for this value, print it as a raw integer instead

snprintf(dest, destLen, "%u", value);
}
}

void flightlogFlightModeToString(uint32_t flightMode, char *dest, int destLen)
{
flightlogDecodeFlagsToString(flightMode, FLIGHT_LOG_FLIGHT_MODE_COUNT, FLIGHT_LOG_FLIGHT_MODE_NAME, dest, destLen);
Expand All @@ -905,6 +927,11 @@ void flightlogFlightStateToString(uint32_t flightState, char *dest, int destLen)
flightlogDecodeFlagsToString(flightState, FLIGHT_LOG_FLIGHT_STATE_COUNT, FLIGHT_LOG_FLIGHT_STATE_NAME, dest, destLen);
}

void flightlogFailsafePhaseToString(uint8_t failsafePhase, char *dest, int destLen)
{
flightlogDecodeEnumToString(failsafePhase, FLIGHT_LOG_FAILSAFE_PHASE_COUNT, FLIGHT_LOG_FAILSAFE_PHASE_NAME, dest, destLen);
}

flightLog_t * flightLogCreate(int fd)
{
const char *logSearchStart;
Expand Down
2 changes: 2 additions & 0 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ typedef struct gpsHFieldIndexes_t {
typedef struct slowFieldIndexes_t {
int flightModeFlags;
int stateFlags;
int failsafePhase;
} slowFieldIndexes_t;

typedef struct mainFieldIndexes_t {
Expand Down Expand Up @@ -171,6 +172,7 @@ double flightlogGyroToRadiansPerSecond(flightLog_t *log, int32_t gyroRaw);
double flightlogAccelerationRawToGs(flightLog_t *log, int32_t accRaw);
void flightlogFlightModeToString(uint32_t flightMode, char *dest, int destLen);
void flightlogFlightStateToString(uint32_t flightState, char *dest, int destLen);
void flightlogFailsafePhaseToString(uint8_t failsafePhase, char *dest, int destLen);

bool flightLogParse(flightLog_t *log, int logIndex, FlightLogMetadataReady onMetadataReady, FlightLogFrameReady onFrameReady, FlightLogEventReady onEvent, bool raw);
void flightLogDestroy(flightLog_t *log);
Expand Down
3 changes: 3 additions & 0 deletions visual-studio/blackbox_decode/blackbox_decode.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\lib\getopt_mb_uni\getopt.c" />
<ClCompile Include="..\..\src\battery.c" />
<ClCompile Include="..\..\src\blackbox_decode.c" />
<ClCompile Include="..\..\src\blackbox_fielddefs.c" />
<ClCompile Include="..\..\src\decoders.c" />
<ClCompile Include="..\..\src\gpxwriter.c" />
<ClCompile Include="..\..\src\imu.c" />
Expand All @@ -65,6 +67,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\lib\getopt_mb_uni\getopt.h" />
<ClInclude Include="..\..\src\battery.h" />
<ClInclude Include="..\..\src\decoders.h" />
<ClInclude Include="..\..\src\gpxwriter.h" />
<ClInclude Include="..\..\src\imu.h" />
Expand Down
9 changes: 9 additions & 0 deletions visual-studio/blackbox_decode/blackbox_decode.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
<ClCompile Include="..\..\src\units.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\battery.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\blackbox_fielddefs.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\parser.h">
Expand Down Expand Up @@ -74,5 +80,8 @@
<ClInclude Include="..\..\src\units.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\battery.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions visual-studio/blackbox_render/blackbox_render.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\lib\getopt_mb_uni\getopt.c" />
<ClCompile Include="..\..\src\blackbox_fielddefs.c" />
<ClCompile Include="..\..\src\blackbox_render.c" />
<ClCompile Include="..\..\src\datapoints.c" />
<ClCompile Include="..\..\src\decoders.c" />
Expand Down
3 changes: 3 additions & 0 deletions visual-studio/blackbox_render/blackbox_render.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,8 @@
<ClCompile Include="..\..\src\stream.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\blackbox_fielddefs.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

0 comments on commit bd6944a

Please sign in to comment.