Skip to content

Commit

Permalink
Make call sign configurable with cli expressions (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
trholdridge authored Apr 24, 2024
1 parent 9d54859 commit 0d0f172
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
14 changes: 13 additions & 1 deletion common/system/tasks/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static CliOptionVals_s cliOptionVals = {
.r = NULL, // ground temperature
.h = false, // help flag
.c = NULL, // Radio channel, can be negative
.s = NULL, // call sign
.lcCmd = NULL, // Line cuttter command
.lcId = NULL // Line cuttter id
};
Expand All @@ -60,6 +61,7 @@ static struct option longOptions[] = {
{0, 0, 0, 0}};

static CliConfigs_s cliConfigs = {0};
static const char* defaultCall = "KC1UAW";

static CliComms_e lastCommsType; // Used to help send ack to right places
static uint8_t lastStringId = 0xFF;
Expand Down Expand Up @@ -102,6 +104,7 @@ void cli_setDefaultConfig() {
cliConfigs.groundElevationM = 0;
cliConfigs.groundTemperatureC = 14.85;
cliConfigs.radioChannel = 1;
snprintf(cliConfigs.callsign, sizeof(cliConfigs.callsign), "%s", defaultCall);
triggerManager_setDefaultConfig();
}

Expand Down Expand Up @@ -192,7 +195,7 @@ CliCommand_e cli_parse(CliComms_e commsType) {
int optionIndex = 0;
optind = 0;
primaryCommand = NONE;
while ((opt = getopt_long(argc, argv, "f:t:m:p:d:w:C:e:r:c:i:DhN",
while ((opt = getopt_long(argc, argv, "f:t:m:p:d:w:C:e:r:c:s:i:DhN",
longOptions, &optionIndex)) != -1) {
switch (opt) {
case 0:
Expand All @@ -210,6 +213,7 @@ CliCommand_e cli_parse(CliComms_e commsType) {
cliOptionVals.r = NULL;
cliOptionVals.h = false;
cliOptionVals.c = NULL;
cliOptionVals.s = NULL;
cliOptionVals.lcCmd = NULL;
cliOptionVals.lcId = NULL;
break;
Expand Down Expand Up @@ -307,6 +311,14 @@ CliCommand_e cli_parse(CliComms_e commsType) {
invalidOptCommand = true;
}
break;
case 's':
// Call sign
if (primaryCommand == CONFIG) {
cliOptionVals.s = optarg;
} else {
invalidOptCommand = true;
}
break;
// Line cutter ID
case 'i':
if (primaryCommand == LINECUTTER) {
Expand Down
2 changes: 2 additions & 0 deletions common/system/tasks/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct {
char* r; // ground temperature
bool h; // help flag
char* c; // Radio channel, can be negative
char* s; // call sign
char* lcCmd; // Line cuttter command
char* lcId; // Line cuttter id
} CliOptionVals_s;
Expand All @@ -66,6 +67,7 @@ typedef struct __attribute__((__packed__)) {
double groundElevationM;
double groundTemperatureC;
int32_t radioChannel;
char callsign[8];
} CliConfigs_s;

/**
Expand Down
16 changes: 15 additions & 1 deletion common/system/tasks/cli/task_cli_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ void CliTasks::config() {
}
}

// Configure call sign
if (options.s) {
if (strlen(options.s) > 7) {
cli_sendAck(false, "Call sign must be seven characters or less");
return;
}
snprintf(cli_getConfigs()->callsign, sizeof(cli_getConfigs()->callsign),
"%s", options.s);
// Write new cli configs to flash
dataLog_writeCliConfigs();
}

// Send positive ACK (all inputs have been appropriately processed)
cli_sendAck(true, nullptr);

Expand Down Expand Up @@ -254,12 +266,14 @@ void CliTasks::config() {
dtoa(val, sizeof(val), cli_getConfigs()->groundElevationM, 3);
generateConfigHelp("Ground Elevation (m):", val);
// Ground temperature

dtoa(val, sizeof(val), cli_getConfigs()->groundTemperatureC, 3);
generateConfigHelp("Ground Temperature (C):", val);
// Radio channel
snprintf(val, sizeof(val), "%" PRIi32, cli_getConfigs()->radioChannel);
generateConfigHelp("Radio Channel:", val);
// Radio call sign
snprintf(val, sizeof(val), "%s", cli_getConfigs()->callsign);
generateConfigHelp("Call sign:", val);
}

// If reached, send complete message to CLI
Expand Down
1 change: 1 addition & 0 deletions common/system/tasks/cli/task_cli_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void CliTasks::help() {
generateDoc("", "-c int*1",
"Configure radio channel (in multiples of bandwidth), negative "
"numbers allowed");
generateDoc("", "-s string*1", "Configure radio call sign");
generateDoc("", "-h", "Help for config. Prints current configuration values");
generateDoc("--create_flight", "",
"Clear state log and move back to preflight");
Expand Down
6 changes: 3 additions & 3 deletions common/system/tasks/radio_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ static DataTransmitState_s lastSent[NUM_RADIO];

static RadioPacket_s transmitPacket[NUM_RADIO];

static const char *call = "KM6GNL";

// https://stackoverflow.com/q/9695329
#define ROUND_2_INT(f) ((int)((f) >= 0.0 ? (f + 0.5) : (f - 0.5)))

Expand All @@ -34,7 +32,8 @@ void radioManager_init() {
sizeof(RadioRecievedPacket_s));
hm_radioRegisterConsumer(i, &dataRx[i].rxBuffer);

strncpy(transmitPacket[i].callsign, call, 8);
snprintf(transmitPacket[i].callsign, sizeof(transmitPacket[i].callsign),
"%s", cli_getConfigs()->callsign);

#ifdef SOFTWARE_VERSION
transmitPacket[i].softwareVersion = SOFTWARE_VERSION; // TODO set this;
Expand Down Expand Up @@ -69,6 +68,7 @@ void radioManager_tick() {
}

void radioManager_sendInternal(int radioId) {
strncpy(transmitPacket[radioId].callsign, cli_getConfigs()->callsign, 8);
hm_radioSend(radioId, (uint8_t *)&transmitPacket[radioId],
sizeof(RadioPacket_s));
}
Expand Down

0 comments on commit 0d0f172

Please sign in to comment.