/*****************************************************************************
 * file    Inc/RS485_debug.h 
 * author  YuLiang
 * version 1.0.0
 * date    17-Jun-2022
 * brief   This file provides all the headers of RS485 debug function.
 ******************************************************************************
 * Attention
 *
 * <h2><center>&copy; COPYRIGHT(c) 2022 LandPower</center></h2>
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *   1. Redistributions of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright notice,
 *      this list of conditions and the following disclaimer in the documentation
 *      and/or other materials provided with the distribution.
 *   3. Neither the name of WTOE nor the names of its contributors may be used to 
 *      endorse or promote products derived from this software without specific
 *      prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 ******************************************************************************/

#ifndef __RS485_DEBUG_H__
#define __RS485_DEBUG_H__

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "FreeRTOS.h"
#include "task.h"
#include "cmsis_os.h"

/* Define --------------------------------------------------------------------*/

/* Exported types ------------------------------------------------------------*/
/* 实时数据传输结构体. */
typedef struct
{
    int16_t temperature;                    // 设备温度, 单位: 0.1℃.
    uint16_t vbat;                          // 电池电压, 单位: mv.
    int16_t CSQ;                            // 4G 信号质量 > -51dBm 统一显示 -51dBm, < -113 dBm 为无信号.
    uint16_t vin;                           // 工作电压, 单位: mv.
    uint32_t elec[CFG_ADC_CH_CNT];          // 通道电流有效值 mA.
    uint16_t vsc;                           // 超级电容电压, 单位: mv.
    int16_t sen_temp[SENSOR_SUM];           // 传感器温度: 单位: 0.1℃.
    uint16_t sen_x[SENSOR_SUM];             // 传感器震动 x 轴.
    uint16_t sen_y[SENSOR_SUM];             // 传感器震动 y 轴.
    uint16_t sen_z[SENSOR_SUM];             // 传感器震动 z 轴.
    uint8_t energy_mode;
    uint8_t sen_short;                      // 传感器是否短路, 0 – 没有短路, 1 – 短路.
    uint8_t sen_valid[SENSOR_SUM];         // 传感器数据是否有效, 0 - 无效, 1 - 有效.
} debug_real_data_t;

/* 校准命令信息. */
typedef struct
{
    uint8_t ch_selecet;
    uint8_t is_voltage_sel;
    uint8_t manual_index;
    uint8_t reserve[1];
} debug_adj_set;

/* 自动校准仪器通讯协议头. */
typedef struct
{
    uint8_t id_recv;
    uint8_t id_send;
    uint8_t len;
    uint8_t cmd;
} debug_adj_head_t;

/* 自动校准仪器通讯协议中数据的表示结构. */
typedef struct
{
    int32_t data;
    int8_t index;
} debug_adj_num_t;

/* 南网配置信息. */
typedef struct
{
    uint8_t passwd[8];
    uint8_t beat_interval;
    uint8_t reset_time[3];
    uint16_t collect_interval;
    uint16_t sleep_time;
    uint16_t online_time;
    uint8_t reserve[2];
    uint8_t ciphertext[8];      // 实时数据认证密文.
} debug_csg_config_t;

/* Exported macro ------------------------------------------------------------*/
/* Extern global variables ---------------------------------------------------*/
extern usart_buf_t debug_buf;

/* Extern functions ----------------------------------------------------------*/
extern void debug_start(void);
extern void debug_adj_auto(uint8_t bitmap);
extern int32_t debug_app_check(uint32_t addr, uint32_t size, uint8_t file_type);
#endif
/******************* (C) COPYRIGHT LandPower ***** END OF FILE ****************/

