Post History
Command protocols which use strings are a norm. They use more bytes compared to binary protocols, but they are human readable. If the UART itself isn’t a bottleneck, then command strings are a go...
#2: Post edited
- Command protocols which use strings are a norm. They use more bytes compared to binary protocols, but they are human readable. If the UART itself isn’t a bottleneck, then command strings are a good choice. Some examples of mainstream protocols which send ASCII strings: [NMEA 0183](https://en.wikipedia.org/wiki/NMEA_0183) and [SCPI](https://en.wikipedia.org/wiki/Standard_Commands_for_Programmable_Instruments).
- The data frames either have start and stop markers. or a start marker and length field. There’s always a CRC or checksum field to detect possible data corruption.
- > Right now, I have it set up such that my python script sends two things. First, a string containing the command. Second, the switch number that the command affects.
- It’s better to send the command and the number of the relay in the same packet. You wouldn’t have to figure out how to handle the command if the second packet doesn’t get through.
- You like commands which are English words, rather than opcodes, because that’s more readable in the Python and C code. That’s alright. If someday you need to switch to opcodes, that can be made readable in the code too.
- ```C
- typedef enum {
OPCODE_STATUS = 0x00,- OPCODE_RELAY = 0x01,
- // more opcodes...
- } Opcodes;
- ```
- ```C
- switch (receivedOpcode) {
- case OPCODE_RELAY:
- // do your things
- break;
- // more opcode cases ...
- }
- ```
- Command protocols which use strings are a norm. They use more bytes compared to binary protocols, but they are human readable. If the UART itself isn’t a bottleneck, then command strings are a good choice. Some examples of mainstream protocols which send ASCII strings: [NMEA 0183](https://en.wikipedia.org/wiki/NMEA_0183) and [SCPI](https://en.wikipedia.org/wiki/Standard_Commands_for_Programmable_Instruments).
- The data frames either have start and stop markers. or a start marker and length field. There’s always a CRC or checksum field to detect possible data corruption.
- > Right now, I have it set up such that my python script sends two things. First, a string containing the command. Second, the switch number that the command affects.
- It’s better to send the command and the number of the relay in the same packet. You wouldn’t have to figure out how to handle the command if the second packet doesn’t get through.
- You like commands which are English words, rather than opcodes, because that’s more readable in the Python and C code. That’s alright. If someday you need to switch to opcodes, that can be made readable in the code too.
- ```C
- typedef enum {
- OPCODE_STATUS = 0x00, // Named constants make the numeric opcodes more readable in the source
- OPCODE_RELAY = 0x01,
- // more opcodes...
- } Opcodes;
- ```
- ```C
- switch (receivedOpcode) {
- case OPCODE_RELAY:
- // do your things
- break;
- // more opcode cases ...
- }
- ```
#1: Initial revision
Command protocols which use strings are a norm. They use more bytes compared to binary protocols, but they are human readable. If the UART itself isn’t a bottleneck, then command strings are a good choice. Some examples of mainstream protocols which send ASCII strings: [NMEA 0183](https://en.wikipedia.org/wiki/NMEA_0183) and [SCPI](https://en.wikipedia.org/wiki/Standard_Commands_for_Programmable_Instruments).
The data frames either have start and stop markers. or a start marker and length field. There’s always a CRC or checksum field to detect possible data corruption.
> Right now, I have it set up such that my python script sends two things. First, a string containing the command. Second, the switch number that the command affects.
It’s better to send the command and the number of the relay in the same packet. You wouldn’t have to figure out how to handle the command if the second packet doesn’t get through.
You like commands which are English words, rather than opcodes, because that’s more readable in the Python and C code. That’s alright. If someday you need to switch to opcodes, that can be made readable in the code too.
```C
typedef enum {
OPCODE_STATUS = 0x00,
OPCODE_RELAY = 0x01,
// more opcodes...
} Opcodes;
```
```C
switch (receivedOpcode) {
case OPCODE_RELAY:
// do your things
break;
// more opcode cases ...
}
```
