159 lines
6.3 KiB
C
159 lines
6.3 KiB
C
|
/*
|
|||
|
* 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"
|
|||
|
|
|||
|
|
|||
|
/* <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_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>ʽ */
|
|||
|
SL_Register_Battery_Voltage = 0x0100, /* <20><><EFBFBD>ص<EFBFBD>ѹ */
|
|||
|
SL_Register_Battery_temperature = 0x0101, /* <20><><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD> */
|
|||
|
SL_Register_Remaining_Battery_Bower = 0x0102, /* <20><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
SL_Register_Solar_Open_Circuit_Voltage1 = 0x0103, /* ̫<><CCAB><EFBFBD>ܿ<EFBFBD>·<EFBFBD><C2B7>ѹ1 */
|
|||
|
SL_Register_Solar_Open_Circuit_Voltage2 = 0x0104, /* ̫<><CCAB><EFBFBD>ܿ<EFBFBD>·<EFBFBD><C2B7>ѹ2 */
|
|||
|
}SL_Mppt_MsgRegister;
|
|||
|
|
|||
|
/* ע<><D7A2>״̬ */
|
|||
|
typedef enum
|
|||
|
{
|
|||
|
UNREGISTER = 0, /* δע<CEB4><D7A2> */
|
|||
|
REGISTER_FAIL = 1, /* ע<><D7A2>ʧ<EFBFBD><CAA7> */
|
|||
|
REGISTER_SUCCESS = 2, /* ע<><D7A2><EFBFBD>ɹ<EFBFBD> */
|
|||
|
}SL_REGISTERSTATUS;
|
|||
|
|
|||
|
#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))
|
|||
|
|
|||
|
/* */
|
|||
|
#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;
|
|||
|
|
|||
|
/* <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_ */
|