Skip to content

Commit

Permalink
Use 10 bits for switches to prevent overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic committed Dec 21, 2022
1 parent 6e6be76 commit 14fd8f2
Show file tree
Hide file tree
Showing 21 changed files with 174 additions and 231 deletions.
2 changes: 0 additions & 2 deletions radio/src/dataconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,7 @@ enum Functions {
FUNC_PLAY_SOUND = FUNC_FIRST_WITHOUT_ENABLE,
FUNC_PLAY_TRACK,
FUNC_PLAY_VALUE,
FUNC_RESERVE4,
FUNC_PLAY_SCRIPT,
FUNC_RESERVE5,
FUNC_BACKGND_MUSIC,
FUNC_BACKGND_MUSIC_PAUSE,
FUNC_VARIO,
Expand Down
20 changes: 10 additions & 10 deletions radio/src/datastructs_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ PACK(struct MixData {
uint16_t mixWarn:2; // mixer warning
uint16_t mltpx:2 ENUM(MixerMultiplex);
uint16_t spare:1 SKIP;
int32_t offset:14 CUST(in_read_weight,in_write_weight);
int32_t swtch:9 CUST(r_swtchSrc,w_swtchSrc);
int32_t offset:13 CUST(in_read_weight,in_write_weight);
int32_t swtch:10 CUST(r_swtchSrc,w_swtchSrc);
uint32_t flightModes:9 CUST(r_flightModes, w_flightModes);
CurveRef curve;
uint8_t delayUp;
Expand All @@ -98,10 +98,9 @@ PACK(struct ExpoData {
uint16_t srcRaw:10 ENUM(MixSources) CUST(r_mixSrcRaw,w_mixSrcRaw);
int16_t carryTrim:6;
uint32_t chn:5;
int32_t swtch:9 CUST(r_swtchSrc,w_swtchSrc);
int32_t swtch:10 CUST(r_swtchSrc,w_swtchSrc);
uint32_t flightModes:9 CUST(r_flightModes, w_flightModes);
int32_t weight:8 CUST(in_read_weight,in_write_weight);
int32_t spare:1 SKIP;
NOBACKUP(char name[LEN_EXPOMIX_NAME]);
int8_t offset CUST(in_read_weight,in_write_weight);
CurveRef curve;
Expand Down Expand Up @@ -132,9 +131,9 @@ PACK(struct LogicalSwitchData {
CUST_ATTR(def,r_logicSw,w_logicSw);
int32_t v1:10 SKIP;
int32_t v3:10 SKIP;
int32_t andsw:9 CUST(r_swtchSrc,w_swtchSrc); // TODO rename to xswtch
int32_t andsw:10 CUST(r_swtchSrc,w_swtchSrc); // TODO rename to xswtch
uint32_t andswtype:1 SKIP; // TODO rename to xswtchType (AND / OR)
uint32_t spare:2 SKIP; // anything else needed?
uint32_t spare:1 SKIP; // anything else needed?
int16_t v2 SKIP;
uint8_t delay;
uint8_t duration;
Expand All @@ -152,8 +151,8 @@ PACK(struct LogicalSwitchData {
#endif

PACK(struct CustomFunctionData {
int16_t swtch:9 CUST(r_swtchSrc,w_swtchSrc);
uint16_t func:7 ENUM(Functions);
int16_t swtch:10 CUST(r_swtchSrc,w_swtchSrc);
uint16_t func:6 ENUM(Functions); // TODO: 6 bits for Functions?
CUST_ATTR(def,r_customFn,w_customFn);
PACK(union {
NOBACKUP(PACK(struct {
Expand Down Expand Up @@ -192,8 +191,9 @@ PACK(struct trim_t {
PACK(struct FlightModeData {
trim_t trim[NUM_TRIMS];
NOBACKUP(char name[LEN_FLIGHT_MODE_NAME]);
int16_t swtch:9 ENUM(SwitchSources) CUST(r_swtchSrc,w_swtchSrc); // swtch of phase[0] is not used
int16_t spare:7 SKIP;
// swtch of phase[0] is not used
int16_t swtch:10 ENUM(SwitchSources) CUST(r_swtchSrc,w_swtchSrc);
int16_t spare:6 SKIP;
uint8_t fadeIn;
uint8_t fadeOut;
gvar_t gvars[MAX_GVARS] FUNC(gvar_is_active);
Expand Down
5 changes: 2 additions & 3 deletions radio/src/gui/gui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,17 +520,16 @@ bool isAssignableFunctionAvailable(int function, CustomFunctionData * functions)
return false;
#endif
#if !defined(HAPTIC)
case FUNC_HAPTIC:
case FUNC_HAPTIC:
#endif
case FUNC_RESERVE4:
#if !defined(DANGEROUS_MODULE_FUNCTIONS)
case FUNC_RANGECHECK:
case FUNC_BIND:
#endif
#if !defined(LUA)
case FUNC_PLAY_SCRIPT:
#endif
case FUNC_RESERVE5:
case FUNC_MAX:
return false;

default:
Expand Down
21 changes: 9 additions & 12 deletions radio/src/storage/yaml/yaml_datastructs_lr3pro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ const struct YamlIdStr enum_Functions[] = {
{ FUNC_PLAY_SOUND, "PLAY_SOUND" },
{ FUNC_PLAY_TRACK, "PLAY_TRACK" },
{ FUNC_PLAY_VALUE, "PLAY_VALUE" },
{ FUNC_RESERVE4, "RESERVE4" },
{ FUNC_PLAY_SCRIPT, "PLAY_SCRIPT" },
{ FUNC_RESERVE5, "RESERVE5" },
{ FUNC_BACKGND_MUSIC, "BACKGND_MUSIC" },
{ FUNC_BACKGND_MUSIC_PAUSE, "BACKGND_MUSIC_PAUSE" },
{ FUNC_VARIO, "VARIO" },
Expand Down Expand Up @@ -277,8 +275,8 @@ static const struct YamlNode union_anonymous_0_elmts[] = {
};
static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 6, enum_Functions),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
Expand Down Expand Up @@ -408,8 +406,8 @@ static const struct YamlNode struct_MixData[] = {
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
YAML_PADDING( 1 ),
YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_SIGNED_CUST( "offset", 13, in_read_weight, in_write_weight ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
YAML_UNSIGNED( "delayUp", 8 ),
Expand Down Expand Up @@ -438,10 +436,9 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED( "carryTrim", 6 ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ),
YAML_PADDING( 1 ),
YAML_STRING("name", 6),
YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
Expand All @@ -466,9 +463,9 @@ static const struct YamlNode struct_LogicalSwitchData[] = {
YAML_CUSTOM("def",r_logicSw,w_logicSw),
YAML_PADDING( 10 ),
YAML_PADDING( 10 ),
YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ),
YAML_SIGNED_CUST( "andsw", 10, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 1 ),
YAML_PADDING( 1 ),
YAML_PADDING( 2 ),
YAML_PADDING( 16 ),
YAML_UNSIGNED( "delay", 8 ),
YAML_UNSIGNED( "duration", 8 ),
Expand All @@ -495,8 +492,8 @@ static const struct YamlNode struct_FlightModeData[] = {
YAML_IDX,
YAML_ARRAY("trim", 16, 4, struct_trim_t, NULL),
YAML_STRING("name", 6),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 7 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 6 ),
YAML_UNSIGNED( "fadeIn", 8 ),
YAML_UNSIGNED( "fadeOut", 8 ),
YAML_ARRAY("gvars", 16, 9, struct_signed_16, gvar_is_active),
Expand Down
21 changes: 9 additions & 12 deletions radio/src/storage/yaml/yaml_datastructs_nv14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ const struct YamlIdStr enum_Functions[] = {
{ FUNC_PLAY_SOUND, "PLAY_SOUND" },
{ FUNC_PLAY_TRACK, "PLAY_TRACK" },
{ FUNC_PLAY_VALUE, "PLAY_VALUE" },
{ FUNC_RESERVE4, "RESERVE4" },
{ FUNC_PLAY_SCRIPT, "PLAY_SCRIPT" },
{ FUNC_RESERVE5, "RESERVE5" },
{ FUNC_BACKGND_MUSIC, "BACKGND_MUSIC" },
{ FUNC_BACKGND_MUSIC_PAUSE, "BACKGND_MUSIC_PAUSE" },
{ FUNC_VARIO, "VARIO" },
Expand Down Expand Up @@ -288,8 +286,8 @@ static const struct YamlNode union_anonymous_0_elmts[] = {
};
static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 6, enum_Functions),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 48 ),
YAML_PADDING( 8 ),
Expand Down Expand Up @@ -443,8 +441,8 @@ static const struct YamlNode struct_MixData[] = {
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
YAML_PADDING( 1 ),
YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_SIGNED_CUST( "offset", 13, in_read_weight, in_write_weight ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
YAML_UNSIGNED( "delayUp", 8 ),
Expand Down Expand Up @@ -473,10 +471,9 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED( "carryTrim", 6 ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ),
YAML_PADDING( 1 ),
YAML_STRING("name", 6),
YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
Expand All @@ -501,9 +498,9 @@ static const struct YamlNode struct_LogicalSwitchData[] = {
YAML_CUSTOM("def",r_logicSw,w_logicSw),
YAML_PADDING( 10 ),
YAML_PADDING( 10 ),
YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ),
YAML_SIGNED_CUST( "andsw", 10, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 1 ),
YAML_PADDING( 1 ),
YAML_PADDING( 2 ),
YAML_PADDING( 16 ),
YAML_UNSIGNED( "delay", 8 ),
YAML_UNSIGNED( "duration", 8 ),
Expand All @@ -530,8 +527,8 @@ static const struct YamlNode struct_FlightModeData[] = {
YAML_IDX,
YAML_ARRAY("trim", 16, 4, struct_trim_t, NULL),
YAML_STRING("name", 10),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 7 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 6 ),
YAML_UNSIGNED( "fadeIn", 8 ),
YAML_UNSIGNED( "fadeOut", 8 ),
YAML_ARRAY("gvars", 16, 9, struct_signed_16, gvar_is_active),
Expand Down
21 changes: 9 additions & 12 deletions radio/src/storage/yaml/yaml_datastructs_t12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ const struct YamlIdStr enum_Functions[] = {
{ FUNC_PLAY_SOUND, "PLAY_SOUND" },
{ FUNC_PLAY_TRACK, "PLAY_TRACK" },
{ FUNC_PLAY_VALUE, "PLAY_VALUE" },
{ FUNC_RESERVE4, "RESERVE4" },
{ FUNC_PLAY_SCRIPT, "PLAY_SCRIPT" },
{ FUNC_RESERVE5, "RESERVE5" },
{ FUNC_BACKGND_MUSIC, "BACKGND_MUSIC" },
{ FUNC_BACKGND_MUSIC_PAUSE, "BACKGND_MUSIC_PAUSE" },
{ FUNC_VARIO, "VARIO" },
Expand Down Expand Up @@ -277,8 +275,8 @@ static const struct YamlNode union_anonymous_0_elmts[] = {
};
static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 6, enum_Functions),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
Expand Down Expand Up @@ -408,8 +406,8 @@ static const struct YamlNode struct_MixData[] = {
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
YAML_PADDING( 1 ),
YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_SIGNED_CUST( "offset", 13, in_read_weight, in_write_weight ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
YAML_UNSIGNED( "delayUp", 8 ),
Expand Down Expand Up @@ -438,10 +436,9 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED( "carryTrim", 6 ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ),
YAML_PADDING( 1 ),
YAML_STRING("name", 6),
YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
Expand All @@ -466,9 +463,9 @@ static const struct YamlNode struct_LogicalSwitchData[] = {
YAML_CUSTOM("def",r_logicSw,w_logicSw),
YAML_PADDING( 10 ),
YAML_PADDING( 10 ),
YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ),
YAML_SIGNED_CUST( "andsw", 10, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 1 ),
YAML_PADDING( 1 ),
YAML_PADDING( 2 ),
YAML_PADDING( 16 ),
YAML_UNSIGNED( "delay", 8 ),
YAML_UNSIGNED( "duration", 8 ),
Expand All @@ -495,8 +492,8 @@ static const struct YamlNode struct_FlightModeData[] = {
YAML_IDX,
YAML_ARRAY("trim", 16, 4, struct_trim_t, NULL),
YAML_STRING("name", 6),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 7 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 6 ),
YAML_UNSIGNED( "fadeIn", 8 ),
YAML_UNSIGNED( "fadeOut", 8 ),
YAML_ARRAY("gvars", 16, 9, struct_signed_16, gvar_is_active),
Expand Down
21 changes: 9 additions & 12 deletions radio/src/storage/yaml/yaml_datastructs_t8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ const struct YamlIdStr enum_Functions[] = {
{ FUNC_PLAY_SOUND, "PLAY_SOUND" },
{ FUNC_PLAY_TRACK, "PLAY_TRACK" },
{ FUNC_PLAY_VALUE, "PLAY_VALUE" },
{ FUNC_RESERVE4, "RESERVE4" },
{ FUNC_PLAY_SCRIPT, "PLAY_SCRIPT" },
{ FUNC_RESERVE5, "RESERVE5" },
{ FUNC_BACKGND_MUSIC, "BACKGND_MUSIC" },
{ FUNC_BACKGND_MUSIC_PAUSE, "BACKGND_MUSIC_PAUSE" },
{ FUNC_VARIO, "VARIO" },
Expand Down Expand Up @@ -277,8 +275,8 @@ static const struct YamlNode union_anonymous_0_elmts[] = {
};
static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 6, enum_Functions),
YAML_CUSTOM("def",r_customFn,w_customFn),
YAML_PADDING( 64 ),
YAML_PADDING( 8 ),
Expand Down Expand Up @@ -408,8 +406,8 @@ static const struct YamlNode struct_MixData[] = {
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_ENUM("mltpx", 2, enum_MixerMultiplex),
YAML_PADDING( 1 ),
YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_SIGNED_CUST( "offset", 13, in_read_weight, in_write_weight ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
YAML_UNSIGNED( "delayUp", 8 ),
Expand Down Expand Up @@ -438,10 +436,9 @@ static const struct YamlNode struct_ExpoData[] = {
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_SIGNED( "carryTrim", 6 ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ),
YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ),
YAML_PADDING( 1 ),
YAML_STRING("name", 6),
YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
Expand All @@ -466,9 +463,9 @@ static const struct YamlNode struct_LogicalSwitchData[] = {
YAML_CUSTOM("def",r_logicSw,w_logicSw),
YAML_PADDING( 10 ),
YAML_PADDING( 10 ),
YAML_SIGNED_CUST( "andsw", 9, r_swtchSrc, w_swtchSrc ),
YAML_SIGNED_CUST( "andsw", 10, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 1 ),
YAML_PADDING( 1 ),
YAML_PADDING( 2 ),
YAML_PADDING( 16 ),
YAML_UNSIGNED( "delay", 8 ),
YAML_UNSIGNED( "duration", 8 ),
Expand All @@ -495,8 +492,8 @@ static const struct YamlNode struct_FlightModeData[] = {
YAML_IDX,
YAML_ARRAY("trim", 16, 4, struct_trim_t, NULL),
YAML_STRING("name", 6),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 7 ),
YAML_SIGNED_CUST( "swtch", 10, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 6 ),
YAML_UNSIGNED( "fadeIn", 8 ),
YAML_UNSIGNED( "fadeOut", 8 ),
YAML_ARRAY("gvars", 16, 9, struct_signed_16, gvar_is_active),
Expand Down
Loading

0 comments on commit 14fd8f2

Please sign in to comment.