| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- //
- // Created by macheng on 2018/5/2.
- //
- #ifndef STATEMACHINE_H
- #define STATEMACHINE_H
- #include "message.h"
- #include "config.h"
- ////
- #define INST_DONE_WAIT_FOR_NEXT_EVENT 1 //this signifies that the current event has been processed and instance is ready for next one
- #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
- //which will trigger if no event coming in specified time
- #define INST_NOT_DONE_YET 0 //this signifies that the instance is still processing the current event
- //Listener = in this mode, the instance only receives frames, does not respond
- //Tag = Exchanges DecaRanging messages (Poll-Response-Final) with Anchor and enabling Anchor to calculate the range between the two instances
- //Anchor = see above
- //Anchor_Rng = the anchor (assumes a tag function) and ranges to another anchor - used in Anchor to Anchor TWR for auto positioning function
- typedef enum instanceModes{
- LISTENER=0x00000000,
- TAG=0x00000001,
- ANCHOR,
- ANCHOR_RNG,
- NUM_MODES
- } INST_MODE;
- typedef enum inst_states
- {
- TA_INIT = 0, //0
- TA_TXRESPONSE_WAIT_SEND, //4 - a place holder - response is sent from call back
- TA_TX_WAIT_CONF, //5 - confirmation of TX done message
- TA_RXE_WAIT, //6
- TA_RX_WAIT_DATA, //7
- TA_TXRESPONSE_SENT_POLLRX, //9
- TA_TXRESPONSE_SENT_RESPRX, //10
- TA_TXRESPONSE_SENT_TORX //11
- } INST_STATES;
- typedef struct _anc_resp_record_{
- uint16_t address;
- uint16_t rangNum;
- uint32_t tof;
- uint32_t tickTime;
- }stAncRespRecord;
- typedef struct _anc_resp_time_{
- uint16_t address;
- uint8_t ancRespRxTime[TIMESTAME_LENGTH];
- }stAncRespTime;
- typedef struct _tag_final_record_{
- uint16_t tagAddress;
- uint8_t rangNum;
- uint8_t tagPollTxTime[TIMESTAME_LENGTH];
- stAncRespTime ancRespTimes[MAX_ANCHOR_LIST_SIZE];
- uint8_t tagFinalTxTime[TIMESTAME_LENGTH];
- }stTagFinalRecord;
- typedef struct {
- INST_MODE mode; //instance mode (anchor)
- INST_STATES testAppState ; //state machine - current state
- INST_STATES nextState ; //state machine - next state
- INST_STATES previousState ; //state machine - previous state
- int done ; //done with the current event/wait for next event to arrive
- int8_t responseTO ;
- //uint8_t isAncResp ;
- uint8_t wait4ack ; // if this is set to DWT_RESPONSE_EXPECTED, then the receiver will turn on automatically after TX completion
- uint8_t gotTO; // got timeout event appState_TA_TX_WAIT_CONF
- int newRange; //flag set when there is a new range to report TOF_REPORT_A2A or TOF_REPORT_T2A
- int newRangeAncAddress; //last 4 bytes of anchor address - used for printing/range output display
- int newRangeTagAddress; //last 4 bytes of tag address - used for printing/range output display
- uint32_t newRangeTime;
- }state_machine;
- #endif //STATEMACHINE_H
|