This commit is contained in:
parent
1d9fb354f7
commit
578899b5a5
@ -5,6 +5,7 @@
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
#include <fsfw_hal/linux/uart/UartCookie.h>
|
||||
#include <linux/devices/ScexDleParser.h>
|
||||
#include <linux/devices/ScexHelper.h>
|
||||
#include <linux/devices/ScexUartReader.h>
|
||||
#include <unistd.h> // write(), read(), close()
|
||||
|
||||
@ -167,6 +168,7 @@ void UartTestClass::scexInit() {
|
||||
|
||||
void UartTestClass::scexPeriodic() {
|
||||
using namespace std;
|
||||
using namespace scex;
|
||||
if (reader == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -187,38 +189,39 @@ void UartTestClass::scexPeriodic() {
|
||||
ReturnValue_t result = reader->readReceivedMessage(uartCookie, &decodedPacket, &len);
|
||||
|
||||
if (len > 0) {
|
||||
sif::info << "CmdByte: " << std::setw(2) << std::setfill('0') << std::hex
|
||||
<< (int)decodedPacket[0] << std::dec << endl;
|
||||
scex::ScexCmds cmd = static_cast<scex::ScexCmds>((decodedPacket[0] >> 1) & 0b11111);
|
||||
sif::info << "Command: 0x" << std::setw(2) << std::setfill('0') << std::hex
|
||||
<< static_cast<int>(cmd) << std::dec << std::endl;
|
||||
size_t packetCounter = decodedPacket[1];
|
||||
sif::info << "PacketCounter: " << packetCounter << 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;
|
||||
ScexHelper helper;
|
||||
const uint8_t* helperPtr = decodedPacket;
|
||||
result = helper.deSerialize(&helperPtr, &len);
|
||||
if (result == ScexHelper::INVALID_CRC) {
|
||||
sif::warning << "CRC invalid" << std::endl;
|
||||
}
|
||||
sif::info << helper << endl;
|
||||
|
||||
sif::info << "ExpectedPacketLength: " << packetLen + 7 << endl;
|
||||
if (expectedPacketLen != len) {
|
||||
sif::warning << "ExpectedPacketLength " << expectedPacketLen << " is not Length" << len
|
||||
<< endl;
|
||||
//ping
|
||||
//if ping cmd
|
||||
ofstream out("/tmp/scex-ping.bin", ofstream::binary );
|
||||
if (out.bad()) {
|
||||
sif::warning << "bad" <<std::endl;
|
||||
}
|
||||
if (CRC::crc16ccitt(decodedPacket, expectedPacketLen) != 0) {
|
||||
sif::warning << "CRC invalid" << endl;
|
||||
} else {
|
||||
sif::info << "CRC valid" << endl;
|
||||
//fram
|
||||
//packetcounter eins höher, wenn mehr packet verloren ->
|
||||
//countdown (max 2min), wenn nicht if (helper.getPacketCounter() == helper.getTotalPacketCounter()) { nach 2min reader->finish();
|
||||
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();
|
||||
sif::info << "Reader is finished" << endl;
|
||||
cmdDone = true;
|
||||
// TODO: Bug in firmware, other command will be returned
|
||||
cmdSent = false;
|
||||
// if (cmd == scex::ScexCmds::PING) {
|
||||
// cmdSent = false;
|
||||
// }
|
||||
if (helper.getCmd() == scex::ScexCmds::PING) {
|
||||
cmdSent = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ class UartTestClass : public TestTask {
|
||||
std::array<uint8_t, 64> cmdBuf = {};
|
||||
std::array<uint8_t, 524> recBuf = {};
|
||||
ScexDleParser* dleParser;
|
||||
scex::ScexCmds cmdHelper;
|
||||
uint8_t recvCnt = 0;
|
||||
};
|
||||
|
||||
|
@ -7,6 +7,7 @@ endif()
|
||||
target_sources(${OBSW_NAME} PRIVATE
|
||||
ScexUartReader.cpp
|
||||
ScexDleParser.cpp
|
||||
ScexHelper.cpp
|
||||
)
|
||||
add_subdirectory(ploc)
|
||||
add_subdirectory(startracker)
|
||||
|
83
linux/devices/ScexHelper.cpp
Normal file
83
linux/devices/ScexHelper.cpp
Normal 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;
|
||||
}
|
48
linux/devices/ScexHelper.h
Normal file
48
linux/devices/ScexHelper.h
Normal 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_ */
|
@ -6,7 +6,7 @@
|
||||
// Definitions for the Solar Cell Experiment
|
||||
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_1_DEF_STATE = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user