kvmlib.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 by KVASER AB, SWEDEN
3  * WWW: http://www.kvaser.com
4  *
5  * This software is furnished under a license and may be used and copied
6  * only in accordance with the terms of such license.
7  */
8 
9 #ifndef KVMLIB_H
10 #define KVMLIB_H
11 
46 #include <windows.h>
47 #include <stdint.h>
48 #include <stdio.h>
49 
50 typedef int8_t int8;
51 typedef uint8_t uint8;
52 typedef int16_t int16;
53 typedef uint16_t uint16;
54 typedef int32_t int32;
55 typedef uint32_t uint32;
56 typedef int64_t int64;
57 
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
71 #define kvmDEVICE_MHYDRA 0
72 #define kvmDEVICE_MHYDRA_EXT 1
73 
83 #define kvmLDF_MAJOR_CAN 3
84 #define kvmLDF_MAJOR_CAN64 5
85 
90 typedef HANDLE kmeFileHandle;
91 
100 #define kvmFS_FAT16 0
101 #define kvmFS_FAT32 1
102 
112 #define kvmFILE_KME24 0
113 #define kvmFILE_KME25 1
114 #define kvmFILE_KME40 2
115 #define kvmFILE_KME50 3
116 #define kvmFILE_KME60 4
117 
122 typedef HANDLE kvmHandle;
123 
124 
135  // If you change here, remember to also change kvmlib.cpp and kvmlibtest...
136 typedef enum {
137  kvmOK = 0,
138  kvmFail = -1,
144  kvmEOF = -12,
171 
172 } kvmStatus;
183 #define kvmLogFileType_ERR 0
184 #define kvmLogFileType_ALL 1
185 
196 #define kvm_SWINFO_KVMLIB 1
197 #define kvm_SWINFO_DRIVER 2
198 #define kvm_SWINFO_FIRMWARE 3
199 #define kvm_SWINFO_DRIVER_PRODUCT 4
200 #define kvm_SWINFO_CONFIG_VERSION_NEEDED 5
201 #define kvm_SWINFO_CPLD_VERSION 6
202 
204 #include <pshpack1.h>
205 
206 #ifndef canMSG_RTR
207 
216 # define canMSG_RTR 0x0001
217 # define canMSG_STD 0x0002
218 # define canMSG_EXT 0x0004
219 # define canMSG_ERROR_FRAME 0x0020
220 # define canMSG_TXACK 0x0040
221 # define canMSG_TXRQ 0x0080
222 # define canMSGERR_OVERRUN 0x0600
223 # define canFDMSG_EDL 0x010000
224 # define canFDMSG_FDF 0x010000
225 # define canFDMSG_BRS 0x020000
226 # define canFDMSG_ESI 0x040000
227 
228 #endif
229 
238 #define TRIGVAR_TYPE_MSG_ID 0
239 #define TRIGVAR_TYPE_MSG_DLC 1
240 #define TRIGVAR_TYPE_MSG_FLAG 2
241 #define TRIGVAR_TYPE_SIGVAL 3
242 #define TRIGVAR_TYPE_EXTERNAL 4
243 #define TRIGVAR_TYPE_TIMER 5
244 #define TRIGVAR_TYPE_DISK_FULL 6
245 #define TRIGVAR_TYPE_STARTUP 9
246 
251 typedef struct {
257  uint8 data[64];
258 } kvmLogMsgEx;
259 
263 typedef struct {
267 
268 
272 typedef struct {
279 
283 typedef struct
284 {
285  uint32 lioMajor; // Lio major version
286  uint32 lioMinor; // Lio minor version
287  uint32 fwMajor; // Firmware major version
288  uint32 fwMinor; // Firmware major version
289  uint32 fwBuild; // Firmware build version
290  uint32 serialNumber; // Serial number
291  uint32 eanHi; // EAN high bytes
292  uint32 eanLo; // EAN low bytes
294 
295 
303 #define kvmLOG_TYPE_INVALID 0
304 #define kvmLOG_TYPE_CLOCK 1
305 #define kvmLOG_TYPE_MSG 2
306 #define kvmLOG_TYPE_TRIGGER 3
307 #define kvmLOG_TYPE_VERSION 4
308 
313 typedef struct {
315  union {
316  kvmLogMsgEx msg;
317  kvmLogRtcClockEx rtc;
318  kvmLogTriggerEx trig;
319  kvmLogVersionEx ver;
320  uint8 raw[128];
321  } eventUnion;
322 } kvmLogEventEx;
323 
324 #include <poppack.h>
325 
335 void WINAPI kvmInitialize(void);
336 
352 kvmStatus WINAPI kvmGetVersion(int *major, int *minor, int *build);
353 
366 kvmStatus WINAPI kvmGetErrorText(kvmStatus error, char *buf, size_t len);
367 
384 kvmStatus WINAPI kvmClose(kvmHandle h);
385 
405 kvmHandle WINAPI kvmDeviceOpen(int32 cardNr,
406  kvmStatus *status,
407  int32 deviceType);
408 
428 
450 kvmStatus WINAPI kvmDeviceMountKmfEx(kvmHandle h, int *ldfMajor, int *ldfMinor);
451 
476 kvmHandle WINAPI kvmKmfOpen(const char *filename,
477  kvmStatus *status,
478  int32 deviceType);
479 
507 kvmHandle WINAPI kvmKmfOpenEx(const char *filename,
508  kvmStatus *status,
509  int32 deviceType,
510  int *ldfMajor,
511  int *ldfMinor);
512 
527 
552  int fileSystem,
553  uint32 reserveSpace,
554  uint32 dbaseSpace);
555 
570 kvmStatus WINAPI kvmLogFileGetCount(kvmHandle h, uint32 *fileCount);
571 
587 kvmStatus WINAPI kvmLogFileGetType(kvmHandle h, uint32 fileIndx, int32 *logFileType);
588 
612 kvmStatus WINAPI kvmLogFileMount(kvmHandle h, uint32 fileIndx,
613  uint32 *eventCount);
614 
633 kvmStatus WINAPI kvmLogFileMountEx(kvmHandle h, uint32 fileIndx,
634  int64 *eventCount);
635 
648 
665  uint32 *startTime);
666 
683  uint32 *endTime);
684 
701  uint32 *serialNumber);
702 
720 
721 
736 
753 kvmStatus WINAPI kvmDeviceDiskStatus(kvmHandle h, int *present);
754 
772  uint32 *totalSectorCount,
773  uint32 *usedSectorCount);
774 
790 kvmStatus WINAPI kvmDeviceDiskSize(kvmHandle h, uint32 *diskSize);
791 
806 kvmStatus WINAPI kvmDeviceGetSerialNumber(kvmHandle h, unsigned int *serial);
807 
827  int32 itemCode,
828  unsigned int *major,
829  unsigned int *minor,
830  unsigned int *build,
831  unsigned int *flags);
846 
847 
865 
883 
900 kvmStatus WINAPI kvmKmfReadConfig(kvmHandle h, void *buf,
901  size_t buflen, size_t *actual_len);
902 
918 kvmStatus WINAPI kvmKmfWriteConfig(kvmHandle h, void *buf, size_t buflen);
919 
920 
940 kvmStatus WINAPI kvmKmfGetDbaseFile(kvmHandle h, char *path, char *filenamebuf, size_t buflen);
941 
959 kvmStatus WINAPI kvmKmfPutDbaseFile(kvmHandle h, char *filename);
960 
975 
994 kmeFileHandle WINAPI kvmKmeOpenFile (const char *filename,
995  kvmStatus *status,
996  int32 fileType);
997 
1015 kvmStatus WINAPI kvmKmeScanFileType (const char *filename,
1016  int32 *fileType);
1017 
1039 kmeFileHandle WINAPI kvmKmeCreateFile (const char *filename,
1040  kvmStatus *status,
1041  int32 fileType);
1042 
1062 
1081 
1104 kvmStatus WINAPI kvmKmeCountEvents(kmeFileHandle h, uint32 *eventCount);
1105 
1123 kvmStatus WINAPI kvmKmeCountEventsEx(kmeFileHandle h, int64 *eventCount);
1124 
1143 
1177 #ifdef __cplusplus
1178 }
1179 #endif
1180 
1181 #endif //KVMLIB_H
kvmStatus kvmClose(kvmHandle h)
Unsupported version.
Definition: kvmlib.h:156
Error writing log file.
Definition: kvmlib.h:143
Disk full (data).
Definition: kvmlib.h:153
uint32 flags
Message flags canMSG_xxx.
Definition: kvmlib.h:256
uint32 eanLo
Definition: kvmlib.h:292
kvmStatus kvmLogFileGetCount(kvmHandle h, uint32 *fileCount)
kmeFileHandle kvmKmeOpenFile(const char *filename, kvmStatus *status, int32 fileType)
kvmStatus kvmKmeCloseFile(kmeFileHandle h)
uint32 trigMask
Bitmask with all active triggers.
Definition: kvmlib.h:276
kvmStatus kvmDeviceDiskStatus(kvmHandle h, int *present)
Queue is full.
Definition: kvmlib.h:147
File not found.
Definition: kvmlib.h:160
HANDLE kvmHandle
A handle to a Memorator or equivalent KMF file.
Definition: kvmlib.h:122
Configuration error.
Definition: kvmlib.h:168
kvmStatus kvmLogFileMount(kvmHandle h, uint32 fileIndx, uint32 *eventCount)
uint16_t uint16
Definition: kvmlib.h:53
int32 postTrigger
Posttrigger time in milliseconds.
Definition: kvmlib.h:275
A RTC clock message.
Definition: kvmlib.h:263
No log message found.
Definition: kvmlib.h:142
kvmStatus kvmDeviceGetRTC(kvmHandle h, uint32 *t)
kvmStatus kvmKmeWriteEvent(kmeFileHandle h, kvmLogEventEx *e)
HANDLE kmeFileHandle
A handle to a KME file.
Definition: kvmlib.h:90
uint32 serialNumber
Definition: kvmlib.h:290
kvmStatus kvmKmfGetUsage(kvmHandle h, uint32 *totalSectorCount, uint32 *usedSectorCount)
User abort.
Definition: kvmlib.h:166
kmeFileHandle kvmKmeCreateFile(const char *filename, kvmStatus *status, int32 fileType)
File system corrupt.
Definition: kvmlib.h:155
Error while reading log file.
Definition: kvmlib.h:146
OK!
Definition: kvmlib.h:137
Timeout.
Definition: kvmlib.h:163
kvmStatus kvmDeviceFormatDisk(kvmHandle h, int fileSystem, uint32 reserveSpace, uint32 dbaseSpace)
kvmStatus kvmKmfEraseDbaseFile(kvmHandle h)
Disk is write protected.
Definition: kvmlib.h:169
kvmStatus kvmKmeCountEventsEx(kmeFileHandle h, int64 *eventCount)
uint32 id
The message identifier.
Definition: kvmlib.h:252
Wrong disk type.
Definition: kvmlib.h:162
kvmStatus kvmKmfWriteConfig(kvmHandle h, void *buf, size_t buflen)
kvmStatus kvmDeviceFlashLeds(kvmHandle h)
uint32 fwMinor
Definition: kvmlib.h:288
uint32 lioMinor
Definition: kvmlib.h:286
End of file found.
Definition: kvmlib.h:144
uint32 type
kvmLOG_TYPE_xxx, Event types in log
Definition: kvmlib.h:314
kvmStatus kvmLogFileDismount(kvmHandle h)
kvmStatus kvmLogFileDeleteAll(kvmHandle h)
int8_t int8
Definition: kvmlib.h:50
kvmStatus kvmKmfReadConfig(kvmHandle h, void *buf, size_t buflen, size_t *actual_len)
File I/O error.
Definition: kvmlib.h:150
Disk not formatted.
Definition: kvmlib.h:161
uint32 fwMajor
Definition: kvmlib.h:287
kvmStatus kvmKmeScanFileType(const char *filename, int32 *fileType)
Illegal request.
Definition: kvmlib.h:159
The union of events used by kvmKmeReadEvent().
Definition: kvmlib.h:313
kvmStatus kvmLogFileGetType(kvmHandle h, uint32 fileIndx, int32 *logFileType)
int16_t int16
Definition: kvmlib.h:52
uint32 channel
The device channel on which the message arrived, 0,1,...
Definition: kvmlib.h:254
kvmStatus kvmDeviceGetSoftwareInfo(kvmHandle h, int32 itemCode, unsigned int *major, unsigned int *minor, unsigned int *build, unsigned int *flags)
kvmStatus kvmDeviceMountKmfEx(kvmHandle h, int *ldfMajor, int *ldfMinor)
uint32 dlc
The length of the message.
Definition: kvmlib.h:255
kvmStatus kvmGetErrorText(kvmStatus error, char *buf, size_t len)
kvmStatus kvmLogFileReadEvent(kvmHandle h, kvmLogEventEx *e)
int32 type
The type of trigger TRIGVAR_TYPE_xxx.
Definition: kvmlib.h:273
kvmStatus kvmDeviceMountKmf(kvmHandle h)
signed __int64 int64
Definition: kvlclib.h:65
CRC check failed.
Definition: kvmlib.h:148
uint32 lioMajor
Definition: kvmlib.h:285
kvmStatus kvmLogFileGetCreatorSerial(kvmHandle h, uint32 *serialNumber)
Firmware error.
Definition: kvmlib.h:167
int64 timeStamp
The timestamp in units of 1 nanosecond.
Definition: kvmlib.h:253
kvmStatus kvmLogFileMountEx(kvmHandle h, uint32 fileIndx, int64 *eventCount)
int64_t int64
Definition: kvmlib.h:56
Generic error.
Definition: kvmlib.h:138
kvmStatus kvmKmfValidate(kvmHandle h)
Fatal error.
Definition: kvmlib.h:158
kvmStatus kvmLogFileGetEndTime(kvmHandle h, uint32 *endTime)
Disk full (directory).
Definition: kvmlib.h:152
Not implemented.
Definition: kvmlib.h:157
kvmStatus kvmKmeReadEvent(kmeFileHandle h, kvmLogEventEx *e)
Device occupied.
Definition: kvmlib.h:165
General disk error.
Definition: kvmlib.h:151
uint32_t uint32
Definition: kvmlib.h:55
uint32 fwBuild
Definition: kvmlib.h:289
A trigger message.
Definition: kvmlib.h:272
No disk found.
Definition: kvmlib.h:145
Device communication error.
Definition: kvmlib.h:164
kvmStatus
Definition: kvmlib.h:136
Sector unexpectadly erased.
Definition: kvmlib.h:149
Error in supplied parameters.
Definition: kvmlib.h:139
int32 preTrigger
Pretrigger time in milliseconds.
Definition: kvmlib.h:274
Can&#39;t find/open log file.
Definition: kvmlib.h:140
kvmStatus kvmLogFileGetStartTime(kvmHandle h, uint32 *startTime)
uint8_t uint8
Definition: kvmlib.h:51
int32_t int32
Definition: kvmlib.h:54
kvmStatus kvmKmfGetDbaseFile(kvmHandle h, char *path, char *filenamebuf, size_t buflen)
Result is too big for an out-parameter.
Definition: kvmlib.h:170
kvmStatus kvmDeviceSetRTC(kvmHandle h, uint32 t)
kvmStatus kvmDeviceDiskSize(kvmHandle h, uint32 *diskSize)
A version message.
Definition: kvmlib.h:283
kvmHandle kvmKmfOpenEx(const char *filename, kvmStatus *status, int32 deviceType, int *ldfMajor, int *ldfMinor)
uint32 calendarTime
RTC date, seconds since 1970-01-01T00:00:00+00:00 (UTC)
Definition: kvmlib.h:264
kvmHandle kvmKmfOpen(const char *filename, kvmStatus *status, int32 deviceType)
uint32 eanHi
Definition: kvmlib.h:291
kvmStatus kvmKmeCountEvents(kmeFileHandle h, uint32 *eventCount)
kvmHandle kvmDeviceOpen(int32 cardNr, kvmStatus *status, int32 deviceType)
Start time not found.
Definition: kvmlib.h:141
void kvmInitialize(void)
Unexpected sequence.
Definition: kvmlib.h:154
kvmStatus kvmKmfPutDbaseFile(kvmHandle h, char *filename)
A CAN message.
Definition: kvmlib.h:251
kvmStatus kvmGetVersion(int *major, int *minor, int *build)
kvmStatus kvmDeviceGetSerialNumber(kvmHandle h, unsigned int *serial)