FEP interrupt, response, ring buffer

Dependents:   087_myFEP_TX 087_myFEP_RX

FEP.h

Committer:
piroro4560
Date:
2021-10-09
Revision:
2:aa9a344a42a8
Parent:
1:a4103af46277
Child:
3:12dcc46fb9dc

File content as of revision 2:aa9a344a42a8:

/** @FEP.h
 *  @brief FEP
 */
#ifndef FEP_H
#define FEP_H

#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
 */
class myFEP{
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
     */
    myFEP(PinName tx, PinName rx, uint8_t addr_, int baud=115200);

    /** Receive start function
     */
    void StartReceive();

    /** Receive interrupt function
     */
    void ReceiveBytes();

    /** Message reading function
     */
    void CheckData();

    /** Received message substitution function
     *  @param data Data address of storage destination
     */
    void 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 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
     */
    uint8_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
     *
     *  @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
     */
    uint8_t SendData(uint8_t *data, uint8_t length);

    /** Response acquisition function
     *  @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
     */
    uint8_t GetResponse();

private :
    uint8_t ctoi(char c);

    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
}

#endif