keytag.c
Go to the documentation of this file.00001
00045 #include "keytag.h"
00046
00047 #include <kern/kfile.h>
00048
00049 #include <drv/timer.h>
00050 #include <drv/ser.h>
00051
00052 #include <cfg/macros.h>
00053 #include <cfg/debug.h>
00054
00055 static void keytag_clearPkt(struct TagPacket *pkt)
00056 {
00057 pkt->sync = false;
00058 pkt->len = 0;
00059 }
00060
00061 void keytag_init(struct TagPacket *pkt)
00062 {
00063 keytag_clearPkt(pkt);
00064 }
00065
00066 void keytag_poll(struct TagPacket *pkt)
00067 {
00068 int c;
00069
00070
00071 while ((c = kfile_getc(&pkt->tag_ser->fd)) != EOF)
00072 {
00073
00074 if (c == TAG_STX)
00075 {
00076
00077 if (pkt->sync)
00078 kprintf("TAG double sync!\n");
00079 keytag_clearPkt(pkt);
00080 pkt->sync = true;
00081 }
00082 else if (pkt->sync)
00083 {
00084
00085 if (c == TAG_ETX)
00086 {
00087 pkt->buf[TAG_MAX_PRINT_CHARS] = '\x0';
00088
00089 kfile_printf(&pkt->comm_ser->fd, "tag %s", pkt->buf);
00090 pkt->sync = false;
00091 }
00092 else
00093 {
00094
00095 if (pkt->len >= TAG_MAX_LEN)
00096 {
00097 kprintf("TAG buffer overflow\n");
00098 pkt->sync = false;
00099 }
00100 else
00101 {
00102
00103 if (pkt->sync)
00104 {
00105 pkt->buf[pkt->len] = c;
00106 pkt->len++;
00107 }
00108 }
00109 }
00110 }
00111 }
00112 }