81041
2019-01-15 253879d0d562db0290a67160d30d3f15e8e7bf09
gx_tieta/src/com/fgkj/dao/BattTestData.java
@@ -1,7 +1,16 @@
package com.fgkj.dao;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
public class BattTestData {
final public static int BATT_MON_COUNT_MAX = 512;
   final public static int BATT_DISCHARGE=3;//放电测试
   final public static int BATT_RES=5;//内阻测试
   final public static int AppServer_Reinit_BattGroupData_EN=1;//修改删除添加电池组信息时识别信号
    final public static int BATT_MON_COUNT_MAX = 512;
   
   final public static byte BATTDATA_NULL = 0;
   final public static byte BATTDATA_FLOAT = 1;
@@ -66,6 +75,78 @@
   
   //落后单体参数(组端电压>标称*test_stop)
   public static final float test_stop = 0.9f;
   //启动创建数据库的jar文件
   public static void run_cmdOld() {
      String path=System.getProperty("user.dir");
      String realapth=path.substring(0,path.lastIndexOf("\\"));
      //System.out.println(realapth);
      String strcmd="cmd /c start  "+realapth+"/webapps/cmd_BTSE_DB_Builder.cmd";
      //
        Runtime rt = Runtime.getRuntime(); //Runtime.getRuntime()返回当前应用程序的Runtime对象
        Process ps = null;  //Process可以控制该子进程的执行或获取该子进程的信息。
        try {
            ps = rt.exec(strcmd);   //该对象的exec()方法指示Java虚拟机创建一个子进程执行指定的可执行程序,并返回与该子进程对应的Process对象实例。
            ps.waitFor();  //等待子进程完成再往下执行。
        } catch (IOException e1) {
            e1.printStackTrace();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        int i = ps.exitValue();  //接收执行完毕的返回值
        if (i == 0) {
            System.out.println("执行完成.");
        } else {
            System.out.println("执行失败.");
        }
        ps.destroy();  //销毁子进程
        ps = null;
    }
   //启动创建数据库的jar文件
   public static void run_cmd() {
      String path=System.getProperty("user.dir");            //myeclipse中获取的目录(获取到的是tomcat/bin)和分离项目获取到的路径(tomcat)不一样
      //System.out.println(path);
      String realapth=path.substring(0,path.lastIndexOf("\\"));
      String strcmd="cmd /c start  "+realapth+"/webapps/cmd_BTSE_DB_Builder.cmd";
      String batPath = realapth+"/webapps/cmd_BTSE_DB_Builder.cmd";
      File f = new File(path);
        //System.out.println("File :"+f.getParentFile().getAbsolutePath()+File.separator+"Batt_MS_FBSDEV_X64/Batt_MS_FBSDEV/"+"cmd_BTSE_DB_Builder.cmd");
        //batPath = f.getParentFile().getAbsolutePath()+File.separator+"Batt_MS_FBSDEV_X64/Batt_MS_FBSDEV/"+"cmd_BTSE_DB_Builder.cmd";
      String jarPath = "";
      if(path.endsWith("bin")){
         f = f.getParentFile();
        }
      jarPath = f.getParentFile().getAbsolutePath()+File.separator+"Batt_MS_FBSDEV_X64/Batt_MS_FBSDEV/"+"BTSE_DB_Builder.exe";            //主程序中exe的目录
        //strcmd = "cmd /c start "+batPath;
        strcmd = ("cmd /c start ")+jarPath.replaceAll(" ", "\" \"");         //修复绝对路径中存在空格时执行不成功bug
        System.out.println(strcmd);
        Process child = null;
      InputStream in = null;
      try {
         //System.out.println(strcmd);
         child = Runtime.getRuntime().exec(strcmd);
         in = child.getInputStream();
         int c;
         while ((c = in.read()) != -1) {
            //System.out.print((char)c);
         }
         in.close();
         try {
            child.waitFor();
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
         //System.out.println("Run Bat OK....");
      } catch (IOException e) {
         e.printStackTrace();
      }
    }
   //判断电池组的当前状态
   public static String battState(int num){
      String state="";
@@ -180,13 +261,45 @@
      return stop_type; 
   }
    //设备状态变换对应关系
   public static String getFbsdev_Statechange(int state){
      String state_name="停止";
      switch(state){
            case 0:state_name="停止";break;
            case 1:state_name="放电";break;
            case 2:state_name="充电";break;
         }
   public static String getFbsdev_Statechange(int eve_type,int state){
      String state_name="未知";
      if(eve_type==0){
         if(state==0){
            state_name="在线监测";
         }else if(state==1){
            state_name="放电测试";
         }else if(state==2){
            state_name="充电测试";
         }else if(state==3){
            state_name="升压续航";
         }
      }else if(eve_type==11){
         if(state==0){
            state_name="正常";
         }else if(state==1){
            state_name="故障";
         }
      }else if(eve_type==12){
         if(state==0){
            state_name="在线";
         }else if(state==1){
            state_name="离线";
         }
      }else if(eve_type==20){
         state_name="0x"+Integer.toHexString(state);
      }
      return state_name;
   }
   //设备状态变换对应eve_type
   public static String getEve_type_name(int eve_type){
      String eve_type_name="未知";
      switch(eve_type){
            case 0:eve_type_name="BTS工作状态";break;
            case 11:eve_type_name="SD卡故障";break;
            case 12:eve_type_name="电池离线状态";break;
            case 20:eve_type_name="DCDC模块告警状态";break;
         }
      return eve_type_name;
   }
}