forked from redBorder/rb_mse_api
/
examples.c
104 lines (88 loc) · 2.73 KB
/
examples.c
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
104
/*
** Copyright (C) 2014 Eneo Tecnologia S.L.
** Author: Eugenio Perez <eupm90@gmail.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License Version 2 as
** published by the Free Software Foundation. You may not use, modify or
** distribute this program under any other version of the GNU General
** Public License.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "rb_mse_api.h"
#include <assert.h>
#include <unistd.h>
#include <semaphore.h>
#define HORIZONTAL_LINE "---------------\n"
void stdout_stats_and_post_sem_cb(struct rb_mse_api *rb_mse, struct rb_mse_stats *stats, void *_sem)
{
sem_t * sem = _sem;
stdout_stats_cb(rb_mse,stats,NULL);
sem_post(sem);
}
void printUsage(char *argv0)
{
fprintf(stderr,"Usage: %s MSE_IP user:password MAC\n",argv0);
}
int main(int argc,char *argv[]){
sem_t sem;
sem_init(&sem,0,0);
if(argc!=4)
{
printUsage(argv[0]);
return(1);
}
struct rb_mse_api * rb_mse = rb_mse_api_new(5, argv[1], argv[2]);
rb_mse_set_stats_cb(rb_mse,stdout_stats_and_post_sem_cb,&sem);
assert(rb_mse);
assert(rb_mse_isempty(rb_mse));
rb_mse_debug_set(rb_mse,1);
CURLcode retCode = CURLE_OK;
if(retCode == CURLE_OK)
{
printf("Sleeping until mac_position filled\n");
sem_wait(&sem);
printf("Time to ask\n");
const struct rb_mse_api_pos *position= rb_mse_req_for_mac(rb_mse,argv[3]);
if(position)
{
printf(HORIZONTAL_LINE);
printf("Location of mac %s\n",argv[3]);
printf(HORIZONTAL_LINE);
printf("Currently tracked: %d\n",rb_mse_pos_currently_tracked(position));
printf(HORIZONTAL_LINE);
printf("floor: %s\n",rb_mse_pos_floor(position));
printf("build: %s\n",rb_mse_pos_build(position));
printf("zone: %s\n",rb_mse_pos_zone(position));
if(rb_mse_pos_geo_valid(position))
{
printf("lattitude: %lf\n",rb_mse_pos_geo_lattitude(position));
printf("longitude: %lf\n",rb_mse_pos_geo_longitude(position));
printf("unit: %s\n",rb_mse_pos_geo_unit(position));
}
else
{
printf("geo_data not valid\n");
}
}
else
{
fprintf(stderr,"position cannot be filled because some reason\n");
}
}
else
{
fprintf(stderr,"There was an error updating MAC positions: %s",curl_easy_strerror(retCode));
}
sleep(600); // Wating for auto-update.
rb_mse_api_destroy(rb_mse);
return 0;
}