#include "main.h"
#include "menu.h"
 #include "state.h"
/**
 * menu_tree 结点序号  0，1
 * father 这个结点的父节点
 * next  这个节点输出后的下一个节点序号，0则表示后序无节点
 * child 子节点，进入该节点后，显示的第一个节点
 * 
 * 字符串用  char  pre_command[64]  MENU_DATA_TYPE_CHAR
 * 如果需要执行命令， 用状态符号，任务执行状态命令
 */

extern struct operating_state op_state; 
 
const struct menu_tree_node menu_tree[] = {
    {
        .data_type=MENU_DATA_TYPE_CHAR,
        .max_value=0,
        .min_value=0,
        .father=0,
        .next=0,
        .child=1,
        .info_str="\r\n                        ███████╗███████╗███████╗ █████╗ \r\n                        ██╔════╝██╔════╝██╔════╝██╔══██╗\r\n                        █████╗  ███████╗█████╗  ███████║\r\n                        ██╔══╝  ╚════██║██╔══╝  ██╔══██║\r\n                        ███████╗███████║███████╗██║  ██║\r\n                        ╚══════╝╚══════╝╚══════╝╚═╝  ╚═╝\r\n\r\n                             逸海光学(青岛)科技有限公司\r\n\r\n                                手持式光辐射测量装置\r\n",
        .data=NULL,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT8,
        .max_value=0,
        .min_value=0,
        .father=0,
        .next=0,
        .child=2,
        .info_str="菜单",
        .data=NULL,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT8,
        .max_value=0,
        .min_value=0,
        .father=1,
        .next=7,
        .child=3,
        .info_str="串口配置",
        .data=NULL,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT32,
        .max_value=4000000,
        .min_value=2400,
        .father=2,
        .next=4,
        .child=0,
        .info_str="波特率",
        .data=&config.uart.baudrate,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=11,
        .min_value=7,
        .father=2,
        .next=5,
        .child=0,
        .info_str="数据位",
        .data=&config.uart.databits,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=1536,
        .min_value=0,
        .father=2,
        .next=6,
        .child=0,
        .info_str="奇偶校验\r\n不校验:0\r\n奇校验:1024\r\n偶校验:1536",
        .data=&config.uart.parity,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=12288,
        .min_value=0,
        .father=2,
        .next=0,
        .child=0,
        .info_str="停止位\r\n1bit:0\r\n0.5bit:4096\r\n2bit:8192\r\n1.5bit:12288",
        .data=&config.uart.stopbits,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT8,
        .max_value=0,
        .min_value=0,
        .father=1,
        .next=15,
        .child=8,
        .info_str="协议配置",
        .data=NULL,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=2,
        .min_value=0,
        .father=7,
        .next=9,
        .child=0,
        .info_str="协议类型  0:RTU 1:HEX 2:ASCII",
        .data=&config.protocol.type,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_CHAR,
        .max_value=0,
        .min_value=0,
        .father=7,
        .next=10,
        .child=0,
        .info_str="预命令",
        .data=config.protocol.pre_command,
        .num=64
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=65535,
        .min_value=0,
        .father=7,
        .next=11,
        .child=0,
        .info_str="预命令超时",
        .data=&config.protocol.pre_timeout,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_CHAR,
        .max_value=0,
        .min_value=0,
        .father=7,
        .next=12,
        .child=0,
        .info_str="命令",
        .data=config.protocol.command,
        .num=64
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=65535,
        .min_value=0,
        .father=7,
        .next=13,
        .child=0,
        .info_str="超时",
        .data=&config.protocol.timeout,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=0,
        .min_value=0,
        .father=7,
        .next=14,
        .child=0,
        .info_str="数据解析",
        .data=&config.protocol.parser,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=1,
        .min_value=0,
        .father=7,
        .next=0,
        .child=0,
        .info_str="大小端",
        .data=&config.protocol.endian,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT8,
        .max_value=0,
        .min_value=0,
        .father=1,
        .next=21,
        .child=16,
        .info_str="输出配置",
        .data=NULL,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=0,
        .min_value=0,
        .father=14,
        .next=17,
        .child=0, 
        .info_str="开始字节",
        .data=&config.output.begin_byte,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=0,
        .min_value=0,
        .father=14,
        .next=18,
        .child=0, 
        .info_str="长度",
        .data=&config.output.begin_byte,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=0,
        .min_value=0,
        .father=14,
        .next=19,
        .child=0, 
        .info_str="结束字节",
        .data=&config.output.end_byte,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=0,
        .min_value=0,
        .father=14,
        .next=20,
        .child=0, 
        .info_str="输出位置",
        .data=&config.output.place,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=0,
        .min_value=0,
        .father=14,
        .next=0,
        .child=0, 
        .info_str="输出数目",
        .data=&config.output.number,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT8,
        .max_value=1,
        .min_value=0,
        .father=1,
        .next=26,
        .child=22,
        .info_str="菜单串口",
        .data=NULL,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT32,
        .max_value=4000000,
        .min_value=2400,
        .father=21,
        .next=23,
        .child=0,
        .info_str="波特率",
        .data=&config.menu.baudrate,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=11,
        .min_value=7,
        .father=21,
        .next=24,
        .child=0,
        .info_str="数据位",
        .data=&config.menu.databits,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=1536,
        .min_value=0,
        .father=21,
        .next=25,
        .child=0,
        .info_str="奇偶校验\r\n不校验:0\r\n奇校验:1024\r\n偶校验:1536",
        .data=&config.menu.parity,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=12288,
        .min_value=0,
        .father=21,
        .next=0,
        .child=0,
        .info_str="停止位\r\n1bit:0\r\n0.5bit:4096\r\n2bit:8192\r\n1.5bit:12288",
        .data=&config.menu.stopbits,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT8,
        .max_value=1,
        .min_value=0,
        .father=1,
        .next=31,
        .child=27,
        .info_str="Modbus串口",
        .data=NULL,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT32,
        .max_value=4000000,
        .min_value=2400,
        .father=26,
        .next=28,
        .child=0,
        .info_str="波特率",
        .data=&config.modbus.baudrate,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=11,
        .min_value=7,
        .father=26,
        .next=29,
        .child=0,
        .info_str="数据位",
        .data=&config.modbus.databits,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=1536,
        .min_value=0,
        .father=26,
        .next=30,
        .child=0,
        .info_str="奇偶校验\r\n不校验:0\r\n奇校验:1024\r\n偶校验:1536",
        .data=&config.modbus.parity,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT16,
        .max_value=12288,
        .min_value=0,
        .father=26,
        .next=0,
        .child=0,
        .info_str="停止位\r\n1bit:0\r\n0.5bit:4096\r\n2bit:8192\r\n1.5bit:12288",
        .data=&config.modbus.stopbits,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT8,
        .max_value=1,
        .min_value=0,
        .father=1,
        .next=32,
        .child=0,
        .info_str="保存配置",
        .data=&op_state.flag_save_cfg,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT8,
        .max_value=1,
        .min_value=0,
        .father=1,
        .next=33,
        .child=0,
        .info_str="恢复出厂配置",
        .data=&op_state.flag_save_cfg,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_CHAR,
        .max_value=0,
        .min_value=0,
        .father=1,
        .next=34,
        .child=0,
        .info_str="设置系统时间\r\nFormat:20230707120101",
        .data=op_state.flag_time,
        .num=0
    },
    {
        .data_type=MENU_DATA_TYPE_UINT8,
        .max_value=1,
        .min_value=0,
        .father=1,
        .next=0,
        .child=0,
        .info_str="重启",
        .data=&op_state.flag_reboot,
        .num=0
    }

};