综合管理平台数据库数据模拟程序
Administrator
2021-03-25 578faecf2a59d3062c96aed307b6df80c87a315d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.thread.devs;
 
import java.util.Date;
 
import com.mode.Device_Inf;
import com.mode.Manage_Util;
import com.mode.Motor_State;
import com.sql.MysqlConnPool;
 
public class Manage_Simul_Motor_Thread implements Runnable{
    public MysqlConnPool pool;
    public Device_Inf device;
    public Motor_State state;
    
    public Manage_Simul_Motor_Thread(MysqlConnPool pool,Device_Inf device){
        this.device = device;
        this.pool = pool;
        state = new Motor_State(device.getDevice_id());
    }
    
    @Override
    public void run() {
        Manage_Simul_Motor_Thread_SQL.insertOrUpdateMotor_State_Table(pool, state);
        while(true) {
            try {
                createRandomData(state);
                
                Manage_Simul_Motor_Thread_SQL.updateMotor_State_Table(pool, state);
                
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    
    public void createRandomData(Motor_State state) {
        state.record_time = new Date();//'¼Ç¼ʱ¼ä',
        state.motor_curr = state.motor_curr + Manage_Util.CreateIntRandom()*Manage_Util.CreateFloat0To1();//'µç»úµçÁ÷',
        state.motor_power = state.motor_power + Manage_Util.CreateIntRandom()*Manage_Util.CreateFloat0To1();//'µç»ú¹¦ÂÊ',
        state.motor_speed = state.motor_speed + Manage_Util.CreateIntRandom()*Manage_Util.CreateFloat0To1();//'µç»úתËÙ',
        state.motor_vol = state.motor_vol + Manage_Util.CreateIntRandom()*Manage_Util.CreateFloat0To1();//'µç»úµçѹ',
        state.motor_out_tmp = state.motor_out_tmp + Manage_Util.CreateIntRandom()*Manage_Util.CreateFloat0To1();//'µç»ú³ö¿ÚζÈ',
        state.motor_into_tmp = state.motor_into_tmp + Manage_Util.CreateIntRandom()*Manage_Util.CreateFloat0To1();//'µç»ú½ø¿ÚζÈ',
        state.motor_torque = state.motor_torque+ Manage_Util.CreateIntRandom()*Manage_Util.CreateFloat0To1();//'µç»úת¾Ø',
        state.motor_state = Manage_Util.CreateSwitchRanDom();//'µç»ú״̬',
    }
    
    
}