clean up op done
This commit is contained in:
93
linux/power/CspComIF.h
Normal file
93
linux/power/CspComIF.h
Normal file
@ -0,0 +1,93 @@
|
||||
#ifndef LINUX_POWER_CSPCOMIF_H_
|
||||
#define LINUX_POWER_CSPCOMIF_H_
|
||||
|
||||
#include <csp/csp.h>
|
||||
#include <csp/csp_autoconfig.h>
|
||||
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/returnvalues/returnvalue.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* @brief This class serves as the communication interface to devices
|
||||
* supporting the CSP protocol. As physical layer can0 is used
|
||||
* in this implementation.
|
||||
* @author J. Meier
|
||||
*/
|
||||
class CspComIF : public DeviceCommunicationIF, public SystemObject {
|
||||
public:
|
||||
CspComIF(object_id_t objectId, const char *routeTaskName, uint32_t routerRealTimePriority);
|
||||
virtual ~CspComIF();
|
||||
|
||||
ReturnValue_t initializeInterface(CookieIF *cookie) override;
|
||||
ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) override;
|
||||
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
|
||||
ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) override;
|
||||
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **readData, size_t *readLen) override;
|
||||
|
||||
private:
|
||||
#ifdef CSP_USE_RDP
|
||||
//! If RDP is enabled, the router needs to awake some times to check timeouts
|
||||
static constexpr uint32_t FIFO_TIMEOUT = 100;
|
||||
#else
|
||||
//! If no RDP, the router can sleep untill data arrives
|
||||
static constexpr uint32_t FIFO_TIMEOUT = CSP_MAX_DELAY;
|
||||
#endif
|
||||
/**
|
||||
* @brief This function initiates the CSP transfer.
|
||||
*
|
||||
* @param cspAddress The CSP address of the target device.
|
||||
* @param cspPort The port of the target device.
|
||||
* @param timeout The timeout to wait for csp_send and csp_read
|
||||
* functions. Specifies how long the functions wait
|
||||
* for a successful operation.
|
||||
* @param cmdBuffer The data to send.
|
||||
* @param cmdLen The number of bytes to send.
|
||||
* @param querySize The size of the requested message.
|
||||
*/
|
||||
ReturnValue_t cspTransfer(uint8_t cspAddress, uint8_t cspPort, const uint8_t *cmdBuffer,
|
||||
int cmdLen, uint16_t querySize);
|
||||
|
||||
typedef uint8_t node_t;
|
||||
struct ReplyInfo {
|
||||
ReplyInfo(size_t maxLen) : replyBuf(maxLen){};
|
||||
std::vector<uint8_t> replyBuf;
|
||||
size_t replyLen = 0;
|
||||
};
|
||||
using VectorBufferMap = std::unordered_map<node_t, ReplyInfo>;
|
||||
|
||||
/* In this map assigns reply buffers to a CSP device */
|
||||
VectorBufferMap cspDeviceMap;
|
||||
|
||||
/* This is the CSP address of the OBC. */
|
||||
node_t cspOwnAddress = 1;
|
||||
|
||||
pthread_t routerTaskHandle{};
|
||||
uint32_t routerRealTimePriority = 0;
|
||||
const char *routerTaskName;
|
||||
|
||||
/* Interface struct for csp protocol stack */
|
||||
csp_iface_t csp_if;
|
||||
char canInterface[5] = "can0";
|
||||
int bitrate = 1000;
|
||||
|
||||
/**
|
||||
* @brief Function to extract the csp port and the query size from the
|
||||
* command buffer.
|
||||
*/
|
||||
ReturnValue_t getPortAndQuerySize(const uint8_t **sendData, size_t *sendLen, uint8_t *cspPort,
|
||||
uint16_t *querySize);
|
||||
|
||||
/**
|
||||
* @brief This function initiates the ping request.
|
||||
*/
|
||||
void initiatePingRequest(uint8_t cspAddress, uint16_t querySize);
|
||||
|
||||
ReturnValue_t startRouterTask();
|
||||
static void *routerWorkWrapper(void *args);
|
||||
};
|
||||
|
||||
#endif /* LINUX_POWER_CSPCOMIF_H_ */
|
Reference in New Issue
Block a user