eive-obsw/bsp_hosted/comIF/ArduinoComIF.h

67 lines
2.1 KiB
C
Raw Normal View History

2020-10-01 02:06:39 +02:00
#ifndef MISSION_ARDUINOCOMMINTERFACE_H_
#define MISSION_ARDUINOCOMMINTERFACE_H_
#include <fsfw/container/FixedMap.h>
#include <fsfw/container/SimpleRingBuffer.h>
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
#include <fsfw/objectmanager/SystemObject.h>
2022-08-24 17:27:47 +02:00
#include <fsfw/returnvalues/returnvalue.h>
2020-10-01 02:06:39 +02:00
#include <cstdint>
#include <map>
#ifdef WIN32
#include <windows.h>
#endif
2022-01-17 15:58:27 +01:00
// Forward declaration, so users don't peek
2020-10-01 02:06:39 +02:00
class ArduinoCookie;
2022-01-17 15:58:27 +01:00
class ArduinoComIF : public SystemObject, public DeviceCommunicationIF {
public:
static const uint8_t MAX_NUMBER_OF_SPI_DEVICES = 8;
static const uint8_t MAX_PACKET_SIZE = 64;
2020-10-01 02:06:39 +02:00
2022-01-17 15:58:27 +01:00
static const uint8_t COMMAND_INVALID = -1;
static const uint8_t COMMAND_SPI = 1;
2020-10-01 02:06:39 +02:00
2022-01-17 15:58:27 +01:00
ArduinoComIF(object_id_t setObjectId, bool promptComIF = false,
const char *serialDevice = nullptr);
void setBaudrate(uint32_t baudRate);
2020-10-01 02:06:39 +02:00
2022-01-17 15:58:27 +01:00
virtual ~ArduinoComIF();
2020-10-01 02:06:39 +02:00
2022-01-17 15:58:27 +01:00
/** DeviceCommunicationIF overrides */
virtual ReturnValue_t initializeInterface(CookieIF *cookie) override;
virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t *sendData,
size_t sendLen) override;
virtual ReturnValue_t getSendSuccess(CookieIF *cookie) override;
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) override;
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size) override;
2020-10-01 02:06:39 +02:00
2022-01-17 15:58:27 +01:00
private:
2020-10-01 02:06:39 +02:00
#ifdef LINUX
#elif WIN32
2022-01-17 15:58:27 +01:00
HANDLE hCom = INVALID_HANDLE_VALUE;
2020-10-01 02:06:39 +02:00
#endif
2022-01-17 15:58:27 +01:00
// remembering if the initialization in the ctor worked
// if not, all calls are disabled
bool initialized = false;
int serialPort = 0;
// Default baud rate is 9600 for now.
uint32_t baudRate = 9600;
2020-10-01 02:06:39 +02:00
2022-01-17 15:58:27 +01:00
// used to know where to put the data if a reply is received
std::map<uint8_t, ArduinoCookie> spiMap;
2020-10-01 02:06:39 +02:00
2022-01-17 15:58:27 +01:00
SimpleRingBuffer rxBuffer;
2020-10-01 02:06:39 +02:00
2022-01-17 15:58:27 +01:00
ReturnValue_t sendMessage(uint8_t command, uint8_t address, const uint8_t *data, size_t dataLen);
void handleSerialPortRx();
2020-10-01 02:06:39 +02:00
2022-01-17 15:58:27 +01:00
void handlePacket(uint8_t *packet, size_t packetLen);
2020-10-01 02:06:39 +02:00
};
#endif /* MISSION_ARDUINOCOMMINTERFACE_H_ */