FEP interrupt, response, ring buffer
Dependents: 087_myFEP_TX 087_myFEP_RX
FEP.h@3:12dcc46fb9dc, 2021-10-11 (annotated)
- Committer:
- piroro4560
- Date:
- Mon Oct 11 13:22:16 2021 +0000
- Revision:
- 3:12dcc46fb9dc
- Parent:
- 2:aa9a344a42a8
- Child:
- 4:8d754f144b96
fixed fixed fixed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
piroro4560 | 2:aa9a344a42a8 | 1 | /** @FEP.h |
piroro4560 | 2:aa9a344a42a8 | 2 | * @brief FEP |
piroro4560 | 2:aa9a344a42a8 | 3 | */ |
piroro4560 | 0:b01dc5fd59bc | 4 | #ifndef FEP_H |
piroro4560 | 0:b01dc5fd59bc | 5 | #define FEP_H |
piroro4560 | 0:b01dc5fd59bc | 6 | |
piroro4560 | 1:a4103af46277 | 7 | #include "mbed.h" |
piroro4560 | 1:a4103af46277 | 8 | |
piroro4560 | 2:aa9a344a42a8 | 9 | /** |
piroro4560 | 2:aa9a344a42a8 | 10 | * @class myFEP Class for communicating using FEP-01, FEP-02 |
piroro4560 | 2:aa9a344a42a8 | 11 | * @brief Class for communicating using FEP-01, FEP-02 |
piroro4560 | 2:aa9a344a42a8 | 12 | * @note Not compatible with mbed-os 6 |
piroro4560 | 2:aa9a344a42a8 | 13 | */ |
piroro4560 | 3:12dcc46fb9dc | 14 | class myFEP : public RawSerial { |
piroro4560 | 0:b01dc5fd59bc | 15 | public : |
piroro4560 | 2:aa9a344a42a8 | 16 | /** constructor |
piroro4560 | 2:aa9a344a42a8 | 17 | * @param tx SerialTX mbed pin to connect to FEP |
piroro4560 | 2:aa9a344a42a8 | 18 | * @param rx SerialRX mbed pin to connect to FEP |
piroro4560 | 2:aa9a344a42a8 | 19 | * @param addr Destination address |
piroro4560 | 2:aa9a344a42a8 | 20 | * @param baud baudrate |
piroro4560 | 0:b01dc5fd59bc | 21 | */ |
piroro4560 | 0:b01dc5fd59bc | 22 | myFEP(PinName tx, PinName rx, uint8_t addr_, int baud=115200); |
piroro4560 | 0:b01dc5fd59bc | 23 | |
piroro4560 | 2:aa9a344a42a8 | 24 | /** Receive start function |
piroro4560 | 0:b01dc5fd59bc | 25 | */ |
piroro4560 | 0:b01dc5fd59bc | 26 | void StartReceive(); |
piroro4560 | 0:b01dc5fd59bc | 27 | |
piroro4560 | 2:aa9a344a42a8 | 28 | /** Receive interrupt function |
piroro4560 | 0:b01dc5fd59bc | 29 | */ |
piroro4560 | 0:b01dc5fd59bc | 30 | void ReceiveBytes(); |
piroro4560 | 0:b01dc5fd59bc | 31 | |
piroro4560 | 2:aa9a344a42a8 | 32 | /** Message reading function |
piroro4560 | 0:b01dc5fd59bc | 33 | */ |
piroro4560 | 0:b01dc5fd59bc | 34 | void CheckData(); |
piroro4560 | 0:b01dc5fd59bc | 35 | |
piroro4560 | 2:aa9a344a42a8 | 36 | /** Received message substitution function |
piroro4560 | 2:aa9a344a42a8 | 37 | * @param data Data address of storage destination |
piroro4560 | 0:b01dc5fd59bc | 38 | */ |
piroro4560 | 0:b01dc5fd59bc | 39 | void GetData(uint8_t *data); |
piroro4560 | 0:b01dc5fd59bc | 40 | |
piroro4560 | 2:aa9a344a42a8 | 41 | /** Send data to the other party FEP |
piroro4560 | 2:aa9a344a42a8 | 42 | * Send all data in the @brief argument |
piroro4560 | 2:aa9a344a42a8 | 43 | * @param data Array to send |
piroro4560 | 2:aa9a344a42a8 | 44 | * @return 0 Successful transmission |
piroro4560 | 3:12dcc46fb9dc | 45 | * @return 1 Excessive amount of datax |
piroro4560 | 2:aa9a344a42a8 | 46 | * @return 2 command error |
piroro4560 | 2:aa9a344a42a8 | 47 | * @return 3 No response from the other party |
piroro4560 | 2:aa9a344a42a8 | 48 | * @return 4 The other party failed to receive |
piroro4560 | 2:aa9a344a42a8 | 49 | * @return -1 Not sure |
piroro4560 | 0:b01dc5fd59bc | 50 | */ |
piroro4560 | 3:12dcc46fb9dc | 51 | int8_t SendData(uint8_t *data); |
piroro4560 | 0:b01dc5fd59bc | 52 | |
piroro4560 | 2:aa9a344a42a8 | 53 | /** Send by specifying the length |
piroro4560 | 2:aa9a344a42a8 | 54 | * @brief Send 'data' of 'length' length |
piroro4560 | 2:aa9a344a42a8 | 55 | * @param data address of array to send |
piroro4560 | 2:aa9a344a42a8 | 56 | * @param length length to send |
piroro4560 | 2:aa9a344a42a8 | 57 | * |
piroro4560 | 2:aa9a344a42a8 | 58 | * @return 0 Successful transmission |
piroro4560 | 2:aa9a344a42a8 | 59 | * @return 1 Excessive amount of data |
piroro4560 | 2:aa9a344a42a8 | 60 | * @return 2 command error |
piroro4560 | 2:aa9a344a42a8 | 61 | * @return 3 No response from the other party |
piroro4560 | 2:aa9a344a42a8 | 62 | * @return 4 The other party failed to receive |
piroro4560 | 2:aa9a344a42a8 | 63 | * @return -1 Not sure |
piroro4560 | 0:b01dc5fd59bc | 64 | */ |
piroro4560 | 3:12dcc46fb9dc | 65 | int8_t SendData(uint8_t *data, uint8_t length); |
piroro4560 | 0:b01dc5fd59bc | 66 | |
piroro4560 | 2:aa9a344a42a8 | 67 | /** Response acquisition function |
piroro4560 | 2:aa9a344a42a8 | 68 | * @return 0 Successful transmission |
piroro4560 | 2:aa9a344a42a8 | 69 | * @return 2 command error |
piroro4560 | 2:aa9a344a42a8 | 70 | * @return 3 No response from the other party |
piroro4560 | 2:aa9a344a42a8 | 71 | * @return 4 The other party failed to receive |
piroro4560 | 2:aa9a344a42a8 | 72 | * @return -1 Not sure |
piroro4560 | 0:b01dc5fd59bc | 73 | */ |
piroro4560 | 3:12dcc46fb9dc | 74 | int8_t GetResponse(); |
piroro4560 | 0:b01dc5fd59bc | 75 | |
piroro4560 | 0:b01dc5fd59bc | 76 | private : |
piroro4560 | 3:12dcc46fb9dc | 77 | int8_t ctoi(char c); |
piroro4560 | 0:b01dc5fd59bc | 78 | |
piroro4560 | 3:12dcc46fb9dc | 79 | uint8_t addr; //! Destination address |
piroro4560 | 3:12dcc46fb9dc | 80 | uint8_t buffer[256]; //! Array for storing received data |
piroro4560 | 3:12dcc46fb9dc | 81 | uint8_t retdata[256]; //! Data storage array for Substitution |
piroro4560 | 3:12dcc46fb9dc | 82 | uint16_t bufindex; //! index of buffer |
piroro4560 | 3:12dcc46fb9dc | 83 | uint16_t retindex; //! index of retdata |
piroro4560 | 3:12dcc46fb9dc | 84 | }; |
piroro4560 | 0:b01dc5fd59bc | 85 | |
piroro4560 | 0:b01dc5fd59bc | 86 | #endif |