mppt/App/inc/sl_protocol.h

250 lines
9.7 KiB
C
Raw Normal View History

2024-07-11 06:58:55 +00:00
/*
* sl_protocol.h
*
* Created on: 2024<EFBFBD><EFBFBD>6<EFBFBD><EFBFBD>20<EFBFBD><EFBFBD>
* Author: psx
*/
#ifndef APP_INC_SL_PROTOCOL_H_
#define APP_INC_SL_PROTOCOL_H_
#include "debug.h"
#include "uart_dev.h"
2024-08-29 02:50:22 +00:00
#include "math.h"
2024-07-11 06:58:55 +00:00
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
typedef enum
{
SL_Function_Code_Read_Register = 0x30, /* <20><><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
SL_Function_Code_Write_Register = 0x10, /* д<>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
SL_Function_Code_Broadcast_Scan = 0xA0, /* <20>㲥ɨ<E3B2A5><C9A8> */
SL_Function_Code_Registration_request = 0xA1, /* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
SL_Function_Code_Update_Profile = 0xD0, /* <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD> */
SL_Function_Code_Remote_Upgrade = 0xD1, /* Զ<><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
2024-07-11 06:58:55 +00:00
}SL_MsgFunctionCode;
/* <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ */
typedef enum
{
SL_Register_Registration_Status = 0x0000, /* ע<><D7A2>״̬ */
SL_Register_address = 0x0001, /* <20><>ַ */
SL_Register_Access_Node_Type = 0x0002, /* <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD> */
SL_Register_Communication_Methods = 0x0003, /* ͨ<>ŷ<EFBFBD>ʽ */
2024-09-18 01:47:44 +00:00
SL_Register_Output_Voltage = 0x0100, /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ */
SL_Register_Battery_Voltage = 0x0101, /* <20><><EFBFBD>ص<EFBFBD>ѹ */
SL_Register_Charg_Current = 0x0102, /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD>أ<EFBFBD> */
SL_Register_Discharg_Current = 0x0103, /* <20>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD> */
SL_Register_Solar_Open_Circuit_Voltage = 0x0104, /* ̫<><CCAB><EFBFBD>ܿ<EFBFBD>·<EFBFBD><C2B7>ѹ */
SL_Register_HighSideMos_Temperature = 0x0105, /* <20>߶<EFBFBD>mos<6F><73><EFBFBD><EFBFBD> */
SL_Register_DischargMos_State = 0x0106, /* <20>ŵ<EFBFBD>mos<6F><73>״̬ */
SL_Register_MPPT_Mode = 0x0107, /* <20><><EFBFBD><EFBFBD>ģʽ */
2024-07-11 06:58:55 +00:00
}SL_Mppt_MsgRegister;
/* ע<><D7A2>״̬ */
typedef enum
{
UNREGISTER = 0, /* δע<CEB4><D7A2> */
REGISTER_FAIL = 1, /* ע<><D7A2>ʧ<EFBFBD><CAA7> */
REGISTER_SUCCESS = 2, /* ע<><D7A2><EFBFBD>ɹ<EFBFBD> */
}SL_REGISTERSTATUS;
2024-08-29 02:50:22 +00:00
/* <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD> */
typedef enum
{
POWERBOX = 1, /* <20><>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD> */
MICROMETEOROLOGY = 2, /* ΢<><CEA2><EFBFBD><EFBFBD> */
}SL_ACCESSNODETYPE;
/* ͨ<>ŷ<EFBFBD>ʽ */
typedef enum
{
RS485 = 1,
RJ45 = 2,
Lora = 3,
}SL_COMMUNICATIONMETHODS;
/* <20>ŵ<EFBFBD>mos<6F><73>״̬ */
typedef enum
{
close = 0,
open = 1,
}SL_DischargMos_State;
/* mppt<70><74><EFBFBD><EFBFBD>ģʽ */
typedef enum
{
NoWork = 0, /* û<>й<EFBFBD><D0B9><EFBFBD> */
TRICKLE = 1, /* <20><><EFBFBD><EFBFBD>ģʽ */
CONSTANTCURRENT = 2, /* <20><><EFBFBD><EFBFBD>ģʽ */
CONSTANTVOLTAGE = 3, /* <20><>ѹģʽ */
FLOAT = 4, /* <20><><EFBFBD><EFBFBD>ģʽ */
NoBattery = 5, /* û<>е<EFBFBD><D0B5><EFBFBD> */
}SL_MPPT_MODE;
2024-07-11 06:58:55 +00:00
#define chang_8_to_16(L,H) (L | (H<<8))
/* ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD>ʽΪ1<CEAA>ֽ<EFBFBD> */
#pragma pack(push,1)
/* <20><>ʱ<EFBFBD><CAB1><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>֡<EFBFBD><D6A1>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-><3E><><EFBFBD><EFBFBD><EFBFBD>ڵ㣩 */
typedef struct _SL_Mppt_Rorecv_pack{
uint8_t start_Flag[2]; /* <20><>ʼ<EFBFBD><CABC>־ */
uint8_t address[7]; /* <20><>ַ */
uint8_t function_Code; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
uint8_t read_Register_Start_Address_H; /* <20><>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ<EFBFBD><D6B7>8λ */
uint8_t read_Register_Start_Address_L; /* <20><>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ<EFBFBD>Ͱ<EFBFBD>λ */
uint8_t read_Register_Number_H; /* <20><>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߰<EFBFBD>λ */
uint8_t read_Register_Number_L; /* <20><>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD>λ */
uint8_t check_Bit_H; /* У<><D0A3>λ<EFBFBD>߰<EFBFBD>λ */
uint8_t check_Bit_L; /* У<><D0A3>λ<EFBFBD>Ͱ<EFBFBD>λ */
uint8_t end_Flag; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ */
}SL_Mppt_Rorecv_pack;
#define SL_MPPT_RORECV_PACK_SIZE (sizeof(SL_Mppt_Rorecv_pack))
/* дʱ<D0B4><CAB1><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>֡<EFBFBD><D6A1>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-><3E><><EFBFBD><EFBFBD><EFBFBD>ڵ㣩 */
typedef struct _SL_Mppt_Worecv_pack{
uint8_t start_Flag[2]; /* <20><>ʼ<EFBFBD><CABC>־ */
uint8_t address[7]; /* <20><>ַ */
uint8_t function_Code; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
uint8_t write_Register_Start_Address_H; /* д<>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ<EFBFBD><D6B7>8λ */
uint8_t write_Register_Start_Address_L; /* д<>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ<EFBFBD>Ͱ<EFBFBD>λ */
uint8_t write_Register_Number_H; /* д<>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߰<EFBFBD>λ */
uint8_t write_Register_Number_L; /* д<>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD>λ */
uint8_t *content; /* д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
uint8_t check_Bit_H; /* У<><D0A3>λ<EFBFBD>߰<EFBFBD>λ */
uint8_t check_Bit_L; /* У<><D0A3>λ<EFBFBD>Ͱ<EFBFBD>λ */
uint8_t end_Flag; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ */
}SL_Mppt_Worecv_pack;
#define SL_MPPT_WORECV_PACK_SIZE (sizeof(SL_Mppt_Worecv_pack))
/* ɨ<><C9A8><EFBFBD>㲥֡F1<46><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-><3E><><EFBFBD><EFBFBD><EFBFBD>ڵ㣩 */
typedef struct _SL_Mppt_ScanBroadcast_pack{
uint8_t start_Flag[2]; /* <20><>ʼ<EFBFBD><CABC>־ */
uint8_t address[7]; /* <20><>ַ */
uint8_t function_Code; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
uint8_t check_Bit_H; /* У<><D0A3>λ<EFBFBD>߰<EFBFBD>λ */
uint8_t check_Bit_L; /* У<><D0A3>λ<EFBFBD>Ͱ<EFBFBD>λ */
uint8_t end_Flag; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ */
}SL_Mppt_Scan_Broadcast_pack;
#define SL_MPPT_SCAN_BROADCAST_PACK_SIZE (sizeof(SL_Mppt_Scan_Broadcast_pack))
/* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡F2<46><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>-><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD> */
typedef struct _SL_Mppt_RegistrationRequest_pack{
uint8_t start_Flag[2]; /* <20><>ʼ<EFBFBD><CABC>־ */
uint8_t address[7]; /* <20><>ַ */
uint8_t function_Code; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
uint8_t register_Length_H; /* <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȸ߰<C8B8>λ */
uint8_t register_Length_L; /* <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȵͰ<C8B5>λ */
uint8_t registration_Status_H; /* ע<><D7A2>״̬<D7B4>߰<EFBFBD>λ */
uint8_t registration_Status_L; /* ע<><D7A2>״̬<D7B4>Ͱ<EFBFBD>λ */
uint8_t access_Node_ID[7]; /* <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ID */
uint8_t access_Node_Type_H; /* <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD>͸߰<CDB8>λ */
uint8_t access_Node_Type_L; /* <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD>͵Ͱ<CDB5>λ */
uint8_t check_Bit_H; /* У<><D0A3>λ<EFBFBD>߰<EFBFBD>λ */
uint8_t check_Bit_L; /* У<><D0A3>λ<EFBFBD>Ͱ<EFBFBD>λ */
uint8_t end_Flag; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ */
}SL_Mppt_RegistrationRequest_pack;
#define SL_MPPT_REGISTRATIONREQUEST_PACK_SIZE (sizeof(SL_Mppt_RegistrationRequest_pack))
/* ע<><D7A2><EFBFBD>ظ<EFBFBD>֡F3<46><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-><3E><><EFBFBD><EFBFBD><EFBFBD>ڵ㣩 */
typedef struct _SL_Mppt_RegistrationReply_pack{
uint8_t start_Flag[2]; /* <20><>ʼ<EFBFBD><CABC>־ */
uint8_t address[7]; /* <20><>ַ */
uint8_t function_Code; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
uint8_t register_Length_H; /* <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȸ߰<C8B8>λ */
uint8_t register_Length_L; /* <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȵͰ<C8B5>λ */
uint8_t registration_Status_H; /* ע<><D7A2>״̬<D7B4>߰<EFBFBD>λ */
uint8_t registration_Status_L; /* ע<><D7A2>״̬<D7B4>Ͱ<EFBFBD>λ */
uint8_t check_Bit_H; /* У<><D0A3>λ<EFBFBD>߰<EFBFBD>λ */
uint8_t check_Bit_L; /* У<><D0A3>λ<EFBFBD>Ͱ<EFBFBD>λ */
uint8_t end_Flag; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ */
}SL_Mppt_RegistrationReply_pack;
#define SL_MPPT_REGISTRATIONREPLY_PACK_SIZE (sizeof(SL_Mppt_RegistrationReply_pack))
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-><3E><><EFBFBD><EFBFBD><EFBFBD>ڵ㣩 */
typedef struct _SL_Mppt_ROther_pack{
uint8_t start_Flag[2]; /* <20><>ʼ<EFBFBD><CABC>־ */
uint8_t address[7]; /* <20><>ַ */
uint8_t function_Code; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
uint8_t check_Bit_H; /* У<><D0A3>λ<EFBFBD>߰<EFBFBD>λ */
uint8_t check_Bit_L; /* У<><D0A3>λ<EFBFBD>Ͱ<EFBFBD>λ */
uint8_t end_Flag; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ */
}SL_Mppt_ROther_pack;
#define SL_MPPT_ROTHER_PACK_SIZE (sizeof(SL_Mppt_ROther_pack))
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>-><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD> */
typedef struct _SL_Mppt_SOther_pack{
uint8_t start_Flag[2]; /* <20><>ʼ<EFBFBD><CABC>־ */
uint8_t address[7]; /* <20><>ַ */
uint8_t function_Code; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
uint8_t state; /* ׼<><D7BC>״̬<D7B4><CCAC>01H׼<48><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
uint8_t check_Bit_H; /* У<><D0A3>λ<EFBFBD>߰<EFBFBD>λ */
uint8_t check_Bit_L; /* У<><D0A3>λ<EFBFBD>Ͱ<EFBFBD>λ */
uint8_t end_Flag; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ */
}SL_Mppt_SOther_pack;
#define SL_MPPT_SOTHER_PACK_SIZE (sizeof(SL_Mppt_SOther_pack))
2024-07-11 06:58:55 +00:00
/* */
#define RECV_LENGTH 20
typedef struct _SL_Mppt_Recv_pack{
uint8_t start_Flag[2]; /* <20><>ʼ<EFBFBD><CABC>־ */
uint8_t address[7]; /* <20><>ַ */
uint8_t function_Code; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
uint8_t recv_Data[RECV_LENGTH]; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
}SL_Mppt_Recv_pack;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
typedef void (*MsgProcFunc)(device_handle device, void*, uint32_t MsgLen);
typedef struct _SL_FunctionMsgProcTable{
u_int32_t msgId;
MsgProcFunc pMsgProc;
}SL_FuncionMsgProcTable;
/* <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
typedef uint16_t (*RegProcFunc)(void*);
typedef struct _SL_RegProcTable{
uint32_t regId;
RegProcFunc pRegProc;
}SL_RegProcTable;
2024-08-29 02:50:22 +00:00
/* Ĭ<>ϲ<EFBFBD><CFB2><EFBFBD> */
typedef struct _default_Value{
uint8_t start_Flag[2]; /* <20><>ʼ<EFBFBD><CABC>־ */
uint8_t address[7]; /* <20><>ַ */
uint16_t access_Node_Type; /* <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD> */
uint16_t communication_Methods; /* ͨ<>ŷ<EFBFBD>ʽ */
uint8_t end_Flag; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ */
}default_Value;
extern default_Value defaultValue;
typedef struct _SL_Mppt_para{
uint16_t Registration_Status; /* ע<><D7A2>״̬ */
uint8_t address[7]; /* <20><>ַ */
uint16_t Access_Node_Type; /* <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD> */
uint16_t Communication_Methods; /* ͨ<>ŷ<EFBFBD>ʽ */
2024-09-18 01:47:44 +00:00
float_t Output_Voltage; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ */
2024-08-29 02:50:22 +00:00
float_t Battery_Voltage; /* <20><><EFBFBD>ص<EFBFBD>ѹ */
float_t Charg_Current; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD>أ<EFBFBD> */
float_t Discharg_Current; /* <20>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD> */
float_t Input_Voltage; /* ̫<><CCAB><EFBFBD>ܰ<EFBFBD><DCB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ */
float_t Solar_Open_Circuit_Voltage; /* ̫<><CCAB><EFBFBD>ܰ忪·<E5BFAA><C2B7>ѹ */
2024-08-29 02:50:22 +00:00
float_t HighSideMos_Temperature; /* <20>߶<EFBFBD>mos<6F><73><EFBFBD><EFBFBD> */
uint16_t DischargMos_State; /* <20>ŵ<EFBFBD>mos<6F><73>״̬ */
uint16_t MPPT_Mode; /* <20><><EFBFBD><EFBFBD>ģʽ */
}SL_Mppt_para;
extern SL_Mppt_para g_Mppt_Para;
2024-07-11 06:58:55 +00:00
/* <20>ָ<EFBFBD>Ĭ<EFBFBD>ϵĶ<CFB5><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#pragma pack(pop)
void read_and_process_uart_data(device_handle device);
uint16_t CheckFunc(uint8_t *arr_buff, uint8_t len);
int randomDelay();
uint8_t Check_485_bus_busy(device_handle device);
#endif /* APP_INC_SL_PROTOCOL_H_ */