eive-obsw/thirdparty/tas/tas/hdlc.h

53 lines
1.4 KiB
C

//**************************************************************************************
/*! \copyright: 2020-2021 Thales Alenia Space Deutschland GmbH
* \project: multiMIND
* \file: (name of source file: hdlc.h)
* \date: (09.02.2022)
* \author: (Stelios Filippopoulos)
* \brief: (hdlc header file)
* \language: (C)
**************************************************************************************
*/
#ifndef LIB_HDLC_H_
#define LIB_HDLC_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stddef.h>
#define HDLC_ENABLE
#define HDLC_START_BYTE (0x7Eu)
#define HDLC_ESC_BYTE (0x7Du)
#define HDLC_END_BYTE (0x7Cu)
#define HDLC_ESCAPE_CHAR (0x20u)
void hdlc_add_byte(uint8_t ch, uint8_t *buff, size_t *pos);
void hdlc_add_framing(const uint8_t *src, size_t slen, uint8_t *dst, size_t *dlen);
/**
* Decode a HDLC frame, including CRC check and CRC removal in addition
* to the removal of the frame markers.
* @param src
* @param slen
* @param dst
* @param dlen
* @return
* -1 Invalid source length
* -2 No start marker at first byte or end marker at slen - 1
* 1 Invalid CRC
* 0 CRC OK, framing and CRC removed
*/
int hdlc_remove_framing_with_crc_check(const uint8_t *src, size_t slen, uint8_t *dst, size_t *dlen);
#ifdef __cplusplus
}
#endif
#endif /* LIB_HDLC_H_ */