]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
barcode: Testing version of barcode app.
authorMiroslav Strob <strobmir@fel.cvut.cz>
Fri, 8 Apr 2011 09:03:49 +0000 (11:03 +0200)
committerMiroslav Strob <strobmir@fel.cvut.cz>
Fri, 8 Apr 2011 09:03:49 +0000 (11:03 +0200)
The program is not working properly. It resets the arm board connected via USB.

src/barcode/Makefile.omk
src/barcode/barcode.c

index b6f866825ad9c7a11ea3ccb7c920584e5867377e..a1648d7aac060bce90ce077135ac6337a5f4d2a9 100644 (file)
@@ -2,8 +2,8 @@
 
 bin_PROGRAMS = barcode
 
-hokuyo_SOURCES = barcode.c
+barcode_SOURCES = barcode.c
 
 include_HEADERS = barcode.h
 
-lib_LOADLIBES = pthread roboorte robottype orte m rt
+lib_LOADLIBES = pthread roboorte robottype orte sercom
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..674dc9a8ee31409f1b50079430327e62e0c6748b 100644 (file)
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <sercom.h>
+#include <string.h>
+#include <pthread.h>
+#include "barcode.h"
+
+static struct sercom_data sercom;
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+int barcode_sercom_init(char * tty, void(*sighandler)(int)) 
+{
+       int ret;
+       strcpy((char *)&sercom.devname, tty);
+       sercom.baudrate = 9600;
+       sercom.parity = SERCOM_PARNONE;
+       sercom.databits = 8;
+       sercom.stopbits = 1;
+       sercom.mode = 0;
+       sercom.sighandler = NULL;
+       ret = sercom_open(&sercom);
+       if (ret < 0)
+               return -1;
+       else
+               return 0;
+}
+
+
+int barcode_read(unsigned char *buff, int size)
+{
+       int ret;
+       pthread_mutex_lock(&mutex);
+       ret = read(sercom.fd, buff, size);
+       pthread_mutex_unlock(&mutex);
+       if(ret != size) {
+                printf("uoled: READ FAILED!\n");
+                return -1;
+        }
+       // jinak vracim prvni
+        return ret;
+}
+
+int main(void)
+{  
+  barcode_sercom_init("/dev/ttyUSB0", NULL);
+  
+  
+  unsigned char rcmd[10];
+  
+  barcode_read(rcmd, 3);
+  
+  printf("%s\n", rcmd);
+  
+  return 0; 
+}