X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fnet%2Fpocketbus.c;h=61d4d2b44261432885e33fa0bb81050a5c8d7330;hb=f04b11589eb9bff739ac3e33a4c74ed5a4504fe7;hp=63f369ac97193e59f5962d2e9fcbd24f24acc488;hpb=9ad4bfda67375c05ca590cc793da190b9dc8de5b;p=bertos.git diff --git a/bertos/net/pocketbus.c b/bertos/net/pocketbus.c index 63f369ac..61d4d2b4 100644 --- a/bertos/net/pocketbus.c +++ b/bertos/net/pocketbus.c @@ -83,7 +83,7 @@ #include -#include +#include #include @@ -98,7 +98,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 +115,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 +208,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) {