|
@@ -146,7 +146,7 @@ void* power_thread(void* arg)
|
|
|
_globalDeviceManager->_all_ctrl_board[i]._globalPowerInManger._PowerWarninginfo);
|
|
_globalDeviceManager->_all_ctrl_board[i]._globalPowerInManger._PowerWarninginfo);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- usleep(usleepTime);
|
|
|
|
|
|
|
+ //usleep(usleepTime);
|
|
|
}
|
|
}
|
|
|
bool SaveDBFlag=false; //数据库存储记录,只要有通道存,就存一次总通道数据
|
|
bool SaveDBFlag=false; //数据库存储记录,只要有通道存,就存一次总通道数据
|
|
|
int _chn = 0;
|
|
int _chn = 0;
|
|
@@ -950,6 +950,60 @@ int dev_sensor_init(GlobalDeviceManager *_globalDeviceManager)
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * @brief 报警控制通道
|
|
|
|
|
+ *
|
|
|
|
|
+ * 这是一个用于报警控制通道的函数。
|
|
|
|
|
+ */
|
|
|
|
|
+void AlarmCtrlChn(int nChID, int nCtrl)
|
|
|
|
|
+{
|
|
|
|
|
+ char buff[256];
|
|
|
|
|
+ int ret = 0;
|
|
|
|
|
+ GlobalPowerManger *_globalPowerMangerTemp = NULL;
|
|
|
|
|
+ list_for_each_entry(_globalPowerMangerTemp, &__globalDeviceManage._globalPowerManger.list, list)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (_globalPowerMangerTemp == NULL)
|
|
|
|
|
+ break;
|
|
|
|
|
+ if (nChID == _globalPowerMangerTemp->product_ch_id)
|
|
|
|
|
+ {
|
|
|
|
|
+ log_d("switch ctrl:%d", _globalPowerMangerTemp->product_ch_id);
|
|
|
|
|
+ ret = g_switch_set_all_chn_ctrl(&__globalDeviceManage._globalRelaySampManger, _globalPowerMangerTemp,
|
|
|
|
|
+ _globalPowerMangerTemp->product_saddr,
|
|
|
|
|
+ _globalPowerMangerTemp->product_ch_addr,
|
|
|
|
|
+ nCtrl, false);
|
|
|
|
|
+ if (ret < 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ ret = g_switch_set_all_chn_ctrl(&__globalDeviceManage._globalRelaySampManger, _globalPowerMangerTemp,
|
|
|
|
|
+ _globalPowerMangerTemp->product_saddr,
|
|
|
|
|
+ _globalPowerMangerTemp->product_ch_addr,
|
|
|
|
|
+ nCtrl, false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sprintf(buff, "$开启$|$通道$|%d", _globalPowerMangerTemp->product_ch_id);
|
|
|
|
|
+ dev_insert_alarm_ctrl(__globalDeviceManage.db, _globalPowerMangerTemp->product_id, 2, buff);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+void AlarmCtrlAll(int nCtrl)
|
|
|
|
|
+{
|
|
|
|
|
+ //总关
|
|
|
|
|
+ int nSendAddr=0;
|
|
|
|
|
+ char buff[256];
|
|
|
|
|
+ GlobalPowerManger* _globalPowerMangerTemp = NULL ;
|
|
|
|
|
+ list_for_each_entry(_globalPowerMangerTemp, &__globalDeviceManage._globalPowerManger.list, list)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(_globalPowerMangerTemp==NULL)
|
|
|
|
|
+ break;
|
|
|
|
|
+ if(_globalPowerMangerTemp->product_saddr==nSendAddr)continue;
|
|
|
|
|
+ nSendAddr=_globalPowerMangerTemp->product_saddr;
|
|
|
|
|
+ log_i("Close All address Start");
|
|
|
|
|
+ int rec=g_switch_set_all_ctrl(&__globalDeviceManage._globalRelaySampManger,_globalPowerMangerTemp->product_ch_type,_globalPowerMangerTemp->product_saddr,nCtrl);
|
|
|
|
|
+ if(rec<0)log_i("Close All address:%d rec:%d:%s",nSendAddr,rec,modbus_strerror(errno));
|
|
|
|
|
+ }
|
|
|
|
|
+ sprintf(buff,"$关闭$|$所有$|$通道$");
|
|
|
|
|
+ dev_insert_alarm_ctrl(__globalDeviceManage.db,_globalPowerMangerTemp->product_id,2,buff);
|
|
|
|
|
+}
|
|
|
/**
|
|
/**
|
|
|
* @brief 传感器报警函数
|
|
* @brief 传感器报警函数
|
|
|
*
|
|
*
|
|
@@ -964,6 +1018,8 @@ void sensor_alarm(GlobalSensorManger *_globalSensorMangerTemp, int nAlarmType)
|
|
|
bool *pSave = NULL; //是否已报警
|
|
bool *pSave = NULL; //是否已报警
|
|
|
float *pValthreshold = NULL;//阈值
|
|
float *pValthreshold = NULL;//阈值
|
|
|
float *pValData = NULL; //当前值
|
|
float *pValData = NULL; //当前值
|
|
|
|
|
+ char *nCtrlType = NULL; //报警方式
|
|
|
|
|
+ char *nCtrlValue= NULL; //控制通道
|
|
|
if (!_globalSensorMangerTemp|| !_globalSensorMangerTemp->over_manager)
|
|
if (!_globalSensorMangerTemp|| !_globalSensorMangerTemp->over_manager)
|
|
|
{
|
|
{
|
|
|
return;
|
|
return;
|
|
@@ -975,24 +1031,32 @@ void sensor_alarm(GlobalSensorManger *_globalSensorMangerTemp, int nAlarmType)
|
|
|
pValthreshold = &_globalSensorMangerTemp->over_manager->sensor_val1_upper_threshold;
|
|
pValthreshold = &_globalSensorMangerTemp->over_manager->sensor_val1_upper_threshold;
|
|
|
pSave = &_globalSensorMangerTemp->warning_status.sensor_val1_upper;
|
|
pSave = &_globalSensorMangerTemp->warning_status.sensor_val1_upper;
|
|
|
pValData = &_globalSensorMangerTemp->Cur_sensor_info.val1;
|
|
pValData = &_globalSensorMangerTemp->Cur_sensor_info.val1;
|
|
|
|
|
+ nCtrlType = &_globalSensorMangerTemp->over_manager->sensor_val1_upper_threshold_ctrl;
|
|
|
|
|
+ nCtrlValue = &_globalSensorMangerTemp->over_manager->sensor_val1_upper_threshold_ctrl_para;
|
|
|
break;
|
|
break;
|
|
|
case SENSOR_VAL1_LOWER:
|
|
case SENSOR_VAL1_LOWER:
|
|
|
penable = &_globalSensorMangerTemp->over_manager->sensor_val1_lower_enabled;
|
|
penable = &_globalSensorMangerTemp->over_manager->sensor_val1_lower_enabled;
|
|
|
pValthreshold = &_globalSensorMangerTemp->over_manager->sensor_val1_lower_threshold;
|
|
pValthreshold = &_globalSensorMangerTemp->over_manager->sensor_val1_lower_threshold;
|
|
|
pSave = &_globalSensorMangerTemp->warning_status.sensor_val1_lower;
|
|
pSave = &_globalSensorMangerTemp->warning_status.sensor_val1_lower;
|
|
|
pValData = &_globalSensorMangerTemp->Cur_sensor_info.val1;
|
|
pValData = &_globalSensorMangerTemp->Cur_sensor_info.val1;
|
|
|
|
|
+ nCtrlType = &_globalSensorMangerTemp->over_manager->sensor_val1_lower_threshold_ctrl;
|
|
|
|
|
+ nCtrlValue = &_globalSensorMangerTemp->over_manager->sensor_val1_lower_threshold_ctrl_para;
|
|
|
break;
|
|
break;
|
|
|
case SENSOR_VAL2_UPPER:
|
|
case SENSOR_VAL2_UPPER:
|
|
|
penable = &_globalSensorMangerTemp->over_manager->sensor_val2_upper_enabled;
|
|
penable = &_globalSensorMangerTemp->over_manager->sensor_val2_upper_enabled;
|
|
|
pValthreshold = &_globalSensorMangerTemp->over_manager->sensor_val2_upper_threshold;
|
|
pValthreshold = &_globalSensorMangerTemp->over_manager->sensor_val2_upper_threshold;
|
|
|
pSave = &_globalSensorMangerTemp->warning_status.sensor_val2_upper;
|
|
pSave = &_globalSensorMangerTemp->warning_status.sensor_val2_upper;
|
|
|
pValData = &_globalSensorMangerTemp->Cur_sensor_info.val2;
|
|
pValData = &_globalSensorMangerTemp->Cur_sensor_info.val2;
|
|
|
|
|
+ nCtrlType = &_globalSensorMangerTemp->over_manager->sensor_val2_upper_threshold_ctrl;
|
|
|
|
|
+ nCtrlValue = &_globalSensorMangerTemp->over_manager->sensor_val2_upper_threshold_ctrl_para;
|
|
|
break;
|
|
break;
|
|
|
case SENSOR_VAL2_LOWER:
|
|
case SENSOR_VAL2_LOWER:
|
|
|
penable = &_globalSensorMangerTemp->over_manager->sensor_val2_lower_enabled;
|
|
penable = &_globalSensorMangerTemp->over_manager->sensor_val2_lower_enabled;
|
|
|
pValthreshold = &_globalSensorMangerTemp->over_manager->sensor_val2_lower_threshold;
|
|
pValthreshold = &_globalSensorMangerTemp->over_manager->sensor_val2_lower_threshold;
|
|
|
pSave = &_globalSensorMangerTemp->warning_status.sensor_val2_lower;
|
|
pSave = &_globalSensorMangerTemp->warning_status.sensor_val2_lower;
|
|
|
pValData = &_globalSensorMangerTemp->Cur_sensor_info.val2;
|
|
pValData = &_globalSensorMangerTemp->Cur_sensor_info.val2;
|
|
|
|
|
+ nCtrlType = &_globalSensorMangerTemp->over_manager->sensor_val2_lower_threshold_ctrl;
|
|
|
|
|
+ nCtrlValue = &_globalSensorMangerTemp->over_manager->sensor_val2_lower_threshold_ctrl_para;
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
default:
|
|
@@ -1010,6 +1074,13 @@ void sensor_alarm(GlobalSensorManger *_globalSensorMangerTemp, int nAlarmType)
|
|
|
{
|
|
{
|
|
|
*pSave = true;
|
|
*pSave = true;
|
|
|
dev_sensor_Alarm_send_message(&__globalDeviceManage, _globalSensorMangerTemp, nAlarmType);
|
|
dev_sensor_Alarm_send_message(&__globalDeviceManage, _globalSensorMangerTemp, nAlarmType);
|
|
|
|
|
+ if (*nCtrlType == ALARM_CTRL_CLOSE_CH)
|
|
|
|
|
+ {
|
|
|
|
|
+ AlarmCtrlChn(*nCtrlValue,0);
|
|
|
|
|
+ }else if (*nCtrlType == ALARM_CTRL_CLOSE_CH)
|
|
|
|
|
+ {
|
|
|
|
|
+ AlarmCtrlAll(0);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -1025,6 +1096,13 @@ void sensor_alarm(GlobalSensorManger *_globalSensorMangerTemp, int nAlarmType)
|
|
|
{
|
|
{
|
|
|
*pSave = true;
|
|
*pSave = true;
|
|
|
dev_sensor_Alarm_send_message(&__globalDeviceManage, _globalSensorMangerTemp, nAlarmType);
|
|
dev_sensor_Alarm_send_message(&__globalDeviceManage, _globalSensorMangerTemp, nAlarmType);
|
|
|
|
|
+ if (*nCtrlType == ALARM_CTRL_CLOSE_CH)
|
|
|
|
|
+ {
|
|
|
|
|
+ AlarmCtrlChn(*nCtrlValue, 0);
|
|
|
|
|
+ }else if (*nCtrlType == ALARM_CTRL_CLOSE_CH)
|
|
|
|
|
+ {
|
|
|
|
|
+ AlarmCtrlAll(0);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -1145,10 +1223,17 @@ void* sensor_thread(void* arg)
|
|
|
// printf("get \n");
|
|
// printf("get \n");
|
|
|
float temperature = 0.0;
|
|
float temperature = 0.0;
|
|
|
float humidity = 0.0;
|
|
float humidity = 0.0;
|
|
|
|
|
+#ifdef CUST_ANDERSON
|
|
|
|
|
+ ret = _g_sensor_get_temperature_value_ANDERSON((void *)&_globalDeviceManager->sensor_modbus_manager,
|
|
|
|
|
+ _globalSensorMangerTemp->sensor_addr,
|
|
|
|
|
+ &temperature,
|
|
|
|
|
+ &humidity);
|
|
|
|
|
+#else
|
|
|
ret = _g_sensor_get_temperature_value((void *)&_globalDeviceManager->sensor_modbus_manager,
|
|
ret = _g_sensor_get_temperature_value((void *)&_globalDeviceManager->sensor_modbus_manager,
|
|
|
_globalSensorMangerTemp->sensor_addr,
|
|
_globalSensorMangerTemp->sensor_addr,
|
|
|
&temperature,
|
|
&temperature,
|
|
|
&humidity);
|
|
&humidity);
|
|
|
|
|
+#endif
|
|
|
if (ret == -1)
|
|
if (ret == -1)
|
|
|
{
|
|
{
|
|
|
_globalSensorMangerTemp->sensor_status = 1;
|
|
_globalSensorMangerTemp->sensor_status = 1;
|
|
@@ -1206,6 +1291,40 @@ void* sensor_thread(void* arg)
|
|
|
case SENSOR_TYPE_AIR_PRESS: // 气流
|
|
case SENSOR_TYPE_AIR_PRESS: // 气流
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case SENSOR_TYPE_DoubleT://双头传感器
|
|
|
|
|
+ {
|
|
|
|
|
+ float temperature = 0.0;
|
|
|
|
|
+ float temperature2 = 0.0;
|
|
|
|
|
+ ret = _g_sensor_get_D_temperature_value_ANDERSON((void *)&_globalDeviceManager->sensor_modbus_manager,
|
|
|
|
|
+ _globalSensorMangerTemp->sensor_addr,
|
|
|
|
|
+ &temperature,
|
|
|
|
|
+ &temperature2);
|
|
|
|
|
+
|
|
|
|
|
+ if (ret == -1)
|
|
|
|
|
+ {
|
|
|
|
|
+ //log_w("Relay modbus Error:%s\n", modbus_strerror(errno));
|
|
|
|
|
+ _globalSensorMangerTemp->sensor_status = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ _globalSensorMangerTemp->sensor_status = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ // log_d("sensor val:%0.2f %0.2f\n",temperature,humidity);
|
|
|
|
|
+ // printf("get temperature=%f humidity=%f\n",temperature,humidity);
|
|
|
|
|
+ gettimeofday(&tv, &tz);
|
|
|
|
|
+ t = localtime(&tv.tv_sec);
|
|
|
|
|
+ sprintf(_globalSensorInfo.samp_time, "%04d-%02d-%02d %02d:%02d:%02d.%03ld",
|
|
|
|
|
+ t->tm_year + 1900, t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec / 1000);
|
|
|
|
|
+ _globalSensorInfo.product_id = __globalDeviceManage._globalDevInfo.product_id;
|
|
|
|
|
+ _globalSensorInfo.sensor_id = _globalSensorMangerTemp->sensor_id;
|
|
|
|
|
+ _globalSensorInfo.val1 = temperature;
|
|
|
|
|
+ _globalSensorInfo.val2 = temperature2;
|
|
|
|
|
+ _globalSensorInfo.product_log_time=_globalSensorMangerTemp->Cur_sensor_info.product_log_time;;
|
|
|
|
|
+ _globalSensorMangerTemp->Cur_sensor_info=_globalSensorInfo;
|
|
|
|
|
+ _globalDeviceManager->g_modebus_read.temprature=temperature;
|
|
|
|
|
+ _globalDeviceManager->g_modebus_read.temprature2=temperature2;
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -1502,7 +1621,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
|
|
|
log_e("_globalPowerManger->global_over_manager malloc error.\n");
|
|
log_e("_globalPowerManger->global_over_manager malloc error.\n");
|
|
|
return -1 ;
|
|
return -1 ;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ memset(_globalDeviceManager->_globalPowerManger.global_over_manager, 0, sizeof(GlobalOverManager));
|
|
|
//查询是否存在全部通道信息
|
|
//查询是否存在全部通道信息
|
|
|
ret = dev_get_power_manage_info(_globalDeviceManager->db,
|
|
ret = dev_get_power_manage_info(_globalDeviceManager->db,
|
|
|
_globalDeviceManager->_globalDevInfo.product_id,0,
|
|
_globalDeviceManager->_globalDevInfo.product_id,0,
|