Добавлен функция скана всех сенсоров на линии через модбас
Заполнение респонса в модбас выведено в отдельную функцию
This commit is contained in:
@@ -112,7 +112,7 @@ HAL_StatusTypeDef Dallas_SensorInitByROM(DALLAS_HandleTypeDef *hdallas, DALLAS_S
|
|||||||
comparebytes = DALLAS_ROM_SIZE;
|
comparebytes = DALLAS_ROM_SIZE;
|
||||||
for(int rom_byte = 0; rom_byte < DALLAS_ROM_SIZE; rom_byte++)
|
for(int rom_byte = 0; rom_byte < DALLAS_ROM_SIZE; rom_byte++)
|
||||||
{
|
{
|
||||||
if(DS.DevAddr[i][rom_byte] == ROM[rom_byte])
|
if(hdallas->ds_devices->DevAddr[i][rom_byte] == ROM[rom_byte])
|
||||||
comparebytes--;
|
comparebytes--;
|
||||||
}
|
}
|
||||||
if(comparebytes == 0)
|
if(comparebytes == 0)
|
||||||
@@ -126,7 +126,7 @@ HAL_StatusTypeDef Dallas_SensorInitByROM(DALLAS_HandleTypeDef *hdallas, DALLAS_S
|
|||||||
if(comparebytes == 0)
|
if(comparebytes == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
result = Dallas_SensorInit(hdallas, sensor, &DS.DevAddr[ROM_ind]);
|
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices->DevAddr[ROM_ind]);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -164,7 +164,7 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(DALLAS_HandleTypeDef *hdallas, DA
|
|||||||
for(int i = 0; i < hdallas->onewire->RomCnt; i++)
|
for(int i = 0; i < hdallas->onewire->RomCnt; i++)
|
||||||
{
|
{
|
||||||
/* Проверка присутствует ли выбранный датчик на линии */
|
/* Проверка присутствует ли выбранный датчик на линии */
|
||||||
result = DS18B20_ReadScratchpad(hdallas->onewire, (uint8_t *)&DS.DevAddr[i], (uint8_t *)&hdallas->scratchpad);
|
result = DS18B20_ReadScratchpad(hdallas->onewire, (uint8_t *)&hdallas->ds_devices->DevAddr[i], (uint8_t *)&hdallas->scratchpad);
|
||||||
if (result != HAL_OK)
|
if (result != HAL_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(DALLAS_HandleTypeDef *hdallas, DA
|
|||||||
{
|
{
|
||||||
// sensor->isInitialized = 1;
|
// sensor->isInitialized = 1;
|
||||||
// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
||||||
result = Dallas_SensorInit(hdallas, sensor, &DS.DevAddr[i]);
|
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices->DevAddr[i]);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,7 +226,7 @@ HAL_StatusTypeDef Dallas_SensorInitByInd(DALLAS_HandleTypeDef *hdallas, DALLAS_S
|
|||||||
if(sensor == NULL)
|
if(sensor == NULL)
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
|
|
||||||
result = Dallas_SensorInit(hdallas, sensor, &DS.DevAddr[sensor->Init.InitParam]);
|
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices->DevAddr[sensor->Init.InitParam]);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ typedef struct __packed
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
OneWire_t *onewire;
|
OneWire_t *onewire;
|
||||||
|
DS18B20_Drv_t *ds_devices;
|
||||||
DALLAS_ScratchpadTypeDef scratchpad;
|
DALLAS_ScratchpadTypeDef scratchpad;
|
||||||
}DALLAS_HandleTypeDef;
|
}DALLAS_HandleTypeDef;
|
||||||
extern DALLAS_HandleTypeDef hdallas1;
|
extern DALLAS_HandleTypeDef hdallas1;
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ typedef enum {
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t DevAddr[DS18B20_DEVICE_AMOUNT][8];
|
uint8_t DevAddr[DS18B20_DEVICE_AMOUNT][8];
|
||||||
DS18B20_Res_t Resolution;
|
|
||||||
} DS18B20_Drv_t;
|
} DS18B20_Drv_t;
|
||||||
extern DS18B20_Drv_t DS;
|
extern DS18B20_Drv_t DS;
|
||||||
extern OneWire_t OW;
|
extern OneWire_t OW;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ void OneWire_WriteBit(OneWire_t* OW, uint8_t bit)
|
|||||||
if(OW == NULL)
|
if(OW == NULL)
|
||||||
return;
|
return;
|
||||||
#ifndef ONEWIRE_UART_H
|
#ifndef ONEWIRE_UART_H
|
||||||
|
__disable_irq();
|
||||||
if(bit)
|
if(bit)
|
||||||
{
|
{
|
||||||
/* Set line low */
|
/* Set line low */
|
||||||
@@ -46,6 +47,7 @@ void OneWire_WriteBit(OneWire_t* OW, uint8_t bit)
|
|||||||
OneWire_Delay_uw(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_WRITE_0_US);
|
OneWire_Delay_uw(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_WRITE_0_US);
|
||||||
OneWire_Pin_Mode(OW, Input);
|
OneWire_Pin_Mode(OW, Input);
|
||||||
}
|
}
|
||||||
|
__enable_irq();
|
||||||
#else
|
#else
|
||||||
OneWireUART_ProcessBit(onewire_uart, bit);
|
OneWireUART_ProcessBit(onewire_uart, bit);
|
||||||
#endif
|
#endif
|
||||||
@@ -61,6 +63,7 @@ uint8_t OneWire_ReadBit(OneWire_t* OW)
|
|||||||
if(OW == NULL)
|
if(OW == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
__disable_irq();
|
||||||
uint8_t bit = 0;
|
uint8_t bit = 0;
|
||||||
#ifndef ONEWIRE_UART_H
|
#ifndef ONEWIRE_UART_H
|
||||||
/* Line low */
|
/* Line low */
|
||||||
@@ -77,6 +80,7 @@ uint8_t OneWire_ReadBit(OneWire_t* OW)
|
|||||||
|
|
||||||
/* Wait 50us to complete 60us period */
|
/* Wait 50us to complete 60us period */
|
||||||
OneWire_Delay_uw(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_READ_CMD_US - ONEWIRE_READ_DELAY_US);
|
OneWire_Delay_uw(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_READ_CMD_US - ONEWIRE_READ_DELAY_US);
|
||||||
|
__enable_irq();
|
||||||
#else
|
#else
|
||||||
bit = OneWireUART_ProcessBit(onewire_uart, 1);
|
bit = OneWireUART_ProcessBit(onewire_uart, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -287,6 +287,9 @@ MB_ExceptionTypeDef MB_DefineRegistersAddress(uint16_t **pRegs, uint16_t Addr, u
|
|||||||
else if(MB_Check_Address_For_Arr(Addr, Qnt, R_SENS_PARAMS_ADDR, R_SENS_PARAMS_QNT) == NO_ERRORS)
|
else if(MB_Check_Address_For_Arr(Addr, Qnt, R_SENS_PARAMS_ADDR, R_SENS_PARAMS_QNT) == NO_ERRORS)
|
||||||
{
|
{
|
||||||
*pRegs = MB_Set_Register_Ptr(&MB_DATA.InRegs, Addr); // начало регистров хранения/входных
|
*pRegs = MB_Set_Register_Ptr(&MB_DATA.InRegs, Addr); // начало регистров хранения/входных
|
||||||
|
// икрементирвоание счетчика скана, для вывода всех датчиков на линии в модбас структуру
|
||||||
|
extern void PYModule_IncrementScanSensor(void);
|
||||||
|
PYModule_IncrementScanSensor();
|
||||||
}
|
}
|
||||||
// if address doesnt match any array - return illegal data address response
|
// if address doesnt match any array - return illegal data address response
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ typedef struct //MB_DataInRegsTypeDef
|
|||||||
// DEFINES FOR INPUT REGISTERS ARRAYS
|
// DEFINES FOR INPUT REGISTERS ARRAYS
|
||||||
#define R_TEMPERATURE_ADDR (0)
|
#define R_TEMPERATURE_ADDR (0)
|
||||||
#define R_TEMPERATURE_QNT (DS18B20_DEVICE_AMOUNT)
|
#define R_TEMPERATURE_QNT (DS18B20_DEVICE_AMOUNT)
|
||||||
#define R_SENS_PARAMS_ADDR (DS18B20_DEVICE_AMOUNT+1)
|
#define R_SENS_PARAMS_ADDR (DS18B20_DEVICE_AMOUNT)
|
||||||
#define R_SENS_PARAMS_QNT (sizeof(MB_SensorParamsTypeDef)/sizeof(uint16_t))
|
#define R_SENS_PARAMS_QNT (sizeof(MB_SensorParamsTypeDef)/sizeof(uint16_t))
|
||||||
|
|
||||||
// DEFINES FOR HOLDING REGISTERS ARRAYS
|
// DEFINES FOR HOLDING REGISTERS ARRAYS
|
||||||
@@ -112,8 +112,9 @@ typedef struct //MB_DataCoilsTypeDef
|
|||||||
unsigned ReadSensor:1;
|
unsigned ReadSensor:1;
|
||||||
unsigned InitSensor:1;
|
unsigned InitSensor:1;
|
||||||
unsigned DeInitSensor:1;
|
unsigned DeInitSensor:1;
|
||||||
|
unsigned ScanSensors:1;
|
||||||
|
|
||||||
unsigned reserved:13;
|
unsigned reserved:11;
|
||||||
|
|
||||||
/* reg 2 - settings */
|
/* reg 2 - settings */
|
||||||
unsigned ConvertionDone:1;
|
unsigned ConvertionDone:1;
|
||||||
|
|||||||
@@ -12,8 +12,13 @@
|
|||||||
|
|
||||||
/* Declarations and definitions --------------------------------------------*/
|
/* Declarations and definitions --------------------------------------------*/
|
||||||
PCHSens_TypeDef pchsens;
|
PCHSens_TypeDef pchsens;
|
||||||
|
PCHSens_DallasBusHandle DallasBus;
|
||||||
|
static uint8_t scan_cnt;
|
||||||
|
|
||||||
/* Functions ---------------------------------------------------------------*/
|
/* Functions ---------------------------------------------------------------*/
|
||||||
|
void PYModule_FillResponse(PCHSens_SensorTypeDef* sensor, Sensor_ResponseStatusTypeDef status);
|
||||||
|
void PYModule_CheckModuleLosted(PCHSens_ModuleTypeDef *module, uint8_t *losted_flag);
|
||||||
|
void PYModule_StoreModuleToModbus(PCHSens_ModuleTypeDef *module);
|
||||||
|
|
||||||
void PYModule_main(void)
|
void PYModule_main(void)
|
||||||
{
|
{
|
||||||
@@ -27,10 +32,13 @@ void PYModule_main(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(MB_DATA.Coils.ReadSensor)
|
if(MB_DATA.Coils.ScanSensors)
|
||||||
{
|
{
|
||||||
PYModule_ReadSensor(&hdallas1, &pchsens);
|
PYModule_ScanSensor(&DallasBus);
|
||||||
MB_DATA.Coils.ReadSensor = 0;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scan_cnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(MB_DATA.Coils.InitSensor)
|
if(MB_DATA.Coils.InitSensor)
|
||||||
@@ -47,7 +55,6 @@ void PYModule_main(void)
|
|||||||
|
|
||||||
PYModule_CheckLosted(&pchsens);
|
PYModule_CheckLosted(&pchsens);
|
||||||
|
|
||||||
|
|
||||||
if(MB_DATA.Coils.RunConvertions)
|
if(MB_DATA.Coils.RunConvertions)
|
||||||
{
|
{
|
||||||
if(DS18B20_WaitForEndConvertion_NonBlocking(hdallas1.onewire) == HAL_OK)
|
if(DS18B20_WaitForEndConvertion_NonBlocking(hdallas1.onewire) == HAL_OK)
|
||||||
@@ -70,7 +77,6 @@ void PYModule_FirstInit(void)
|
|||||||
{
|
{
|
||||||
OW.DataPin = DS_Pin;
|
OW.DataPin = DS_Pin;
|
||||||
OW.DataPort = DS_GPIO_Port;
|
OW.DataPort = DS_GPIO_Port;
|
||||||
DS.Resolution = DS18B20_RESOLUTION_9BITS;
|
|
||||||
|
|
||||||
/* Инициализация onewire и поиск датчиков*/
|
/* Инициализация onewire и поиск датчиков*/
|
||||||
OneWire_Init(&OW);
|
OneWire_Init(&OW);
|
||||||
@@ -84,6 +90,7 @@ void PYModule_FirstInit(void)
|
|||||||
/* Инициализация структур датчиков ПЧ */
|
/* Инициализация структур датчиков ПЧ */
|
||||||
DallasBus.hdallas = &hdallas1;
|
DallasBus.hdallas = &hdallas1;
|
||||||
DallasBus.hdallas->onewire = &OW;
|
DallasBus.hdallas->onewire = &OW;
|
||||||
|
DallasBus.hdallas->ds_devices = &DS;
|
||||||
PCHSens_InitModule(&hdallas1, &pchsens.module1, REG_PCH_NUMB_11|REG_PCH_DIODE_NUMB_1);
|
PCHSens_InitModule(&hdallas1, &pchsens.module1, REG_PCH_NUMB_11|REG_PCH_DIODE_NUMB_1);
|
||||||
PCHSens_InitModule(&hdallas1, &pchsens.module2, REG_PCH_NUMB_12|REG_PCH_DIODE_NUMB_1);
|
PCHSens_InitModule(&hdallas1, &pchsens.module2, REG_PCH_NUMB_12|REG_PCH_DIODE_NUMB_1);
|
||||||
PCHSens_InitModule(&hdallas1, &pchsens.module3, REG_PCH_NUMB_13|REG_PCH_DIODE_NUMB_1);
|
PCHSens_InitModule(&hdallas1, &pchsens.module3, REG_PCH_NUMB_13|REG_PCH_DIODE_NUMB_1);
|
||||||
@@ -98,7 +105,33 @@ void PYModule_FirstInit(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PYModule_ScanSensor(PCHSens_DallasBusHandle *hbus)
|
||||||
|
{
|
||||||
|
PCHSens_SensorTypeDef sensor;
|
||||||
|
sensor.sens.hdallas = hbus->hdallas;
|
||||||
|
sensor.sens.sensROM = *(uint64_t *)(hbus->hdallas->ds_devices->DevAddr[scan_cnt]);
|
||||||
|
if (scan_cnt >= hbus->hdallas->onewire->RomCnt)
|
||||||
|
{
|
||||||
|
scan_cnt = hbus->hdallas->onewire->RomCnt;
|
||||||
|
PYModule_FillResponse(&sensor, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(Dallas_ReadScratchpad(&sensor.sens) == HAL_OK)
|
||||||
|
{
|
||||||
|
PYModule_FillResponse(&sensor, STATUS_OK);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PYModule_FillResponse(&sensor, STATUS_ERR_SCAN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void PYModule_IncrementScanSensor(void)
|
||||||
|
{
|
||||||
|
if(MB_DATA.Coils.ScanSensors)
|
||||||
|
{
|
||||||
|
scan_cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
void PYModule_ReadSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_TypeDef *pchsens)
|
void PYModule_ReadSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_TypeDef *pchsens)
|
||||||
{
|
{
|
||||||
// чтение по локации
|
// чтение по локации
|
||||||
@@ -111,48 +144,28 @@ void PYModule_ReadSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_TypeDef *pchsens
|
|||||||
|
|
||||||
if(Dallas_ReadScratchpad(&sensor->sens) == HAL_OK)
|
if(Dallas_ReadScratchpad(&sensor->sens) == HAL_OK)
|
||||||
{
|
{
|
||||||
MB_DATA.InRegs.Response.Location = *(uint16_t *)&sensor->sens.hdallas->scratchpad.tHighRegister;
|
PYModule_FillResponse(sensor, STATUS_OK);
|
||||||
MB_DATA.InRegs.Response.Config = sensor->sens.hdallas->scratchpad.ConfigRegister;
|
|
||||||
MB_DATA.InRegs.Response.ROM[0] = __REV16((sensor->sens.sensROM) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.ROM[1] = __REV16((sensor->sens.sensROM >> 16) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.ROM[2] = __REV16((sensor->sens.sensROM >> 32) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.ROM[3] = __REV16((sensor->sens.sensROM >> 48) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.Status = 0x1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MB_DATA.InRegs.Response.Location = MB_DATA.HoldRegs.InitStruct.Location;
|
PYModule_FillResponse(sensor, STATUS_ERR_READ_LOCATION);
|
||||||
MB_DATA.InRegs.Response.Config = 0;
|
|
||||||
MB_DATA.InRegs.Response.ROM[0] = 0;
|
|
||||||
MB_DATA.InRegs.Response.ROM[1] = 0;
|
|
||||||
MB_DATA.InRegs.Response.ROM[2] = 0;
|
|
||||||
MB_DATA.InRegs.Response.ROM[3] = 0;
|
|
||||||
MB_DATA.InRegs.Response.Status = 0xFF;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// чтение по ROM
|
// чтение по ROM
|
||||||
else if(MB_DATA.HoldRegs.InitStruct.ROM[0] | MB_DATA.HoldRegs.InitStruct.ROM[1] | // если РОМ не равен нулю
|
else if(MB_DATA.HoldRegs.InitStruct.ROM[0] | MB_DATA.HoldRegs.InitStruct.ROM[1] | // если РОМ не равен нулю
|
||||||
MB_DATA.HoldRegs.InitStruct.ROM[2] | MB_DATA.HoldRegs.InitStruct.ROM[3] != 0)
|
MB_DATA.HoldRegs.InitStruct.ROM[2] | MB_DATA.HoldRegs.InitStruct.ROM[3] != 0)
|
||||||
{
|
{
|
||||||
if(DS18B20_ReadScratchpad(hdallas->onewire, (uint8_t *)MB_DATA.HoldRegs.InitStruct.ROM, (uint8_t *)&hdallas->scratchpad) == HAL_OK)
|
PCHSens_SensorTypeDef sensor;
|
||||||
|
sensor.sens.hdallas = hdallas;
|
||||||
|
sensor.sens.sensROM = *(uint64_t *)MB_DATA.HoldRegs.InitStruct.ROM;
|
||||||
|
|
||||||
|
if(Dallas_ReadScratchpad(&sensor.sens) == HAL_OK)
|
||||||
{
|
{
|
||||||
MB_DATA.InRegs.Response.Location = *(uint16_t *)&hdallas->scratchpad.tHighRegister;
|
PYModule_FillResponse(&sensor, STATUS_OK);
|
||||||
MB_DATA.InRegs.Response.Config = hdallas->scratchpad.ConfigRegister;
|
|
||||||
MB_DATA.InRegs.Response.ROM[0] = MB_DATA.HoldRegs.InitStruct.ROM[0];
|
|
||||||
MB_DATA.InRegs.Response.ROM[1] = MB_DATA.HoldRegs.InitStruct.ROM[1];
|
|
||||||
MB_DATA.InRegs.Response.ROM[2] = MB_DATA.HoldRegs.InitStruct.ROM[2];
|
|
||||||
MB_DATA.InRegs.Response.ROM[3] = MB_DATA.HoldRegs.InitStruct.ROM[3];
|
|
||||||
MB_DATA.InRegs.Response.Status = 0x1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MB_DATA.InRegs.Response.Location = 0;
|
PYModule_FillResponse(&sensor, STATUS_ERR_READ_ROM);
|
||||||
MB_DATA.InRegs.Response.Config = 0;
|
|
||||||
MB_DATA.InRegs.Response.ROM[0] = MB_DATA.HoldRegs.InitStruct.ROM[0];
|
|
||||||
MB_DATA.InRegs.Response.ROM[1] = MB_DATA.HoldRegs.InitStruct.ROM[1];
|
|
||||||
MB_DATA.InRegs.Response.ROM[2] = MB_DATA.HoldRegs.InitStruct.ROM[2];
|
|
||||||
MB_DATA.InRegs.Response.ROM[3] = MB_DATA.HoldRegs.InitStruct.ROM[3];
|
|
||||||
MB_DATA.InRegs.Response.Status = 0xFF;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,23 +189,11 @@ void PYModule_InitSensor(PCHSens_TypeDef *pchsens)
|
|||||||
connectROM |= ((uint64_t)(MB_DATA.HoldRegs.InitStruct.ROM[3]));
|
connectROM |= ((uint64_t)(MB_DATA.HoldRegs.InitStruct.ROM[3]));
|
||||||
if(PCHSens_InitNewSensor(&hdallas1, sensor, connectROM) == HAL_OK)
|
if(PCHSens_InitNewSensor(&hdallas1, sensor, connectROM) == HAL_OK)
|
||||||
{
|
{
|
||||||
MB_DATA.InRegs.Response.Location = *(uint16_t *)&sensor->sens.hdallas->scratchpad.tHighRegister;
|
PYModule_FillResponse(sensor, STATUS_OK);
|
||||||
MB_DATA.InRegs.Response.Config = sensor->sens.hdallas->scratchpad.ConfigRegister;
|
|
||||||
MB_DATA.InRegs.Response.ROM[0] = __REV16((sensor->sens.sensROM) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.ROM[1] = __REV16((sensor->sens.sensROM >> 16) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.ROM[2] = __REV16((sensor->sens.sensROM >> 32) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.ROM[3] = __REV16((sensor->sens.sensROM >> 48) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.Status = 0x1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MB_DATA.InRegs.Response.Location = MB_DATA.HoldRegs.InitStruct.Location;
|
PYModule_FillResponse(sensor, STATUS_ERR_INIT);
|
||||||
MB_DATA.InRegs.Response.Config = 0;
|
|
||||||
MB_DATA.InRegs.Response.ROM[0] = MB_DATA.HoldRegs.InitStruct.ROM[0];
|
|
||||||
MB_DATA.InRegs.Response.ROM[1] = MB_DATA.HoldRegs.InitStruct.ROM[1];
|
|
||||||
MB_DATA.InRegs.Response.ROM[2] = MB_DATA.HoldRegs.InitStruct.ROM[2];
|
|
||||||
MB_DATA.InRegs.Response.ROM[3] = MB_DATA.HoldRegs.InitStruct.ROM[3];
|
|
||||||
MB_DATA.InRegs.Response.Status = 0xFF;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,38 +209,15 @@ void PYModule_DeInitSensor(PCHSens_TypeDef *pchsens)
|
|||||||
|
|
||||||
if(PCHSens_UndefineSensor(sensor) != HAL_OK)
|
if(PCHSens_UndefineSensor(sensor) != HAL_OK)
|
||||||
{
|
{
|
||||||
MB_DATA.InRegs.Response.Location = *(uint16_t *)&sensor->sens.hdallas->scratchpad.tHighRegister;
|
PYModule_FillResponse(sensor, STATUS_OK);
|
||||||
MB_DATA.InRegs.Response.Config = sensor->sens.hdallas->scratchpad.ConfigRegister;
|
|
||||||
MB_DATA.InRegs.Response.ROM[0] = __REV16((sensor->sens.sensROM) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.ROM[1] = __REV16((sensor->sens.sensROM >> 16) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.ROM[2] = __REV16((sensor->sens.sensROM >> 32) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.ROM[3] = __REV16((sensor->sens.sensROM >> 48) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.Status = 0xFF;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MB_DATA.InRegs.Response.Location = *(uint16_t *)&sensor->sens.hdallas->scratchpad.tHighRegister;
|
PYModule_FillResponse(sensor, STATUS_ERR_DEINIT);
|
||||||
MB_DATA.InRegs.Response.Config = sensor->sens.hdallas->scratchpad.ConfigRegister;
|
|
||||||
MB_DATA.InRegs.Response.ROM[0] = __REV16((sensor->sens.sensROM) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.ROM[1] = __REV16((sensor->sens.sensROM >> 16) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.ROM[2] = __REV16((sensor->sens.sensROM >> 32) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.ROM[3] = __REV16((sensor->sens.sensROM >> 48) & 0xFFFF);
|
|
||||||
MB_DATA.InRegs.Response.Status = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PYModule_CheckModuleLosted(PCHSens_ModuleTypeDef *module, uint8_t *losted_flag)
|
|
||||||
{
|
|
||||||
if(module->sens1.not_found)
|
|
||||||
*losted_flag |= 1;
|
|
||||||
if(module->sens2.not_found)
|
|
||||||
*losted_flag |= 1;
|
|
||||||
if(module->sens3.not_found)
|
|
||||||
*losted_flag |= 1;
|
|
||||||
if(module->sens4.not_found)
|
|
||||||
*losted_flag |= 1;
|
|
||||||
}
|
|
||||||
void PYModule_CheckLosted(PCHSens_TypeDef *pchsens)
|
void PYModule_CheckLosted(PCHSens_TypeDef *pchsens)
|
||||||
{
|
{
|
||||||
uint8_t losted = 0;
|
uint8_t losted = 0;
|
||||||
@@ -258,6 +236,119 @@ void PYModule_CheckLosted(PCHSens_TypeDef *pchsens)
|
|||||||
MB_DATA.Coils.LostedSensors = 0;
|
MB_DATA.Coils.LostedSensors = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PYModule_StoreModbus(PCHSens_TypeDef *pchsens)
|
||||||
|
{
|
||||||
|
uint8_t losted = 0;
|
||||||
|
|
||||||
|
// module1
|
||||||
|
PYModule_StoreModuleToModbus(&pchsens->module1);
|
||||||
|
PYModule_StoreModuleToModbus(&pchsens->module2);
|
||||||
|
PYModule_StoreModuleToModbus(&pchsens->module3);
|
||||||
|
PYModule_StoreModuleToModbus(&pchsens->module4);
|
||||||
|
PYModule_StoreModuleToModbus(&pchsens->module5);
|
||||||
|
PYModule_StoreModuleToModbus(&pchsens->module6);
|
||||||
|
|
||||||
|
MB_DATA.Coils.ConvertionDone |= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PYModule_FillResponse(PCHSens_SensorTypeDef* sensor, Sensor_ResponseStatusTypeDef status)
|
||||||
|
{
|
||||||
|
switch(status)
|
||||||
|
{
|
||||||
|
// successfull response
|
||||||
|
case STATUS_OK:
|
||||||
|
// fil with sensor data
|
||||||
|
MB_DATA.InRegs.Response.Location = *(uint16_t *)&sensor->sens.hdallas->scratchpad.tHighRegister;
|
||||||
|
MB_DATA.InRegs.Response.Config = sensor->sens.hdallas->scratchpad.ConfigRegister;
|
||||||
|
MB_DATA.InRegs.Response.ROM[0] = __REV16((sensor->sens.sensROM) & 0xFFFF);
|
||||||
|
MB_DATA.InRegs.Response.ROM[1] = __REV16((sensor->sens.sensROM >> 16) & 0xFFFF);
|
||||||
|
MB_DATA.InRegs.Response.ROM[2] = __REV16((sensor->sens.sensROM >> 32) & 0xFFFF);
|
||||||
|
MB_DATA.InRegs.Response.ROM[3] = __REV16((sensor->sens.sensROM >> 48) & 0xFFFF);
|
||||||
|
MB_DATA.InRegs.Response.Status = status;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// error read by location
|
||||||
|
case STATUS_ERR_READ_LOCATION:
|
||||||
|
// fill only location from holdreg
|
||||||
|
MB_DATA.InRegs.Response.Location = MB_DATA.HoldRegs.InitStruct.Location;
|
||||||
|
MB_DATA.InRegs.Response.Config = 0;
|
||||||
|
MB_DATA.InRegs.Response.ROM[0] = 0;
|
||||||
|
MB_DATA.InRegs.Response.ROM[1] = 0;
|
||||||
|
MB_DATA.InRegs.Response.ROM[2] = 0;
|
||||||
|
MB_DATA.InRegs.Response.ROM[3] = 0;
|
||||||
|
MB_DATA.InRegs.Response.Status = status;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// error read by ROM
|
||||||
|
case STATUS_ERR_READ_ROM:
|
||||||
|
// fill only ROM from holdreg
|
||||||
|
MB_DATA.InRegs.Response.Location = 0;
|
||||||
|
MB_DATA.InRegs.Response.Config = 0;
|
||||||
|
MB_DATA.InRegs.Response.ROM[0] = MB_DATA.HoldRegs.InitStruct.ROM[0];
|
||||||
|
MB_DATA.InRegs.Response.ROM[1] = MB_DATA.HoldRegs.InitStruct.ROM[1];
|
||||||
|
MB_DATA.InRegs.Response.ROM[2] = MB_DATA.HoldRegs.InitStruct.ROM[2];
|
||||||
|
MB_DATA.InRegs.Response.ROM[3] = MB_DATA.HoldRegs.InitStruct.ROM[3];
|
||||||
|
MB_DATA.InRegs.Response.Status = status;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// error init
|
||||||
|
case STATUS_ERR_INIT:
|
||||||
|
// fill ROM and location from holdreg
|
||||||
|
MB_DATA.InRegs.Response.Location = MB_DATA.HoldRegs.InitStruct.Location;
|
||||||
|
MB_DATA.InRegs.Response.Config = 0;
|
||||||
|
MB_DATA.InRegs.Response.ROM[0] = MB_DATA.HoldRegs.InitStruct.ROM[0];
|
||||||
|
MB_DATA.InRegs.Response.ROM[1] = MB_DATA.HoldRegs.InitStruct.ROM[1];
|
||||||
|
MB_DATA.InRegs.Response.ROM[2] = MB_DATA.HoldRegs.InitStruct.ROM[2];
|
||||||
|
MB_DATA.InRegs.Response.ROM[3] = MB_DATA.HoldRegs.InitStruct.ROM[3];
|
||||||
|
MB_DATA.InRegs.Response.Status = status;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// error deinit
|
||||||
|
case STATUS_ERR_DEINIT:
|
||||||
|
// fill with sensor data
|
||||||
|
MB_DATA.InRegs.Response.Location = *(uint16_t *)&sensor->sens.hdallas->scratchpad.tHighRegister;
|
||||||
|
MB_DATA.InRegs.Response.Config = sensor->sens.hdallas->scratchpad.ConfigRegister;
|
||||||
|
MB_DATA.InRegs.Response.ROM[0] = __REV16((sensor->sens.sensROM) & 0xFFFF);
|
||||||
|
MB_DATA.InRegs.Response.ROM[1] = __REV16((sensor->sens.sensROM >> 16) & 0xFFFF);
|
||||||
|
MB_DATA.InRegs.Response.ROM[2] = __REV16((sensor->sens.sensROM >> 32) & 0xFFFF);
|
||||||
|
MB_DATA.InRegs.Response.ROM[3] = __REV16((sensor->sens.sensROM >> 48) & 0xFFFF);
|
||||||
|
MB_DATA.InRegs.Response.Status = status;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// error deinit
|
||||||
|
case STATUS_ERR_SCAN:
|
||||||
|
// fill with sensor data
|
||||||
|
MB_DATA.InRegs.Response.Location = 0;
|
||||||
|
MB_DATA.InRegs.Response.Config = 0;
|
||||||
|
MB_DATA.InRegs.Response.ROM[0] = __REV16((sensor->sens.sensROM) & 0xFFFF);
|
||||||
|
MB_DATA.InRegs.Response.ROM[1] = __REV16((sensor->sens.sensROM >> 16) & 0xFFFF);
|
||||||
|
MB_DATA.InRegs.Response.ROM[2] = __REV16((sensor->sens.sensROM >> 32) & 0xFFFF);
|
||||||
|
MB_DATA.InRegs.Response.ROM[3] = __REV16((sensor->sens.sensROM >> 48) & 0xFFFF);
|
||||||
|
MB_DATA.InRegs.Response.Status = status;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
MB_DATA.InRegs.Response.Location = 0;
|
||||||
|
MB_DATA.InRegs.Response.Config = 0;
|
||||||
|
MB_DATA.InRegs.Response.ROM[0] = 0;
|
||||||
|
MB_DATA.InRegs.Response.ROM[1] = 0;
|
||||||
|
MB_DATA.InRegs.Response.ROM[2] = 0;
|
||||||
|
MB_DATA.InRegs.Response.ROM[3] = 0;
|
||||||
|
MB_DATA.InRegs.Response.Status = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void PYModule_CheckModuleLosted(PCHSens_ModuleTypeDef *module, uint8_t *losted_flag)
|
||||||
|
{
|
||||||
|
if(module->sens1.not_found)
|
||||||
|
*losted_flag |= 1;
|
||||||
|
if(module->sens2.not_found)
|
||||||
|
*losted_flag |= 1;
|
||||||
|
if(module->sens3.not_found)
|
||||||
|
*losted_flag |= 1;
|
||||||
|
if(module->sens4.not_found)
|
||||||
|
*losted_flag |= 1;
|
||||||
|
}
|
||||||
void PYModule_StoreModuleToModbus(PCHSens_ModuleTypeDef *module)
|
void PYModule_StoreModuleToModbus(PCHSens_ModuleTypeDef *module)
|
||||||
{
|
{
|
||||||
uint8_t mb_location;
|
uint8_t mb_location;
|
||||||
@@ -281,17 +372,3 @@ void PYModule_StoreModuleToModbus(PCHSens_ModuleTypeDef *module)
|
|||||||
MB_DATA.InRegs.SensTemperature[mb_location] = module->sens4.sens.temperature*100;
|
MB_DATA.InRegs.SensTemperature[mb_location] = module->sens4.sens.temperature*100;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PYModule_StoreModbus(PCHSens_TypeDef *pchsens)
|
|
||||||
{
|
|
||||||
uint8_t losted = 0;
|
|
||||||
|
|
||||||
// module1
|
|
||||||
PYModule_StoreModuleToModbus(&pchsens->module1);
|
|
||||||
PYModule_StoreModuleToModbus(&pchsens->module2);
|
|
||||||
PYModule_StoreModuleToModbus(&pchsens->module3);
|
|
||||||
PYModule_StoreModuleToModbus(&pchsens->module4);
|
|
||||||
PYModule_StoreModuleToModbus(&pchsens->module5);
|
|
||||||
PYModule_StoreModuleToModbus(&pchsens->module6);
|
|
||||||
|
|
||||||
MB_DATA.Coils.ConvertionDone |= 1;
|
|
||||||
}
|
|
||||||
@@ -14,10 +14,20 @@
|
|||||||
#include "modbus_data.h"
|
#include "modbus_data.h"
|
||||||
|
|
||||||
/* Declarations and definitions ---------------------------------------------*/
|
/* Declarations and definitions ---------------------------------------------*/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
STATUS_OK = 0x01,
|
||||||
|
STATUS_ERR_READ_LOCATION = 0xF0,
|
||||||
|
STATUS_ERR_READ_ROM = 0x0F,
|
||||||
|
STATUS_ERR_INIT = 0xAA,
|
||||||
|
STATUS_ERR_DEINIT = 0x55,
|
||||||
|
STATUS_ERR_SCAN = 0xBB,
|
||||||
|
}Sensor_ResponseStatusTypeDef;
|
||||||
|
|
||||||
/* Functions ---------------------------------------------------------------*/
|
/* Functions ---------------------------------------------------------------*/
|
||||||
void PYModule_main(void);
|
void PYModule_main(void);
|
||||||
void PYModule_FirstInit(void);
|
void PYModule_FirstInit(void);
|
||||||
|
void PYModule_ScanSensor(PCHSens_DallasBusHandle *hbus);
|
||||||
void PYModule_ReadSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_TypeDef *pchsens);
|
void PYModule_ReadSensor(DALLAS_HandleTypeDef *hdallas, PCHSens_TypeDef *pchsens);
|
||||||
void PYModule_InitSensor(PCHSens_TypeDef *pchsens);
|
void PYModule_InitSensor(PCHSens_TypeDef *pchsens);
|
||||||
void PYModule_DeInitSensor(PCHSens_TypeDef *pchsens);
|
void PYModule_DeInitSensor(PCHSens_TypeDef *pchsens);
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
#include "pch_sensors.h"
|
#include "pch_sensors.h"
|
||||||
#include "modbus_data.h"
|
#include "modbus_data.h"
|
||||||
PCHSens_DallasBusHandle DallasBus;
|
|
||||||
|
|
||||||
/* Declarations and definitions --------------------------------------------*/
|
/* Declarations and definitions --------------------------------------------*/
|
||||||
|
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ typedef struct
|
|||||||
DALLAS_HandleTypeDef *hdallas;
|
DALLAS_HandleTypeDef *hdallas;
|
||||||
uint8_t UnknownCnt;
|
uint8_t UnknownCnt;
|
||||||
}PCHSens_DallasBusHandle;
|
}PCHSens_DallasBusHandle;
|
||||||
extern PCHSens_DallasBusHandle DallasBus;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|||||||
@@ -153,7 +153,40 @@
|
|||||||
<Name>(105=-1,-1,-1,-1,0)</Name>
|
<Name>(105=-1,-1,-1,-1,0)</Name>
|
||||||
</SetRegEntry>
|
</SetRegEntry>
|
||||||
</TargetDriverDllRegistry>
|
</TargetDriverDllRegistry>
|
||||||
<Breakpoint/>
|
<Breakpoint>
|
||||||
|
<Bp>
|
||||||
|
<Number>0</Number>
|
||||||
|
<Type>0</Type>
|
||||||
|
<LineNumber>37</LineNumber>
|
||||||
|
<EnabledFlag>1</EnabledFlag>
|
||||||
|
<Address>134235612</Address>
|
||||||
|
<ByteObject>0</ByteObject>
|
||||||
|
<HtxType>0</HtxType>
|
||||||
|
<ManyObjects>0</ManyObjects>
|
||||||
|
<SizeOfObject>0</SizeOfObject>
|
||||||
|
<BreakByAccess>0</BreakByAccess>
|
||||||
|
<BreakIfRCount>1</BreakIfRCount>
|
||||||
|
<Filename>..\Core\PY32Module\PY32module_main.c</Filename>
|
||||||
|
<ExecCommand></ExecCommand>
|
||||||
|
<Expression>\\Project\../Core/PY32Module/PY32module_main.c\37</Expression>
|
||||||
|
</Bp>
|
||||||
|
<Bp>
|
||||||
|
<Number>1</Number>
|
||||||
|
<Type>0</Type>
|
||||||
|
<LineNumber>48</LineNumber>
|
||||||
|
<EnabledFlag>1</EnabledFlag>
|
||||||
|
<Address>134235662</Address>
|
||||||
|
<ByteObject>0</ByteObject>
|
||||||
|
<HtxType>0</HtxType>
|
||||||
|
<ManyObjects>0</ManyObjects>
|
||||||
|
<SizeOfObject>0</SizeOfObject>
|
||||||
|
<BreakByAccess>0</BreakByAccess>
|
||||||
|
<BreakIfRCount>1</BreakIfRCount>
|
||||||
|
<Filename>..\Core\PY32Module\PY32module_main.c</Filename>
|
||||||
|
<ExecCommand></ExecCommand>
|
||||||
|
<Expression>\\Project\../Core/PY32Module/PY32module_main.c\48</Expression>
|
||||||
|
</Bp>
|
||||||
|
</Breakpoint>
|
||||||
<WatchWindow1>
|
<WatchWindow1>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>0</count>
|
<count>0</count>
|
||||||
@@ -240,6 +273,21 @@
|
|||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>DS</ItemText>
|
<ItemText>DS</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>17</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>\\Project\../Core/PY32Module/PY32module_main.c\pchsens.module3</ItemText>
|
||||||
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>18</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>\\Project\../Core/PY32Module/PY32module_main.c\pchsens.module4</ItemText>
|
||||||
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>19</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>scan_cnt</ItemText>
|
||||||
|
</Ww>
|
||||||
</WatchWindow1>
|
</WatchWindow1>
|
||||||
<WatchWindow2>
|
<WatchWindow2>
|
||||||
<Ww>
|
<Ww>
|
||||||
@@ -250,7 +298,7 @@
|
|||||||
<Ww>
|
<Ww>
|
||||||
<count>1</count>
|
<count>1</count>
|
||||||
<WinNumber>2</WinNumber>
|
<WinNumber>2</WinNumber>
|
||||||
<ItemText>DS</ItemText>
|
<ItemText>DS,0x10</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>2</count>
|
<count>2</count>
|
||||||
|
|||||||
Reference in New Issue
Block a user