package com.dev.data;
|
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
import java.util.Date;
|
import java.util.List;
|
|
import com.base.BaseData;
|
import com.base.Com;
|
import com.base.ComBase;
|
import com.sql.MysqlConnPool;
|
|
/**
|
* ´¦Àí×ÓÕ¾ºÍÆûÂÖ·¢µç»úÊý¾Ý
|
* @author LiJun
|
*
|
*/
|
public class ChildStoodParse_Thread implements Runnable{
|
|
public static final int Config_DataType = 1; //ÅäÖÃÐÅÏ¢
|
public static final int State_DataType = 2; //״ֵ̬ÐÅÏ¢
|
|
public MysqlConnPool conn_pool;
|
public List<Device_inf> devices;
|
public List<ConfigData> configs; //ÅäÖÃÎļþÊý¾Ý
|
public BaseData baseData;
|
public int dev_id; //µ±Ç°½âÎöµÄÉ豸id
|
public int dev_type; //Êý¾ÝÀàÐÍ
|
|
public ChildStoodParse_Thread(MysqlConnPool conn_pool,List<Device_inf> devices,List<ConfigData> configs,BaseData baseData,int dev_type) {
|
this.conn_pool = conn_pool;
|
this.devices = devices;
|
this.configs = configs;
|
this.baseData = baseData;
|
this.dev_type = dev_type;
|
}
|
|
@Override
|
public void run() {
|
//System.out.println(" ChildStoodParse_Thread start at "+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
Device_inf device = null;
|
if(dev_type == Dev_UDPServer_Thread.ZIZHAN_DATATYPE) {
|
/************************½âÎö×ÓÕ¾Êý¾Ý°ü********************************************/
|
device = assemDevData(); //½âÎöÊý¾Ý°ü
|
if(null != device) {
|
//¸üÐÂʵʱÊý¾Ý
|
ChildStoodParse_Thread_SQL.upDeviceRtData(conn_pool,device);
|
|
//²åÈëÀúʷʵʱÊý¾Ý
|
ChildStoodParse_Thread_SQL.insertDeviceHistoryData(conn_pool, device);
|
|
|
}
|
}else if(dev_type == Dev_UDPServer_Thread.QIFA_DATATYPE){
|
|
/************************½âÎöÆûÂÖ·¢µç»úÊý¾Ý°ü********************************************/
|
for(int i = 0; i<devices.size();i++) {
|
if(devices.get(i).dev_id/100 == 40) {
|
//¸üÐÂʵʱÊý¾Ý
|
ChildStoodParse_Thread_SQL.upDeviceRtData(conn_pool,device);
|
|
//²åÈëÀúʷʵʱÊý¾Ý
|
ChildStoodParse_Thread_SQL.insertDeviceHistoryData(conn_pool, device);
|
}
|
}
|
|
}
|
|
Dev_UDPServer_Thread.thread_count--; //×ÜÏß³ÌÊý-1
|
}
|
|
//½âÎöÊý¾Ý
|
public Device_inf assemDevData() {
|
ByteBuffer bf = ByteBuffer.allocate(baseData.data.length);
|
bf.order(ByteOrder.LITTLE_ENDIAN);
|
bf.put(baseData.data);
|
bf.flip();
|
bf.position(0);
|
int index;
|
ConfigData data = null;
|
for(int i=0;i<baseData.dataCount/2;i++) {
|
index = ComBase.changeShortToInt(bf.getShort());
|
data = configs.get(index-1);
|
data.setValue((float)ComBase.changeShortToDouble(bf.getShort()));
|
//data.value = data.value + (float)Math.random()*100;
|
if(i == 0) {
|
dev_id = data.dev_id;
|
}
|
}
|
return getNowDevice(dev_id);
|
}
|
|
/**
|
* »ñÈ¡µ±Ç°É豸
|
* @param dev_id
|
* @return
|
*/
|
public Device_inf getNowDevice(int dev_id) {
|
for(int i=0;i<devices.size();i++) {
|
if(dev_id == devices.get(i).dev_id) {
|
return devices.get(i);
|
}
|
}
|
return null;
|
}
|
|
/**
|
* ¼ì²éÉ豸¸æ¾¯¼Ç¼
|
* @param conn_pool
|
* @param dev
|
*/
|
public static void checkDevAlarm(MysqlConnPool conn_pool,Device_inf dev) {
|
String sql_str = "";
|
}
|
|
|
public static void main(String[] args) {
|
int max=100,min=1;
|
int ran2 = (int) (Math.random()*(max-min)+min);
|
System.out.println(ran2);
|
}
|
}
|