|
|
|
@ -23,7 +23,7 @@
|
|
|
|
|
UartTestClass::UartTestClass(object_id_t objectId, ScexUartReader* reader)
|
|
|
|
|
: TestTask(objectId), reader(reader) {
|
|
|
|
|
mode = TestModes::SCEX;
|
|
|
|
|
scexMode = ScexModes::READER_TASK;
|
|
|
|
|
scexMode = ScexModes::SIMPLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReturnValue_t UartTestClass::initialize() {
|
|
|
|
@ -138,6 +138,99 @@ void UartTestClass::scexInit() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (scexMode == ScexModes::SIMPLE) {
|
|
|
|
|
scexSimpleInit();
|
|
|
|
|
} else {
|
|
|
|
|
#if defined(RASPBERRY_PI)
|
|
|
|
|
std::string devname = "/dev/serial0";
|
|
|
|
|
#else
|
|
|
|
|
std::string devname = "/dev/ul-scex";
|
|
|
|
|
#endif
|
|
|
|
|
uartCookie =
|
|
|
|
|
new UartCookie(this->getObjectId(), devname, UartModes::NON_CANONICAL, 57600, 4096);
|
|
|
|
|
reader->setDebugMode(true);
|
|
|
|
|
ReturnValue_t result = reader->initializeInterface(uartCookie);
|
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
|
sif::warning << "UartTestClass::gpsPeriodic: Initializing SCEX reader "
|
|
|
|
|
"UART IF failed"
|
|
|
|
|
<< std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UartTestClass::scexPeriodic() {
|
|
|
|
|
if (reader == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scexMode == ScexModes::SIMPLE) {
|
|
|
|
|
scexSimplePeriodic();
|
|
|
|
|
} else {
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
prepareScexPing(cmdBuf.data(), &len);
|
|
|
|
|
reader->sendMessage(uartCookie, cmdBuf.data(), len);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int UartTestClass::prepareScexPing(uint8_t* cmdBuf, size_t* len) {
|
|
|
|
|
// Send ping command
|
|
|
|
|
cmdBuf[0] = scex::CMD_PING;
|
|
|
|
|
// These two fields are the packet counter and the total packet count. Those are 1 and 1 for each
|
|
|
|
|
// telecommand so far
|
|
|
|
|
cmdBuf[1] = 1;
|
|
|
|
|
cmdBuf[2] = 1;
|
|
|
|
|
uint16_t userDataLen = 0;
|
|
|
|
|
cmdBuf[3] = (userDataLen >> 8) & 0xff;
|
|
|
|
|
cmdBuf[4] = userDataLen & 0xff;
|
|
|
|
|
uint16_t crc = CRC::crc16ccitt(cmdBuf, 5);
|
|
|
|
|
cmdBuf[5] = (crc >> 8) & 0xff;
|
|
|
|
|
cmdBuf[6] = crc & 0xff;
|
|
|
|
|
*len = 7;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UartTestClass::scexSimplePeriodic() {
|
|
|
|
|
sif::info << "UartTestClass::scexInit: Sending ping command to SCEX" << std::endl;
|
|
|
|
|
uint8_t tmpCmdBuf[32] = {};
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
prepareScexPing(tmpCmdBuf, &len);
|
|
|
|
|
ReturnValue_t result =
|
|
|
|
|
dleEncoder.encode(tmpCmdBuf, len, cmdBuf.data(), cmdBuf.size(), &encodedLen, true);
|
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
|
sif::warning << "UartTestClass::scexInit: Encoding failed" << std::endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (result != 0) {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
size_t bytesWritten = write(serialPort, cmdBuf.data(), encodedLen);
|
|
|
|
|
if (bytesWritten != encodedLen) {
|
|
|
|
|
sif::warning << "Sending ping command to solar experiment failed" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read back reply immediately
|
|
|
|
|
int bytesRead = 0;
|
|
|
|
|
do {
|
|
|
|
|
bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()),
|
|
|
|
|
static_cast<unsigned int>(recBuf.size()));
|
|
|
|
|
if (bytesRead == 0) {
|
|
|
|
|
sif::warning << "Reading SCEX: Timeout occured after 0.5 seconds" << std::endl;
|
|
|
|
|
} else if (bytesRead < 0) {
|
|
|
|
|
sif::warning << "UartTestClass::performPeriodicAction: read call failed with error [" << errno
|
|
|
|
|
<< ", " << strerror(errno) << "]" << std::endl;
|
|
|
|
|
break;
|
|
|
|
|
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
|
|
|
|
|
sif::debug << "UartTestClass::performPeriodicAction: recv buffer might not be large enough"
|
|
|
|
|
<< std::endl;
|
|
|
|
|
} else if (bytesRead > 0) {
|
|
|
|
|
sif::info << "Received " << bytesRead
|
|
|
|
|
<< " bytes from the Solar Cell Experiment:" << std::endl;
|
|
|
|
|
arrayprinter::print(recBuf.data(), bytesRead, OutputType::HEX, false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} while (bytesRead > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UartTestClass::scexSimpleInit() {
|
|
|
|
|
#if defined(RASPBERRY_PI)
|
|
|
|
|
std::string devname = "/dev/serial0";
|
|
|
|
|
#else
|
|
|
|
@ -163,8 +256,8 @@ void UartTestClass::scexInit() {
|
|
|
|
|
|
|
|
|
|
// Non-blocking mode, read until either line is 0.1 second idle or maximum of 255 bytes are
|
|
|
|
|
// received in one go
|
|
|
|
|
tty.c_cc[VTIME] = 1; // In units of 0.1 seconds
|
|
|
|
|
tty.c_cc[VMIN] = 255; // Read up to 255 bytes
|
|
|
|
|
tty.c_cc[VTIME] = 5; // In units of 0.1 seconds
|
|
|
|
|
tty.c_cc[VMIN] = 1; // Read up to 255 bytes
|
|
|
|
|
|
|
|
|
|
// Q7S UART Lite has fixed baud rate. For other linux systems, set baud rate here.
|
|
|
|
|
#if !defined(XIPHOS_Q7S)
|
|
|
|
@ -173,89 +266,10 @@ void UartTestClass::scexInit() {
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Flush received and unread data
|
|
|
|
|
tcflush(serialPort, TCIOFLUSH);
|
|
|
|
|
if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
|
|
|
|
|
sif::warning << "tcsetattr call failed with error [" << errno << ", " << strerror(errno)
|
|
|
|
|
<< std::endl;
|
|
|
|
|
}
|
|
|
|
|
// Flush received and unread data
|
|
|
|
|
tcflush(serialPort, TCIFLUSH);
|
|
|
|
|
} else {
|
|
|
|
|
#if defined(RASPBERRY_PI)
|
|
|
|
|
std::string devname = "/dev/serial0";
|
|
|
|
|
#else
|
|
|
|
|
std::string devname = "/dev/ul-scex";
|
|
|
|
|
#endif
|
|
|
|
|
uartCookie =
|
|
|
|
|
new UartCookie(this->getObjectId(), devname, UartModes::NON_CANONICAL, 57600, 4096);
|
|
|
|
|
reader->setDebugMode(true);
|
|
|
|
|
ReturnValue_t result = reader->initializeInterface(uartCookie);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UartTestClass::scexPeriodic() {
|
|
|
|
|
if (reader == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scexMode == ScexModes::SIMPLE) {
|
|
|
|
|
sif::info << "UartTestClass::scexInit: Sending ping command to SCEX" << std::endl;
|
|
|
|
|
// reader->sendMessage(nullptr, nullptr, 0);
|
|
|
|
|
uint8_t tmpCmdBuf[32] = {};
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
prepareScexPing(tmpCmdBuf, &len);
|
|
|
|
|
ReturnValue_t result =
|
|
|
|
|
dleEncoder.encode(tmpCmdBuf, len, cmdBuf.data(), cmdBuf.size(), &encodedLen, true);
|
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
|
sif::warning << "UartTestClass::scexInit: Encoding failed" << std::endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (result != 0) {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
size_t bytesWritten = write(serialPort, cmdBuf.data(), encodedLen);
|
|
|
|
|
if (bytesWritten != encodedLen) {
|
|
|
|
|
sif::warning << "Sending ping command to solar experiment failed" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read back reply immediately
|
|
|
|
|
int bytesRead = 0;
|
|
|
|
|
do {
|
|
|
|
|
bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()),
|
|
|
|
|
static_cast<unsigned int>(recBuf.size()));
|
|
|
|
|
if (bytesRead < 0) {
|
|
|
|
|
sif::warning << "UartTestClass::performPeriodicAction: read call failed with error ["
|
|
|
|
|
<< errno << ", " << strerror(errno) << "]" << std::endl;
|
|
|
|
|
break;
|
|
|
|
|
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
|
|
|
|
|
sif::debug << "UartTestClass::performPeriodicAction: recv buffer might not be large enough"
|
|
|
|
|
<< std::endl;
|
|
|
|
|
} else if (bytesRead > 0) {
|
|
|
|
|
sif::info << "Received " << bytesRead
|
|
|
|
|
<< " bytes from the Solar Cell Experiment:" << std::endl;
|
|
|
|
|
arrayprinter::print(recBuf.data(), bytesRead, OutputType::HEX, false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} while (bytesRead > 0);
|
|
|
|
|
} else {
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
prepareScexPing(cmdBuf.data(), &len);
|
|
|
|
|
reader->sendMessage(uartCookie, cmdBuf.data(), len);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int UartTestClass::prepareScexPing(uint8_t* cmdBuf, size_t* len) {
|
|
|
|
|
// Send ping command
|
|
|
|
|
cmdBuf[0] = scex::CMD_PING;
|
|
|
|
|
// These two fields are the packet counter and the total packet count. Those are 1 and 1 for each
|
|
|
|
|
// telecommand so far
|
|
|
|
|
cmdBuf[1] = 1;
|
|
|
|
|
cmdBuf[2] = 1;
|
|
|
|
|
uint16_t userDataLen = 0;
|
|
|
|
|
cmdBuf[3] = (userDataLen >> 8) & 0xff;
|
|
|
|
|
cmdBuf[4] = userDataLen & 0xff;
|
|
|
|
|
uint16_t crc = CRC::crc16ccitt(cmdBuf, 5);
|
|
|
|
|
cmdBuf[5] = (crc >> 8) & 0xff;
|
|
|
|
|
cmdBuf[6] = crc & 0xff;
|
|
|
|
|
*len = 7;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|