Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. // cli.h
  2. // version 1.0.0
  3.  
  4. // define callback functions (can be anywhere, not just here)
  5. void some_func(void) { return; }
  6. void some_other_func(void) { return; }
  7.  
  8. // define some actions manually
  9. // undesired, just an example!
  10. CLI_ACTION act1 = { 0x10, &some_func };
  11. CLI_ACTION act2 = { 0x11, &some_func };
  12.  
  13. // initialize UART module and assign to CLI
  14. UART* uart1 = uart.new(2);
  15. cli.uart_module = uart1;
  16.  
  17. // initialize command table (MACRO)
  18. // max 8 types and 8 actions per type (#defined in cli.h)
  19. // undesired types can be omitted
  20. CMD_TABLE
  21. {
  22. { UART_GET, {
  23. { 0x00, &some_func }, // do this
  24. { 0x01, NULL } // n/a
  25. }},
  26.  
  27. { UART_SET, {
  28. { 0x00, NULL }, // n/a
  29. { 0x01, NULL } // n/a
  30. }}
  31. };
  32.  
  33. // update a callback manually
  34. // UART_SET -> 0x01 -> some_other_func()
  35. cli.commands[1].actions[1].callback = &some_other_func;
  36.  
  37. // parse some UART_FRAME
  38. // type is specified by "frame->type" (UART_GET)
  39. // action identifier is specified by "frame->payload[0]" (123)
  40. UART_FRAME frm =
  41. {
  42. UART_GET,
  43. 2,
  44. (uint8_t[2]){123, 40},
  45. 0
  46. };
  47.  
  48. // this will call the matching callback
  49. cli.parse_frame(&frm);
  50.  
  51. // log a message to the PC console (max 256 bytes)
  52. cli.log("Hello world!");
  53.  
  54. // check for and parse UART frame
  55. cli.check();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement