X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fnet%2Fpocketbus.c;h=bded2db0bccbe406e47ff98f908eef8c28508c48;hb=911d2706a86d326786bfe721dcc3d63aeade7f28;hp=e793f95df54b26886ee5bc62edb0951b7d85c0eb;hpb=791e167e053bdd9250d34a9a5ccae6ccde4d6679;p=bertos.git diff --git a/bertos/net/pocketbus.c b/bertos/net/pocketbus.c index e793f95d..bded2db0 100644 --- a/bertos/net/pocketbus.c +++ b/bertos/net/pocketbus.c @@ -1,12 +1,33 @@ /** * \file * + * This file is part of BeRTOS. + * + * Bertos is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. * - * \version $Id: pocketbus.c 20131 2007-12-13 17:39:55Z batt $ + * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * \author Francesco Sacchi + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + * + * Copyright 2007 Develer S.r.l. (http://www.develer.com/) + * --> * * \brief pocketBus protocol implementation. * @@ -57,12 +78,18 @@ #include "pocketbus.h" -#include +#include "cfg/cfg_pocketbus.h" + +// Define logging setting (for cfg/log.h module). +#define LOG_LEVEL POCKETBUS_LOG_LEVEL +#define LOG_VERBOSITY POCKETBUS_LOG_FORMAT +#include #include +#include -#include +#include -#include +#include #include @@ -77,7 +104,7 @@ void pocketbus_putchar(struct PocketBusCtx *ctx, uint8_t c) /* Escape characters with special meaning */ if (c == POCKETBUS_ESC || c == POCKETBUS_STX || c == POCKETBUS_ETX) kfile_putc(POCKETBUS_ESC, ctx->fd); - + kfile_putc(c, ctx->fd); } @@ -94,7 +121,7 @@ void pocketbus_begin(struct PocketBusCtx *ctx, pocketbus_addr_t addr) /* Send STX */ kfile_putc(POCKETBUS_STX, ctx->fd); - + /* Send header */ pocketbus_write(ctx, &hdr, sizeof(hdr)); } @@ -187,12 +214,16 @@ bool pocketbus_recv(struct PocketBusCtx *ctx, struct PocketMsg *msg) /* Compute checksum */ rotating_update(ctx->buf, ctx->len, &ctx->in_cks); - rotating_t recv_cks = be16_to_cpu(*((rotating_t *)(ctx->buf + ctx->len))); + uint8_t cks_h = *(ctx->buf + ctx->len); + uint8_t cks_l = *(ctx->buf + ctx->len + 1); + + rotating_t recv_cks = (cks_h << 8) | cks_l; /* Checksum check */ if (recv_cks == ctx->in_cks) { - PocketBusHdr *hdr = (PocketBusHdr *)(ctx->buf); + PocketBusHdr *hdr = (PocketBusHdr *)ctx; + /* Check packet version */ if (hdr->ver == POCKETBUS_VER) { @@ -239,7 +270,7 @@ bool pocketbus_recv(struct PocketBusCtx *ctx, struct PocketMsg *msg) */ if (kfile_error(ctx->fd)) { - TRACEMSG("fd status[%04X]", kfile_error(ctx->fd)); + LOG_ERR("fd status[%04X]\n", kfile_error(ctx->fd)); kfile_clearerr(ctx->fd); }