stateMachine.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // Created by macheng on 2018/5/2.
  3. //
  4. #ifndef STATEMACHINE_H
  5. #define STATEMACHINE_H
  6. #include "message.h"
  7. #include "config.h"
  8. ////
  9. #define INST_DONE_WAIT_FOR_NEXT_EVENT 1 //this signifies that the current event has been processed and instance is ready for next one
  10. #define INST_DONE_WAIT_FOR_NEXT_EVENT_TO 2 //this signifies that the current event has been processed and that instance is waiting for next one with a timeout
  11. //which will trigger if no event coming in specified time
  12. #define INST_NOT_DONE_YET 0 //this signifies that the instance is still processing the current event
  13. //Listener = in this mode, the instance only receives frames, does not respond
  14. //Tag = Exchanges DecaRanging messages (Poll-Response-Final) with Anchor and enabling Anchor to calculate the range between the two instances
  15. //Anchor = see above
  16. //Anchor_Rng = the anchor (assumes a tag function) and ranges to another anchor - used in Anchor to Anchor TWR for auto positioning function
  17. typedef enum instanceModes{
  18. LISTENER=0x00000000,
  19. TAG=0x00000001,
  20. ANCHOR,
  21. ANCHOR_RNG,
  22. NUM_MODES
  23. } INST_MODE;
  24. typedef enum inst_states
  25. {
  26. TA_INIT = 0, //0
  27. TA_TXRESPONSE_WAIT_SEND, //4 - a place holder - response is sent from call back
  28. TA_TX_WAIT_CONF, //5 - confirmation of TX done message
  29. TA_RXE_WAIT, //6
  30. TA_RX_WAIT_DATA, //7
  31. TA_TXRESPONSE_SENT_POLLRX, //9
  32. TA_TXRESPONSE_SENT_RESPRX, //10
  33. TA_TXRESPONSE_SENT_TORX //11
  34. } INST_STATES;
  35. typedef struct _anc_resp_record_{
  36. uint16_t address;
  37. uint16_t rangNum;
  38. uint32_t tof;
  39. uint32_t tickTime;
  40. }stAncRespRecord;
  41. typedef struct _anc_resp_time_{
  42. uint16_t address;
  43. uint8_t ancRespRxTime[TIMESTAME_LENGTH];
  44. }stAncRespTime;
  45. typedef struct _tag_final_record_{
  46. uint16_t tagAddress;
  47. uint8_t rangNum;
  48. uint8_t tagPollTxTime[TIMESTAME_LENGTH];
  49. stAncRespTime ancRespTimes[MAX_ANCHOR_LIST_SIZE];
  50. uint8_t tagFinalTxTime[TIMESTAME_LENGTH];
  51. }stTagFinalRecord;
  52. typedef struct {
  53. INST_MODE mode; //instance mode (anchor)
  54. INST_STATES testAppState ; //state machine - current state
  55. INST_STATES nextState ; //state machine - next state
  56. INST_STATES previousState ; //state machine - previous state
  57. int done ; //done with the current event/wait for next event to arrive
  58. int8_t responseTO ;
  59. //uint8_t isAncResp ;
  60. uint8_t wait4ack ; // if this is set to DWT_RESPONSE_EXPECTED, then the receiver will turn on automatically after TX completion
  61. uint8_t gotTO; // got timeout event appState_TA_TX_WAIT_CONF
  62. int newRange; //flag set when there is a new range to report TOF_REPORT_A2A or TOF_REPORT_T2A
  63. int newRangeAncAddress; //last 4 bytes of anchor address - used for printing/range output display
  64. int newRangeTagAddress; //last 4 bytes of tag address - used for printing/range output display
  65. uint32_t newRangeTime;
  66. }state_machine;
  67. #endif //STATEMACHINE_H