From ea9f2eb7d3ab9137f317d02404ff60f6806e1bb9 Mon Sep 17 00:00:00 2001 From: qwert Date: Wed, 23 Jul 2008 15:31:52 +0000 Subject: [PATCH] Refactoring code. Redefined TagPacket struct and keytag_init to support the new implementation. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1510 38d2e660-2303-0410-9eaa-f027e97ec537 --- app/triface/triface.c | 5 +---- bertos/net/keytag.c | 15 +++++++++------ bertos/net/keytag.h | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/triface/triface.c b/app/triface/triface.c index 4b45f221..c807eac5 100644 --- a/app/triface/triface.c +++ b/app/triface/triface.c @@ -84,10 +84,7 @@ int main(void) ser_init(&tag_ser, TAG_SER_PORT); ser_setbaudrate(&tag_ser, TAG_SER_BAUDRATE); - pkt.comm_ser = &fd_ser; - pkt.tag_ser = &tag_ser; - - keytag_init(&pkt); + keytag_init(&pkt, &fd_ser.fd, &tag_ser.fd); protocol_init(&fd_ser.fd); diff --git a/bertos/net/keytag.c b/bertos/net/keytag.c index 861169b4..68b51997 100644 --- a/bertos/net/keytag.c +++ b/bertos/net/keytag.c @@ -58,17 +58,20 @@ static void keytag_clearPkt(struct TagPacket *pkt) pkt->len = 0; } - void keytag_init(struct TagPacket *pkt) - { - keytag_clearPkt(pkt); - } +void keytag_init(struct TagPacket *pkt, struct KFile *comm, struct KFile *tag) +{ + keytag_clearPkt(pkt); + pkt->host = comm; + pkt->tag = tag; + +} void keytag_poll(struct TagPacket *pkt) { int c; /* Get all chars from buffer */ - while ((c = kfile_getc(&pkt->tag_ser->fd)) != EOF) + while ((c = kfile_getc(pkt->tag)) != EOF) { /* Search for STX char in received chars */ if (c == TAG_STX) @@ -86,7 +89,7 @@ static void keytag_clearPkt(struct TagPacket *pkt) { pkt->buf[TAG_MAX_PRINT_CHARS] = '\x0'; /* Write read TAG on communication serial */ - kfile_printf(&pkt->comm_ser->fd, "tag %s", pkt->buf); + kfile_printf(pkt->host, "tag %s", pkt->buf); pkt->sync = false; } else diff --git a/bertos/net/keytag.h b/bertos/net/keytag.h index 541005ea..b815a8b1 100644 --- a/bertos/net/keytag.h +++ b/bertos/net/keytag.h @@ -69,14 +69,14 @@ */ typedef struct TagPacket { - KFileSerial *tag_ser; // Tag serial - KFileSerial *comm_ser; // Communication serial - bool sync; // Status flag: true if we find an STX - uint16_t len; // Packet lenght - uint8_t buf[TAG_MAX_LEN]; // Reception buffer + KFile *tag; ///