WIP: SCEX Init #272

Closed
muellerr wants to merge 62 commits from irini into develop
6 changed files with 163 additions and 27 deletions
Showing only changes of commit 578899b5a5 - Show all commits

View File

@ -5,6 +5,7 @@
#include <fsfw/tasks/TaskFactory.h> #include <fsfw/tasks/TaskFactory.h>
#include <fsfw_hal/linux/uart/UartCookie.h> #include <fsfw_hal/linux/uart/UartCookie.h>
#include <linux/devices/ScexDleParser.h> #include <linux/devices/ScexDleParser.h>
#include <linux/devices/ScexHelper.h>
#include <linux/devices/ScexUartReader.h> #include <linux/devices/ScexUartReader.h>
#include <unistd.h> // write(), read(), close() #include <unistd.h> // write(), read(), close()
@ -167,6 +168,7 @@ void UartTestClass::scexInit() {
void UartTestClass::scexPeriodic() { void UartTestClass::scexPeriodic() {
using namespace std; using namespace std;
using namespace scex;
if (reader == nullptr) { if (reader == nullptr) {
return; return;
} }
@ -187,38 +189,39 @@ void UartTestClass::scexPeriodic() {
ReturnValue_t result = reader->readReceivedMessage(uartCookie, &decodedPacket, &len); ReturnValue_t result = reader->readReceivedMessage(uartCookie, &decodedPacket, &len);
if (len > 0) { if (len > 0) {
sif::info << "CmdByte: " << std::setw(2) << std::setfill('0') << std::hex ScexHelper helper;
<< (int)decodedPacket[0] << std::dec << endl; const uint8_t* helperPtr = decodedPacket;
scex::ScexCmds cmd = static_cast<scex::ScexCmds>((decodedPacket[0] >> 1) & 0b11111); result = helper.deSerialize(&helperPtr, &len);
sif::info << "Command: 0x" << std::setw(2) << std::setfill('0') << std::hex if (result == ScexHelper::INVALID_CRC) {
<< static_cast<int>(cmd) << std::dec << std::endl; sif::warning << "CRC invalid" << std::endl;
size_t packetCounter = decodedPacket[1]; }
sif::info << "PacketCounter: " << packetCounter << endl; sif::info << helper << endl;
size_t totalPacketCounter = decodedPacket[2];
sif::info << "TotalPacketCount: " << totalPacketCounter << endl;
uint16_t packetLen = (decodedPacket[3] << 8) | (decodedPacket[4]);
sif::info << "PacketLength: " << packetLen << endl;
uint16_t expectedPacketLen = packetLen + 7;
sif::info << "ExpectedPacketLength: " << packetLen + 7 << endl; //ping
if (expectedPacketLen != len) { //if ping cmd
sif::warning << "ExpectedPacketLength " << expectedPacketLen << " is not Length" << len ofstream out("/tmp/scex-ping.bin", ofstream::binary );
<< endl; if (out.bad()) {
sif::warning << "bad" <<std::endl;
} }
if (CRC::crc16ccitt(decodedPacket, expectedPacketLen) != 0) { //fram
sif::warning << "CRC invalid" << endl; //packetcounter eins höher, wenn mehr packet verloren ->
} else { //countdown (max 2min), wenn nicht if (helper.getPacketCounter() == helper.getTotalPacketCounter()) { nach 2min reader->finish();
sif::info << "CRC valid" << endl; if(helper.getCmd() == FRAM) {
if(helper.getPacketCounter() == 0) {
// neues file anlegen wie oben ping
} else {
// an bestehendes file hinzufügen
}
} }
if (packetCounter == totalPacketCounter) { out << helper;
if (helper.getPacketCounter() == helper.getTotalPacketCounter()) {
reader->finish(); reader->finish();
sif::info << "Reader is finished" << endl; sif::info << "Reader is finished" << endl;
cmdDone = true; cmdDone = true;
// TODO: Bug in firmware, other command will be returned if (helper.getCmd() == scex::ScexCmds::PING) {
cmdSent = false; cmdSent = false;
// if (cmd == scex::ScexCmds::PING) { }
// cmdSent = false;
// }
} }
} }
} }

View File

@ -61,6 +61,7 @@ class UartTestClass : public TestTask {
std::array<uint8_t, 64> cmdBuf = {}; std::array<uint8_t, 64> cmdBuf = {};
std::array<uint8_t, 524> recBuf = {}; std::array<uint8_t, 524> recBuf = {};
ScexDleParser* dleParser; ScexDleParser* dleParser;
scex::ScexCmds cmdHelper;
uint8_t recvCnt = 0; uint8_t recvCnt = 0;
}; };

View File

@ -7,6 +7,7 @@ endif()
target_sources(${OBSW_NAME} PRIVATE target_sources(${OBSW_NAME} PRIVATE
ScexUartReader.cpp ScexUartReader.cpp
ScexDleParser.cpp ScexDleParser.cpp
ScexHelper.cpp
) )
add_subdirectory(ploc) add_subdirectory(ploc)
add_subdirectory(startracker) add_subdirectory(startracker)

View File

@ -0,0 +1,83 @@
#include "ScexHelper.h"
#include <fsfw/globalfunctions/CRC.h>
#include "fsfw/serviceinterface.h"
ScexHelper::ScexHelper() {}
ReturnValue_t ScexHelper::serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const {
return RETURN_FAILED;
}
size_t ScexHelper::getSerializedSize() const { return totalPacketLen; }
ReturnValue_t ScexHelper::deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) {
if (buffer == nullptr or size == nullptr) {
return RETURN_FAILED;
}
if (*size < 7) {
return STREAM_TOO_SHORT;
}
start = *buffer;
cmdByteRaw = **buffer;
cmd = static_cast<scex::ScexCmds>((cmdByteRaw >> 1) & 0b11111);
*buffer += 1;
packetCounter = **buffer;
*buffer += 1;
totalPacketCounter = **buffer;
*buffer += 1;
payloadLen = (**buffer << 8) | *(*buffer + 1);
*buffer += 2;
totalPacketLen = payloadLen + HEADER_LEN + CRC_LEN;
if (totalPacketLen >= *size) {
return STREAM_TOO_SHORT;
}
*buffer += payloadLen;
crc = (**buffer << 8) | *(*buffer + 1);
if (CRC::crc16ccitt(start, totalPacketLen) != 0) {
return INVALID_CRC;
}
return RETURN_OK;
}
scex::ScexCmds ScexHelper::getCmd() const { return cmd; }
uint8_t ScexHelper::getCmdByteRaw() const { return cmdByteRaw; }
uint16_t ScexHelper::getCrc() const { return crc; }
size_t ScexHelper::getExpectedPacketLen() const { return totalPacketLen; }
uint8_t ScexHelper::getPacketCounter() const { return packetCounter; }
uint16_t ScexHelper::getPayloadLen() const { return payloadLen; }
const uint8_t* ScexHelper::getStart() const { return start; }
uint8_t ScexHelper::getTotalPacketCounter() const { return totalPacketCounter; }
std::ostream& operator<<(std::ostream& os, const ScexHelper& h) {
using namespace std;
sif::info << "Command Byte Raw: 0x" << std::setw(2) << std::setfill('0') << std::hex
<< (int)h.cmdByteRaw << " | Command: 0x" << std::setw(2) << std::setfill('0')
<< std::hex << static_cast<int>(h.cmd) << std::dec << std::endl;
sif::info << "PacketCounter: " << h.packetCounter << endl;
sif::info << "TotalPacketCount: " << h.totalPacketCounter << endl;
sif::info << "PayloadLength: " << h.payloadLen << endl;
sif::info << "TotalPacketLength: " << h.totalPacketLen << endl;
return os;
}
std::ofstream& operator<<(std::ofstream& of, const ScexHelper& h) {
of.write(reinterpret_cast<const char*>(h.start), h.getSerializedSize());
return of;
}

View File

@ -0,0 +1,48 @@
#ifndef LINUX_DEVICES_SCEXHELPER_H_
#define LINUX_DEVICES_SCEXHELPER_H_
#include <fsfw/serialize/SerializeIF.h>
#include <mission/devices/devicedefinitions/ScexDefinitions.h>
#include <cstddef>
#include <cstdint>
#include <fstream>
#include <iostream>
// ScexHelper helper;
// helper.deSerialize(data, ...);
// sif::info << helper << std::endl;
class ScexHelper : public HasReturnvaluesIF, public SerializeIF {
public:
static const ReturnValue_t INVALID_CRC = HasReturnvaluesIF::makeReturnCode(0, 2);
static constexpr uint8_t HEADER_LEN = 5;
static constexpr uint8_t CRC_LEN = 2;
ScexHelper();
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override;
size_t getSerializedSize() const override;
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness = Endianness::BIG) override;
friend std::ostream &operator<<(std::ostream &os, const ScexHelper &h);
friend std::ofstream &operator<<(std::ofstream &os, const ScexHelper &h);
scex::ScexCmds getCmd() const;
uint8_t getCmdByteRaw() const;
uint16_t getCrc() const;
size_t getExpectedPacketLen() const;
uint8_t getPacketCounter() const;
uint16_t getPayloadLen() const;
const uint8_t *getStart() const;
uint8_t getTotalPacketCounter() const;
private:
const uint8_t *start = nullptr;
uint16_t crc = 0;
uint8_t cmdByteRaw = 0;
scex::ScexCmds cmd = scex::ScexCmds::INVALID;
int packetCounter = 0;
int totalPacketCounter = 0;
uint16_t payloadLen = 0;
size_t totalPacketLen = 0;
};
#endif /* LINUX_DEVICES_SCEXHELPER_H_ */

View File

@ -6,7 +6,7 @@
// Definitions for the Solar Cell Experiment // Definitions for the Solar Cell Experiment
namespace scex { namespace scex {
enum ScexCmds : uint8_t { PING = 0b00111, ONE_CELL = 0b00110, FRAM = 0b00001 }; enum ScexCmds : uint8_t { PING = 0b00111, ONE_CELL = 0b00110, FRAM = 0b00001, INVALID = 255 };
static constexpr uint8_t IDLE_BIT_0_DEF_STATE = 0; static constexpr uint8_t IDLE_BIT_0_DEF_STATE = 0;
static constexpr uint8_t IDLE_BIT_1_DEF_STATE = 1; static constexpr uint8_t IDLE_BIT_1_DEF_STATE = 1;