Newer
Older
/*
============================================================================
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>
#include "tools.h"
//-----------------------------
// OS specific
// extern int usleep (__useconds_t __useconds);
# define Sleep(x) usleep((x)*1000)
#endif
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
// UID for stop polling - exit from application
u8 stop_uid[4] = { 0x16, 0x78, 0x58, 0x56 };
//------------------------------------------------------------------
#define UID_STR_LEN_MAX 32
int fCB_OK(c_string sn, u8 uid[], int uid_len, int control_info)
{
TWR_STATUS e;
char uid_str[UID_STR_LEN_MAX + 1]; // +1 null character
size_t uid_str_len = UID_STR_LEN_MAX;
hex2str(uid, uid_len, uid_str, &uid_str_len);
// TODO: test hex2str() result
puts("");
puts("Application CB_OK is called ...");
printf("Arrived packet from TWR SN:[%8s] with UID[len:%d]= %s | "
"control_info= %d\n\n", sn, uid_len, uid_str, 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 <--");
}
//--------------------------------------------------------------
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((void *) fCB_Error);
printf("TWR_registerCB_Error(fCB_Error) : %s\n", TWR_Status2Str(e));
printf("TWR_registerCB_OK(fCB_OK) : %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;
}