restructure repository

This commit is contained in:
2021-07-13 18:40:52 +02:00
parent 5adb5cce95
commit bdb8b0a757
738 changed files with 0 additions and 78 deletions

View File

@ -0,0 +1,7 @@
target_sources(${LIB_FSFW_NAME}
PRIVATE
RMAP.cpp
RMAPCookie.cpp
RmapDeviceCommunicationIF.cpp
)

91
src/opt/rmap/RMAP.cpp Normal file
View File

@ -0,0 +1,91 @@
#include "RMAP.h"
#include "rmapStructs.h"
#include "RMAPChannelIF.h"
#include "../devicehandlers/DeviceCommunicationIF.h"
#include <cstddef>
ReturnValue_t RMAP::reset(RMAPCookie* cookie) {
return cookie->getChannel()->reset();
}
RMAP::RMAP(){
}
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;
}
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;
}
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;
}
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,
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);
}
}
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);
}

125
src/opt/rmap/RMAPCookie.cpp Normal file
View File

@ -0,0 +1,125 @@
#include "RMAPChannelIF.h"
#include "RMAPCookie.h"
#include <cstddef>
RMAPCookie::RMAPCookie() {
this->header.dest_address = 0;
this->header.protocol = 0x01;
this->header.instruction = 0;
this->header.dest_key = 0;
this->header.source_address = 0;
this->header.tid_h = 0;
this->header.tid_l = 0;
this->header.extended_address = 0;
this->header.address_hh = 0;
this->header.address_h = 0;
this->header.address_l = 0;
this->header.address_ll = 0;
this->header.datalen_h = 0;
this->header.datalen_m = 0;
this->header.datalen_l = 0;
this->header.header_crc = 0;
this->channel = NULL;
this->command_mask = 0;
this->dataCRC = 0;
this->maxReplyLen = 0;
}
RMAPCookie::RMAPCookie(uint32_t set_address, uint8_t set_extended_address,
RMAPChannelIF *set_channel, uint8_t set_command_mask,
size_t maxReplyLen) {
this->header.dest_address = 0;
this->header.protocol = 0x01;
this->header.instruction = 0;
this->header.dest_key = 0;
this->header.source_address = 0;
this->header.tid_h = 0;
this->header.tid_l = 0;
this->header.extended_address = set_extended_address;
setAddress(set_address);
this->header.datalen_h = 0;
this->header.datalen_m = 0;
this->header.datalen_l = 0;
this->header.header_crc = 0;
this->channel = set_channel;
this->command_mask = set_command_mask;
this->dataCRC = 0;
this->maxReplyLen = maxReplyLen;
}
void RMAPCookie::setAddress(uint32_t address) {
this->header.address_hh = (address & 0xFF000000) >> 24;
this->header.address_h = (address & 0x00FF0000) >> 16;
this->header.address_l = (address & 0x0000FF00) >> 8;
this->header.address_ll = address & 0x000000FF;
}
void RMAPCookie::setExtendedAddress(uint8_t extendedAddress) {
this->header.extended_address = extendedAddress;
}
void RMAPCookie::setChannel(RMAPChannelIF *channel) {
this->channel = channel;
}
void RMAPCookie::setCommandMask(uint8_t commandMask) {
this->command_mask = commandMask;
}
uint32_t RMAPCookie::getAddress() {
return (header.address_hh << 24) + (header.address_h << 16)
+ (header.address_l << 8) + (header.address_ll);
}
uint8_t RMAPCookie::getExtendedAddress() {
return header.extended_address;
}
RMAPChannelIF *RMAPCookie::getChannel() {
return channel;
}
uint8_t RMAPCookie::getCommandMask() {
return command_mask;
}
RMAPCookie::~RMAPCookie() {
}
size_t RMAPCookie::getMaxReplyLen() const {
return maxReplyLen;
}
void RMAPCookie::setMaxReplyLen(size_t maxReplyLen) {
this->maxReplyLen = maxReplyLen;
}
RMAPStructs::rmap_cmd_header* RMAPCookie::getHeader(){
return &this->header;
}
uint16_t RMAPCookie::getTransactionIdentifier() const {
return static_cast<uint16_t>((header.tid_h << 8) | (header.tid_l));
}
void RMAPCookie::setTransactionIdentifier(uint16_t id_) {
header.tid_l = id_ & 0xFF;
header.tid_h = (id_ >> 8 ) & 0xFF;
}
uint32_t RMAPCookie::getDataLength() const {
return static_cast<uint32_t>(header.datalen_h << 16 | header.datalen_m << 8 | header.datalen_l);
}
void RMAPCookie::setDataLength(uint32_t length_) {
header.datalen_l = length_ & 0xff;
header.datalen_m = (length_ >> 8) & 0xff;
header.datalen_h = (length_ >> 16) & 0xff;
}

View File

@ -0,0 +1,47 @@
#include "RmapDeviceCommunicationIF.h"
#include "RMAP.h"
//TODO Cast here are all potential bugs
RmapDeviceCommunicationIF::~RmapDeviceCommunicationIF() {
}
ReturnValue_t RmapDeviceCommunicationIF::sendMessage(CookieIF *cookie,
const uint8_t * sendData, size_t sendLen) {
return RMAP::sendWriteCommand((RMAPCookie *) cookie, sendData, sendLen);
}
ReturnValue_t RmapDeviceCommunicationIF::getSendSuccess(CookieIF* cookie) {
return RMAP::getWriteReply((RMAPCookie *) cookie);
}
ReturnValue_t RmapDeviceCommunicationIF::requestReceiveMessage(
CookieIF *cookie, size_t requestLen) {
return RMAP::sendReadCommand((RMAPCookie *) cookie,
((RMAPCookie *) cookie)->getMaxReplyLen());
}
ReturnValue_t RmapDeviceCommunicationIF::readReceivedMessage(CookieIF* cookie,
uint8_t** buffer, size_t * size) {
return RMAP::getReadReply((RMAPCookie *) cookie, buffer, size);
}
ReturnValue_t RmapDeviceCommunicationIF::setAddress(CookieIF* cookie,
uint32_t address) {
((RMAPCookie *) cookie)->setAddress(address);
return HasReturnvaluesIF::RETURN_OK;
}
uint32_t RmapDeviceCommunicationIF::getAddress(CookieIF* cookie) {
return ((RMAPCookie *) cookie)->getAddress();
}
ReturnValue_t RmapDeviceCommunicationIF::setParameter(CookieIF* cookie,
uint32_t parameter) {
//TODO Empty?
return HasReturnvaluesIF::RETURN_FAILED;
}
uint32_t RmapDeviceCommunicationIF::getParameter(CookieIF* cookie) {
return 0;
}