2020-08-13 20:53:35 +02:00
|
|
|
#include "../devicehandlers/DeviceCommunicationIF.h"
|
|
|
|
#include "rmapStructs.h"
|
|
|
|
#include "RMAP.h"
|
|
|
|
#include "RMAPChannelIF.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
ReturnValue_t RMAP::reset(RMAPCookie* cookie) {
|
2018-07-13 18:28:26 +02:00
|
|
|
return cookie->getChannel()->reset();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RMAP::RMAP(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t RMAP::sendWriteCommand(RMAPCookie *cookie, uint8_t* buffer,
|
|
|
|
uint32_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();
|
2016-06-15 23:48:41 +02:00
|
|
|
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)) {
|
2016-06-15 23:48:41 +02:00
|
|
|
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));
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
return cookie->getChannel()->sendCommand(cookie, command, NULL, expLength);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t RMAP::getReadReply(RMAPCookie *cookie, uint8_t **buffer,
|
|
|
|
uint32_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)) {
|
2016-06-15 23:48:41 +02:00
|
|
|
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);
|
|
|
|
}
|