kopia lustrzana https://github.com/fsphil/hadie
Update to the new packet format -- added a 16-bit checksum
rodzic
5705af4f23
commit
f2e6d0aea2
11
ssdv.c
11
ssdv.c
|
@ -11,6 +11,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <util/crc16.h>
|
||||||
#include "ssdv.h"
|
#include "ssdv.h"
|
||||||
#include "rs8.h"
|
#include "rs8.h"
|
||||||
|
|
||||||
|
@ -516,6 +517,7 @@ char ssdv_enc_get_packet(ssdv_t *s)
|
||||||
{
|
{
|
||||||
uint16_t mcu_id = s->packet_mcu_id;
|
uint16_t mcu_id = s->packet_mcu_id;
|
||||||
uint16_t mcu_offset = s->packet_mcu_offset;
|
uint16_t mcu_offset = s->packet_mcu_offset;
|
||||||
|
uint16_t i, x;
|
||||||
|
|
||||||
if(mcu_offset != 0xFFFF && mcu_offset >= SSDV_PKT_SIZE_PAYLOAD * 8)
|
if(mcu_offset != 0xFFFF && mcu_offset >= SSDV_PKT_SIZE_PAYLOAD * 8)
|
||||||
{
|
{
|
||||||
|
@ -545,8 +547,15 @@ char ssdv_enc_get_packet(ssdv_t *s)
|
||||||
/* Fill any remaining bytes with noise */
|
/* Fill any remaining bytes with noise */
|
||||||
if(s->out_len > 0) ssdv_memset_prng(s->outp, s->out_len);
|
if(s->out_len > 0) ssdv_memset_prng(s->outp, s->out_len);
|
||||||
|
|
||||||
|
/* Calculate the CRC codes */
|
||||||
|
for(i = 1, x = 0xFFFF; i < SSDV_PKT_SIZE - SSDV_PKT_SIZE_RSCODES - SSDV_PKT_SIZE_CHECKSUM; i++)
|
||||||
|
x = _crc_xmodem_update(x, s->out[i]);
|
||||||
|
|
||||||
|
s->out[i++] = x >> 8;
|
||||||
|
s->out[i++] = x & 0xFF;
|
||||||
|
|
||||||
/* Generate the RS codes */
|
/* Generate the RS codes */
|
||||||
encode_rs_8(&s->out[1], &s->out[SSDV_PKT_SIZE - SSDV_PKT_SIZE_RSCODES], 0);
|
encode_rs_8(&s->out[1], &s->out[i], 0);
|
||||||
|
|
||||||
s->packet_id++;
|
s->packet_id++;
|
||||||
|
|
||||||
|
|
7
ssdv.h
7
ssdv.h
|
@ -21,9 +21,10 @@
|
||||||
|
|
||||||
/* Packet details */
|
/* Packet details */
|
||||||
#define SSDV_PKT_SIZE (0x100)
|
#define SSDV_PKT_SIZE (0x100)
|
||||||
#define SSDV_PKT_SIZE_HEADER (0x0B)
|
#define SSDV_PKT_SIZE_HEADER (0x0B)
|
||||||
#define SSDV_PKT_SIZE_RSCODES (0x20)
|
#define SSDV_PKT_SIZE_CHECKSUM (0x02)
|
||||||
#define SSDV_PKT_SIZE_PAYLOAD (SSDV_PKT_SIZE - SSDV_PKT_SIZE_HEADER - SSDV_PKT_SIZE_RSCODES)
|
#define SSDV_PKT_SIZE_RSCODES (0x20)
|
||||||
|
#define SSDV_PKT_SIZE_PAYLOAD (SSDV_PKT_SIZE - SSDV_PKT_SIZE_HEADER - SSDV_PKT_SIZE_CHECKSUM - SSDV_PKT_SIZE_RSCODES)
|
||||||
|
|
||||||
#define HBUFF_LEN (16)
|
#define HBUFF_LEN (16)
|
||||||
#define COMPONENTS (3)
|
#define COMPONENTS (3)
|
||||||
|
|
Ładowanie…
Reference in New Issue