Basic: | Intro/Trade | Quote | Category | Status | Symbol | Options |
Detailed: | Trade | Quote |
Introduction to Statuses
Status messages indicate general information about the tape has changed. pNxCoreSys contains details of the status message. pNxCoreSys is also populated for non-status messages as well. For this example we will be printing a timestamp every minute and printing the API version on initialization. Both NxCORESTATUS_WAITFORCOREACCESS and NxCORESTATUS_ERROR will not occur for demo.XU.nx2, but they are generally good checks to have while processing.
Code
#include "stdio.h" #include "NxCoreAPI_Wrapper_C++.h" NxCoreClass NxCore; int OnNxCoreCallback(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg) { if(pNxCoreMsg->MessageType == NxMSG_STATUS) { if (pNxCoreSys->ClockUpdateInterval >= NxCLOCK_MINUTE) { int year = pNxCoreSys->nxDate.Year; int month = pNxCoreSys->nxDate.Month; int day = pNxCoreSys->nxDate.Day; int hour = pNxCoreSys->nxTime.Hour; int minute = pNxCoreSys->nxTime.Minute; printf("%02d/%02d/%04d %02d:%02d\n", month, day, year, hour, minute); } if (pNxCoreSys->Status == NxCORESTATUS_WAITFORCOREACCESS) printf("Waiting on NxCore Access\n"); if (pNxCoreSys->Status == NxCORESTATUS_ERROR) printf("tape error:%d\n", pNxCoreSys->StatusData); if (pNxCoreSys->Status == NxCORESTATUS_INITIALIZING) { int major = NxCore.GetMajorVersion(pNxCoreSys->DLLVersion); int minor = NxCore.GetMinorVersion(pNxCoreSys->DLLVersion); int build = NxCore.GetBuildVersion(pNxCoreSys->DLLVersion); printf("Initialized with decoder version %d.%d.%d\n", major, minor, build); } } return NxCALLBACKRETURN_CONTINUE; } int main(int argc, char* argv[]) { if (argc < 3) return 1; if (NxCore.LoadNxCore(argv[1])){ int returnValue = NxCore.ProcessTape(argv[2], 0, 0, 0, OnNxCoreCallback); NxCore.ProcessReturnValue(returnValue); } else printf("loading library failed\n"); return 0; }
Callback Function
Since we only want to process status messages we check that MessageType equals NxMSG_STATUS. |
@Override int OnNxCoreCallback( const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMsg) { if(pNxCoreMsg->MessageType == NxMSG_STATUS) { ... } return defines.NxCALLBACKRETURN_CONTINUE; } |
On Interval
During status messages ClockUpdateInterval indicates if the timestamp has changed and whether it is a new hour, minute, or second. In this example we want to do something every minute, so we will check if ClockUpdateInterval is greater or equal to NxCLOCK_MINUTE, which is equivalent to 3. Checking greater than ensures we also perform the action on a new hour, since NxCLOCK_HOUR is equivalent to 4. The fields nxDate and nxTime reflect the date and time of the server processing the data. |
if (pNxCoreSys->ClockUpdateInterval >= NxCLOCK_MINUTE) { int year = pNxCoreSys->nxDate.Year; int month = pNxCoreSys->nxDate.Month; int day = pNxCoreSys->nxDate.Day; int hour = pNxCoreSys->nxTime.Hour; int minute = pNxCoreSys->nxTime.Minute; ... } |
Incomplete File
The Status field of NxCore message is the current state of the tape. Most of the time Status will be NxCORESTATUS_RUNNING. If the API is unable process the next message after a period of time, either because the file is incomplete or real-time stream is paused, Status will be set to NxCORESTATUS_WAITFORCOREACCESS. |
if (pNxCoreSys->Status == NxCORESTATUS_WAITFORCOREACCESS) printf("Waiting on NxCore Access\n"); |
Errors
If there is a problem while processing the tape, Status is set to NxCORESTATUS_ERROR. StatusData contains details of the Status. In this case it corresponds to the Error Codes Table. |
if (pNxCoreSys->Status == NxCORESTATUS_ERROR) printf("tape error:%d\n", pNxCoreSys->StatusData); |
Initialization
The first Status when beginning at the start of the file is NxCORESTATUS_INITIALIZING. If loading midday using states then the first status will instead be NxCORESTATUS_LOADED_STATE. | if (pNxCoreSys->Status == NxCORESTATUS_INITIALIZING) { int major = NxCore.GetMajorVersion(pNxCoreSys->DLLVersion); int minor = NxCore.GetMinorVersion(pNxCoreSys->DLLVersion); int build = NxCore.GetBuildVersion(pNxCoreSys->DLLVersion); printf("Initialized with decoder version %d.%d.%d\n", major, minor, build); } |
Next:
Symbol