增加一些中英文切换和MODBUS
This commit is contained in:
parent
a6888da205
commit
5d3d57d9e0
|
|
@ -54,7 +54,7 @@ SemaphoreHandle_t Form_KeyQ = NULL;
|
||||||
|
|
||||||
// 首页表格,报警页表格,查询表格, 关于表格
|
// 首页表格,报警页表格,查询表格, 关于表格
|
||||||
form_grid_t gridAll, gridWarn, gridQuery, gridAbout,gridAboutEn;
|
form_grid_t gridAll, gridWarn, gridQuery, gridAbout,gridAboutEn;
|
||||||
|
form_grid2_t gridBox;
|
||||||
// 用于生成显示屏命令
|
// 用于生成显示屏命令
|
||||||
form_data_t formData;
|
form_data_t formData;
|
||||||
|
|
||||||
|
|
@ -132,7 +132,7 @@ void DWIN_ParseFrame(uint8_t c)
|
||||||
// 触摸按键返回
|
// 触摸按键返回
|
||||||
if(readData.Addr == 0x5000 || readData.Addr == 0x5012 || readData.Addr == 0x5030
|
if(readData.Addr == 0x5000 || readData.Addr == 0x5012 || readData.Addr == 0x5030
|
||||||
|| readData.Addr == 0x5022 || readData.Addr == 0x502C || readData.Addr == 0x502E
|
|| readData.Addr == 0x5022 || readData.Addr == 0x502C || readData.Addr == 0x502E
|
||||||
|| readData.Addr == 0x5032|| readData.Addr == 0x6F00)
|
|| readData.Addr == 0x5032|| readData.Addr == 0x5034|| readData.Addr == 0x5036|| readData.Addr == 0x6F00)
|
||||||
{
|
{
|
||||||
LoopBuff_PutItem(&Form_KeyM, (uint8_t *) &readData);
|
LoopBuff_PutItem(&Form_KeyM, (uint8_t *) &readData);
|
||||||
// 发消息给任务
|
// 发消息给任务
|
||||||
|
|
@ -339,7 +339,47 @@ void Form_RefreshGrid(form_grid_t *grid)
|
||||||
// 发送消息给任务
|
// 发送消息给任务
|
||||||
xSemaphoreGive(Form_DataQ);
|
xSemaphoreGive(Form_DataQ);
|
||||||
}
|
}
|
||||||
|
// 刷新表格
|
||||||
|
void Form_RefreshGrid2(form_grid2_t *grid)
|
||||||
|
{
|
||||||
|
int16_t i, len;
|
||||||
|
|
||||||
|
// 加锁
|
||||||
|
xSemaphoreTake(Form_DataLock, portMAX_DELAY);
|
||||||
|
|
||||||
|
// 先将数据写入备份缓冲
|
||||||
|
for(i = 0; i < grid->rowCount; i++)
|
||||||
|
{
|
||||||
|
formData.oper = DWIN_OPER_WRITE;
|
||||||
|
formData.Addr = grid->rowPtr[i] + (grid->bufIdx == 0 ? 0x40 : 0);
|
||||||
|
strcpy(formData.str, grid->rowStr[i]);
|
||||||
|
len = strlen(formData.str);
|
||||||
|
memset(formData.str + len, ' ', sizeof(formData.str) - len);
|
||||||
|
formData.count = sizeof(formData.str);
|
||||||
|
// 加入队列
|
||||||
|
LoopBuff_PutItem(&Form_DataM, (uint8_t *) &formData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 再将备份缓冲作为显示缓冲
|
||||||
|
for(i = 0; i < 30; i++)
|
||||||
|
{
|
||||||
|
formData.oper = DWIN_OPER_WRITE;
|
||||||
|
formData.Addr = grid->rowDesc[i];
|
||||||
|
formData.count = 2;
|
||||||
|
formData.word[0] = htons(grid->rowPtr[i] + (grid->bufIdx == 0 ? 0x40 : 0));
|
||||||
|
// 加入队列
|
||||||
|
LoopBuff_PutItem(&Form_DataM, (uint8_t *) &formData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将原显示缓冲作为备份缓冲
|
||||||
|
grid->bufIdx = 1 - grid->bufIdx;
|
||||||
|
|
||||||
|
// 解锁
|
||||||
|
xSemaphoreGive(Form_DataLock);
|
||||||
|
|
||||||
|
// 发送消息给任务
|
||||||
|
xSemaphoreGive(Form_DataQ);
|
||||||
|
}
|
||||||
// 滚动表格
|
// 滚动表格
|
||||||
void Form_ScrollGrid(form_grid_t *grid)
|
void Form_ScrollGrid(form_grid_t *grid)
|
||||||
{
|
{
|
||||||
|
|
@ -422,6 +462,7 @@ void Form_Open()
|
||||||
gridQuery.rowCount = 10;
|
gridQuery.rowCount = 10;
|
||||||
gridAbout.rowCount = 10;
|
gridAbout.rowCount = 10;
|
||||||
gridAboutEn.rowCount = 10;
|
gridAboutEn.rowCount = 10;
|
||||||
|
gridBox.rowCount=30;
|
||||||
|
|
||||||
gridAll.hdrAddr = 0x5200;
|
gridAll.hdrAddr = 0x5200;
|
||||||
for(i = 0; i < gridAll.rowCount; i++)
|
for(i = 0; i < gridAll.rowCount; i++)
|
||||||
|
|
@ -453,6 +494,12 @@ void Form_Open()
|
||||||
gridAboutEn.rowDesc[i] = 0xB7F0 + 0x10 * i;
|
gridAboutEn.rowDesc[i] = 0xB7F0 + 0x10 * i;
|
||||||
gridAboutEn.rowPtr[i] = 0x7A00 + 0x80 * i;
|
gridAboutEn.rowPtr[i] = 0x7A00 + 0x80 * i;
|
||||||
}
|
}
|
||||||
|
gridBox.hdrAddr=0x8000;
|
||||||
|
for(i = 0; i < gridBox.rowCount; i++)
|
||||||
|
{
|
||||||
|
gridBox.rowDesc[i] = 0xC010 + 0x10 * i;
|
||||||
|
gridBox.rowPtr[i] = 0x8080 + 0x80 * i;
|
||||||
|
}
|
||||||
// 启动串口
|
// 启动串口
|
||||||
huart10.RxISR = DWIN_IRQHandler;
|
huart10.RxISR = DWIN_IRQHandler;
|
||||||
SET_BIT(UART10->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
|
SET_BIT(UART10->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
|
||||||
|
|
@ -614,17 +661,29 @@ void Form_Task(void *p_arg)
|
||||||
" 日期", " 时间", " 罐箱号 ", "液位(mmWC)", "质量(kg)", "百分比", "压力(MPa)", "温度(℃)", "报警", "故障", " PSN ");
|
" 日期", " 时间", " 罐箱号 ", "液位(mmWC)", "质量(kg)", "百分比", "压力(MPa)", "温度(℃)", "报警", "故障", " PSN ");
|
||||||
data.count = strlen(data.str);
|
data.count = strlen(data.str);
|
||||||
DWIN_Refresh(&data);
|
DWIN_Refresh(&data);
|
||||||
|
|
||||||
data.oper = DWIN_OPER_WRITE;
|
data.oper = DWIN_OPER_WRITE;
|
||||||
data.Addr = gridWarn.hdrAddr+0x2000;
|
data.Addr = gridWarn.hdrAddr+0x2000;
|
||||||
sprintf(data.str, " %5s %5s %11s %10s %8s %6s %9s %6s %4s %4s %13s",
|
sprintf(data.str, " %5s %5s %11s %10s %8s %6s %9s %6s %4s %4s %13s",
|
||||||
" data", " time", "Number_Box", "Level(mmWC)", "Qual(kg)", "Per(%)", "Pres(MPa)", "T(deg)", "Warn", "Err", " PSN ");
|
" data", " time", "Number_Box", "Level(mmWC)", "Qual(kg)", "Per(%)", "Pres(MPa)", "T(deg)", "Warn", "Err", " PSN ");
|
||||||
data.count = strlen(data.str);
|
data.count = strlen(data.str);
|
||||||
DWIN_Refresh(&data);
|
DWIN_Refresh(&data);
|
||||||
|
|
||||||
|
data.oper = DWIN_OPER_WRITE;
|
||||||
|
data.Addr = gridBox.hdrAddr;
|
||||||
|
sprintf(data.str, " %11s %13s %11s %13s %11s %13s ",
|
||||||
|
" BOX ", " PSN "," BOX ", " PSN "," BOX ", " PSN ");
|
||||||
|
data.count = strlen(data.str);
|
||||||
|
DWIN_Refresh(&data);
|
||||||
|
|
||||||
// 设置曲线的纵坐标
|
// 设置曲线的纵坐标
|
||||||
// 绿轴:液位(百分比)
|
// 绿轴:液位(百分比)
|
||||||
data.oper = DWIN_OPER_WRITE;
|
data.oper = DWIN_OPER_WRITE;
|
||||||
data.Addr = 0x6580;
|
data.Addr = 0x6580;
|
||||||
strcpy(data.str, " 液位-%");
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
strcpy(data.str, " Level-%");
|
||||||
|
else
|
||||||
|
strcpy(data.str, " 液位-%");
|
||||||
data.count = strlen(data.str);
|
data.count = strlen(data.str);
|
||||||
DWIN_Refresh(&data);
|
DWIN_Refresh(&data);
|
||||||
axisMax = 100;
|
axisMax = 100;
|
||||||
|
|
@ -640,7 +699,10 @@ void Form_Task(void *p_arg)
|
||||||
// 黄轴:压力(MPa)
|
// 黄轴:压力(MPa)
|
||||||
data.oper = DWIN_OPER_WRITE;
|
data.oper = DWIN_OPER_WRITE;
|
||||||
data.Addr = 0x6590;
|
data.Addr = 0x6590;
|
||||||
strcpy(data.str, "压力-MPa");
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
strcpy(data.str, "pressure-%");
|
||||||
|
else
|
||||||
|
strcpy(data.str, "压力-MPa");
|
||||||
data.count = strlen(data.str);
|
data.count = strlen(data.str);
|
||||||
DWIN_Refresh(&data);
|
DWIN_Refresh(&data);
|
||||||
axisMax = 5;
|
axisMax = 5;
|
||||||
|
|
@ -656,7 +718,10 @@ void Form_Task(void *p_arg)
|
||||||
// 红轴:温度(℃)
|
// 红轴:温度(℃)
|
||||||
data.oper = DWIN_OPER_WRITE;
|
data.oper = DWIN_OPER_WRITE;
|
||||||
data.Addr = 0x65A0;
|
data.Addr = 0x65A0;
|
||||||
strcpy(data.str, "温度-℃");
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
strcpy(data.str, "Temperature-%");
|
||||||
|
else
|
||||||
|
strcpy(data.str, "温度-℃");
|
||||||
data.count = strlen(data.str);
|
data.count = strlen(data.str);
|
||||||
DWIN_Refresh(&data);
|
DWIN_Refresh(&data);
|
||||||
axisMax = 90;
|
axisMax = 90;
|
||||||
|
|
@ -676,10 +741,10 @@ void Form_Task(void *p_arg)
|
||||||
// 开机画面等待4秒
|
// 开机画面等待4秒
|
||||||
osDelay(3000);
|
osDelay(3000);
|
||||||
// 跳转到首页
|
// 跳转到首页
|
||||||
if(dcBuff.configDisplay.ch_en)
|
if(dcBuff.configDisplay.ch_en)
|
||||||
Form_SwitchPage(50);
|
Form_SwitchPage(50);
|
||||||
else
|
else
|
||||||
Form_SwitchPage(0);
|
Form_SwitchPage(0);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
|
@ -717,19 +782,19 @@ void Form_Task(void *p_arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
seconds = rf_get_seconds();
|
seconds = rf_get_seconds();
|
||||||
|
//apex
|
||||||
|
// // LORA: 最新接收时间在3秒以内
|
||||||
|
// val = (RF_initStatus && RF_seconds > 0 && RF_seconds + 3 > seconds);
|
||||||
|
// if(last_lora != val)
|
||||||
|
// {
|
||||||
|
// data.oper = DWIN_OPER_WRITE;
|
||||||
|
// data.Addr = 0x5002;
|
||||||
|
// data.count = 2;
|
||||||
|
// data.word[0] = htons(val);
|
||||||
|
// DWIN_Refresh(&data);
|
||||||
|
|
||||||
// LORA: 最新接收时间在3秒以内
|
// last_lora = val;
|
||||||
val = (RF_initStatus && RF_seconds > 0 && RF_seconds + 3 > seconds);
|
// }
|
||||||
if(last_lora != val)
|
|
||||||
{
|
|
||||||
data.oper = DWIN_OPER_WRITE;
|
|
||||||
data.Addr = 0x5002;
|
|
||||||
data.count = 2;
|
|
||||||
data.word[0] = htons(val);
|
|
||||||
DWIN_Refresh(&data);
|
|
||||||
|
|
||||||
last_lora = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
// GPS标志: 最新定位时间在180秒以内
|
// GPS标志: 最新定位时间在180秒以内
|
||||||
if(dcBuff.dtuData.posState)
|
if(dcBuff.dtuData.posState)
|
||||||
|
|
@ -755,7 +820,7 @@ void Form_Task(void *p_arg)
|
||||||
Form_ClearMessage();
|
Form_ClearMessage();
|
||||||
}
|
}
|
||||||
// 每30秒统计一次设备数量
|
// 每30秒统计一次设备数量
|
||||||
if(RTC_offsetSeconds > 0 && seconds >= statisSeconds)
|
if(/*RTC_offsetSeconds > 0 &&*/ seconds >= statisSeconds)
|
||||||
{
|
{
|
||||||
statisSeconds = seconds + 30;
|
statisSeconds = seconds + 30;
|
||||||
|
|
||||||
|
|
@ -1253,7 +1318,14 @@ uint8_t Form_ModifyPSN(form_data_t *key, char *msg)
|
||||||
char str[26];
|
char str[26];
|
||||||
uint8_t len, i = 0;
|
uint8_t len, i = 0;
|
||||||
u16 serial = 0;
|
u16 serial = 0;
|
||||||
const static char errMsg[20] = "PSN输入有误!";
|
char errMsg[20] = "PSN输入有误!";
|
||||||
|
char errMsgEn[20] = "PSN incorrect";
|
||||||
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
{
|
||||||
|
|
||||||
|
strcpy(errMsg, errMsgEn);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// 读取PSN
|
// 读取PSN
|
||||||
while(i < key->count && key->byte[i] != 0xFF && key->byte[i] != 0)
|
while(i < key->count && key->byte[i] != 0xFF && key->byte[i] != 0)
|
||||||
|
|
@ -1313,7 +1385,7 @@ uint8_t Form_GetQuery(uint16_t func, char *msg)
|
||||||
uint8_t len, i;
|
uint8_t len, i;
|
||||||
u16 serial = 0, y = 2000, m = 1, d = 1;
|
u16 serial = 0, y = 2000, m = 1, d = 1;
|
||||||
|
|
||||||
const static char errMsg[5][20] =
|
char errMsg[5][20] =
|
||||||
{
|
{
|
||||||
"通信故障!",
|
"通信故障!",
|
||||||
"罐箱号输入有误!",
|
"罐箱号输入有误!",
|
||||||
|
|
@ -1321,6 +1393,20 @@ uint8_t Form_GetQuery(uint16_t func, char *msg)
|
||||||
"起始日期输入有误!",
|
"起始日期输入有误!",
|
||||||
"查询天数输入有误!"
|
"查询天数输入有误!"
|
||||||
};
|
};
|
||||||
|
char errMsgEn[5][20] =
|
||||||
|
{
|
||||||
|
"Commu failure!",
|
||||||
|
"Box number err",
|
||||||
|
"The PSN err",
|
||||||
|
"startdate err.",
|
||||||
|
" days err"
|
||||||
|
};
|
||||||
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
{
|
||||||
|
for (i = 0; i < 5; ++i) {
|
||||||
|
strcpy(errMsg[i], errMsgEn[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 读取罐箱号
|
// 读取罐箱号
|
||||||
if(!Form_ReadStr(0x5E00, str, sizeof(str)))
|
if(!Form_ReadStr(0x5E00, str, sizeof(str)))
|
||||||
|
|
@ -1498,14 +1584,20 @@ uint8_t Form_PreQuery()
|
||||||
// 储罐要判断是否离线
|
// 储罐要判断是否离线
|
||||||
if(formQuery.func == 1 && RTC_offsetSeconds == 0)
|
if(formQuery.func == 1 && RTC_offsetSeconds == 0)
|
||||||
{
|
{
|
||||||
Form_DispMessage("尚未获取基站时间!", DWIN_COLOR_RED);
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("The time not obtained!", DWIN_COLOR_RED);
|
||||||
|
else
|
||||||
|
Form_DispMessage("尚未获取基站时间!", DWIN_COLOR_RED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 曲线只能查询唯一PSN的数据
|
// 曲线只能查询唯一PSN的数据
|
||||||
if(formQuery.func == 3 && !formQuery.tgguFlag && !formQuery.psnFlag)
|
if(formQuery.func == 3 && !formQuery.tgguFlag && !formQuery.psnFlag)
|
||||||
{
|
{
|
||||||
Form_DispMessage("请输入罐箱号或PSN!", DWIN_COLOR_RED);
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("Enter the Box number or PSN", DWIN_COLOR_RED);
|
||||||
|
else
|
||||||
|
Form_DispMessage("请输入罐箱号或PSN!", DWIN_COLOR_RED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1516,12 +1608,18 @@ uint8_t Form_PreQuery()
|
||||||
idx = Ext_Lookup_Box_TGGU(formQuery.TGGU, boxCnt.count);
|
idx = Ext_Lookup_Box_TGGU(formQuery.TGGU, boxCnt.count);
|
||||||
if(idx == -1)
|
if(idx == -1)
|
||||||
{
|
{
|
||||||
Form_DispMessage("无此罐箱号!", DWIN_COLOR_RED);
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("There is no box number", DWIN_COLOR_RED);
|
||||||
|
else
|
||||||
|
Form_DispMessage("无此罐箱号!", DWIN_COLOR_RED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(formQuery.psnFlag && memcmp(formQuery.PSN, boxTGGU[idx].PSN, 6) != 0)
|
if(formQuery.psnFlag && memcmp(formQuery.PSN, boxTGGU[idx].PSN, 6) != 0)
|
||||||
{
|
{
|
||||||
Form_DispMessage("罐箱号和PSN冲突!", DWIN_COLOR_RED);
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("Box number conflicts with PSN", DWIN_COLOR_RED);
|
||||||
|
else
|
||||||
|
Form_DispMessage("罐箱号和PSN冲突!", DWIN_COLOR_RED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// 记录PSN,用于查询显示
|
// 记录PSN,用于查询显示
|
||||||
|
|
@ -1548,13 +1646,23 @@ uint8_t Form_PreQuery()
|
||||||
formData.Addr = gridQuery.hdrAddr;
|
formData.Addr = gridQuery.hdrAddr;
|
||||||
if(formQuery.func == 1)
|
if(formQuery.func == 1)
|
||||||
{
|
{
|
||||||
sprintf(formData.str, " %4s %11s %6s %9s %8s %4s %4s %4s %13s %5s %5s %7s",
|
if(dcBuff.configDisplay.ch_en)
|
||||||
"序号", " 罐箱号 ", "百分比", "压力(MPa)", "温度(℃)", "报警", "故障", "离线", " PSN ", "日期", "时间", "电压(v)");
|
sprintf(formData.str, " %4s %11s %6s %9s %8s %4s %4s %4s %13s %5s %5s %7s",
|
||||||
|
"Num", " Box_number ", "Percentage", "Press(MPa)", "Temp(℃)", "Alarm", "Err", "Offline", " PSN ", "Date", "Time", "Vol(v)");
|
||||||
|
|
||||||
|
else
|
||||||
|
sprintf(formData.str, " %4s %11s %6s %9s %8s %4s %4s %4s %13s %5s %5s %7s",
|
||||||
|
"序号", " 罐箱号 ", "百分比", "压力(MPa)", "温度(℃)", "报警", "故障", "离线", " PSN ", "日期", "时间", "电压(v)");
|
||||||
}
|
}
|
||||||
else if(formQuery.func == 2)
|
else if(formQuery.func == 2)
|
||||||
{
|
{
|
||||||
sprintf(formData.str, " %5s %5s %11s %10s %8s %6s %9s %8s %4s %4s %13s",
|
if(dcBuff.configDisplay.ch_en)
|
||||||
" 日期", " 时间", " 罐箱号 ", "液位(mmWC)", "质量(kg)", "百分比", "压力(MPa)", "温度(℃)", "报警", "故障", " PSN ");
|
sprintf(formData.str, " %5s %5s %11s %10s %8s %6s %9s %8s %4s %4s %13s",
|
||||||
|
"Data", "Time", " Box_number ", "Level(mmWC)", "m(kg)", "Percent", "Press(MPa)", "Temp(℃)", "Alarm", "Err", " PSN ");
|
||||||
|
|
||||||
|
else
|
||||||
|
sprintf(formData.str, " %5s %5s %11s %10s %8s %6s %9s %8s %4s %4s %13s",
|
||||||
|
" 日期", " 时间", " 罐箱号 ", "液位(mmWC)", "质量(kg)", "百分比", "压力(MPa)", "温度(℃)", "报警", "故障", " PSN ");
|
||||||
}
|
}
|
||||||
len = strlen(formData.str);
|
len = strlen(formData.str);
|
||||||
memset(formData.str + len, ' ', sizeof(formData.str) - len);
|
memset(formData.str + len, ' ', sizeof(formData.str) - len);
|
||||||
|
|
@ -1704,7 +1812,12 @@ void Form_QueryBox(int32_t lastRec)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(row < gridQuery.rowCount)
|
if(row < gridQuery.rowCount)
|
||||||
Form_DispMessage("没有更多记录!", DWIN_COLOR_GREEN);
|
{
|
||||||
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("There are no more records.", DWIN_COLOR_RED);
|
||||||
|
else
|
||||||
|
Form_DispMessage("没有更多记录!", DWIN_COLOR_GREEN);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Form_ClearMessage();
|
Form_ClearMessage();
|
||||||
|
|
@ -1747,7 +1860,10 @@ void Form_QueryData(int32_t lastRec)
|
||||||
FRAM_BufferRead(FRAM_BOTTLE_DATA_BASE + sizeof(ext_bottle_t) * bottlePSN[idx].recNo, (uint8_t *) &bottleRec, sizeof(ext_bottle_t));
|
FRAM_BufferRead(FRAM_BOTTLE_DATA_BASE + sizeof(ext_bottle_t) * bottlePSN[idx].recNo, (uint8_t *) &bottleRec, sizeof(ext_bottle_t));
|
||||||
if(idx < 0 || bottleRec.lastData < 0)
|
if(idx < 0 || bottleRec.lastData < 0)
|
||||||
{
|
{
|
||||||
Form_DispMessage("无此PSN的数据!", DWIN_COLOR_RED);
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("There is no data for PSN", DWIN_COLOR_RED);
|
||||||
|
else
|
||||||
|
Form_DispMessage("无此PSN的数据!", DWIN_COLOR_RED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1894,7 +2010,12 @@ void Form_QueryData(int32_t lastRec)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(row < gridQuery.rowCount)
|
if(row < gridQuery.rowCount)
|
||||||
Form_DispMessage("没有更多记录!", DWIN_COLOR_GREEN);
|
{
|
||||||
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("There are no more records.", DWIN_COLOR_GREEN);
|
||||||
|
else
|
||||||
|
Form_DispMessage("没有更多记录!", DWIN_COLOR_GREEN);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Form_ClearMessage();
|
Form_ClearMessage();
|
||||||
|
|
@ -1983,7 +2104,10 @@ void Form_QueryCurve(int32_t lastRec)
|
||||||
if(idx < 0 || bottleRec.lastData < 0)
|
if(idx < 0 || bottleRec.lastData < 0)
|
||||||
{
|
{
|
||||||
Form_ClearCurves();
|
Form_ClearCurves();
|
||||||
Form_DispMessage("无此PSN的数据!", DWIN_COLOR_RED);
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("There is no data for PSN", DWIN_COLOR_RED);
|
||||||
|
else
|
||||||
|
Form_DispMessage("无此PSN的数据!", DWIN_COLOR_RED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2262,9 +2386,19 @@ void Form_QueryCurve(int32_t lastRec)
|
||||||
if(temprCnt == 0)
|
if(temprCnt == 0)
|
||||||
Form_ClearCurve(temprAddr);
|
Form_ClearCurve(temprAddr);
|
||||||
if(levelCnt == 0 && pressCnt == 0 && temprCnt == 0)
|
if(levelCnt == 0 && pressCnt == 0 && temprCnt == 0)
|
||||||
Form_DispMessage("无此时间段内的数据!", DWIN_COLOR_GREEN);
|
{
|
||||||
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("No data for this time period", DWIN_COLOR_GREEN);
|
||||||
|
else
|
||||||
|
Form_DispMessage("无此时间段内的数据!", DWIN_COLOR_GREEN);
|
||||||
|
}
|
||||||
else if(lastRec < 0)
|
else if(lastRec < 0)
|
||||||
Form_DispMessage("无更早时间的数据!", DWIN_COLOR_GREEN);
|
{
|
||||||
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("No data from an earlier time", DWIN_COLOR_GREEN);
|
||||||
|
else
|
||||||
|
Form_DispMessage("无更早时间的数据!", DWIN_COLOR_GREEN);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Form_ClearMessage();
|
Form_ClearMessage();
|
||||||
|
|
||||||
|
|
@ -2330,8 +2464,7 @@ void Form_About()
|
||||||
void Form_En_About()
|
void Form_En_About()
|
||||||
{
|
{
|
||||||
uint8_t row = 0;
|
uint8_t row = 0;
|
||||||
|
sprintf(gridAboutEn.rowStr[row++], " PSN: 20%02d%02d%02d%02d%03d",
|
||||||
sprintf(gridAboutEn.rowStr[row++], "PSN of Device: 20%02d%02d%02d%02d%03d",
|
|
||||||
dcBuff.configBottle.PSN[0], dcBuff.configBottle.PSN[1], dcBuff.configBottle.PSN[2],
|
dcBuff.configBottle.PSN[0], dcBuff.configBottle.PSN[1], dcBuff.configBottle.PSN[2],
|
||||||
dcBuff.configBottle.PSN[3], (dcBuff.configBottle.PSN[4] << 8) | dcBuff.configBottle.PSN[5]);
|
dcBuff.configBottle.PSN[3], (dcBuff.configBottle.PSN[4] << 8) | dcBuff.configBottle.PSN[5]);
|
||||||
sprintf(gridAboutEn.rowStr[row++], " Hard ver: %d.%d, Soft ver: %d.%d, data:20%02d-%02d-%02d",
|
sprintf(gridAboutEn.rowStr[row++], " Hard ver: %d.%d, Soft ver: %d.%d, data:20%02d-%02d-%02d",
|
||||||
|
|
@ -2350,6 +2483,68 @@ void Form_En_About()
|
||||||
|
|
||||||
Form_RefreshGrid(&gridAboutEn);
|
Form_RefreshGrid(&gridAboutEn);
|
||||||
}
|
}
|
||||||
|
static int16_t topPtr=0;
|
||||||
|
void Form_BOX_PSN()
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
uint8_t row = 0;
|
||||||
|
int16_t rowCount=0;
|
||||||
|
topPtr=0;
|
||||||
|
rowCount=gridBox.rowCount;
|
||||||
|
if(rowCount>30)rowCount=30;
|
||||||
|
for(i=0; i<rowCount; i++)
|
||||||
|
{
|
||||||
|
sprintf(gridBox.rowStr[row++], "%s 20%02d%02d%02d%02d%03d",
|
||||||
|
boxTGGU[i].TGGU, boxTGGU[i].PSN[0], boxTGGU[i].PSN[1], boxTGGU[i].PSN[2],
|
||||||
|
boxTGGU[i].PSN[3], (boxTGGU[i].PSN[4] << 8) | boxTGGU[i].PSN[5]);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
Form_RefreshGrid2(&gridBox);
|
||||||
|
|
||||||
|
}
|
||||||
|
void Form_BOX_PSN_D0WN()
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
int16_t rowCount=0;
|
||||||
|
uint8_t row = 0;
|
||||||
|
|
||||||
|
//boxCnt.count
|
||||||
|
rowCount=boxCnt.count-topPtr;
|
||||||
|
if(rowCount<31) return;
|
||||||
|
topPtr+=30;
|
||||||
|
rowCount-=30;
|
||||||
|
row=0;
|
||||||
|
if(rowCount>30)rowCount=30;
|
||||||
|
memset(gridBox.rowStr, 0, sizeof(gridBox.rowStr));
|
||||||
|
for(i=0; i<rowCount; i++)
|
||||||
|
{
|
||||||
|
sprintf(gridBox.rowStr[row++], "%s 20%02d%02d%02d%02d%03d",
|
||||||
|
boxTGGU[topPtr+i].TGGU, boxTGGU[topPtr+i].PSN[0], boxTGGU[topPtr+i].PSN[1], boxTGGU[topPtr+i].PSN[2],
|
||||||
|
boxTGGU[topPtr+i].PSN[3], (boxTGGU[topPtr+i].PSN[4] << 8) | boxTGGU[topPtr+i].PSN[5]);
|
||||||
|
|
||||||
|
}
|
||||||
|
Form_RefreshGrid2(&gridBox);
|
||||||
|
|
||||||
|
}
|
||||||
|
void Form_BOX_PSN_UP()
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
int16_t rowCount=0;
|
||||||
|
uint8_t row = 0;
|
||||||
|
if(topPtr<30)return;
|
||||||
|
topPtr-=30;
|
||||||
|
|
||||||
|
for(i=0; i<30; i++)
|
||||||
|
{
|
||||||
|
sprintf(gridBox.rowStr[row++], "%s 20%02d%02d%02d%02d%03d",
|
||||||
|
boxTGGU[topPtr+i].TGGU, boxTGGU[topPtr+i].PSN[0], boxTGGU[topPtr+i].PSN[1], boxTGGU[topPtr+i].PSN[2],
|
||||||
|
boxTGGU[topPtr+i].PSN[3], (boxTGGU[topPtr+i].PSN[4] << 8) | boxTGGU[topPtr+i].PSN[5]);
|
||||||
|
|
||||||
|
}
|
||||||
|
Form_RefreshGrid2(&gridBox);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// 按键任务主体
|
// 按键任务主体
|
||||||
void Key_Task(void *p_arg)
|
void Key_Task(void *p_arg)
|
||||||
|
|
@ -2375,7 +2570,7 @@ void Key_Task(void *p_arg)
|
||||||
// 点击当前页面,不处理
|
// 点击当前页面,不处理
|
||||||
if(page == val)
|
if(page == val)
|
||||||
continue;
|
continue;
|
||||||
page = val;
|
|
||||||
|
|
||||||
if((val == 3)||(val == 0x13)) // 进入设置页
|
if((val == 3)||(val == 0x13)) // 进入设置页
|
||||||
Form_RestoreParam();
|
Form_RestoreParam();
|
||||||
|
|
@ -2383,37 +2578,56 @@ void Key_Task(void *p_arg)
|
||||||
{
|
{
|
||||||
// Form_SwitchPage(23); // 切换到开机画面
|
// Form_SwitchPage(23); // 切换到开机画面
|
||||||
// osDelay(2000); // 延时2秒
|
// osDelay(2000); // 延时2秒
|
||||||
// Form_SwitchPage(21); // 切换到关于页面
|
|
||||||
Form_About(); // 显示关于信息
|
Form_About(); // 显示关于信息
|
||||||
}
|
}
|
||||||
else if(val == 0x14) // 显示关于信息
|
else if(val == 0x14) // 显示关于信息
|
||||||
{
|
{
|
||||||
// Form_SwitchPage(23); // 切换到开机画面
|
// Form_SwitchPage(23); // 切换到开机画面
|
||||||
// osDelay(2000); // 延时2秒
|
|
||||||
// Form_SwitchPage(21); // 切换到关于页面
|
|
||||||
Form_En_About(); // 显示关于信息
|
Form_En_About(); // 显示关于信息
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(val == 0x15) // 显示关于信息
|
else if(val == 0x15) // 显示关于信息
|
||||||
{
|
{
|
||||||
// Form_En_About(); // 显示关于信息
|
if(3==page)
|
||||||
dcBuff.configDisplay.ch_en=0;
|
Form_En_About(); // 显示关于信息
|
||||||
Config_SaveConfig();
|
dcBuff.configDisplay.ch_en=0;
|
||||||
|
Config_SaveConfig();
|
||||||
}
|
}
|
||||||
else if(val == 0x05) // 显示关于信息
|
else if(val == 0x05) // 显示关于信息
|
||||||
{
|
{
|
||||||
dcBuff.configDisplay.ch_en=1;
|
dcBuff.configDisplay.ch_en=1;
|
||||||
// Form_En_About(); // 显示关于信息
|
if(4==page)
|
||||||
Config_SaveConfig();
|
Form_En_About(); // 显示关于信息
|
||||||
|
Config_SaveConfig();
|
||||||
}
|
}
|
||||||
|
else if(val == 0x06) // chu罐
|
||||||
|
{
|
||||||
|
Form_BOX_PSN();
|
||||||
|
}
|
||||||
|
|
||||||
|
page = val;
|
||||||
|
}
|
||||||
|
else if(key.Addr == 0x5034) // chu罐
|
||||||
|
{
|
||||||
|
Form_BOX_PSN_UP();
|
||||||
|
}
|
||||||
|
else if(key.Addr == 0x5036) // chu罐
|
||||||
|
{
|
||||||
|
Form_BOX_PSN_D0WN();
|
||||||
}
|
}
|
||||||
else if(key.Addr == 0x5012) // 设置
|
else if(key.Addr == 0x5012) // 设置
|
||||||
{
|
{
|
||||||
if(val == 1) // 保存参数
|
if(val == 1) // 保存参数
|
||||||
{
|
{
|
||||||
Form_DispMessage("请输入密码!", DWIN_COLOR_GREEN);
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("Please enter the password.", DWIN_COLOR_GREEN);
|
||||||
|
else
|
||||||
|
Form_DispMessage("请输入密码!", DWIN_COLOR_GREEN);
|
||||||
// 弹出密码输入对话(触控区域在可视区域之外,只能由程序弹出)
|
// 弹出密码输入对话(触控区域在可视区域之外,只能由程序弹出)
|
||||||
DWIN_Touch(2040, 257);
|
DWIN_Touch(2040, 257);
|
||||||
|
|
||||||
}
|
}
|
||||||
else // 取消
|
else // 取消
|
||||||
Form_RestoreParam();
|
Form_RestoreParam();
|
||||||
|
|
@ -2423,12 +2637,27 @@ void Key_Task(void *p_arg)
|
||||||
if(ntohl(key.dword[0]) == atoi(dcBuff.configDisplay.pwd1))
|
if(ntohl(key.dword[0]) == atoi(dcBuff.configDisplay.pwd1))
|
||||||
{
|
{
|
||||||
if(Form_SaveParam())
|
if(Form_SaveParam())
|
||||||
Form_DispMessage("保存成功!", DWIN_COLOR_GREEN);
|
{
|
||||||
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("Save successfully", DWIN_COLOR_GREEN);
|
||||||
|
else
|
||||||
|
Form_DispMessage("保存成功!", DWIN_COLOR_GREEN);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Form_DispMessage("通信故障,保存失败!", DWIN_COLOR_RED);
|
{
|
||||||
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("Communication and save failure", DWIN_COLOR_RED);
|
||||||
|
else
|
||||||
|
Form_DispMessage("通信故障,保存失败!", DWIN_COLOR_RED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Form_DispMessage("密码错误!", DWIN_COLOR_RED);
|
{
|
||||||
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("Password error", DWIN_COLOR_RED);
|
||||||
|
else
|
||||||
|
Form_DispMessage("密码错误!", DWIN_COLOR_RED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(key.Addr == 0x5022) // 查询储罐、数据和曲线
|
else if(key.Addr == 0x5022) // 查询储罐、数据和曲线
|
||||||
{
|
{
|
||||||
|
|
@ -2453,9 +2682,12 @@ void Key_Task(void *p_arg)
|
||||||
}
|
}
|
||||||
else if(key.Addr == 0x5032) // 修改PSN
|
else if(key.Addr == 0x5032) // 修改PSN
|
||||||
{
|
{
|
||||||
Form_DispMessage("请输入密码!", DWIN_COLOR_GREEN);
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("Please enter the password.", DWIN_COLOR_GREEN);
|
||||||
|
else
|
||||||
|
Form_DispMessage("请输入密码!", DWIN_COLOR_GREEN);
|
||||||
// 弹出密码输入对话(触控区域在可视区域之外,只能由程序弹出)
|
// 弹出密码输入对话(触控区域在可视区域之外,只能由程序弹出)
|
||||||
DWIN_Touch(1581, 166);//DWIN_Touch(1541, 166);
|
DWIN_Touch(1541, 166);
|
||||||
}
|
}
|
||||||
else if(key.Addr == 0x502E) // 修改PSN的密码输入
|
else if(key.Addr == 0x502E) // 修改PSN的密码输入
|
||||||
{
|
{
|
||||||
|
|
@ -2480,13 +2712,20 @@ void Key_Task(void *p_arg)
|
||||||
|
|
||||||
// 发送消息给任务
|
// 发送消息给任务
|
||||||
xSemaphoreGive(Form_DataQ);
|
xSemaphoreGive(Form_DataQ);
|
||||||
|
if(dcBuff.configDisplay.ch_en)
|
||||||
Form_DispMessage("请输入新的PSN!", DWIN_COLOR_GREEN);
|
Form_DispMessage("Please enter a new PSN", DWIN_COLOR_GREEN);
|
||||||
|
else
|
||||||
|
Form_DispMessage("请输入新的PSN!", DWIN_COLOR_GREEN);
|
||||||
// 弹出PSN输入对话(触控区域在可视区域之外,只能由程序弹出)
|
// 弹出PSN输入对话(触控区域在可视区域之外,只能由程序弹出)
|
||||||
DWIN_Touch(2179, 166);
|
DWIN_Touch(2179, 166);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Form_DispMessage("密码错误!", DWIN_COLOR_RED);
|
{
|
||||||
|
if(dcBuff.configDisplay.ch_en)
|
||||||
|
Form_DispMessage("Password error", DWIN_COLOR_GREEN);
|
||||||
|
else
|
||||||
|
Form_DispMessage("密码错误!", DWIN_COLOR_RED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(key.Addr == 0x6F00) // PSN输入
|
else if(key.Addr == 0x6F00) // PSN输入
|
||||||
{
|
{
|
||||||
|
|
@ -2494,8 +2733,18 @@ void Key_Task(void *p_arg)
|
||||||
Form_DispMessage(msg, DWIN_COLOR_RED);
|
Form_DispMessage(msg, DWIN_COLOR_RED);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Form_About(); // 刷新关于页的内容
|
if(dcBuff.configDisplay.ch_en)
|
||||||
Form_DispMessage("修改成功!", DWIN_COLOR_GREEN);
|
{
|
||||||
|
Form_En_About(); // 刷新关于页的内容
|
||||||
|
|
||||||
|
Form_DispMessage("The modification was successful.", DWIN_COLOR_GREEN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Form_About(); // 刷新关于页的内容
|
||||||
|
|
||||||
|
Form_DispMessage("修改成功!", DWIN_COLOR_GREEN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,17 @@ typedef struct
|
||||||
int32_t topPtr; // 分页查询起始位置
|
int32_t topPtr; // 分页查询起始位置
|
||||||
} form_grid_t;
|
} form_grid_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int16_t rowCount; // 记录条数
|
||||||
|
uint16_t hdrAddr; // 表头显示地址
|
||||||
|
uint16_t rowPtr[30]; // 各行显示地址
|
||||||
|
uint16_t rowDesc[30]; // 各行描述地址
|
||||||
|
char rowStr[30][30]; // 各行显示内容
|
||||||
|
uint8_t bufIdx; // 双缓冲序号
|
||||||
|
int32_t topPtr; // 分页查询起始位置
|
||||||
|
} form_grid2_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t func; // 查询功能(1-储罐,2-数据,3-曲线)
|
uint8_t func; // 查询功能(1-储罐,2-数据,3-曲线)
|
||||||
|
|
|
||||||
|
|
@ -323,20 +323,20 @@ void Data_Open()
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
// 测试代码,手动建立几个储罐扩展档案
|
// 测试代码,手动建立几个储罐扩展档案
|
||||||
boxCnt.count = 500;
|
boxCnt.count = 500;
|
||||||
for(i = 0; i < boxCnt.count; i++)
|
for(i = 0; i < boxCnt.count; i++)
|
||||||
{
|
{
|
||||||
memset(&boxRec, 0, sizeof(ext_box_t));
|
memset(&boxRec, 0, sizeof(ext_box_t));
|
||||||
boxRec.PSN[0] = 10;
|
boxRec.PSN[0] = 26;
|
||||||
boxRec.PSN[3] = (10 + i * 10) / 1000;
|
boxRec.PSN[3] = (0 + i * 1) / 1000;
|
||||||
boxRec.PSN[4] = ((10 + i * 10) % 1000) >> 8;
|
boxRec.PSN[4] = ((0 + i * 1) % 1000) >> 8;
|
||||||
boxRec.PSN[5] = ((10 + i * 10) % 1000) & 0xFF;
|
boxRec.PSN[5] = ((0 + i * 1) % 1000) & 0xFF;
|
||||||
strcpy(boxRec.TGGU, "TGGU2000010");
|
strcpy(boxRec.TGGU, "TGGU2000000");
|
||||||
boxRec.TGGU[7] = '0' + (1 + i) / 100;
|
boxRec.TGGU[7] = '0' + (0 + i) / 100;
|
||||||
boxRec.TGGU[8] = '0' + (1 + i) % 100 / 10;
|
boxRec.TGGU[8] = '0' + (0 + i) % 100 / 10;
|
||||||
boxRec.TGGU[9] = '0' + (1 + i) % 10;
|
boxRec.TGGU[9] = '0' + (0 + i) % 10;
|
||||||
FRAM_BufferWrite(FRAM_BOX_DATA_BASE + sizeof(ext_box_t) * i, (uint8_t *) &boxRec, sizeof(ext_box_t));
|
FRAM_BufferWrite(FRAM_BOX_DATA_BASE + sizeof(ext_box_t) * i, (uint8_t *) &boxRec, sizeof(ext_box_t));
|
||||||
}
|
}
|
||||||
FRAM_SaveInfo(FRAM_BOX_INFO_BASE, (uint8_t *) &boxCnt, sizeof(ext_count_t));
|
FRAM_SaveInfo(FRAM_BOX_INFO_BASE, (uint8_t *) &boxCnt, sizeof(ext_count_t));
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,20 @@ uint8_t Modbus_SendM_Data[sizeof(ext_data_t) * (MODBUS_SENDM_DATA_COUNT + 1)] =
|
||||||
// RF串口接收的消息通知
|
// RF串口接收的消息通知
|
||||||
SemaphoreHandle_t Modbus_SendQ = NULL; // 二值信号量句柄
|
SemaphoreHandle_t Modbus_SendQ = NULL; // 二值信号量句柄
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t id; // 通信地址
|
||||||
|
uint8_t cmd; // 功能码
|
||||||
|
uint8_t index; // 包序号
|
||||||
|
uint8_t all; // 包数
|
||||||
|
// union
|
||||||
|
// {
|
||||||
|
// uint16_t cnt; // 读取:寄存器数量
|
||||||
|
// uint16_t data; // 写入:寄存器数据
|
||||||
|
// };
|
||||||
|
// uint16_t crc;
|
||||||
|
} modbus_request_t;
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
// 发送心跳报文缓冲
|
// 发送心跳报文缓冲
|
||||||
|
|
@ -20,12 +34,20 @@ uint8_t Heart_sendBuff[HEART_SENDBUFF_SIZE];
|
||||||
|
|
||||||
// 发送数据报文缓冲
|
// 发送数据报文缓冲
|
||||||
uint8_t Modbus_sendBuff[TASK_SENDBUFF_SIZE];
|
uint8_t Modbus_sendBuff[TASK_SENDBUFF_SIZE];
|
||||||
|
void ReadModbus_Task(uint8_t c);
|
||||||
|
|
||||||
static void RS485_SendDataByte(uint8_t *pu8TxBuf, uint32_t u32WriteBytes)
|
static void RS485_SendDataByte(uint8_t *pu8TxBuf, uint32_t u32WriteBytes)
|
||||||
{
|
{
|
||||||
/* Send data */
|
/* Send data */
|
||||||
UART_Transmit(&huart4, pu8TxBuf, u32WriteBytes);
|
UART_Transmit(&huart4, pu8TxBuf, u32WriteBytes);
|
||||||
}
|
}
|
||||||
|
void Slave_IRQHandler(USART_Handle *huart)
|
||||||
|
{
|
||||||
|
uint8_t u8DTU = (uint8_t) huart->Instance->DR;
|
||||||
|
|
||||||
|
/* Handle received data */
|
||||||
|
ReadModbus_Task(u8DTU);
|
||||||
|
}
|
||||||
|
|
||||||
void Modbus_Open()
|
void Modbus_Open()
|
||||||
{
|
{
|
||||||
|
|
@ -127,3 +149,134 @@ void Modbus_Task(void *p_arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理modbus rtu命令(已经验证过长度和CRC的包)
|
||||||
|
void MODBUS_RTU_CMD(modbus_request_t *req)
|
||||||
|
{
|
||||||
|
// static uint8_t BUFF[(MODBUS_LAST_REG - MODBUS_1ST_REG + 1) * 2 + 6]; // 响应包
|
||||||
|
// uint8_t err = 0; // 错误代码
|
||||||
|
// uint8_t len = 0; // 发送数据长度
|
||||||
|
|
||||||
|
// uint16_t id; // 通信地址
|
||||||
|
// uint16_t reg; // 数据地址
|
||||||
|
// uint16_t cnt; // 数据个数
|
||||||
|
// uint16_t crc;
|
||||||
|
|
||||||
|
// // 检查通信地址
|
||||||
|
// if(req->id != dcBuff.configBottle.addr && req->id != 0)
|
||||||
|
// return;
|
||||||
|
//
|
||||||
|
// // 清空发送帧
|
||||||
|
// memset(BUFF, 0, sizeof(BUFF));
|
||||||
|
|
||||||
|
// BUFF[len++] = dcBuff.configBottle.addr; // 从机地址
|
||||||
|
// BUFF[len++] = req->cmd; // 命令代码
|
||||||
|
|
||||||
|
// reg = ntohs(req->reg); // 数据寄存器
|
||||||
|
// if(req->cmd == 0x03 || req->cmd == 0x06)
|
||||||
|
// reg += 40001;
|
||||||
|
// else if(req->cmd == 0x04)
|
||||||
|
// reg += 30001;
|
||||||
|
// else
|
||||||
|
// err = MODBUS_ERR_ILF; // 无效功能码
|
||||||
|
//
|
||||||
|
// if(err == 0)
|
||||||
|
// {
|
||||||
|
// if(req->cmd == 0x03) // 读保持数据
|
||||||
|
// {
|
||||||
|
// cnt = ntohs(req->cnt); // 参数个数
|
||||||
|
// if(reg != MODBUS_ADR_REG || cnt != 1)
|
||||||
|
// err = MODBUS_ERR_NAK; // 命令无法执行
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// // 用最新的通讯地址刷新缓冲
|
||||||
|
// id = htons(dcBuff.configBottle.addr);
|
||||||
|
// BUFF[len++] = 2; // 数据长度
|
||||||
|
// memmove(BUFF + len, (uint8_t *) &id, 2);
|
||||||
|
// len += 2;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else if(req->cmd == 0x06) // 设置数据
|
||||||
|
// {
|
||||||
|
// if(reg != MODBUS_ADR_REG)
|
||||||
|
// err = MODBUS_ERR_NAK; // 命令无法执行
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// id = ntohs(req->data);
|
||||||
|
|
||||||
|
// if(id < 1 || id > 247)
|
||||||
|
// err = MODBUS_ERR_ILD; // 无效数据值
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// // 设置地址并保存
|
||||||
|
// dcBuff.configBottle.addr = id;
|
||||||
|
// Config_SaveConfig();
|
||||||
|
//
|
||||||
|
// BUFF[0] = id; // 新地址
|
||||||
|
// memmove(BUFF + len, &req->reg, 4); // 数据地址和通讯地址
|
||||||
|
// len += 4;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else if(req->cmd == 0x04) // 读输入数据
|
||||||
|
// {
|
||||||
|
// cnt = ntohs(req->cnt); // 参数个数
|
||||||
|
// if(reg < MODBUS_1ST_REG || reg > MODBUS_LAST_REG || cnt < 1 || reg + (cnt - 1) > MODBUS_LAST_REG)
|
||||||
|
// err = MODBUS_ERR_NAK; // 命令无法执行
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// // 用最新的采集数据刷新缓冲
|
||||||
|
// if(!Fill_MODBUS_RTU_Buf())
|
||||||
|
// return;
|
||||||
|
//
|
||||||
|
// BUFF[len++] = cnt * 2; // 数据长度
|
||||||
|
// memmove(BUFF + len, MODBUS_RTU_Buf + (reg - MODBUS_1ST_REG) * 2, cnt * 2);
|
||||||
|
// len += cnt * 2;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if(err != 0)
|
||||||
|
// {
|
||||||
|
// BUFF[1] |= 0x80; // 错误指示
|
||||||
|
// BUFF[len++] = err; // 错误代码
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 计算CRC
|
||||||
|
// crc = MODBUS_RTU_CRC16(BUFF, len);
|
||||||
|
// crc = htons(crc);
|
||||||
|
|
||||||
|
// memmove(BUFF + len, &crc, 2);
|
||||||
|
// len += 2;
|
||||||
|
|
||||||
|
// if(req->id != 0)
|
||||||
|
// {
|
||||||
|
// // 发送应答
|
||||||
|
// RS485_SendDataByte(BUFF, len);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 任务主体
|
||||||
|
void ReadModbus_Task(uint8_t c)
|
||||||
|
{
|
||||||
|
static uint8_t BUFF[sizeof(modbus_request_t)] = {0};
|
||||||
|
static uint8_t len = 0;
|
||||||
|
|
||||||
|
// 取数据
|
||||||
|
BUFF[len++] = c;
|
||||||
|
|
||||||
|
// 验证长度和CRC值
|
||||||
|
if(len == sizeof(modbus_request_t))
|
||||||
|
{
|
||||||
|
if(MODBUS_RTU_CRC16(BUFF, sizeof(modbus_request_t)) == 0)
|
||||||
|
{
|
||||||
|
MODBUS_RTU_CMD((modbus_request_t *) BUFF);
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 丢掉第一个字节
|
||||||
|
memmove(BUFF, BUFF + 1, --len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -735,7 +735,7 @@ void RF_GatewayTask(void *p_arg)
|
||||||
if(RTC_offsetSeconds == 0)
|
if(RTC_offsetSeconds == 0)
|
||||||
{
|
{
|
||||||
printf("\nRTC_offsetSeconds = 0, ignored ...\n");
|
printf("\nRTC_offsetSeconds = 0, ignored ...\n");
|
||||||
//apex continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理帧
|
// 处理帧
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue