Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define a compact representation of the command system #15

Closed
liquiddandruff opened this issue Jun 9, 2017 · 1 comment
Closed

Define a compact representation of the command system #15

liquiddandruff opened this issue Jun 9, 2017 · 1 comment
Labels

Comments

@liquiddandruff
Copy link
Member

Currently the commands implementation parses a string to determine what commands to run. For example, passing the string task suspend radio into checkAndRunCommand(char *cmd) will call the "task" command with arguments "suspend" and "radio", which will be further interpreted within the task function as encountering a sub-command "suspend" with argument "radio".

This was fine when the commands were only called through UART (serial), but since we plan to schedule commands to be run in the future, keeping command strings such as task suspend radio in memory for extended periods is inefficient. Having a more compact representation will also help the radio link budget.

Notes:

  • Decide between...
    • spreading out a command into separate arrays (eg, CMD_NAMES, CMD_FUNCS) such that an index X references the components of command Y (like in our current implementation)
      • seems like the better option, since we can index with X which is faster than scanning an array of structs as below
    • or defining a struct with members that self-contains a single command, and construct an array of instances of such structs to contain our commands
  • A command can look like this...
    • 4 bits for the command
    • 4 bits for subcommand
    • 10 bytes for arguments?
    • facility for way to express large arguments? for ex, in cases of uploading new config registers, etc
liquiddandruff added a commit that referenced this issue Jun 10, 2017
…proceed

- Moved macros from sfu_cmds.c into header to allow the CMD_IDS enum to be declared in sfu_cmds.h
@liquiddandruff
Copy link
Member Author

liquiddandruff commented Jul 5, 2017

Done now.

Radio uplink/other areas of the system can now initialize a struct to represent a command instead of a string. String commands from UART are now also parsed into the corresponding compact command representation, with cmd_id and subcmd_id specified using natural words, and cmd_data as hex strings.

For example, the following representation is 12 bytes (with 10 bytes unused)

	CMD_t cmd = {
			.cmd_id = CMD_TASK,
			.subcmd_id = CMD_TASK_SUSPEND,
			.cmd_task_data = {
					.task_id = TASK_BLINKY
			}
	};

and is equivalent and formed from > task suspend 40, where 40 is a hexadecimal string literal parsed and type-punned via union into cmd_task_data. 40 is the first byte in cmd_task_data, of which the first nibble is task_id. task_id then has a value of 4, which is the int value of enum TASK_BLINKY. Subsequent data fields in arbitrary commands can then be populated in this way.

liquiddandruff added a commit that referenced this issue Jun 10, 2018
Setup:
- OBC/RF board set 1 compiled with STX strobe in rfTxTestSequence().
- OBC/RF board set 2 compiled with SRX strobe in rfTxTestSequence().
- In UART prompt, enter on both sets: > task resume 10
- Set 1 sample output:
...
radio task (0x0)
S 0x3d
 < 0x0f
tx_underflowed:no tx_numbytes:0
S 0x3d
 < 0x0f
TX FIFO_BYTES_AVAILABLE: 0xf
S 0xbd
 < 0x00
RX FIFO_BYTES_AVAILABLE: 0x0
S 0x3d
 < 0x0f
62 Bytes Radio TX FIFO written
AFTER: tx_underflowed:no tx_numbytes:62
S 0x35
 < 0x02
STX strobed...
S 0x3d
 < 0x24
StatusByte: 0x24
radio task (0x0)
S 0x3d
 < 0x0f
tx_underflowed:no tx_numbytes:0
S 0x3d
 < 0x0f
TX FIFO_BYTES_AVAILABLE: 0xf
S 0xbd
 < 0x00
RX FIFO_BYTES_AVAILABLE: 0x0
S 0x3d
 < 0x0f
62 Bytes Radio TX FIFO written
AFTER: tx_underflowed:no tx_numbytes:62
S 0x35
 < 0x02
STX strobed...
S 0x3d
 < 0x24
StatusByte: 0x24
radio task (0x0)
S 0x3d
 < 0x0f
tx_underflowed:no tx_numbytes:0
S 0x3d
 < 0x0f
TX FIFO_BYTES_AVAILABLE: 0xf
S 0xbd
 < 0x00
RX FIFO_BYTES_AVAILABLE: 0x0
S 0x3d
 < 0x0f
62 Bytes Radio TX FIFO written
AFTER: tx_underflowed:no tx_numbytes:62
S 0x35
 < 0x02
STX strobed...
S 0x3d
 < 0x24
StatusByte: 0x24

- Set 2 sample output:
...
radio task (0x0)
S 0x3d
< 0x02
tx_underflowed:no tx_numbytes:62
S 0x3d
< 0x02
TX FIFO_BYTES_AVAILABLE: 0x2
S 0xbd
< 0x0f
RX FIFO_BYTES_AVAILABLE: 0xf
S 0x3d
< 0x02
Radio did not write
AFTER: tx_underflowed:no tx_numbytes:62
S 0x34
< 0x02
STX strobed...
S 0x3d
< 0x12
StatusByte: 0x12
RX Byte #0: 3e
RX Byte #1: 10
RX Byte #2: 02
RX Byte #3: 03
RX Byte #4: 04
RX Byte #5: 05
RX Byte #6: 06
RX Byte #7: 07
RX Byte #8: 08
RX Byte #9: 09
RX Byte #10: 0a
RX Byte #11: 0b
RX Byte #12: 0c
RX Byte #13: 0d
RX Byte #14: 0e
RX Byte #15: 0f
RX Byte #16: 10
RX Byte #17: 11
RX Byte #18: 12
RX Byte #19: 13
RX Byte #20: 14
RX Byte #21: 15
RX Byte #22: 16
RX Byte #23: 17
RX Byte #24: 18
RX Byte #25: 19
RX Byte #26: 1a
RX Byte #27: 1b
RX Byte #28: 1c
RX Byte #29: 1d
RX Byte #30: 1e
RX Byte #31: 1f
RX Byte #32: 20
RX Byte #33: 21
RX Byte #34: 22
RX Byte #35: 23
RX Byte #36: 24
RX Byte #37: 25
RX Byte #38: 26
RX Byte #39: 27
RX Byte #40: 28
RX Byte #41: 29
RX Byte #42: 2a
RX Byte #43: 2b
RX Byte #44: 2c
RX Byte #45: 2d
RX Byte #46: 2e
RX Byte #47: 2f
RX Byte #48: 30
RX Byte #49: 31
RX Byte #50: 32
RX Byte #51: 33
RX Byte #52: 34
RX Byte #53: 35
RX Byte #54: 36
RX Byte #55: 37
RX Byte #56: 38
RX Byte #57: 39
RX Byte #58: 3a
RX Byte #59: 3b
RX Byte #60: 3c
RX Byte #61: 3d
RX Byte #62: e8
RX Byte #63: ba

Misc:
- Fix calculation of fifo bytes in writeToTxFIFO.
- TODO: readFromRxFIFO changed to always queuering FIFO_RX; change to check only when needed.
- Create IS_STATE macro to check state easily.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant