Commit 18cc56bb by developer4

template version 1.0

parent 9cd65fdb
This diff is collapsed. Click to expand it.
[submodule "lib"]
path = lib
url = https://git.d-logic.net/nfc-rfid-reader-sdk/ufr-lib.git
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>template-console</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/MINGW_HOME/delimiter=;
environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/MINGW_HOME/operation=replace
environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/MINGW_HOME/value=C\:\\mingw32
environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/append=true
environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.1284259793/appendContributed=true
environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/MINGW_HOME/delimiter=;
environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/MINGW_HOME/operation=replace
environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/MINGW_HOME/value=C\:\\mingw64
environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/append=true
environment/project/cdt.managedbuild.config.gnu.mingw.exe.debug.1203933141.242952993/appendContributed=true
environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/MINGW_HOME/delimiter=;
environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/MINGW_HOME/operation=replace
environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/MINGW_HOME/value=C\:\\mingw32
environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/append=true
environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1810471863/appendContributed=true
environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/MINGW_HOME/delimiter=;
environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/MINGW_HOME/operation=replace
environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/MINGW_HOME/value=C\:\\mingw64
environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/append=true
environment/project/cdt.managedbuild.config.gnu.mingw.exe.release.445926757.1814614570/appendContributed=true
eclipse.preferences.version=1
encoding/<project>=UTF-8
eclipse.preferences.version=1
line.separator=\r\n
eclipse.preferences.version=1
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
lib @ 70617467
Subproject commit 70617467346c37a45fd0514a02de78a002ba8066
/*
* conio_gnu.c
*
* Created on: 31.05.2016.
* Author: d-logic (http://www.d-logic.net/nfc-rfid-reader-sdk/)
*/
#if linux || __linux__ || __APPLE__
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/ioctl.h>
static struct termios old, new;
// Initialize new terminal i/o settings:
void _initTermios(int echo)
{
tcgetattr(0, &old); // grab old terminal i/o settings
new = old; // make new settings same as old settings
new.c_lflag &= ~ICANON; // disable buffered i/o
new.c_lflag &= echo ? ECHO : ~ECHO; // set echo mode
tcsetattr(0, TCSANOW, &new); // use these new terminal i/o settings now
}
// Restore old terminal i/o settings:
void _resetTermios(void)
{
tcsetattr(0, TCSANOW, &old);
}
// Read 1 character:
char _getch(void)
{
return getchar();
}
int _kbhit(void)
{
int byteswaiting;
ioctl(0, FIONREAD, &byteswaiting);
return byteswaiting > 0;
}
#endif // linux || __linux__ || __APPLE__
/*
* conio_gnu.h
*
* Created on: 31.05.2016.
* Author: d-logic (http://www.d-logic.net/nfc-rfid-reader-sdk/)
*/
#ifndef CONIO_GNU_H_
#define CONIO_GNU_H_
#if linux || __linux__ || __APPLE__
void _initTermios(int echo);
void _resetTermios(void);
char _getch(void);
int _kbhit(void);
#endif // linux || __linux__ || __APPLE__
#endif /* CONIO_GNU_H_ */
/*
* ini.h
*/
#ifndef INI_H_
#define INI_H_
#define APP_VERSION "0.0"
#define EXIT_ON_WRONG_FW_DEPENDENCY
#define MIN_DEPEND_FW_VER_MAJOR 0
#define MIN_DEPEND_FW_VER_MINOR 0
#define MIN_DEPEND_FW_VER_BUILD 0
#define EXIT_ON_WRONG_LIB_DEPENDENCY
#define MIN_DEPEND_LIB_VER_MAJOR 0
#define MIN_DEPEND_LIB_VER_MINOR 0
#define MIN_DEPEND_LIB_VER_BUILD 0
#ifdef __DEBUG
# if __WIN32 || __WIN64
# define PORT_NAME "COM3"
# else
# define PORT_NAME "/dev/ttyS3"
# endif
#endif
#endif /* INI_H_ */
/*
============================================================================
Project Name: project_name
Name : file_name.c
Author : d-logic (http://www.d-logic.net/nfc-rfid-reader-sdk/)
Version :
Copyright : 2017.
Description : Project in C (Language standard: c99)
Dependencies: uFR firmware - min. version x.y.z {define in ini.h}
uFRCoder library - min. version x.y.z {define in ini.h}
============================================================================
*/
/* includes:
* stdio.h & stdlib.h are included by default (for printf and LARGE_INTEGER.QuadPart (long long) use %lld or %016llx).
* inttypes.h, stdbool.h & string.h included for various type support and utilities.
* conio.h is included for windows(dos) console input functions.
* windows.h is needed for various timer functions (GetTickCount(), QueryPerformanceFrequency(), QueryPerformanceCounter())
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#if __WIN32 || __WIN64
# include <conio.h>
# include <windows.h>
#elif linux || __linux__ || __APPLE__
# define __USE_MISC
# include <unistd.h>
# include <termios.h>
# undef __USE_MISC
# include "conio_gnu.h"
#else
# error "Unknown build platform."
#endif
#include <uFCoder.h>
#include "ini.h"
#include "uFR.h"
#include "utils.h"
//------------------------------------------------------------------------------
void usage(void);
void menu(char key);
UFR_STATUS NewCardInField(uint8_t sak, uint8_t *uid, uint8_t uid_size);
void Operation1(void);
void Operation2(void);
void Operation3(void);
//------------------------------------------------------------------------------
int main(void)
{
char key;
bool card_in_field = false;
uint8_t old_sak = 0, old_uid_size = 0, old_uid[10];
uint8_t sak, uid_size, uid[10];
UFR_STATUS status;
usage();
printf(" --------------------------------------------------\n");
printf(" Please wait while opening uFR NFC reader.\n");
printf(" --------------------------------------------------\n");
#ifdef __DEBUG
status = ReaderOpenEx(1, PORT_NAME, 1, NULL);
#else
status = ReaderOpen();
#endif
if (status != UFR_OK)
{
printf("Error while opening device, status is: 0x%08X\n", status);
getchar();
return EXIT_FAILURE;
}
if (!CheckDependencies())
{
ReaderClose();
getchar();
return EXIT_FAILURE;
}
status = ReaderReset();
if (status != UFR_OK)
{
printf("Error while opening device, status is: 0x%08X\n", status);
getchar();
return EXIT_FAILURE;
}
printf(" --------------------------------------------------\n");
printf(" uFR NFC reader successfully opened.\n");
printf(" --------------------------------------------------\n");
#if linux || __linux__ || __APPLE__
_initTermios(0);
#endif
do
{
while (!_kbhit())
{
status = GetCardIdEx(&sak, uid, &uid_size);
switch (status)
{
case UFR_OK:
if (card_in_field)
{
if (old_sak != sak || old_uid_size != uid_size || memcmp(old_uid, uid, uid_size))
{
old_sak = sak;
old_uid_size = uid_size;
memcpy(old_uid, uid, uid_size);
NewCardInField(sak, uid, uid_size);
}
}
else
{
old_sak = sak;
old_uid_size = uid_size;
memcpy(old_uid, uid, uid_size);
NewCardInField(sak, uid, uid_size);
card_in_field = true;
}
break;
case UFR_NO_CARD:
card_in_field = false;
status = UFR_OK;
break;
default:
ReaderClose();
printf(" Fatal error while trying to read card, status is: 0x%08X\n", status);
getchar();
#if linux || __linux__ || __APPLE__
_resetTermios();
tcflush(0, TCIFLUSH); // Clear stdin to prevent characters appearing on prompt
#endif
return EXIT_FAILURE;
}
#if __WIN32 || __WIN64
Sleep(300);
#else // if linux || __linux__ || __APPLE__
usleep(300000);
#endif
}
key = _getch();
menu(key);
}
while (key != '\x1b');
ReaderClose();
#if linux || __linux__ || __APPLE__
_resetTermios();
tcflush(0, TCIFLUSH); // Clear stdin to prevent characters appearing on prompt
#endif
return EXIT_SUCCESS;
}
//------------------------------------------------------------------------------
void menu(char key)
{
switch (key)
{
case '1':
Operation1();
break;
case '2':
Operation2();
break;
case '3':
Operation3();
break;
case '\x1b':
break;
default:
usage();
break;
}
}
//------------------------------------------------------------------------------
void usage(void)
{
printf(" +------------------------------------------------+\n"
" | Application title |\n"
" | version "APP_VERSION" |\n"
" +------------------------------------------------+\n"
" For exit, hit escape.\n");
printf(" --------------------------------------------------\n");
printf(" (1) - Option 1\n"
" (2) - Option 2\n"
" (3) - Option 3\n");
}
//------------------------------------------------------------------------------
UFR_STATUS NewCardInField(uint8_t sak, uint8_t *uid, uint8_t uid_size)
{
UFR_STATUS status;
uint8_t dl_card_type;
status = GetDlogicCardType(&dl_card_type);
if (status != UFR_OK)
return status;
printf(" \a-------------------------------------------------------------------\n");
printf(" Card type: %s, sak = 0x%02X, uid[%d] = ", GetDlTypeName(dl_card_type), sak, uid_size);
print_hex_ln(uid, uid_size, ":");
printf(" -------------------------------------------------------------------\n");
return UFR_OK;
}
//------------------------------------------------------------------------------
void Operation1(void)
{
printf(" -------------------------------------------------------------------\n");
printf(" Operation 1 \n");
printf(" -------------------------------------------------------------------\n");
}
//------------------------------------------------------------------------------
void Operation2(void)
{
printf(" -------------------------------------------------------------------\n");
printf(" Operation 2 \n");
printf(" -------------------------------------------------------------------\n");
}
//------------------------------------------------------------------------------
void Operation3(void)
{
printf(" -------------------------------------------------------------------\n");
printf(" Operation 3 \n");
printf(" -------------------------------------------------------------------\n");
}
//------------------------------------------------------------------------------
/*
* uFR.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdbool.h>
#include <uFCoder.h>
#include "ini.h"
#include "uFR.h"
//------------------------------------------------------------------------------
bool CheckDependencies(void) {
#if defined(EXIT_ON_WRONG_FW_DEPENDENCY) || defined(EXIT_ON_WRONG_LIB_DEPENDENCY)
uint8_t version_major, version_minor, build;
bool wrong_version = false;
#endif
UFR_STATUS status;
#ifdef EXIT_ON_WRONG_LIB_DEPENDENCY
uint32_t dwDllVersion = 0;
dwDllVersion = GetDllVersion();
// "explode" the uFCoder library version:
version_major = (uint8_t)dwDllVersion;
version_minor = (uint8_t)(dwDllVersion >> 8);
// Get the uFCoder library build number.
build = (uint8_t)(dwDllVersion >> 16);
if (version_major < MIN_DEPEND_LIB_VER_MAJOR) {
wrong_version = true;
} else if (version_major == MIN_DEPEND_LIB_VER_MAJOR && version_minor < MIN_DEPEND_LIB_VER_MINOR) {
wrong_version = true;
} else if (version_major == MIN_DEPEND_LIB_VER_MAJOR && version_minor == MIN_DEPEND_LIB_VER_MINOR && build < MIN_DEPEND_LIB_VER_BUILD) {
wrong_version = true;
}
if (wrong_version) {
printf("Wrong uFCoder library version (%d.%d.%d).\n"
"Please update uFCoder library to at last %d.%d.%d version.\n",
version_major, version_minor, build,
MIN_DEPEND_LIB_VER_MAJOR, MIN_DEPEND_LIB_VER_MINOR, MIN_DEPEND_LIB_VER_BUILD);
return false;
}
#endif
#ifdef EXIT_ON_WRONG_FW_DEPENDENCY
wrong_version = false;
status = GetReaderFirmwareVersion(&version_major, &version_minor);
if (status != UFR_OK) {
printf("Error while checking firmware version, status is: 0x%08X\n", status);
}
status = GetBuildNumber(&build);
if (status != UFR_OK) {
printf("Error while firmware version, status is: 0x%08X\n", status);
}
if (version_major < MIN_DEPEND_FW_VER_MAJOR) {
wrong_version = true;
} else if (version_major == MIN_DEPEND_FW_VER_MAJOR && version_minor < MIN_DEPEND_FW_VER_MINOR) {
wrong_version = true;
} else if (version_major == MIN_DEPEND_LIB_VER_MAJOR && version_minor == MIN_DEPEND_FW_VER_MINOR && build < MIN_DEPEND_FW_VER_BUILD) {
wrong_version = true;
}
if (wrong_version) {
printf("Wrong uFR NFC reader firmware version (%d.%d.%d).\n"
"Please update uFR firmware to at last %d.%d.%d version.\n",
version_major, version_minor, build,
MIN_DEPEND_FW_VER_MAJOR, MIN_DEPEND_FW_VER_MINOR, MIN_DEPEND_FW_VER_BUILD);
return false;
}
#endif
return true;
}
//------------------------------------------------------------------------------
sz_ptr GetDlTypeName(uint8_t dl_type_code) {
switch (dl_type_code) {
case DL_MIFARE_ULTRALIGHT:
return "DL_MIFARE_ULTRALIGHT";
case DL_MIFARE_ULTRALIGHT_EV1_11:
return "DL_MIFARE_ULTRALIGHT_EV1_11";
case DL_MIFARE_ULTRALIGHT_EV1_21:
return "DL_MIFARE_ULTRALIGHT_EV1_21";
case DL_MIFARE_ULTRALIGHT_C:
return "DL_MIFARE_ULTRALIGHT_C";
case DL_NTAG_203:
return "DL_NTAG_203";
case DL_NTAG_210:
return "DL_NTAG_210";
case DL_NTAG_212:
return "DL_NTAG_212";
case DL_NTAG_213:
return "DL_NTAG_213";
case DL_NTAG_215:
return "DL_NTAG_215";
case DL_NTAG_216:
return "DL_NTAG_216";
case DL_MIKRON_MIK640D:
return "DL_MIKRON_MIK640D";
case DL_MIFARE_MINI:
return "DL_MIFARE_MINI";
case DL_MIFARE_CLASSIC_1K:
return "DL_MIFARE_CLASSIC_1K";
case DL_MIFARE_CLASSIC_4K:
return "DL_MIFARE_CLASSIC_4K";
case DL_MIFARE_PLUS_S_2K:
return "DL_MIFARE_PLUS_S_2K";
case DL_MIFARE_PLUS_S_4K:
return "DL_MIFARE_PLUS_S_4K";
case DL_MIFARE_PLUS_X_2K:
return "DL_MIFARE_PLUS_X_2K";
case DL_MIFARE_PLUS_X_4K:
return "DL_MIFARE_PLUS_X_4K";
case DL_MIFARE_DESFIRE:
return "DL_MIFARE_DESFIRE";
case DL_MIFARE_DESFIRE_EV1_2K:
return "DL_MIFARE_DESFIRE_EV1_2K";
case DL_MIFARE_DESFIRE_EV1_4K:
return "DL_MIFARE_DESFIRE_EV1_4K";
case DL_MIFARE_DESFIRE_EV1_8K:
return "DL_MIFARE_DESFIRE_EV1_8K";
case DL_MIFARE_DESFIRE_EV2_2K:
return "DL_MIFARE_DESFIRE_EV2_2K";
case DL_MIFARE_DESFIRE_EV2_4K:
return "DL_MIFARE_DESFIRE_EV2_4K";
case DL_MIFARE_DESFIRE_EV2_8K:
return "DL_MIFARE_DESFIRE_EV2_8K";
case DL_GENERIC_ISO14443_4:
return "DL_GENERIC_ISO_14443_4";
case DL_GENERIC_ISO14443_TYPE_B:
return "DL_GENERIC_ISO14443_TYPE_B";
case DL_IMEI_UID:
return "DL_IMEI_UID";
}
return "UNKNOWN CARD";
}
//------------------------------------------------------------------------------
/*
* uFR.h
*/
#ifndef UFR_H_
#define UFR_H_
#include "ini.h"
//------------------------------------------------------------------------------
typedef const char * sz_ptr;
//------------------------------------------------------------------------------
bool CheckDependencies(void);
sz_ptr GetDlTypeName(uint8_t dl_type_code);
//------------------------------------------------------------------------------
#endif /* UFR_H_ */
/*
* utils.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include "ini.h"
#include "utils.h"
//------------------------------------------------------------------------------
size_t hex2bin(uint8_t *dst, const char *src) {
size_t dst_len = 0;
char s_tmp[3];
s_tmp[2] = '\0';
while (*src) {
while (((char)*src < '0' || (char)*src > '9')
&& ((char)*src < 'a' || (char)*src > 'f')
&& ((char)*src < 'A' || (char)*src > 'F'))
src++; // skip delimiters, white spaces, etc.
s_tmp[0] = (char) *src++;
// Must be pair of the hex digits:
if (!(*src))
break;
// And again, must be pair of the hex digits:
if (((char)*src < '0' || (char)*src > '9')
&& ((char)*src < 'a' || (char)*src > 'f')
&& ((char)*src < 'A' || (char)*src > 'F'))
break;
s_tmp[1] = (char) *src++;
*dst++ = strtoul(s_tmp, NULL, 16);
dst_len++;
}
return dst_len;
}
//------------------------------------------------------------------------------
void print_ln_len(char symbol, uint8_t cnt) {
for (int i = 0; i < cnt; i++)
printf("%c", symbol);
printf("\n");
}
//------------------------------------------------------------------------------
inline void print_ln(char symbol) {
print_ln_len(symbol, DEFAULT_LINE_LEN);
}
//------------------------------------------------------------------------------
void print_hex(const uint8_t *data, uint32_t len, const char *delimiter) {
for (int i = 0; i < len; i++) {
printf("%02X", data[i]);
if ((delimiter != NULL) && (i < (len - 1)))
printf("%c", *delimiter);
}
}
//------------------------------------------------------------------------------
void print_hex_ln(const uint8_t *data, uint32_t len, const char *delimiter) {
print_hex(data, len, delimiter);
printf("\n");
}
//==============================================================================
/*
* utils.h
*/
#ifndef UTILS_H_
#define UTILS_H_
#define DEFAULT_LINE_LEN 60
size_t hex2bin(uint8_t *dst, const char *src);
void print_ln_len(char symbol, uint8_t cnt);
void print_ln(char symbol);
void print_hex(const uint8_t *data, uint32_t len, const char *delimiter);
void print_hex_ln(const uint8_t *data, uint32_t len, const char *delimiter);
#endif /* UTILS_H_ */
@echo off
set path=..\lib\windows\x86;%path%
template-console.exe
@echo off
set path=..\lib\windows\x86_64;%path%
template-console.exe
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment