Extracting the API Log Information
To extract information of API function calls from the API log file, the OpenApiLogFile, GetApiLogData, and CloseApiLogFile functions must be called.
The OpenApiLogFile function opens an API log file for reading. After calling this function, the GetApiLogData function can be called any number of times.
Each time the GetApiLogData function is called, the information of one API function call is extracted from the file. If the API log file contains data of more than one API function call, this function must be called multiple times to extract all of the information. When there is no more API function call data remaining in the file, the NoMoreLogData error is returned.
In addition to the information that is contained in the ApiLogInfo class, additional raw data of the API function call is also extracted into a buffer that is passed to the GetApiLogData function. If the buffer that is passed to GetApiLogData is too small to store the raw data, the BufferTooSmall error is returned. The maximum size of the raw data of an API function call is 262164 bytes (256KB+20bytes).
The raw data obtained with the GetApiLogData function can be converted to a string that represents the contained data using the ApiLogToString function of the module that defines the called API function. The ApiLogToString function is defined in every module, and using the ApiLogToString function of a module that does not match the raw data causes it to return the InvalidModuleId error. The ApiLogInfo.moduleId value returned by GetApiLogData can be read to check which module defines the API function that was called.
The size of the char array passed to the pString argument of ApiLogToString to guarantee that the entire string fits depends on the module. If the string does not fit, the BufferTooSmall error is returned. See the following table for the required size.
Library |
Required Size (Characters) |
|---|---|
1024 |
|
128*1024=131072 |
|
1024 |
|
1024 |
|
1024 |
|
1024 |
|
128*1024=131072 |
|
1024 |
|
128*1024=131072 |
|
128*1024=131072 |
|
1024 |
|
1024 |
|
RTEX::ApiLogToString |
1024 |
MIII::ApiLogToString |
1024 |
CCLink::ApiLogToString |
1024 |
1024 |
By default, only the command data (arguments passed to the WMX3 engine) of API function calls is saved to the API log file. If the moduleResp option is set, the response data (values returned from the WMX3 engine, including the error code) is also saved to the API log file. The command data and response data of an API function call are saved and extracted separately from the API log file (therefore, the GetApiLogData function must be called twice to extract both the command data and the response data). To match the command data to the response data, check the ApiLogInfo.logId values returned by GetApiLogData. The command data and the response data of the same API function call will share the same value for ApiLogInfo.logId.
Example Code for Extracting API Log Information
FILE *pApiLogFile;
ApiLogInfo logInfo;
unsigned char dataBuff[262164];
wchar_t strBuff[131072];
//The file name should be replaced with the file name including the date and time
wmxlib_Log->OpenApiLogFile(_T("C:\\Program Files\\SoftServo\\WMX3\\apilog.dat"), &pApiLogFile);
//Extract API log information
while (wmxlib_Log->GetApiLogData(pApiLogFile, dataBuff, sizeof(dataBuff), &logInfo) == ErrorCode::None) {
//Process data returned by ApiLogInfo
//Make a branch to call ApiLogToString for all modules from which API functions are called
if (logInfo.moduleId == ModuleId::WMX3Engine) {
wmxlib->ApiLogToString(dataBuff, 262164, strBuff, 131072);
}
else if (logInfo.moduleId == ModuleId::CoreMotion) {
wmxlib_CoreMotion->ApiLogToString(dataBuff, 262164, strBuff, 131072);
}
else if (logInfo.moduleId == ModuleId::Log) {
wmxlib_Log->ApiLogToString(dataBuff, 262164, strBuff, 131072);
}
//etc.
//Process the data returned by ApiLogToString
}
//Close file
wmxlib_Log->CloseApiLogFile(pApiLogFile);