/*
 * aprs_encoder.h
 *
 *  Created on: Oct 22, 2019
 *      Author: curiousmuch
 */

#ifndef APRS_ENCODER_H_
#define APRS_ENCODER_H_

#include <stdint.h>

/* Data Structures */

typedef enum {
	NOCONFIG = 0,
	STOP,
	READY,
	ERROR,
} ax25_enc_status_t;

typedef struct {
	uint8_t tx_delay;
	uint8_t tx_tail;
} ax25_enc_param_t;

typedef enum {
	PREAMBLE = 0,
	FRAME,
	TAIL,
	DONE
} ax25_enc_state_t;

typedef struct {
	uint8_t *frame;				// frame buffer ptr
	uint32_t frame_len;			// frame buffer len
	uint32_t index;				// current buffer index
	uint8_t bit_index;			// current bit index
	uint8_t one_count;			// stores the number of "1s" for NRZI
	uint8_t cur_bit;			// current raw bit being processed
	uint8_t prev_bit;			// previous raw bit
	uint8_t nrzi_bit;			// nrzi-bit to be sent
	uint32_t byte;				// current raw byte being processed
	uint8_t flag_count;			// number of flags "0x7E" sent
	ax25_enc_status_t status;	// status of the encoding process
	ax25_enc_state_t state;		// state of the encoding state machine
} ax25_enc_var_t;



/* Public Functions*/
void ax25_encoder_init(uint8_t tx_delay, uint8_t tx_tail);
ax25_enc_status_t ax25_encoder_encode(uint8_t *frame, int32_t frame_len);
uint8_t ax25_encoder_get_bit(void);
ax25_enc_status_t ax25_encoder_get_status(void);


#endif /* COMPONENTS_APRS_INCLUDE_APRS_ENCODER_H_ */