Update preset.
[bertos.git] / bertos / net / pocketbus.c
index fb50a278cf1f7bcd6948ca657fab779aa51b75fd..bded2db0bccbe406e47ff98f908eef8c28508c48 100644 (file)
 
 #include "pocketbus.h"
 
-#include <cfg/macros.h>
+#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 <cfg/log.h>
 #include <cfg/debug.h>
+#include <cfg/macros.h>
 
-#include <kern/kfile.h>
+#include <io/kfile.h>
 
 #include <cpu/byteorder.h>
 
@@ -98,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);
 }
 
@@ -115,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));
 }
@@ -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);
        }