X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fnet%2Fpocketbus.c;h=117e40d07204e515e1b80494e0f19f5413700d80;hb=d5c46be7818a9f9bd63b746d81f5223273c42a65;hp=a9cb4727c162362e7f594a702c5853e0c350a756;hpb=cafdb86d36274921d12ee8c3559b40474834e41c;p=bertos.git diff --git a/bertos/net/pocketbus.c b/bertos/net/pocketbus.c index a9cb4727..117e40d0 100644 --- a/bertos/net/pocketbus.c +++ b/bertos/net/pocketbus.c @@ -78,8 +78,14 @@ #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 @@ -208,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) { @@ -260,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); }