v1.14.0 #304
2
fsfw
2
fsfw
@ -1 +1 @@
|
||||
Subproject commit 5ff88129b8158a3a66366968231a68d01564f8fe
|
||||
Subproject commit e0c9bf587151094a54568117aa7159607b8bac2e
|
@ -21,14 +21,17 @@
|
||||
#endif
|
||||
|
||||
UartTestClass::UartTestClass(object_id_t objectId, ScexUartReader* reader)
|
||||
: TestTask(objectId), reader(reader), decodeRingBuf(4096, true) {
|
||||
: TestTask(objectId), reader(reader) {
|
||||
mode = TestModes::SCEX;
|
||||
scexMode = ScexModes::SIMPLE;
|
||||
scexMode = ScexModes::READER_TASK;
|
||||
currCmd = scex::ScexCmds::FRAM;
|
||||
if (mode == TestModes::SCEX) {
|
||||
if (scexMode == ScexModes::SIMPLE) {
|
||||
auto encodingBuf = new std::array<uint8_t, 4096>;
|
||||
DleParser::BufPair encodingBufPair {encodingBuf->data(), encodingBuf->size()};
|
||||
auto decodedBuf = new std::array<uint8_t, 4096>;
|
||||
DleParser::BufPair decodingBufPair {decodedBuf->data(), decodedBuf->size()};
|
||||
dleParser =
|
||||
new ScexDleParser(decodeRingBuf, dleEncoder, {encodedBuf.data(), encodedBuf.size()},
|
||||
{decodedBuf.data(), decodedBuf.size()}, &foundDlePacketHandler, this);
|
||||
new ScexDleParser(*(new SimpleRingBuffer(4096, true)), dleEncoder, encodingBufPair, decodingBufPair, &foundDlePacketHandler, this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,6 +166,7 @@ void UartTestClass::scexInit() {
|
||||
}
|
||||
|
||||
void UartTestClass::scexPeriodic() {
|
||||
using namespace std;
|
||||
if (reader == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -170,10 +174,53 @@ void UartTestClass::scexPeriodic() {
|
||||
if (scexMode == ScexModes::SIMPLE) {
|
||||
scexSimplePeriodic();
|
||||
} else {
|
||||
if (not cmdSent){
|
||||
size_t len = 0;
|
||||
prepareScexCmd(scex::ScexCmds::PING, false, cmdBuf.data(), &len);
|
||||
reader->sendMessage(uartCookie, cmdBuf.data(), len);
|
||||
cmdSent = true;
|
||||
cmdDone = false;
|
||||
}
|
||||
if (cmdSent and not cmdDone){
|
||||
uint8_t* decodedPacket = nullptr;
|
||||
size_t len = 0;
|
||||
ReturnValue_t result = reader->readReceivedMessage(uartCookie, &decodedPacket, &len);
|
||||
|
||||
if(len > 0){
|
||||
sif::info<<"CmdByte: "<<(int)decodedPacket[0]<<endl;
|
||||
scex::ScexCmds cmd = static_cast<scex::ScexCmds>((decodedPacket[0] >> 1) & 0b11111);
|
||||
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;
|
||||
|
||||
sif::info<<"ExpectedPacketLength: "<< packetLen+7 <<endl;
|
||||
if(expectedPacketLen != len){
|
||||
sif::warning<<"ExpectedPacketLength " << expectedPacketLen <<" is not Length"<< len<<endl;
|
||||
|
||||
}
|
||||
if(CRC::crc16ccitt(decodedPacket, expectedPacketLen) != 0){
|
||||
sif::warning<<"CRC invalid"<<endl;
|
||||
}else{
|
||||
sif::info<<"CRC valid"<<endl;
|
||||
}
|
||||
if(packetCounter == totalPacketCounter){
|
||||
reader->finish();
|
||||
sif::info<<"Reader is finished" << endl;
|
||||
cmdDone = true;
|
||||
if(cmd == scex::ScexCmds::PING){
|
||||
cmdSent = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UartTestClass::scexSimpleInit() {
|
||||
|
@ -58,11 +58,8 @@ class UartTestClass : public TestTask {
|
||||
int serialPort = 0;
|
||||
bool startFound = false;
|
||||
ScexUartReader* reader = nullptr;
|
||||
SimpleRingBuffer decodeRingBuf;
|
||||
std::array<uint8_t, 64> cmdBuf = {};
|
||||
std::array<uint8_t, 524> recBuf = {};
|
||||
std::array<uint8_t, 4096> encodedBuf = {};
|
||||
std::array<uint8_t, 4096> decodedBuf = {};
|
||||
ScexDleParser* dleParser;
|
||||
uint8_t recvCnt = 0;
|
||||
};
|
||||
|
@ -26,16 +26,15 @@ ScexUartReader::ScexUartReader(object_id_t objectId)
|
||||
lock = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
// void ScexUartRead::start() { /* semaphore->give(); */ }
|
||||
ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
|
||||
lock->lockMutex();
|
||||
state = States::IDLE;
|
||||
lock->unlockMutex();
|
||||
while (true) {
|
||||
semaphore->acquire();
|
||||
std::cout << "task was started" << std::endl;
|
||||
sif::info << "task was started" << std::endl;
|
||||
int bytesRead = 0;
|
||||
do {
|
||||
while(true) {
|
||||
bytesRead = read(serialPort, reinterpret_cast<void *>(recBuf.data()),
|
||||
static_cast<unsigned int>(recBuf.size()));
|
||||
if (bytesRead == 0) {
|
||||
@ -52,21 +51,17 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
|
||||
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
|
||||
sif::error << "ScexUartReader::performOperation: Receive buffer too small" << std::endl;
|
||||
} else if (bytesRead > 0) {
|
||||
MutexGuard mg(lock);
|
||||
ipcQueue.insert(bytesRead);
|
||||
ReturnValue_t result = dleParser.passData(recBuf.data(), bytesRead);
|
||||
if (debugMode) {
|
||||
sif::info << "Received " << bytesRead
|
||||
<< " bytes from the Solar Cell Experiment:" << std::endl;
|
||||
}
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "ScexUartReader::performOperation: Passing data to DLE parser failed"
|
||||
<< std::endl;
|
||||
}
|
||||
if (debugMode) {
|
||||
sif::info << "Received " << bytesRead
|
||||
<< " bytes from the Solar Cell Experiment:" << std::endl;
|
||||
arrayprinter::print(recBuf.data(), bytesRead, OutputType::HEX, false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} while (bytesRead > 0);
|
||||
};
|
||||
// task block comes here
|
||||
std::cout << "done" << std::endl;
|
||||
}
|
||||
@ -75,10 +70,11 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
|
||||
|
||||
ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
|
||||
UartCookie *uartCookie = dynamic_cast<UartCookie *>(cookie);
|
||||
if (uartCookie) {
|
||||
if (uartCookie == nullptr) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
std::string devname = uartCookie->getDeviceFile();
|
||||
sif::info << devname << std::endl;
|
||||
/* Get file descriptor */
|
||||
serialPort = open(devname.c_str(), O_RDWR);
|
||||
if (serialPort < 0) {
|
||||
@ -98,8 +94,8 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
|
||||
tty.c_lflag &= ~(ICANON | ECHO);
|
||||
|
||||
// Non-blocking mode, use polling
|
||||
tty.c_cc[VTIME] = 0; // Read for up to 2 seconds
|
||||
tty.c_cc[VMIN] = 0; // Read as much as there is available
|
||||
tty.c_cc[VTIME] = 10; // Read for up to 1 seconds
|
||||
tty.c_cc[VMIN] = 255; // Read as much as there is available
|
||||
|
||||
// Q7S UART Lite has fixed baud rate. For other linux systems, set baud rate here.
|
||||
#if !defined(XIPHOS_Q7S)
|
||||
@ -174,11 +170,21 @@ void ScexUartReader::foundDlePacketHandler(const DleParser::Context &ctx) {
|
||||
void ScexUartReader::handleFoundDlePacket(uint8_t *packet, size_t len) {
|
||||
// TODO: insert data into IPC ring buffer here
|
||||
sif::info << "Detected DLE encoded packet with decoded size " << len << std::endl;
|
||||
//MutexGuard mg(lock);
|
||||
ReturnValue_t result = ipcQueue.insert(len);
|
||||
if(result != RETURN_OK){
|
||||
sif::warning<< "IPCQueue error" << std::endl;
|
||||
}
|
||||
result = ipcRingBuf.writeData(packet, len);
|
||||
if(result != RETURN_OK){
|
||||
sif::warning<< "IPCRingBuf error" << std::endl;
|
||||
}
|
||||
sif::info << "DLE handler done" << std::endl;
|
||||
}
|
||||
|
||||
ReturnValue_t ScexUartReader::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
||||
size_t *size) {
|
||||
MutexGuard mg(lock);
|
||||
//MutexGuard mg(lock);
|
||||
if (ipcQueue.empty()) {
|
||||
*size = 0;
|
||||
return RETURN_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user