From: asterix Date: Fri, 7 May 2010 09:21:00 +0000 (+0000) Subject: Clean up. Use log module. Add cfg file and move some setting to cfg. X-Git-Tag: 2.5.0~285 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=4c1f21207a513ed836c86143b550092bae866084;p=bertos.git Clean up. Use log module. Add cfg file and move some setting to cfg. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3623 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cfg/cfg_keytag.h b/bertos/cfg/cfg_keytag.h new file mode 100644 index 00000000..32b14e6a --- /dev/null +++ b/bertos/cfg/cfg_keytag.h @@ -0,0 +1,67 @@ +/** + * \file + * + * + * \brief Configuration file for keytag module. + * + * \author Daniele Basile + */ + +#ifndef CFG_KEYTAG_H +#define CFG_KEYTAG_H + +/** + * Module logging level. + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_level" + */ +#define CONFIG_KEYTAG_LOG_LEVEL LOG_LVL_ERR +/** + * Module logging format. + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_format" + */ +#define CONFIG_KEYTAG_LOG_FORMAT LOG_FMT_TERSE + +/** + * Max buffer lenght + * $WIZ$ type = "int" + */ +#define CONFIG_TAG_MAX_LEN 14 + +/** + * Label to put before the tag code. + * $WIZ$ type = "string" + */ +#define CONFIG_TAG_LABEL "tag " + +#endif /* CFG_KEYTAG_H */ + diff --git a/bertos/net/keytag.c b/bertos/net/keytag.c index 1f57fdfe..f686a7aa 100644 --- a/bertos/net/keytag.c +++ b/bertos/net/keytag.c @@ -44,13 +44,24 @@ #include "keytag.h" +#include +// Define log settings for cfg/log.h +#define LOG_LEVEL CONFIG_KEYTAG_LOG_LEVEL +#define LOG_FORMAT CONFIG_KEYTAG_LOG_FORMAT +#include +#include + #include -#include -#include +/** + * Starting communication char (STX). + */ +#define TAG_STX 0x02 -#include -#include +/** + * Ending communication char (ETX). + */ +#define TAG_ETX 0x03 static void keytag_clearPkt(struct TagPacket *pkt) { @@ -77,7 +88,7 @@ void keytag_poll(struct TagPacket *pkt) { /* When STX is found a new packet begins */ if (pkt->sync) - kprintf("TAG double sync!\n"); + LOG_WARN("TAG double sync!\n"); keytag_clearPkt(pkt); pkt->sync = true; } @@ -86,17 +97,19 @@ void keytag_poll(struct TagPacket *pkt) /* Check for end of packet */ if (c == TAG_ETX) { - pkt->buf[TAG_MAX_PRINT_CHARS] = '\x0'; + /* Terminate the tag string */ + uint16_t len = MIN((uint16_t)CONFIG_TAG_MAX_LEN, pkt->len); + pkt->buf[len] = '\0'; /* Write read TAG on communication serial */ - kfile_printf(pkt->host, "tag %s", pkt->buf); + kfile_printf(pkt->host, "%s%s", CONFIG_TAG_LABEL, pkt->buf); pkt->sync = false; } else { /* Check for buffer overflow */ - if (pkt->len >= TAG_MAX_LEN) + if (pkt->len >= CONFIG_TAG_MAX_LEN) { - kprintf("TAG buffer overflow\n"); + LOG_ERR("TAG buffer overflow\n"); pkt->sync = false; } else @@ -113,7 +126,7 @@ void keytag_poll(struct TagPacket *pkt) } if (kfile_error(pkt->tag) != 0) { - kprintf("Error %08x\n", kfile_error(pkt->tag)); + LOG_ERR("Error %08x\n", kfile_error(pkt->tag)); kfile_clearerr(pkt->tag); } diff --git a/bertos/net/keytag.h b/bertos/net/keytag.h index 0985a207..375b490e 100644 --- a/bertos/net/keytag.h +++ b/bertos/net/keytag.h @@ -33,45 +33,31 @@ * \author Andrea Grandi * * \brief Tag protocol. (interface). + * + * $WIZ$ module_name = "keytag" + * $WIZ$ module_configuration = "bertos/cfg/cfg_keytag.h" + * $WIZ$ module_depends = "kfile" + * $WIZ$ module_hw = "" */ #ifndef NET_KEYTAG_H #define NET_KEYTAG_H -#include -#include - -/** - * Starting communication char (STX). - */ -#define TAG_STX 0x02 - -/** - * Ending communication char (ETX). - */ -#define TAG_ETX 0x03 - -/** - * Max buffer lenght - */ -#define TAG_MAX_LEN 14 +#include +#include -/** - * Max number of chars to print in the communication serial - */ -#define TAG_MAX_PRINT_CHARS 12 /** * Structure of a Tag packet */ typedef struct TagPacket { - KFile *tag; ///< Tag communication channel - KFile *host; ///< Host communication channel - 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; ///< Tag communication channel + KFile *host; ///< Host communication channel + bool sync; ///< Status flag: true if we find an STX + uint16_t len; ///< Packet lenght + uint8_t buf[CONFIG_TAG_MAX_LEN]; ///< Reception buffer } TagPacket; void keytag_init(struct TagPacket *pkt, struct KFile *comm, struct KFile *tag);