Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
============================================================================
Name : twr-lib-tester.c
Author : Digital Logic
Description : Tester for twr-comm library
Tester for easy SN/ID
============================================================================
*/
#include "../lib/include/twr-comm.h"
//-----------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//-----------------------------
// OS specific
#include <windows.h>
//-----------------------------
static int polling = TRUE;
// UID for stop polling - exit from application
u8 stop_uid[4] = { 0x16, 0x78, 0x58, 0x56 };
int fCB_UID(c_string sn, u8 uid[], int uid_len, int control_info)
{
TWR_STATUS e;
int i;
puts("");
puts("Application CB_OK is called ...");
printf("Arrived packet from TWR SN=[%8s] with UID[len: %d]=", sn, uid_len);
// hex to string
for (i = 0; i < uid_len; ++i)
printf("%02X:", uid[i]);
printf(" | control_info= %d\n\n", control_info);
puts("Application send ACK...");
int r_status = 0; // OK
e = TWR_Packet_Ack(sn, uid, uid_len, control_info, r_status);
printf("TWR_Packet_Ack() : %s\n", TWR_Status2Str(e));
puts("");
puts("");
//--------------------------------------------------------------
// stop polling on specific UID
if (!memcmp(uid, stop_uid, sizeof(stop_uid)))
{
puts("--> STOP POLLING UID detected <--");
polling = FALSE;
}
//--------------------------------------------------------------
return 0;
}
int fCB_Error(int err_id, const char *err_msg)
{
printf("ERROR happens: id= %d | msg= %s\n", err_id, err_msg);
return 0;
}
int main(void)
{
TWR_STATUS e;
printf("Tester for TWR-comm library version: ");
puts(TWR_GetLibraryVersionStr());
e = TWR_registerCB_Error(fCB_Error);
printf("TWR_registerCB_Error(fCB_Error) : %s\n", TWR_Status2Str(e));
e = TWR_registerCB_UID(fCB_UID);
printf("TWR_registerCB_OK(fCB_UID) : %s\n", TWR_Status2Str(e));
//---
puts("Wait for SN/UID events...");
puts("");
while (polling)
{
e = TWR_Manager();
if (e)
{
printf("TWR_Manager() : %s\n", TWR_Status2Str(e));
break;
}
Sleep(1);
fflush(stdout);
}
puts("Done.");
puts("Tester exit!");
return EXIT_SUCCESS;
}