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 kvmKmeCountEvents(kmeFileHandle h, uint32 *eventCount)
kvmStatus kvmLogFileDeleteAll(kvmHandle h)
HANDLE kvmHandle
A handle to a Memorator or equivalent KMF file.
Definition: kvmlib.h:122
No log message found.
Definition: kvmlib.h:142
kvmStatus kvmDeviceDiskSize(kvmHandle h, uint32 *diskSize)
uint32 id
The message identifier.
Definition: kvmlib.h:252
kvmStatus kvmKmeCloseFile(kmeFileHandle h)
kvmStatus kvmLogFileGetStartTime(kvmHandle h, uint32 *startTime)
int32 type
The type of trigger TRIGVAR_TYPE_xxx.
Definition: kvmlib.h:273
signed __int64 int64
Definition: kvlclib.h:65
kvmStatus kvmKmfGetUsage(kvmHandle h, uint32 *totalSectorCount, uint32 *usedSectorCount)
kvmStatus kvmDeviceFormatDisk(kvmHandle h, int fileSystem, uint32 reserveSpace, uint32 dbaseSpace)
Timeout.
Definition: kvmlib.h:163
kvmStatus kvmDeviceGetSoftwareInfo(kvmHandle h, int32 itemCode, unsigned int *major, unsigned int *minor, unsigned int *build, unsigned int *flags)
kvmStatus
Definition: kvmlib.h:136
Configuration error.
Definition: kvmlib.h:168
Unexpected sequence.
Definition: kvmlib.h:154
kvmStatus kvmKmeScanFileType(const char *filename, int32 *fileType)
kvmHandle kvmDeviceOpen(int32 cardNr, kvmStatus *status, int32 deviceType)
Wrong disk type.
Definition: kvmlib.h:162
kvmHandle kvmKmfOpen(const char *filename, kvmStatus *status, int32 deviceType)
OK!
Definition: kvmlib.h:137
kvmStatus kvmGetVersion(int *major, int *minor, int *build)
Sector unexpectadly erased.
Definition: kvmlib.h:149
uint32 fwBuild
Definition: kvmlib.h:289
Disk not formatted.
Definition: kvmlib.h:161
kvmStatus kvmKmfReadConfig(kvmHandle h, void *buf, size_t buflen, size_t *actual_len)
Error in supplied parameters.
Definition: kvmlib.h:139
kvmStatus kvmDeviceMountKmf(kvmHandle h)
CRC check failed.
Definition: kvmlib.h:148
uint32 lioMajor
Definition: kvmlib.h:285
void kvmInitialize(void)
kvmStatus kvmDeviceDiskStatus(kvmHandle h, int *present)
Result is too big for an out-parameter.
Definition: kvmlib.h:170
Device communication error.
Definition: kvmlib.h:164
uint32 serialNumber
Definition: kvmlib.h:290
uint32 trigMask
Bitmask with all active triggers.
Definition: kvmlib.h:276
uint32 eanLo
Definition: kvmlib.h:292
General disk error.
Definition: kvmlib.h:151
uint8_t uint8
Definition: kvmlib.h:51
A version message.
Definition: kvmlib.h:283
File I/O error.
Definition: kvmlib.h:150
Disk full (data).
Definition: kvmlib.h:153
kvmStatus kvmDeviceGetSerialNumber(kvmHandle h, unsigned int *serial)
kvmStatus kvmLogFileGetCount(kvmHandle h, uint32 *fileCount)
File not found.
Definition: kvmlib.h:160
kvmStatus kvmDeviceFlashLeds(kvmHandle h)
int8_t int8
Definition: kvmlib.h:50
int32 preTrigger
Pretrigger time in milliseconds.
Definition: kvmlib.h:274
kvmStatus kvmLogFileGetEndTime(kvmHandle h, uint32 *endTime)
kvmStatus kvmKmfEraseDbaseFile(kvmHandle h)
uint32 eanHi
Definition: kvmlib.h:291
kvmStatus kvmClose(kvmHandle h)
kvmStatus kvmKmfPutDbaseFile(kvmHandle h, char *filename)
Firmware error.
Definition: kvmlib.h:167
Fatal error.
Definition: kvmlib.h:158
int64 timeStamp
The timestamp in units of 1 nanosecond.
Definition: kvmlib.h:253
HANDLE kmeFileHandle
A handle to a KME file.
Definition: kvmlib.h:90
Illegal request.
Definition: kvmlib.h:159
uint16_t uint16
Definition: kvmlib.h:53
Unsupported version.
Definition: kvmlib.h:156
int32 postTrigger
Posttrigger time in milliseconds.
Definition: kvmlib.h:275
kvmStatus kvmDeviceGetRTC(kvmHandle h, uint32 *t)
uint32 dlc
The length of the message.
Definition: kvmlib.h:255
kvmStatus kvmLogFileMount(kvmHandle h, uint32 fileIndx, uint32 *eventCount)
kvmHandle kvmKmfOpenEx(const char *filename, kvmStatus *status, int32 deviceType, int *ldfMajor, int *ldfMinor)
No disk found.
Definition: kvmlib.h:145
Start time not found.
Definition: kvmlib.h:141
A trigger message.
Definition: kvmlib.h:272
kvmStatus kvmKmeCountEventsEx(kmeFileHandle h, int64 *eventCount)
uint32 fwMajor
Definition: kvmlib.h:287
uint32_t uint32
Definition: kvmlib.h:55
int16_t int16
Definition: kvmlib.h:52
int64_t int64
Definition: kvmlib.h:56
kvmStatus kvmDeviceSetRTC(kvmHandle h, uint32 t)
End of file found.
Definition: kvmlib.h:144
kvmStatus kvmKmfGetDbaseFile(kvmHandle h, char *path, char *filenamebuf, size_t buflen)
Disk is write protected.
Definition: kvmlib.h:169
User abort.
Definition: kvmlib.h:166
kvmStatus kvmKmfValidate(kvmHandle h)
int32_t int32
Definition: kvmlib.h:54
kmeFileHandle kvmKmeOpenFile(const char *filename, kvmStatus *status, int32 fileType)
Device occupied.
Definition: kvmlib.h:165
A RTC clock message.
Definition: kvmlib.h:263
Error while reading log file.
Definition: kvmlib.h:146
kvmStatus kvmDeviceMountKmfEx(kvmHandle h, int *ldfMajor, int *ldfMinor)
uint32 fwMinor
Definition: kvmlib.h:288
kvmStatus kvmLogFileMountEx(kvmHandle h, uint32 fileIndx, int64 *eventCount)
kvmStatus kvmLogFileDismount(kvmHandle h)
uint32 lioMinor
Definition: kvmlib.h:286
A CAN message.
Definition: kvmlib.h:251
uint32 channel
The device channel on which the message arrived, 0,1,...
Definition: kvmlib.h:254
Not implemented.
Definition: kvmlib.h:157
kvmStatus kvmKmfWriteConfig(kvmHandle h, void *buf, size_t buflen)
File system corrupt.
Definition: kvmlib.h:155
kvmStatus kvmLogFileReadEvent(kvmHandle h, kvmLogEventEx *e)
uint32 flags
Message flags canMSG_xxx.
Definition: kvmlib.h:256
Queue is full.
Definition: kvmlib.h:147
Error writing log file.
Definition: kvmlib.h:143
kvmStatus kvmKmeReadEvent(kmeFileHandle h, kvmLogEventEx *e)
Generic error.
Definition: kvmlib.h:138
The union of events used by kvmKmeReadEvent().
Definition: kvmlib.h:313
kvmStatus kvmLogFileGetType(kvmHandle h, uint32 fileIndx, int32 *logFileType)
kvmStatus kvmLogFileGetCreatorSerial(kvmHandle h, uint32 *serialNumber)
uint32 calendarTime
RTC date, seconds since 1970-01-01T00:00:00+00:00 (UTC)
Definition: kvmlib.h:264
uint32 type
kvmLOG_TYPE_xxx, Event types in log
Definition: kvmlib.h:314
kmeFileHandle kvmKmeCreateFile(const char *filename, kvmStatus *status, int32 fileType)
kvmStatus kvmGetErrorText(kvmStatus error, char *buf, size_t len)
kvmStatus kvmKmeWriteEvent(kmeFileHandle h, kvmLogEventEx *e)
Can&#39;t find/open log file.
Definition: kvmlib.h:140
Disk full (directory).
Definition: kvmlib.h:152