/*
 * Created by jiaqiang.ye@lnxall.com
 *
 * Simple LNXALL binary logger interface
 *
 * 2024/12/23
 */

#ifndef LNXBINLOG_H
#define LNXBINLOG_H 1

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

struct binlog_type {
	uint16_t           log_type;
	const uint8_t *    desc_data;
	uint8_t            desc_len;
};

struct bldesc_modbus_tcp {
	unsigned int            remote_ip;
	unsigned short          port_no;
};

#define BINLOG_TYPE_INIT(type__, bltype__) \
	do { \
		(type__)->log_type = bltype__; \
		(type__)->desc_data = (const uint8_t *) 0; \
		(type__)->desc_len = 0; \
	} while (0)

#define BINLOG_TYPE_INIT1(type__, bltype__, t_len__, t_data__) \
	do { \
		(type__)->log_type = bltype__; \
		(type__)->desc_data = (const uint8_t *) t_data__; \
		(type__)->desc_len = (uint8_t) t_len__; \
	} while (0)

int lnxbinlog_flush(uint64_t * cursize);

int lnxbinlog_setfile(const char * logfile);

int lnxbinlog_getfile(char * fpath,
	unsigned int flen, uint64_t * cursize);

int lnxbinlog_push(const struct binlog_type * bltype,
	const char * logdat, unsigned int loglen);

#define BLTYPE_MBTCP_BASE   0x2200
#define BLTYPE_MBTCP_R      (BLTYPE_MBTCP_BASE + 0)
#define BLTYPE_MBTCP_W      (BLTYPE_MBTCP_BASE + 1)

#define BLTYPE_CAN_BASE     0x3200
#define BLTYPE_CAN_R        (BLTYPE_CAN_BASE + 0)
#define BLTYPE_CAN_W        (BLTYPE_CAN_BASE + 1)

#define BLTYPE_CAN_1_R      (BLTYPE_CAN_BASE + 2)
#define BLTYPE_CAN_1_W      (BLTYPE_CAN_BASE + 3)

#define BLTYPE_CAN_2_R      (BLTYPE_CAN_BASE + 4)
#define BLTYPE_CAN_2_W      (BLTYPE_CAN_BASE + 5)

#define BLTYPE_CAN_3_R      (BLTYPE_CAN_BASE + 6)
#define BLTYPE_CAN_3_W      (BLTYPE_CAN_BASE + 7)

#define BLTYPE_RS485_BASE   0x4850
#define BLTYPE_RS485_R      (BLTYPE_RS485_BASE + 0)
#define BLTYPE_RS485_W      (BLTYPE_RS485_BASE + 1)

#define BLTYPE_RS485_1_R    (BLTYPE_RS485_BASE + 2)
#define BLTYPE_RS485_1_W    (BLTYPE_RS485_BASE + 3)

#define BLTYPE_RS485_2_R    (BLTYPE_RS485_BASE + 4)
#define BLTYPE_RS485_2_W    (BLTYPE_RS485_BASE + 5)

#define BLTYPE_RS485_3_R    (BLTYPE_RS485_BASE + 6)
#define BLTYPE_RS485_3_W    (BLTYPE_RS485_BASE + 7)

#define BLTYPE_RS485_4_R    (BLTYPE_RS485_BASE + 8)
#define BLTYPE_RS485_4_W    (BLTYPE_RS485_BASE + 9)

#define BLTYPE_RS485_5_R    (BLTYPE_RS485_BASE + 10)
#define BLTYPE_RS485_5_W    (BLTYPE_RS485_BASE + 11)

#define BLTYPE_RS485_6_R    (BLTYPE_RS485_BASE + 12)
#define BLTYPE_RS485_6_W    (BLTYPE_RS485_BASE + 13)

#define BLTYPE_RS485_7_R    (BLTYPE_RS485_BASE + 14)
#define BLTYPE_RS485_7_W    (BLTYPE_RS485_BASE + 15)

#define BLTYPE_RS485_8_R    (BLTYPE_RS485_BASE + 16)
#define BLTYPE_RS485_8_W    (BLTYPE_RS485_BASE + 17)

#define BLTYPE_RS485_9_R    (BLTYPE_RS485_BASE + 18)
#define BLTYPE_RS485_9_W    (BLTYPE_RS485_BASE + 19)

#define BLTYPE_RS485_10_R    (BLTYPE_RS485_BASE + 20)
#define BLTYPE_RS485_10_W    (BLTYPE_RS485_BASE + 21)

#define BLTYPE_RS485_11_R    (BLTYPE_RS485_BASE + 22)
#define BLTYPE_RS485_11_W    (BLTYPE_RS485_BASE + 23)

#define BLTYPE_RS485_12_R    (BLTYPE_RS485_BASE + 24)
#define BLTYPE_RS485_12_W    (BLTYPE_RS485_BASE + 25)

#define BLTYPE_RS485_13_R    (BLTYPE_RS485_BASE + 26)
#define BLTYPE_RS485_13_W    (BLTYPE_RS485_BASE + 27)

#define BLTYPE_RS485_14_R    (BLTYPE_RS485_BASE + 28)
#define BLTYPE_RS485_14_W    (BLTYPE_RS485_BASE + 29)

#define BLTYPE_RS485_15_R    (BLTYPE_RS485_BASE + 30)
#define BLTYPE_RS485_15_W    (BLTYPE_RS485_BASE + 31)

#define BLTYPE_RS485_16_R    (BLTYPE_RS485_BASE + 32)
#define BLTYPE_RS485_16_W    (BLTYPE_RS485_BASE + 33)

#ifdef __cplusplus
}
#endif
#endif
