| | |
| | | 2021-03-25 11:16:09.984 [main] [WARN] main.main_Demo_Manage_Simul - IP:127.0.0.1port3360
|
| | | 2021-03-25 11:16:09.994 [main] [WARN] main.main_Demo_Manage_Simul - 开始检测数据库连接 2021-03-25 11:16:09
|
| | | 2021-03-25 11:16:10.197 [main] [WARN] main.main_Demo_Manage_Simul - 检测数据库连接成功
|
| | | 2021-03-25 12:01:38.452 [main] [WARN] main.main_Demo_Manage_Simul - main_MonitorServer_Motor Server VWelcome To Use main_Demo_Manage_Simul V1.101 Started At DateTime: 2021-03-25 12:01:38
|
| | | 2021-03-25 12:01:38.483 [main] [WARN] main.main_Demo_Manage_Simul - SQLserver IP:127.0.0.1, port: 3360
|
| | | 2021-03-25 12:01:39.146 [main] [WARN] main.main_Demo_Manage_Simul - IP:127.0.0.1port3360
|
| | | 2021-03-25 12:01:39.158 [main] [WARN] main.main_Demo_Manage_Simul - 开始检测数据库连接 2021-03-25 12:01:39
|
| | | 2021-03-25 12:01:39.362 [main] [WARN] main.main_Demo_Manage_Simul - 检测数据库连接成功 |
| | | 2021-03-25 12:02:13.914 [main] [WARN] main.main_Demo_Manage_Simul - main_MonitorServer_Motor Server VWelcome To Use main_Demo_Manage_Simul V1.101 Started At DateTime: 2021-03-25 12:02:13
|
| | | 2021-03-25 12:02:13.944 [main] [WARN] main.main_Demo_Manage_Simul - SQLserver IP:127.0.0.1, port: 3360
|
| | | 2021-03-25 12:02:14.596 [main] [WARN] main.main_Demo_Manage_Simul - IP:127.0.0.1port3360
|
| | | 2021-03-25 12:02:14.606 [main] [WARN] main.main_Demo_Manage_Simul - 开始检测数据库连接 2021-03-25 12:02:14
|
| | | 2021-03-25 12:02:14.807 [main] [WARN] main.main_Demo_Manage_Simul - 检测数据库连接成功 |
| | |
| | | package com.mode;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.Random;
|
| | |
|
| | | public class Manage_Util{
|
| | |
|
| | | public static final int DEV_TYPE_DYNAMICLOAD = 1001; //水冷负载
|
| | |
| | | public static final int DEV_TYPE_4MWPOWER = 1003; //1号,2号大功率整流电源
|
| | | public static final int DEV_TYPE_2MWPOWER = 1004; //3号大功率整流电源
|
| | |
|
| | | /**
|
| | | * 随机生成开关量变量
|
| | | * @return
|
| | | */
|
| | | public static int CreateSwitchRanDom() {
|
| | | return new BigDecimal(Math.random()).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 随机生成1或者-1
|
| | | * @return
|
| | | */
|
| | | public static int CreateIntRandom() {
|
| | | Random rand = new Random();
|
| | | if (rand.nextBoolean())
|
| | | return 1;
|
| | | else
|
| | | return -1;
|
| | | }
|
| | | |
| | | /**
|
| | | * 生成整数随机数
|
| | | * @return
|
| | | */
|
| | | public static int CreateIntRanDom() {
|
| | | return new Random().nextInt();
|
| | | }
|
| | | |
| | | /**
|
| | | * 生成整数随机数
|
| | | * @return 包含min,不包含max
|
| | | */
|
| | | public static int CreateIntRanDom(int min,int max) {
|
| | | return (min + ((int) (new Random().nextFloat() * (max - min))));
|
| | | }
|
| | | |
| | | /**
|
| | | * 生成0.0-1.0之间的float随机数
|
| | | * @return 包含0.0不包含1.0
|
| | | */
|
| | | public static float CreateFloat0To1() {
|
| | | return new Random().nextFloat();
|
| | | }
|
| | | |
| | | /**
|
| | | * 生成有边界的float 随机数
|
| | | * @param min
|
| | | * @param max
|
| | | * @return
|
| | | */
|
| | | public static float CreateFloatRanDom(float min,float max) {
|
| | | return (min + new Random().nextFloat() * (max - min));
|
| | | } |
| | | |
| | | public static void main(String[] args) {
|
| | | for(int i=0;i<1000;i++) {
|
| | | System.out.println(CreateIntRandom());
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | public class Motor_State {
|
| | | public int device_id;// '设备id',
|
| | | public Date record_time;//'记录时间',
|
| | | public float motor_curr;//'电机电流',
|
| | | public float motor_power;//'电机功率',
|
| | | public float motor_speed;//'电机转速',
|
| | | public float motor_vol;//'电机电压',
|
| | | public float motor_out_tmp;//'电机出口温度',
|
| | | public float motor_into_tmp;//'电机进口温度',
|
| | | public float motor_torque;//'电机转矩',
|
| | | public int motor_state;//'电机状态',
|
| | | public float motor_curr = 99.6f;//'电机电流',
|
| | | public float motor_power = 50;//'电机功率',
|
| | | public float motor_speed = 0;//'电机转速',
|
| | | public float motor_vol = 300;//'电机电压',
|
| | | public float motor_out_tmp = 32;//'电机出口温度',
|
| | | public float motor_into_tmp = 65;//'电机进口温度',
|
| | | public float motor_torque = 1000;//'电机转矩',
|
| | | public int motor_state = 1;//'电机状态',
|
| | | |
| | | public Motor_State(int device_id){
|
| | | this.device_id = device_id;
|
| | | }
|
| | | |
| | | public int getDevice_id() {
|
| | | return device_id;
|
| | | }
|
| | |
| | | import com.mode.Device_Inf;
|
| | | import com.mode.Manage_Util;
|
| | | import com.sql.MysqlConnPool;
|
| | | import com.thread.devs.Manage_Simul_Motor_Thread;
|
| | |
|
| | | public class Manage_Simul_Server {
|
| | | public MysqlConnPool pool;
|
| | |
| | | if(devices.size() > 0) {
|
| | | for(int i=0;i<devices.size();i++) {
|
| | | Device_Inf dev = devices.get(i);
|
| | | System.out.println(dev);
|
| | | //System.out.println(dev);
|
| | | switch(dev.getSystem_id()) {
|
| | | case Manage_Util.DEV_TYPE_DYNAMICLOAD:{
|
| | |
|
| | |
| | |
|
| | | }break;
|
| | | case Manage_Util.DEV_TYPE_MOTOR:{
|
| | | |
| | | Manage_Simul_Motor_Thread motor_thread = new Manage_Simul_Motor_Thread(pool, dev);
|
| | | new Thread(motor_thread).start();
|
| | | }break;
|
| | | }
|
| | | }
|
New file |
| | |
| | | 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() {
|
| | | |
| | | while(true) {
|
| | | try {
|
| | | createRandomData(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();//'电机状态',
|
| | | }
|
| | | |
| | | |
| | | }
|
New file |
| | |
| | | package com.thread.devs;
|
| | |
|
| | | import com.mode.Motor_State;
|
| | | import com.sql.MysqlConnPool;
|
| | | import com.sql.Sql_Mysql;
|
| | |
|
| | | public class Manage_Simul_Motor_Thread_SQL {
|
| | |
|
| | | public static void insertMotor_State_Table(MysqlConnPool pool,Motor_State state) {
|
| | | String sql_str = " SELECT device_id FROM "+Sql_Mysql.Tb_Motor_State_Table+" WHERE device_id = " + state.device_id;
|
| | | String sql_str_ins = " INSERT INTO " + Sql_Mysql.Tb_Motor_State_Table +
|
| | | "(device_id,record_time,motor_curr,motor_power,motor_speed,motor_vol,motor_out_tmp,motor_into_tmp,motor_torque,motor_state) " + |
| | | "VALUES("+state.device_id+",'"+state.record_time+"',"+state.motor_curr+","+state.motor_power+","+state.motor_speed+","+state.motor_vol+","+state.motor_out_tmp+","+state.motor_into_tmp+","+state.motor_torque+","+state.motor_state+")";
|
| | | |
| | | }
|
| | | |
| | | }
|