A common problem with IoT hardware is to setup configuration parameters for correct operation. For example, we may want to set the sampling loops, network transmission interval, APN for 4G and the device serial number for each PCB. The configuration parameters need to be set on demand and operators need a quick and easy way to change the device configuration from outside without changing the hex file.
To support configuration changes on demand, we need support in the hex file to receive commands on a communication port and set command values in the EEPROM for long term usage. The commands can vary across the PCB and the use cases. For example, a router PCB may need to setup the network transmission interval whereas a node PCB needs to set and store the gateway address. To support multiple commands and do future proofing, Yuktix provides the serial command processor (scp) library that can be integrated with the application hex files. The application hex writer needs to focus only on the commands he or she needs to integrate in the hex file. Few commands are provided by the scp lib itself, like the serial command. Rest of the commands can be written according to the scp lib convention to provide seamless command support.
With scp lib, you can send commands on a standard serial line and no new software is required. You can send commands from a Linux, PC or mac OSX. The only hardware you need is a serial cable. Further, if a BLE serial line is available then you can send commands from a phone as well. The PCB would publish the list of supported commands an operator can use to tweak the configuration.
The serial command processor (scp) library expects commands in a certain format. All commands begin with a dot and continue till the first space is found. Anything after the first space and upto the end of the line is treated as argument to that command.
// The commands are located at run time
// using a lookup table
struct scp_command_lookup {
const char *name ;
void *command;
void (*handler) (void *command, char*buffer, uint8_t offset);
};
// The commands used by a user program
// should be registered. An application program
// only needs to register what it uses.
static struct scp_modem_command modem_command;
const static struct scp_command_lookup table[NUM_COMMANDS] = {
{"modem", &modem_command, scp_run_modem},
...
};
// we need to implement or link the command handler
// The scp lib will automatically pass the command
// struct and the serial buffer to the registered handler.
// The use of void* is to handle generic data structures.
// The access to serial line is via SCP_PRINT macros.
void scp_run_modem(void *p_command, char *buffer, uint8_t offset) {
char ch;
struct scp_modem_command *command = p_command;
volatile unsigned long start_time = millis();
...
...
if(offset == 0) {
SCP_PRINT("no command received...\r\n");
return;
}
...
...
if(uart_available(command->modem_port)) {
ch = uart_getc(command->modem_port);
...
}
// a command shell is needed to trigger the
// command processing based on the state of
// mode GPIO. We need to put mode GPIO
// in a known state to enter command mode.
static struct scp_shell command_shell;
command_shell.io_pin_register = &MODE_PIN_REGISTER;
command_shell.io_ddr_register = &MODE_DDR;
command_shell.io_signal_pin = MODE_PIN;
command_shell.io_signal_value = 0;
...
...
scp_monitor(&command_shell);
// default is to print information
shell $ .serial
hosac001
shell $ .modem AT+CSQ
+CSQ: 25,99
OK
You can implement any command and register it with an application program. The scp lib provides access to a serial line, the command shell buffer and a command struct holding useful data. The PCB runs in logger mode by default. You need to change the mode JMP settings to enter the programming mode. The mode JMP (open or short) setting should match the one set on command_shell.io_signal_value field.
Red | |
Vcc | NC | Do not connect |
Orange | |
Tx | MCU Rx | |
Yellow | |
Rx | MCU Tx | |
Black | |
GND |
A serial terminal software is required to enter commands in the programming mode. You can use any serial terminal software. We recommend using the Termite software. To view information on Termite setup, check out the Yuktic PCB debugging page.