|
|
@@ -966,9 +966,19 @@ void sensor_or_cascade_init()
|
|
|
GlobalDeviceInfo *devInfo = &_globalDeviceManager->_globalDevInfo;
|
|
|
//uint8_t query[512] = {0};
|
|
|
int ret = 0;
|
|
|
- ret = dev_get_sensor_manage_info(_globalDeviceManager->db,
|
|
|
- _globalDeviceManager->_globalDevInfo.product_id,
|
|
|
- &_globalDeviceManager->_globalSensorManger);
|
|
|
+ // ret = dev_get_sensor_manage_info(_globalDeviceManager->db,
|
|
|
+ // _globalDeviceManager->_globalDevInfo.product_id,
|
|
|
+ // &_globalDeviceManager->_globalSensorManger);
|
|
|
+
|
|
|
+
|
|
|
+ //dev_get_sensor_info
|
|
|
+ GlobalSensorManger *temp = (GlobalSensorManger*)malloc(sizeof(GlobalSensorManger));
|
|
|
+ if(!temp)
|
|
|
+ return;
|
|
|
+ dev_get_sensor_info(_globalDeviceManager->db,0,0,temp);
|
|
|
+
|
|
|
+ list_add_tail(&temp->list,&_globalDeviceManager->_globalSensorManger.list);
|
|
|
+
|
|
|
|
|
|
dev_Alarm_Run_message(_globalDeviceManager,language_alarm_Init_Success[0],"sensor");
|
|
|
cascade_slave_init();
|
|
|
@@ -1021,19 +1031,19 @@ void * thread_sensor_or_485(void*arg)
|
|
|
int nSaveIndex = 1;
|
|
|
char strTable[] = "Table_SensorInfo";
|
|
|
char strTemp[64] = {0};
|
|
|
- dev_search_last_Index(_globalDeviceManager->db, &nSaveIndex, strTable); // 查询日志最大点
|
|
|
- int nMaxIndex = 2000000000;
|
|
|
- int nDeleteNumber = 1000 / 120000 * 3600 * 24 * 30 * 10; // 1/60s;
|
|
|
+ // dev_search_last_Index(_globalDeviceManager->db, &nSaveIndex, strTable); // 鏌ヨ�鏃ュ織鏈€澶х偣
|
|
|
+ // int nMaxIndex = 2000000000;
|
|
|
+ // int nDeleteNumber = 1000 / 120000 * 3600 * 24 * 30 * 10; // 1/60s;
|
|
|
|
|
|
while(_globalDeviceManager->dev_samp_flag)
|
|
|
{
|
|
|
if(devInfo->_gmodbus_info.product_modbus_type > 0)
|
|
|
{
|
|
|
//printf("12323451541545135435\n");
|
|
|
- dev_search_last_Index(_globalDeviceManager->db, &nSaveIndex, strTable);
|
|
|
- pthread_mutex_lock(&__globalDeviceManage._sensor_update);
|
|
|
+ //dev_search_last_Index(_globalDeviceManager->db, &nSaveIndex, strTable);
|
|
|
+ // pthread_mutex_lock(&__globalDeviceManage._sensor_update);
|
|
|
|
|
|
- pthread_mutex_unlock(&__globalDeviceManage._sensor_update);
|
|
|
+ // pthread_mutex_unlock(&__globalDeviceManage._sensor_update);
|
|
|
list_for_each_entry(_globalSensorMangerTemp, &_globalDeviceManager->_globalSensorManger.list, list)
|
|
|
{
|
|
|
switch (_globalSensorMangerTemp->sensor_type)
|
|
|
@@ -1067,145 +1077,89 @@ void * thread_sensor_or_485(void*arg)
|
|
|
}else
|
|
|
{
|
|
|
//printf("--------------------------\n");
|
|
|
- if (nSaveIndex > nMaxIndex)
|
|
|
- {
|
|
|
- dev_change_last_Index(_globalDeviceManager->db, &nSaveIndex, nDeleteNumber, strTable);
|
|
|
- }
|
|
|
- pthread_mutex_lock(&__globalDeviceManage._sensor_update);
|
|
|
- list_for_each_entry(_globalSensorMangerTemp, &_globalDeviceManager->_globalSensorManger.list, list)
|
|
|
- {
|
|
|
- switch (_globalSensorMangerTemp->sensor_type)
|
|
|
- {
|
|
|
- case SENSOR_TYPE_TEMPERATURE: // 温湿度
|
|
|
- {
|
|
|
- // printf("get \n");
|
|
|
- float temperature = 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,
|
|
|
- _globalSensorMangerTemp->sensor_addr,
|
|
|
- &temperature,
|
|
|
- &humidity);
|
|
|
-#endif
|
|
|
- if (ret == -1)
|
|
|
- {
|
|
|
- _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 = humidity;
|
|
|
-
|
|
|
- _globalSensorInfo.product_log_time=_globalSensorMangerTemp->Cur_sensor_info.product_log_time;
|
|
|
- _globalSensorMangerTemp->Cur_sensor_info=_globalSensorInfo;
|
|
|
- _globalDeviceManager->g_modebus_read.temprature=temperature *1000;
|
|
|
- _globalDeviceManager->g_modebus_read.humidity=humidity *1000;
|
|
|
- }
|
|
|
- break;
|
|
|
- case SENSOR_TYPE_SMOKE: // 烟雾
|
|
|
- case SENSOR_TYPE_WATER: // 水浸
|
|
|
- case SENSOR_TYPE_DOOR: // 门禁 IO信号
|
|
|
- {
|
|
|
- if (_globalSensorMangerTemp->sensor_interface_type==2)//干节点传感器
|
|
|
- {
|
|
|
- int nStatus=0;
|
|
|
- g_switch_get_gpio_status(_globalSensorMangerTemp->sensor_addr+GPIO_PD11,&nStatus);
|
|
|
- _globalSensorMangerTemp->Cur_sensor_info.val1=nStatus;
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case SENSOR_TYPE_GAS: // 气体
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- break;
|
|
|
- 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;
|
|
|
- }
|
|
|
- // 通用功能
|
|
|
- // 写入数据库
|
|
|
- gettimeofday(&tv, NULL);
|
|
|
- time_t now;
|
|
|
- time(&now);
|
|
|
- t = localtime(&now);
|
|
|
- char buffer[80];
|
|
|
- strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", t);
|
|
|
- memset(_globalSensorMangerTemp->Cur_sensor_info.samp_time, 0, sizeof(_globalSensorMangerTemp->Cur_sensor_info.samp_time));
|
|
|
- strftime(_globalSensorMangerTemp->Cur_sensor_info.samp_time, sizeof(_globalSensorMangerTemp->Cur_sensor_info.samp_time), "%Y-%m-%d %H:%M:%S", t);
|
|
|
- sprintf(buffer, ".%03ld", tv.tv_usec / 1000);
|
|
|
- strcat(_globalSensorMangerTemp->Cur_sensor_info.samp_time, buffer);
|
|
|
- if (difftime(now, _globalSensorMangerTemp->Cur_sensor_info.product_log_time) > (30000 / 1000))
|
|
|
- {
|
|
|
- _globalSensorMangerTemp->Cur_sensor_info.product_log_time = now;
|
|
|
- // 插入数据库
|
|
|
- ret = dev_insert_sensor_info(_globalDeviceManager->db, &_globalSensorMangerTemp->Cur_sensor_info, &nSaveIndex);
|
|
|
- if (ret != 0)
|
|
|
- {
|
|
|
- log_e("sensor_temp_write database error.");
|
|
|
- }
|
|
|
- }
|
|
|
- if (_globalSensorMangerTemp->sensor_status == 0)
|
|
|
- {
|
|
|
- sensor_alarm(_globalSensorMangerTemp, SENSOR_VAL1_UPPER);
|
|
|
- sensor_alarm(_globalSensorMangerTemp, SENSOR_VAL1_LOWER);
|
|
|
- sensor_alarm(_globalSensorMangerTemp, SENSOR_VAL2_UPPER);
|
|
|
- sensor_alarm(_globalSensorMangerTemp, SENSOR_VAL2_LOWER);
|
|
|
- }
|
|
|
- }
|
|
|
- pthread_mutex_unlock(&__globalDeviceManage._sensor_update);
|
|
|
- sleep(3);
|
|
|
+ // if (nSaveIndex > nMaxIndex)
|
|
|
+ // {
|
|
|
+ // dev_change_last_Index(_globalDeviceManager->db, &nSaveIndex, nDeleteNumber, strTable);
|
|
|
+ // }
|
|
|
+ // pthread_mutex_lock(&__globalDeviceManage._sensor_update);
|
|
|
+ //list_for_each_entry(_globalSensorMangerTemp, &_globalDeviceManager->_globalSensorManger.list, list)
|
|
|
+ //{
|
|
|
+ // if(_globalSensorMangerTemp->product_id == 0)
|
|
|
+ // {
|
|
|
+ // switch (_globalSensorMangerTemp->sensor_type)
|
|
|
+ // {
|
|
|
+ // case SENSOR_TYPE_TEMPERATURE: // 温湿度
|
|
|
+ // {
|
|
|
+ // // printf("get \n");
|
|
|
+ // float temperature = 0.0;
|
|
|
+ // float humidity = 0.0;
|
|
|
+ // ret = _g_sensor_get_temperature_value((void *)&_globalDeviceManager->sensor_modbus_manager,
|
|
|
+ // _globalSensorMangerTemp->sensor_addr,
|
|
|
+ // &temperature,
|
|
|
+ // &humidity);
|
|
|
+
|
|
|
+ // if (ret == -1)
|
|
|
+ // {
|
|
|
+ // _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 = humidity;
|
|
|
+
|
|
|
+ // _globalSensorInfo.product_log_time=_globalSensorMangerTemp->Cur_sensor_info.product_log_time;
|
|
|
+ // _globalSensorMangerTemp->Cur_sensor_info=_globalSensorInfo;
|
|
|
+ // _globalDeviceManager->g_modebus_read.temprature=temperature *1000;
|
|
|
+ // _globalDeviceManager->g_modebus_read.humidity=humidity *1000;
|
|
|
+ // }
|
|
|
+ // break;
|
|
|
+ // default:
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // // 閫氱敤鍔熻兘
|
|
|
+ // // 写入数据库
|
|
|
+ // gettimeofday(&tv, NULL);
|
|
|
+ // time_t now;
|
|
|
+ // time(&now);
|
|
|
+ // t = localtime(&now);
|
|
|
+ // char buffer[80];
|
|
|
+ // strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", t);
|
|
|
+ // memset(_globalSensorMangerTemp->Cur_sensor_info.samp_time, 0, sizeof(_globalSensorMangerTemp->Cur_sensor_info.samp_time));
|
|
|
+ // strftime(_globalSensorMangerTemp->Cur_sensor_info.samp_time, sizeof(_globalSensorMangerTemp->Cur_sensor_info.samp_time), "%Y-%m-%d %H:%M:%S", t);
|
|
|
+ // sprintf(buffer, ".%03ld", tv.tv_usec / 1000);
|
|
|
+ // strcat(_globalSensorMangerTemp->Cur_sensor_info.samp_time, buffer);
|
|
|
+ // if (difftime(now, _globalSensorMangerTemp->Cur_sensor_info.product_log_time) > (30000 / 1000))
|
|
|
+ // {
|
|
|
+ // _globalSensorMangerTemp->Cur_sensor_info.product_log_time = now;
|
|
|
+ // // 插入数据库
|
|
|
+ // ret = dev_insert_sensor_info(_globalDeviceManager->db, &_globalSensorMangerTemp->Cur_sensor_info, &nSaveIndex);
|
|
|
+ // if (ret != 0)
|
|
|
+ // {
|
|
|
+ // log_e("sensor_temp_write database error.");
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if (_globalSensorMangerTemp->sensor_status == 0)
|
|
|
+ // {
|
|
|
+ // sensor_alarm(_globalSensorMangerTemp, SENSOR_VAL1_UPPER);
|
|
|
+ // sensor_alarm(_globalSensorMangerTemp, SENSOR_VAL1_LOWER);
|
|
|
+ // sensor_alarm(_globalSensorMangerTemp, SENSOR_VAL2_UPPER);
|
|
|
+ // sensor_alarm(_globalSensorMangerTemp, SENSOR_VAL2_LOWER);
|
|
|
+ // }
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // pthread_mutex_unlock(&__globalDeviceManage._sensor_update);
|
|
|
+ sleep(1);
|
|
|
|
|
|
}
|
|
|
}
|