I am trying to get the DataLogger and Logbook to work on the movesense device. What I am trying to do is similar/continuation to what is asked in this question. When I am configuring my service when a device is connecting I would like to wait for the DataLogger to start(return status code 200) before continuing the execution of the rest of my code.
As part of the onSubscribe() function I execute the following code to configure the DataLogger:
WB_RES::DataLoggerConfig logConfig;
WB_RES::DataEntry entry;
WB_RES::DataLoggerStateValues::Type logState = WB_RES::DataLoggerStateValues::Type::DATALOGGER_LOGGING;
entry.path = <pathToService>;
<del>logConfig.dataEntries.dataEntry= {entry}; </del>
logConfig.dataEntries.dataEntry = whiteboard::MakeArray<WB_RES::DataEntry>(&entry, 1);
result = asyncPut(WB_RES::LOCAL::MEM_DATALOGGER_CONFIG(), AsyncRequestOptions::Empty, logConfig);
The status code I get after this command is the 202 Accepted. What I understood from the previous question are that I need to check that this function returns return code 200 in the onPutResult() function.
This I do by
switch(resourceId.localResourceId)
{
case WB_RES::LOCAL::MEM_DATALOGGER_CONFIG::LID:
{
if(resultCode == whiteboard::HTTP_CODE_OK)
{
asyncPut(WB_RES::LOCAL::MEM_DATALOGGER_STATE(), AsyncRequestOptions::Empty,WB_RES::DataLoggerStateValues::Type::DATALOGGER_LOGGING);
}
}
break;
And again in the onPutResult() I check that the datalogger is set in the correct state using this piece of code
case WB_RES::LOCAL::MEM_DATALOGGER_STATE::LID:
{
if(resultCode == whiteboard::HTTP_CODE_OK)
{
// Boolean variable that indicate that the dataLogger is running.
DataLoggerRunning = true;
}
else
{
DEBUGLOG("onPutResult::MEM_DATALOGGER_STATE::
SomethingIsNotRight");
}
}
break;
Now I want to detect if the variable DataLoggerRunning is true before starting the my service. This is where I am a bit lost, I tried just waiting in a while loop, and looking for a sleep function in the movesense-device-lib (with no luck) in the hope that would not crash the code while waiting for the datalogger to start. The while loop resulted in an infinite loop, and I presume that a sleep function would also be blocking if I could find one.
Is this the wrong approach or am I on the right track, if so help making progress would be appreciated.
EDIT: Updated code for adding path to datalogger. If the old code is used we will get an 404 not found for the path.