#ifndef __USART_NRF3_H #define __USART_NRF3_H #ifdef DTU3PRO #include "stm32f4xx.h" #define UsartNrf USART3 #else #include "stm32f10x.h" #endif #include #include #include #include #include #include #include "rtc.h" #include "SysTick.h" /* Polling, polling software version, upgrade program, command, anti-theft polling, anti-theft settings, lock MI, unlock MI, limit power, configure grid-connected file, switch air baud rate*/ #define ANSWER_EXCEPTION_ONE_MULTI 0XFF #define ANSWER_EXCEPTION_MULTI_ONE 0xF1 #define REQ_ARW_DAT_ALL 0X15 #define PARASET_ALL 0X52 #define ANSWER_PARASET_ALL (PARASET_ALL|0X80) #define DEVCONTROL_ALL 0x51 #define ANSWER_DEVCONTROL_ALL (DEVCONTROL_ALL|0X80) #define ANSWER_REQ_ARW_DAT_ALL (REQ_ARW_DAT_ALL|0X80) #define REQ_VERSISON 0x0f //Query terminal software and hardware information #define ANSWER_REQ_VERSISON (REQ_VERSISON | 0x80) //0x8F// #define MAX_SUB_DAT_DATA_LEN 64 #define MAX_TRANS_DAT_DATA_LEN 16 //The micro-reverse connection state is used locally #define MI_CONNECT 0X02 #define MI_DISCONNECT 0XFD //The micro-reverse connection state is used for the abnormal flag of historical power generation #define MI_TOTAL_ENERGY_FAULT 0X04 #define MI_TOTAL_ENERGY_FAULTCLEAR 0XFB //The micro-reverse connection state is used on the server side #define MI_SERVER_CONNECT 0X01 #define MI_SERVER_DISCONNECT 0XFE // Micro-inverse the difference between the historical power generation of the two packages #define PV_ONE_DAY_TOTAL_ENERGY 2000 extern vu32 LineCnt_Pro; //�෢���� extern vu8 SubData3[MAX_TRANS_DAT_DATA_LEN]; extern vu8 CurSendRecLastPackageNO; extern vu8 CurSendRecLostPackageNO; //�������� typedef enum { SendInitPackage = 0x00, SendFirstPackage = 0x01, SendLastPackage = 0x02, SendLostPackage = 0x03, } SendPackageState; extern vu8 CurRecSendPackageDataType; extern vu8 TotalPackageNum; extern vu8 CurRecSendLostPackageNO; extern vu32 CurRecSendLostPackageState; extern vu16 PortNO_App; extern vu16 PortNO_Alarm_Server; extern vu8 InformAlarmDataNO; typedef union { struct { //dong 20200520 u16 WCode; u8 Alarm_Id[6] ; u8 WNum[2]; u8 WTime1[4]; u8 WTime2[4]; u8 Data1[2]; u8 Data2[2]; } Data; u8 DataMsg[22]; } AlarmDataType; typedef struct { u8 Alarm_Id[6] ; //dong 20200520 u16 WCode; u8 WNum[2]; u8 WTime1[4]; u8 WVDataL[2]; u8 WPos[2]; u8 WVData[1200];//The wave recording data is tentatively set to 1200 } WaveDataType; //CurAlarmState -- alarm state type typedef enum { InitState = 0, //There is a new alarm record HasNewAlarmRecord = 1, //There is a new wave recording alarm HasNewWaveRecord = 2, //No new alarm record HasNONewAlarmRecord = 3, //No new wave recording alarm HasNONewWaveRecord = 4, // Suspend the alarm AlarmInforUpdate_Server = 10, //APP state switch AlarmInforUpdate_App = 11, } AlarmStateType; extern volatile AlarmStateType CurAlarmState; typedef enum { InverterDevInform_Simple = 0, InverterDevInform_All = 1, GridOnProFilePara = 2, HardWareConfig = 3, SimpleCalibrationPara = 4, SystemConfigPara = 5, RealTimeRunData_Debug = 11, // 0x0b RealTimeRunData_Reality = 12, // 0x0c RealTimeRunData_A_Phase = 13, // 0x0d RealTimeRunData_B_Phase = 14, // 0x0e RealTimeRunData_C_Phase = 15, // 0x0f //Alarm data - all unsent alarms AlarmData = 17, // 0x11 //Alarm data - all pending alarms AlarmUpdate = 18, // 0x12 RecordData = 19, // 0x13 InternalData = 20, // 0x14 GetLossRate = 21, // 0x15 //dong 2020-06-15 GetSelfCheckState = 30, // 0x1e InitDataState = 0xff, } DataType; typedef enum { Type_TurnOn = 0, Type_TurnOff = 1, Type_Restart = 2, Type_Lock = 3, Type_Unlock = 4, Type_ActivePowerContr = 11, // 0x0b Type_ReactivePowerContr = 12, // 0x0c Type_PFSet = 13, // 0x0d Type_CleanState_LockAndAlarm = 20, // 0x14 //dong 06-15 Type_SelfInspection = 40, // 0x28 // self-inspection of grid-connected protection files Type_Init = 0xff, } DevControlType; typedef enum { SysParaSet = 0, EleEnergySet = 1, TempSampleCalibration = 2, PortEleParaCalibration = 3, AntitheftParaSet = 4, } ParaSetType; // AppState typedef enum { //Single micro inverse scan PollSigleMi = 1, //Multiple micro inverse scans PollAllMi = 2, //dong ???? SigleMiLossRate = 3, //Multiple packet loss rate statistics AllMiLossRate = 4, //Single packet loss rate statistics ManuSigleLossRate = 5, //Network command mode OtherNetCmdState = 100, } App_DataPollState; // typedef union { struct { vu16 code; //Number of decimal places and self-test result code vu16 dflt_val; //Regulation protection point vu16 dflt_tim; //Regulation protection action time vu16 rslt_val; //Measured protection point vu16 rslt_tim; //Measured protection action time } Property; vu8 Data[10]; } STVal; typedef union { struct { vu8 pv_sn[6]; //Micro inverse ID vu16 ver; //Data version vu16 st; //Test status vu16 gpf; //Code of grid-connected rule file vu16 gpf_ver; //Version of grid-connected rule file STVal hv1_stval; // Level 1 overvoltage self-test result STVal lv1_stval; //Level 1 undervoltage self-test result STVal hv2_stval; //Secondary overvoltage self-test result STVal lv2_stval; //Secondary undervoltage self-test result STVal hf1_stval; //Level 1 overfrequency self-test result STVal lf1_stval; //First-level underfrequency self-test result STVal hf2_stval; //Secondary overfrequency self-test result STVal lf2_stval; //Secondary underfrequency self-test result } Property; vu8 Data[94]; } GPSTVal; extern volatile App_DataPollState AppState; extern bool UsartNrf3_AlarmInformationSearch(void); extern bool UsartNrf3_PollRealTimeWithVersion(void); //Three generations of protocol round sequence NRF version number u8 UsartNrf3_Send_Mi_Nrf_VER(u8 *target_adr, u8 *rout_adr); //Single package multi-receive send package extern u8 UsartNrf3_Send_PackPollSigleDataCommand(u8 *target_adr, u8 *rout_adr, u8 FrameNO); //Multiple orders extern u8 UsartNrf3_Send_PackPollMultiDataCommand(u8 *target_adr, u8 *rout_adr, u8 DataType, u8 Gap, u8 *Password); extern bool UsartNrf3_HasPollCurInverterPort(void); extern void UsartNrf3_Send_PackPollVersionCmd(void); extern void UsartNrf3_Process_Pro(u8 *pBuffer); extern bool HasSendCurFirstPackage; extern bool UsartNrf3_HasSetCurrentInverterOk(void); extern void UsartNrf3_Send_PackNrfCmd(void); extern void UsartNrf3_Send_NetCmdToNrfCmd(void); extern void UsartNrf3_Send_DownLoadDat(void); extern void UsartNrf3_Send_DownLoadPro(void); extern u8 UsartNrf_Send_PackBaseCommand(u8 *target_adr, u8 *rout_adr, u8 cmd, u8 dat); extern bool UsartNrf3_SendLoop_ReplyOK(void); extern void UsartNrf3_Send_ParaSet(void); extern void UsartNrf3_SendLoop_SetTaskTimeOut(bool Stop); extern void UsartNrf3_Process_One_MultiPackage(u8 *pBuffer); //Search for the next microinverse extern void UsartNrf3_Send_SearchNextPannelOrInv(void); extern void UsartNrf3_Process_AlarmFlashWriteEvery15Min(void); extern void UsartNrf3_Process_LedShow(bool RealTimeState); extern void UsartNrf3_Process_ClearMIVersion(void); //dong 2020-06-15 //Micro-inverse self-test status processing void UsartNrf3_Process_Self_Check_State(u8 *pBuffer); // Function name: Three-generation protocol polling, all alarm transmission, application layer receipt processing void UsartNrf3_Process_DevInform_Alarm(u8 *pBuffer); //Alarm data - all pending alarms void UsartNrf3_Process_DevInform_InformUpdate(u8 *pBuffer); //The receiving transport layer of the single-send and multiple-receive mechanism (combined package) uint16_t UsartNrf3_Process_GetDatatoProBuffer(u8 *pBuffer, u16 BufferSize); // Process real-time data void UsartNrf3_Process_DevRunReality(u8 *pBuffer); //D1 Command device control response processing void UsartNrf3_Process_DevControl(u8 *pBuffer); //Third-generation protocol device control application layer transmission void UsartNrf_Send_DevControlUpdate(u8 *target_adr, u8 *rout_adr); //Third-generation protocol device control transport layer transmission void UsartNrf3_Send_DevControlUpdate(u8 *target_adr, u8 *rout_adr); //The third-generation protocol device controls the transmission of the transmission application layer extern void UsartNrf3_Send_DevControl(void); //Third-generation protocol device control transmission application layer transmission u8 UsartNrf3_Send_PackDevControl(u8 *target_adr, u8 *rout_adr, u16 ControlMode, u8 *ControlData, u8 nub, u8 Num); //typedef enum //{ // IdleState = 0, // WriteFlashState = 1, // PollMulPackageState = 2, //}FlashLockState; typedef enum { InitLayer = 0, ToTransLayer_Send = 1, ToAppLayer = 2, ToTransLayer_Process = 3, } ProtocalLayerType; typedef struct { s16 MI_CF_Num_End; s16 MI_RF_Num_End; s16 MI_CF_Num_Start; s16 MI_RF_Num_Start; } DataCntType; extern ProtocalLayerType ProtocalLayer_Poll, ProtocalLayer_Cmd; //extern char TempRowData[]; extern volatile bool CurPollIsDebugDataTime; extern volatile bool CurPollIsAllDataTime; extern volatile AlarmDataType pInformAlarm[]; //extern vu16 CurInformAlarmNum; extern vu8 CurRowTotalLen; extern vu32 LocalTime_TaskTimeOut; extern vu32 NeedLostPackageState; extern bool UsartNrf3_AppStateSwitch(u8 TotalCnt, u8 SucCnt); //extern bool LockFlag; #endif