kvmlib.h
Go to the documentation of this file.
1 /*
2 * Copyright 2017 by Kvaser AB, Molndal, Sweden
3 * http://www.kvaser.com
4 *
5 * This software is dual licensed under the following two licenses:
6 * BSD-new and GPLv2. You may use either one. See the included
7 * COPYING file for details.
8 *
9 * License: BSD-new
10 * ==============================================================================
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * * Neither the name of the <organization> nor the
19 * names of its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
30 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 *
35 * License: GPLv2
36 * ==============================================================================
37 * This program is free software; you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation; either version 2 of the License, or
40 * (at your option) any later version.
41 *
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
46 *
47 * You should have received a copy of the GNU General Public License
48 * along with this program; if not, write to the Free Software
49 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
50 *
51 *
52 * IMPORTANT NOTICE:
53 * ==============================================================================
54 * This source code is made available for free, as an open license, by Kvaser AB,
55 * for use with its applications. Kvaser AB does not accept any liability
56 * whatsoever for any third party patent or other immaterial property rights
57 * violations that may result from any usage of this source code, regardless of
58 * the combination of source code and various applications that it can be used
59 * in, or with.
60 *
61 * -----------------------------------------------------------------------------
62 */
63 
64 #ifndef KVMLIB_H
65 #define KVMLIB_H
66 
101 #define WINAPI
102 #define INVALID_HANDLE_VALUE NULL
103 typedef void* HANDLE;
104 #include <stdint.h>
105 #include <stdio.h>
106 
107 typedef int8_t int8;
108 typedef uint8_t uint8;
109 typedef int16_t int16;
110 typedef uint16_t uint16;
111 typedef int32_t int32;
112 typedef uint32_t uint32;
113 typedef int64_t int64;
114 
115 
116 #ifdef __cplusplus
117 extern "C" {
118 #endif
119 
128 #define kvmDEVICE_MHYDRA 0
129 #define kvmDEVICE_MHYDRA_EXT 1
130 
140 #define kvmLDF_MAJOR_CAN 3
141 #define kvmLDF_MAJOR_CAN64 5
142 
147 typedef HANDLE kmeFileHandle;
148 
157 #define kvmFS_FAT16 0
158 #define kvmFS_FAT32 1
159 
169 #define kvmFILE_KME24 0
170 #define kvmFILE_KME25 1
171 #define kvmFILE_KME40 2
172 #define kvmFILE_KME50 3
173 #define kvmFILE_KME60 4
174 
179 typedef HANDLE kvmHandle;
180 
181 
192  // If you change here, remember to also change kvmlib.cpp and kvmlibtest...
193 typedef enum {
194  kvmOK = 0,
195  kvmFail = -1,
201  kvmEOF = -12,
228 
229 } kvmStatus;
240 #define kvmLogFileType_ERR 0
241 #define kvmLogFileType_ALL 1
242 
253 #define kvm_SWINFO_KVMLIB 1
254 #define kvm_SWINFO_DRIVER 2
255 #define kvm_SWINFO_FIRMWARE 3
256 #define kvm_SWINFO_DRIVER_PRODUCT 4
257 #define kvm_SWINFO_CONFIG_VERSION_NEEDED 5
258 #define kvm_SWINFO_CPLD_VERSION 6
259 
261 #include <pshpack1.h>
262 
263 #ifndef canMSG_RTR
264 
273 # define canMSG_RTR 0x0001
274 # define canMSG_STD 0x0002
275 # define canMSG_EXT 0x0004
276 # define canMSG_ERROR_FRAME 0x0020
277 # define canMSG_TXACK 0x0040
278 # define canMSG_TXRQ 0x0080
279 # define canMSGERR_OVERRUN 0x0600
280 # define canFDMSG_EDL 0x010000
281 # define canFDMSG_FDF 0x010000
282 # define canFDMSG_BRS 0x020000
283 # define canFDMSG_ESI 0x040000
284 
285 #endif
286 
295 #define TRIGVAR_TYPE_MSG_ID 0
296 #define TRIGVAR_TYPE_MSG_DLC 1
297 #define TRIGVAR_TYPE_MSG_FLAG 2
298 #define TRIGVAR_TYPE_SIGVAL 3
299 #define TRIGVAR_TYPE_EXTERNAL 4
300 #define TRIGVAR_TYPE_TIMER 5
301 #define TRIGVAR_TYPE_DISK_FULL 6
302 #define TRIGVAR_TYPE_STARTUP 9
303 
308 typedef struct {
314  uint8 data[64];
315 } kvmLogMsgEx;
316 
320 typedef struct {
324 
325 
329 typedef struct {
336 
340 typedef struct
341 {
342  uint32 lioMajor; // Lio major version
343  uint32 lioMinor; // Lio minor version
344  uint32 fwMajor; // Firmware major version
345  uint32 fwMinor; // Firmware major version
346  uint32 fwBuild; // Firmware build version
347  uint32 serialNumber; // Serial number
348  uint32 eanHi; // EAN high bytes
349  uint32 eanLo; // EAN low bytes
351 
352 
360 #define kvmLOG_TYPE_INVALID 0
361 #define kvmLOG_TYPE_CLOCK 1
362 #define kvmLOG_TYPE_MSG 2
363 #define kvmLOG_TYPE_TRIGGER 3
364 #define kvmLOG_TYPE_VERSION 4
365 
370 typedef struct {
372  union {
377  uint8 raw[128];
378  } eventUnion;
379 } kvmLogEventEx;
380 
381 #include <poppack.h>
382 
392 void WINAPI kvmInitialize(void);
393 
409 kvmStatus WINAPI kvmGetVersion(int *major, int *minor, int *build);
410 
423 kvmStatus WINAPI kvmGetErrorText(kvmStatus error, char *buf, size_t len);
424 
442 
463  kvmStatus *status,
464  int32 deviceType);
465 
485 
507 kvmStatus WINAPI kvmDeviceMountKmfEx(kvmHandle h, int *ldfMajor, int *ldfMinor);
508 
533 kvmHandle WINAPI kvmKmfOpen(const char *filename,
534  kvmStatus *status,
535  int32 deviceType);
536 
564 kvmHandle WINAPI kvmKmfOpenEx(const char *filename,
565  kvmStatus *status,
566  int32 deviceType,
567  int *ldfMajor,
568  int *ldfMinor);
569 
584 
609  int fileSystem,
610  uint32 reserveSpace,
611  uint32 dbaseSpace);
612 
628 
644 kvmStatus WINAPI kvmLogFileGetType(kvmHandle h, uint32 fileIndx, int32 *logFileType);
645 
670  uint32 *eventCount);
671 
691  int64 *eventCount);
692 
705 
722  uint32 *startTime);
723 
740  uint32 *endTime);
741 
758  uint32 *serialNumber);
759 
777 
778 
793 
811 
829  uint32 *totalSectorCount,
830  uint32 *usedSectorCount);
831 
848 
863 kvmStatus WINAPI kvmDeviceGetSerialNumber(kvmHandle h, unsigned int *serial);
864 
884  int32 itemCode,
885  unsigned int *major,
886  unsigned int *minor,
887  unsigned int *build,
888  unsigned int *flags);
903 
904 
922 
940 
958  size_t buflen, size_t *actual_len);
959 
975 kvmStatus WINAPI kvmKmfWriteConfig(kvmHandle h, void *buf, size_t buflen);
976 
977 
997 kvmStatus WINAPI kvmKmfGetDbaseFile(kvmHandle h, char *path, char *filenamebuf, size_t buflen);
998 
1016 kvmStatus WINAPI kvmKmfPutDbaseFile(kvmHandle h, char *filename);
1017 
1032 
1051 kmeFileHandle WINAPI kvmKmeOpenFile (const char *filename,
1052  kvmStatus *status,
1053  int32 fileType);
1054 
1072 kvmStatus WINAPI kvmKmeScanFileType (const char *filename,
1073  int32 *fileType);
1074 
1096 kmeFileHandle WINAPI kvmKmeCreateFile (const char *filename,
1097  kvmStatus *status,
1098  int32 fileType);
1099 
1119 
1138 
1162 
1181 
1200 
1234 #ifdef __cplusplus
1235 }
1236 #endif
1237 
1238 #endif //KVMLIB_H
int32 postTrigger
Posttrigger time in milliseconds.
Definition: kvmlib.h:332
kvmStatus kvmClose(kvmHandle h)
Unsupported version.
Definition: kvmlib.h:213
Error writing log file.
Definition: kvmlib.h:200
Disk full (data).
Definition: kvmlib.h:210
uint32 eanLo
Definition: kvmlib.h:349
uint32 calendarTime
RTC date, seconds since 1970-01-01T00:00:00+00:00 (UTC)
Definition: kvmlib.h:321
kvmStatus kvmLogFileGetCount(kvmHandle h, uint32 *fileCount)
kmeFileHandle kvmKmeOpenFile(const char *filename, kvmStatus *status, int32 fileType)
kvmStatus kvmKmeCloseFile(kmeFileHandle h)
kvmStatus kvmDeviceDiskStatus(kvmHandle h, int *present)
uint32 channel
The device channel on which the message arrived, 0,1,...
Definition: kvmlib.h:311
#define WINAPI
Definition: kvmlib.h:101
Queue is full.
Definition: kvmlib.h:204
File not found.
Definition: kvmlib.h:217
HANDLE kvmHandle
A handle to a Memorator or equivalent KMF file.
Definition: kvmlib.h:179
uint32 id
The message identifier.
Definition: kvmlib.h:309
Configuration error.
Definition: kvmlib.h:225
kvmStatus kvmLogFileMount(kvmHandle h, uint32 fileIndx, uint32 *eventCount)
uint16_t uint16
Definition: kvmlib.h:110
A trigger message.
Definition: kvmlib.h:329
No log message found.
Definition: kvmlib.h:199
kvmStatus kvmDeviceGetRTC(kvmHandle h, uint32 *t)
kvmStatus kvmKmeWriteEvent(kmeFileHandle h, kvmLogEventEx *e)
HANDLE kmeFileHandle
A handle to a KME file.
Definition: kvmlib.h:147
kvmStatus kvmKmfGetUsage(kvmHandle h, uint32 *totalSectorCount, uint32 *usedSectorCount)
uint32 serialNumber
Definition: kvmlib.h:347
User abort.
Definition: kvmlib.h:223
kmeFileHandle kvmKmeCreateFile(const char *filename, kvmStatus *status, int32 fileType)
File system corrupt.
Definition: kvmlib.h:212
void * HANDLE
Definition: kvmlib.h:103
A version message.
Definition: kvmlib.h:340
uint32 trigMask
Bitmask with all active triggers.
Definition: kvmlib.h:333
Error while reading log file.
Definition: kvmlib.h:203
OK!
Definition: kvmlib.h:194
Timeout.
Definition: kvmlib.h:220
kvmStatus kvmDeviceFormatDisk(kvmHandle h, int fileSystem, uint32 reserveSpace, uint32 dbaseSpace)
kvmStatus kvmKmfEraseDbaseFile(kvmHandle h)
Disk is write protected.
Definition: kvmlib.h:226
kvmStatus kvmKmeCountEventsEx(kmeFileHandle h, int64 *eventCount)
Wrong disk type.
Definition: kvmlib.h:219
kvmStatus kvmKmfWriteConfig(kvmHandle h, void *buf, size_t buflen)
uint32 fwBuild
Definition: kvmlib.h:346
kvmStatus kvmDeviceFlashLeds(kvmHandle h)
End of file found.
Definition: kvmlib.h:201
kvmStatus kvmLogFileDismount(kvmHandle h)
kvmStatus kvmLogFileDeleteAll(kvmHandle h)
int64 timeStamp
The timestamp in units of 1 nanosecond.
Definition: kvmlib.h:334
int8_t int8
Definition: kvmlib.h:107
kvmStatus kvmKmfReadConfig(kvmHandle h, void *buf, size_t buflen, size_t *actual_len)
File I/O error.
Definition: kvmlib.h:207
int32 type
The type of trigger TRIGVAR_TYPE_xxx.
Definition: kvmlib.h:330
Disk not formatted.
Definition: kvmlib.h:218
uint32 flags
Message flags canMSG_xxx.
Definition: kvmlib.h:313
uint32 eanHi
Definition: kvmlib.h:348
kvmStatus kvmKmeScanFileType(const char *filename, int32 *fileType)
uint32 fwMajor
Definition: kvmlib.h:344
A RTC clock message.
Definition: kvmlib.h:320
Illegal request.
Definition: kvmlib.h:216
uint32 type
kvmLOG_TYPE_xxx, Event types in log
Definition: kvmlib.h:371
int64 timeStamp
The timestamp in units of 1 nanosecond.
Definition: kvmlib.h:322
A CAN message.
Definition: kvmlib.h:308
kvmStatus kvmLogFileGetType(kvmHandle h, uint32 fileIndx, int32 *logFileType)
int16_t int16
Definition: kvmlib.h:109
The union of events used by kvmKmeReadEvent().
Definition: kvmlib.h:370
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)
kvmStatus kvmGetErrorText(kvmStatus error, char *buf, size_t len)
kvmStatus kvmLogFileReadEvent(kvmHandle h, kvmLogEventEx *e)
uint32 lioMajor
Definition: kvmlib.h:342
kvmStatus kvmDeviceMountKmf(kvmHandle h)
CRC check failed.
Definition: kvmlib.h:205
kvmStatus kvmLogFileGetCreatorSerial(kvmHandle h, uint32 *serialNumber)
Firmware error.
Definition: kvmlib.h:224
kvmStatus kvmLogFileMountEx(kvmHandle h, uint32 fileIndx, int64 *eventCount)
int64_t int64
Definition: kvmlib.h:113
int64 timeStamp
The timestamp in units of 1 nanosecond.
Definition: kvmlib.h:310
Generic error.
Definition: kvmlib.h:195
kvmStatus kvmKmfValidate(kvmHandle h)
Fatal error.
Definition: kvmlib.h:215
kvmStatus kvmLogFileGetEndTime(kvmHandle h, uint32 *endTime)
Disk full (directory).
Definition: kvmlib.h:209
Not implemented.
Definition: kvmlib.h:214
kvmStatus kvmKmeReadEvent(kmeFileHandle h, kvmLogEventEx *e)
Device occupied.
Definition: kvmlib.h:222
General disk error.
Definition: kvmlib.h:208
kvmLogVersionEx ver
A version message.
Definition: kvmlib.h:376
uint32_t uint32
Definition: kvmlib.h:112
No disk found.
Definition: kvmlib.h:202
Device communication error.
Definition: kvmlib.h:221
kvmStatus
Definition: kvmlib.h:193
Sector unexpectadly erased.
Definition: kvmlib.h:206
uint32 dlc
The length of the message.
Definition: kvmlib.h:312
Error in supplied parameters.
Definition: kvmlib.h:196
Can&#39;t find/open log file.
Definition: kvmlib.h:197
uint32 lioMinor
Definition: kvmlib.h:343
kvmLogTriggerEx trig
A trigger message.
Definition: kvmlib.h:375
kvmStatus kvmLogFileGetStartTime(kvmHandle h, uint32 *startTime)
int64_t int64
Definition: kvlclib.h:122
uint8_t uint8
Definition: kvmlib.h:108
int32_t int32
Definition: kvmlib.h:111
kvmStatus kvmKmfGetDbaseFile(kvmHandle h, char *path, char *filenamebuf, size_t buflen)
Result is too big for an out-parameter.
Definition: kvmlib.h:227
kvmLogRtcClockEx rtc
An RTC message.
Definition: kvmlib.h:374
kvmStatus kvmDeviceSetRTC(kvmHandle h, uint32 t)
kvmStatus kvmDeviceDiskSize(kvmHandle h, uint32 *diskSize)
kvmHandle kvmKmfOpenEx(const char *filename, kvmStatus *status, int32 deviceType, int *ldfMajor, int *ldfMinor)
uint32 fwMinor
Definition: kvmlib.h:345
kvmHandle kvmKmfOpen(const char *filename, kvmStatus *status, int32 deviceType)
kvmStatus kvmKmeCountEvents(kmeFileHandle h, uint32 *eventCount)
kvmHandle kvmDeviceOpen(int32 cardNr, kvmStatus *status, int32 deviceType)
Start time not found.
Definition: kvmlib.h:198
void kvmInitialize(void)
Unexpected sequence.
Definition: kvmlib.h:211
kvmStatus kvmKmfPutDbaseFile(kvmHandle h, char *filename)
kvmLogMsgEx msg
A CAN message.
Definition: kvmlib.h:373
kvmStatus kvmGetVersion(int *major, int *minor, int *build)
int32 preTrigger
Pretrigger time in milliseconds.
Definition: kvmlib.h:331
kvmStatus kvmDeviceGetSerialNumber(kvmHandle h, unsigned int *serial)