2025-03-04 10:04:30 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "FreeRTOS.h"
|
|
|
|
|
#include "freerotsTask.h"
|
|
|
|
|
#include "task.h"
|
|
|
|
|
|
|
|
|
|
#include "pDebug.h"
|
|
|
|
|
#include "upUartParse.h"
|
|
|
|
|
#include "FM_GPIO.h"
|
|
|
|
|
#include "FM_ADC.h"
|
|
|
|
|
#include "queueUart.h"
|
2025-03-05 08:27:39 +00:00
|
|
|
|
#include "parameter.h"
|
2025-03-04 10:04:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* <20><>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼλ */
|
|
|
|
|
#define maxStartReadResAddr 10
|
|
|
|
|
/* <20><>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
#define maxReadResAddrLen 20
|
|
|
|
|
|
|
|
|
|
/* д<><D0B4><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼλ */
|
|
|
|
|
#define maxStartWriteResAddr 10
|
|
|
|
|
/* д<><D0B4><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
#define maxWriteResAddrLen 20
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD>ζ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
#define maxReadCfgLen 80
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD> */
|
|
|
|
|
#define maxDistributionCfgLen 230
|
|
|
|
|
|
|
|
|
|
/* 2<><32><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
#define tick_2S (configTICK_RATE_HZ * 2)
|
|
|
|
|
/* 1<><31><EFBFBD>ӵĽ<D3B5><C4BD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
#define tick_1M (configTICK_RATE_HZ * 60)
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD> */
|
|
|
|
|
typedef enum {
|
|
|
|
|
/* (1<>ֽ<EFBFBD>)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>ͨ<EFBFBD>Ų<EFBFBD><C5B2><EFBFBD><EFBFBD><EFBFBD>(00H<30><48><EFBFBD><EFBFBD>ʹ<EFBFBD>øô<C3B8><C3B4><EFBFBD>,01H<31><48>4800;02H<32><48>9600;03H<33><48>19200;04H<34><48>38400;05H<35><48>57600;06H<36><48>115200) */
|
|
|
|
|
Upward_UART_Communication_Baud_Rate = 0x0001,
|
|
|
|
|
J1_485_Communication_Baud_Rate = 0x0002,
|
|
|
|
|
J2_485_Communication_Baud_Rate = 0x0003,
|
|
|
|
|
J3_485_Communication_Baud_Rate = 0x0004,
|
|
|
|
|
J4_485_Communication_Baud_Rate = 0x0005,
|
|
|
|
|
J5_0_485_Communication_Baud_Rate = 0x0006,
|
|
|
|
|
}gateWayCfgFileType;
|
|
|
|
|
|
|
|
|
|
/* ״̬<D7B4><CCAC> */
|
|
|
|
|
typedef enum {
|
|
|
|
|
wait = 0, /* <20><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>ʼ״̬ */
|
|
|
|
|
startFlagGW, /* <20><><EFBFBD>յ<EFBFBD>֡ͷ */
|
|
|
|
|
functionCodeGW, /* <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
readRegStartAddressGW, /* <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ */
|
|
|
|
|
readRegStartNumberGW, /* <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
crcCheckBitGW, /* <20><><EFBFBD>յ<EFBFBD>У<EFBFBD><D0A3>λ */
|
|
|
|
|
endFlagGW, /* <20><><EFBFBD>յ<EFBFBD>֡β */
|
|
|
|
|
writeRegStartAddressGW, /* <20><><EFBFBD>յ<EFBFBD>д<EFBFBD><D0B4><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ */
|
|
|
|
|
writeRegStartNumberGW, /* <20><><EFBFBD>յ<EFBFBD>д<EFBFBD><D0B4><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
cfgFramesNumGW, /* <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>֡<EFBFBD><D6A1> */
|
|
|
|
|
cfgLengthGW, /* <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
readCfgLengthGW, /* <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
startFlagSL, /* <20><><EFBFBD>յ<EFBFBD>֡ͷ */
|
|
|
|
|
portSL, /* <20><><EFBFBD>յ<EFBFBD><D5B5>˿ں<CBBF> */
|
|
|
|
|
lengthSL, /* <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0>ij<EFBFBD><C4B3><EFBFBD> */
|
|
|
|
|
endFlagSL, /* <20><><EFBFBD>յ<EFBFBD>֡β */
|
|
|
|
|
} uartStateMachine;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /* <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1min<69><6E>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD> */
|
|
|
|
|
// static uint32_t gw485CfgTime = 0;
|
|
|
|
|
|
|
|
|
|
/* <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡<D2BB><D6A1><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD> */
|
|
|
|
|
static uint32_t gw485RxTime = 0;
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>gw485<38><35><EFBFBD><EFBFBD> */
|
|
|
|
|
static uint8_t gw485RxBuffer[1100];
|
|
|
|
|
static uint16_t gw485RxBufferIndex = 0;
|
|
|
|
|
|
|
|
|
|
/* ״̬<D7B4><CCAC>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
static uartStateMachine state = wait;
|
|
|
|
|
/* ֡<><D6A1><EFBFBD><EFBFBD> */
|
|
|
|
|
static uint16_t frameLength = 0;
|
|
|
|
|
|
|
|
|
|
static void stateMachine(device_handle device);
|
|
|
|
|
|
|
|
|
|
/* ״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
static uint8_t analysisWait(void);
|
|
|
|
|
static uint8_t analysisStartFlagGW(void);
|
|
|
|
|
static uint8_t analysisFunctionCodeGW(void);
|
|
|
|
|
static uint8_t analysisReadRegStartAddressGW(void);
|
|
|
|
|
static uint8_t analysisReadRegStartNumberGW(void);
|
|
|
|
|
static uint8_t analysisCrcCheckBitGW(void);
|
|
|
|
|
static uint8_t analysisEndFlagGW(device_handle device);
|
|
|
|
|
static uint8_t analysisWriteRegStartAddressGW(void);
|
|
|
|
|
static uint8_t analysisWriteRegStartNumberGW(void);
|
|
|
|
|
static uint8_t analysisCfgFramesNumGW(void);
|
|
|
|
|
static uint8_t analysisCfgLengthGW(void);
|
|
|
|
|
static uint8_t analysisReadCfgLengthGW(void);
|
|
|
|
|
static uint8_t analysisStartFlagSL(void);
|
|
|
|
|
static uint8_t analysisPortSL(void);
|
|
|
|
|
static uint8_t analysisLengthSL(void);
|
|
|
|
|
static uint8_t analysisEndFlagSL(void);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void GW_MsgProcFunc_Read_Register(device_handle device,uint8_t *buff, uint16_t buffLen);
|
|
|
|
|
static void GW_MsgProcFunc_Write_Register(device_handle device, void *pMsg, uint32_t MsgLen);
|
|
|
|
|
static void GW_MsgProcFunc_Distribution_Profile(device_handle device, void *pMsg, uint32_t MsgLen);
|
|
|
|
|
static void GW_MsgProcFunc_Read_Profile(device_handle device, void *pMsg, uint32_t MsgLen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* <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><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
static uint16_t ReadRegisterWorkCurrent(void *pMsg);
|
|
|
|
|
static uint16_t ReadRegisterWorkVoltage(void *pMsg);
|
|
|
|
|
static uint16_t ReadRegisterTemperature(void *pMsg);
|
|
|
|
|
static uint16_t ReadRegisterPort1_Power(void *pMsg);
|
|
|
|
|
static uint16_t ReadRegisterPort2_Power(void *pMsg);
|
|
|
|
|
static uint16_t ReadRegisterPort3_Power(void *pMsg);
|
|
|
|
|
static uint16_t ReadRegisterPort4_Power(void *pMsg);
|
|
|
|
|
static uint16_t ReadRegisterPort5_Power(void *pMsg);
|
|
|
|
|
static uint16_t ReadRegisterPort6_Power(void *pMsg);
|
|
|
|
|
static uint16_t ReadRegisterPort7_Power(void *pMsg);
|
|
|
|
|
static uint16_t ReadRegisterPort8_Power(void *pMsg);
|
|
|
|
|
static uint16_t ReadRegisterPort9_Power(void *pMsg);
|
|
|
|
|
static uint16_t WriteRegisterPort1_Power(void *pMsg);
|
|
|
|
|
static uint16_t WriteRegisterPort2_Power(void *pMsg);
|
|
|
|
|
static uint16_t WriteRegisterPort3_Power(void *pMsg);
|
|
|
|
|
static uint16_t WriteRegisterPort4_Power(void *pMsg);
|
|
|
|
|
static uint16_t WriteRegisterPort5_Power(void *pMsg);
|
|
|
|
|
static uint16_t WriteRegisterPort6_Power(void *pMsg);
|
|
|
|
|
static uint16_t WriteRegisterPort7_Power(void *pMsg);
|
|
|
|
|
static uint16_t WriteRegisterPort8_Power(void *pMsg);
|
|
|
|
|
static uint16_t WriteRegisterPort9_Power(void *pMsg);
|
|
|
|
|
|
|
|
|
|
/* <20><>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
SL_RegProcTable g_RegTblR[] =
|
|
|
|
|
{
|
|
|
|
|
{GW_Register_WorkCurrent, ReadRegisterWorkCurrent},
|
|
|
|
|
{GW_Register_WorkVoltage, ReadRegisterWorkVoltage},
|
|
|
|
|
{GW_Register_Temperature, ReadRegisterTemperature},
|
|
|
|
|
{GW_Register_Port1_Power, ReadRegisterPort1_Power},
|
|
|
|
|
{GW_Register_Port2_Power, ReadRegisterPort2_Power},
|
|
|
|
|
{GW_Register_Port3_Power, ReadRegisterPort3_Power},
|
|
|
|
|
{GW_Register_Port4_Power, ReadRegisterPort4_Power},
|
|
|
|
|
{GW_Register_Port5_Power, ReadRegisterPort5_Power},
|
|
|
|
|
{GW_Register_Port6_Power, ReadRegisterPort6_Power},
|
|
|
|
|
{GW_Register_Port7_Power, ReadRegisterPort7_Power},
|
|
|
|
|
{GW_Register_Port8_Power, ReadRegisterPort8_Power},
|
|
|
|
|
{GW_Register_Port9_Power, ReadRegisterPort9_Power},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* д<><D0B4><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
SL_RegProcTable g_RegTblW[] =
|
|
|
|
|
{
|
|
|
|
|
{GW_Register_Port1_Power, WriteRegisterPort1_Power},
|
|
|
|
|
{GW_Register_Port2_Power, WriteRegisterPort2_Power},
|
|
|
|
|
{GW_Register_Port3_Power, WriteRegisterPort3_Power},
|
|
|
|
|
{GW_Register_Port4_Power, WriteRegisterPort4_Power},
|
|
|
|
|
{GW_Register_Port5_Power, WriteRegisterPort5_Power},
|
|
|
|
|
{GW_Register_Port6_Power, WriteRegisterPort6_Power},
|
|
|
|
|
{GW_Register_Port7_Power, WriteRegisterPort7_Power},
|
|
|
|
|
{GW_Register_Port8_Power, WriteRegisterPort8_Power},
|
|
|
|
|
{GW_Register_Port9_Power, WriteRegisterPort9_Power},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t ReadRegisterWorkCurrent(void *pMsg)
|
|
|
|
|
{
|
2025-03-05 08:27:39 +00:00
|
|
|
|
return (uint16_t)(getWorkCurrent() * 10);
|
2025-03-04 10:04:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t ReadRegisterWorkVoltage(void *pMsg)
|
|
|
|
|
{
|
2025-03-05 08:27:39 +00:00
|
|
|
|
return (uint16_t)(getWorkVoltage() * 10);
|
2025-03-04 10:04:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD>¶ȼĴ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t ReadRegisterTemperature(void *pMsg)
|
|
|
|
|
{
|
2025-03-05 08:27:39 +00:00
|
|
|
|
return (uint16_t)(getTemperature() * 10);
|
2025-03-04 10:04:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD>˿<EFBFBD>1<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t ReadRegisterPort1_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
return readPwrCtrlState(J1_PwrCtrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD>˿<EFBFBD>2<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t ReadRegisterPort2_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
return readPwrCtrlState(J2_PwrCtrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD>˿<EFBFBD>3<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t ReadRegisterPort3_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
return readPwrCtrlState(J3_PwrCtrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD>˿<EFBFBD>4<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t ReadRegisterPort4_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
return readPwrCtrlState(J4_PwrCtrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD>˿<EFBFBD>5<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t ReadRegisterPort5_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
return readPwrCtrlState(J5_PwrCtrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD>˿<EFBFBD>6<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t ReadRegisterPort6_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
return readPwrCtrlState(J6_PwrCtrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD>˿<EFBFBD>7<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t ReadRegisterPort7_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
return readPwrCtrlState(J7_PwrCtrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD>˿<EFBFBD>8<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t ReadRegisterPort8_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
return readPwrCtrlState(J8_PwrCtrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD>˿<EFBFBD>9<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t ReadRegisterPort9_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
return readPwrCtrlState(J9_PwrCtrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>ö˿<EFBFBD>1<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t WriteRegisterPort1_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
writePwrCtrlState(J1_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>ö˿<EFBFBD>2<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t WriteRegisterPort2_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
writePwrCtrlState(J2_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>ö˿<EFBFBD>3<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t WriteRegisterPort3_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
writePwrCtrlState(J3_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>ö˿<EFBFBD>4<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t WriteRegisterPort4_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
writePwrCtrlState(J4_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>ö˿<EFBFBD>5<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t WriteRegisterPort5_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
writePwrCtrlState(J5_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>ö˿<EFBFBD>6<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t WriteRegisterPort6_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
writePwrCtrlState(J6_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>ö˿<EFBFBD>7<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t WriteRegisterPort7_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
writePwrCtrlState(J7_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>ö˿<EFBFBD>8<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t WriteRegisterPort8_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
writePwrCtrlState(J8_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>ö˿<EFBFBD>9<EFBFBD><EFBFBD>Դ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint16_t WriteRegisterPort9_Power(void *pMsg)
|
|
|
|
|
{
|
|
|
|
|
writePwrCtrlState(J9_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ wait
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
#define waitMaxLen 2
|
|
|
|
|
uint8_t analysisWait(void)
|
|
|
|
|
{
|
|
|
|
|
if (gw485RxBufferIndex >= 2) {
|
|
|
|
|
/* <><CDB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>ͷ */
|
|
|
|
|
if (gw485RxBuffer[0] == 'S' && gw485RxBuffer[1] == 'L') {
|
|
|
|
|
// log_info("startFlagSL\n");
|
|
|
|
|
state = startFlagSL;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>ͷ */
|
|
|
|
|
else if (gw485RxBuffer[0] == 'G' && gw485RxBuffer[1] == 'W') {
|
|
|
|
|
state = startFlagGW;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gw485RxBufferIndex < waitMaxLen) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ startFlagGW
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
uint8_t analysisStartFlagGW(void)
|
|
|
|
|
{
|
|
|
|
|
if (gw485RxBuffer[2] == SL_Function_Code_Read_Register
|
|
|
|
|
|| gw485RxBuffer[2] == SL_Function_Code_Write_Register
|
|
|
|
|
|| gw485RxBuffer[2] == SL_Function_Code_Distribution_Profile
|
|
|
|
|
|| gw485RxBuffer[2] == SL_Function_Code_Read_Profile) {
|
|
|
|
|
state = functionCodeGW;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ functionCodeGW
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
#define functionCodeGWMaxLen 5
|
|
|
|
|
uint8_t analysisFunctionCodeGW(void)
|
|
|
|
|
{
|
|
|
|
|
if (gw485RxBufferIndex >= 5 && gw485RxBuffer[2] == SL_Function_Code_Read_Register) {
|
|
|
|
|
/* <20><>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ */
|
|
|
|
|
uint16_t startResAddr = ((gw485RxBuffer[3] << 8) | gw485RxBuffer[4]);
|
|
|
|
|
if (startResAddr < maxStartReadResAddr) {
|
|
|
|
|
frameLength = 10;
|
|
|
|
|
state = readRegStartAddressGW;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gw485RxBufferIndex >= 5 && gw485RxBuffer[2] == SL_Function_Code_Write_Register) {
|
|
|
|
|
/* д<><D0B4><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ */
|
|
|
|
|
uint16_t startResAddr = ((gw485RxBuffer[3] << 8) | gw485RxBuffer[4]);
|
|
|
|
|
if (startResAddr < maxStartWriteResAddr) {
|
|
|
|
|
state = writeRegStartAddressGW;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gw485RxBufferIndex >= 5 && gw485RxBuffer[2] == SL_Function_Code_Write_Register) {
|
|
|
|
|
/* д<><D0B4><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ */
|
|
|
|
|
uint16_t startResAddr = ((gw485RxBuffer[3] << 8) | gw485RxBuffer[4]);
|
|
|
|
|
if (startResAddr < maxStartWriteResAddr) {
|
|
|
|
|
state = writeRegStartAddressGW;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>·<EFBFBD>֡<EFBFBD><D6A1> */
|
|
|
|
|
if ((gw485RxBufferIndex >= 5) && (gw485RxBuffer[2] == SL_Function_Code_Distribution_Profile)) {
|
|
|
|
|
if (gw485RxBuffer[3] <= gw485RxBuffer[4]) {
|
|
|
|
|
state = cfgFramesNumGW;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ݵij<DDB5><C4B3><EFBFBD> */
|
|
|
|
|
if ((gw485RxBufferIndex >= 5) && (gw485RxBuffer[2] == SL_Function_Code_Read_Profile)) {
|
|
|
|
|
uint32_t tempCfgLen = 0;
|
|
|
|
|
tempCfgLen = (gw485RxBuffer[3] << 8) | gw485RxBuffer[4];
|
|
|
|
|
|
|
|
|
|
if (tempCfgLen < maxReadCfgLen && tempCfgLen > 0) {
|
|
|
|
|
state = readCfgLengthGW;
|
|
|
|
|
frameLength = 8 + tempCfgLen;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gw485RxBufferIndex < functionCodeGWMaxLen) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ readRegStartAddressGW
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
#define ReadRegStartAddressGWMaxLen 7
|
|
|
|
|
uint8_t analysisReadRegStartAddressGW(void)
|
|
|
|
|
{
|
|
|
|
|
if (gw485RxBufferIndex >= 7) {
|
|
|
|
|
/* <20><>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ */
|
|
|
|
|
uint16_t resAddrLen = ((gw485RxBuffer[5] << 8) | gw485RxBuffer[6]);
|
|
|
|
|
if (resAddrLen < maxReadResAddrLen) {
|
|
|
|
|
state = readRegStartNumberGW;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gw485RxBufferIndex < functionCodeGWMaxLen) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ readRegStartNumberGW
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
#define ReadRegStartNumberMaxLen 9
|
|
|
|
|
uint8_t analysisReadRegStartNumberGW(void)
|
|
|
|
|
{
|
|
|
|
|
/* crcУ<63><D0A3> */
|
|
|
|
|
if (gw485RxBufferIndex >= ReadRegStartNumberMaxLen) {
|
|
|
|
|
uint16_t tempCrc = 0;
|
|
|
|
|
tempCrc = (gw485RxBuffer[frameLength - 3] << 8) | gw485RxBuffer[frameLength - 2];
|
|
|
|
|
|
|
|
|
|
if (tempCrc == checkModebusCrc(gw485RxBuffer, frameLength - 3)) {
|
|
|
|
|
state = crcCheckBitGW;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gw485RxBufferIndex < ReadRegStartNumberMaxLen) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ crcCheckBitGW
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
uint8_t analysisCrcCheckBitGW(void)
|
|
|
|
|
{
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־У<D6BE><D0A3>У<EFBFBD><D0A3> */
|
|
|
|
|
if (gw485RxBufferIndex == frameLength) {
|
|
|
|
|
if (gw485RxBuffer[frameLength - 1] == 0x16) {
|
|
|
|
|
state = endFlagSL;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ endFlagGW
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
uint8_t analysisEndFlagGW(device_handle device)
|
|
|
|
|
{
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD> */
|
|
|
|
|
if (gw485RxBuffer[2] == SL_Function_Code_Read_Register) {
|
|
|
|
|
GW_MsgProcFunc_Read_Register(device, gw485RxBuffer, frameLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>Ϊд<CEAA><D0B4><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD> */
|
|
|
|
|
if (gw485RxBuffer[2] == SL_Function_Code_Write_Register) {
|
|
|
|
|
GW_MsgProcFunc_Write_Register(device, gw485RxBuffer, frameLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD> */
|
|
|
|
|
else if (gw485RxBuffer[9] == SL_Function_Code_Distribution_Profile) {
|
|
|
|
|
GW_MsgProcFunc_Distribution_Profile(device, gw485RxBuffer, frameLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD> */
|
|
|
|
|
else if (gw485RxBuffer[9] == SL_Function_Code_Read_Profile) {
|
|
|
|
|
GW_MsgProcFunc_Read_Profile(device, gw485RxBuffer, frameLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>buff
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex = 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ writeRegStartAddressGW
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
#define WriteRegStartAddressGWMaxLen 7
|
|
|
|
|
uint8_t analysisWriteRegStartAddressGW(void)
|
|
|
|
|
{
|
|
|
|
|
if (gw485RxBufferIndex >= 7) {
|
|
|
|
|
/* д<><D0B4><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ */
|
|
|
|
|
uint16_t resAddrLen = ((gw485RxBuffer[5] << 8) | gw485RxBuffer[6]);
|
|
|
|
|
if (resAddrLen < maxReadResAddrLen) {
|
|
|
|
|
frameLength = 10 + 2 * resAddrLen;
|
|
|
|
|
state = readRegStartNumberGW;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gw485RxBufferIndex < WriteRegStartAddressGWMaxLen) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ writeRegStartNumberGW
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
#define WriteRegStartNumberGWMaxLen (frameLength - 1)
|
|
|
|
|
uint8_t analysisWriteRegStartNumberGW(void)
|
|
|
|
|
{
|
|
|
|
|
/* crcУ<63><D0A3> */
|
|
|
|
|
if (gw485RxBufferIndex >= WriteRegStartNumberGWMaxLen) {
|
|
|
|
|
uint16_t tempCrc = 0;
|
|
|
|
|
tempCrc = (gw485RxBuffer[frameLength - 3] << 8) | gw485RxBuffer[frameLength - 2];
|
|
|
|
|
|
|
|
|
|
if (tempCrc == checkModebusCrc(gw485RxBuffer, frameLength - 3)) {
|
|
|
|
|
state = crcCheckBitGW;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gw485RxBufferIndex < WriteRegStartNumberGWMaxLen) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ cfgFramesNumGW
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
#define CfgFramesNumGWMaxLen 7
|
|
|
|
|
uint8_t analysisCfgFramesNumGW(void)
|
|
|
|
|
{
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> */
|
|
|
|
|
if (gw485RxBufferIndex >= CfgFramesNumGWMaxLen) {
|
|
|
|
|
uint32_t tempLen = 0;
|
|
|
|
|
tempLen = (gw485RxBuffer[12] << 8) | gw485RxBuffer[13];
|
|
|
|
|
|
|
|
|
|
if (tempLen > 0 && tempLen <= maxDistributionCfgLen) {
|
|
|
|
|
state = cfgLengthGW;
|
|
|
|
|
frameLength = 10 + tempLen;
|
|
|
|
|
// log_error("cfgFramesNumSL error : tempLen = %d \n", tempLen);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gw485RxBufferIndex < CfgFramesNumGWMaxLen) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ cfgLengthGW
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
#define CfgLengthGWMaxLen (frameLength - 1)
|
|
|
|
|
uint8_t analysisCfgLengthGW(void)
|
|
|
|
|
{
|
|
|
|
|
/* crcУ<63><D0A3> */
|
|
|
|
|
if (gw485RxBufferIndex >= CfgLengthGWMaxLen) {
|
|
|
|
|
uint16_t tempCrc = 0;
|
|
|
|
|
tempCrc = (gw485RxBuffer[frameLength - 3] << 8) | gw485RxBuffer[frameLength - 2];
|
|
|
|
|
|
|
|
|
|
if (tempCrc == checkModebusCrc(gw485RxBuffer, frameLength - 3)) {
|
|
|
|
|
state = crcCheckBitGW;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gw485RxBufferIndex < CfgLengthGWMaxLen) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
#define ReadCfgLengthGWMaxLen (frameLength - 1)
|
|
|
|
|
uint8_t analysisReadCfgLengthGW(void)
|
|
|
|
|
{
|
|
|
|
|
/* crcУ<63><D0A3> */
|
|
|
|
|
if (gw485RxBufferIndex >= ReadCfgLengthGWMaxLen) {
|
|
|
|
|
uint16_t tempCrc = 0;
|
|
|
|
|
tempCrc = (gw485RxBuffer[frameLength - 3] << 8) | gw485RxBuffer[frameLength - 2];
|
|
|
|
|
|
|
|
|
|
if (tempCrc == checkModebusCrc(gw485RxBuffer, frameLength - 3)) {
|
|
|
|
|
state = crcCheckBitGW;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gw485RxBufferIndex < ReadCfgLengthGWMaxLen) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ startFlagSL
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
uint8_t analysisStartFlagSL(void)
|
|
|
|
|
{
|
|
|
|
|
/* У<><D0A3><EFBFBD>˿ں<CBBF> */
|
|
|
|
|
if (gw485RxBuffer[2] < 10 && gw485RxBuffer[2] >= 0) {
|
|
|
|
|
// log_info("portSL\n");
|
|
|
|
|
state = portSL;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// log_error("portSL %d \n", gw485RxBuffer[2]);
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ portSL
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
#define PortSLMaxLen 5
|
|
|
|
|
uint8_t analysisPortSL(void)
|
|
|
|
|
{
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0>Ķ<EFBFBD> */
|
|
|
|
|
if (gw485RxBufferIndex >= PortSLMaxLen) {
|
|
|
|
|
uint32_t tempLen = 0;
|
|
|
|
|
tempLen = (gw485RxBuffer[3] << 8) | gw485RxBuffer[4];
|
|
|
|
|
|
|
|
|
|
if (tempLen > 0 && tempLen <= 1024) {
|
|
|
|
|
// log_info("lengthSL\n");
|
|
|
|
|
state = lengthSL;
|
|
|
|
|
frameLength = 6 + tempLen;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gw485RxBufferIndex < PortSLMaxLen) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// log_error("lengthSL %d \n", (gw485RxBuffer[3] << 8) | gw485RxBuffer[4]);
|
|
|
|
|
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ lengthSL
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
#define LengthSLMaxLen frameLength
|
|
|
|
|
uint8_t analysisLengthSL(void)
|
|
|
|
|
{
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>֡β */
|
|
|
|
|
if (gw485RxBufferIndex >= LengthSLMaxLen) {
|
|
|
|
|
if (gw485RxBuffer[LengthSLMaxLen - 1] == 0x17) {
|
|
|
|
|
// log_info("endFlagSL\n");
|
|
|
|
|
state = endFlagSL;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gw485RxBufferIndex < LengthSLMaxLen) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
// log_info("endFlagSL %d\n", gw485RxBuffer[LengthSLMaxLen - 1]);
|
|
|
|
|
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex--;
|
|
|
|
|
memcpy(gw485RxBuffer, gw485RxBuffer + 1, gw485RxBufferIndex);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬ endFlagSL
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 0:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|
|
|
|
1:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
uint8_t analysisEndFlagSL(void)
|
|
|
|
|
{
|
|
|
|
|
uint32_t tempLen = 0;
|
|
|
|
|
tempLen = (gw485RxBuffer[3] << 8) | gw485RxBuffer[4];
|
|
|
|
|
|
2025-03-05 08:27:39 +00:00
|
|
|
|
//ϵͳ<CFB5>ڴ治<DAB4>㣬<EFBFBD><E3A3AC>ȥ<EFBFBD><C8A5>ǰ<EFBFBD><C7B0>
|
|
|
|
|
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-04 10:04:30 +00:00
|
|
|
|
/* <20><><EFBFBD>ڲ<EFBFBD>ͬͨ<CDAC>˿ڣ<CBBF><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľṹ<C4BD>岻ͬ */
|
|
|
|
|
uint8_t *Buff;
|
|
|
|
|
if (gw485RxBuffer[2] > 0 && gw485RxBuffer[2] < 5) {
|
|
|
|
|
Buff = (uint8_t *)pvPortMalloc(tempLen + queueUartSendInfoSize);
|
|
|
|
|
queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
|
|
|
|
|
sendBuff->length = tempLen + 1;
|
|
|
|
|
sendBuff->data = Buff + queueUartSendInfoSize;
|
|
|
|
|
strlcpy((char *)sendBuff->data, (char *)&gw485RxBuffer[5], tempLen + 1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Buff = (uint8_t *)pvPortMalloc(tempLen + queueTimeShareSendInfoSize);
|
|
|
|
|
queueTimeShareSendInfo *sendBuff = (queueTimeShareSendInfo *)Buff;
|
|
|
|
|
sendBuff->length = tempLen + 1;
|
|
|
|
|
sendBuff->data = Buff + queueTimeShareSendInfoSize;
|
|
|
|
|
strlcpy((char *)sendBuff->data, (char *)&gw485RxBuffer[5], tempLen + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ͨ<><CDA8><EFBFBD><EFBFBD>ͬ<EFBFBD>Ķ˿ڽ<CBBF><DABD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7>͵<EFBFBD><CDB5><EFBFBD>ͬ<EFBFBD>ĵط<C4B5> */
|
|
|
|
|
if (gw485RxBuffer[2] == 1) {
|
|
|
|
|
if (uxQueueSpacesAvailable(J1_485_Queue)) {
|
|
|
|
|
xQueueSend(J1_485_Queue, &Buff, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (gw485RxBuffer[2] == 2) {
|
|
|
|
|
if (uxQueueSpacesAvailable(J2_485_Queue)) {
|
|
|
|
|
xQueueSend(J2_485_Queue, &Buff, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (gw485RxBuffer[2] == 3) {
|
|
|
|
|
if (uxQueueSpacesAvailable(J3_485_Queue)) {
|
|
|
|
|
xQueueSend(J3_485_Queue, &Buff, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (gw485RxBuffer[2] == 4) {
|
|
|
|
|
if (uxQueueSpacesAvailable(J4_485_Queue)) {
|
|
|
|
|
xQueueSend(J4_485_Queue, &Buff, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (gw485RxBuffer[2] == 5) {
|
|
|
|
|
queueTimeShareSendInfo *sendBuff = (queueTimeShareSendInfo *)Buff;
|
|
|
|
|
sendBuff->connectPort = connectJ5;
|
|
|
|
|
if (uxQueueSpacesAvailable(J5_0_485_Queue)) {
|
|
|
|
|
xQueueSend(J5_0_485_Queue, &Buff, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (gw485RxBuffer[2] == 6) {
|
|
|
|
|
queueTimeShareSendInfo *sendBuff = (queueTimeShareSendInfo *)Buff;
|
|
|
|
|
sendBuff->connectPort = connectJ6;
|
|
|
|
|
if (uxQueueSpacesAvailable(J5_0_485_Queue)) {
|
|
|
|
|
xQueueSend(J5_0_485_Queue, &Buff, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (gw485RxBuffer[2] == 7) {
|
|
|
|
|
queueTimeShareSendInfo *sendBuff = (queueTimeShareSendInfo *)Buff;
|
|
|
|
|
sendBuff->connectPort = connectJ7;
|
|
|
|
|
if (uxQueueSpacesAvailable(J5_0_485_Queue)) {
|
|
|
|
|
xQueueSend(J5_0_485_Queue, &Buff, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (gw485RxBuffer[2] == 8) {
|
|
|
|
|
queueTimeShareSendInfo *sendBuff = (queueTimeShareSendInfo *)Buff;
|
|
|
|
|
sendBuff->connectPort = connectJ8;
|
|
|
|
|
if (uxQueueSpacesAvailable(J5_0_485_Queue)) {
|
|
|
|
|
xQueueSend(J5_0_485_Queue, &Buff, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (gw485RxBuffer[2] == 9) {
|
|
|
|
|
queueTimeShareSendInfo *sendBuff = (queueTimeShareSendInfo *)Buff;
|
|
|
|
|
sendBuff->connectPort = connectJ9;
|
|
|
|
|
if (uxQueueSpacesAvailable(J5_0_485_Queue)) {
|
|
|
|
|
xQueueSend(J5_0_485_Queue, &Buff, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (gw485RxBuffer[2] == 0) {
|
|
|
|
|
queueTimeShareSendInfo *sendBuff = (queueTimeShareSendInfo *)Buff;
|
|
|
|
|
sendBuff->connectPort = connectJ0;
|
|
|
|
|
if (uxQueueSpacesAvailable(J5_0_485_Queue)) {
|
|
|
|
|
xQueueSend(J5_0_485_Queue, &Buff, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-05 08:27:39 +00:00
|
|
|
|
err:
|
2025-03-04 10:04:30 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>buff
|
|
|
|
|
state = wait;
|
|
|
|
|
gw485RxBufferIndex = 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void GW_MsgProcFunc_Read_Register(device_handle device,uint8_t *buff, uint16_t buffLen)
|
|
|
|
|
{
|
|
|
|
|
uint16_t Start_Address_16 = (gw485RxBuffer[3] << 8) | gw485RxBuffer[4];
|
|
|
|
|
uint16_t Register_Number_16 = (gw485RxBuffer[5] << 8) | gw485RxBuffer[6];
|
|
|
|
|
|
|
|
|
|
/* <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> */
|
|
|
|
|
uint16_t reply_Data_Content[maxReadResAddrLen] = {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)) {
|
|
|
|
|
reply_Data_Content[pos] = g_RegTblR[var].pRegProc(NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD> */
|
2025-03-05 08:27:39 +00:00
|
|
|
|
//ϵͳ<CFB5>ڴ治<DAB4>㣬<EFBFBD><E3A3AC>ȥ<EFBFBD><C8A5>ǰ<EFBFBD><C7B0>
|
|
|
|
|
uint32_t tempLen = 8 + 2 * Register_Number_16 + queueUartSendInfoSize;
|
|
|
|
|
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
2025-03-04 10:04:30 +00:00
|
|
|
|
queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
|
|
|
|
|
sendBuff->length = 8 + 2 * Register_Number_16;
|
|
|
|
|
sendBuff->data = Buff + sizeof(queueUartSendInfo);
|
|
|
|
|
|
|
|
|
|
uint8_t *replay_pack = sendBuff->data;
|
|
|
|
|
/* <20><>ʼ<EFBFBD><CABC>־ */
|
|
|
|
|
*(replay_pack) = 'G';
|
|
|
|
|
*(replay_pack + 1) = 'W';
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
replay_pack += 2;
|
|
|
|
|
*replay_pack = SL_Function_Code_Read_Register;
|
|
|
|
|
|
|
|
|
|
/* <20>ظ<EFBFBD><D8B8>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
replay_pack += 1;
|
|
|
|
|
*replay_pack = (uint8_t)((Register_Number_16 * 2) >> 8);
|
|
|
|
|
*(replay_pack + 1) = (uint8_t)(Register_Number_16 * 2);
|
|
|
|
|
|
|
|
|
|
/* <20>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
replay_pack += 2;
|
|
|
|
|
for (uint8_t var = 0; var < Register_Number_16 * 2; var++) {
|
|
|
|
|
if (0 == (var & 0x01)) {
|
|
|
|
|
*(replay_pack + var) = (uint8_t)(reply_Data_Content[var / 2] >> 8);
|
|
|
|
|
} else {
|
|
|
|
|
*(replay_pack + var) = (uint8_t)(reply_Data_Content[var / 2]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* У<><D0A3>λ */
|
|
|
|
|
replay_pack += Register_Number_16 * 2;
|
|
|
|
|
uint16_t packLen = 2 + 1 + 2 + Register_Number_16 * 2 + 3;
|
|
|
|
|
uint16_t crc_temp = checkModebusCrc(sendBuff->data, packLen - 3);
|
|
|
|
|
*replay_pack = (uint8_t)(crc_temp >> 8);
|
|
|
|
|
replay_pack += 1;
|
|
|
|
|
*replay_pack = (uint8_t)crc_temp;
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ */
|
|
|
|
|
replay_pack += 1;
|
|
|
|
|
*replay_pack = 0x16;
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>пռ䣬<D5BC><EFBFBD><F2BDABB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
if (uxQueueSpacesAvailable(upward_uart_Queue)) {
|
|
|
|
|
xQueueSend(upward_uart_Queue, &Buff, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief д<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void GW_MsgProcFunc_Write_Register(device_handle device, void *pMsg, uint32_t MsgLen)
|
|
|
|
|
{
|
|
|
|
|
uint16_t Register_Start_Address = (gw485RxBuffer[3] << 8) | gw485RxBuffer[4];
|
|
|
|
|
uint16_t Register_Number = (gw485RxBuffer[5] << 8) | gw485RxBuffer[6];
|
|
|
|
|
|
|
|
|
|
/* <20><>ָ<EFBFBD><D6B8><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD>ݶ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> */
|
|
|
|
|
uint16_t content[maxWriteResAddrLen] = {0};
|
|
|
|
|
for (uint16_t var = 0; var < Register_Number; var++) {
|
|
|
|
|
content[var] = gw485RxBuffer[14 + 2 * var] << 8 | gw485RxBuffer[14 + 2 * var + 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>뵽<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
for ( uint16_t pos = 0; pos < Register_Number; pos++) {
|
|
|
|
|
for (uint16_t i = 0; i < sizeof(g_RegTblW) / sizeof(SL_RegProcTable); i++) {
|
|
|
|
|
// debug_printf("g_RegTblW[i].regId : %x \n", g_RegTblW[i].regId);
|
|
|
|
|
// debug_printf("Register_Start_Address : %x \n", (Register_Start_Address + pos));
|
|
|
|
|
if (g_RegTblW[i].regId == (Register_Start_Address + pos)) {
|
|
|
|
|
g_RegTblW[i].pRegProc(&content[pos]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void GW_MsgProcFunc_Distribution_Profile(device_handle device, void *pMsg, uint32_t MsgLen)
|
|
|
|
|
{
|
|
|
|
|
log_info("in GW_MsgProcFunc_Distribution_Profile\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void GW_MsgProcFunc_Read_Profile(device_handle device, void *pMsg, uint32_t MsgLen)
|
|
|
|
|
{
|
|
|
|
|
log_info("in GW_MsgProcFunc_Read_Profile\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void stateMachine(device_handle device)
|
|
|
|
|
{
|
|
|
|
|
if (state == wait) {
|
|
|
|
|
if (analysisWait() == TRUE) {
|
|
|
|
|
gw485RxTime = xTaskGetTickCount();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == startFlagGW) {
|
|
|
|
|
analysisStartFlagGW();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == functionCodeGW) {
|
|
|
|
|
analysisFunctionCodeGW();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == readRegStartAddressGW) {
|
|
|
|
|
analysisReadRegStartAddressGW();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == readRegStartNumberGW) {
|
|
|
|
|
analysisReadRegStartNumberGW();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == crcCheckBitGW) {
|
|
|
|
|
analysisCrcCheckBitGW();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == endFlagGW) {
|
|
|
|
|
analysisEndFlagGW(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == writeRegStartAddressGW) {
|
|
|
|
|
analysisWriteRegStartAddressGW();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == writeRegStartNumberGW) {
|
|
|
|
|
analysisWriteRegStartNumberGW();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == cfgFramesNumGW) {
|
|
|
|
|
analysisCfgFramesNumGW();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == cfgLengthGW) {
|
|
|
|
|
analysisCfgLengthGW();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == readCfgLengthGW) {
|
|
|
|
|
analysisReadCfgLengthGW();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == startFlagSL) {
|
|
|
|
|
analysisStartFlagSL();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == portSL) {
|
|
|
|
|
analysisPortSL();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == lengthSL) {
|
|
|
|
|
analysisLengthSL();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (state == endFlagSL) {
|
|
|
|
|
analysisEndFlagSL();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief modbus<EFBFBD><EFBFBD>crcУ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param *arr_buff <EFBFBD><EFBFBD>ҪУ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* len <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @retval crc У<EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
uint16_t checkModebusCrc(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 <EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ĵIJ<EFBFBD>ֵ
|
|
|
|
|
* @param lastTick <EFBFBD>ϴλ<EFBFBD>ȡ<EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint32_t getTickDiff(uint32_t lastTick)
|
|
|
|
|
{
|
|
|
|
|
int64_t temp;
|
|
|
|
|
temp = xTaskGetTickCount() - lastTick;
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD> */
|
|
|
|
|
if (temp < 0) {
|
|
|
|
|
temp = portMAX_DELAY - lastTick + xTaskGetTickCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>鷢<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param device <EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>鷢<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void upwardUartDataAnalysis(device_handle device)
|
|
|
|
|
{
|
|
|
|
|
/* ÿ<>κ<EFBFBD><CEBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>10ms */
|
|
|
|
|
static uint32_t tickstart = 0U;
|
|
|
|
|
tickstart = xTaskGetTickCount();
|
|
|
|
|
|
|
|
|
|
/* 2Sδ<53><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡<D2BB><D6A1><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
if (getTickDiff(gw485RxTime) >= tick_2S) {
|
|
|
|
|
gw485RxTime = xTaskGetTickCount();
|
|
|
|
|
gw485RxBufferIndex = 0;
|
|
|
|
|
state = wait;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (uart_dev_char_present(device) == 1 && ((xTaskGetTickCount() - tickstart) < 5)) {
|
|
|
|
|
gw485RxBuffer[gw485RxBufferIndex++] = uart_dev_in_char(device);
|
|
|
|
|
stateMachine(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (uart_dev_char_present(device) != 1 && state != wait) {
|
|
|
|
|
stateMachine(device);
|
|
|
|
|
}
|
|
|
|
|
}
|