Skip to content

Instantly share code, notes, and snippets.

@reefwing
Created April 17, 2023 08:22
Show Gist options
  • Save reefwing/b0bbdc789ea827c4ddc168ac0009f9df to your computer and use it in GitHub Desktop.
Save reefwing/b0bbdc789ea827c4ddc168ac0009f9df to your computer and use it in GitHub Desktop.
#define BAD_ID -1
typedef struct {
char *key;
int val;
} msp_commands_t;
static msp_commands_t lookupTable[] = {
{ "MSP_API_VERSION", MSP_API_VERSION }, { "MSP_FC_VARIANT", MSP_FC_VARIANT }, { "MSP_FC_VERSION", MSP_FC_VERSION }, { "MSP_BOARD_INFO", MSP_BOARD_INFO },
{ "MSP_BUILD_INFO", MSP_BUILD_INFO }, { "MSP_NAME", MSP_NAME }, { "MSP_SET_NAME", MSP_SET_NAME }, { "MSP_IDENT", MSP_IDENT }, { "MSP_STATUS", MSP_STATUS },
{ "MSP_RAW_IMU", MSP_RAW_IMU }, { "MSP_SERVO", MSP_SERVO }, { "MSP_MOTOR", MSP_MOTOR}, { "MSP_RC", MSP_RC }, { "MSP_ATTITUDE", MSP_ATTITUDE }, { "MSP_ALTITUDE", MSP_ALTITUDE },
{ "MSP_PID", MSP_PID }, { "MSP_BOX", MSP_BOX }, { "MSP_BOXNAMES", MSP_BOXNAMES }, { "MSP_PIDNAMES", MSP_PIDNAMES }, { "MSP_BOXIDS", MSP_BOXIDS },
{ "MSP_SET_RAW_RC", MSP_SET_RAW_RC }, { "MSP_SET_RAW_GPS", MSP_SET_RAW_GPS }, { "MSP_SET_PID", MSP_SET_PID }, { "MSP_SET_BOX", MSP_SET_BOX },
{ "MSP_SET_RC_TUNING", MSP_SET_RC_TUNING }, { "MSP_ACC_CALIBRATION", MSP_ACC_CALIBRATION }, { "MSP_MAG_CALIBRATION", MSP_MAG_CALIBRATION }, { "MSP_SET_MISC", MSP_SET_MISC },
{ "MSP_RESET_CONF", MSP_RESET_CONF }, { "MSP_SET_WP", MSP_SET_WP }, { "MSP_SELECT_SETTING", MSP_SELECT_SETTING }, { "MSP_SET_HEAD", MSP_SET_HEAD }
};
#define NKEYS (sizeof(lookupTable)/sizeof(msp_commands_t))
int idLookup(char *key) {
for (int i = 0; i < NKEYS; i++) {
msp_commands_t sym = lookupTable[i];
if (!strcmp(sym.key, key))
return sym.val;
}
return BAD_ID;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment