Go to the documentation of this file.
77 using namespace xsens;
100 , m_abortLoadLogFile(false)
101 , m_loadFileTaskId(0)
102 , m_extractor(nullptr)
107 p->ignoreMaximumMessageSize(
true);
114 , m_ioInterfaceFile(ioInterfaceFile)
115 , m_abortLoadLogFile(false)
116 , m_loadFileTaskId(0)
117 , m_extractor(nullptr)
122 p->ignoreMaximumMessageSize(
true);
154 if (r.getBusId() !=
msg.getBusId())
239 for (
int count = 0; count < maxMsgs; ++count)
242 if (msgId == 0 ||
msg.getMessageId() == msgId)
266 std::deque<XsMessage> rv;
294 for (
int count = 0; count < maxMsgs; ++count)
299 else if (msgId == 0 ||
msg.getMessageId() == msgId)
308 if (msgId == 0 ||
msg.getMessageId() == msgId)
355 JLDEBUGG(
"Starting dedicated read thread");
394 #ifndef ANDROID // Invoking XsDevice::logFileName() results in a crash on Android for some reason...
396 XsString filename = m_task->m_device->logFileName();
397 std::string name = xprintf(
"FileReader: %s", filename.c_str());
399 JLDEBUGG(
"Loading file " << filename);
405 m_task->m_loader->readLogFile(m_task->m_device);
407 catch (XsException
const& e)
409 m_task->m_device->onError(m_task->m_device, e.code());
424 waitForLastTaskCompletion();
426 m_abortLoadLogFile =
false;
428 m_loadFileTaskId = ThreadPool::instance()->addTask(tsk, m_loadFileTaskId);
450 res = readSinglePacketFromFile();
463 const int percentage = (int)(pos * 100 / size);
464 if (prevFilePos != percentage && percentage < 100)
466 onProgressUpdated(device, percentage < 100 ? percentage : 99, 100, &
id);
467 prevFilePos = percentage;
472 if (!m_abortLoadLogFile)
474 masterDevice()->onEofReached();
475 onProgressUpdated(device, 100, 100, &
id);
478 return setAndReturnLastResult(res);
501 m_abortLoadLogFile =
true;
513 if (m_ioInterfaceFile)
516 if (filename == logFileName())
525 setLastResult(m_ioInterfaceFile->open(filename,
false,
true));
526 if (lastResult() !=
XRV_OK)
528 m_ioInterfaceFile.reset();
537 rv = m_ioInterfaceFile->readData(1, hdrBuf);
538 if (rv !=
XRV_OK || hdrBuf.size() < 1 || hdrBuf[0] != 0xFA)
541 m_ioInterfaceFile.reset();
545 resetLogFileReadPosition();
552 m_ioInterfaceFile.reset();
556 resetLogFileReadPosition();
564 m_ioInterfaceFile.reset();
569 config.readFromMessage(rcv);
570 setMasterDeviceId(
XsDeviceId((
char*)config.masterInfo().m_productCode, 0, 0, config.masterInfo().m_masterDeviceId));
580 if (!m_ioInterfaceFile)
583 if (m_ioInterfaceFile->getName(retString) !=
XRV_OK)
592 if (!m_ioInterfaceFile)
595 return m_ioInterfaceFile->getFileSize();
602 if (!m_ioInterfaceFile)
605 return m_ioInterfaceFile->getFileDate();
619 if (!m_ioInterfaceFile)
622 auto pos = m_ioInterfaceFile->getReadPosition();
623 if (pos < m_ioInterfaceFile->getFileSize())
626 if (m_extractedMessages->empty())
629 return pos > 0 ? pos - 1 : 0;
638 if (m_ioInterfaceFile)
640 m_extractor->clearBuffer();
641 m_extractedMessages->clear();
664 if (!m_ioInterfaceFile)
674 msg = readNextMessage();
675 }
while (!
msg.empty() && msgId != 0 &&
msg.getMessageId() != msgId);
677 if (msgId == 0 ||
msg.getMessageId() == msgId)
689 while (m_extractedMessages->empty())
692 XsResultValue res = m_ioInterfaceFile->readDataBlocks(1, raw);
700 m_extractor->processNewData(masterDevice(), raw, *m_extractedMessages);
705 m_extractedMessages->pop_front();
713 return ThreadPool::instance()->doesTaskExist(m_loadFileTaskId);
784 (void)skipDeviceIdCheck;
XsFilePos logFileReadPosition() const override
Retrieve the read position of the log file.
bool isPortOpen() const override
bool reopenPort(OpenPortStage stage=OPS_Full, bool skipDeviceIdCheck=false) override
Reopens the port.
FileLoader * m_loader
The Communicator object that contains information on calibration and filtering.
A generic task implementation for the thread pool.
struct XsMessage XsMessage
A list of uint8_t values.
xsens::ThreadPool::TaskId m_loadFileTaskId
OpenPortStage
Port opening stages.
virtual void ignoreMaximumMessageSize(bool ignore)
Tells the protocol handler to ignore/expand its maximum message size.
bool isRunning(void) volatile const noexcept
Returns whether the thread is currently running.
bool openPort(const XsPortInfo &portInfo, OpenPortStage stage=OPS_Full, bool detectRs485=false) override
Opens a port.
std::shared_ptr< ProtocolManager > protocolManager() const
Structure containing a full device configuration as returned by the ReqConfig message.
virtual XsResultValue readLogFile(XsDevice *device) override
Read a log file into cache.
std::shared_ptr< IoInterfaceFile > m_ioInterfaceFile
XsTimeStamp logFileDate() const override
Retrieve the date of the open log file.
void XSTYPES_DLL_API xsNameThisThread(const char *threadName)
Set the name of the current thread to threadName.
@ XRV_ENDOFFILE
270: End of file is reached
bool doTransaction(const XsMessage &msg, XsMessage &rcv, uint32_t timeout) override
Pretend to be a live system.
XsMessage readMessageFromStartOfFile(uint8_t msgId, int maxMsgs=0) override
Read a message from the start of the open file.
A class that is used for the communcation with a mtb file.
The low-level file communication class.
@ XRV_ALREADYOPEN
269: An I/O device is already opened with this object
@ XRV_NOFILEOPEN
287: No file opened for reading/writing
MtbFileCommunicator()
Default constructor.
@ XRV_OK
0: Operation was performed successfully
std::deque< XsMessage > readMessagesFromStartOfFile(uint8_t msgId, int maxMsgs=0) override
Read multiple similar messages from the start of the open file.
bool startThread(const char *name=NULL)
Starts the thread.
ReaderThread(Xs4FileTask *task)
virtual void addProtocolHandler(IProtocolHandler *handler)
Adds a protocol handler.
void resetLogFileReadPosition(void) override
Restart reading from the start of the open log file.
static Communicator * construct()
Constructs new MtbFileCommunicator.
XsResultValue
Xsens result values.
XsResultValue lastResult() const
Get the result value of the last operation.
int32_t innerFunction(void) override
Virtual inner function.
uint32_t timeoutToMaxMessages(uint32_t timeout) const
A rather stupid function that tries to convert a live timeout into a number of messages.
void closePort() override
Closes the open port.
XsResultValue gotoConfig(bool detectRs485=false) override
Request a device to go to config mode.
XsPortInfo portInfo() const override
A base struct for a communication interface.
struct XsPortInfo XsPortInfo
void setKeepAlive(bool enable) override
Either disable or enable (default) the keep alive mechanism (if supported by the device)
void prepareForDestruction() override
Prepares for the destruction.
std::deque< XsMessage > * m_extractedMessages
bool writeMessage(const XsMessage &message) override
Write message to the device.
Contains a descriptor for opening a communication port to an Xsens device.
bool isDockedAt(Communicator *other) const override
Returns true if the other device is docked at this device.
Interface class for protocol handlers.
@ XRV_NODATA
272: No data is available
bool openLogFile(const XsString &filename) override
Open a log file for input.
XsMessage readMessage(uint8_t msgId=0) override
Read a message from the open file.
Function calling janitor class for std::function with 0 parameters.
XsXbusMessageId
Xsens Xbus Message Identifiers.
bool isLoadLogFileInProgress() const override
struct XsDeviceId XsDeviceId
Structure for storing a single message.
XsFilePos logFileSize() const override
Retrieve the size of the open log file in bytes.
void closeLogFile() override
Close the log file.
void completeAllThreadedWork()
Completes all threaded work.
bool isReadingFromFile() const override
Return whether we are reading from file.
MessageExtractor * m_extractor
void loadLogFile(XsDevice *device) override
Load a log file with thread pool.
@ XRV_OTHER
286: Something else was received than was requested
static int configurationMessageSearchLimit()
void setGotoConfigTimeout(uint32_t timeout) override
Set the timeout for the gotoConfig function.
A class for a standard thread that has to perform the same action repeatedly.
XsResultValue getDeviceId() override
Request a device to get device ID.
virtual void prepareForDestruction()
Prepares communicator for destruction.
A class for handling file loading process in a separate thread.
virtual XsMessage readNextMessage()
Read the next message from the open file.
void stopThread(void) noexcept
Tells the thread to stop and waits for it to end.
bool exec() override
Check if the file load is complete.
bool isAlive(void) volatile const noexcept
void abortLoadLogFile() override
Abort a process that takes a long time to complete.
@ XRV_UNSUPPORTED
303: The requested functionality is not supported by the device
Xs4FileTask(FileLoader *inf, XsDevice *device)
Construct a file task, but does not schedule it.
void flushPort() override
Flushes all remaining data on the open port.
void setLastResult(XsResultValue lastResult, XsString const &text=XsString()) const
Sets the last result.
static XsResultValue setLastResult(XsSocket *thisPtr, XsResultValue retval, int systemError)
void waitForLastTaskCompletion() override
Wait for the last processing task to complete in the threadpool.
@ XRV_INVALIDOPERATION
265: Operation is invalid at this point
virtual XsResultValue readSinglePacketFromFile() override
Read a single XsDataPacket from an open log file.
virtual ~Xs4FileTask()
Destroy this process task.
XsString logFileName() const override
Retrieve the name of the open log file or an empty string if no log file is open.
int64_t XsFilePos
The type that is used for positioning inside a file.
A 0-terminated managed string of characters.
struct XsTimeStamp XsTimeStamp
XsResultValue gotoMeasurement() override
Request a device to go to measurement mode.
@ XRV_DATACORRUPT
278: A trusted data stream proves to contain corrupted data
void addProtocolHandler(IProtocolHandler *handler) override
Add the protocol handler.
This class contains method to set, retrieve and compare timestamps.
Xs4FileTask::ReaderThread m_thread