2021-07-13 20:58:45 +02:00
|
|
|
#include "fsfw/rmap/RMAP.h"
|
2020-12-13 22:12:57 +01:00
|
|
|
|
|
|
|
#include <cstddef>
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
|
|
|
|
#include "fsfw/rmap/RMAPChannelIF.h"
|
|
|
|
#include "fsfw/rmap/rmapStructs.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t RMAP::reset(RMAPCookie *cookie) { return cookie->getChannel()->reset(); }
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
RMAP::RMAP() {}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t RMAP::sendWriteCommand(RMAPCookie *cookie, const uint8_t *buffer, size_t length) {
|
|
|
|
uint8_t instruction;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
if ((buffer == NULL) && (length != 0)) {
|
|
|
|
return DeviceCommunicationIF::NULLPOINTER;
|
|
|
|
}
|
|
|
|
if (cookie->getChannel() == NULL) {
|
|
|
|
return COMMAND_NO_CHANNEL;
|
|
|
|
}
|
|
|
|
instruction = RMAPIds::RMAP_COMMAND_WRITE | cookie->getCommandMask();
|
|
|
|
return cookie->getChannel()->sendCommand(cookie, instruction, buffer, length);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t RMAP::getWriteReply(RMAPCookie *cookie) {
|
2022-02-02 10:29:30 +01:00
|
|
|
if (cookie->getChannel() == NULL) {
|
|
|
|
return COMMAND_NO_CHANNEL;
|
|
|
|
}
|
|
|
|
if (cookie->getHeader()->instruction & (1 << RMAPIds::RMAP_COMMAND_BIT_WRITE)) {
|
|
|
|
return cookie->getChannel()->getReply(cookie, NULL, NULL);
|
|
|
|
} else {
|
|
|
|
return REPLY_MISSMATCH;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t RMAP::writeBlocking(RMAPCookie *cookie, uint8_t *buffer, uint32_t length,
|
|
|
|
uint32_t timeout_us) {
|
|
|
|
if (cookie->getChannel() == NULL) {
|
|
|
|
return COMMAND_NO_CHANNEL;
|
|
|
|
}
|
|
|
|
return cookie->getChannel()->sendCommandBlocking(cookie, buffer, length, NULL, NULL, timeout_us);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
ReturnValue_t RMAP::sendReadCommand(RMAPCookie *cookie, uint32_t expLength) {
|
2022-02-02 10:29:30 +01:00
|
|
|
uint8_t command;
|
|
|
|
if (cookie->getChannel() == NULL) {
|
|
|
|
return COMMAND_NO_CHANNEL;
|
|
|
|
}
|
|
|
|
command = RMAPIds::RMAP_COMMAND_READ |
|
|
|
|
(cookie->getCommandMask() & ~(1 << RMAPIds::RMAP_COMMAND_BIT_VERIFY));
|
|
|
|
|
|
|
|
return cookie->getChannel()->sendCommand(cookie, command, NULL, expLength);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t RMAP::getReadReply(RMAPCookie *cookie, uint8_t **buffer, size_t *size) {
|
|
|
|
if (cookie->getChannel() == NULL) {
|
|
|
|
return COMMAND_NO_CHANNEL;
|
|
|
|
}
|
|
|
|
if (buffer == NULL || size == NULL) {
|
|
|
|
return DeviceCommunicationIF::NULLPOINTER;
|
|
|
|
}
|
|
|
|
if (cookie->getHeader()->instruction & (1 << RMAPIds::RMAP_COMMAND_BIT_WRITE)) {
|
|
|
|
return REPLY_MISSMATCH;
|
|
|
|
} else {
|
|
|
|
return cookie->getChannel()->getReply(cookie, buffer, size);
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t RMAP::readBlocking(RMAPCookie *cookie, uint32_t expLength, uint8_t **buffer,
|
|
|
|
uint32_t *size, uint32_t timeout_us) {
|
|
|
|
if (cookie->getChannel() == NULL) {
|
|
|
|
return COMMAND_NO_CHANNEL;
|
|
|
|
}
|
|
|
|
if (buffer == NULL || size == NULL) {
|
|
|
|
return DeviceCommunicationIF::NULLPOINTER;
|
|
|
|
}
|
|
|
|
return cookie->getChannel()->sendCommandBlocking(cookie, NULL, expLength, buffer, size,
|
|
|
|
timeout_us);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|