![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
SmartMesh QSL for STM32F4 version
Fork of COG-AD4050_QSL by
sm_qsl/dn_fsm.h@0:8ca1e814a851, 2018-05-02 (annotated)
- Committer:
- APS_Lab
- Date:
- Wed May 02 09:26:10 2018 +0000
- Revision:
- 0:8ca1e814a851
version1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
APS_Lab | 0:8ca1e814a851 | 1 | /* |
APS_Lab | 0:8ca1e814a851 | 2 | Copyright (c) 2016, Dust Networks. All rights reserved. |
APS_Lab | 0:8ca1e814a851 | 3 | |
APS_Lab | 0:8ca1e814a851 | 4 | Finite State Machine for the QuickStart Library. |
APS_Lab | 0:8ca1e814a851 | 5 | |
APS_Lab | 0:8ca1e814a851 | 6 | \license See attached DN_LICENSE.txt. |
APS_Lab | 0:8ca1e814a851 | 7 | */ |
APS_Lab | 0:8ca1e814a851 | 8 | |
APS_Lab | 0:8ca1e814a851 | 9 | #ifndef DN_FSM_H |
APS_Lab | 0:8ca1e814a851 | 10 | #define DN_FSM_H |
APS_Lab | 0:8ca1e814a851 | 11 | |
APS_Lab | 0:8ca1e814a851 | 12 | #include "dn_common.h" |
APS_Lab | 0:8ca1e814a851 | 13 | #include "dn_defaults.h" |
APS_Lab | 0:8ca1e814a851 | 14 | |
APS_Lab | 0:8ca1e814a851 | 15 | //=========================== defines ========================================= |
APS_Lab | 0:8ca1e814a851 | 16 | |
APS_Lab | 0:8ca1e814a851 | 17 | //===== FSM states |
APS_Lab | 0:8ca1e814a851 | 18 | #define DN_FSM_STATE_NOT_INITIALIZED 0x00 |
APS_Lab | 0:8ca1e814a851 | 19 | #define DN_FSM_STATE_DISCONNECTED 0x01 |
APS_Lab | 0:8ca1e814a851 | 20 | #define DN_FSM_STATE_PRE_JOIN 0x02 |
APS_Lab | 0:8ca1e814a851 | 21 | #define DN_FSM_STATE_JOINING 0x03 |
APS_Lab | 0:8ca1e814a851 | 22 | #define DN_FSM_STATE_REQ_SERVICE 0x04 |
APS_Lab | 0:8ca1e814a851 | 23 | #define DN_FSM_STATE_RESETTING 0x05 |
APS_Lab | 0:8ca1e814a851 | 24 | #define DN_FSM_STATE_PROMISCUOUS 0x06 |
APS_Lab | 0:8ca1e814a851 | 25 | #define DN_FSM_STATE_CONNECTED 0x0f |
APS_Lab | 0:8ca1e814a851 | 26 | #define DN_FSM_STATE_SENDING 0x10 |
APS_Lab | 0:8ca1e814a851 | 27 | #define DN_FSM_STATE_SEND_FAILED 0x11 |
APS_Lab | 0:8ca1e814a851 | 28 | |
APS_Lab | 0:8ca1e814a851 | 29 | //===== Mote states |
APS_Lab | 0:8ca1e814a851 | 30 | #define DN_MOTE_STATE_IDLE 0x01 |
APS_Lab | 0:8ca1e814a851 | 31 | #define DN_MOTE_STATE_SEARCHING 0x02 |
APS_Lab | 0:8ca1e814a851 | 32 | #define DN_MOTE_STATE_NEGOCIATING 0x03 |
APS_Lab | 0:8ca1e814a851 | 33 | #define DN_MOTE_STATE_CONNECTED 0x04 |
APS_Lab | 0:8ca1e814a851 | 34 | #define DN_MOTE_STATE_OPERATIONAL 0x05 |
APS_Lab | 0:8ca1e814a851 | 35 | |
APS_Lab | 0:8ca1e814a851 | 36 | //===== Mote events |
APS_Lab | 0:8ca1e814a851 | 37 | #define DN_MOTE_EVENT_MASK_NONE 0x0000 |
APS_Lab | 0:8ca1e814a851 | 38 | #define DN_MOTE_EVENT_MASK_BOOT 0x0001 |
APS_Lab | 0:8ca1e814a851 | 39 | #define DN_MOTE_EVENT_MASK_ALARM_CHANGE 0x0002 |
APS_Lab | 0:8ca1e814a851 | 40 | #define DN_MOTE_EVENT_MASK_TIME_CHANGE 0x0004 |
APS_Lab | 0:8ca1e814a851 | 41 | #define DN_MOTE_EVENT_MASK_JOIN_FAIL 0x0008 |
APS_Lab | 0:8ca1e814a851 | 42 | #define DN_MOTE_EVENT_MASK_DISCONNECTED 0x0010 |
APS_Lab | 0:8ca1e814a851 | 43 | #define DN_MOTE_EVENT_MASK_OPERATIONAL 0x0020 |
APS_Lab | 0:8ca1e814a851 | 44 | #define DN_MOTE_EVENT_MASK_SVC_CHANGE 0x0080 |
APS_Lab | 0:8ca1e814a851 | 45 | #define DN_MOTE_EVENT_MASK_JOIN_STARTED 0x0100 |
APS_Lab | 0:8ca1e814a851 | 46 | |
APS_Lab | 0:8ca1e814a851 | 47 | //===== Mote response codes |
APS_Lab | 0:8ca1e814a851 | 48 | #define DN_RC_OK 0x00 |
APS_Lab | 0:8ca1e814a851 | 49 | #define DN_RC_ERROR 0x01 |
APS_Lab | 0:8ca1e814a851 | 50 | #define DN_RC_BUSY 0x03 |
APS_Lab | 0:8ca1e814a851 | 51 | #define DN_RC_INVALID_LEN 0x04 |
APS_Lab | 0:8ca1e814a851 | 52 | #define DN_RC_INVALID_STATE 0x05 |
APS_Lab | 0:8ca1e814a851 | 53 | #define DN_RC_UNSUPPORTED 0x06 |
APS_Lab | 0:8ca1e814a851 | 54 | #define DN_RC_UNKNOWN_PARAM 0x07 |
APS_Lab | 0:8ca1e814a851 | 55 | #define DN_RC_UNKNOWN_CMD 0x08 |
APS_Lab | 0:8ca1e814a851 | 56 | #define DN_RC_WRITE_FAIL 0x09 |
APS_Lab | 0:8ca1e814a851 | 57 | #define DN_RC_READ_FAIL 0x0a |
APS_Lab | 0:8ca1e814a851 | 58 | #define DN_RC_LOW_VOLTAGE 0x0b |
APS_Lab | 0:8ca1e814a851 | 59 | #define DN_RC_NO_RESOURCES 0x0c |
APS_Lab | 0:8ca1e814a851 | 60 | #define DN_RC_INCOMPLETE_JOIN_INFO 0x0d |
APS_Lab | 0:8ca1e814a851 | 61 | #define DN_RC_NOT_FOUND 0x0e |
APS_Lab | 0:8ca1e814a851 | 62 | #define DN_RC_INVALID_VALUE 0x0f |
APS_Lab | 0:8ca1e814a851 | 63 | #define DN_RC_ACCESS_DENIED 0x10 |
APS_Lab | 0:8ca1e814a851 | 64 | #define DN_RC_ERASE_FAIL 0x12 |
APS_Lab | 0:8ca1e814a851 | 65 | |
APS_Lab | 0:8ca1e814a851 | 66 | //===== Timing |
APS_Lab | 0:8ca1e814a851 | 67 | #define DN_FSM_RUN_INTERVAL_MS 10 // Decides how often to kick the FSM |
APS_Lab | 0:8ca1e814a851 | 68 | #define DN_MIN_TX_INTERPACKET_DELAY_MS 20 // Minimum delay between each packet sent to the mote (according to LTC5800-IPM spec) |
APS_Lab | 0:8ca1e814a851 | 69 | #define DN_CMD_PERIOD_MS DN_MIN_TX_INTERPACKET_DELAY_MS * 5 // Delay between each command sent to mote |
APS_Lab | 0:8ca1e814a851 | 70 | #define DN_SERIAL_RESPONSE_TIMEOUT_MS 500 // Very conservative; commands are expected to be answered within 125 ms |
APS_Lab | 0:8ca1e814a851 | 71 | #define DN_CONNECT_TIMEOUT_S 180 // Usually takes 10-60 s, but service req. and promiscuous search can add 60 s each. |
APS_Lab | 0:8ca1e814a851 | 72 | #define DN_SEND_TIMEOUT_MS 1000 // Usually takes < 20 ms |
APS_Lab | 0:8ca1e814a851 | 73 | |
APS_Lab | 0:8ca1e814a851 | 74 | //===== Connect |
APS_Lab | 0:8ca1e814a851 | 75 | #define DN_PROTOCOL_TYPE_UDP 0x00 // Only currently supported protocol type |
APS_Lab | 0:8ca1e814a851 | 76 | |
APS_Lab | 0:8ca1e814a851 | 77 | #define DN_SERVICE_TYPE_BW 0x00 // Only currently supported service type |
APS_Lab | 0:8ca1e814a851 | 78 | #define DN_SERVICE_ADDRESS 0xFFFE // Manager; only currently supported address |
APS_Lab | 0:8ca1e814a851 | 79 | |
APS_Lab | 0:8ca1e814a851 | 80 | #define DN_SERVICE_STATE_COMPLETED 0x00 |
APS_Lab | 0:8ca1e814a851 | 81 | #define DN_SERVICE_STATE_PENDING 0x01 |
APS_Lab | 0:8ca1e814a851 | 82 | |
APS_Lab | 0:8ca1e814a851 | 83 | //===== Send |
APS_Lab | 0:8ca1e814a851 | 84 | #define DN_PACKET_PRIORITY_LOW 0x00 |
APS_Lab | 0:8ca1e814a851 | 85 | #define DN_PACKET_PRIORITY_MEDIUM 0x01 // Recommended for data traffic |
APS_Lab | 0:8ca1e814a851 | 86 | #define DN_PACKET_PRIORITY_HIGH 0x02 |
APS_Lab | 0:8ca1e814a851 | 87 | |
APS_Lab | 0:8ca1e814a851 | 88 | #define DN_PACKET_ID_NO_NOTIF 0xffff // Do not generate txDone notification |
APS_Lab | 0:8ca1e814a851 | 89 | |
APS_Lab | 0:8ca1e814a851 | 90 | //===== Read |
APS_Lab | 0:8ca1e814a851 | 91 | #define DN_INBOX_SIZE 10 // Max number of buffered downstream messages |
APS_Lab | 0:8ca1e814a851 | 92 | |
APS_Lab | 0:8ca1e814a851 | 93 | //===== Reset/disconnect |
APS_Lab | 0:8ca1e814a851 | 94 | /* |
APS_Lab | 0:8ca1e814a851 | 95 | Disconnecting will be more graceful, as the mote first notifies neighbors of |
APS_Lab | 0:8ca1e814a851 | 96 | its imminent software reset. It does, however, take much longer: |
APS_Lab | 0:8ca1e814a851 | 97 | About 20 seconds for disconnect vs 5 seconds for reset only. |
APS_Lab | 0:8ca1e814a851 | 98 | */ |
APS_Lab | 0:8ca1e814a851 | 99 | #define DN_MOTE_DISCONNECT_BEFORE_RESET FALSE |
APS_Lab | 0:8ca1e814a851 | 100 | |
APS_Lab | 0:8ca1e814a851 | 101 | //=========================== typedef ========================================= |
APS_Lab | 0:8ca1e814a851 | 102 | |
APS_Lab | 0:8ca1e814a851 | 103 | typedef void (*dn_fsm_timer_cbt)(void); |
APS_Lab | 0:8ca1e814a851 | 104 | typedef void (*dn_fsm_reply_cbt)(void); |
APS_Lab | 0:8ca1e814a851 | 105 | |
APS_Lab | 0:8ca1e814a851 | 106 | typedef struct |
APS_Lab | 0:8ca1e814a851 | 107 | { |
APS_Lab | 0:8ca1e814a851 | 108 | uint8_t pktBuf[DN_INBOX_SIZE][DN_DEFAULT_PAYLOAD_SIZE_LIMIT]; |
APS_Lab | 0:8ca1e814a851 | 109 | uint8_t pktSize[DN_INBOX_SIZE]; |
APS_Lab | 0:8ca1e814a851 | 110 | uint8_t head; |
APS_Lab | 0:8ca1e814a851 | 111 | uint8_t tail; |
APS_Lab | 0:8ca1e814a851 | 112 | uint8_t unreadPackets; |
APS_Lab | 0:8ca1e814a851 | 113 | } dn_inbox_t; |
APS_Lab | 0:8ca1e814a851 | 114 | |
APS_Lab | 0:8ca1e814a851 | 115 | //=========================== variables ======================================= |
APS_Lab | 0:8ca1e814a851 | 116 | |
APS_Lab | 0:8ca1e814a851 | 117 | //=========================== prototypes ====================================== |
APS_Lab | 0:8ca1e814a851 | 118 | |
APS_Lab | 0:8ca1e814a851 | 119 | #ifdef __cplusplus |
APS_Lab | 0:8ca1e814a851 | 120 | extern "C" |
APS_Lab | 0:8ca1e814a851 | 121 | { |
APS_Lab | 0:8ca1e814a851 | 122 | #endif |
APS_Lab | 0:8ca1e814a851 | 123 | |
APS_Lab | 0:8ca1e814a851 | 124 | #ifdef __cplusplus |
APS_Lab | 0:8ca1e814a851 | 125 | } |
APS_Lab | 0:8ca1e814a851 | 126 | #endif |
APS_Lab | 0:8ca1e814a851 | 127 | |
APS_Lab | 0:8ca1e814a851 | 128 | #endif /* DN_FSM_H */ |
APS_Lab | 0:8ca1e814a851 | 129 | |
APS_Lab | 0:8ca1e814a851 | 130 |