FEP interrupt, response, ring buffer
Dependents: 087_myFEP_TX 087_myFEP_RX
Diff: FEP.h
- Revision:
- 4:8d754f144b96
- Parent:
- 3:12dcc46fb9dc
diff -r 12dcc46fb9dc -r 8d754f144b96 FEP.h --- a/FEP.h Mon Oct 11 13:22:16 2021 +0000 +++ b/FEP.h Fri Oct 15 13:23:15 2021 +0000 @@ -1,86 +1,89 @@ -/** @FEP.h - * @brief FEP +/** + * @file FEP.h + * @brief FEPライブラリ + * @author 安澤瑠 + * @date 21/10/15 */ #ifndef FEP_H #define FEP_H +#define TIMEOUT_COUNT 10 + #include "mbed.h" /** * @class myFEP Class for communicating using FEP-01, FEP-02 * @brief Class for communicating using FEP-01, FEP-02 - * @note Not compatible with mbed-os 6 + * @note mbed-os 6 では使えません。 Not compatible with mbed-os 6 */ class myFEP : public RawSerial { public : /** constructor - * @param tx SerialTX mbed pin to connect to FEP - * @param rx SerialRX mbed pin to connect to FEP - * @param addr Destination address - * @param baud baudrate + * @param tx FEPと接続するSerialTX pin + * @param rx FEPと接続するSerialRX pin + * @param addr 通信相手のアドレス + * @param baud 通信速度(デフォルト115200) */ myFEP(PinName tx, PinName rx, uint8_t addr_, int baud=115200); - /** Receive start function + /** Start receiving */ void StartReceive(); + + /** Check timeout + * @brief 0.1秒毎のループで受信のタイムアウトをチェック + */ + void TimeoutLoop(); - /** Receive interrupt function + /** Interrupt input */ void ReceiveBytes(); - /** Message reading function + /** extract the message */ void CheckData(); - /** Received message substitution function - * @param data Data address of storage destination + /** Write the received message + * @param data 受信メッセージを格納する配列 */ - void GetData(uint8_t *data); + uint8_t GetData(uint8_t *data); - /** Send data to the other party FEP - * Send all data in the @brief argument - * @param data Array to send - * @return 0 Successful transmission - * @return 1 Excessive amount of datax - * @return 2 command error - * @return 3 No response from the other party - * @return 4 The other party failed to receive - * @return -1 Not sure - */ - int8_t SendData(uint8_t *data); - - /** Send by specifying the length - * @brief Send 'data' of 'length' length - * @param data address of array to send - * @param length length to send + /** send message + * @brief data配列のデータをlength分送信する + * @param data 送るデータ配列のアドレス + * @param length 送るデータのバイト数 * - * @return 0 Successful transmission - * @return 1 Excessive amount of data - * @return 2 command error - * @return 3 No response from the other party - * @return 4 The other party failed to receive - * @return -1 Not sure + * @return 0 通信成功 + * @return 1 データ量過多 + * @return 2 コマンドエラー + * @return 3 通信相手からのレスポンス無し + * @return 4 通信相手が受け取りに失敗 + * @return -1 可否不能 */ int8_t SendData(uint8_t *data, uint8_t length); /** Response acquisition function - * @return 0 Successful transmission - * @return 2 command error - * @return 3 No response from the other party - * @return 4 The other party failed to receive - * @return -1 Not sure + * @return 0 通信成功 + * @return 2 コマンドエラー + * @return 3 通信相手からのレスポンス無し + * @return 4 通信相手が受け取りに失敗 + * @return -1 可否不能 */ int8_t GetResponse(); + + bool status; //! (TIMEOUT_COUNT * 0.1)秒間通信が来ていないと0 private : - int8_t ctoi(char c); + + Ticker timeoutTimer; - uint8_t addr; //! Destination address - uint8_t buffer[256]; //! Array for storing received data - uint8_t retdata[256]; //! Data storage array for Substitution - uint16_t bufindex; //! index of buffer - uint16_t retindex; //! index of retdata + uint8_t addr; //! 通信相手のアドレス + uint8_t buffer[256]; //! 全受信データを格納するリングバッファ配列 + uint8_t retdata[128]; //! メッセージのみを格納する配列 + uint8_t bufindex; //! buffer の添え字変数 + uint8_t retindex; //! retdata の添え字変数 + uint8_t length; //! メッセージバイト数 + uint8_t timeout; //! 0.1秒間通信が成功していないと1増える }; #endif \ No newline at end of file