summaryrefslogtreecommitdiff
path: root/host/opcd_presence.c
diff options
context:
space:
mode:
authormeri <meri@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2007-04-10 22:10:10 +0000
committermeri <meri@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2007-04-10 22:10:10 +0000
commite73b417c526bc32355487544b92db058459a5619 (patch)
tree3519454064c19d4dd8a9080cf375cd69648562d6 /host/opcd_presence.c
parent6f440df07f8c30de45e944736ca2a11ae9ce3c43 (diff)
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
Diffstat (limited to 'host/opcd_presence.c')
-rw-r--r--host/opcd_presence.c107
1 files changed, 107 insertions, 0 deletions
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 <laforge@gnumonks.org>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#define _GNU_SOURCE
+#include <getopt.h>
+#include <errno.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+
+#include <usb.h>
+
+#include <openpcd.h>
+#include "opcd_usb.h"
+
+#include <curl/curl.h>
+
+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);
+}
personal git repositories of Harald Welte. Your mileage may vary