добавил gui
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
@@ -434,9 +434,18 @@ void reinit_t_sens(void)
|
||||
// sens[i].Init.InitParam.ROM = rom_address;
|
||||
sens[i].Init.InitParam.Ind = i;
|
||||
sens[i].Init.init_func = &Dallas_SensorInitByInd;
|
||||
sens[i].Init.Resolution = DALLAS_CONFIG_9_BITS;
|
||||
MB_DATA.HoldRegs.set_Temp[i] = sens[i].set_temp = 20.;
|
||||
MB_DATA.HoldRegs.set_hyst[i] = sens[i].hyst = 1;
|
||||
sens[i].Init.Resolution = DALLAS_CONFIG_9_BITS; sens[i].set_temp = 20.;
|
||||
sens[i].hyst = 1;
|
||||
MB_DATA.HoldRegs.set_Temp[i] = (uint16_t)(sens[i].set_temp * MB_ROOM_TEMP_SCALE);
|
||||
MB_DATA.HoldRegs.set_hyst[i] = (uint16_t)(sens[i].hyst * MB_ROOM_TEMP_SCALE);
|
||||
MB_DATA.HoldRegs.room_cfg[i].setpoint_x10 = MB_DATA.HoldRegs.set_Temp[i];
|
||||
MB_DATA.HoldRegs.room_cfg[i].hysteresis_x10 = MB_DATA.HoldRegs.set_hyst[i];
|
||||
MB_DATA.HoldRegs.room_cfg[i].valve_position_pct = 0;
|
||||
MB_DATA.HoldRegs.room_cfg[i].valve_angle_max_deg = MB_ROOM_VALVE_ANGLE_MAX_DEFAULT;
|
||||
MB_DATA.HoldRegs.room_cfg[i].mode = ROOM_MODE_AUTO;
|
||||
MB_DATA.HoldRegs.room_cfg[i].command = ROOM_COMMAND_STOP;
|
||||
MB_DATA.HoldRegs.room_cfg[i].location = 1;
|
||||
MB_DATA.HoldRegs.room_cfg[i].apply = 0;
|
||||
Dallas_AddNewSensors(&hdallas, &sens[i]);
|
||||
|
||||
}
|
||||
@@ -503,6 +512,70 @@ FuncStat packStruct(MB_DataStructureTypeDef* MB_DATA, int sizeARR)
|
||||
return FuncOK;
|
||||
|
||||
}
|
||||
|
||||
static uint16_t clamp_room_percent(uint16_t value)
|
||||
{
|
||||
return value > 100U ? 100U : value;
|
||||
}
|
||||
|
||||
static void update_room_modbus(MB_DataStructureTypeDef* MB_DATA)
|
||||
{
|
||||
for (int i = 0; i < MAX_SENSE; i++)
|
||||
{
|
||||
MB_RoomInputRegsTypeDef* room = &MB_DATA->InRegs.room[i];
|
||||
MB_RoomHoldingRegsTypeDef* cfg = &MB_DATA->HoldRegs.room_cfg[i];
|
||||
uint16_t open_state = 0U;
|
||||
uint16_t close_state = 0U;
|
||||
uint16_t position_pct;
|
||||
uint16_t angle_max;
|
||||
|
||||
if (cfg->valve_angle_max_deg == 0U)
|
||||
{
|
||||
cfg->valve_angle_max_deg = MB_ROOM_VALVE_ANGLE_MAX_DEFAULT;
|
||||
}
|
||||
|
||||
if (i < 16)
|
||||
{
|
||||
open_state = (MB_DATA->Coils.relay_struct_on.all >> i) & 0x1U;
|
||||
close_state = (MB_DATA->Coils.relay_struct_off.all >> i) & 0x1U;
|
||||
}
|
||||
|
||||
position_pct = clamp_room_percent(cfg->valve_position_pct);
|
||||
if (cfg->mode == ROOM_MODE_AUTO)
|
||||
{
|
||||
if (open_state)
|
||||
{
|
||||
position_pct = 100U;
|
||||
}
|
||||
else if (close_state)
|
||||
{
|
||||
position_pct = 0U;
|
||||
}
|
||||
}
|
||||
cfg->valve_position_pct = position_pct;
|
||||
angle_max = cfg->valve_angle_max_deg;
|
||||
|
||||
room->channel = (uint16_t)(i + 1);
|
||||
room->location = cfg->location;
|
||||
for (int reg = 0; reg < 4; reg++)
|
||||
{
|
||||
room->ds18b20_id[reg] = ((uint16_t)MB_DATA->InRegs.ID.DevAddr[i][reg * 2]) |
|
||||
((uint16_t)MB_DATA->InRegs.ID.DevAddr[i][reg * 2 + 1] << 8);
|
||||
}
|
||||
room->temperature_x10 = (i < hdallas.onewire->RomCnt) ? (uint16_t)((int16_t)(sens[i].temperature * MB_ROOM_TEMP_SCALE)) : 0U;
|
||||
room->setpoint_x10 = MB_DATA->HoldRegs.set_Temp[i];
|
||||
room->hysteresis_x10 = MB_DATA->HoldRegs.set_hyst[i];
|
||||
room->valve_position_pct = position_pct;
|
||||
room->valve_angle_deg = (uint16_t)((position_pct * angle_max) / 100U);
|
||||
room->valve_angle_max_deg = angle_max;
|
||||
room->is_connected = (i < hdallas.onewire->RomCnt) ? (uint16_t)sens[i].isConnected : 0U;
|
||||
room->valve_open = open_state;
|
||||
room->valve_close = close_state;
|
||||
room->mode = cfg->mode;
|
||||
room->command_state = cfg->command;
|
||||
room->reserved = 0U;
|
||||
}
|
||||
}
|
||||
FuncStat Field_modbus(MB_DataStructureTypeDef* MB_DATA, Flags_TypeDef* flag)
|
||||
{
|
||||
|
||||
@@ -516,15 +589,23 @@ FuncStat Field_modbus(MB_DataStructureTypeDef* MB_DATA, Flags_TypeDef* flag)
|
||||
|
||||
MB_DATA->Coils.init_param = 0;
|
||||
for(int i = 0; i < hdallas.onewire->RomCnt; i++)
|
||||
{
|
||||
sens[i].set_temp = MB_DATA->HoldRegs.set_Temp[i];
|
||||
sens[i].hyst = MB_DATA->HoldRegs.set_hyst[i];
|
||||
{ if (MB_DATA->HoldRegs.room_cfg[i].apply)
|
||||
{
|
||||
MB_DATA->HoldRegs.set_Temp[i] = MB_DATA->HoldRegs.room_cfg[i].setpoint_x10;
|
||||
MB_DATA->HoldRegs.set_hyst[i] = MB_DATA->HoldRegs.room_cfg[i].hysteresis_x10;
|
||||
MB_DATA->HoldRegs.room_cfg[i].apply = 0U;
|
||||
}
|
||||
MB_DATA->HoldRegs.room_cfg[i].setpoint_x10 = MB_DATA->HoldRegs.set_Temp[i];
|
||||
MB_DATA->HoldRegs.room_cfg[i].hysteresis_x10 = MB_DATA->HoldRegs.set_hyst[i];
|
||||
sens[i].set_temp = ((float)MB_DATA->HoldRegs.set_Temp[i]) / MB_ROOM_TEMP_SCALE;
|
||||
sens[i].hyst = ((float)MB_DATA->HoldRegs.set_hyst[i]) / MB_ROOM_TEMP_SCALE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
update_room_modbus(MB_DATA);
|
||||
return FuncOK;
|
||||
};
|
||||
|
||||
@@ -534,6 +615,31 @@ FuncStat value_control(void )
|
||||
|
||||
for(int i = 0; i < hdallas.onewire->RomCnt; i++)
|
||||
{
|
||||
if (i < 16 && MB_DATA.HoldRegs.room_cfg[i].mode == ROOM_MODE_MANUAL)
|
||||
{
|
||||
uint16_t manual_pct = clamp_room_percent(MB_DATA.HoldRegs.room_cfg[i].valve_position_pct);
|
||||
if (MB_DATA.HoldRegs.room_cfg[i].command == ROOM_COMMAND_CLOSE)
|
||||
{
|
||||
manual_pct = 0U;
|
||||
}
|
||||
else if (MB_DATA.HoldRegs.room_cfg[i].command == ROOM_COMMAND_OPEN && manual_pct == 0U)
|
||||
{
|
||||
manual_pct = 100U;
|
||||
}
|
||||
MB_DATA.HoldRegs.room_cfg[i].valve_position_pct = manual_pct;
|
||||
if (manual_pct > 0U)
|
||||
{
|
||||
MB_DATA.Coils.relay_struct_off.all &= ~(1 << i);
|
||||
MB_DATA.Coils.relay_struct_on.all |= 1 << i;
|
||||
}
|
||||
else
|
||||
{
|
||||
MB_DATA.Coils.relay_struct_on.all &= ~(1 << i);
|
||||
MB_DATA.Coils.relay_struct_off.all |= 1 << i;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sens[i].temperature < sens[i].set_temp - sens[i].hyst)
|
||||
|
||||
{
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -21,7 +21,7 @@ Target DLL: UL2CM3.DLL V1.164.14.0
|
||||
Dialog DLL: TCM.DLL V1.56.4.0
|
||||
|
||||
<h2>Project:</h2>
|
||||
F:\set\workspace\setcorp\set506\git_project\ds128b20\new rev\john103C8T6\MDK-ARM\john103C8T6.uvprojx
|
||||
F:\set\workspace\setcorp\set506\git_project\ds128b20\john_proj\ds18b20-MODBUS\new rev\john103C8T6\MDK-ARM\john103C8T6.uvprojx
|
||||
Project File Date: 05/28/2026
|
||||
|
||||
<h2>Output:</h2>
|
||||
@@ -49,7 +49,7 @@ Package Vendor: Keil
|
||||
<h2>Collection of Component Files used:</h2>
|
||||
|
||||
* Component: ::CMSIS Driver:Flash(API)@2.3.0
|
||||
Build Time Elapsed: 00:00:00
|
||||
Build Time Elapsed: 00:00:01
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file modbus_data.h
|
||||
* @brief Заголовочный файл с описанием даты MODBUS.
|
||||
@@ -105,6 +105,21 @@
|
||||
*
|
||||
*/
|
||||
#define mb_fill_rsv(_align_, _struct_) ((_align_ > mb_sizeof(_struct_)) ? (_align_ - mb_sizeof(_struct_)) : 0)
|
||||
#define mb_fill_gap(_from_, _to_, _struct_) (((_to_) > ((_from_) + mb_sizeof(_struct_))) ? ((_to_) - (_from_) - mb_sizeof(_struct_)) : 0)
|
||||
|
||||
#define R_INPUT_ROOM_ADDR 400
|
||||
#define R_INPUT_ID_ADDR 1000
|
||||
#define R_INPUT_NUM_TSENS_ADDR 1200
|
||||
#define R_HOLDING_HYST_ADDR 100
|
||||
#define R_HOLDING_ROOM_ADDR 300
|
||||
|
||||
#define MB_ROOM_TEMP_SCALE 10U
|
||||
#define MB_ROOM_VALVE_ANGLE_MAX_DEFAULT 90U
|
||||
#define ROOM_MODE_AUTO 0U
|
||||
#define ROOM_MODE_MANUAL 1U
|
||||
#define ROOM_COMMAND_STOP 0U
|
||||
#define ROOM_COMMAND_OPEN 1U
|
||||
#define ROOM_COMMAND_CLOSE 2U
|
||||
|
||||
|
||||
|
||||
@@ -124,6 +139,38 @@ typedef __PACKED_STRUCT
|
||||
uint16_t status;
|
||||
} MB_RtcCalendarRegsTypeDef;
|
||||
|
||||
typedef __PACKED_STRUCT
|
||||
{
|
||||
uint16_t channel;
|
||||
uint16_t location;
|
||||
uint16_t ds18b20_id[4];
|
||||
uint16_t temperature_x10;
|
||||
uint16_t setpoint_x10;
|
||||
uint16_t hysteresis_x10;
|
||||
uint16_t valve_position_pct;
|
||||
uint16_t valve_angle_deg;
|
||||
uint16_t valve_angle_max_deg;
|
||||
uint16_t is_connected;
|
||||
uint16_t valve_open;
|
||||
uint16_t valve_close;
|
||||
uint16_t mode;
|
||||
uint16_t command_state;
|
||||
uint16_t reserved;
|
||||
} MB_RoomInputRegsTypeDef;
|
||||
|
||||
|
||||
typedef __PACKED_STRUCT
|
||||
{
|
||||
uint16_t setpoint_x10;
|
||||
uint16_t hysteresis_x10;
|
||||
uint16_t valve_position_pct;
|
||||
uint16_t valve_angle_max_deg;
|
||||
uint16_t mode;
|
||||
uint16_t command;
|
||||
uint16_t location;
|
||||
uint16_t apply;
|
||||
} MB_RoomHoldingRegsTypeDef;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -132,9 +179,11 @@ typedef __PACKED_STRUCT//MB_DataInRegsTypeDef
|
||||
{
|
||||
|
||||
uint16_t sens_Temp[MAX_SENSE];
|
||||
uint16_t reserve[mb_fill_rsv(1000, uint16_t[MAX_SENSE])];
|
||||
uint16_t reserve_to_room[mb_fill_rsv(R_INPUT_ROOM_ADDR, uint16_t[MAX_SENSE])];
|
||||
MB_RoomInputRegsTypeDef room[MAX_SENSE];
|
||||
uint16_t reserve_to_id[mb_fill_gap(R_INPUT_ROOM_ADDR, R_INPUT_ID_ADDR, MB_RoomInputRegsTypeDef[MAX_SENSE])];
|
||||
DS18B20_Drv_t ID;
|
||||
uint16_t reserve1[mb_fill_rsv(200, DS18B20_Drv_t)];
|
||||
uint16_t reserve_to_num_tsens[mb_fill_gap(R_INPUT_ID_ADDR, R_INPUT_NUM_TSENS_ADDR, DS18B20_Drv_t)];
|
||||
uint16_t num_Tsens;
|
||||
MB_RtcCalendarRegsTypeDef rtc;
|
||||
|
||||
@@ -148,10 +197,12 @@ typedef __PACKED_STRUCT//MB_DataInRegsTypeDef
|
||||
typedef __PACKED_STRUCT //MB_DataInRegsTypeDef
|
||||
{
|
||||
uint16_t set_Temp[MAX_SENSE];
|
||||
uint16_t reserve[mb_fill_rsv(100, uint16_t[MAX_SENSE])];
|
||||
uint16_t reserve_to_hyst[mb_fill_rsv(R_HOLDING_HYST_ADDR, uint16_t[MAX_SENSE])];
|
||||
uint16_t set_hyst[MAX_SENSE];
|
||||
uint16_t reserve1[mb_fill_rsv(100, uint16_t[MAX_SENSE])];
|
||||
uint16_t reserve_to_rtc[mb_fill_gap(R_HOLDING_HYST_ADDR, R_HOLDING_RTC_ADDR, uint16_t[MAX_SENSE])];
|
||||
MB_RtcCalendarRegsTypeDef rtc;
|
||||
uint16_t reserve_to_room_cfg[mb_fill_gap(R_HOLDING_RTC_ADDR, R_HOLDING_ROOM_ADDR, MB_RtcCalendarRegsTypeDef)];
|
||||
MB_RoomHoldingRegsTypeDef room_cfg[MAX_SENSE];
|
||||
} MB_DataHoldRegsTypeDef;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user