WIP: SCEX Init #272
@ -64,13 +64,13 @@ 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 << "UartTestClass::gpsInit: 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 << "UartTestClass::gpsInit: open call failed with error [" << errno << ", " << strerror(errno)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
/* Setting up UART parameters */
|
/* Setting up UART parameters */
|
||||||
@ -99,7 +99,7 @@ void UartTestClass::gpsInit() {
|
|||||||
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 << "UartTestClass::gpsInit: tcsetattr call failed with error [" << errno << ", " << strerror(errno)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@ -115,11 +115,11 @@ void UartTestClass::gpsPeriodic() {
|
|||||||
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::gpsPeriodic: 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::gpsPeriodic: "
|
||||||
"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) {
|
||||||
@ -129,7 +129,7 @@ void UartTestClass::gpsPeriodic() {
|
|||||||
#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::gpsPeriodic: lwgps_process error" << std::endl;
|
||||||
}
|
}
|
||||||
recvCnt++;
|
recvCnt++;
|
||||||
if (recvCnt == 6) {
|
if (recvCnt == 6) {
|
||||||
@ -163,7 +163,7 @@ void UartTestClass::scexInit() {
|
|||||||
reader->setDebugMode(false);
|
reader->setDebugMode(false);
|
||||||
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::scexInit: Initializing SCEX reader "
|
||||||
"UART IF failed"
|
"UART IF failed"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
@ -199,7 +199,7 @@ void UartTestClass::scexPeriodic() {
|
|||||||
const uint8_t* helperPtr = decodedPacket;
|
const uint8_t* helperPtr = decodedPacket;
|
||||||
result = helper.deSerialize(&helperPtr, &len);
|
result = helper.deSerialize(&helperPtr, &len);
|
||||||
if (result == ScexHelper::INVALID_CRC) {
|
if (result == ScexHelper::INVALID_CRC) {
|
||||||
sif::warning << "CRC invalid" << std::endl;
|
sif::warning << "UartTestClass::scexPeriodic: CRC invalid" << std::endl;
|
||||||
}
|
}
|
||||||
sif::info << helper << endl;
|
sif::info << helper << endl;
|
||||||
|
|
||||||
@ -238,7 +238,7 @@ void UartTestClass::scexPeriodic() {
|
|||||||
if (finishCountdown.hasTimedOut()) {
|
if (finishCountdown.hasTimedOut()) {
|
||||||
triggerEvent(scex::EXPERIMENT_TIMEDOUT, currCmd, 0);
|
triggerEvent(scex::EXPERIMENT_TIMEDOUT, currCmd, 0);
|
||||||
reader->finish();
|
reader->finish();
|
||||||
sif::warning << "Reader timeout" << endl;
|
sif::warning << "UartTestClass::scexPeriodic: Reader timeout" << endl;
|
||||||
cmdDone = true;
|
cmdDone = true;
|
||||||
fileNameSet = false;
|
fileNameSet = false;
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ void UartTestClass::scexPeriodic() {
|
|||||||
|
|
||||||
if (helper.getPacketCounter() == helper.getTotalPacketCounter()) {
|
if (helper.getPacketCounter() == helper.getTotalPacketCounter()) {
|
||||||
reader->finish();
|
reader->finish();
|
||||||
sif::info << "Reader is finished" << endl;
|
sif::info << "UartTestClass::scexPeriodic: Reader is finished" << endl;
|
||||||
cmdDone = true;
|
cmdDone = true;
|
||||||
fileNameSet = false;
|
fileNameSet = false;
|
||||||
if (helper.getCmd() == scex::Cmds::PING) {
|
if (helper.getCmd() == scex::Cmds::PING) {
|
||||||
@ -268,7 +268,7 @@ void UartTestClass::scexSimpleInit() {
|
|||||||
/* 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 << "UartTestClass::scexSimpleInit: Open call failed with error [" << errno << ", " << strerror(errno)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -291,12 +291,12 @@ void UartTestClass::scexSimpleInit() {
|
|||||||
// 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::scexSimpleInit: 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 << "UartTestClass::scexSimpleInit: tcsetattr call failed with error [" << errno << ", " << strerror(errno)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
// Flush received and unread data
|
// Flush received and unread data
|
||||||
@ -315,7 +315,7 @@ void UartTestClass::scexSimplePeriodic() {
|
|||||||
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::scexSimplePeriodic: Encoding failed" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
@ -323,7 +323,7 @@ void UartTestClass::scexSimplePeriodic() {
|
|||||||
};
|
};
|
||||||
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 << "UartTestClass::scexSimplePeriodic: Sending command to solar experiment failed" << std::endl;
|
||||||
}
|
}
|
||||||
cmdSent = true;
|
cmdSent = true;
|
||||||
cmdDone = false;
|
cmdDone = false;
|
||||||
@ -335,13 +335,13 @@ void UartTestClass::scexSimplePeriodic() {
|
|||||||
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 << "UartTestClass::scexSimplePeriodic: 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::scexSimplePeriodic: 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 "
|
sif::debug << "UartTestClass::scexSimplePeriodic: recv buffer might not be large "
|
||||||
"enough, bytes read:"
|
"enough, bytes read:"
|
||||||
<< bytesRead << std::endl;
|
<< bytesRead << std::endl;
|
||||||
} else if (bytesRead > 0) {
|
} else if (bytesRead > 0) {
|
||||||
@ -383,7 +383,7 @@ void UartTestClass::foundDlePacketHandler(const DleParser::Context& ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 << "UartTestClass::handleFoundDlePacket: Detected DLE encoded packet with decoded size " << len << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UartTestClass::random_string(std::string::size_type length) {
|
std::string UartTestClass::random_string(std::string::size_type length) {
|
||||||
|
Loading…
Reference in New Issue
Block a user