ifw-ll 1.0.0
 
Loading...
Searching...
No Matches
EKS.h
Go to the documentation of this file.
1#pragma once
2#include <Windows.h>
3#include <stdexcept>
4
5#define EKSAPI __declspec(dllexport) __stdcall
6
7constexpr ULONGLONG timeout = 2000;
8
9constexpr BYTE STX = 0x02;
10constexpr BYTE ETX = 0x03;
11constexpr BYTE DLE = 0x10;
12constexpr BYTE NAK = 0x15;
13
14constexpr BYTE CMD_SEND = 0x54;
15constexpr BYTE CMD_RESPONSE = 0x52;
16constexpr BYTE CMD_WRITE = 0x50;
17constexpr BYTE CMD_READ = 0x4C;
18constexpr BYTE CMD_RES_STATUS = 0x46;
19
20static BYTE accByte = DLE;
21static BYTE startByte = STX;
22static HANDLE hCom = INVALID_HANDLE_VALUE;
23static DWORD dwErr = 0;
24static COMSTAT comStat;
25enum class ResponseCode : BYTE
26{
27 SUCCESS = 0x00,
33 ERR_UNKNOWN = 0x40, // test highest byte only (0x4x)
35 ERR_IO = 0xF1,
38};
39
40class EKSError : std::exception
41{
42 const char* msg;
43
44 public:
46 EKSError() = delete;
47 EKSError(const ResponseCode& responseCode, const char* msg) noexcept : msg(msg), responseCode(responseCode){};
49 : responseCode(responseCode), msg("See response code for more information"){};
50 EKSError(const EKSError& other) noexcept : responseCode(other.responseCode), msg(other.msg){};
51 EKSError(EKSError&& other) noexcept : msg(std::move(other.msg)), responseCode(other.responseCode){};
52 const char* what() const noexcept { return msg; };
53};
54
55extern "C" VOID EKSAPI GetSysComm(BYTE* buffer);
56extern "C" HANDLE EKSAPI OpenComm(unsigned char port, unsigned int baud_rate = 9600);
57extern "C" VOID EKSAPI CloseComm(HANDLE pCom);
58extern "C" DWORD EKSAPI GetKeyStatus(HANDLE pCom);
59extern "C" DWORD EKSAPI GetSerialNumber(HANDLE pCom, BYTE* buffer);
60// Dont read at byte 16 or 16 bytes. The protocol is weird when sending 0x10 and i couldn't figure it out :(
61extern "C" DWORD EKSAPI ReadKeyData(HANDLE pCom, const BYTE startByte, const BYTE length, BYTE* buffer);
62// Not implemented
63extern "C" DWORD EKSAPI WriteKeyData(HANDLE pCom, const BYTE startByte, const BYTE length, const BYTE* buffer);
ResponseCode
Definition EKS.h:26
constexpr BYTE CMD_SEND
Definition EKS.h:14
constexpr BYTE CMD_READ
Definition EKS.h:17
VOID EKSAPI GetSysComm(BYTE *buffer)
Definition EKS.cpp:170
constexpr BYTE CMD_RES_STATUS
Definition EKS.h:18
DWORD EKSAPI WriteKeyData(HANDLE pCom, const BYTE startByte, const BYTE length, const BYTE *buffer)
constexpr BYTE CMD_WRITE
Definition EKS.h:16
#define EKSAPI
Definition EKS.h:5
DWORD EKSAPI GetKeyStatus(HANDLE pCom)
Definition EKS.cpp:244
constexpr BYTE DLE
Definition EKS.h:11
DWORD EKSAPI ReadKeyData(HANDLE pCom, const BYTE startByte, const BYTE length, BYTE *buffer)
Definition EKS.cpp:266
VOID EKSAPI CloseComm(HANDLE pCom)
Definition EKS.cpp:237
HANDLE EKSAPI OpenComm(unsigned char port, unsigned int baud_rate=9600)
Definition EKS.cpp:201
ResponseCode
Definition EKS.h:26
@ ERR_WRITE_PROTECTED
Definition EKS.h:34
@ ERR_NO_KEY_DETECTED
Definition EKS.h:28
@ ERR_CAN_ONLY_READ_R_KEYS
Definition EKS.h:31
@ ERR_CAN_ONLY_READ_RW_KEYS
Definition EKS.h:32
@ ERR_WRITE_BLOCKSIZE
Definition EKS.h:30
@ ERR_UNKNOWN
Definition EKS.h:33
@ ERR_IO
Definition EKS.h:35
@ ERR_COMMUNICATION
Definition EKS.h:36
@ ERR_CONNECTION
Definition EKS.h:37
@ SUCCESS
Definition EKS.h:27
@ ERR_PARITY_BIT
Definition EKS.h:29
constexpr BYTE NAK
Definition EKS.h:12
constexpr BYTE CMD_RESPONSE
Definition EKS.h:15
constexpr ULONGLONG timeout
Definition EKS.h:7
DWORD EKSAPI GetSerialNumber(HANDLE pCom, BYTE *buffer)
Definition EKS.cpp:263
#define STX
Definition RFID.cpp:13
#define ETX
Definition RFID.cpp:14
EKSError(const EKSError &other) noexcept
Definition EKS.h:50
EKSError()=delete
EKSError(const ResponseCode &responseCode) noexcept
Definition EKS.h:48
const ResponseCode responseCode
Definition EKS.h:45
EKSError(const ResponseCode &responseCode, const char *msg) noexcept
Definition EKS.h:47
EKSError(EKSError &&other) noexcept
Definition EKS.h:51
const char * what() const noexcept
Definition EKS.h:52