From e73b417c526bc32355487544b92db058459a5619 Mon Sep 17 00:00:00 2001 From: meri Date: Tue, 10 Apr 2007 22:10:10 +0000 Subject: opcd_presence: counterpart for main_presence firmware - posts sighted tags to URL via http protocol git-svn-id: https://svn.openpcd.org:2342/trunk@307 6dc7ffe9-61d6-0310-9af1-9938baff3ed1 --- host/Makefile | 7 +++- host/ausb/ausb.h | 3 ++ host/ausb/usb.c | 1 + host/ausb/usb.h | 5 +++ host/opcd_presence.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++ host/opcd_usb.c | 3 +- 6 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 host/opcd_presence.c diff --git a/host/Makefile b/host/Makefile index 12edce0..8d27808 100644 --- a/host/Makefile +++ b/host/Makefile @@ -1,8 +1,8 @@ #!/usr/bin/make LDFLAGS=-lusb -lcrypt #-lzebvty -Lzebvty/ -CFLAGS=-Wall +CFLAGS=-Wall -I../firmware/include -all: opcd_test opcd_sh +all: opcd_presence opcd_test opcd_sh clean: -rm -f *.o opcd_test @@ -11,6 +11,9 @@ clean: ausb/libausb.a: $(MAKE) -C ausb libausb.a +opcd_presence: opcd_presence.o opcd_usb.o ausb/libausb.a + $(CC) $(LDFLAGS) -L/usr/lib -lcurl -lidn -lssl -lcrypto -ldl -lz -o $@ $^ + opcd_test: opcd_test.o opcd_usb.o ausb/libausb.a $(CC) $(LDFLAGS) -o $@ $^ diff --git a/host/ausb/ausb.h b/host/ausb/ausb.h index 4d62cac..96247bb 100644 --- a/host/ausb/ausb.h +++ b/host/ausb/ausb.h @@ -9,6 +9,9 @@ * Distributed under the terms of GNU LGPL, Version 2.1 */ +#ifndef __user +#define __user +#endif/*__user*/ #include #include diff --git a/host/ausb/usb.c b/host/ausb/usb.c index 1f1078d..1d3aaf4 100644 --- a/host/ausb/usb.c +++ b/host/ausb/usb.c @@ -4,6 +4,7 @@ #include #include #include +#include "usb.h" #include #define MAX_READ_WRITE 4096 diff --git a/host/ausb/usb.h b/host/ausb/usb.h index 66be0ee..979d30c 100644 --- a/host/ausb/usb.h +++ b/host/ausb/usb.h @@ -1,5 +1,10 @@ #ifndef _AUSB_USB_H #define _AUSB_USB_H + +#ifndef __user +#define __user +#endif/*__user*/ + int __usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int length, int timeout); int __usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int length, diff --git a/host/opcd_presence.c b/host/opcd_presence.c new file mode 100644 index 0000000..47333df --- /dev/null +++ b/host/opcd_presence.c @@ -0,0 +1,107 @@ +/* opcd_test - Low-Level test program for OpenPCD + * (C) 2006 by Harald Welte + * + * 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 + * + * 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 + */ + +#define __user + +#include +#include +#include +#include +#define _GNU_SOURCE +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include "opcd_usb.h" + +#include + +int main(int argc, char **argv) +{ + struct opcd_handle *od; + int retlen; + unsigned int uid; + unsigned char *data; + static unsigned char buf[8192]; + CURL *curl; + CURLcode res; + + curl = curl_easy_init(); + if(!curl) + { + printf("Can't open CURL library\n"); + exit(1); + } + + curl_easy_setopt(curl, CURLOPT_URL, "http://medusa.benutzerserver.de/openpcd.announce.php"); + curl_easy_setopt(curl, CURLOPT_POST, 1); + + od = NULL; + + while (1) + { + if(od) + { + retlen = opcd_send_command(od, OPENPCD_CMD_PRESENCE_UID_GET, 0, 0, 0, NULL); + if(retlen<=0) + { + opcd_fini(od); + od=NULL; + } + else + { + retlen = opcd_recv_reply(od, (char*)buf, sizeof(struct openpcd_hdr)+4); + if (retlen == (sizeof(struct openpcd_hdr)+4) ) + { + data = buf + sizeof(struct openpcd_hdr); + + uid= ((unsigned int)data[0])<<24 | + ((unsigned int)data[1])<<16 | + ((unsigned int)data[2])<< 8 | + ((unsigned int)data[3]); + + sprintf((char*)buf,"uid=%08X",uid); + printf("%s\n",buf); + + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buf); + res = curl_easy_perform(curl); + if(res) + printf("CURL: error(%i)\n",res); + } + } + } + else + { + printf("STATUS: reinitializing\n"); + od = opcd_init(0); + } + // sleep for 250ms + usleep(1000*250); + } + + /* always cleanup */ + curl_easy_cleanup(curl); + + return(0); +} diff --git a/host/opcd_usb.c b/host/opcd_usb.c index d5f7db9..842a6f1 100644 --- a/host/opcd_usb.c +++ b/host/opcd_usb.c @@ -26,7 +26,7 @@ #include #include "ausb/ausb.h" -#include "../firmware/include/openpcd.h" +#include #include "opcd_usb.h" @@ -83,7 +83,6 @@ static void opcd_dump_hdr(struct openpcd_hdr *hdr) static void handle_interrupt(struct usbdevfs_urb *uurb, void *userdata) { - struct opcd_handle *od = userdata; ausb_dev_handle *ah; struct openpcd_hdr *opcdh; -- cgit v1.2.3