Базово всё запущено. Датчики считываются записываются в модбас регистры, и по запросу выдаются.
Есть запас на 27-30 датчиков
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
/* Includes ----------------------------------------------------------------*/
|
||||
|
||||
#include "pch_sensors.h"
|
||||
#include "modbus_data.h"
|
||||
PCHSens_DallasBusHandle DallasBus;
|
||||
PCHSens_SensorActionsTypeDef action;
|
||||
|
||||
@@ -111,8 +112,7 @@ HAL_StatusTypeDef PCHSens_InitModule(DALLAS_HandleTypeDef *hdallas, PCHSens_Modu
|
||||
PCHSens_AddSensor(hdallas, &module->sens1);
|
||||
|
||||
module->sens2.Location.all = module->refLocation.all;
|
||||
module->sens2.Location.param.Location = 1;
|
||||
|
||||
module->sens2.Location.param.Location = 1;
|
||||
PCHSens_AddSensor(hdallas, &module->sens2);
|
||||
|
||||
module->sens3.Location.all = module->refLocation.all;
|
||||
@@ -126,13 +126,13 @@ HAL_StatusTypeDef PCHSens_InitModule(DALLAS_HandleTypeDef *hdallas, PCHSens_Modu
|
||||
}
|
||||
|
||||
|
||||
HAL_StatusTypeDef PCHSens_ReadTemperature(PCHSens_ModuleTypeDef *module)
|
||||
HAL_StatusTypeDef PCHSens_ModuleHandleAction(PCHSens_ModuleTypeDef* module)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
if(module == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
|
||||
result = PCHSens_SensorHandleActions(module->hdallas, &module->sens1);
|
||||
result = PCHSens_SensorHandleActions(module->hdallas, &module->sens2);
|
||||
result = PCHSens_SensorHandleActions(module->hdallas, &module->sens3);
|
||||
@@ -140,15 +140,25 @@ HAL_StatusTypeDef PCHSens_ReadTemperature(PCHSens_ModuleTypeDef *module)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef PCHSens_Covert(PCHSens_DallasBusHandle *hbus)
|
||||
{
|
||||
return Dallas_StartConvertTAll(hbus->hdallas, DALLAS_WAIT_BUS, 0);
|
||||
}
|
||||
HAL_StatusTypeDef PCHSens_ReadTemperature(PCHSens_SensorTypeDef* sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
result = Dallas_ReadTemperature(&sensor->sens);
|
||||
PCHSens_StoreToModbus(sensor);
|
||||
|
||||
return result;
|
||||
}
|
||||
HAL_StatusTypeDef PCHSens_CheckSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_SensorTypeDef* sensor)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
PCHSens_LocationTypeDef initlocation;
|
||||
unsigned unknow_sensors_flag = 0;
|
||||
|
||||
if(sensor == NULL)
|
||||
@@ -158,7 +168,6 @@ HAL_StatusTypeDef PCHSens_CheckSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_Sen
|
||||
|
||||
if((sensor->sens.isLost == 1))
|
||||
{
|
||||
initlocation.param.Location = 0;
|
||||
if(Dallas_ReplaceLostedSensor(&sensor->sens) != HAL_OK)
|
||||
{
|
||||
sensor->not_found = 1;
|
||||
@@ -249,7 +258,7 @@ HAL_StatusTypeDef PCHSens_SensorHandleActions(DALLAS_HandleTypeDef *hdallas, PCH
|
||||
|
||||
if(action.read != NULL)
|
||||
{
|
||||
result = Dallas_ReadTemperature(&sensor->sens);
|
||||
result = PCHSens_ReadTemperature(sensor);
|
||||
if(result != HAL_OK)
|
||||
PCHSens_CheckSensor(hdallas, sensor);
|
||||
}
|
||||
@@ -275,30 +284,30 @@ void PCHSens_FirstInit(void)
|
||||
|
||||
DallasBus.hdallas = &hdallas1;
|
||||
DallasBus.hdallas->onewire = &OW;
|
||||
|
||||
|
||||
|
||||
PCHSens_InitModule(&hdallas1, &module1, REG_PCH_NUMB_11|REG_PCH_DIODE_NUMB_1);
|
||||
PCHSens_InitModule(&hdallas1, &module2, REG_PCH_NUMB_12|REG_PCH_DIODE_NUMB_1);
|
||||
PCHSens_InitModule(&hdallas1, &module3, REG_PCH_NUMB_13|REG_PCH_DIODE_NUMB_1);
|
||||
PCHSens_InitModule(&hdallas1, &module4, REG_PCH_NUMB_21|REG_PCH_DIODE_NUMB_1);
|
||||
PCHSens_InitModule(&hdallas1, &module5, REG_PCH_NUMB_22|REG_PCH_DIODE_NUMB_1);
|
||||
PCHSens_InitModule(&hdallas1, &module6, REG_PCH_NUMB_23|REG_PCH_DIODE_NUMB_1);
|
||||
|
||||
PCHSens_FindUnknownSensors(&DallasBus);
|
||||
// PCHSens_DefineUnknownSensor(&UnknownSensors, NULL);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.outdoor, 0);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.indoor, 2);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.bathroom, 1);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.kitchen, 3);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.big_room, 4);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.small_room, 5);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.living_room, 6);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.basement, 7);
|
||||
//
|
||||
// uint8_t mask = DALLAS_USER_BYTE_ALL;
|
||||
// Dallas_WriteUserBytes(&AllSens.outdoor, 1, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.indoor, 2, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.bathroom, 3, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.kitchen, 4, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.big_room, 5, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.small_room, 6, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.living_room, 7, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.basement, 8, NULL, mask);
|
||||
}
|
||||
|
||||
|
||||
void PCHSens_StoreToModbus(PCHSens_SensorTypeDef *sensor)
|
||||
{
|
||||
uint8_t pch_numb = (sensor->Location.param.PCHdig1 - 1)*3 + (sensor->Location.param.PCHdig2 - 1);
|
||||
uint8_t location = (sensor->Location.param.Location);
|
||||
|
||||
uint8_t mb_location = pch_numb*4 + location;
|
||||
|
||||
if (mb_location < DS18B20_DEVICE_AMOUNT)
|
||||
MB_DATA.InRegs.SensTemperature[mb_location] = sensor->sens.temperature*100;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user