cmdRx.c 958 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "uart.h"
  2. #include "stdio.h"
  3. #include "main.h"
  4. /*
  5. #define MAX_LEN 100
  6. void handleCmdRx() {
  7. static int mode = -1;
  8. static unsigned char str[MAX_LEN];
  9. static unsigned char *valP;
  10. static int reset = 1;
  11. if( reset == 1 ) {
  12. valP = str;
  13. mode = 0;
  14. reset = 0;
  15. }
  16. while( serialAvailable() ) {
  17. const unsigned char c = serialRead();
  18. if( !(c>='0' && c<='9') &&
  19. !(c>='a' && c<='z') &&
  20. !(c>='A' && c<='Z') &&
  21. c!='\"' && c!=',' && c!='.' && c!='{' && c!='}') {
  22. reset = 1;
  23. }
  24. else {
  25. if( mode == 0 && c=='{' ) {
  26. *(valP)++ = c;
  27. mode = 1;
  28. }
  29. else if( mode == 1 && c=='}' ) {
  30. *(valP)++ = c;
  31. *(valP)++ = '\0';
  32. int val=-1;
  33. const int no = sscanf((const char *)str,"{%d}",&val);
  34. if( no == 1 ) {
  35. HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, (val==1)?GPIO_PIN_RESET:GPIO_PIN_SET);
  36. }
  37. reset=1;
  38. }
  39. else if( mode==1 ){
  40. *(valP)++ = c;
  41. }
  42. }
  43. }
  44. }
  45. */