Initial commit: my SECS2 project
This commit is contained in:
745
usr/protocol/proto_Para_Modbus.c
Normal file
745
usr/protocol/proto_Para_Modbus.c
Normal file
@@ -0,0 +1,745 @@
|
||||
#include "proto_Para_Modbus.h"
|
||||
#include "string.h"
|
||||
#include "bsp_Uart.h"
|
||||
#include "os_timer.h"
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "bsp_W5500.h"
|
||||
#include "proto_HSMS.h"
|
||||
#include "bsp_Flash.h"
|
||||
#include "bsp_Wdg.h"
|
||||
|
||||
|
||||
static ModbusAnalysisData_t ModbusAnalysisData;//ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||||
static ModbusCommunicationSendBuf_t SendStruct;//<2F><><EFBFBD>ͽṹ<CDBD><E1B9B9>
|
||||
|
||||
static void ModbusCommunicationDataReceive(u8 *pData, u16 len,void *other_data);
|
||||
static void ModbusCommunicationDataSend(u8 *pData, u16 len);
|
||||
static void proto_Modbus_Init(void);
|
||||
static void proto_Modbus_Task(void);
|
||||
static ModbusErrorCode_e ModbusCommunicationDataWrite(u16 Addr, u16 Value);
|
||||
static u16 ModbusCommunicationDataRead(u16 Addr);
|
||||
|
||||
proto_Modbus_t Para_Modbus=
|
||||
{
|
||||
.ID = 0x01,
|
||||
.DataRead = ModbusCommunicationDataRead,
|
||||
.DataWrite = ModbusCommunicationDataWrite,
|
||||
.DataAnalysis = ModbusCommunicationDataReceive,
|
||||
.Init = proto_Modbus_Init,
|
||||
.Task = proto_Modbus_Task,
|
||||
};
|
||||
|
||||
static proto_Modbus_t *pModbus = &Para_Modbus;
|
||||
static bsp_Uart_t *rx_uart = NULL;
|
||||
|
||||
static void ModbusCommunicationDataSend(u8 *pData, u16 Len)
|
||||
{
|
||||
if(&COM_Uart1 == rx_uart)
|
||||
{
|
||||
COM_Uart1.Send(&COM_Uart1,pData,Len);
|
||||
}
|
||||
else if(&COM_Uart2 == rx_uart)
|
||||
{
|
||||
COM_Uart2.Send(&COM_Uart2,pData,Len);
|
||||
}
|
||||
}
|
||||
|
||||
static void proto_Modbus_Init(void)
|
||||
{
|
||||
COM_Uart1.Rx_DataAnalysis = ModbusCommunicationDataReceive;
|
||||
COM_Uart2.Rx_DataAnalysis = ModbusCommunicationDataReceive;
|
||||
}
|
||||
static void proto_Modbus_Task(void)
|
||||
{
|
||||
|
||||
}
|
||||
static void ModbusCommunicationDataReceive(u8 *pData, u16 len,void *other_data)
|
||||
{
|
||||
ModbusErrorCode_e ErrorCode;
|
||||
u8 inx;
|
||||
u16 TempAddr, TempData, Crc16;
|
||||
|
||||
if (0 == ModbusAnalysis(&ModbusAnalysisData, pData, len))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> У<><D0A3><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ
|
||||
return;
|
||||
if (pModbus->ID != ModbusAnalysisData.ID)//<2F>ж<EFBFBD>ID<49>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ
|
||||
return;
|
||||
|
||||
ErrorCode = ModbusErrorCode_Success;
|
||||
rx_uart = (bsp_Uart_t *)other_data;
|
||||
|
||||
/* //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>Ƿ<C7B7><F1B3ACB3><EFBFBD>Χ
|
||||
if ((ModbusAnalysisData.StartAddress >= MODBUS_REG_LEN) || (ModbusAnalysisData.RegNumber >= MODBUS_REG_LEN) ||
|
||||
(ModbusAnalysisData.StartAddress + ModbusAnalysisData.RegNumber >= MODBUS_REG_LEN))
|
||||
{
|
||||
ErrorCode = ModbusErrorCode_IllegalAddr;
|
||||
goto Error;
|
||||
}
|
||||
*/
|
||||
|
||||
switch (ModbusAnalysisData.Func)
|
||||
{
|
||||
case 0x03:
|
||||
case 0x04:
|
||||
{
|
||||
TempAddr = ModbusAnalysisData.StartAddress;
|
||||
SendStruct.SendBuffer[0] = ModbusAnalysisData.ID;
|
||||
SendStruct.SendBuffer[1] = ModbusAnalysisData.Func;
|
||||
SendStruct.SendBuffer[2] = 2 * ModbusAnalysisData.RegNumber;
|
||||
for (inx = 0; inx < ModbusAnalysisData.RegNumber; inx++)
|
||||
{
|
||||
TempData = ModbusCommunicationDataRead(TempAddr);
|
||||
SendStruct.SendBuffer[3 + 2 * inx] = (TempData >> 8) & 0xff;
|
||||
SendStruct.SendBuffer[4 + 2 * inx] = TempData & 0xff;
|
||||
TempAddr++;
|
||||
}
|
||||
Crc16 = ModbusCrc16(SendStruct.SendBuffer, 3 + SendStruct.SendBuffer[2]);
|
||||
SendStruct.SendBuffer[3 + SendStruct.SendBuffer[2]] = Crc16 & 0xff;
|
||||
SendStruct.SendBuffer[4 + SendStruct.SendBuffer[2]] = (Crc16 >> 8) & 0xff;
|
||||
SendStruct.Len = 5 + SendStruct.SendBuffer[2];
|
||||
}goto Success;
|
||||
/*<2A><><EFBFBD><EFBFBD>Э<EFBFBD><D0AD>*/
|
||||
case 0x41:
|
||||
{
|
||||
TempAddr = ModbusAnalysisData.StartAddress;
|
||||
SendStruct.SendBuffer[0] = ModbusAnalysisData.ID;
|
||||
SendStruct.SendBuffer[1] = ModbusAnalysisData.Func;
|
||||
SendStruct.SendBuffer[2] = ModbusAnalysisData.StartAddress >> 8;
|
||||
SendStruct.SendBuffer[3] = ModbusAnalysisData.StartAddress & 0xff;
|
||||
SendStruct.SendBuffer[4] = (2 * ModbusAnalysisData.RegNumber) >> 8;
|
||||
SendStruct.SendBuffer[5] = (2 * ModbusAnalysisData.RegNumber) & 0xff;
|
||||
for (inx = 0; inx < ModbusAnalysisData.RegNumber; inx++)
|
||||
{
|
||||
TempData = ModbusCommunicationDataRead(TempAddr);
|
||||
SendStruct.SendBuffer[6 + 2 * inx] = (TempData >> 8) & 0xff;
|
||||
SendStruct.SendBuffer[7 + 2 * inx] = TempData & 0xff;
|
||||
TempAddr++;
|
||||
}
|
||||
Crc16 = ModbusCrc16(SendStruct.SendBuffer, 6 + 2 * ModbusAnalysisData.RegNumber);
|
||||
SendStruct.SendBuffer[6 + 2 * ModbusAnalysisData.RegNumber] = Crc16 & 0xff;
|
||||
SendStruct.SendBuffer[7 + 2 * ModbusAnalysisData.RegNumber] = (Crc16 >> 8) & 0xff;
|
||||
SendStruct.Len = 8 + 2 * ModbusAnalysisData.RegNumber;
|
||||
}goto Success;
|
||||
|
||||
case 0x06:
|
||||
{
|
||||
TempAddr = ModbusAnalysisData.StartAddress;
|
||||
TempData = (ModbusAnalysisData.wDataAddress[0] << 8) | ModbusAnalysisData.wDataAddress[1];
|
||||
ErrorCode = ModbusCommunicationDataWrite(TempAddr, TempData);
|
||||
if (ErrorCode)
|
||||
{
|
||||
goto Error;
|
||||
}
|
||||
|
||||
SendStruct.Len = 8;
|
||||
SendStruct.SendBuffer[0] = ModbusAnalysisData.ID;
|
||||
SendStruct.SendBuffer[1] = ModbusAnalysisData.Func;
|
||||
SendStruct.SendBuffer[2] = ModbusAnalysisData.StartAddress >> 8;
|
||||
SendStruct.SendBuffer[3] = ModbusAnalysisData.StartAddress & 0xff;
|
||||
SendStruct.SendBuffer[4] = ModbusAnalysisData.wDataAddress[0];
|
||||
SendStruct.SendBuffer[5] = ModbusAnalysisData.wDataAddress[1];
|
||||
Crc16 = ModbusCrc16(SendStruct.SendBuffer, 6);
|
||||
SendStruct.SendBuffer[6] = Crc16 & 0xff;
|
||||
SendStruct.SendBuffer[7] = (Crc16 >> 8) & 0xff;
|
||||
}break;
|
||||
|
||||
case 0x10:
|
||||
{
|
||||
TempAddr = ModbusAnalysisData.StartAddress;
|
||||
for (inx = 0; inx < ModbusAnalysisData.RegNumber; inx++)
|
||||
{
|
||||
TempData = ModbusAnalysisData.wDataAddress[2 * inx];
|
||||
TempData = (TempData << 8) | ModbusAnalysisData.wDataAddress[2 * inx + 1];
|
||||
ErrorCode = ModbusCommunicationDataWrite(TempAddr, TempData);
|
||||
TempAddr++;
|
||||
if (ErrorCode)
|
||||
{
|
||||
goto Error;
|
||||
}
|
||||
}
|
||||
SendStruct.Len = 8;
|
||||
SendStruct.SendBuffer[0] = ModbusAnalysisData.ID;
|
||||
SendStruct.SendBuffer[1] = ModbusAnalysisData.Func;
|
||||
SendStruct.SendBuffer[2] = ModbusAnalysisData.StartAddress >> 8;
|
||||
SendStruct.SendBuffer[3] = ModbusAnalysisData.StartAddress & 0xff;
|
||||
SendStruct.SendBuffer[4] = ModbusAnalysisData.RegNumber >> 8;
|
||||
SendStruct.SendBuffer[5] = ModbusAnalysisData.RegNumber & 0xff;
|
||||
Crc16 = ModbusCrc16(SendStruct.SendBuffer, 6);
|
||||
SendStruct.SendBuffer[6] = Crc16 & 0xff;
|
||||
SendStruct.SendBuffer[7] = (Crc16 >> 8) & 0xff;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
ErrorCode = ModbusErrorCode_IllegalFunction;
|
||||
}
|
||||
goto Error;
|
||||
}
|
||||
|
||||
Success:
|
||||
ModbusCommunicationDataSend(SendStruct.SendBuffer, SendStruct.Len);
|
||||
return;
|
||||
|
||||
Error:
|
||||
SendStruct.Len = 5;
|
||||
SendStruct.SendBuffer[0] = ModbusAnalysisData.ID;
|
||||
SendStruct.SendBuffer[1] = ModbusAnalysisData.Func | 0x80;
|
||||
SendStruct.SendBuffer[2] = ErrorCode;
|
||||
Crc16 = ModbusCrc16(SendStruct.SendBuffer, 3);
|
||||
SendStruct.SendBuffer[3] = Crc16 & 0xff;
|
||||
SendStruct.SendBuffer[4] = (Crc16 >> 8) & 0xff;
|
||||
ModbusCommunicationDataSend(SendStruct.SendBuffer, SendStruct.Len);
|
||||
}
|
||||
|
||||
/*modbus<75><73><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>u16ת<36><D7AA>Ϊascii<69><69>u16 ʵ<><CAB5>Ϊ<EFBFBD>Ե<EFBFBD><D4B5>ߵ<EFBFBD><DFB5>ֽ<EFBFBD>*/
|
||||
static u16 modbus_u16_to_ascii_u16(u16 modbus_u16)
|
||||
{
|
||||
return (modbus_u16 << 8) | (modbus_u16 >> 8);
|
||||
}
|
||||
|
||||
/*ascii<69><69>u16 ת<><D7AA>Ϊmodbus u16<31><36><EFBFBD><EFBFBD> ʵ<><CAB5>Ϊ<EFBFBD>Ե<EFBFBD><D4B5>ߵ<EFBFBD><DFB5>ֽ<EFBFBD>*/
|
||||
static u16 ascii_u16_to_modbus_u16(u16 modbus_u16)
|
||||
{
|
||||
return (modbus_u16 << 8) | (modbus_u16 >> 8);
|
||||
}
|
||||
|
||||
/******************************************
|
||||
* <20><><EFBFBD><EFBFBD>: ModbusCommunicationDataWrite
|
||||
* <20><><EFBFBD><EFBFBD>: Modbusд<73>Ĵ<EFBFBD><C4B4><EFBFBD>
|
||||
* <20><><EFBFBD><EFBFBD>: Addr: <20><>ַ
|
||||
Value:<3A><><EFBFBD><EFBFBD>
|
||||
* <20><><EFBFBD><EFBFBD>: <20><>
|
||||
* <20><><EFBFBD><EFBFBD>: <20><>
|
||||
******************************************/
|
||||
static ModbusErrorCode_e ModbusCommunicationDataWrite(u16 Addr, u16 Value)
|
||||
{
|
||||
ModbusErrorCode_e ErrorCode;
|
||||
ErrorCode = ModbusErrorCode_Success;
|
||||
|
||||
switch(Addr)
|
||||
{
|
||||
/*SN*/
|
||||
case 12 ... 16:
|
||||
{
|
||||
Usr_Flash.FlashData.SN[Addr - 12] = Value;
|
||||
Usr_Flash.Write();
|
||||
}break;
|
||||
/*IP<49><50>ַ*/
|
||||
case 17 ... 20:
|
||||
{
|
||||
W5500.IP_Addr[Addr - 17] = Value;
|
||||
Usr_Flash.FlashData.IP_Addr[Addr - 17] = Value;
|
||||
}break;
|
||||
/*<2A>˿ں<CBBF>*/
|
||||
case 21:
|
||||
{
|
||||
W5500.W5500_Class[0].ConfigData.Port[0] = Value >> 8;
|
||||
W5500.W5500_Class[0].ConfigData.Port[1] = Value & 0x00ff;
|
||||
Usr_Flash.FlashData.Port[0] = Value >> 8;
|
||||
Usr_Flash.FlashData.Port[1] = Value & 0x00ff;
|
||||
}break;
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
case 22 ... 25:
|
||||
{
|
||||
W5500.Sub_Mask[Addr - 22] = Value;
|
||||
Usr_Flash.FlashData.Sub_Mask[Addr - 22] = Value;
|
||||
}break;
|
||||
case 26:
|
||||
{
|
||||
HSMS.Flash_ConfigData.Device_Id = Value;
|
||||
Usr_Flash.FlashData.Devic_Id = Value;
|
||||
Wdg.Feed();
|
||||
W5500.Init();
|
||||
Wdg.Feed();
|
||||
Usr_Flash.Write();
|
||||
}break;
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
case 27 ... 30:
|
||||
{
|
||||
W5500.Gateway_IP[Addr - 27] = Value;
|
||||
Usr_Flash.FlashData.Gateway_IP[Addr - 27] = Value;
|
||||
W5500.Init();
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* <20>豸 SN */
|
||||
case 100 ... 107:
|
||||
{
|
||||
Usr_Flash.FlashData.Device_SN[Addr - 100] = modbus_u16_to_ascii_u16(Value);
|
||||
} break;
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨<EFBFBD><CCA8>λ<EFBFBD><CEBB> */
|
||||
case 108 ... 115:
|
||||
{
|
||||
Usr_Flash.FlashData.Device_Model[Addr - 108] = modbus_u16_to_ascii_u16(Value);
|
||||
} break;
|
||||
|
||||
/* <20>豸<EFBFBD>ͺ<EFBFBD> */
|
||||
case 116 ... 123:
|
||||
{
|
||||
Usr_Flash.FlashData.Device_ID[Addr - 116] = modbus_u16_to_ascii_u16(Value);
|
||||
} break;
|
||||
|
||||
/* <20><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD><E6B1BE> */
|
||||
case 124 ... 131:
|
||||
{
|
||||
Usr_Flash.FlashData.Version[Addr - 124] = modbus_u16_to_ascii_u16(Value);
|
||||
} break;
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
case 132 ... 139:
|
||||
{
|
||||
Usr_Flash.FlashData.Manufacturer[Addr - 132] = modbus_u16_to_ascii_u16(Value);
|
||||
} break;
|
||||
|
||||
/* <20><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD> */
|
||||
case 140 ... 147:
|
||||
{
|
||||
Usr_Flash.FlashData.Station_Name[Addr - 140] = modbus_u16_to_ascii_u16(Value);
|
||||
} break;
|
||||
|
||||
/* ǻ<><C7BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
case 148 ... 155:
|
||||
{
|
||||
Usr_Flash.FlashData.Chamber_Name[Addr - 148] = modbus_u16_to_ascii_u16(Value);
|
||||
} break;
|
||||
|
||||
/* <20><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD> */
|
||||
case 156 ... 163:
|
||||
{
|
||||
Usr_Flash.FlashData.Station_Type[Addr - 156] = modbus_u16_to_ascii_u16(Value);
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm_info */
|
||||
case 164 ... 183:
|
||||
{
|
||||
Usr_Flash.FlashData.Alarm_info[Addr - 164] = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Data_ID1 */
|
||||
case 184:
|
||||
{
|
||||
Usr_Flash.FlashData.Data_ID1 = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Collection_event_ID1 */
|
||||
case 185:
|
||||
{
|
||||
Usr_Flash.FlashData.Collection_event_ID1 = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Report_ID1 */
|
||||
case 186:
|
||||
{
|
||||
Usr_Flash.FlashData.Report_ID1 = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm_ID */
|
||||
case 187:
|
||||
{
|
||||
Usr_Flash.FlashData.Alarm_ID = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm_Type */
|
||||
case 188 ... 194:
|
||||
{
|
||||
Usr_Flash.FlashData.Alarm_Type[Addr - 188] = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Begin_Warning */
|
||||
case 195 ... 201:
|
||||
{
|
||||
Usr_Flash.FlashData.Begin_Warning[Addr - 195] = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> IDS */
|
||||
case 202 ... 212:
|
||||
{
|
||||
Usr_Flash.FlashData.IDS[Addr - 202] = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Over_Trigger */
|
||||
case 213 ... 221:
|
||||
{
|
||||
Usr_Flash.FlashData.Over_Trigger[Addr - 213] = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Equipment */
|
||||
case 222 ... 226:
|
||||
{
|
||||
Usr_Flash.FlashData.Equipment[Addr - 222] = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> E9 */
|
||||
case 227 ... 245:
|
||||
{
|
||||
Usr_Flash.FlashData.E9[Addr - 227] = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Device_Type */
|
||||
case 246:
|
||||
{
|
||||
Usr_Flash.FlashData.Device_Type = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Sensor */
|
||||
case 247:
|
||||
{
|
||||
Usr_Flash.FlashData.Sensor = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm_value */
|
||||
case 248:
|
||||
{
|
||||
Usr_Flash.FlashData.Alarm_value = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm_ubit */
|
||||
case 249:
|
||||
{
|
||||
Usr_Flash.FlashData.Alarm_ubit = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Start_Time */
|
||||
case 250 ... 260:
|
||||
{
|
||||
Usr_Flash.FlashData.Start_Time[Addr - 250] = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm_Time */
|
||||
case 261 ... 266:
|
||||
{
|
||||
Usr_Flash.FlashData.Alarm_Time[Addr - 261] = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm */
|
||||
case 267 ... 272:
|
||||
{
|
||||
Usr_Flash.FlashData.Alarm[Addr - 267] = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Data_ID2 */
|
||||
case 273:
|
||||
{
|
||||
Usr_Flash.FlashData.Data_ID2 = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Collection_event_ID2 */
|
||||
case 274:
|
||||
{
|
||||
Usr_Flash.FlashData.Collection_event_ID2 = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Report_ID2 */
|
||||
case 275:
|
||||
{
|
||||
Usr_Flash.FlashData.Report_ID2 = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Sub_Device_Type */
|
||||
case 276 ... 277:
|
||||
{
|
||||
Usr_Flash.FlashData.Sub_Device_Type[Addr - 276] = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Sub_Device_State */
|
||||
case 278 ... 279:
|
||||
{
|
||||
Usr_Flash.FlashData.Sub_Device_State[Addr - 278] = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> State_Change_Time */
|
||||
case 280 ... 281:
|
||||
{
|
||||
Usr_Flash.FlashData.State_Change_Time[Addr - 280] = Value;
|
||||
Usr_Flash.Write();
|
||||
} break;
|
||||
}
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
/******************************************
|
||||
* <20><><EFBFBD><EFBFBD>: ModbusCommunicationDataRead
|
||||
* <20><><EFBFBD><EFBFBD>: Modbus<75><73><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <20><><EFBFBD><EFBFBD>: Addr: <20><>ַ
|
||||
* <20><><EFBFBD><EFBFBD>: <20><>ַ<EFBFBD><D6B7>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <20><><EFBFBD><EFBFBD>: <20><>
|
||||
******************************************/
|
||||
static u16 ModbusCommunicationDataRead(u16 Addr)
|
||||
{
|
||||
u8 *p_u8Data;
|
||||
u16 Data;
|
||||
u16 *pData;
|
||||
|
||||
switch(Addr)
|
||||
{
|
||||
/*SV*/
|
||||
case 0 ... 11:
|
||||
{
|
||||
p_u8Data = &SwVersion[Addr * 2];
|
||||
Data = p_u8Data[1] | p_u8Data[0] << 8;
|
||||
}break;
|
||||
/*SN*/
|
||||
case 12 ... 16:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.SN[Addr - 12];
|
||||
}break;
|
||||
/*IP<49><50>ַ*/
|
||||
case 17 ... 20:
|
||||
{
|
||||
Data = W5500.IP_Addr[Addr - 17];
|
||||
}break;
|
||||
/*<2A>˿ں<CBBF>*/
|
||||
case 21:
|
||||
{
|
||||
Data = W5500.W5500_Class[0].ConfigData.Port[0] << 8 | W5500.W5500_Class[0].ConfigData.Port[1];
|
||||
}break;
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
case 22 ... 25:
|
||||
{
|
||||
Data = W5500.Sub_Mask[Addr - 22];
|
||||
}break;
|
||||
/*SECS2Э<32><D0AD><EFBFBD>豸ID*/
|
||||
case 26:
|
||||
{
|
||||
Data = HSMS.Flash_ConfigData.Device_Id;
|
||||
}break;
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>*/
|
||||
case 27 ... 30:
|
||||
{
|
||||
Data = W5500.Gateway_IP[Addr - 27];
|
||||
} break;
|
||||
|
||||
/* <20>豸 SN */
|
||||
case 100 ... 107:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Device_SN[Addr - 100];
|
||||
Data = ascii_u16_to_modbus_u16(Data);
|
||||
} break;
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨<EFBFBD><CCA8>λ<EFBFBD><CEBB> */
|
||||
case 108 ... 115:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Device_Model[Addr - 108];
|
||||
Data = ascii_u16_to_modbus_u16(Data);
|
||||
} break;
|
||||
|
||||
/* <20>豸<EFBFBD>ͺ<EFBFBD> */
|
||||
case 116 ... 123:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Device_ID[Addr - 116];
|
||||
Data = ascii_u16_to_modbus_u16(Data);
|
||||
} break;
|
||||
|
||||
/* <20><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD><E6B1BE> */
|
||||
case 124 ... 131:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Version[Addr - 124];
|
||||
Data = ascii_u16_to_modbus_u16(Data);
|
||||
} break;
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
case 132 ... 139:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Manufacturer[Addr - 132];
|
||||
Data = ascii_u16_to_modbus_u16(Data);
|
||||
} break;
|
||||
|
||||
/* <20><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD> */
|
||||
case 140 ... 147:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Station_Name[Addr - 140];
|
||||
Data = ascii_u16_to_modbus_u16(Data);
|
||||
} break;
|
||||
|
||||
/* ǻ<><C7BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
case 148 ... 155:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Chamber_Name[Addr - 148];
|
||||
Data = ascii_u16_to_modbus_u16(Data);
|
||||
} break;
|
||||
|
||||
/* <20><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD> */
|
||||
case 156 ... 163:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Station_Type[Addr - 156];
|
||||
Data = ascii_u16_to_modbus_u16(Data);
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm_info */
|
||||
case 164 ... 183:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Alarm_info[Addr - 164];
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Data_ID1 */
|
||||
case 184:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Data_ID1;
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Collection_event_ID1 */
|
||||
case 185:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Collection_event_ID1;
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Report_ID1 */
|
||||
case 186:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Report_ID1;
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm_ID */
|
||||
case 187:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Alarm_ID;
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm_Type */
|
||||
case 188 ... 194:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Alarm_Type[Addr - 188];
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Begin_Warning */
|
||||
case 195 ... 201:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Begin_Warning[Addr - 195];
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> IDS */
|
||||
case 202 ... 212:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.IDS[Addr - 202];
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Over_Trigger */
|
||||
case 213 ... 221:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Over_Trigger[Addr - 213];
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Equipment */
|
||||
case 222 ... 226:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Equipment[Addr - 222];
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> E9 */
|
||||
case 227 ... 245:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.E9[Addr - 227];
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Device_Type */
|
||||
case 246:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Device_Type;
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Sensor */
|
||||
case 247:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Sensor;
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm_value */
|
||||
case 248:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Alarm_value;
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm_ubit */
|
||||
case 249:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Alarm_ubit;
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Start_Time */
|
||||
case 250 ... 260:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Start_Time[Addr - 250];
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm_Time */
|
||||
case 261 ... 266:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Alarm_Time[Addr - 261];
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Alarm */
|
||||
case 267 ... 272:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Alarm[Addr - 267];
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Data_ID2 */
|
||||
case 273:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Data_ID2;
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Collection_event_ID2 */
|
||||
case 274:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Collection_event_ID2;
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Report_ID2 */
|
||||
case 275:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Report_ID2;
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Sub_Device_Type */
|
||||
case 276 ... 277:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Sub_Device_Type[Addr - 276];
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> Sub_Device_State */
|
||||
case 278 ... 279:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.Sub_Device_State[Addr - 278];
|
||||
} break;
|
||||
|
||||
/* Ԥ<><D4A4> State_Change_Time */
|
||||
case 280 ... 281:
|
||||
{
|
||||
Data = Usr_Flash.FlashData.State_Change_Time[Addr - 280];
|
||||
} break;
|
||||
|
||||
default:
|
||||
Data = 0;
|
||||
}
|
||||
return Data;
|
||||
}
|
||||
Reference in New Issue
Block a user