package tomolib.bouhan;
import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*; //2006/11/21
import tomolib.net.*;
import tomolib.util.*;
/**
* BouhanComm
* 処理概要:Udp通信で防犯装置に命令を送付し、結果をファイルするプログラム
* 作者:TomoyukiIto
* 履歴:
* 2006/05/9 製作開始
* 2006/11/21dbs接続を追加する
2007/2/28動作設定DATA読み込みを毎時行うように変更する。
*/
public class BouhanComm implements Runnable
{
Thread timer;
//通信制御数
int num ;
String snum ;
//返信してきたH83664の名前
String returndConName ;
//返信DATA
String returndData ;
//返信した通信制御数
String returndNum ;
/**制御Dataの行数が入る*/
public int row = 0 ;
/**制御Dataの列数が入る*/
public int col = 0 ;
//制御Data(String)
public String[][] data = null ;
//制御Data(int)
public int[] data_mon = null;
public int[] data_day = null;
public int[] data_hr = null;
public int[] data_min = null;
//保存ファイルの作成
TextFile t = new TextFile();
//受信したDATAの入れ物
String rmessage = "";
//送信する命令
String smessage = "";
//Udpの初期化
Udp u = new Udp() ;
//時刻管理
Util util = new Util();
//dbs関連 2006/11/21
// ユーザ名の指定
String user = "wmpq11<<";
// パスワードの記入
String password = "as>zp";
// 接続先の指定
Connection conn = null;
Statement stmt = null;
//動作するOS
String osname =null;
public static void main( String argv[] ) //throws SQLException, IOException
{
BouhanComm bp = new BouhanComm() ;
}
public BouhanComm()
{
timer = new Thread(this);
timer.start();
}
public void readData()
{
//処理DATAの取り込み
col = 8;
readKanmaFile rkf = new readKanmaFile();
if( osname.equals( "Linux" ) ){
rkf.read(col, "/var/socie/tomolib/bouhan/bouhan.csv" ) ;
}else if( osname.equals( "Windows" ) ){
rkf.read(col, "bouhan.csv" ) ;
}
data = rkf.data ;
row = rkf.row;
// System.out.println( row + " " +col );
data_mon = new int[ row ];data_day = new int[ row ];
data_hr = new int[ row ];data_min = new int[ row ];
//for(int ii=0;ii=0){
osname = "Windows" ;
} else if(osname.indexOf( "Linux" )>=0){
osname = "Linux" ;
} else if(osname.indexOf( "Mac" )>=0){
osname = "Mac" ;
} else {
// その他の環境だったときの処理
}
//出力ファイル作成
Calendar c = Calendar.getInstance(); //現在時刻のカレンダー作成
if( osname.equals( "Linux" ) ){
t.OutOpen( "/var/socie/tomolib/bouhan/"+util.CalendarToString1(c) + ".txt" );
}else if( osname.equals( "Windows" ) ){
t.OutOpen( util.CalendarToString1(c) + ".txt" );
}
//通信相手(H8LAN)の設定
try {
u.iniUdp( 124 , "192.168.6.23" );
}catch( Exception e ) { System.out.println( "初期化失敗shokika failed" ) ; System.exit(-1); }
try{
//dbs関連 2006/11/21
// PostgreSQL JDBC driverのロード
DriverManager.registerDriver(new org.postgresql.Driver());
conn = DriverManager.getConnection ("jdbc:postgresql://localhost:5432/bouhan046",user, password);
stmt = conn.createStatement ();
}catch( Exception e ) {}
//設定DATA読み込み
readData();
//無限ループ
do{
// for( kount1=0; kount1<10000 ; kount1++ ){for( kount2=0; kount2<10000 ; kount2++ ){}}
//1秒休憩
try{ timer.sleep(1000);}catch(InterruptedException e){}
c = Calendar.getInstance(); //現在時刻のカレンダー作成
min = c.get( Calendar.MINUTE );
hr = c.get( Calendar.HOUR_OF_DAY );
day = c.get( Calendar.DAY_OF_MONTH );
mon = c.get( Calendar.MONTH ) + 1;
// System.out.println( mon+"/"+day+"/"+hr+"/"+min );
for(int i=0;i|