Compare commits

..

2 Commits

Author SHA1 Message Date
起床就犯困 f72590e9a8 修改flash中保存的数据,设置两个结构体,保存全局所需数据 2024-10-12 17:51:15 +08:00
起床就犯困 3ec7ad0781 串口主体 2024-10-12 10:23:32 +08:00
38 changed files with 5856 additions and 19110 deletions

567
App/inc/hy_protocol.h Normal file
View File

@ -0,0 +1,567 @@
/*
* hy_protocol.h
*
* Created on: 20241011
* Author: psx
*/
#ifndef APP_INC_HY_PROTOCOL_H_
#define APP_INC_HY_PROTOCOL_H_
#include "debug.h"
#include "uart_dev.h"
#include "math.h"
/* 功能码 */
typedef enum
{
HY_batteryStatus = 0x60, /* 电池状态数据报 */
HY_electricityStatistics = 0x61, /* 电量统计数据报 */
HY_sensorNumberConfiguration = 0x62, /* 传感器号码配置 */
HY_sensorNumberInquiry = 0x63, /* 传感器号码查询 */
HY_chargingThresholdVoltageConfiguration = 0x64, /* 充电阈值电压配置 */
HY_chargingRangeVoltageQuery = 0x65, /* 充电域值电压查询 */
HY_resetInstruction = 0x66, /* 复位指令 */
HY_chargingControlConfiguration = 0x6C, /* 充电控制配置 */
HY_chargingControlQuery = 0x6D, /* 充电控制查询 */
HY_configureProtocolType = 0x70, /* 配置协议类型 */
HY_responseConfigureProtocolType = 0x71, /* 响应配置协议类型 */
HY_queryControlBoxConfiguration = 0x74, /* 查询电池控制盒当前配置 */
HY_querySoftwareVersion = 0x75, /* 查询电池控制盒软件版本 */
HY_enterConfigurationMode = 0x76, /* 进入配置模式 */
HY_configureHardwareID = 0x7B, /* 配置控制盒硬件ID号 */
HY_hardwareID_communicationIDQuery = 0x7C, /* 控制盒硬件ID号及通信ID号原传感器号查询 */
HY_modifyCommunicationID = 0x7D, /* 修改通信ID号原传感器号 */
HY_checkMotherboardTemperature = 0x7E, /* 查询主板温度值 */
}HY_MsgFunctionCode;
/* 解析数据包的长度 */
typedef enum
{
HY_analyzeStartFlag = 1, /* 长度为1时解析起始标志 */
HY_analyzeHardwareID = 7, /* 长度为7时解析硬件ID */
HY_analyzeCommunicationID = 11, /* 长度为10时解析通信ID */
HY_analyzeControlWord = 12, /* 长度为12时解析控制字 */
HY_analyzeDataLen = 14, /* 长度为14时解析数据长度 */
}HY_AnalyzeDataLen;
/* 指定对齐方式为1字节 */
#pragma pack(push,1)
/* 默认参数 */
typedef struct _HY_default_Value{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t end_Flag; /* 结束标志 */
}HY_default_Value;
extern HY_default_Value HY_defaultValue;
/* 默认参数 */
typedef struct _HY_Recv_pack{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
}HY_Recv_pack;
/* 功能码处理函数 */
typedef void (*HYMsgProcFunc)(device_handle device, void*, uint32_t MsgLen);
typedef struct _HY_FunctionMsgProcTable{
u_int32_t msgId;
HYMsgProcFunc pMsgProc;
}HY_FuncionMsgProcTable;
/* 电池状态数据报查询 */
typedef struct _HY_batteryStatusQuery{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_batteryStatusQuery;
#define HY_batteryStatusQuery_PACK_SIZE (sizeof(HY_batteryStatusQuery))
/* 电池状态数据报响应 */
typedef struct _HY_batteryStatusResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
float_t batteryVoltage; /* 电池电压 */
float_t dischargCurrent; /* 输出电流(流向负载) */
float_t chargCurrent1; /* 充电电流(流向电池+负载) */
float_t SOC; /* 剩余电量 */
float_t openCircuitVoltage1; /* 充电开路电压 */
uint8_t chargSwitchStatus1; /* 充电开关状态 */
float_t chargCurrent2; /* 充电电流(流向电池+负载) */
float_t openCircuitVoltage2; /* 充电开路电压 */
uint8_t chargSwitchStatus2; /* 充电开关状态 */
float_t Mos_Temperature; /* 工作温度 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_batteryStatusResponse;
#define HY_batteryStatusResponse_PACK_SIZE (sizeof(HY_batteryStatusResponse))
/* 电量统计数据报查询 */
typedef struct _HY_electricityStatisticsQuery{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_electricityStatisticsQuery;
#define HY_electricityStatisticsQuery_PACK_SIZE (sizeof(HY_electricityStatisticsQuery))
/* 电池状态数据报响应 */
typedef struct _HY_electricityStatisticsResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
float_t statisticalDuration; /* 统计时长 */
float_t totalElectricityConsumption; /* 总电量消耗 */
float_t totalChargCapacity; /* 总充电电量 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_electricityStatisticsResponse;
#define HY_electricityStatisticsResponse_PACK_SIZE (sizeof(HY_electricityStatisticsResponse))
/* 传感器号码配置 */
typedef struct _HY_sensorNumberConfig{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t newHardwareID[6]; /* 新硬件ID高字节在前低字节在后保持不变 */
uint8_t newCommunicationID[4]; /* 新通信ID高字节在前低字节在后 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_sensorNumberConfig;
#define HY_sensorNumberConfiguration_PACK_SIZE (sizeof(HY_sensorNumberConfig))
/* 传感器号码配置响应 */
typedef struct _HY_sensorNumberConfigurationResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t state; /* 状态 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_sensorNumberConfigurationResponse;
#define HY_sensorNumberConfigurationResponse_PACK_SIZE (sizeof(HY_sensorNumberConfigurationResponse))
/* 传感器号码查询 */
typedef struct _HY_sensorNumberInquiryQuery{
uint8_t start_Flag; /* 起始标志 */
uint8_t broadcastTerminal[6]; /* 广播终端ID:0xFF 0xFF 0xFF 0xFF 0xFF 0xFF */
uint8_t broadcastCommunication[4]; /* 广播通信ID:0xFF 0xFF 0xFF 0xFF */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_sensorNumberInquiryQuery;
#define HY_sensorNumberInquiryQuery_PACK_SIZE (sizeof(HY_sensorNumberInquiryQuery))
/* 传感器号码查询响应 */
typedef struct _HY_sensorNumberInquiryResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t hardwareIDR[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationIDR[4]; /* 通信ID高字节在前低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_sensorNumberInquiryResponse;
#define HY_sensorNumberInquiryResponse_PACK_SIZE (sizeof(HY_sensorNumberInquiryResponse))
/* 充电阈值电压配置 */
typedef struct _HY_chargingThresholdVoltageConfig{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
float_t chargOpenVoltage; /* 充电开电池电压 */
float_t chargCloseVoltage; /* 充电关电池电压 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_chargingThresholdVoltageConfig;
#define HY_chargingThresholdVoltageConfig_PACK_SIZE (sizeof(HY_chargingThresholdVoltageConfig))
/* 充电阈值电压配置响应 */
typedef struct _HY_chargingThresholdVoltageConfigResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t state; /* 状态 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_chargingThresholdVoltageConfigResponse;
#define HY_chargingThresholdVoltageConfigResponse_PACK_SIZE (sizeof(HY_chargingThresholdVoltageConfigResponse))
/* 充电域值电压查询 */
typedef struct _HY_chargRangeVoltageQuery{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_chargRangeVoltageQuery;
#define HY_chargRangeVoltageQuery_PACK_SIZE (sizeof(HY_chargRangeVoltageQuery))
/* 充电域值电压查询响应 */
typedef struct _HY_chargRangeVoltageQueryResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
float_t chargOpenVoltage; /* 充电开电池电压 */
float_t chargCloseVoltage; /* 充电关电池电压 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_chargRangeVoltageQueryResponse;
#define HY_chargRangeVoltageQueryResponse_PACK_SIZE (sizeof(HY_chargRangeVoltageQueryResponse))
/* 复位指令 */
typedef struct _HY_resetInstructionQuery{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_resetInstructionQuery;
#define HY_resetInstructionQuery_PACK_SIZE (sizeof(HY_resetInstructionQuery))
/* 复位指令响应 */
typedef struct _HY_resetInstructionResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t state; /* 状态 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_resetInstructionResponse;
#define HY_resetInstructionResponse_PACK_SIZE (sizeof(HY_resetInstructionResponse))
/* 充电控制配置 */
typedef struct _HY_chargingControlConfig{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t chargInterface; /* 充电接口 */
uint8_t chargInterfaceControl; /* 充电接口控制 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_chargingControlConfig;
#define HY_chargingControlConfig_PACK_SIZE (sizeof(HY_chargingControlConfig))
/* 充电控制配置响应 */
typedef struct _HY_chargingControlConfigResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t state; /* 状态 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_chargingControlConfigResponse;
#define HY_chargingControlConfigResponse_PACK_SIZE (sizeof(HY_chargingControlConfigResponse))
/* 充电控制查询 */
typedef struct _HY_QueryChargingControl{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_QueryChargingControl;
#define HY_QueryChargingControl_PACK_SIZE (sizeof(HY_QueryChargingControl))
/* 充电控制查询响应 */
typedef struct _HY_QueryChargingControlResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t chargInterface; /* 充电接口状态 */
uint8_t chargInterfaceControl; /* 充电接口状态 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_QueryChargingControlResponse;
#define HY_QueryChargingControlResponse_PACK_SIZE (sizeof(HY_QueryChargingControlResponse))
/* 配置协议类型 */
typedef struct _HY_configProtocolType{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t protocolType; /* 协议类型; 0x01表示汇源协议(波特率9600) 0x02表示南瑞协议(波特率115200)*/
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_configProtocolType;
#define HY_configProtocolType_PACK_SIZE (sizeof(HY_configProtocolType))
/* 配置协议类型响应 */
typedef struct _HY_configProtocolTypeResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t state; /* 状态 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_configProtocolTypeResponse;
#define HY_configProtocolTypeResponse_PACK_SIZE (sizeof(HY_configProtocolTypeResponse))
/* 查询电池控制盒当前配置 */
typedef struct _HY_queryControlBoxConfigurationQuery{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_queryControlBoxConfigurationQuery;
#define HY_queryControlBoxConfigurationQuery_PACK_SIZE (sizeof(HY_queryControlBoxConfigurationQuery))
/* 查询电池控制盒当前配置响应 */
typedef struct _HY_queryControlBoxConfigurationResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t protocolType; /* 协议类型; 0x01表示汇源协议(波特率9600) 0x02表示南瑞协议(波特率115200)*/
uint8_t voltageLevel; /* 电压等级 */
uint8_t mainBoardTemperatureSensorType; /* 主板温度传感器类型 */
uint8_t batteryTemperatureSensorType; /* 电池温度传感器类型 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_queryControlBoxConfigurationResponse;
#define HY_queryControlBoxConfigurationResponse_PACK_SIZE (sizeof(HY_queryControlBoxConfigurationResponse))
/* 查询电池控制盒软件版本 */
typedef struct _HY_SoftwareVersionQuery{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_SoftwareVersionQuery;
#define HY_SoftwareVersionQuery_PACK_SIZE (sizeof(HY_SoftwareVersionQuery))
/* 查询电池控制盒软件版本 */
typedef struct _HY_SoftwareVersionQueryResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t versionInformation[13]; /* 版本信息 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_SoftwareVersionQueryResponse;
#define HY_SoftwareVersionQueryResponse_PACK_SIZE (sizeof(HY_SoftwareVersionQueryResponse))
/* 进入配置模式 */
typedef struct _HY_enterConfigMode{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_enterConfigMode;
#define HY_enterConfigMode_PACK_SIZE (sizeof(HY_enterConfigMode))
/* 进入配置模式响应 */
typedef struct _HY_enterConfigModeResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t state; /* 状态 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_enterConfigModeResponse;
#define HY_enterConfigModeResponse_PACK_SIZE (sizeof(HY_enterConfigModeResponse))
/* 配置控制盒硬件ID号 */
typedef struct _HY_configHardwareID{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t newHardwareID[6]; /* 新硬件ID高字节在前低字节在后 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_configHardwareID;
#define HY_configHardwareID_PACK_SIZE (sizeof(HY_configHardwareID))
/* 配置控制盒硬件ID号 响应*/
typedef struct _HY_configHardwareIDResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t state; /* 状态 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_configHardwareIDResponse;
#define HY_configHardwareIDResponse_PACK_SIZE (sizeof(HY_configHardwareIDResponse))
///* 控制盒硬件ID号及通信ID号原传感器号查询 */
//typedef struct _HY_QueryhardwareID_communicationID{
// uint8_t start_Flag; /* 起始标志 */
// uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
// uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
// uint8_t controlWord; /* 控制字 */
// uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
// uint32_t frameNumber; /* 帧序号 */
// uint8_t check_Bit; /* 校验码 */
// uint8_t end_Flag; /* 结束标志 */
//}HY_QueryhardwareID_communicationID;
//#define HY_QueryhardwareID_communicationID_PACK_SIZE (sizeof(HY_QueryhardwareID_communicationID))
/* 修改通信ID号原传感器号 */
typedef struct _HY_modifyCommunicationIDChange{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t nowHardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t newcommunicationID[4]; /* 新通信ID高字节在前低字节在后 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_modifyCommunicationIDChange;
#define HY_modifyCommunicationIDChange_PACK_SIZE (sizeof(HY_modifyCommunicationIDChange))
/* 修改通信ID号原传感器号响应 */
typedef struct _HY_modifyCommunicationIDChangeResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t state; /* 状态 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_modifyCommunicationIDChangeResponse;
#define HY_modifyCommunicationIDChangeResponse_PACK_SIZE (sizeof(HY_modifyCommunicationIDChangeResponse))
/* 查询主板温度值 */
typedef struct _HY_checkMotherboardTemperatureQuery{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_checkMotherboardTemperatureQuery;
#define HY_checkMotherboardTemperatureQuery_PACK_SIZE (sizeof(HY_checkMotherboardTemperatureQuery))
/* 查询主板温度值响应 */
typedef struct _HY_checkMotherboardTemperatureResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
float_t MotherboardTemperature; /* 主板温度 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_checkMotherboardTemperatureResponse;
#define HY_checkMotherboardTemperatureResponse_PACK_SIZE (sizeof(HY_checkMotherboardTemperatureResponse))
/* 恢复默认的对齐设置 */
#pragma pack(pop)
uint8_t HY_CheckFunc(uint8_t *arr_buff, uint8_t len);
void HY_read_and_process_uart_data(device_handle device);
#endif /* APP_INC_HY_PROTOCOL_H_ */

View File

@ -12,71 +12,78 @@
#pragma pack(push,1) #pragma pack(push,1)
typedef struct _uint8_config_info{ /* 高字节在前,低字节在后 */
uint8_t start_Flag[2]; /* 起始标志 */ typedef struct _recv_config_info{
uint8_t start_Flag[2]; /* 开始标志 */
/* SL */
uint8_t address[7]; /* 地址 */ uint8_t address[7]; /* 地址 */
uint8_t end_Flag; /* 结束标志 */
uint8_t Access_Node_Type[2]; /* 接入节点类型 */ uint8_t Access_Node_Type[2]; /* 接入节点类型 */
uint8_t Communication_Methods[2]; /* 通信方式 */ uint8_t Communication_Methods[2]; /* 通信方式 */
uint8_t bat485_Baud[4]; /* 串口波特率,为0代表bms不支持通信 */ uint8_t gw485_Baud[4]; /* 串口波特率,为0代表bms不支持通信 */
uint8_t gw485_Baud[4]; /* 串口波特率 */ uint8_t bat485_Baud[4]; /* 串口波特率 */
uint8_t ConstantCurrentV[2]; /* 高于该(电压 / 100),小于ConstantVoltageV * 100电压进行恒流充电 */
/* HY */
uint8_t hardwareID[6]; /* 硬件ID */
uint8_t communicationID[4]; /* 通信ID */
uint8_t protocolType; /* 协议类型; 0x01表示汇源协议(波特率9600) 0x02表示南瑞协议(波特率115200)*/
uint8_t ConstantVoltageV[2]; /* 高于该(电压 / 100)且电流大于FloatI * 100进行恒压充电 */ uint8_t ConstantVoltageV[2]; /* 高于该(电压 / 100)且电流大于FloatI * 100进行恒压充电 */
uint8_t FloatI[2]; /* 高于该(电压 / 100)且电流低于FloatI * 100进行浮充充电 */ uint8_t FloatI[2]; /* 高于该(电压 / 100)且电流低于FloatI * 100进行浮充充电 */
uint8_t startSolarOpenCircuitV[2]; /* 高于该(电压 / 100)开始充电 */ uint8_t startSolarOpenCircuitV[2]; /* 高于该(电压 / 100)开始充电 */
}uint8_config_info; uint8_t stopSolarOpenCircuitV[2]; /* 太阳能板开路电压高于该电压停止充电 (V) */
uint8_t constantVoltageChargeV[2]; /* 恒压充电时的输出电压 (V) */
uint8_t FloatV[2]; /* 浮充充电时的输出电压 (V) */
uint8_t HighSideMosTemperature_stop[2]; /* 当上桥温度达到该值时,停止输出 (°C) */
uint8_t HighSideMosTemperature_end[2]; /* 当上桥温度上升到该值时,降低功率运行 (°C) */
uint8_t HighSideMosTemperature_start[2];/* 当上桥温度降低到该值时,按照正常情况输出 (°C) */
uint8_t loopImpedance[2]; /* 回路阻抗大小 (mΩ) */
uint8_t checkSolarOpenCircuitVTime[2]; /* 启动任务中太阳能板开路电压检测间隔时间 (S) */
//typedef struct _config_info{ uint8_t outputAgainFlagTime[2]; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 (S) */
// uint8_t start_Flag[2]; /* 起始标志 */ uint8_t excessiveLoadFlagTime[2]; /* 出现过载后在该间隔时间中多次2次出现过载则关闭输出 (S) */
// uint8_t address[7]; /* 地址 */ uint8_t eLAgainTime[2]; /* 出现过载过载保护后,在该间隔段时间后,再次尝试输出 (S) */
// uint8_t end_Flag; /* 结束标志 */ uint8_t crc[2]; /* 校验 */
// uint16_t Access_Node_Type; /* 接入节点类型 */ uint8_t end_Flag; /* 结束标志 */
// uint16_t Communication_Methods; /* 通信方式 */ }recv_config_info;
// uint32_t bat485_Baud; /* 串口波特率 */
// uint32_t gw485_Baud; /* 串口波特率 */
// uint16_t ConstantCurrentV; /* 高于该(电压 / 100),小于ConstantVoltageV / 100电压进行恒流充电 */
// uint16_t ConstantVoltageV; /* 高于该(电压 / 100)且电流大于FloatI / 100进行恒压充电 */
// uint16_t FloatI; /* 高于该(电压 / 100)且电流低于FloatI / 100进行浮充充电 */
// uint16_t startSolarOpenCircuitV;/* 高于该(电压 / 100)开始充电 */
//}config_info;
typedef struct _config_info{ typedef struct _config_info{
uint8_t start_Flag[2]; /* 起始标志 */ /* SL */
uint8_t address[7]; /* 地址 */ uint8_t address[7]; /* 地址 */
uint32_t baud_485; /* 串口波特率 */ uint8_t Access_Node_Type[2]; /* 接入节点类型 */
uint16_t constantCurrentV; /* 电压高于(ConstantCurrentV / 100 + 0.4),小于ConstantVoltageV / 100 - 0.4进入mppt模式 */ uint8_t Communication_Methods[2]; /* 通信方式 */
uint8_t gw485_Baud[4]; /* 串口波特率,为0代表bms不支持通信 */
uint8_t bat485_Baud[4]; /* 串口波特率 */
/* HY */
uint8_t hardwareID[6]; /* 硬件ID */
uint8_t communicationID[4]; /* 通信ID */
uint8_t protocolType; /* 协议类型; 0x01表示汇源协议(波特率9600) 0x02表示南瑞协议(波特率115200)*/
uint16_t constantVoltageV; /* 电压高于该(ConstantVoltageV / 100)且电流大于FloatI / 100 + 0.1)进行恒压充电 */ uint16_t constantVoltageV; /* 电压高于该(ConstantVoltageV / 100)且电流大于FloatI / 100 + 0.1)进行恒压充电 */
uint16_t floatI; /* 电压高于该(ConstantVoltageV / 100)且电流低于FloatI / 100进行浮充充电 */ uint16_t floatI; /* 电压高于该(ConstantVoltageV / 100)且电流低于FloatI / 100进行浮充充电 */
uint16_t startSolarOpenCircuitV; /* 太阳能板开路电压高于该(电压 / 100)开始充电 */ uint16_t startSolarOpenCircuitV; /* 太阳能板开路电压高于该(电压 / 100)开始充电 */
uint16_t stopSolarOpenCircuitV; /* 太阳能板开路电压高于该(电压 / 100)停止充电 */ uint16_t stopSolarOpenCircuitV; /* 太阳能板开路电压高于该(电压 / 100)停止充电 */
uint16_t constantVoltageChargeV; /* 恒压充电时的输出电压 */ uint16_t constantVoltageChargeV; /* 恒压充电时的输出电压 */
uint16_t trickleChargeC; /* 涓流充电电流 */
// uint16_t FloatTime; /* 浮充时间(秒) */
uint16_t FloatV; /* 浮充电压 */ uint16_t FloatV; /* 浮充电压 */
uint16_t checkSolarOpenCircuitVTime; /* 启动任务中太阳能板开路电压检测时间 */ uint16_t checkSolarOpenCircuitVTime; /* 启动任务中太阳能板开路电压检测时间 */
uint16_t registerRefreshTime; /* 寄存器数据刷新时间 */ uint16_t registerRefreshTime; /* 寄存器数据刷新时间 */
uint16_t loopImpedance; /* 回路阻抗大小 */
// uint16_t resRefreshTime; /* 回路阻抗计算间隔时长 */
uint16_t sensorEnableBroadcastTime; /* 传感器运行再次注册的间隔 */ uint16_t sensorEnableBroadcastTime; /* 传感器运行再次注册的间隔 */
uint16_t HighSideMosTemperature_stop; /* 当上桥温度达到该值时,停止输出 */ uint16_t HighSideMosTemperature_stop; /* 当上桥温度达到该值时,停止输出 */
uint16_t HighSideMosTemperature_end; /* 当上桥温度上升到该值时,降低功率运行 */ uint16_t HighSideMosTemperature_end; /* 当上桥温度上升到该值时,降低功率运行 */
uint16_t HighSideMosTemperature_start; /* 当上桥温度降低到该值时,按照正常情况输出 */ uint16_t HighSideMosTemperature_start; /* 当上桥温度降低到该值时,按照正常情况输出 */
uint16_t loopImpedance; /* 回路阻抗大小 (mΩ) */
uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 */ uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 */
uint16_t excessiveLoadFlagTime; /* 出现过载后,在该段时间中再次出现过载,则关闭输出 */ uint16_t excessiveLoadFlagTime; /* 出现过载后,在该段时间中再次出现过载,则关闭输出 */
uint16_t eLAgainTime; /* 出现过载过载保护后,该段时间后,再次尝试输出 */ uint16_t eLAgainTime; /* 出现过载过载保护后,该段时间后,再次尝试输出 */
uint8_t end_Flag; /* 结束标志 */
uint16_t crc; /* 校验 */
}config_info; }config_info;
#define CONFIG_INFO_SIZE (sizeof(config_info)) #define CONFIG_INFO_SIZE (sizeof(config_info))
#pragma pack(pop) #pragma pack(pop)
extern config_info g_slConfigInfo; #define CONFIG_SAVE_ADDR_BEGIN (0x00)
#define CONFIG_SAVE_ADDR_END (0x00 + CONFIG_INFO_SIZE)
#define FLASH_SAVE_ADDR_BEGIN (0x00)
#define FLASH_SAVE_ADDR_END (0x00 + CONFIG_INFO_SIZE)
void save_config_info(config_info *save_config_info);
uint8_t read_config_info(void);
uint8_t read_config_info1(config_info *in_config_info);
#endif /* APP_INC_INFLASH_H_ */ #endif /* APP_INC_INFLASH_H_ */

View File

@ -11,14 +11,5 @@
#include "debug.h" #include "debug.h"
#include <math.h> #include <math.h>
extern float g_duty_ratio;
void mppt_readJust(void);
void MpptMode(void);
void mppt_constantVoltage(float InVoltage);
void test(void);
void printf_data(void);
//float_t get_capturedata(float_t (*fun)(void));
uint16_t get_mpptMode(void);
#endif /* APP_INC_MPPT_CONTROL_H_ */ #endif /* APP_INC_MPPT_CONTROL_H_ */

79
App/inc/parameter.h Normal file
View File

@ -0,0 +1,79 @@
/*
* parameter.h
*
* Created on: 20241012
* Author: psx
*/
#ifndef APP_INC_PARAMETER_H_
#define APP_INC_PARAMETER_H_
#include "debug.h"
#include "math.h"
#include "uart_dev.h"
typedef struct _Mppt_controlparameter{
float_t constantVoltageV; /* 电压高于ConstantVoltageV且电流大于FloatI + 0.1)进行恒压充电
(ConstantVoltageV - 0.2) (V) */
float_t floatI; /* 电压高于该ConstantVoltageV且电流低于FloatI进行浮充充电 (A) */
float_t startSolarOpenCircuitV; /* 太阳能板开路电压高于该电压开始充电 (V) */
float_t stopSolarOpenCircuitV; /* 太阳能板开路电压高于该电压停止充电 (V) */
float_t constantVoltageChargeV; /* 恒压充电时的输出电压 (V) */
float_t FloatV; /* 浮充充电时的输出电压 (V) */
float_t loopImpedance; /* 回路阻抗大小 (mΩ) */
float_t HighSideMosTemperature_stop; /* 当上桥温度达到该值时,停止输出 (°C) */
float_t HighSideMosTemperature_end; /* 当上桥温度上升到该值时,降低功率运行 (°C) */
float_t HighSideMosTemperature_start; /* 当上桥温度降低到该值时,按照正常情况输出 (°C) */
uint16_t sensorEnableBroadcastTime; /* 传感器运行再次注册的间隔 */
uint16_t checkSolarOpenCircuitVTime; /* 启动任务中太阳能板开路电压检测间隔时间 (S) */
uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 (S) */
uint16_t excessiveLoadFlagTime; /* 出现过载后在该间隔时间中多次2次出现过载则关闭输出 (S) */
uint16_t eLAgainTime; /* 出现过载过载保护后,在该间隔段时间后,再次尝试输出 (S) */
} Mppt_controlparameter;
extern Mppt_controlparameter g_controlParameter;
typedef struct _Mppt_otherParameter{
/* SL */
uint8_t address[7]; /* 地址 */
uint16_t Access_Node_Type; /* 接入节点类型 */
uint16_t Communication_Methods; /* 通信方式 */
uint16_t Registration_Status; /* 注册状态 */
uint32_t gw485_Baud; /* 串口波特率 */
uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */
/* HY */
uint8_t hardwareID[6]; /* 硬件ID */
uint8_t communicationID[4]; /* 通信ID */
uint8_t protocolType; /* 协议类型; 0x01表示汇源协议(波特率9600) 0x02表示南瑞协议(波特率115200)*/
float_t Battery_Voltage; /* 电池电压 (V) */
float_t Output_Voltage; /* 输出电压 */
float_t Charg_Current; /* 充电电流(流向电池+负载) (A) */
float_t Discharg_Current; /* 放电电流(流向负载) (A) */
float_t Input_Voltage; /* 太阳能板输入电压 (V) */
float_t Solar_Open_Circuit_Voltage; /* 太阳能板开路电压 (V) */
float_t HighSideMos_Temperature; /* 高端mos的温度 (°C) */
float_t Solar_In_Circuit_Voltage; /* 太阳能板输入电压 (V) */
float_t Charg_BatteryCurrent; /* 电池充电电流(流向电池) (A) */
float_t totalElectricityConsumption; /* 总电量消耗 */
float_t totalChargCapacity; /* 总充电电量 */
float_t SOC; /* 剩余电量 */
uint16_t chargMos_State; /* 充电开关状态 */
uint16_t DischargMos_State; /* 放电mos的状态 */
uint16_t MPPT_Mode; /* 工作模式 */
uint8_t versionInformation[13]; /* 软件版本信息 */
}Mppt_otherParameter;
extern Mppt_otherParameter g_otherParameter;
#endif /* APP_INC_PARAMETER_H_ */

View File

@ -219,23 +219,6 @@ typedef struct _default_Value{
extern default_Value defaultValue; extern default_Value defaultValue;
typedef struct _SL_Mppt_para{
uint16_t Registration_Status; /* 注册状态 */
uint8_t address[7]; /* 地址 */
uint16_t Access_Node_Type; /* 接入节点类型 */
uint16_t Communication_Methods; /* 通信方式 */
float_t Output_Voltage; /* 输出电压 */
float_t Battery_Voltage; /* 电池电压 */
float_t Charg_Current; /* 充电电流(流向电池+负载) */
float_t Discharg_Current; /* 放电电流(流向负载) */
float_t Input_Voltage; /* 太阳能板输出电压 */
float_t Solar_Open_Circuit_Voltage; /* 太阳能板开路电压 */
float_t HighSideMos_Temperature; /* 高端mos的温度 */
uint16_t DischargMos_State; /* 放电mos的状态 */
uint16_t MPPT_Mode; /* 工作模式 */
}SL_Mppt_para;
extern SL_Mppt_para g_Mppt_Para;
/* 恢复默认的对齐设置 */ /* 恢复默认的对齐设置 */
#pragma pack(pop) #pragma pack(pop)

View File

@ -13,79 +13,9 @@
#include "uart_dev.h" #include "uart_dev.h"
#include "math.h" #include "math.h"
//extern uint8_t g_interruptNum;
void stop_mpptWork(void);
void start_mpptWork(void);
#define runled_reloadVal 1000 /* 任务执行间隔 */
#define runled_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset m_runled;
extern void Task_RunLED(void);
#define startMpptControl_reloadVal 1000 /* 任务执行间隔 */
#define startMpptControl_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset m_startMpptControl;;
extern void Task_startMpptControl(void);
#define softStart_reloadVal 30 /* 任务执行间隔 */
#define softStart_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset m_softStart;
extern void Task_softStart(void);
#define usart_reloadVal 100 /* 任务执行间隔 */
#define usart_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset m_usart;
extern uint8_t RegistrationRequestFlag; /* 接收到广播帧标志位 */
void Task_usart(void);
#define wdi_reloadVal 1000 /* 任务执行间隔 */
#define wdi_offset 30 /* 任务执行偏移量 */
#define wdi_RESET (60 * 60 * 24) /* 一天复位一次 */
extern STR_TimeSliceOffset m_wdi;
extern void Task_wdi(void);
#define refreshRegister_reloadVal 1000 /* 任务执行间隔 */
#define refreshRegister_offset 100 /* 任务执行偏移量 */
extern STR_TimeSliceOffset m_refreshRegister;
extern uint8_t overTemperature;
extern void Task_refreshRegister(void);
#define recvbroadcast_reloadVal 3000 /* 任务执行间隔 */
#define recvbroadcast_offset 0 /* 任务执行偏移量 */
extern uint8_t recvbroadcast_flag; /* 是否需要再次发送标志 */
extern device_handle g_recvBroadcastDevice; /* 串口句柄 */
extern uint8_t g_recvBroadcastRegisterNumber; /* 寄存器长度 */
extern STR_TimeSliceOffset m_recvbroadcast;
extern void Task_recvbroadcast(void);
#define impedanceCalculation_reloadVal 200 /* 任务执行间隔 */
#define impedanceCalculation_offset 0 /* 任务执行偏移量 */
extern float_t g_impedance;
extern uint8_t g_batteryState;
extern uint8_t g_impedanceStart;
extern STR_TimeSliceOffset m_impedanceCalculation;
extern void Task_impedanceCalculation(void);
#define outputAgain_reloadVal 1000 /* 任务执行间隔 */
#define outputAgain_offset 0 /* 任务执行偏移量 */
extern uint8_t outputAgainFlag;
extern STR_TimeSliceOffset m_outputAgain;
extern void Task_outputAgain(void);
#define excessiveLoad_reloadVal 1000 /* 任务执行间隔 */
#define excessiveLoad_offset 0 /* 任务执行偏移量 */
extern uint8_t excessiveLoadFlag;
extern STR_TimeSliceOffset m_excessiveLoad;
extern void Task_excessiveLoad(void);
#define sensorEnableBroadcast_reloadVal 1000 /* 任务执行间隔 */
#define sensorEnableBroadcast_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset m_sensorEnableBroadcast;
/* 是否接收广播帧标志位 */
extern uint8_t run_Broadcast;
extern void Task_sensorEnableBroadcast(void);
void task_Init(void);
void hardware_Init(void);
#endif /* APP_INC_TASK_H_ */ #endif /* APP_INC_TASK_H_ */

412
App/src/hy_protocol.c Normal file
View File

@ -0,0 +1,412 @@
/*
* hy_protocol.c
*
* Created on: 20241011
* Author: psx
*/
#include "hy_protocol.h"
#include <string.h>
#include "inflash.h"
#include "pdebug.h"
#include "mppt_control.h"
#include <stdlib.h>
#include "task.h"
#include "tim.h"
HY_default_Value HY_defaultValue = {0x68\
, 0x48, 0x59, 0x30, 0x30, 0x30, 0x31\
, 0x00, 0x00, 0x00, 0x01\
, 0x16};
/* 读取串口数据时用该数组解析 */
static uint8_t rs485_buff[100]={0x00};
/* 电池状态数据报 */
static void HY_MsgProcFunc_batteryStatus(device_handle device, void *pMsg, uint32_t MsgLen);
/* 电量统计数据报 */
static void HY_MsgProcFunc_electricityStatistics(device_handle device, void *pMsg, uint32_t MsgLen);
/* 传感器号码配置 */
static void HY_MsgProcFunc_sensorNumberConfiguration(device_handle device, void *pMsg, uint32_t MsgLen);
/* 传感器号码查询 */
static void HY_MsgProcFunc_sensorNumberInquiry(device_handle device, void *pMsg, uint32_t MsgLen);
/* 充电阈值电压配置 */
static void HY_MsgProcFunc_chargingThresholdVoltageConfiguration(device_handle device, void *pMsg, uint32_t MsgLen);
/* 充电域值电压查询 */
static void HY_MsgProcFunc_chargingRangeVoltageQuery(device_handle device, void *pMsg, uint32_t MsgLen);
/* 复位指令 */
static void HY_MsgProcFunc_resetInstruction(device_handle device, void *pMsg, uint32_t MsgLen);
/* 充电控制配置 */
static void HY_MsgProcFunc_chargingControlConfiguration(device_handle device, void *pMsg, uint32_t MsgLen);
/* 充电控制查询 */
static void HY_MsgProcFunc_chargingControlQuery(device_handle device, void *pMsg, uint32_t MsgLen);
/* 配置协议类型 */
static void HY_MsgProcFunc_configureProtocolType(device_handle device, void *pMsg, uint32_t MsgLen);
///* 响应配置协议类型 */
//static void HY_MsgProcFunc_batteryStatus(device_handle device, void *pMsg, uint32_t MsgLen);
/* 查询电池控制盒当前配置 */
static void HY_MsgProcFunc_queryControlBoxConfiguration(device_handle device, void *pMsg, uint32_t MsgLen);
/* 查询电池控制盒软件版本 */
static void HY_MsgProcFunc_querySoftwareVersion(device_handle device, void *pMsg, uint32_t MsgLen);
/* 进入配置模式 */
static void HY_MsgProcFunc_enterConfigurationMode(device_handle device, void *pMsg, uint32_t MsgLen);
/* 配置控制盒硬件ID号 */
static void HY_MsgProcFunc_configureHardwareID(device_handle device, void *pMsg, uint32_t MsgLen);
/* 控制盒硬件ID号及通信ID号原传感器号查询 */
static void HY_MsgProcFunc_hardwareID_communicationIDQuery(device_handle device, void *pMsg, uint32_t MsgLen);
/* 修改通信ID号原传感器号 */
static void HY_MsgProcFunc_modifyCommunicationID(device_handle device, void *pMsg, uint32_t MsgLen);
/* 查询主板温度值 */
static void HY_MsgProcFunc_checkMotherboardTemperature(device_handle device, void *pMsg, uint32_t MsgLen);
/* 功能码处理表 */
HY_FuncionMsgProcTable g_hyMsgTbl[] =
{
{HY_batteryStatus, HY_MsgProcFunc_batteryStatus},
{HY_electricityStatistics, HY_MsgProcFunc_electricityStatistics},
{HY_sensorNumberConfiguration, HY_MsgProcFunc_sensorNumberConfiguration},
{HY_sensorNumberInquiry, HY_MsgProcFunc_sensorNumberInquiry},
{HY_chargingThresholdVoltageConfiguration, HY_MsgProcFunc_chargingThresholdVoltageConfiguration},
{HY_chargingRangeVoltageQuery, HY_MsgProcFunc_chargingRangeVoltageQuery},
{HY_resetInstruction, HY_MsgProcFunc_resetInstruction},
{HY_chargingControlConfiguration, HY_MsgProcFunc_chargingControlConfiguration},
{HY_chargingControlQuery, HY_MsgProcFunc_chargingControlQuery},
{HY_configureProtocolType, HY_MsgProcFunc_configureProtocolType},
// {HY_responseConfigureProtocolType, HY_MsgProcFunc_batteryStatus},
{HY_queryControlBoxConfiguration, HY_MsgProcFunc_queryControlBoxConfiguration},
{HY_querySoftwareVersion, HY_MsgProcFunc_querySoftwareVersion},
{HY_enterConfigurationMode, HY_MsgProcFunc_enterConfigurationMode},
{HY_configureHardwareID, HY_MsgProcFunc_configureHardwareID},
{HY_hardwareID_communicationIDQuery, HY_MsgProcFunc_hardwareID_communicationIDQuery},
{HY_modifyCommunicationID, HY_MsgProcFunc_modifyCommunicationID},
{HY_checkMotherboardTemperature, HY_MsgProcFunc_checkMotherboardTemperature},
};
/**
* @brief 485线
* @param
* @retval 1
* 0
*/
uint8_t HY_Check_485_bus_busy(device_handle device)
{
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
uint16_t num_ago = ring_queue_length(device);
Delay_Ms(2);
uint16_t num_now = ring_queue_length(device);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, DISABLE);
}
if (num_now == num_ago) {
return 0;
}
return 1;
}
/**
* @brief
* @param
* @retval
*/
uint8_t HY_CheckFunc(uint8_t *arr_buff, uint8_t len)
{
uint8_t temp = 0x00;
uint32_t sum = 0x00;
for(uint8_t i = 0; i < len; i++) {
sum += *arr_buff++;
}
temp = (~sum) & 0xff;
return temp;
}
/**
* @brief
* @param address
* @retval 1
* 0
*/
static int HY_matchhardwareID(u_int8_t hardwareID[6])
{
//// if (!strcmp(address, g_slConfigInfo.address)) {
//// log_info("Match_address fail \r\n");
//// return 1;
//// }
// if ((hardwareID[0] == g_slConfigInfo.address[0]) && \
// (hardwareID[1] == g_slConfigInfo.address[1]) && \
// (hardwareID[2] == g_slConfigInfo.address[2]) && \
// (hardwareID[3] == g_slConfigInfo.address[3]) && \
// (hardwareID[4] == g_slConfigInfo.address[4]) && \
// (hardwareID[5] == g_slConfigInfo.address[5]) && \
// (hardwareID[6] == g_slConfigInfo.address[6])) {
// log_info("Match_address success \r\n");
// return 1;
// }
return 0;
}
/**
* @brief 广
* @param address
* @retval 1
* 0
*/
static int Match_Broadcastaddress(u_int8_t address[6])
{
if (address[0] == 0xFF && \
address[1] == 0xFF && \
address[2] == 0xFF && \
address[3] == 0xFF && \
address[4] == 0xFF && \
address[5] == 0xFF && \
address[6] == 0xFF) {
log_info("Match_Broadcastaddress success\r\n");
return 1;
}
return 0;
}
/**
* @brief
* @param uart_handle
* @param buff
* @param buff_size
* @retval
*/
static int HY_uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint32_t buff_size)
{
uint32_t offset = 0;
uint32_t len = 0;
uint8_t flag_run = 0;
char c = 0;
HY_Recv_pack *pack = (HY_Recv_pack *)buff;
buff_size--; //预留一个'\0'位置
for (; offset < buff_size;){
if (ring_queue_length(uart_handle) == 0) {
break;
}
c = uart_dev_in_char(uart_handle);
buff[offset++] = c;
/* 匹配起始标志位 */
if (offset == HY_analyzeStartFlag || (flag_run > 0)) {
if (pack->start_Flag != HY_defaultValue.start_Flag) {
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
/* 匹配硬件ID */
if (offset == HY_analyzeHardwareID || (flag_run > 1)) {
if (HY_matchhardwareID(pack->hardwareID) || Match_Broadcastaddress(pack->hardwareID)) {
if (flag_run < 1) {
flag_run = 1;
}
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
}
return 0;
}
/**
* @brief
* @param
* @retval
*/
static void HY_FRT_MsgHandler(device_handle device, uint8_t *pMsg, uint32_t MsgLen)
{
HY_Recv_pack *pack = (HY_Recv_pack *)pMsg;
for (u_int16_t i = 0; i < sizeof(g_hyMsgTbl) / sizeof(HY_FuncionMsgProcTable); i++){
if (pack->controlWord == g_hyMsgTbl[i].msgId){
g_hyMsgTbl[i].pMsgProc(device, pMsg, MsgLen);
}
}
}
/**
* @brief
* @param
* @retval
*/
void HY_read_and_process_uart_data(device_handle device)
{
// printf("ring_queue_length = %d \n", ring_queue_length(device));
// if (ring_queue_length(device) > 10) {uart_dev_char_present(device_handle device)
if (uart_dev_char_present(device)) {
Delay_Ms(20);
// printf("ring_queue_length = %d \n", ring_queue_length(device));
memset(rs485_buff, 0, sizeof(rs485_buff));
int ret = HY_uart_read_climate_pack(device, rs485_buff, sizeof(rs485_buff));
if(ret > 0){
HY_FRT_MsgHandler(device, rs485_buff, ret);
}
}
}
/* 电池状态数据报 */
void HY_MsgProcFunc_batteryStatus(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 电量统计数据报 */
void HY_MsgProcFunc_electricityStatistics(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 传感器号码配置 */
void HY_MsgProcFunc_sensorNumberConfiguration(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 传感器号码查询 */
void HY_MsgProcFunc_sensorNumberInquiry(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 充电阈值电压配置 */
void HY_MsgProcFunc_chargingThresholdVoltageConfiguration(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 充电域值电压查询 */
void HY_MsgProcFunc_chargingRangeVoltageQuery(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 复位指令 */
void HY_MsgProcFunc_resetInstruction(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 充电控制配置 */
void HY_MsgProcFunc_chargingControlConfiguration(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 充电控制查询 */
static void HY_MsgProcFunc_chargingControlQuery(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 配置协议类型 */
void HY_MsgProcFunc_configureProtocolType(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
///* 响应配置协议类型 */
//static void HY_MsgProcFunc_batteryStatus(device_handle device, void *pMsg, uint32_t MsgLen);
/* 查询电池控制盒当前配置 */
void HY_MsgProcFunc_queryControlBoxConfiguration(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 查询电池控制盒软件版本 */
void HY_MsgProcFunc_querySoftwareVersion(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 进入配置模式 */
void HY_MsgProcFunc_enterConfigurationMode(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 配置控制盒硬件ID号 */
void HY_MsgProcFunc_configureHardwareID(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 控制盒硬件ID号及通信ID号原传感器号查询 */
void HY_MsgProcFunc_hardwareID_communicationIDQuery(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 修改通信ID号原传感器号 */
void HY_MsgProcFunc_modifyCommunicationID(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* 查询主板温度值 */
void HY_MsgProcFunc_checkMotherboardTemperature(device_handle device, void *pMsg, uint32_t MsgLen)
{
}

View File

@ -9,103 +9,6 @@
#include "flash.h" #include "flash.h"
#include "sl_protocol.h" #include "sl_protocol.h"
config_info g_slConfigInfo = {
.constantCurrentV = 1000,
.constantVoltageV = 1420,
.floatI = 20,
.startSolarOpenCircuitV = 1700,
.stopSolarOpenCircuitV = 1500,
.constantVoltageChargeV = 1440,
.trickleChargeC = 100,
// .FloatTime = 10,
.FloatV = 1420,
.checkSolarOpenCircuitVTime = 10,
.registerRefreshTime = 1,
.loopImpedance = 20,
// .resRefreshTime = 1,
.sensorEnableBroadcastTime = 20,
.HighSideMosTemperature_stop = 70,
.HighSideMosTemperature_end = 50,
.HighSideMosTemperature_start = 40,
.outputAgainFlagTime = 10,
.excessiveLoadFlagTime = 60,
.eLAgainTime = 3600,
};
/**
* @brief
* @param save_config_info
* @retval
*/
void save_config_info(config_info *save_config_info)
{
SPI_Flash_Write((uint8_t *)save_config_info, FLASH_SAVE_ADDR_BEGIN, CONFIG_INFO_SIZE);
}
/**
* @brief
* @param read_config_info
* @retval 0 flash中读取配置失败
* 1 flash中读取配置成功
*/
uint8_t read_config_info(void)
{
config_info temp_config_info;
SPI_Flash_Read((uint8_t *)&temp_config_info, FLASH_SAVE_ADDR_BEGIN, CONFIG_INFO_SIZE);
if (temp_config_info.start_Flag[0] == 'S'
&& temp_config_info.start_Flag[1] == 'L'
&& temp_config_info.end_Flag == 0x16) {
g_slConfigInfo = temp_config_info;
return 1;
}
else {
g_slConfigInfo.start_Flag[0] = defaultValue.start_Flag[0];
g_slConfigInfo.start_Flag[1] = defaultValue.start_Flag[1];
g_slConfigInfo.address[0] = defaultValue.address[0];
g_slConfigInfo.address[1] = defaultValue.address[1];
g_slConfigInfo.address[2] = defaultValue.address[2];
g_slConfigInfo.address[3] = defaultValue.address[3];
g_slConfigInfo.address[4] = defaultValue.address[4];
g_slConfigInfo.address[5] = defaultValue.address[5];
g_slConfigInfo.address[6] = defaultValue.address[6];
g_slConfigInfo.end_Flag = defaultValue.end_Flag;
}
return 0;
}
/**
* @brief
* @param read_config_info1 in_config_info中
* @retval 0 flash中读取配置失败使
* 1 flash中读取配置成功
*/
uint8_t read_config_info1(config_info *in_config_info)
{
config_info temp_config_info;
SPI_Flash_Read((uint8_t *)&temp_config_info, FLASH_SAVE_ADDR_BEGIN, CONFIG_INFO_SIZE);
if (temp_config_info.start_Flag[0] == 'S'
&& temp_config_info.start_Flag[1] == 'L'
&& temp_config_info.end_Flag == 0x16) {
*in_config_info = temp_config_info;
return 1;
} else {
in_config_info->start_Flag[0] = defaultValue.start_Flag[0];
in_config_info->start_Flag[1] = defaultValue.start_Flag[1];
in_config_info->address[0] = defaultValue.address[0];
in_config_info->address[1] = defaultValue.address[1];
in_config_info->address[2] = defaultValue.address[2];
in_config_info->address[3] = defaultValue.address[3];
in_config_info->address[4] = defaultValue.address[4];
in_config_info->address[5] = defaultValue.address[5];
in_config_info->address[6] = defaultValue.address[6];
in_config_info->end_Flag = defaultValue.end_Flag;
}
return 0;
}

View File

@ -12,916 +12,5 @@
#include "gpio.h" #include "gpio.h"
#include "sl_protocol.h" #include "sl_protocol.h"
#include "task.h" #include "task.h"
#include "uart_dev.h" #include "uart_dev.h"
#include "parameter.h"
static void TrickleCharge(void);
static void ConstantCurrentCharge(void);
static void ConstantVoltageCharge(void);
static void FloatingCharge(void);
//static void NoBatteryCharge(void);
/* 占空比 */
float g_duty_ratio = 0.75;
/* 用于确定工作模式 */
//static uint8_t modeFlag = 2;
/**
* @brief
* @param
* @retval OutputPower
*/
static float Get_OutputPower(void)
{
static float OutputPower;
static float V_out, I_out;
V_out = get_PV_VOLT_OUT();
I_out = get_CHG_CURR();
OutputPower = V_out * I_out;
printf(" V = %d/100, I = %d/10000, OutputPower = %d/10000 \r\n",
(int)(V_out*100), (int)(I_out * 10000), (int)(OutputPower * 10000));
return OutputPower;
}
/**
* @brief 使,,使
* @param
* @retval
*/
/* pwm占空比调节步长 */
const float step1_pwm = 0.01;
const float step2_pwm = 0.005;
//#define array_num 10
void mppt_readJust(void)
{
// static float last_duty_ratio = 0.5;
// static float now_duty_ratio;
// static float last_OutputPower;
// static float now_OutputPower;
// static float step_pwm = step1_pwm;
//
// last_OutputPower = Get_OutputPower();
//
// printf(" duty_ratio = %d/1000 \r\n", (int)(last_duty_ratio * 1000));
//
// /* 正向调节查看功率是否会变大 */
// now_duty_ratio = last_duty_ratio + step_pwm;
// if (now_duty_ratio > 1) {
// now_duty_ratio = 1;
// }
// Set_duty_ratio(now_duty_ratio);
// now_OutputPower = Get_OutputPower();
// if (now_OutputPower > last_OutputPower) {
// printf(" now_OutputPower > last_OutputPower1 \r\n");
// last_duty_ratio = now_duty_ratio;
// return;
// }
//
// /* 负向调节查看功率是否会变大 */
// now_duty_ratio = last_duty_ratio - step_pwm;
// if (now_duty_ratio < 0) {
// now_duty_ratio = 0;
// }
// Set_duty_ratio(now_duty_ratio);
// now_OutputPower = Get_OutputPower();
// if (now_OutputPower > last_OutputPower) {
// printf(" now_OutputPower > last_OutputPower2 \r\n");
// last_duty_ratio = now_duty_ratio;
// return;
// }
//
// /* 正负向调节功率均未变大,此时设置功率为原来的点 */
// Set_duty_ratio(last_duty_ratio);
// step_pwm = step2_pwm;
static float last_duty_ratio = 0.5;
static float last_OutputPower;
static float now_OutputPower;
static float step_pwm = step1_pwm;
last_OutputPower = Get_OutputPower();
printf(" duty_ratio = %d/1000 \r\n", (int)(last_duty_ratio * 1000));
/* 正向调节查看功率是否会变大 */
g_duty_ratio = last_duty_ratio + step_pwm;
Set_duty_ratio(&g_duty_ratio);
now_OutputPower = Get_OutputPower();
if (now_OutputPower > last_OutputPower) {
printf(" now_OutputPower > last_OutputPower1 \r\n");
last_duty_ratio = g_duty_ratio;
return;
}
/* 负向调节查看功率是否会变大 */
g_duty_ratio = last_duty_ratio - step_pwm;
Set_duty_ratio(&g_duty_ratio);
now_OutputPower = Get_OutputPower();
if (now_OutputPower > last_OutputPower) {
printf(" now_OutputPower > last_OutputPower2 \r\n");
last_duty_ratio = g_duty_ratio;
return;
}
/* 正负向调节功率均未变大,此时设置功率为原来的点 */
g_duty_ratio = last_duty_ratio;
Set_duty_ratio(&g_duty_ratio);
step_pwm = step2_pwm;
}
void printf_data(void)
{
printf("\n");
// get_CHG_CURR();
// get_PV_VOLT_OUT();
// get_DSG_CURR();
// get_PV1_VOLT_IN();
// get_PV_VOLT_IN1();
// get_MOSFET_Temper();
// get_PV2_VOLT_IN();
printf("\n");
}
//float_t get_capturedata(float_t (*fun)(void))
//{
// float_t temp1;
// float_t temp[3];
//
// for (int i = 0; i < 3; ++i) {
// temp[i] = fun();
//// Delay_Us(1);
// }
//
// if (temp[0] > temp[1]) {
// temp1 = temp[0];
// temp[0] = temp[1];
// temp[1] = temp1;
// }
//
// if (temp[0] > temp[2]) {
// temp1 = temp[0];
// temp[0] = temp[2];
// temp[2] = temp1;
// if (temp[1] > temp[2]) {
// temp1 = temp[1];
// temp[1] = temp[2];
// temp[2] = temp1;
// }
// }
//
// return temp[1];
//}
//uint16_t get_mpptMode(void)
//{
// return (uint16_t)modeFlag;
//}
/**
* @brief
* @param
* @retval
*
*/
void mppt_constantVoltage(float InVoltage)
{
// static uint8_t ConstantVoltageFlag = 1;
// float PV1_V = get_PV1_VOLT_IN();
//
// if (ConstantVoltageFlag) {
// if (PV1_V > InVoltage) {
// g_duty_ratio += step1_pwm;
// Set_duty_ratio(&g_duty_ratio);
// } else {
// g_duty_ratio -= step1_pwm;
// Set_duty_ratio(&g_duty_ratio);
// }
//
// if (PV1_V - InVoltage < 0.1) {
// ConstantVoltageFlag = 0;
// }
// } else {
// if (PV1_V > InVoltage) {
// g_duty_ratio += step2_pwm;
// Set_duty_ratio(&g_duty_ratio);
// } else {
// g_duty_ratio -= step2_pwm;
// Set_duty_ratio(&g_duty_ratio);
// }
//
// if (PV1_V - InVoltage > 0.1) {
// ConstantVoltageFlag = 1;
// }
// }
static float_t kp = 0.005;
static float_t ki = 0.00001;
// static float_t allError = 0;
// float_t error = (get_PV1_VOLT_IN()) - InVoltage;
// float_t error = InVoltage - (get_PV2_VOLT_IN());
// allError += error;
// printf("111\n");
// float_t pv1Volt = get_capturedata(get_PV1_VOLT_IN);
// float_t pv1Volt = get_PV1_VOLT_IN();
float_t pv1Volt = g_Mppt_Para.Input_Voltage;
// printf("volt in : %d \n", pv1Volt);
float_t error = pv1Volt - InVoltage;
// float_t error = InVoltage - pv1Volt;
float_t stepPwm = kp * error + ki * pv1Volt;
g_duty_ratio += stepPwm;
// printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
// printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
// printf("g_duty_ratio : %d/10000 \n", (int)(g_duty_ratio * 10000));
Set_duty_ratio(&g_duty_ratio);
}
/**
* @brief ()
* @param
* @retval
*
*/
void mppt_constantVoltageB(float OutVoltage)
{
// static uint8_t ConstantVoltageFlag = 1;
// float PV1_V = get_PV_VOLT_OUT();
//
// if (ConstantVoltageFlag) {
// if (PV1_V > OutVoltage) {
// g_duty_ratio -= step1_pwm;
// Set_duty_ratio(&g_duty_ratio);
// } else {
// g_duty_ratio += step1_pwm;
// Set_duty_ratio(&g_duty_ratio);
// }
//
// if (PV1_V - OutVoltage < 0.1) {
// ConstantVoltageFlag = 0;
// }
// } else {
// if (PV1_V > OutVoltage) {
// g_duty_ratio -= step2_pwm;
// Set_duty_ratio(&g_duty_ratio);
// } else {
// g_duty_ratio += step2_pwm;
// Set_duty_ratio(&g_duty_ratio);
// }
//
// if (PV1_V - OutVoltage > 0.1) {
// ConstantVoltageFlag = 1;
// }
// }
// static float_t kp = 0.0005;
// static float_t ki = 0.000001;
static float_t kp = 0.005;
static float_t ki = 0.00001;
// static float_t kp = 0.1;
// static float_t ki = 0.001;
// float_t outVolt = get_PV_VOLT_OUT();
float_t outVolt = g_Mppt_Para.Battery_Voltage;
// float_t outVolt = voltOut;
// float_t error = outVolt - OutVoltage;
float_t error = OutVoltage - outVolt;
float_t stepPwm = kp * error + ki * outVolt;
g_duty_ratio += stepPwm;
// printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
Set_duty_ratio(&g_duty_ratio);
}
/**
* @brief
* @param
* @retval
*
*/
void mppt_constantVoltageO(float OutVoltage)
{
// static uint8_t ConstantVoltageFlag = 1;
// float PV1_V = get_PV_VOLT_OUT();
//
// if (ConstantVoltageFlag) {
// if (PV1_V > OutVoltage) {
// g_duty_ratio -= step1_pwm;
// Set_duty_ratio(&g_duty_ratio);
// } else {
// g_duty_ratio += step1_pwm;
// Set_duty_ratio(&g_duty_ratio);
// }
//
// if (PV1_V - OutVoltage < 0.1) {
// ConstantVoltageFlag = 0;
// }
// } else {
// if (PV1_V > OutVoltage) {
// g_duty_ratio -= step2_pwm;
// Set_duty_ratio(&g_duty_ratio);
// } else {
// g_duty_ratio += step2_pwm;
// Set_duty_ratio(&g_duty_ratio);
// }
//
// if (PV1_V - OutVoltage > 0.1) {
// ConstantVoltageFlag = 1;
// }
// }
// static float_t kp = 0.0005;
// static float_t ki = 0.000001;
static float_t kp = 0.005;
static float_t ki = 0.00001;
// static float_t kp = 0.1;
// static float_t ki = 0.001;
// float_t outVolt = get_PV_VOLT_OUT();
float_t outVolt = g_Mppt_Para.Output_Voltage;
// float_t outVolt = voltOut;
// float_t error = outVolt - OutVoltage;
float_t error = OutVoltage - outVolt;
float_t stepPwm = kp * error + ki * outVolt;
g_duty_ratio += stepPwm;
// printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
Set_duty_ratio(&g_duty_ratio);
}
/**
* @brief
* @param
* @retval
*
*/
void mppt_constantCurrentO(float outCurrent)
{
// static uint8_t ConstantCurrent = 1;
// float out_I = get_CHG_CURR();
//
// if (ConstantCurrent) {
// if (out_I > outCurrent) {
// g_duty_ratio -= step1_pwm;
// Set_duty_ratio(&g_duty_ratio);
// } else {
// g_duty_ratio += step1_pwm;
// Set_duty_ratio(&g_duty_ratio);
// }
//
// if (out_I - outCurrent < 0.1) {
// ConstantCurrent = 0;
// }
// }
//
// else {
// if (out_I > outCurrent) {
// g_duty_ratio -= step2_pwm;
// Set_duty_ratio(&g_duty_ratio);
// } else {
// g_duty_ratio += step2_pwm;
// Set_duty_ratio(&g_duty_ratio);
// }
//
// if (out_I - outCurrent > 0.1) {
// ConstantCurrent = 1;
// }
// }
static float_t kp = 0.005;
static float_t ki = 0.00005;
// static float_t last_CHG_CURR = 0;
// static float_t flag = 1;
// static float_t last_OutputPower = 0;
// float_t outCurr = get_CHG_CURR();
float_t outCurr = g_Mppt_Para.Charg_Current;
// float_t OutputPower = outCurr * get_PV_VOLT_OUT();
float_t error = outCurrent - outCurr;
// float_t error = outCurr - outCurrent;
float_t stepPwm = kp * error + ki * outCurr;
// if (flag) {
// if (OutputPower > last_OutputPower) {
// g_duty_ratio += stepPwm;
// flag = 1;
// } else {
// g_duty_ratio -= stepPwm;
// flag = 0;
// }
// } else {
// if (OutputPower > last_OutputPower) {
// g_duty_ratio -= stepPwm;
// flag = 0;
// } else {
// g_duty_ratio += stepPwm;
// flag = 1;
// }
// }
//
// last_OutputPower = OutputPower;
g_duty_ratio += stepPwm;
// printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
// printf("g_duty_ratio : %d/10000 \n", (int)(g_duty_ratio * 10000));
Set_duty_ratio(&g_duty_ratio);
// last_CHG_CURR = outCurr;
// if (stepPwm > 0 && (last_CHG_CURR > outCurr)) {
// flag = 1;
// } else {
// flag = 0;
// }
}
/**
* @brief
* @param
* @retval
*
*/
void TrickleCharge(void)
{
static float_t TrickleChargeC;
static uint8_t onlyOnce = 1;
if (onlyOnce) {
TrickleChargeC = (float_t)g_slConfigInfo.trickleChargeC / 100;
onlyOnce = 0;
}
// printf("Trickle\n");
mppt_constantCurrentO(TrickleChargeC + g_Mppt_Para.Discharg_Current);
}
/**
* @brief mppt最大功率充电
* @param
* @retval
*
*/
void ConstantCurrentCharge(void)
{
// mppt_readJust();
mppt_constantVoltage(18);
// printf("ConstantCurrent\n");
}
/**
* @brief
* @param
* @retval
*
*/
void ConstantVoltageCharge(void)
{
static float_t ConstantVoltageChargeV;
static uint8_t onlyOnce = 1;
if (onlyOnce) {
ConstantVoltageChargeV = (float_t)g_slConfigInfo.constantVoltageChargeV / 100;
onlyOnce = 0;
}
mppt_constantVoltageO(ConstantVoltageChargeV);
}
/**
* @brief
* @param
* @retval
*
*/
void FloatingCharge(void)
{
// static uint32_t num = 0;
// static uint32_t numLenFlag;
// static uint8_t onlyOnce = 1;
// if (onlyOnce) {
// numLenFlag = g_slConfigInfo.FloatTime * 1000;
// onlyOnce = 0;
// }
// printf("float\n");
// TIM_SetCompare4(TIM4, 0);
// if (numLenFlag == ++num) {
// num = 0;
// for (int var = 0; var < 10; ++var) {
// ConstantVoltageCharge();
// }
// g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
// printf("float\n");
// }
static float_t FloatChargeV;
static uint8_t onlyOnce = 1;
if (onlyOnce) {
FloatChargeV = (float_t)g_slConfigInfo.FloatV / 100;
onlyOnce = 0;
}
mppt_constantVoltageO(FloatChargeV);
}
/**
* @brief
* @param
* @retval
*
*/
void NoBatteryCharge(void)
{
// static float_t NoBatteryChargeV;
// static uint8_t onlyOnce = 1;
// if (onlyOnce) {
// NoBatteryChargeV = (float_t)g_slConfigInfo.noBatteryChargeV / 100;
// onlyOnce = 0;
// }
mppt_constantVoltageO(14.2);
// if ((g_Mppt_Para.Battery_Voltage - NoBatteryChargeV > 0.2 && g_Mppt_Para.Charg_Current < 0.1)
// || (NoBatteryChargeV - g_Mppt_Para.Battery_Voltage > 0.1 && g_Mppt_Para.Charg_Current > 0.5)) {
// ConstantCurrentCharge();
// g_Mppt_Para.MPPT_Mode = CONSTANTCURRENT;
// }
// if (!overTemperature) {
// if (!(g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < 0.3
// && g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current < 0.3)) {
// ConstantCurrentCharge();
// g_Mppt_Para.MPPT_Mode = CONSTANTCURRENT;
// }
// }
}
void MpptContorl(void)
{
switch(g_Mppt_Para.MPPT_Mode) {
case TRICKLE:
// printf("111\n");
TrickleCharge();
break;
case CONSTANTCURRENT:
// printf("222222\n");
ConstantCurrentCharge();
// ConstantVoltageCharge();
break;
case CONSTANTVOLTAGE:
// printf("333333333\n");
ConstantVoltageCharge();
break;
case FLOAT:
// printf("444444444444\n");
FloatingCharge();
break;
// case NoBattery:
//// printf("555555555555555\n");
// NoBatteryCharge();
// break;
default:
break;
}
}
void MpptMode(void)
{
// printf("vout : %d /100 \n", (int)(g_Mppt_Para.Battery_Voltage * 100));
// printf("iout : %d /1000 \n", (int)(g_Mppt_Para.Charg_Current * 1000));
// printf("in checkSolarOpenCircuitVoltage v: %d/100 \n", (int)(g_Mppt_Para.Solar_Open_Circuit_Voltage * 100));
static float ConstantCurrentV;
static float ConstantVoltageV;
static float FloatI;
static float StopSolarOpenCircuitV;
/* 赋值仅执行一次 */
static uint8_t only_once = 1;
if (only_once) {
ConstantCurrentV = (float)g_slConfigInfo.constantCurrentV / 100;
ConstantVoltageV = (float)g_slConfigInfo.constantVoltageV / 100;
FloatI = (float)g_slConfigInfo.floatI / 100;
printf("FloatI: %d / 100 \n", (int)(FloatI * 100));
StopSolarOpenCircuitV = (float)g_slConfigInfo.stopSolarOpenCircuitV / 100;
only_once = 0;
}
//// if (g_Mppt_Para.Battery_Voltage > 16 || g_Mppt_Para.Battery_Voltage < 8
//// || modeFlag == NoBattery) {
//// modeFlag = NoBattery;
// if (g_Mppt_Para.Battery_Voltage > 16 || g_Mppt_Para.Battery_Voltage < 8
// || g_Mppt_Para.MPPT_Mode == NoBattery) {
// g_Mppt_Para.MPPT_Mode = NoBattery;
// return;
// }
//
//// if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage) &&
//// (FloatI > g_Mppt_Para.Charg_Current)) || modeFlag == FLOAT) {
//// modeFlag = FLOAT;
// if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage) &&
// (FloatI > g_Mppt_Para.Charg_Current)) || g_Mppt_Para.MPPT_Mode == FLOAT) {
// g_Mppt_Para.MPPT_Mode = FLOAT;
// return;
// }
//
// if (((ConstantCurrentV + 0.4) < g_Mppt_Para.Battery_Voltage) &&
// ((ConstantVoltageV - 0.4) >= g_Mppt_Para.Battery_Voltage)) {
//// modeFlag = CONSTANTCURRENT;
// g_Mppt_Para.MPPT_Mode = CONSTANTCURRENT;
// return;
// }
//
// if ((ConstantVoltageV < g_Mppt_Para.Battery_Voltage) &&
// (FloatI + 0.1 <= g_Mppt_Para.Charg_Current)) {
//// modeFlag = CONSTANTVOLTAGE;
// g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
// return;
// }
//
// if (ConstantCurrentV > g_Mppt_Para.Battery_Voltage) {
//// modeFlag = TRICKLE;
// g_Mppt_Para.MPPT_Mode = TRICKLE;
// return;
// }
// if (g_Mppt_Para.Battery_Voltage > 16 || g_Mppt_Para.Battery_Voltage < 8
// || g_Mppt_Para.MPPT_Mode == NoBattery) {
// g_Mppt_Para.MPPT_Mode = NoBattery;
// return;
// }
// if (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < 0.05
// || g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current < 0.05) {
// g_Mppt_Para.MPPT_Mode = NoBattery;
// return;
// }
//
// if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage) &&
// (FloatI > g_Mppt_Para.Charg_Current)) || g_Mppt_Para.MPPT_Mode == FLOAT) {
// g_Mppt_Para.MPPT_Mode = FLOAT;
// return;
// }
//
// if (((ConstantCurrentV + 0.4) < g_Mppt_Para.Battery_Voltage) &&
// ((ConstantVoltageV - 0.4) >= g_Mppt_Para.Battery_Voltage)) {
// g_Mppt_Para.MPPT_Mode = CONSTANTCURRENT;
// return;
// }
//
// if ((ConstantVoltageV < g_Mppt_Para.Battery_Voltage) &&
// (FloatI + 0.1 <= g_Mppt_Para.Charg_Current)) {
// g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
// return;
// }
//
// if (ConstantCurrentV > g_Mppt_Para.Battery_Voltage) {
// g_Mppt_Para.MPPT_Mode = TRICKLE;
// return;
// }
// if (g_Mppt_Para.Input_Voltage < StopSolarOpenCircuitV
// && (g_Mppt_Para.Discharg_Current >= g_Mppt_Para.Charg_Current
// || g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < 0.05)) {
if ((g_Mppt_Para.Input_Voltage < StopSolarOpenCircuitV && g_Mppt_Para.Charg_Current < 0.05)
&& g_Mppt_Para.MPPT_Mode != NoWork) {
g_Mppt_Para.MPPT_Mode = NoWork;
// printf("nowork \n");
stop_mpptWork();
TimeSliceOffset_Register(&m_startMpptControl, Task_startMpptControl
, startMpptControl_reloadVal, startMpptControl_offset);
return;
}
// if (((g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < 0.03
// && g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current < 0.03)
// && (g_Mppt_Para.Battery_Voltage < ConstantVoltageV - 1
// || g_Mppt_Para.Battery_Voltage > ConstantVoltageV + 1))
// || g_Mppt_Para.MPPT_Mode == NoBattery) {
// g_Mppt_Para.MPPT_Mode = NoBattery;
// return;
// }
// if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage) &&
// (FloatI > g_Mppt_Para.Charg_Current)) || g_Mppt_Para.MPPT_Mode == FLOAT) {
// g_Mppt_Para.MPPT_Mode = FLOAT;
// return;
// }
if ((g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < 0.05
&& g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current < 0.05)
|| g_Mppt_Para.Battery_Voltage > 16 || g_Mppt_Para.Battery_Voltage < 8) {
// || g_Mppt_Para.MPPT_Mode == NoBattery) {
// g_Mppt_Para.MPPT_Mode = NoBattery;
// g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
g_Mppt_Para.MPPT_Mode = FLOAT;
// printf("Charg_Current : %d/100 \n", (int)(g_Mppt_Para.Charg_Current * 100));
// printf("Discharg_Current : %d/100 \n", (int)(g_Mppt_Para.Discharg_Current * 100));
// printf("Battery_Voltage : %d/100 \n", (int)(g_Mppt_Para.Battery_Voltage * 100));
g_batteryState = 0;
return;
}
if ((((ConstantCurrentV + 0.2) < g_Mppt_Para.Battery_Voltage)
&&((ConstantVoltageV - 0.2) >= g_Mppt_Para.Battery_Voltage))
&&(g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current > 0.1)) {
g_Mppt_Para.MPPT_Mode = CONSTANTCURRENT;
return;
}
// if ((g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current > 4)) {
// g_Mppt_Para.MPPT_Mode = CONSTANTCURRENT;
// return;
// }
// if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage)
// &&(FloatI + 0.1 <= g_Mppt_Para.Charg_Current))
// || (FloatI + 0.1 <= g_Mppt_Para.Discharg_Current)) {
//// || (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < 0.03
//// && g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current < 0.03)) {
//
//// printf("mppt mode \n");
//// printf(" vout : %d/100 \n", (int)(g_Mppt_Para.Battery_Voltage * 100));
// g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
// return;
// }
if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage)
&&(FloatI + 0.1 <= g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current))) {
g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
return;
}
if ((((ConstantVoltageV < g_Mppt_Para.Battery_Voltage)
&& (FloatI > g_Mppt_Para.Charg_Current))
&& (FloatI > g_Mppt_Para.Discharg_Current))) {
// || g_Mppt_Para.MPPT_Mode == FLOAT) {
g_Mppt_Para.MPPT_Mode = FLOAT;
return;
}
if (ConstantCurrentV > g_Mppt_Para.Battery_Voltage) {
g_Mppt_Para.MPPT_Mode = TRICKLE;
return;
}
}
void findMiNDutyRatio(void)
{
static uint8_t num = 100;
if (0.05 < get_CHG_CURR()) {
num -= 1;
TIM_SetCompare4(TIM4, num);
}
else {
printf("min duty ratio : %d/200 \n", num);
}
}
void test(void)
{
// mppt_readjust();
// Get_OutputPower();
// mppt_constantVoltage(18);
// findMiNDutyRatio();
// MpptContorl();
// printf_data();
// void MpptContorl();
// mppt_constantVoltageO(12);
// FloatingCharge();
// mppt_readJust();
// mppt_constantCurrentO(1);
// if (g_interruptNum < 5) {
// g_interruptNum++;
// return;
// }
// g_Mppt_Para.Charg_Current = get_capturedata(get_CHG_CURR);
// g_Mppt_Para.Discharg_Current = get_capturedata(get_DSG_CURR);
// g_Mppt_Para.Output_Voltage = get_capturedata(get_PV_VOLT_OUT);
// g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
g_Mppt_Para.Charg_Current = get_CHG_CURR();
g_Mppt_Para.Discharg_Current = get_DSG_CURR();
g_Mppt_Para.Output_Voltage = get_PV_VOLT_OUT();
g_Mppt_Para.Input_Voltage = get_PV1_VOLT_IN();
// mppt_constantVoltage(18);
// return;
if (g_Mppt_Para.Discharg_Current == 0 && g_Mppt_Para.Charg_Current == 0) {
return;
}
// g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
// static float_t Volt = 0.7;
// static float_t Curr = 5.5;
// static float_t loopImpedance;
// static uint8_t onlyone = 1;
// if (onlyone) {
// loopImpedance = (float_t)g_slConfigInfo.loopImpedance / 100;
// }
static float_t inBatteryCurr;
static float_t outBatteryCurr;
inBatteryCurr = g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current;
outBatteryCurr = g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current;
if (inBatteryCurr > 0.1) {
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage - inBatteryCurr * g_impedance;
} else {
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
}
if (g_batteryState == 0 && (inBatteryCurr > 0.1 || outBatteryCurr > 0.1) && g_Mppt_Para.Output_Voltage < 14.2) {
// printf("int g_batteryState : %d\n", g_batteryState);
g_batteryState = 1;
// TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
// , impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
}
// mppt_constantVoltage(18);
// if (g_Mppt_Para.MPPT_Mode == CONSTANTCURRENT
// || g_Mppt_Para.MPPT_Mode == CONSTANTVOLTAGE) {
//
// g_Mppt_Para.Battery_Voltage = get_capturedata(get_PV_VOLT_OUT)
// - g_impedance * (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current);
// } else {
// g_Mppt_Para.Battery_Voltage = get_capturedata(get_PV_VOLT_OUT);
// }
// voltOut = get_capturedata(get_PV_VOLT_OUT);
// g_Mppt_Para.Battery_Voltage = voltOut - g_impedance * (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current);
// ConstantVoltageCharge();
// return;
if (!overTemperature) {
MpptMode();
MpptContorl();
}
// mppt_constantVoltageO(12);
// static uint32_t run_num = 0;
// if (1000 < run_num++) {
// FloatingCharge();
// run_num = 1200;
// printf("in floatcharge \n");
// return;
// }
// mppt_readJust();
// mppt_constantCurrentO(1.2);
// int16_t var = 0;
// char buff[4];
// for (var = 0; var < 100; ++var) {
// sprintf(buff, "%3d:", var);
// uart_dev_write(g_gw485_uart4_handle, buff, sizeof(buff));
// uart_dev_write(g_gw485_uart4_handle, "1234567890\n", sizeof("1234567890\n"));
// Delay_Ms(1);
// }
// uart_dev_write(g_gw485_uart4_handle, "\n\n\n\n\n\n", sizeof("\n\n\n\n\n\n"));
}

12
App/src/parameter.c Normal file
View File

@ -0,0 +1,12 @@
/*
* parameter.c
*
* Created on: 20241012
* Author: psx
*/
#include "parameter.h"
Mppt_controlparameter g_controlParameter = {0};
Mppt_otherParameter g_otherParameter = {0};

View File

@ -13,858 +13,10 @@
#include <stdlib.h> #include <stdlib.h>
#include "task.h" #include "task.h"
#include "tim.h" #include "tim.h"
#include "parameter.h"
default_Value defaultValue = {'S', 'L'\ default_Value defaultValue = {'S', 'L'\
, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11\ , 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11\
, POWERBOX\ , POWERBOX\
, RS485 , RS485
, 0x16}; , 0x16};
SL_Mppt_para g_Mppt_Para = {0};
/* 静态函数申明 */
static void SL_MsgProcFunc_Read_Register(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFunc_Write_Register(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFunc_Broadcast_Scan(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFunc_Registration_request(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFunc_Update_Profile(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFunc_Remote_Upgrade(device_handle device, void *pMsg, uint32_t MsgLen);
//static uint16_t SL_ReadRegisterRegistrationStatus(void *pMsg);
//static uint16_t SL_ReadRegisteraddress(void *pMsg);
//static uint16_t SL_ReadRegisterAccessNodeType(void *pMsg);
//static uint16_t SL_ReadRegisterCommunicationMethods(void *pMsg);
static uint16_t SL_ReadRegisterBatteryVoltage(void *pMsg);
static uint16_t SL_ReadRegisterChargCurrent(void *pMsg);
static uint16_t SL_ReadRegisterDischargCurrent(void *pMsg);
static uint16_t SL_ReadRegisterSolarOpenCircuitVoltage(void *pMsg);
static uint16_t SL_ReadRegisterHighSideMosTemperature(void *pMsg);
static uint16_t SL_ReadRegisterDischargMosState(void *pMsg);
static uint16_t SL_ReadRegisterMPPTMode(void *pMsg);
//static uint16_t SL_WriteRegisterRegistrationStatus(void *pMsg);
//static uint16_t SL_WriteRegisteraddress(void *pMsg);
//static uint16_t SL_WriteRegisterAccessNodeType(void *pMsg);
//static uint16_t SL_WriteRegisterCommunicationMethods(void *pMsg);
//static uint16_t SL_WriteRegisterBatteryVoltage(void *pMsg);
//static uint16_t SL_WriteRegisterBatterytemperature(void *pMsg);
//static uint16_t SL_WriteRegisterRemainingBatteryBower(void *pMsg);
//static uint16_t SL_WriteRegisterSolarOpenCircuitVoltage1(void *pMsg);
//static uint16_t SL_WriteRegisterSolarOpenCircuitVoltage2(void *pMsg);
/* 读取串口数据时用该数组解析 */
static uint8_t rs485_buff[50]={0x00};
/* 一次最多读写的寄存器个数,由设备决定 */
#define Register_Number_Max 5
/* 寄存器个数,由设备决定 */
#define MPPT_Register_Number 5
/* 读写的寄存器的最大起始位置,由设备决定 */
#define Register_Start_Address_Max 0x0200
/* 用于解析串口包时的长度 */
#define analyzeStartFlag 2 //长度为2时解析起始标志
#define analyzeAddress 9 //长度为9时解析地址
#define analyzeFunctionCode 10 //长度为10时解析功能码
#define analyzeWritelen 14 //功能码为写入寄存器且buffer长度为14时可以解析出写入寄存器包的长度
/* 功能码处理表 */
SL_FuncionMsgProcTable g_MsgTbl[] =
{
{SL_Function_Code_Read_Register, SL_MsgProcFunc_Read_Register},
{SL_Function_Code_Write_Register, SL_MsgProcFunc_Write_Register},
{SL_Function_Code_Broadcast_Scan, SL_MsgProcFunc_Broadcast_Scan},
{SL_Function_Code_Registration_request, SL_MsgProcFunc_Registration_request},
{SL_Function_Code_Update_Profile, SL_MsgProcFunc_Update_Profile},
{SL_Function_Code_Remote_Upgrade, SL_MsgProcFunc_Remote_Upgrade},
};
/* 寄存器处理表 */
SL_RegProcTable g_RegTblR[] =
{
// {SL_Register_Registration_Status, SL_ReadRegisterRegistrationStatus},
// {SL_Register_address, SL_ReadRegisteraddress},
// {SL_Register_Access_Node_Type, SL_ReadRegisterAccessNodeType},
// {SL_Register_Communication_Methods, SL_ReadRegisterCommunicationMethods},
{SL_Register_Battery_Voltage, SL_ReadRegisterBatteryVoltage},
{SL_Register_Charg_Current, SL_ReadRegisterChargCurrent},
{SL_Register_Discharg_Current, SL_ReadRegisterDischargCurrent},
{SL_Register_Solar_Open_Circuit_Voltage, SL_ReadRegisterSolarOpenCircuitVoltage},
{SL_Register_HighSideMos_Temperature, SL_ReadRegisterHighSideMosTemperature},
{SL_Register_DischargMos_State, SL_ReadRegisterDischargMosState},
{SL_Register_MPPT_Mode, SL_ReadRegisterMPPTMode},
};
/* 寄存器处理表 */
SL_RegProcTable g_RegTblW[] =
{
// {SL_Register_Registration_Status, SL_WriteRegisterRegistrationStatus},
// {SL_Register_address, SL_WriteRegisteraddress},
// {SL_Register_Access_Node_Type, SL_WriteRegisterAccessNodeType},
// {SL_Register_Communication_Methods, SL_WriteRegisterCommunicationMethods},
// {SL_Register_Battery_Voltage, SL_WriteRegisterBatteryVoltage},
// {SL_Register_Battery_temperature, SL_WriteRegisterBatterytemperature},
// {SL_Register_Remaining_Battery_Bower, SL_WriteRegisterRemainingBatteryBower},
// {SL_Register_Solar_Open_Circuit_Voltage1, SL_WriteRegisterSolarOpenCircuitVoltage1},
// {SL_Register_Solar_Open_Circuit_Voltage2, SL_WriteRegisterSolarOpenCircuitVoltage2},
};
/**
* @brief
* @param
* @retval
*/
uint16_t CheckFunc(uint8_t *arr_buff, uint8_t len)
{
uint16_t crc = 0xFFFF;
uint16_t i, j;
for (j = 0; j < len; ++j) {
crc = crc ^ (*arr_buff++);
for (i = 0; i < 8; ++i) {
if ((crc&0x0001) > 0) {
crc = crc >> 1;
crc = crc ^ 0xa001;
}
else {
crc = crc >> 1;
}
}
}
return crc;
}
/**
* @brief ,100-2500ms10ms  
* @param
* @retval
*/
int randomDelay()
{
int minSeconds = 10;
int maxSeconds = 250;
// srand(SystemCoreClock);//time(NULL)替换为对应操作系统时钟
srand(TIM_GetCounter(TIM4));
int delaySeconds = minSeconds + rand() % (maxSeconds - minSeconds + 1);
return delaySeconds * 10;
}
/**
* @brief 485线
* @param
* @retval 1
* 0
*/
uint8_t Check_485_bus_busy(device_handle device)
{
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
uint16_t num_ago = ring_queue_length(device);
Delay_Ms(2);
uint16_t num_now = ring_queue_length(device);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, DISABLE);
}
if (num_now == num_ago) {
return 0;
}
return 1;
}
/**
* @brief
* @param
* @retval
*/
void SL_MsgProcFunc_Read_Register(device_handle device, void *pMsg, uint32_t MsgLen)
{
SL_Mppt_Rorecv_pack *rpack = (SL_Mppt_Rorecv_pack *)pMsg;
uint16_t Register_Number_16 = chang_8_to_16(rpack->read_Register_Number_L,rpack->read_Register_Number_H);
if (Register_Number_16 > Register_Number_Max) {
log_error(" Register_Number error:%x \r\n", Register_Number_16);
return;
}
uint16_t Start_Address_16 = chang_8_to_16(rpack->read_Register_Start_Address_L,rpack->read_Register_Start_Address_H);
if (Start_Address_16 > Register_Start_Address_Max) {
log_error(" Register_Start_Address error : %x \r\n", Start_Address_16);
return;
}
/* 读取寄存器数据 */
// uint8_t reply_Data_Content[2 * 5] = {0};
uint16_t reply_Data_Content[Register_Number_Max] = {0};
for ( uint16_t pos = 0; pos < Register_Number_16; pos++) {
for (uint16_t var = 0; var < sizeof(g_RegTblR) / sizeof(SL_RegProcTable); var++) {
if (g_RegTblR[var].regId == (Start_Address_16 + pos)) {
// *(uint16_t *)&reply_Data_Content[pos * 2] = g_RegTblR[var].pRegProc(NULL);
reply_Data_Content[pos] = g_RegTblR[var].pRegProc(NULL);
}
}
}
/* 打包 */
memset(rs485_buff, 0, sizeof(rs485_buff));
uint8_t *replay_pack = rs485_buff;
// strlcpy(replay_pack, g_slConfigInfo.start_Flag, 2);
*(replay_pack) = g_slConfigInfo.start_Flag[0];
*(replay_pack + 1) = g_slConfigInfo.start_Flag[1];
replay_pack += 2;
// strlcpy(replay_pack, g_slConfigInfo.address, 7);
*(replay_pack) = g_slConfigInfo.address[0];
*(replay_pack + 1) = g_slConfigInfo.address[1];
*(replay_pack + 2) = g_slConfigInfo.address[2];
*(replay_pack + 3) = g_slConfigInfo.address[3];
*(replay_pack + 4) = g_slConfigInfo.address[4];
*(replay_pack + 5) = g_slConfigInfo.address[5];
*(replay_pack + 6) = g_slConfigInfo.address[6];
replay_pack += 7;
*replay_pack = SL_Function_Code_Read_Register;
replay_pack += 1;
// *(uint16_t *)&replay_pack = rpack->read_Register_Number;
*replay_pack = (Register_Number_16 >> 8);
*(replay_pack + 1) = (Register_Number_16);
replay_pack += 2;
for (uint8_t var = 0; var < Register_Number_16 * 2; var++) {
if (0 == (var & 0x01)) {
*(replay_pack + var) = (reply_Data_Content[var / 2] >> 8);
} else {
*(replay_pack + var) = (reply_Data_Content[var / 2]);
}
}
replay_pack += Register_Number_16 * 2;
uint16_t crc_temp = CheckFunc(rs485_buff, (2 + 7 + 1 + 2 + Register_Number_16 * 2));
// log_info("CheckFunc crc_temp: %x \r\n", crc_temp);
*replay_pack = (uint8_t)(crc_temp >> 8);
replay_pack += 1;
*replay_pack = (uint8_t)crc_temp;
replay_pack += 1;
*replay_pack = g_slConfigInfo.end_Flag;
while (1) {
Delay_Ms(randomDelay());
if (!Check_485_bus_busy(device)) {
// log_info("pack : %s", (uint8_t *)&replay_pack);
// uart_dev_write(device, (uint8_t *)&replay_pack, 16 + Register_Number_16 * 2 + 1);
uart_dev_write(device, rs485_buff, 16 + Register_Number_16 * 2);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
}
}
void SL_MsgProcFunc_Write_Register(device_handle device, void *pMsg, uint32_t MsgLen)
{
SL_Mppt_Worecv_pack *wpack = (SL_Mppt_Worecv_pack *)pMsg;
uint8_t *buff = (uint8_t *)pMsg;
uint16_t Register_Number = \
chang_8_to_16(wpack->write_Register_Number_L, wpack->write_Register_Number_H);
if (Register_Number > Register_Number_Max) {
log_error(" Register_Number error:%x \r\n", Register_Number);
return;
}
uint16_t Register_Start_Address = \
chang_8_to_16(wpack->write_Register_Start_Address_L, wpack->write_Register_Start_Address_H);
if (Register_Start_Address > Register_Start_Address_Max) {
log_error(" Register_Start_Address error : %x \r\n", Register_Start_Address);
return;
}
printf("in write register \n");
uint16_t content[Register_Number_Max] = {0};
for (uint16_t var = 0; var < Register_Number; var++) {
content[var] = buff[14 + 2 * var] << 8 | buff[14 + 2 * var + 1];
}
for ( uint16_t pos = 0; pos < Register_Number; pos++) {
for (uint16_t i = 0; i < sizeof(g_RegTblW) / sizeof(SL_RegProcTable); i++) {
if (g_RegTblW[i].regId == (Register_Start_Address + pos)) {
g_RegTblW[i].pRegProc(&content[pos]);
}
}
}
}
void SL_MsgProcFunc_Broadcast_Scan(device_handle device, void *pMsg, uint32_t MsgLen)
{
g_recvBroadcastDevice = device;
g_recvBroadcastRegisterNumber = MPPT_Register_Number;
RegistrationRequestFlag = 1;
/* 任务创立后,立即执行一次 */
TimeSliceOffset_Register(&m_recvbroadcast, Task_recvbroadcast \
, recvbroadcast_reloadVal, recvbroadcast_offset);
m_recvbroadcast.runFlag = 1;
}
void SL_MsgProcFunc_Registration_request(device_handle device, void *pMsg, uint32_t MsgLen)
{
log_info("Registration success \r\n");
recvbroadcast_flag = 1;
RegistrationRequestFlag = 0;
TimeSliceOffset_Unregister(&m_recvbroadcast);
m_recvbroadcast.runFlag = 0;
SL_Mppt_RegistrationReply_pack *rpack = (SL_Mppt_RegistrationReply_pack *)pMsg;
g_Mppt_Para.Registration_Status = chang_8_to_16(rpack->registration_Status_L, rpack->registration_Status_H);
/* 20s内不再接收广播帧 */
TimeSliceOffset_Register(&m_sensorEnableBroadcast, Task_sensorEnableBroadcast
, sensorEnableBroadcast_reloadVal, sensorEnableBroadcast_offset);
}
void SL_MsgProcFunc_Update_Profile(device_handle device, void *pMsg, uint32_t MsgLen)
{
SL_Mppt_SOther_pack SUpdateProfile_pack = {0};
SUpdateProfile_pack.start_Flag[0] = g_slConfigInfo.start_Flag[0];
SUpdateProfile_pack.start_Flag[1] = g_slConfigInfo.start_Flag[1];
SUpdateProfile_pack.address[0] = g_slConfigInfo.address[0];
SUpdateProfile_pack.address[1] = g_slConfigInfo.address[1];
SUpdateProfile_pack.address[2] = g_slConfigInfo.address[2];
SUpdateProfile_pack.address[3] = g_slConfigInfo.address[3];
SUpdateProfile_pack.address[4] = g_slConfigInfo.address[4];
SUpdateProfile_pack.address[5] = g_slConfigInfo.address[5];
SUpdateProfile_pack.address[6] = g_slConfigInfo.address[6];
SUpdateProfile_pack.function_Code = SL_Function_Code_Update_Profile;
SUpdateProfile_pack.state = 0x01;
uint16_t crc = CheckFunc((uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE - 3);
SUpdateProfile_pack.check_Bit_H = crc >> 8;
SUpdateProfile_pack.check_Bit_L = crc;
SUpdateProfile_pack.end_Flag = g_slConfigInfo.end_Flag;
while (1) {
Delay_Ms(randomDelay());
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, (uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE + 1);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
}
}
void SL_MsgProcFunc_Remote_Upgrade(device_handle device, void *pMsg, uint32_t MsgLen)
{
SL_Mppt_SOther_pack SUpdateProfile_pack = {0};
SUpdateProfile_pack.start_Flag[0] = g_slConfigInfo.start_Flag[0];
SUpdateProfile_pack.start_Flag[1] = g_slConfigInfo.start_Flag[1];
SUpdateProfile_pack.address[0] = g_slConfigInfo.address[0];
SUpdateProfile_pack.address[1] = g_slConfigInfo.address[1];
SUpdateProfile_pack.address[2] = g_slConfigInfo.address[2];
SUpdateProfile_pack.address[3] = g_slConfigInfo.address[3];
SUpdateProfile_pack.address[4] = g_slConfigInfo.address[4];
SUpdateProfile_pack.address[5] = g_slConfigInfo.address[5];
SUpdateProfile_pack.address[6] = g_slConfigInfo.address[6];
SUpdateProfile_pack.function_Code = SL_Function_Code_Remote_Upgrade;
SUpdateProfile_pack.state = 0x01;
uint16_t crc = CheckFunc((uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE - 3);
SUpdateProfile_pack.check_Bit_H = crc >> 8;
SUpdateProfile_pack.check_Bit_L = crc;
SUpdateProfile_pack.end_Flag = g_slConfigInfo.end_Flag;
while (1) {
Delay_Ms(randomDelay());
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, (uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE + 1);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
}
}
///**
// * @brief 读取注册状态寄存器
// * @param
// * @retval
// */
//uint16_t SL_ReadRegisterRegistrationStatus(void *pMsg)
//{
// log_info(" SL_ReadRegisterRegistrationStatus ");
// uint16_t value = g_Mppt_Para.Registration_Status;
// return value;
//}
//
///**
// * @brief 读取地址寄存器
// * @param
// * @retval
// */
//uint16_t SL_ReadRegisteraddress(void *pMsg)
//{
// log_info(" SL_ReadRegisteraddress ");
//
// return 0;
//}
//
///**
// * @brief 读取接入节点类型寄存器
// * @param
// * @retval
// */
//uint16_t SL_ReadRegisterAccessNodeType(void *pMsg)
//{
// log_info(" SL_ReadRegisterAccessNodeType ");
// uint16_t value = g_Mppt_Para.Access_Node_Type;
// return value;
//}
//
///**
// * @brief 读取通信方式寄存器
// * @param
// * @retval
// */
//uint16_t SL_ReadRegisterCommunicationMethods(void *pMsg)
//{
// log_info(" SL_ReadRegisterCommunicationMethods ");
// uint16_t value = g_Mppt_Para.Communication_Methods;
// return value;
//}
/**
* @brief
* @param
* @retval
*/
uint16_t SL_ReadRegisterBatteryVoltage(void *pMsg)
{
log_info(" SL_ReadRegisterBatteryVoltage ");
uint16_t value = (uint16_t)(g_Mppt_Para.Battery_Voltage * 10);
return value;
}
/**
* @brief
* @param
* @retval
*/
uint16_t SL_ReadRegisterChargCurrent(void *pMsg)
{
log_info(" SL_ReadRegisterChargCurrent ");
uint16_t value = (uint16_t)(g_Mppt_Para.Charg_Current * 10);
return value;
}
/**
* @brief
* @param
* @retval
*/
uint16_t SL_ReadRegisterDischargCurrent(void *pMsg)
{
log_info(" SL_ReadRegisterDischargCurrent ");
uint16_t value = (uint16_t)(g_Mppt_Para.Discharg_Current * 10);
return value;
}
/**
* @brief
* @param
* @retval
*/
uint16_t SL_ReadRegisterSolarOpenCircuitVoltage(void *pMsg)
{
log_info(" SL_ReadRegisterSolarOpenCircuitVoltage ");
uint16_t value = (uint16_t)(g_Mppt_Para.Solar_Open_Circuit_Voltage * 10);
return value;
}
/**
* @brief mos管的温度寄存器
* @param
* @retval
*/
uint16_t SL_ReadRegisterHighSideMosTemperature(void *pMsg)
{
log_info(" SL_ReadRegisterHighSideMosTemperature ");
uint16_t value = (uint16_t)(g_Mppt_Para.HighSideMos_Temperature * 10);
return value;
}
/**
* @brief mos管状态寄存器
* @param
* @retval
*/
uint16_t SL_ReadRegisterDischargMosState(void *pMsg)
{
log_info(" SL_ReadRegisterDischargMosState ");
uint16_t value = (uint16_t)g_Mppt_Para.DischargMos_State;
return value;
}
/**
* @brief mppt工作模式寄存器
* @param
* @retval
*/
uint16_t SL_ReadRegisterMPPTMode(void *pMsg)
{
log_info(" SL_ReadRegisterMPPTMode ");
uint16_t value = (uint16_t)g_Mppt_Para.MPPT_Mode;
return value;
}
///**
// * @brief 写入注册状态寄存器
// * @param
// * @retval
// */
//uint16_t SL_WriteRegisterRegistrationStatus(void *pMsg)
//{
// log_info(" WriteRegisterRegistrationStatus %x", *(uint16_t *)pMsg);
//
// return 0;
//}
//
///**
// * @brief 写入地址寄存器
// * @param
// * @retval
// */
//uint16_t SL_WriteRegisteraddress(void *pMsg)
//{
// log_info(" WriteRegisteraddress %x", *(uint16_t *)pMsg);
//
// return 0;
//}
//
///**
// * @brief 写入接入节点类型寄存器
// * @param
// * @retval
// */
//uint16_t SL_WriteRegisterAccessNodeType(void *pMsg)
//{
// log_info(" WriteRegisterAccessNodeType %x", *(uint16_t *)pMsg);
//
// return 0;
//}
//
///**
// * @brief 写入通信方式寄存器
// * @param
// * @retval
// */
//uint16_t SL_WriteRegisterCommunicationMethods(void *pMsg)
//{
// log_info(" WriteRegisterCommunicationMethods %x", *(uint16_t *)pMsg);
//
// return 0;
//}
/**
* @brief "SL"
* @param start_buff
* @retval 1
* 0
*/
static int Match_Startflag(uint8_t start_buff[2])
{
// if (!strcmp(start_buff, g_slConfigInfo.start_Flag)) {
// log_info("Match_Startflag fail \r\n");
// return 1;
// }
if ((start_buff[0] == g_slConfigInfo.start_Flag[0]) && \
(start_buff[1] == g_slConfigInfo.start_Flag[1])) {
log_info("Match_Startflag success \r\n");
return 1;
}
return 0;
}
/**
* @brief
* @param address
* @retval 1
* 0
*/
static int Match_address(u_int8_t address[7])
{
// if (!strcmp(address, g_slConfigInfo.address)) {
// log_info("Match_address fail \r\n");
// return 1;
// }
if ((address[0] == g_slConfigInfo.address[0]) && \
(address[1] == g_slConfigInfo.address[1]) && \
(address[2] == g_slConfigInfo.address[2]) && \
(address[3] == g_slConfigInfo.address[3]) && \
(address[4] == g_slConfigInfo.address[4]) && \
(address[5] == g_slConfigInfo.address[5]) && \
(address[6] == g_slConfigInfo.address[6])) {
log_info("Match_address success \r\n");
return 1;
}
return 0;
}
/**
* @brief 广
* @param address
* @retval 1
* 0
*/
static int Match_Broadcastaddress(u_int8_t address[7])
{
if (address[0] == 0xFF && \
address[1] == 0xFF && \
address[2] == 0xFF && \
address[3] == 0xFF && \
address[4] == 0xFF && \
address[5] == 0xFF && \
address[6] == 0xFF) {
log_info("Match_Broadcastaddress success\r\n");
return 1;
}
return 0;
}
/**
* @brief
* @param uart_handle
* @param buff
* @param buff_size
* @retval
*/
static int uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint32_t buff_size)
{
uint32_t offset = 0;
uint32_t len = 0;
uint8_t flag_run = 0;
char c = 0;
SL_Mppt_Recv_pack *pack = (SL_Mppt_Recv_pack *)buff;
buff_size--; //预留一个'\0'位置
for (; offset < buff_size;){
if (ring_queue_length(uart_handle) == 0) {
break;
}
c = uart_dev_in_char(uart_handle);
buff[offset++] = c;
/* 匹配起始标志位 */
if (offset == analyzeStartFlag || (flag_run > 0)) {
if (!Match_Startflag(pack->start_Flag)) {
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
/* 匹配地址 */
if (offset == analyzeAddress || (flag_run > 1)) {
if (!((((g_Mppt_Para.Registration_Status == 2) || RegistrationRequestFlag) && Match_address(pack->address))
|| (run_Broadcast && Match_Broadcastaddress(pack->address)))) {
if (flag_run < 1) {
flag_run = 1;
}
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
/* 匹配功能码 */
if (offset == analyzeFunctionCode || (flag_run > 2)) {
/* 未注册时,不处理读写和其他帧 */
if (g_Mppt_Para.Registration_Status == 2) {
/* 读寄存器数据 */
if (pack->function_Code == SL_Function_Code_Read_Register) {
log_info("Read_Register\r\n");
len = SL_MPPT_RORECV_PACK_SIZE;
}
/* 写寄存器数据 */
else if (pack->function_Code == SL_Function_Code_Write_Register) {
log_info("Write_Register\r\n");
}
/* 其他帧格式 */
else if (pack->function_Code == SL_Function_Code_Update_Profile
|| pack->function_Code == SL_Function_Code_Remote_Upgrade) {
len = SL_MPPT_ROTHER_PACK_SIZE;
log_info("Other frames\r\n");
}
else if (run_Broadcast) {
/* 广播扫描 */
if (pack->function_Code == SL_Function_Code_Broadcast_Scan) {
log_info("Broadcast_Scan\r\n");
len = SL_MPPT_SCAN_BROADCAST_PACK_SIZE;
}
/* 注册请求 */
else if (pack->function_Code == SL_Function_Code_Registration_request) {
log_info("Registration_request\r\n");
len = SL_MPPT_REGISTRATIONREPLY_PACK_SIZE;
}
else {
if (flag_run < 2) {
flag_run = 2;
}
log_info("funcode error %x\r\n", pack->function_Code);
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
else {
if (flag_run < 2) {
flag_run = 2;
}
log_info("funcode error %x\r\n", pack->function_Code);
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
/* 广播扫描 */
else if (pack->function_Code == SL_Function_Code_Broadcast_Scan) {
log_info("Broadcast_Scan\r\n");
len = SL_MPPT_SCAN_BROADCAST_PACK_SIZE;
}
/* 注册请求 */
else if (pack->function_Code == SL_Function_Code_Registration_request) {
log_info("Registration_request\r\n");
len = SL_MPPT_REGISTRATIONREPLY_PACK_SIZE;
}
else {
if (flag_run < 2) {
flag_run = 2;
}
log_info("funcode error %x\r\n", pack->function_Code);
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
if ((pack->function_Code == SL_Function_Code_Write_Register) && (offset >= 14)) {
SL_Mppt_Worecv_pack *wpack = (SL_Mppt_Worecv_pack *)buff;
uint8_t Register_Number = (wpack->write_Register_Number_H << 8) | wpack->write_Register_Number_L;
len = Register_Number * 2 + SL_MPPT_WORECV_PACK_SIZE - 4;
continue;
}
if (offset == len) {
uint16_t crc_16 = chang_8_to_16(buff[offset - 2], buff[offset - 3]);
if ((CheckFunc(buff, offset - 3) != crc_16) || (buff[offset - 1] != 0x16)) {
if (flag_run < 3) {
flag_run = 3;
}
memcpy(buff, buff+1, offset-1);
offset--;
} else {
return offset;
}
}
}
return 0;
}
/**
* @brief
* @param
* @retval
*/
void FRT_MsgHandler(device_handle device, uint8_t *pMsg, uint32_t MsgLen)
{
SL_Mppt_Recv_pack *pack = (SL_Mppt_Recv_pack *)pMsg;
for (u_int16_t i = 0; i < sizeof(g_MsgTbl) / sizeof(SL_FuncionMsgProcTable); i++){
if (pack->function_Code == g_MsgTbl[i].msgId){
g_MsgTbl[i].pMsgProc(device, pMsg, MsgLen);
}
}
}
/**
* @brief
* @param
* @retval
*/
void read_and_process_uart_data(device_handle device)
{
// printf("ring_queue_length = %d \n", ring_queue_length(device));
// if (ring_queue_length(device) > 10) {uart_dev_char_present(device_handle device)
if (uart_dev_char_present(device)) {
Delay_Ms(20);
// printf("ring_queue_length = %d \n", ring_queue_length(device));
memset(rs485_buff, 0, sizeof(rs485_buff));
int ret = uart_read_climate_pack(device, rs485_buff, sizeof(rs485_buff));
if(ret > 0){
FRT_MsgHandler(device, rs485_buff, ret);
}
}
}

View File

@ -22,811 +22,6 @@
#include "inflash.h" #include "inflash.h"
#include <stdlib.h> #include <stdlib.h>
#include "collect_Conversion.h" #include "collect_Conversion.h"
#include "parameter.h"
//uint8_t g_interruptNum = 0; /* 每次关闭或重新开启定时器3时先清零该引脚 */
void stop_mpptWork(void)
{
// GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, SET);
g_duty_ratio = 0.7;
TIM_Cmd(TIM3, DISABLE);
// g_interruptNum = 0;
TIM_SetCompare4(TIM4, 0);
// TimeSliceOffset_Register(&m_startMpptControl, Task_startMpptControl
// , startMpptControl_reloadVal, startMpptControl_offset);
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, RESET);
}
void start_mpptWork(void)
{
// GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, RESET);
// g_interruptNum = 0;
TIM_Cmd(TIM3, ENABLE);
// TIM3->CNT = 0;
g_Mppt_Para.MPPT_Mode = CONSTANTCURRENT;
// TimeSliceOffset_Unregister(&m_startMpptControl);
// Delay_Ms(500);
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
}
/**
* @brief
* @param
* @retval
*/
STR_TimeSliceOffset m_runled;
void Task_RunLED(void)
{
// uart_sendstr(g_gw485_uart4_handle, "\n\n\n\n\n");
// uart_sendstr(g_gw485_uart4_handle, "is gw485\n");
// uart_sendstr(g_bat485_uart3_handle, "is bat485\n");get_PV1_VOLT_IN();
// printf(" \n");
// printf(" duty_ratio : %d/1000 \n", (int)(g_duty_ratio * 1000));
//
// printf(" vout : %d/100 \n", (int)(g_Mppt_Para.Battery_Voltage * 100));
// printf(" Iout : %d/100 \n", (int)(g_Mppt_Para.Charg_Current * 100));
// printf(" Idisout : %d/100 \n", (int)(g_Mppt_Para.Discharg_Current * 100));
// printf(" mosT : %d/10 \n", (int)(g_Mppt_Para.HighSideMos_Temperature * 10));
// printf(" mosState : %d \n", (int)(g_Mppt_Para.DischargMos_State));
//// printf(" mosState : %d \n", GPIO_ReadOutputDataBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN));
//// printf(" mosState : %d \n", GPIO_ReadInputDataBit(DSG_PROT_GPIO, DSG_PROT_PIN));
//
// printf(" 0.没有工作; 1.涓流模式; 2.恒流模式; 3.恒压模式; 4.浮充模式; 5.没有电池 : %d \n", g_Mppt_Para.MPPT_Mode);
//
// printf(" \n");
// uart_sendstr(g_bat485_uart3_handle, " \n");
uart_dev_write(g_bat485_uart3_handle, " \n", sizeof(" \n"));
char buffer[80];
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " duty_ratio : %d/1000 \n", (int)(g_duty_ratio * 1000));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " Input_Voltage : %d/100 \n", (int)(g_Mppt_Para.Input_Voltage * 100));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " vout : %d/100 \n", (int)(g_Mppt_Para.Output_Voltage * 100));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " vBattery : %d/100 \n", (int)(g_Mppt_Para.Battery_Voltage * 100));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " Iout : %d/100 \n", (int)(g_Mppt_Para.Charg_Current * 100));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " Idisout : %d/100 \n", (int)(g_Mppt_Para.Discharg_Current * 100));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " mosT : %d/10 \n", (int)(g_Mppt_Para.HighSideMos_Temperature * 10));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " impedance : %d/1000 \n", (int)(g_impedance * 1000));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " g_impedanceStart : %d \n", g_impedanceStart);
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " mosState : %d \n", (int)(g_Mppt_Para.DischargMos_State));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " batteryState : %d \n", g_batteryState);
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " outputAgainFlag : %d \n", outputAgainFlag);
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " excessiveLoadFlag : %d \n", excessiveLoadFlag);
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " 0.没有工作; 1.涓流模式; 2.恒流模式; 3.恒压模式; 4.浮充模式; 5.没有电池 : %d \n", g_Mppt_Para.MPPT_Mode);
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
uart_dev_write(g_bat485_uart3_handle, " \n", sizeof(" \n"));
// printf("vout : %d/100 \n", (int)(get_capturedata(get_PV_VOLT_OUT) * 100));
// get_CHG_CURR();
static uint8_t flag = RESET;
flag = !flag;
GPIO_WriteBit(RUN_LED_GPIO, RUN_LED_PIN, flag);
static uint8_t num = 0;
if (10 == ++num) {
GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
}
return;
}
/**
* @brief mppt控制
* @param
* @retval
*/
STR_TimeSliceOffset m_startMpptControl;
void Task_startMpptControl(void)
{
static uint16_t checkSolarOpenCircuitVTimeFlag;
static uint8_t only_once = 1;
if (only_once) {
only_once = 0;
checkSolarOpenCircuitVTimeFlag = g_slConfigInfo.checkSolarOpenCircuitVTime - 3;
}
if (g_slConfigInfo.checkSolarOpenCircuitVTime == ++checkSolarOpenCircuitVTimeFlag) {
checkSolarOpenCircuitVTimeFlag = 0;
g_Mppt_Para.Solar_Open_Circuit_Voltage = get_PV1_VOLT_IN();
// printf("volt in : %d/100 \n", (int)(g_Mppt_Para.Solar_Open_Circuit_Voltage * 100));
// char buff[50];
// memset(buff, 0, sizeof(buff));
// sprintf(buff, "volt in : %d/100 \n", (int)(g_Mppt_Para.Solar_Open_Circuit_Voltage * 100));
// uart_dev_write(g_bat485_uart3_handle, buff, sizeof(buff));
if (g_Mppt_Para.Solar_Open_Circuit_Voltage
> ((float_t)g_slConfigInfo.startSolarOpenCircuitV / 100)) {
TimeSliceOffset_Unregister(&m_startMpptControl);
m_startMpptControl.runFlag = 0;
// printf("1\n");
// start_mpptWork();
if (g_Mppt_Para.Output_Voltage > 11) {
g_batteryState = 1;
} else {
g_batteryState = 0;
}
TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset);
}
}
return;
}
/**
* @brief
* @param
* @retval
*/
STR_TimeSliceOffset m_softStart;
void Task_softStart(void)
{
static uint16_t num = 0;
static float_t dutyRatio = 0;
num++;
// if (num == 1) {
// GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, RESET);
// }
if (num < 5) {
TIM_SetCompare4(TIM4, 100);
}
else if (num > 70 || dutyRatio > g_duty_ratio) {
TimeSliceOffset_Unregister(&m_softStart);
m_softStart.runFlag = 0;
dutyRatio = 0;
num = 0;
Set_duty_ratio(&g_duty_ratio);
if (g_batteryState == 1) {
start_mpptWork();
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
// TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
// , impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
return;
} else {
dutyRatio = 0;
num = 0;
Set_duty_ratio(&g_duty_ratio);
// TimeSliceOffset_Unregister(&m_softStart);
// m_softStart.runFlag = 0;
//软起动后bms保护板开启电池充电
if (get_CHG_CURR() - get_DSG_CURR() > 0.1
|| get_DSG_CURR() - get_CHG_CURR() > 0.1) {
// printf("111\n");
// TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
// , impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
start_mpptWork();
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
return;
}
g_Mppt_Para.MPPT_Mode = FLOAT;
TIM_Cmd(TIM3, ENABLE);
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
return;
}
}
else {
dutyRatio += 0.01;
Set_duty_ratio(&dutyRatio);
}
}
/**
* @brief
* @param
* @retval
*/
STR_TimeSliceOffset m_usart;
uint8_t RegistrationRequestFlag = 0;
void Task_usart(void)
{
read_and_process_uart_data(g_gw485_uart4_handle);
// read_and_process_uart_data(g_bat485_uart3_handle);
// uart_dev_write(g_bat485_uart3_handle, "hello world \n", sizeof("hello world \n"));
return;
}
/**
* @brief
* @param
* @retval
*/
STR_TimeSliceOffset m_wdi;
void Task_wdi(void)
{
static uint32_t temp = 0;
if (wdi_RESET == temp++) {
temp = 0;
NVIC_SystemReset();
}
GPIO_WriteBit(WDI_INPUT_GPIO, WDI_INPUT_PIN, SET);
GPIO_WriteBit(WDI_INPUT_GPIO, WDI_INPUT_PIN, RESET);
return;
}
/**
* @brief ,mos管温度
* @param
* @retval
*/
STR_TimeSliceOffset m_refreshRegister;
uint8_t overTemperature = 0;
void Task_refreshRegister(void)
{
static uint16_t checkRegisterRefreshTimeFlag;
if (g_slConfigInfo.registerRefreshTime == ++checkRegisterRefreshTimeFlag) {
checkRegisterRefreshTimeFlag = 0;
// g_Mppt_Para.Battery_Voltage = get_capturedata(get_PV_VOLT_OUT);
// g_Mppt_Para.Charg_Current = get_capturedata(get_CHG_CURR);
// g_Mppt_Para.Discharg_Current = get_capturedata(get_DSG_CURR);
// g_Mppt_Para.HighSideMos_Temperature = get_capturedata(get_MOSFET_Temper);
// g_Mppt_Para.Battery_Voltage = get_PV_VOLT_OUT();
g_Mppt_Para.Output_Voltage = get_PV_VOLT_OUT();
g_Mppt_Para.Charg_Current = get_CHG_CURR();
g_Mppt_Para.Discharg_Current = get_DSG_CURR();
g_Mppt_Para.HighSideMos_Temperature = get_MOSFET_Temper();
g_Mppt_Para.DischargMos_State = GPIO_ReadOutputDataBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN)
&& GPIO_ReadInputDataBit(DSG_PROT_GPIO, DSG_PROT_PIN);
if (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < -0.1) {
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage
- (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current) * g_impedance;
}
float_t inBatteryCurr = g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current;
float_t outBatteryCurr = g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current;
if (g_batteryState == 0 && (inBatteryCurr > 0.1 || outBatteryCurr > 0.1) && g_Mppt_Para.Output_Voltage < 14.2) {
g_batteryState = 1;
}
/* 有电池,太阳能输出功率大,同时回路阻抗未测试或需要重新测试 */
if (g_batteryState == 1 && (g_Mppt_Para.Charg_Current > 3.0) && (g_impedanceStart == 1 || g_impedance == 0.0)) {
TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
, impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
}
// g_Mppt_Para.DischargMos_State = GPIO_ReadOutputDataBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN);
// g_Mppt_Para.Solar_Open_Circuit_Voltage = get_capturedata(get_PV1_VOLT_IN);
g_Mppt_Para.Input_Voltage = get_PV1_VOLT_IN();
if (g_Mppt_Para.HighSideMos_Temperature < g_slConfigInfo.HighSideMosTemperature_start + 3) {
if (overTemperature == 2) {
// start_mpptWork();
TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset);
}
overTemperature = 0;
return;
}
if (g_Mppt_Para.HighSideMos_Temperature > g_slConfigInfo.HighSideMosTemperature_end + 3
&& g_Mppt_Para.HighSideMos_Temperature < g_slConfigInfo.HighSideMosTemperature_stop) {
// g_Mppt_Para.MPPT_Mode = NoBattery;
// g_duty_ratio -= 0.1;
g_duty_ratio = 0.6;
Set_duty_ratio(&g_duty_ratio);
overTemperature = 1;
}
if (g_Mppt_Para.HighSideMos_Temperature > g_slConfigInfo.HighSideMosTemperature_stop + 3) {
overTemperature = 2;
stop_mpptWork();
}
}
}
/**
* @brief 广,3s
* @param
* @retval
*/
uint8_t recvbroadcast_flag = 0;
device_handle g_recvBroadcastDevice;
uint8_t g_recvBroadcastRegisterNumber;
STR_TimeSliceOffset m_recvbroadcast;
void Task_recvbroadcast(void)
{
static uint8_t run_number = 0;
/* 超过三次,不再发送 */
if (run_number++ == 3 || run_number > 3) {
RegistrationRequestFlag = 0;
run_number = 0;
TimeSliceOffset_Unregister(&m_recvbroadcast);
m_recvbroadcast.runFlag = 0;
return;
}
// if (g_Mppt_Para.Registration_Status == REGISTER_SUCCESS) {
// TimeSliceOffset_Unregister(&m_recvbroadcast);
// return;
// }
SL_Mppt_RegistrationRequest_pack recvpack = {0};
/* 起始标志 */
recvpack.start_Flag[0] = g_slConfigInfo.start_Flag[0];
recvpack.start_Flag[1] = g_slConfigInfo.start_Flag[1];
/* ID */
recvpack.address[0] = 0xFF;
recvpack.address[1] = 0xFF;
recvpack.address[2] = 0xFF;
recvpack.address[3] = 0xFF;
recvpack.address[4] = 0xFF;
recvpack.address[5] = 0xFF;
recvpack.address[6] = 0xFF;
/* 功能码 */
recvpack.function_Code = SL_Function_Code_Registration_request;
/* 寄存器长度 */
recvpack.register_Length_H = g_recvBroadcastRegisterNumber >> 8;
recvpack.register_Length_L = g_recvBroadcastRegisterNumber;
/* 注册状态 */
recvpack.registration_Status_H = g_Mppt_Para.Registration_Status >> 8;
recvpack.registration_Status_L = g_Mppt_Para.Registration_Status;
/* 接入节点ID */
recvpack.access_Node_ID[0] = g_slConfigInfo.address[0];
recvpack.access_Node_ID[1] = g_slConfigInfo.address[1];
recvpack.access_Node_ID[2] = g_slConfigInfo.address[2];
recvpack.access_Node_ID[3] = g_slConfigInfo.address[3];
recvpack.access_Node_ID[4] = g_slConfigInfo.address[4];
recvpack.access_Node_ID[5] = g_slConfigInfo.address[5];
recvpack.access_Node_ID[6] = g_slConfigInfo.address[6];
/* 接入节点类型 */
recvpack.access_Node_Type_H = g_Mppt_Para.Access_Node_Type >> 8;
recvpack.access_Node_Type_L = g_Mppt_Para.Access_Node_Type;
/* 校验位 */
// uint8_t *rpack_buf = (uint8_t *)&recvpack;
uint16_t crc = CheckFunc((uint8_t *)&recvpack, SL_MPPT_REGISTRATIONREQUEST_PACK_SIZE - 3);
recvpack.check_Bit_H = crc >> 8;
recvpack.check_Bit_L = crc;
/* 结束标志 */
recvpack.end_Flag = g_slConfigInfo.end_Flag;
/* 校验位 */
for (uint8_t var = 0; var < 10; ++var) {
Delay_Ms(randomDelay());
if (!Check_485_bus_busy(g_recvBroadcastDevice)) {
if (recvbroadcast_flag == 1) {
recvbroadcast_flag = 0;
run_number = 0;
return;
}
uart_dev_write(g_recvBroadcastDevice, (uint8_t *)&recvpack, SL_MPPT_REGISTRATIONREQUEST_PACK_SIZE + 1);
if (g_recvBroadcastDevice == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
}
}
/**
* @brief
* @param
* @retval
*/
STR_TimeSliceOffset m_impedanceCalculation;
float_t g_impedance = 0; /* 回路阻抗的值 */
uint8_t g_batteryState = 0; /* 有无电池 */
uint8_t g_impedanceStart = 0; /* 是否开始测量回路阻抗 */
//config_info tempConfigInfo;
void Task_impedanceCalculation(void)
{
static uint8_t num = 0;
static float_t currOne = 0;
static float_t voltOne = 0;
static float_t currTwo = 0;
static float_t voltTwo = 0;
// static uint8_t only_one = 1;
// if (only_one) {
// g_impedance = g_slConfigInfo.loopImpedance;
// }
// if (g_Mppt_Para.MPPT_Mode == CONSTANTCURRENT
// || g_Mppt_Para.MPPT_Mode == CONSTANTVOLTAGE) {
// ++num;
// } else {
// num = 0;
// }
//
// if (num == 10) {
// num = 0;
// TIM_Cmd(TIM3, DISABLE);
//
// TIM_SetCompare4(TIM4, 300);
// Delay_Ms(500);
//
// TIM_SetCompare4(TIM4, 420);
// Delay_Ms(5);
//// currOne = get_capturedata(get_CHG_CURR) - get_capturedata(get_DSG_CURR);
//// voltOne = get_capturedata(get_PV_VOLT_OUT);
// currOne = get_CHG_CURR() - get_DSG_CURR();
// voltOne = get_PV_VOLT_OUT();
//
//// currTwo = get_capturedata(get_CHG_CURR) - get_capturedata(get_DSG_CURR);
//// voltTwo = get_capturedata(get_PV_VOLT_OUT);
// currTwo = get_CHG_CURR() - get_DSG_CURR();
// voltTwo = get_PV_VOLT_OUT();
//
// g_impedance = (voltOne - voltTwo) / (currOne - currTwo);
//
// printf("currOne = %d/1000, voltOne = %d/100 \n", (int)(currOne * 1000), (int)(voltOne * 100));
// printf("currTwo = %d/1000, voltTwo = %d/100 \n", (int)(currTwo * 1000), (int)(voltTwo * 100));
// printf("Res = %d/1000, E = %d/100 \n", (int)(g_impedance * 1000), (int)((voltTwo - currTwo * g_impedance) * 100));
//
//// TIM_Cmd(TIM3, ENABLE);
// }
num++;
// printf("g_batteryState : %d\n", g_batteryState);
if (num == 1) {
TIM_Cmd(TIM3, DISABLE);
// g_interruptNum = 0;
TIM_SetCompare4(TIM4, 300);
return;
}
if (num == 11) {
currOne = get_CHG_CURR() - get_DSG_CURR();
voltOne = get_PV_VOLT_OUT();
TIM_SetCompare4(TIM4, 420);
return;
}
if (num == 21) {
TimeSliceOffset_Unregister(&m_impedanceCalculation);
m_impedanceCalculation.runFlag = 0;
currTwo = get_CHG_CURR() - get_DSG_CURR();
voltTwo = get_PV_VOLT_OUT();
g_impedance = (voltOne - voltTwo) / (currOne - currTwo);
// printf("g_batteryState : %d\n", g_batteryState);
// printf("currOne = %d/1000, voltOne = %d/100 \n", (int)(currOne * 1000), (int)(voltOne * 100));
// printf("currTwo = %d/1000, voltTwo = %d/100 \n", (int)(currTwo * 1000), (int)(voltTwo * 100));
// printf("Res = %d/1000, E = %d/100 \n", (int)(g_impedance * 1000), (int)((voltTwo - currTwo * g_impedance) * 100));
/* 判断回路阻抗是否合理 */
if (g_impedance > 1.0 || g_impedance < 0.05) {
g_impedance = 0;
num = 0;
start_mpptWork();
return;
}
/* 将回路阻抗的值放入flash中 */
config_info tempConfigInfo;
if (read_config_info1(&tempConfigInfo)) {
tempConfigInfo.loopImpedance = (uint16_t)(g_impedance * 1000);
save_config_info(&tempConfigInfo);
} else {
tempConfigInfo = g_slConfigInfo;
tempConfigInfo.loopImpedance = (uint16_t)(g_impedance * 1000);
save_config_info(&tempConfigInfo);
}
// uart_dev_write(g_bat485_uart3_handle, "\n\n\n\n\n", sizeof("\n\n\n\n\n"));
// char buffer[80];
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " tempConfigInfo.loopImpedance : %d/1000 \n", tempConfigInfo.loopImpedance);
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
// memset(buffer, 0, sizeof(buffer));
// config_info tempConfigInfo2 = {0};
// read_config_info1(&tempConfigInfo2);
// sprintf(buffer, " tempConfigInfo2.loopImpedance : %d/1000 \n", tempConfigInfo2.loopImpedance);
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
// uart_dev_write(g_bat485_uart3_handle, "\n\n\n\n\n", sizeof("\n\n\n\n\n"));
g_impedanceStart = 0;
num = 0;
start_mpptWork();
// TIM_Cmd(TIM3, ENABLE);
return;
}
return;
}
/**
* @brief
* @param
* @retval
*/
STR_TimeSliceOffset m_outputAgain;
uint8_t outputAgainFlag = 0;
void Task_outputAgain(void)
{
static uint8_t num = 0;
num++;
// if (outputAgainFlag == 1) {
//// outputAgainFlag = 0;
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, RESET);
// TimeSliceOffset_Unregister(&m_outputAgain);
// m_outputAgain.runFlag = 0;
// num = 0;
// }
// printf(" in POW_OUT_CON\n");
if (num == g_slConfigInfo.outputAgainFlagTime) {
num = 0;
outputAgainFlag = 0;
TimeSliceOffset_Unregister(&m_outputAgain);
m_outputAgain.runFlag = 0;
// printf(" in POW_OUT_CON control %d \n", GPIO_ReadInputDataBit(DSG_PROT_GPIO, DSG_PROT_PIN));
if (!(GPIO_ReadInputDataBit(DSG_PROT_GPIO, DSG_PROT_PIN))) {
// uart_dev_write(g_bat485_uart3_handle, " \n\n\n\n\n", sizeof(" \n\n\n\n\n"));
// uart_dev_write(g_bat485_uart3_handle, " in task pow_out_con reset", sizeof(" in task pow_out_con reset"));
// uart_dev_write(g_bat485_uart3_handle, " \n\n\n\n\n", sizeof(" \n\n\n\n\n"));
// printf(" in POW_OUT_CON RESET \n");
GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, RESET);
}
}
return;
}
/**
* @brief
* @param
* @retval
*/
STR_TimeSliceOffset m_excessiveLoad;
uint8_t excessiveLoadFlag = 0;
void Task_excessiveLoad(void)
{
static uint8_t num = 0;
static uint16_t numLong = 0;
// if (outputAgainFlag == 1) {
//// outputAgainFlag = 0;
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, RESET);
// TimeSliceOffset_Unregister(&m_outputAgain);
// m_outputAgain.runFlag = 0;
// num = 0;
// }
// printf(" in POW_OUT_CON\n");
if (outputAgainFlag == 1) {
num = 0;
numLong = 0;
excessiveLoadFlag = 0;
TimeSliceOffset_Unregister(&m_excessiveLoad);
m_excessiveLoad.runFlag = 0;
}
if (excessiveLoadFlag == 1) {
num++;
}
if (num == g_slConfigInfo.excessiveLoadFlagTime) {
num = 0;
excessiveLoadFlag = 0;
TimeSliceOffset_Unregister(&m_excessiveLoad);
m_excessiveLoad.runFlag = 0;
return;
}
if (excessiveLoadFlag >= 2) {
GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, RESET);
num = 0;
}
if (!(GPIO_ReadOutputDataBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN))) {
numLong++;
}
if (numLong == g_slConfigInfo.eLAgainTime) {
numLong = 0;
GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
excessiveLoadFlag = 0;
TimeSliceOffset_Unregister(&m_excessiveLoad);
m_excessiveLoad.runFlag = 0;
}
return;
}
/**
* @brief
* @param
* @retval
*/
STR_TimeSliceOffset m_sensorEnableBroadcast;
/* 是否接收广播帧标志位 */
uint8_t run_Broadcast = 1;
void Task_sensorEnableBroadcast(void)
{
static uint32_t enabBroadcastTimeFlag = 0;
enabBroadcastTimeFlag++;
run_Broadcast = 0;
if (enabBroadcastTimeFlag == g_slConfigInfo.sensorEnableBroadcastTime) {
enabBroadcastTimeFlag = 0;
run_Broadcast = 1;
TimeSliceOffset_Unregister(&m_sensorEnableBroadcast);
m_sensorEnableBroadcast.runFlag = 0;
}
return;
}
/**
* @brief
* @param
* @retval
*/
void g_Mppt_Para_Init(void)
{
g_impedance = (float_t)g_slConfigInfo.loopImpedance / 1000;
g_Mppt_Para.Registration_Status = UNREGISTER;
g_Mppt_Para.address[0] = g_slConfigInfo.address[0];
g_Mppt_Para.address[1] = g_slConfigInfo.address[1];
g_Mppt_Para.address[2] = g_slConfigInfo.address[2];
g_Mppt_Para.address[3] = g_slConfigInfo.address[3];
g_Mppt_Para.address[4] = g_slConfigInfo.address[4];
g_Mppt_Para.address[5] = g_slConfigInfo.address[5];
g_Mppt_Para.address[6] = g_slConfigInfo.address[6];
g_Mppt_Para.Access_Node_Type = defaultValue.access_Node_Type;
g_Mppt_Para.Communication_Methods = defaultValue.communication_Methods;
// g_Mppt_Para.Output_Voltage = get_capturedata(get_PV_VOLT_OUT);
// g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
// g_Mppt_Para.Charg_Current = get_capturedata(get_CHG_CURR);
// g_Mppt_Para.Discharg_Current = get_capturedata(get_DSG_CURR);
// g_Mppt_Para.Solar_Open_Circuit_Voltage = get_capturedata(get_PV1_VOLT_IN);
// g_Mppt_Para.HighSideMos_Temperature = get_capturedata(get_MOSFET_Temper); g_Mppt_Para.Output_Voltage = get_capturedata(get_PV_VOLT_OUT);
g_Mppt_Para.Output_Voltage = get_PV_VOLT_OUT();
// g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
g_Mppt_Para.Charg_Current = get_CHG_CURR();
g_Mppt_Para.Discharg_Current = get_DSG_CURR();
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage
- (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current) * g_impedance;
g_Mppt_Para.Solar_Open_Circuit_Voltage = get_PV1_VOLT_IN();
g_Mppt_Para.HighSideMos_Temperature = get_MOSFET_Temper();
if (g_Mppt_Para.Battery_Voltage < 15 || g_Mppt_Para.Battery_Voltage > 11) {
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
g_impedanceStart = 1;
}
g_Mppt_Para.DischargMos_State = GPIO_ReadOutputDataBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN)
&& GPIO_ReadInputDataBit(DSG_PROT_GPIO, DSG_PROT_PIN);
g_Mppt_Para.MPPT_Mode = NoWork;
// printf("start_flag : %s \n", g_slConfigInfo.start_Flag);
// for (int var = 0; var < 7; ++var) {
// printf("address[%d] : %x\n", var, g_slConfigInfo.address[var]);
// }
// printf("end_flag : %x\n", g_slConfigInfo.end_Flag);
// printf("access_Node_Type : %x\n", defaultValue.access_Node_Type);
// printf("communication_Methods : %x\n", defaultValue.communication_Methods);
}
/**
* @brief
* @param
* @retval
*/
void task_Init(void)
{
read_config_info();
g_Mppt_Para_Init();
TimeSliceOffset_Register(&m_runled, Task_RunLED, runled_reloadVal, runled_offset);
TimeSliceOffset_Register(&m_usart, Task_usart, usart_reloadVal, usart_offset);
TimeSliceOffset_Register(&m_wdi, Task_wdi, wdi_reloadVal, wdi_offset);
// TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
// , impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
TimeSliceOffset_Register(&m_refreshRegister, Task_refreshRegister
, refreshRegister_reloadVal, refreshRegister_reloadVal);
TimeSliceOffset_Register(&m_startMpptControl, Task_startMpptControl
, startMpptControl_reloadVal, startMpptControl_offset);
TimeSliceOffset_Start(); /* 启动时间片轮询 */
}
/**
* @brief
* @param
* @retval
*/
void hardware_Init(void)
{
TIM2_Init(1);
uart_dev_init();
PWM_TIM_Configuration();
// TIM_SetCompare4(TIM4, 0);
ADC_all_Init();
RUN_LED_Init();
WDI_INPUT_Init();
SPI_Flash_Init();
POW_OUT_CON_Init();
DSG_PROT_Init();
WORK_VOLT_INT_Init();
// EnPowerSupply_Init();
// Set_duty_ratio(&g_duty_ratio);
// uart_dev_write(g_bat485_uart3_handle, " hello world \n", sizeof(" hello world \n"));
TIM3_Init(10);
// TIM_Cmd(TIM3, ENABLE); //TIM3使能
}

View File

@ -7,6 +7,7 @@
#include "uart_dev.h" #include "uart_dev.h"
#include "inflash.h" #include "inflash.h"
#include "parameter.h"
/* ʹÄÜ485·¢ËÍ */ /* ʹÄÜ485·¢ËÍ */
#define rs485_send_enable 1 #define rs485_send_enable 1
@ -80,12 +81,12 @@ device_handle uart_dev_init(void)
// } // }
// } // }
InitRingQueue(&uart_devices[0].uart_ring_queue, bat485_in_buff, sizeof(bat485_in_buff)); InitRingQueue(&uart_devices[0].uart_ring_queue, bat485_in_buff, sizeof(bat485_in_buff));
uart_init(BAT485_UART_INDEX, g_slConfigInfo.baud_485); uart_init(BAT485_UART_INDEX, g_otherParameter.bat485_Baud);
uart_devices[0].init = 1; uart_devices[0].init = 1;
g_bat485_uart3_handle = (device_handle)(&uart_devices[0]); g_bat485_uart3_handle = (device_handle)(&uart_devices[0]);
InitRingQueue(&uart_devices[1].uart_ring_queue, gw485_in_buff, sizeof(gw485_in_buff)); InitRingQueue(&uart_devices[1].uart_ring_queue, gw485_in_buff, sizeof(gw485_in_buff));
uart_init(GW485_UART_INDEX, g_slConfigInfo.baud_485); uart_init(GW485_UART_INDEX, g_otherParameter.gw485_Baud);
uart_devices[1].init = 1; uart_devices[1].init = 1;
g_gw485_uart4_handle = (device_handle)(&uart_devices[1]); g_gw485_uart4_handle = (device_handle)(&uart_devices[1]);

View File

@ -103,17 +103,11 @@ void EXTI2_IRQHandler(void)
// GPIO_WriteBit(DSG_PROT_GPIO, DSG_PROT_PIN, RESET); // GPIO_WriteBit(DSG_PROT_GPIO, DSG_PROT_PIN, RESET);
EXTI_ClearITPendingBit(EXTI_Line2); //清除中断标志位 EXTI_ClearITPendingBit(EXTI_Line2); //清除中断标志位
// printf("Run at EXTI 111\r\n"); // printf("Run at EXTI 111\r\n");
if (outputAgainFlag == 0) { // if (outputAgainFlag == 0) {
outputAgainFlag = 1; // outputAgainFlag = 1;
TimeSliceOffset_Register(&m_outputAgain, Task_outputAgain // TimeSliceOffset_Register(&m_outputAgain, Task_outputAgain
, outputAgain_reloadVal, outputAgain_offset); // , outputAgain_reloadVal, outputAgain_offset);
// m_outputAgain.runFlag = 1; // m_outputAgain.runFlag = 1;
return;
}
// if (outputAgainFlag == 1) {
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, RESET);
// EXTI_ClearITPendingBit(EXTI_Line2); //清除中断标志位
// return; // return;
// } // }
@ -163,19 +157,13 @@ void WORK_VOLT_INT_Init(void)
void EXTI15_10_IRQHandler(void) void EXTI15_10_IRQHandler(void)
{ {
if(EXTI_GetITStatus(EXTI_Line12)==SET) { //EXTI_GetITStatus用来获取中断标志位状态如果EXTI线产生中断则返回SET否则返回RESET if(EXTI_GetITStatus(EXTI_Line12)==SET) { //EXTI_GetITStatus用来获取中断标志位状态如果EXTI线产生中断则返回SET否则返回RESET
// printf(" vout low 11V \n"); // EXTI_ClearITPendingBit(EXTI_Line12); //清除中断标志位
EXTI_ClearITPendingBit(EXTI_Line12); //清除中断标志位 // excessiveLoadFlag++;
excessiveLoadFlag++; // TimeSliceOffset_Register(&m_excessiveLoad, Task_excessiveLoad
TimeSliceOffset_Register(&m_excessiveLoad, Task_excessiveLoad // , excessiveLoad_reloadVal, excessiveLoad_offset);
, excessiveLoad_reloadVal, excessiveLoad_offset);
// uart_dev_write(g_bat485_uart3_handle, "\n\n\n\n\n in vout low 8V (Set)\n\n\n\n\n", sizeof("\n\n\n\n\n in vout low 8V (Set)\n\n\n\n\n")); }
}
// uart_dev_write(g_bat485_uart3_handle, "\n\n\n\n\n in vout low 8V\n\n\n\n\n", sizeof("\n\n\n\n\n in vout low 8V\n\n\n\n\n"));
// if(EXTI_GetITStatus(EXTI_Line12)==SET) { //EXTI_GetITStatus用来获取中断标志位状态如果EXTI线产生中断则返回SET否则返回RESET
//// printf(" vout low 11V \n");
// uart_dev_write(g_bat485_uart3_handle, "\n\n\n\n\n in vout low 8V\n\n\n\n\n", sizeof("\n\n\n\n\n in vout low 8V\n\n\n\n\n"));
// }
} }

View File

@ -59,7 +59,7 @@ void TIM3_IRQHandler(void)
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) { //检查TIM3中断是否发生。 if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) { //检查TIM3中断是否发生。
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); //清除TIM3的中断挂起位。 TIM_ClearITPendingBit(TIM3, TIM_IT_Update); //清除TIM3的中断挂起位。
// uart_dev_write(g_bat485_uart3_handle, "\n\n\n\n\nin tim3 irt\n\n\n\n\n", sizeof("\n\n\n\n\nin tim3 irt\n\n\n\n\n")); // uart_dev_write(g_bat485_uart3_handle, "\n\n\n\n\nin tim3 irt\n\n\n\n\n", sizeof("\n\n\n\n\nin tim3 irt\n\n\n\n\n"));
test(); // test();
} }
} }

View File

@ -39,6 +39,6 @@ int main(void)
printf("SystemClk:%d\r\n", SystemCoreClock); printf("SystemClk:%d\r\n", SystemCoreClock);
printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID()); printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID());
hardware_Init(); // hardware_Init();
task_Init(); // task_Init();
} }

113
obj/App/src/hy_protocol.d Normal file
View File

@ -0,0 +1,113 @@
App/src/hy_protocol.o: ../App/src/hy_protocol.c \
D:\psx\MPPT\git\App\inc/hy_protocol.h D:\psx\MPPT\git\Debug/debug.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103.h \
D:\psx\MPPT\git\Core/core_riscv.h D:\psx\MPPT\git\User/system_ch32l103.h \
D:\psx\MPPT\git\User/ch32l103_conf.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_adc.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_bkp.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_can.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_crc.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_dbgmcu.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_dma.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_exti.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_flash.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_gpio.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_i2c.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_iwdg.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_pwr.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_rcc.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_rtc.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_spi.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_tim.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_usart.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_wwdg.h \
D:\psx\MPPT\git\User/ch32l103_it.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_misc.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_lptim.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_opa.h \
D:\psx\MPPT\git\App\inc/uart_dev.h \
D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h \
D:\psx\MPPT\git\Hardware\inc/rs485.h D:\psx\MPPT\git\App\inc/inflash.h \
D:\psx\MPPT\git\App\inc/pdebug.h D:\psx\MPPT\git\App\inc/mppt_control.h \
D:\psx\MPPT\git\App\inc/task.h \
D:\psx\MPPT\git\Drivers\TimeSliceOffset/timeSliceOffset.h \
D:\psx\MPPT\git\App\inc/uart_dev.h D:\psx\MPPT\git\Hardware\inc/tim.h
D:\psx\MPPT\git\App\inc/hy_protocol.h:
D:\psx\MPPT\git\Debug/debug.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103.h:
D:\psx\MPPT\git\Core/core_riscv.h:
D:\psx\MPPT\git\User/system_ch32l103.h:
D:\psx\MPPT\git\User/ch32l103_conf.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_adc.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_bkp.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_can.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_crc.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_dbgmcu.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_dma.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_exti.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_flash.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_gpio.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_i2c.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_iwdg.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_pwr.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_rcc.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_rtc.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_spi.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_tim.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_usart.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_wwdg.h:
D:\psx\MPPT\git\User/ch32l103_it.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_misc.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_lptim.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_opa.h:
D:\psx\MPPT\git\App\inc/uart_dev.h:
D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h:
D:\psx\MPPT\git\Hardware\inc/rs485.h:
D:\psx\MPPT\git\App\inc/inflash.h:
D:\psx\MPPT\git\App\inc/pdebug.h:
D:\psx\MPPT\git\App\inc/mppt_control.h:
D:\psx\MPPT\git\App\inc/task.h:
D:\psx\MPPT\git\Drivers\TimeSliceOffset/timeSliceOffset.h:
D:\psx\MPPT\git\App\inc/uart_dev.h:
D:\psx\MPPT\git\Hardware\inc/tim.h:

BIN
obj/App/src/hy_protocol.o Normal file

Binary file not shown.

Binary file not shown.

View File

@ -33,7 +33,7 @@ App/src/mppt_control.o: ../App/src/mppt_control.c \
D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h \ D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h \
D:\psx\MPPT\git\Hardware\inc/rs485.h D:\psx\MPPT\git\App\inc/task.h \ D:\psx\MPPT\git\Hardware\inc/rs485.h D:\psx\MPPT\git\App\inc/task.h \
D:\psx\MPPT\git\Drivers\TimeSliceOffset/timeSliceOffset.h \ D:\psx\MPPT\git\Drivers\TimeSliceOffset/timeSliceOffset.h \
D:\psx\MPPT\git\App\inc/uart_dev.h D:\psx\MPPT\git\App\inc/uart_dev.h D:\psx\MPPT\git\App\inc/parameter.h
D:\psx\MPPT\git\App\inc/mppt_control.h: D:\psx\MPPT\git\App\inc/mppt_control.h:
@ -116,3 +116,5 @@ D:\psx\MPPT\git\App\inc/task.h:
D:\psx\MPPT\git\Drivers\TimeSliceOffset/timeSliceOffset.h: D:\psx\MPPT\git\Drivers\TimeSliceOffset/timeSliceOffset.h:
D:\psx\MPPT\git\App\inc/uart_dev.h: D:\psx\MPPT\git\App\inc/uart_dev.h:
D:\psx\MPPT\git\App\inc/parameter.h:

Binary file not shown.

95
obj/App/src/parameter.d Normal file
View File

@ -0,0 +1,95 @@
App/src/parameter.o: ../App/src/parameter.c \
D:\psx\MPPT\git\App\inc/parameter.h D:\psx\MPPT\git\Debug/debug.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103.h \
D:\psx\MPPT\git\Core/core_riscv.h D:\psx\MPPT\git\User/system_ch32l103.h \
D:\psx\MPPT\git\User/ch32l103_conf.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_adc.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_bkp.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_can.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_crc.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_dbgmcu.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_dma.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_exti.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_flash.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_gpio.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_i2c.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_iwdg.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_pwr.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_rcc.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_rtc.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_spi.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_tim.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_usart.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_wwdg.h \
D:\psx\MPPT\git\User/ch32l103_it.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_misc.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_lptim.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_opa.h \
D:\psx\MPPT\git\App\inc/uart_dev.h \
D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h \
D:\psx\MPPT\git\Hardware\inc/rs485.h
D:\psx\MPPT\git\App\inc/parameter.h:
D:\psx\MPPT\git\Debug/debug.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103.h:
D:\psx\MPPT\git\Core/core_riscv.h:
D:\psx\MPPT\git\User/system_ch32l103.h:
D:\psx\MPPT\git\User/ch32l103_conf.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_adc.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_bkp.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_can.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_crc.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_dbgmcu.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_dma.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_exti.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_flash.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_gpio.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_i2c.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_iwdg.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_pwr.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_rcc.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_rtc.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_spi.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_tim.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_usart.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_wwdg.h:
D:\psx\MPPT\git\User/ch32l103_it.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_misc.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_lptim.h:
D:\psx\MPPT\git\Peripheral\inc/ch32l103_opa.h:
D:\psx\MPPT\git\App\inc/uart_dev.h:
D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h:
D:\psx\MPPT\git\Hardware\inc/rs485.h:

BIN
obj/App/src/parameter.o Normal file

Binary file not shown.

View File

@ -32,7 +32,8 @@ App/src/sl_protocol.o: ../App/src/sl_protocol.c \
D:\psx\MPPT\git\App\inc/pdebug.h D:\psx\MPPT\git\App\inc/mppt_control.h \ D:\psx\MPPT\git\App\inc/pdebug.h D:\psx\MPPT\git\App\inc/mppt_control.h \
D:\psx\MPPT\git\App\inc/task.h \ D:\psx\MPPT\git\App\inc/task.h \
D:\psx\MPPT\git\Drivers\TimeSliceOffset/timeSliceOffset.h \ D:\psx\MPPT\git\Drivers\TimeSliceOffset/timeSliceOffset.h \
D:\psx\MPPT\git\App\inc/uart_dev.h D:\psx\MPPT\git\Hardware\inc/tim.h D:\psx\MPPT\git\App\inc/uart_dev.h D:\psx\MPPT\git\Hardware\inc/tim.h \
D:\psx\MPPT\git\App\inc/parameter.h
D:\psx\MPPT\git\App\inc/sl_protocol.h: D:\psx\MPPT\git\App\inc/sl_protocol.h:
@ -111,3 +112,5 @@ D:\psx\MPPT\git\Drivers\TimeSliceOffset/timeSliceOffset.h:
D:\psx\MPPT\git\App\inc/uart_dev.h: D:\psx\MPPT\git\App\inc/uart_dev.h:
D:\psx\MPPT\git\Hardware\inc/tim.h: D:\psx\MPPT\git\Hardware\inc/tim.h:
D:\psx\MPPT\git\App\inc/parameter.h:

Binary file not shown.

View File

@ -6,24 +6,30 @@
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../App/src/collect_Conversion.c \ ../App/src/collect_Conversion.c \
../App/src/hy_protocol.c \
../App/src/inflash.c \ ../App/src/inflash.c \
../App/src/mppt_control.c \ ../App/src/mppt_control.c \
../App/src/parameter.c \
../App/src/sl_protocol.c \ ../App/src/sl_protocol.c \
../App/src/task.c \ ../App/src/task.c \
../App/src/uart_dev.c ../App/src/uart_dev.c
OBJS += \ OBJS += \
./App/src/collect_Conversion.o \ ./App/src/collect_Conversion.o \
./App/src/hy_protocol.o \
./App/src/inflash.o \ ./App/src/inflash.o \
./App/src/mppt_control.o \ ./App/src/mppt_control.o \
./App/src/parameter.o \
./App/src/sl_protocol.o \ ./App/src/sl_protocol.o \
./App/src/task.o \ ./App/src/task.o \
./App/src/uart_dev.o ./App/src/uart_dev.o
C_DEPS += \ C_DEPS += \
./App/src/collect_Conversion.d \ ./App/src/collect_Conversion.d \
./App/src/hy_protocol.d \
./App/src/inflash.d \ ./App/src/inflash.d \
./App/src/mppt_control.d \ ./App/src/mppt_control.d \
./App/src/parameter.d \
./App/src/sl_protocol.d \ ./App/src/sl_protocol.d \
./App/src/task.d \ ./App/src/task.d \
./App/src/uart_dev.d ./App/src/uart_dev.d

View File

@ -34,7 +34,8 @@ App/src/task.o: ../App/src/task.c D:\psx\MPPT\git\App\inc/task.h \
D:\psx\MPPT\git\Hardware\inc/flash.h \ D:\psx\MPPT\git\Hardware\inc/flash.h \
D:\psx\MPPT\git\App\inc/sl_protocol.h \ D:\psx\MPPT\git\App\inc/sl_protocol.h \
D:\psx\MPPT\git\App\inc/mppt_control.h D:\psx\MPPT\git\App\inc/inflash.h \ D:\psx\MPPT\git\App\inc/mppt_control.h D:\psx\MPPT\git\App\inc/inflash.h \
D:\psx\MPPT\git\App\inc/collect_Conversion.h D:\psx\MPPT\git\App\inc/collect_Conversion.h \
D:\psx\MPPT\git\App\inc/parameter.h
D:\psx\MPPT\git\App\inc/task.h: D:\psx\MPPT\git\App\inc/task.h:
@ -121,3 +122,5 @@ D:\psx\MPPT\git\App\inc/mppt_control.h:
D:\psx\MPPT\git\App\inc/inflash.h: D:\psx\MPPT\git\App\inc/inflash.h:
D:\psx\MPPT\git\App\inc/collect_Conversion.h: D:\psx\MPPT\git\App\inc/collect_Conversion.h:
D:\psx\MPPT\git\App\inc/parameter.h:

Binary file not shown.

View File

@ -27,7 +27,8 @@ App/src/uart_dev.o: ../App/src/uart_dev.c \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_lptim.h \ D:\psx\MPPT\git\Peripheral\inc/ch32l103_lptim.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_opa.h \ D:\psx\MPPT\git\Peripheral\inc/ch32l103_opa.h \
D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h \ D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h \
D:\psx\MPPT\git\Hardware\inc/rs485.h D:\psx\MPPT\git\App\inc/inflash.h D:\psx\MPPT\git\Hardware\inc/rs485.h D:\psx\MPPT\git\App\inc/inflash.h \
D:\psx\MPPT\git\App\inc/parameter.h D:\psx\MPPT\git\App\inc/uart_dev.h
D:\psx\MPPT\git\App\inc/uart_dev.h: D:\psx\MPPT\git\App\inc/uart_dev.h:
@ -92,3 +93,7 @@ D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h:
D:\psx\MPPT\git\Hardware\inc/rs485.h: D:\psx\MPPT\git\Hardware\inc/rs485.h:
D:\psx\MPPT\git\App\inc/inflash.h: D:\psx\MPPT\git\App\inc/inflash.h:
D:\psx\MPPT\git\App\inc/parameter.h:
D:\psx\MPPT\git\App\inc/uart_dev.h:

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff