fsfw/rmap/RMAP.cpp

92 lines
2.4 KiB
C++
Raw Permalink Normal View History

2020-08-13 20:53:35 +02:00
#include "RMAP.h"
2020-12-13 22:12:57 +01:00
#include "rmapStructs.h"
2020-08-13 20:53:35 +02:00
#include "RMAPChannelIF.h"
2020-12-13 22:12:57 +01:00
#include "../devicehandlers/DeviceCommunicationIF.h"
#include <cstddef>
ReturnValue_t RMAP::reset(RMAPCookie* cookie) {
2018-07-13 18:28:26 +02:00
return cookie->getChannel()->reset();
}
RMAP::RMAP(){
}
2020-12-13 22:12:57 +01:00
ReturnValue_t RMAP::sendWriteCommand(RMAPCookie *cookie, const uint8_t* buffer,
size_t length) {
uint8_t instruction;
if ((buffer == NULL) && (length != 0)) {
return DeviceCommunicationIF::NULLPOINTER;
}
if (cookie->getChannel() == NULL) {
return COMMAND_NO_CHANNEL;
}
2018-07-13 18:28:26 +02:00
instruction = RMAPIds::RMAP_COMMAND_WRITE | cookie->getCommandMask();
return cookie->getChannel()->sendCommand(cookie, instruction, buffer,
length);
}
ReturnValue_t RMAP::getWriteReply(RMAPCookie *cookie) {
if (cookie->getChannel() == NULL) {
return COMMAND_NO_CHANNEL;
}
2018-07-13 18:28:26 +02:00
if (cookie->getHeader()->instruction & (1 << RMAPIds::RMAP_COMMAND_BIT_WRITE)) {
return cookie->getChannel()->getReply(cookie, NULL, NULL);
} else {
return REPLY_MISSMATCH;
}
}
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);
}
ReturnValue_t RMAP::sendReadCommand(RMAPCookie *cookie, uint32_t expLength) {
uint8_t command;
if (cookie->getChannel() == NULL) {
return COMMAND_NO_CHANNEL;
}
2018-07-13 18:28:26 +02:00
command = RMAPIds::RMAP_COMMAND_READ
| (cookie->getCommandMask() & ~(1 << RMAPIds::RMAP_COMMAND_BIT_VERIFY));
return cookie->getChannel()->sendCommand(cookie, command, NULL, expLength);
}
ReturnValue_t RMAP::getReadReply(RMAPCookie *cookie, uint8_t **buffer,
2020-12-13 22:12:57 +01:00
size_t *size) {
if (cookie->getChannel() == NULL) {
return COMMAND_NO_CHANNEL;
}
if (buffer == NULL || size == NULL) {
return DeviceCommunicationIF::NULLPOINTER;
}
2018-07-13 18:28:26 +02:00
if (cookie->getHeader()->instruction & (1 << RMAPIds::RMAP_COMMAND_BIT_WRITE)) {
return REPLY_MISSMATCH;
} else {
return cookie->getChannel()->getReply(cookie, buffer, size);
}
}
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);
}