Project

General

Profile

Download (2.45 KB) Statistics
| Branch: | Tag: | Revision:
1
/* opcd_presence - posts lst seen tag id to selected web page. This tool
2
 * depends on the main_presence firmware
3
 *
4
 * (C) 2006 by Milosch Meriac <meriac@openpcd.de>
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License version 2 
8
 *  as published by the Free Software Foundation
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 */
19

    
20
#include <stdio.h>
21
#include <stdlib.h>
22
#include <unistd.h>
23
#include <string.h>
24
#define _GNU_SOURCE
25
#include <getopt.h>
26
#include <errno.h>
27

    
28
#include <sys/types.h>
29
#include <sys/stat.h>
30
#include <sys/mman.h>
31
#include <fcntl.h>
32

    
33
#include <usb.h>
34

    
35
#include <openpcd.h>
36
#include "opcd_usb.h"
37

    
38
#include <curl/curl.h>
39

    
40
int main(int argc, char **argv)
41
{
42
	struct opcd_handle *od;
43
	int retlen;
44
	unsigned int uid;
45
	unsigned char *data;
46
	static unsigned char buf[8192];
47
	CURL *curl;
48
	CURLcode res;
49
	
50
	curl = curl_easy_init();
51
	if(!curl)
52
	{
53
	    printf("Can't open CURL library\n");
54
	    exit(1);
55
	}
56
	
57
	curl_easy_setopt(curl, CURLOPT_URL, "http://medusa.benutzerserver.de/openpcd.announce.php");
58
	curl_easy_setopt(curl, CURLOPT_POST, 1);
59
	
60
	od = NULL;
61

    
62
	while (1)
63
	{
64
	    if(od)
65
	    {
66
		retlen = opcd_send_command(od, OPENPCD_CMD_PRESENCE_UID_GET, 0, 0, 0, NULL);    
67
		if(retlen<=0)
68
		{
69
		    opcd_fini(od);
70
		    od=NULL;
71
		}
72
		else
73
		{
74
		    retlen = opcd_recv_reply(od, (char*)buf, sizeof(struct openpcd_hdr)+4);
75
		    if (retlen == (sizeof(struct openpcd_hdr)+4) )
76
		    {
77
			data = buf + sizeof(struct openpcd_hdr);
78
		
79
			uid=	((unsigned int)data[0])<<24 |
80
				((unsigned int)data[1])<<16 |
81
				((unsigned int)data[2])<< 8 |
82
				((unsigned int)data[3]);
83

    
84
			sprintf((char*)buf,"uid=%08X",uid);
85
			printf("%s\n",buf);
86
			
87
			curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buf);
88
			res = curl_easy_perform(curl);
89
			if(res)
90
			    printf("CURL: error(%i)\n",res);
91
		    }
92
		}
93
	    }
94
	    else
95
	    {
96
		printf("STATUS: reinitializing\n");
97
		od = opcd_init(0);
98
	    }
99
	    // sleep for 250ms
100
	    usleep(1000*250);
101
	}
102
	
103
	  /* always cleanup */
104
	curl_easy_cleanup(curl);
105
	
106
	return(0);
107
}
(3-3/7)
Add picture from clipboard (Maximum size: 48.8 MB)