v1.14.0 #304
2
fsfw
2
fsfw
@ -1 +1 @@
|
|||||||
Subproject commit 5ff88129b8158a3a66366968231a68d01564f8fe
|
Subproject commit e0c9bf587151094a54568117aa7159607b8bac2e
|
@ -21,284 +21,331 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
UartTestClass::UartTestClass(object_id_t objectId, ScexUartReader* reader)
|
UartTestClass::UartTestClass(object_id_t objectId, ScexUartReader* reader)
|
||||||
: TestTask(objectId), reader(reader), decodeRingBuf(4096, true) {
|
: TestTask(objectId), reader(reader) {
|
||||||
mode = TestModes::SCEX;
|
mode = TestModes::SCEX;
|
||||||
scexMode = ScexModes::SIMPLE;
|
scexMode = ScexModes::READER_TASK;
|
||||||
currCmd = scex::ScexCmds::FRAM;
|
currCmd = scex::ScexCmds::FRAM;
|
||||||
if (mode == TestModes::SCEX) {
|
if (scexMode == ScexModes::SIMPLE) {
|
||||||
dleParser =
|
auto encodingBuf = new std::array<uint8_t, 4096>;
|
||||||
new ScexDleParser(decodeRingBuf, dleEncoder, {encodedBuf.data(), encodedBuf.size()},
|
DleParser::BufPair encodingBufPair {encodingBuf->data(), encodingBuf->size()};
|
||||||
{decodedBuf.data(), decodedBuf.size()}, &foundDlePacketHandler, this);
|
auto decodedBuf = new std::array<uint8_t, 4096>;
|
||||||
}
|
DleParser::BufPair decodingBufPair {decodedBuf->data(), decodedBuf->size()};
|
||||||
|
dleParser =
|
||||||
|
new ScexDleParser(*(new SimpleRingBuffer(4096, true)), dleEncoder, encodingBufPair, decodingBufPair, &foundDlePacketHandler, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartTestClass::initialize() {
|
ReturnValue_t UartTestClass::initialize() {
|
||||||
if (mode == TestModes::GPS) {
|
if (mode == TestModes::GPS) {
|
||||||
gpsInit();
|
gpsInit();
|
||||||
} else if (mode == TestModes::SCEX) {
|
} else if (mode == TestModes::SCEX) {
|
||||||
scexInit();
|
scexInit();
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartTestClass::performOneShotAction() { return HasReturnvaluesIF::RETURN_OK; }
|
ReturnValue_t UartTestClass::performOneShotAction() { return HasReturnvaluesIF::RETURN_OK; }
|
||||||
|
|
||||||
ReturnValue_t UartTestClass::performPeriodicAction() {
|
ReturnValue_t UartTestClass::performPeriodicAction() {
|
||||||
if (mode == TestModes::GPS) {
|
if (mode == TestModes::GPS) {
|
||||||
gpsPeriodic();
|
gpsPeriodic();
|
||||||
} else if (mode == TestModes::SCEX) {
|
} else if (mode == TestModes::SCEX) {
|
||||||
scexPeriodic();
|
scexPeriodic();
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UartTestClass::gpsInit() {
|
void UartTestClass::gpsInit() {
|
||||||
#if RPI_TEST_GPS_HANDLER == 1
|
#if RPI_TEST_GPS_HANDLER == 1
|
||||||
int result = lwgps_init(&gpsData);
|
int result = lwgps_init(&gpsData);
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
sif::warning << "lwgps_init error: " << result << std::endl;
|
sif::warning << "lwgps_init error: " << result << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get file descriptor */
|
/* Get file descriptor */
|
||||||
serialPort = open("/dev/serial0", O_RDWR);
|
serialPort = open("/dev/serial0", O_RDWR);
|
||||||
if (serialPort < 0) {
|
if (serialPort < 0) {
|
||||||
sif::warning << "open call failed with error [" << errno << ", " << strerror(errno)
|
sif::warning << "open call failed with error [" << errno << ", " << strerror(errno)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
/* Setting up UART parameters */
|
/* Setting up UART parameters */
|
||||||
tty.c_cflag &= ~PARENB; // Clear parity bit
|
tty.c_cflag &= ~PARENB; // Clear parity bit
|
||||||
tty.c_cflag &= ~CSTOPB; // Clear stop field, only one stop bit used in communication
|
tty.c_cflag &= ~CSTOPB; // Clear stop field, only one stop bit used in communication
|
||||||
tty.c_cflag &= ~CSIZE; // Clear all the size bits
|
tty.c_cflag &= ~CSIZE; // Clear all the size bits
|
||||||
tty.c_cflag |= CS8; // 8 bits per byte
|
tty.c_cflag |= CS8; // 8 bits per byte
|
||||||
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control
|
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control
|
||||||
tty.c_cflag |= CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1)
|
tty.c_cflag |= CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1)
|
||||||
// Use canonical mode for GPS device
|
// Use canonical mode for GPS device
|
||||||
tty.c_lflag |= ICANON;
|
tty.c_lflag |= ICANON;
|
||||||
tty.c_lflag &= ~ECHO; // Disable echo
|
tty.c_lflag &= ~ECHO; // Disable echo
|
||||||
tty.c_lflag &= ~ECHOE; // Disable erasure
|
tty.c_lflag &= ~ECHOE; // Disable erasure
|
||||||
tty.c_lflag &= ~ECHONL; // Disable new-line echo
|
tty.c_lflag &= ~ECHONL; // Disable new-line echo
|
||||||
tty.c_lflag &= ~ISIG; // Disable interpretation of INTR, QUIT and SUSP
|
tty.c_lflag &= ~ISIG; // Disable interpretation of INTR, QUIT and SUSP
|
||||||
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl
|
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl
|
||||||
tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR |
|
tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR |
|
||||||
ICRNL); // Disable any special handling of received bytes
|
ICRNL); // Disable any special handling of received bytes
|
||||||
tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars)
|
tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars)
|
||||||
tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed
|
tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed
|
||||||
|
|
||||||
// Non-blocking mode
|
// Non-blocking mode
|
||||||
tty.c_cc[VTIME] = 0;
|
tty.c_cc[VTIME] = 0;
|
||||||
tty.c_cc[VMIN] = 0;
|
tty.c_cc[VMIN] = 0;
|
||||||
|
|
||||||
cfsetispeed(&tty, B9600);
|
cfsetispeed(&tty, B9600);
|
||||||
cfsetospeed(&tty, B9600);
|
cfsetospeed(&tty, B9600);
|
||||||
if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
|
if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
|
||||||
sif::warning << "tcsetattr call failed with error [" << errno << ", " << strerror(errno)
|
sif::warning << "tcsetattr call failed with error [" << errno << ", " << strerror(errno)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
// Flush received and unread data. Those are old NMEA strings which are not relevant anymore
|
// Flush received and unread data. Those are old NMEA strings which are not relevant anymore
|
||||||
tcflush(serialPort, TCIFLUSH);
|
tcflush(serialPort, TCIFLUSH);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void UartTestClass::gpsPeriodic() {
|
void UartTestClass::gpsPeriodic() {
|
||||||
#if RPI_TEST_GPS_HANDLER == 1
|
#if RPI_TEST_GPS_HANDLER == 1
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
do {
|
do {
|
||||||
bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()),
|
bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()),
|
||||||
static_cast<unsigned int>(recBuf.size()));
|
static_cast<unsigned int>(recBuf.size()));
|
||||||
if (bytesRead < 0) {
|
if (bytesRead < 0) {
|
||||||
sif::warning << "UartTestClass::performPeriodicAction: read call failed with error [" << errno
|
sif::warning << "UartTestClass::performPeriodicAction: read call failed with error [" << errno
|
||||||
<< ", " << strerror(errno) << "]" << std::endl;
|
<< ", " << strerror(errno) << "]" << std::endl;
|
||||||
break;
|
break;
|
||||||
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
|
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
|
||||||
sif::debug << "UartTestClass::performPeriodicAction: "
|
sif::debug << "UartTestClass::performPeriodicAction: "
|
||||||
"recv buffer might not be large enough"
|
"recv buffer might not be large enough"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
} else if (bytesRead > 0) {
|
} else if (bytesRead > 0) {
|
||||||
// pass data to lwgps for processing
|
// pass data to lwgps for processing
|
||||||
#if GPS_REPLY_WIRETAPPING == 1
|
#if GPS_REPLY_WIRETAPPING == 1
|
||||||
sif::info << recBuf.data() << std::endl;
|
sif::info << recBuf.data() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
int result = lwgps_process(&gpsData, recBuf.data(), bytesRead);
|
int result = lwgps_process(&gpsData, recBuf.data(), bytesRead);
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
sif::warning << "UartTestClass::performPeriodicAction: lwgps_process error" << std::endl;
|
sif::warning << "UartTestClass::performPeriodicAction: lwgps_process error" << std::endl;
|
||||||
}
|
}
|
||||||
recvCnt++;
|
recvCnt++;
|
||||||
if (recvCnt == 6) {
|
if (recvCnt == 6) {
|
||||||
recvCnt = 0;
|
recvCnt = 0;
|
||||||
sif::info << "GPS Data" << std::endl;
|
sif::info << "GPS Data" << std::endl;
|
||||||
// Print messages
|
// Print messages
|
||||||
printf("Valid status: %d\n", gpsData.is_valid);
|
printf("Valid status: %d\n", gpsData.is_valid);
|
||||||
printf("Latitude: %f degrees\n", gpsData.latitude);
|
printf("Latitude: %f degrees\n", gpsData.latitude);
|
||||||
printf("Longitude: %f degrees\n", gpsData.longitude);
|
printf("Longitude: %f degrees\n", gpsData.longitude);
|
||||||
printf("Altitude: %f meters\n", gpsData.altitude);
|
printf("Altitude: %f meters\n", gpsData.altitude);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (bytesRead > 0);
|
} while (bytesRead > 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void UartTestClass::scexInit() {
|
void UartTestClass::scexInit() {
|
||||||
if (reader == nullptr) {
|
if (reader == nullptr) {
|
||||||
sif::warning << "UartTestClass::scexInit: Reader invalid" << std::endl;
|
sif::warning << "UartTestClass::scexInit: Reader invalid" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (scexMode == ScexModes::SIMPLE) {
|
if (scexMode == ScexModes::SIMPLE) {
|
||||||
scexSimpleInit();
|
scexSimpleInit();
|
||||||
} else {
|
} else {
|
||||||
#if defined(RASPBERRY_PI)
|
#if defined(RASPBERRY_PI)
|
||||||
std::string devname = "/dev/serial0";
|
std::string devname = "/dev/serial0";
|
||||||
#else
|
#else
|
||||||
std::string devname = "/dev/ul-scex";
|
std::string devname = "/dev/ul-scex";
|
||||||
#endif
|
#endif
|
||||||
uartCookie = new UartCookie(this->getObjectId(), devname, UartBaudRate::RATE_57600, 4096);
|
uartCookie = new UartCookie(this->getObjectId(), devname, UartBaudRate::RATE_57600, 4096);
|
||||||
reader->setDebugMode(true);
|
reader->setDebugMode(true);
|
||||||
ReturnValue_t result = reader->initializeInterface(uartCookie);
|
ReturnValue_t result = reader->initializeInterface(uartCookie);
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
sif::warning << "UartTestClass::gpsPeriodic: Initializing SCEX reader "
|
sif::warning << "UartTestClass::gpsPeriodic: Initializing SCEX reader "
|
||||||
"UART IF failed"
|
"UART IF failed"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UartTestClass::scexPeriodic() {
|
void UartTestClass::scexPeriodic() {
|
||||||
if (reader == nullptr) {
|
using namespace std;
|
||||||
return;
|
if (reader == nullptr) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (scexMode == ScexModes::SIMPLE) {
|
|
||||||
scexSimplePeriodic();
|
|
||||||
} else {
|
|
||||||
size_t len = 0;
|
|
||||||
prepareScexCmd(scex::ScexCmds::PING, false, cmdBuf.data(), &len);
|
|
||||||
reader->sendMessage(uartCookie, cmdBuf.data(), len);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UartTestClass::scexSimpleInit() {
|
void UartTestClass::scexSimpleInit() {
|
||||||
#if defined(RASPBERRY_PI)
|
#if defined(RASPBERRY_PI)
|
||||||
std::string devname = "/dev/serial0";
|
std::string devname = "/dev/serial0";
|
||||||
#else
|
#else
|
||||||
std::string devname = "/dev/ul-scex";
|
std::string devname = "/dev/ul-scex";
|
||||||
#endif
|
#endif
|
||||||
/* Get file descriptor */
|
/* Get file descriptor */
|
||||||
serialPort = open(devname.c_str(), O_RDWR);
|
serialPort = open(devname.c_str(), O_RDWR);
|
||||||
if (serialPort < 0) {
|
if (serialPort < 0) {
|
||||||
sif::warning << "open call failed with error [" << errno << ", " << strerror(errno)
|
sif::warning << "open call failed with error [" << errno << ", " << strerror(errno)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Setting up UART parameters
|
// Setting up UART parameters
|
||||||
tty.c_cflag &= ~PARENB; // Clear parity bit
|
tty.c_cflag &= ~PARENB; // Clear parity bit
|
||||||
tty.c_cflag &= ~CSTOPB; // Clear stop field, only one stop bit used in communication
|
tty.c_cflag &= ~CSTOPB; // Clear stop field, only one stop bit used in communication
|
||||||
tty.c_cflag &= ~CSIZE; // Clear all the size bits
|
tty.c_cflag &= ~CSIZE; // Clear all the size bits
|
||||||
tty.c_cflag |= CS8; // 8 bits per byte
|
tty.c_cflag |= CS8; // 8 bits per byte
|
||||||
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control
|
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control
|
||||||
tty.c_cflag |= CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1)
|
tty.c_cflag |= CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1)
|
||||||
|
|
||||||
// Use non-canonical mode and clear echo flag
|
// Use non-canonical mode and clear echo flag
|
||||||
tty.c_lflag &= ~(ICANON | ECHO);
|
tty.c_lflag &= ~(ICANON | ECHO);
|
||||||
|
|
||||||
// Non-blocking mode, read until either line is 0.1 second idle or maximum of 255 bytes are
|
// Non-blocking mode, read until either line is 0.1 second idle or maximum of 255 bytes are
|
||||||
// received in one go
|
// received in one go
|
||||||
tty.c_cc[VTIME] = 10; // In units of 0.1 seconds
|
tty.c_cc[VTIME] = 10; // In units of 0.1 seconds
|
||||||
tty.c_cc[VMIN] = 255; // Read up to 255 bytes
|
tty.c_cc[VMIN] = 255; // Read up to 255 bytes
|
||||||
|
|
||||||
// Q7S UART Lite has fixed baud rate. For other linux systems, set baud rate here.
|
// Q7S UART Lite has fixed baud rate. For other linux systems, set baud rate here.
|
||||||
#if !defined(XIPHOS_Q7S)
|
#if !defined(XIPHOS_Q7S)
|
||||||
if (cfsetispeed(&tty, B57600) != 0) {
|
if (cfsetispeed(&tty, B57600) != 0) {
|
||||||
sif::warning << "UartTestClass::scexInit: Setting baud rate failed" << std::endl;
|
sif::warning << "UartTestClass::scexInit: Setting baud rate failed" << std::endl;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
|
if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
|
||||||
sif::warning << "tcsetattr call failed with error [" << errno << ", " << strerror(errno)
|
sif::warning << "tcsetattr call failed with error [" << errno << ", " << strerror(errno)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
// Flush received and unread data
|
// Flush received and unread data
|
||||||
tcflush(serialPort, TCIOFLUSH);
|
tcflush(serialPort, TCIOFLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UartTestClass::scexSimplePeriodic() {
|
void UartTestClass::scexSimplePeriodic() {
|
||||||
using namespace scex;
|
using namespace scex;
|
||||||
ReturnValue_t result = RETURN_OK;
|
ReturnValue_t result = RETURN_OK;
|
||||||
if (not cmdSent) {
|
if (not cmdSent) {
|
||||||
// Flush received and unread data
|
// Flush received and unread data
|
||||||
tcflush(serialPort, TCIFLUSH);
|
tcflush(serialPort, TCIFLUSH);
|
||||||
uint8_t tmpCmdBuf[32] = {};
|
uint8_t tmpCmdBuf[32] = {};
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
sif::info << "UartTestClass::scexSimplePeriodic: Sending command to SCEX" << std::endl;
|
sif::info << "UartTestClass::scexSimplePeriodic: Sending command to SCEX" << std::endl;
|
||||||
prepareScexCmd(currCmd, false, tmpCmdBuf, &len);
|
prepareScexCmd(currCmd, false, tmpCmdBuf, &len);
|
||||||
result = dleEncoder.encode(tmpCmdBuf, len, cmdBuf.data(), cmdBuf.size(), &encodedLen, true);
|
result = dleEncoder.encode(tmpCmdBuf, len, cmdBuf.data(), cmdBuf.size(), &encodedLen, true);
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
sif::warning << "UartTestClass::scexInit: Encoding failed" << std::endl;
|
sif::warning << "UartTestClass::scexInit: Encoding failed" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
size_t bytesWritten = write(serialPort, cmdBuf.data(), encodedLen);
|
size_t bytesWritten = write(serialPort, cmdBuf.data(), encodedLen);
|
||||||
if (bytesWritten != encodedLen) {
|
if (bytesWritten != encodedLen) {
|
||||||
sif::warning << "Sending command to solar experiment failed" << std::endl;
|
sif::warning << "Sending command to solar experiment failed" << std::endl;
|
||||||
}
|
}
|
||||||
cmdSent = true;
|
cmdSent = true;
|
||||||
cmdDone = false;
|
cmdDone = false;
|
||||||
}
|
}
|
||||||
if (not cmdDone) {
|
if (not cmdDone) {
|
||||||
// Read back reply immediately
|
// Read back reply immediately
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
do {
|
do {
|
||||||
bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()),
|
bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()),
|
||||||
static_cast<unsigned int>(recBuf.size()));
|
static_cast<unsigned int>(recBuf.size()));
|
||||||
if (bytesRead == 0) {
|
if (bytesRead == 0) {
|
||||||
sif::warning << "Reading SCEX: Timeout or no bytes read" << std::endl;
|
sif::warning << "Reading SCEX: Timeout or no bytes read" << std::endl;
|
||||||
} else if (bytesRead < 0) {
|
} else if (bytesRead < 0) {
|
||||||
sif::warning << "UartTestClass::performPeriodicAction: read call failed with error ["
|
sif::warning << "UartTestClass::performPeriodicAction: read call failed with error ["
|
||||||
<< errno << ", " << strerror(errno) << "]" << std::endl;
|
<< errno << ", " << strerror(errno) << "]" << std::endl;
|
||||||
break;
|
break;
|
||||||
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
|
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
|
||||||
sif::debug << "UartTestClass::performPeriodicAction: recv buffer might not be large enough"
|
sif::debug << "UartTestClass::performPeriodicAction: recv buffer might not be large enough"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
} else if (bytesRead > 0) {
|
} else if (bytesRead > 0) {
|
||||||
dleParser->passData(recBuf.data(), bytesRead);
|
dleParser->passData(recBuf.data(), bytesRead);
|
||||||
if (currCmd == ScexCmds::PING) {
|
if (currCmd == ScexCmds::PING) {
|
||||||
cmdDone = true;
|
cmdDone = true;
|
||||||
cmdSent = false;
|
cmdSent = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (bytesRead > 0);
|
} while (bytesRead > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int UartTestClass::prepareScexCmd(scex::ScexCmds cmd, bool tempCheck, uint8_t* cmdBuf,
|
int UartTestClass::prepareScexCmd(scex::ScexCmds cmd, bool tempCheck, uint8_t* cmdBuf,
|
||||||
size_t* len) {
|
size_t* len) {
|
||||||
using namespace scex;
|
using namespace scex;
|
||||||
// Send ping command
|
// Send ping command
|
||||||
cmdBuf[0] = scex::createCmdByte(cmd, false);
|
cmdBuf[0] = scex::createCmdByte(cmd, false);
|
||||||
// These two fields are the packet counter and the total packet count. Those are 1 and 1 for each
|
// These two fields are the packet counter and the total packet count. Those are 1 and 1 for each
|
||||||
// telecommand so far
|
// telecommand so far
|
||||||
cmdBuf[1] = 1;
|
cmdBuf[1] = 1;
|
||||||
cmdBuf[2] = 1;
|
cmdBuf[2] = 1;
|
||||||
uint16_t userDataLen = 0;
|
uint16_t userDataLen = 0;
|
||||||
cmdBuf[3] = (userDataLen >> 8) & 0xff;
|
cmdBuf[3] = (userDataLen >> 8) & 0xff;
|
||||||
cmdBuf[4] = userDataLen & 0xff;
|
cmdBuf[4] = userDataLen & 0xff;
|
||||||
uint16_t crc = CRC::crc16ccitt(cmdBuf, 5);
|
uint16_t crc = CRC::crc16ccitt(cmdBuf, 5);
|
||||||
cmdBuf[5] = (crc >> 8) & 0xff;
|
cmdBuf[5] = (crc >> 8) & 0xff;
|
||||||
cmdBuf[6] = crc & 0xff;
|
cmdBuf[6] = crc & 0xff;
|
||||||
*len = 7;
|
*len = 7;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UartTestClass::foundDlePacketHandler(const DleParser::Context& ctx) {
|
void UartTestClass::foundDlePacketHandler(const DleParser::Context& ctx) {
|
||||||
UartTestClass* obj = reinterpret_cast<UartTestClass*>(ctx.userArgs);
|
UartTestClass* obj = reinterpret_cast<UartTestClass*>(ctx.userArgs);
|
||||||
if (ctx.getType() == DleParser::ContextType::PACKET_FOUND) {
|
if (ctx.getType() == DleParser::ContextType::PACKET_FOUND) {
|
||||||
obj->handleFoundDlePacket(ctx.decodedPacket.first, ctx.decodedPacket.second);
|
obj->handleFoundDlePacket(ctx.decodedPacket.first, ctx.decodedPacket.second);
|
||||||
} else {
|
} else {
|
||||||
DleParser::defaultErrorHandler(ctx.error.first, ctx.error.second);
|
DleParser::defaultErrorHandler(ctx.error.first, ctx.error.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UartTestClass::handleFoundDlePacket(uint8_t* packet, size_t len) {
|
void UartTestClass::handleFoundDlePacket(uint8_t* packet, size_t len) {
|
||||||
sif::info << "Detected DLE encoded packet with decoded size " << len << std::endl;
|
sif::info << "Detected DLE encoded packet with decoded size " << len << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -58,11 +58,8 @@ class UartTestClass : public TestTask {
|
|||||||
int serialPort = 0;
|
int serialPort = 0;
|
||||||
bool startFound = false;
|
bool startFound = false;
|
||||||
ScexUartReader* reader = nullptr;
|
ScexUartReader* reader = nullptr;
|
||||||
SimpleRingBuffer decodeRingBuf;
|
|
||||||
std::array<uint8_t, 64> cmdBuf = {};
|
std::array<uint8_t, 64> cmdBuf = {};
|
||||||
std::array<uint8_t, 524> recBuf = {};
|
std::array<uint8_t, 524> recBuf = {};
|
||||||
std::array<uint8_t, 4096> encodedBuf = {};
|
|
||||||
std::array<uint8_t, 4096> decodedBuf = {};
|
|
||||||
ScexDleParser* dleParser;
|
ScexDleParser* dleParser;
|
||||||
uint8_t recvCnt = 0;
|
uint8_t recvCnt = 0;
|
||||||
};
|
};
|
||||||
|
@ -26,16 +26,15 @@ ScexUartReader::ScexUartReader(object_id_t objectId)
|
|||||||
lock = MutexFactory::instance()->createMutex();
|
lock = MutexFactory::instance()->createMutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
// void ScexUartRead::start() { /* semaphore->give(); */ }
|
|
||||||
ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
|
ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
|
||||||
lock->lockMutex();
|
lock->lockMutex();
|
||||||
state = States::IDLE;
|
state = States::IDLE;
|
||||||
lock->unlockMutex();
|
lock->unlockMutex();
|
||||||
while (true) {
|
while (true) {
|
||||||
semaphore->acquire();
|
semaphore->acquire();
|
||||||
std::cout << "task was started" << std::endl;
|
sif::info << "task was started" << std::endl;
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
do {
|
while(true) {
|
||||||
bytesRead = read(serialPort, reinterpret_cast<void *>(recBuf.data()),
|
bytesRead = read(serialPort, reinterpret_cast<void *>(recBuf.data()),
|
||||||
static_cast<unsigned int>(recBuf.size()));
|
static_cast<unsigned int>(recBuf.size()));
|
||||||
if (bytesRead == 0) {
|
if (bytesRead == 0) {
|
||||||
@ -52,21 +51,17 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
|
|||||||
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
|
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
|
||||||
sif::error << "ScexUartReader::performOperation: Receive buffer too small" << std::endl;
|
sif::error << "ScexUartReader::performOperation: Receive buffer too small" << std::endl;
|
||||||
} else if (bytesRead > 0) {
|
} else if (bytesRead > 0) {
|
||||||
MutexGuard mg(lock);
|
|
||||||
ipcQueue.insert(bytesRead);
|
|
||||||
ReturnValue_t result = dleParser.passData(recBuf.data(), 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) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
sif::warning << "ScexUartReader::performOperation: Passing data to DLE parser failed"
|
sif::warning << "ScexUartReader::performOperation: Passing data to DLE parser failed"
|
||||||
<< std::endl;
|
<< 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
|
// task block comes here
|
||||||
std::cout << "done" << std::endl;
|
std::cout << "done" << std::endl;
|
||||||
}
|
}
|
||||||
@ -75,10 +70,11 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
|
|||||||
|
|
||||||
ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
|
ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
|
||||||
UartCookie *uartCookie = dynamic_cast<UartCookie *>(cookie);
|
UartCookie *uartCookie = dynamic_cast<UartCookie *>(cookie);
|
||||||
if (uartCookie) {
|
if (uartCookie == nullptr) {
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
std::string devname = uartCookie->getDeviceFile();
|
std::string devname = uartCookie->getDeviceFile();
|
||||||
|
sif::info << devname << std::endl;
|
||||||
/* Get file descriptor */
|
/* Get file descriptor */
|
||||||
serialPort = open(devname.c_str(), O_RDWR);
|
serialPort = open(devname.c_str(), O_RDWR);
|
||||||
if (serialPort < 0) {
|
if (serialPort < 0) {
|
||||||
@ -98,8 +94,8 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
|
|||||||
tty.c_lflag &= ~(ICANON | ECHO);
|
tty.c_lflag &= ~(ICANON | ECHO);
|
||||||
|
|
||||||
// Non-blocking mode, use polling
|
// Non-blocking mode, use polling
|
||||||
tty.c_cc[VTIME] = 0; // Read for up to 2 seconds
|
tty.c_cc[VTIME] = 10; // Read for up to 1 seconds
|
||||||
tty.c_cc[VMIN] = 0; // Read as much as there is available
|
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.
|
// Q7S UART Lite has fixed baud rate. For other linux systems, set baud rate here.
|
||||||
#if !defined(XIPHOS_Q7S)
|
#if !defined(XIPHOS_Q7S)
|
||||||
@ -174,11 +170,21 @@ void ScexUartReader::foundDlePacketHandler(const DleParser::Context &ctx) {
|
|||||||
void ScexUartReader::handleFoundDlePacket(uint8_t *packet, size_t len) {
|
void ScexUartReader::handleFoundDlePacket(uint8_t *packet, size_t len) {
|
||||||
// TODO: insert data into IPC ring buffer here
|
// TODO: insert data into IPC ring buffer here
|
||||||
sif::info << "Detected DLE encoded packet with decoded size " << len << std::endl;
|
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,
|
ReturnValue_t ScexUartReader::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
||||||
size_t *size) {
|
size_t *size) {
|
||||||
MutexGuard mg(lock);
|
//MutexGuard mg(lock);
|
||||||
if (ipcQueue.empty()) {
|
if (ipcQueue.empty()) {
|
||||||
*size = 0;
|
*size = 0;
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
|
Loading…
Reference in New Issue
Block a user