package com.pcstar.people.activity;
/**
 * 描述：此类为设置类
 * 主要作用：
 * 1.各种通信设备配置及组网
 * 2.系统基本设置
 */
import java.io.UnsupportedEncodingException;

import com.friendlyarm.AndroidSDK.HardwareControler;
import com.pcstar.people.socket.UDPClientSocket;
import com.pcstar.people.sqlite.Mysqlite;
import com.pcstar.people.utils.Configuration;
import com.pcstar.people.utils.Utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class TaskSetActivity extends Activity implements OnCheckedChangeListener,
OnClickListener{
	private String thread = "readThread";
	byte[] buf= new byte[300];
	private String readStr;
	private Button backButton;
	private RadioButton radioButton0;
	private RadioButton radioButton1;
	private RadioButton radioButton2;
	private Button bindButton;//绑定手机号
	private EditText phoneEdit;//手机号输入框
	private SharedPreferences sharedPreferences;//绑定手机号
	private String phone;
	//系统设置选项按钮
	private RadioButton zigbeeRadioButton;
	private RadioButton bluetoothRadioButton;
	private RadioButton cc1101RadioButton;
	private RadioButton rs485RadioButton;
	private RadioButton canRadioButton;
	//系统设置子布局
	private LinearLayout zigbeeLLayout;
	private LinearLayout bluetoothLLayout;
	private LinearLayout cc1101LLayout;
	private LinearLayout rs485LLayout;
	private LinearLayout canLLayout;
	//zigbee_layout
	private RadioButton zigbeeCoordinatorRadioButton;
	private RadioButton zigbeeRouterRadioButton;
	private RadioButton zigbeeRadioButton11;
	private RadioButton zigbeeRadioButton12;
	private RadioButton zigbeeRadioButton13;
	private RadioButton zigbeeRadioButton14;
	private RadioButton zigbeeRadioButton15;
	private RadioButton zigbeeRadioButton16;
	private RadioButton zigbeeRadioButton17;
	private RadioButton zigbeeRadioButton18;
	private RadioButton zigbeeRadioButton19;
	private RadioButton zigbeeRadioButton20;
	private RadioButton zigbeeRadioButton21;
	private RadioButton zigbeeRadioButton22;
	private RadioButton zigbeeRadioButton23;
	private RadioButton zigbeeRadioButton24;
	private RadioButton zigbeeRadioButton25;
	private RadioButton zigbeeRadioButton26;
	private Button zigbeeQueryButton1;
	private Button zigbeeSetButton1;
	private Button zigbeeQueryButton2;
	private Button zigbeeSetButton2;
	private Button zigbeeQueryButton3;
	private Button zigbeeSetButton3;
	private EditText zigbeeEdit;
	private RadioGroup radioGroup1;
	private RadioGroup radioGroup2;
	//bluetooth_layout组件
	private RadioButton yesAAARadioButton;
	private RadioButton noAAARadioButton;
	private RadioButton yesBindingRadioButton;
	private RadioButton noBindingRadioButton;
	private EditText nameEdit;
	private EditText workModeEdit;
	private EditText bluetoothPasswordEdit;	
	private EditText workPatternEdit;
	private Button queryNameButton;
	private Button setNameButton;
	private Button queryworkModeButton;
	private Button queryPasswordButton;
	private Button setPasswordButton;
	private Button queryWorkPatternButton;
	private Button setWorkPatternButton;
	private Button queryAAAButton;
	private Button setAAAButton;
	private Button queryBindingButton;
	private Button setBindingButton;
	private Button clearButton;
	private Button restartButton;
	//can_layout组件
	private RadioButton canRadioButton100;
	private RadioButton canRadioButton200;
	private RadioButton canRadioButton250;
	private RadioButton canRadioButton500;
	private RadioButton cannormRadioButton;
	private RadioButton canexpendRadioButton;
	private Button queryButton2;
	private Button setButton1;
	private Button setButton2;
	private EditText canEdit;
	//rs485_layout组件
	private RadioButton rs485RadioButton2400;
	private RadioButton rs485RadioButton4800;
	private RadioButton rs485RadioButton9600;
	private RadioButton rs485RadioButton19200;
	private RadioButton rs485RadioButton38400;
	private RadioButton rs485RadioButton8;
	private RadioButton rs485RadioButton9;
	private RadioButton rs485RadioButtonno;
	private RadioButton rs485RadioButtonji;
	private RadioButton rs485RadioButtonou;
	private RadioButton rs485RadioButton2;
	private RadioButton rs485RadioButton3;
	private RadioButton rs485RadioButton4;
	private RadioButton rs485RadioButtonin;
	private RadioButton rs485RadioButtonout;
	private Button rs485SetButton1;
	private Button rs485SetButton2;
	private Button rs485QueryButton3;
	private Button rs485SetButton3;
	private EditText rs485EditText;
	//cc1101_layout组件
	private RadioButton cc1101DataRadioButton;
	private RadioButton cc1101DecodeRadioButton;
	private EditText cc1101Edit;
	private Button cc1101QueryButton;
	private Button cc1101SetButton;
	private Button cc1101SetButton1;
	//家居设置界面布局
	private LinearLayout homesetLLayout;
	//系统设置界面布局
	private LinearLayout systemsetLLayout;
	//点击选项后的三个布局
	private RelativeLayout phoneRLayout;
	private RelativeLayout alertingRLayout;
	private RelativeLayout setRLayout;
	
	private EditText passwordEdit;//管理员密码框
	private Button loginButton;
	private String password;
	//蓝牙变量
	private String AUTH_enable = "1";
	private String BIND_enable = "1";
	//CAN变量
	private String CANSET_B = "1";
	private String CANSET_D = "1";
	private String CANID_M;
	private String CANID_id;
	//CC1101变量
	private String MODE_Str = "DATA";
	private String ADDRESS_M;
	private String ADDRESS_addr;
	//RS485变量
	private String RS485SET_N = "1";
	private String RS485SET_B;
	private String RS485SET_D;
	private String RS485SET_P;
	private String RS485SET_S;
	private String RS485SET_F = "0";
	private String RS485MODE_N = "1";
	private String RS485MODE_mode = "0";
	private String RS485ADDR_M;
	private String RS485ADDR_addr;
	//zigbee变量
	private Boolean changeGroup = false;
	private String ZNODE_M;
	private String ZCHANNEL_N = "11";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_taskset);
        initView();
        initCanView();
        initRs485View();
        initCc1101View();
        initBluetoothView();
        initZigBeeView();
        //让之前的串口监听线程停止
        Configuration.isRun = false;
        //开始串口的监听线程 
        new readThread().start(); 
    }
	/**
	 * 描述：实例化zigbee_layout组件
	 */
	public void initZigBeeView(){
		zigbeeCoordinatorRadioButton = (RadioButton)findViewById(R.id.zigbee_coordinatorRadioButton);
		zigbeeRouterRadioButton = (RadioButton)findViewById(R.id.zigbee_routerRadioButton);
		zigbeeRadioButton11 = (RadioButton)findViewById(R.id.zigbee_RadioButton11);
		zigbeeRadioButton12 = (RadioButton)findViewById(R.id.zigbee_RadioButton12);
		zigbeeRadioButton13 = (RadioButton)findViewById(R.id.zigbee_RadioButton13);
		zigbeeRadioButton14 = (RadioButton)findViewById(R.id.zigbee_RadioButton14);
		zigbeeRadioButton15 = (RadioButton)findViewById(R.id.zigbee_RadioButton15);
		zigbeeRadioButton16 = (RadioButton)findViewById(R.id.zigbee_RadioButton16);
		zigbeeRadioButton17 = (RadioButton)findViewById(R.id.zigbee_RadioButton17);
		zigbeeRadioButton18 = (RadioButton)findViewById(R.id.zigbee_RadioButton18);
		zigbeeRadioButton19 = (RadioButton)findViewById(R.id.zigbee_RadioButton19);
		zigbeeRadioButton20 = (RadioButton)findViewById(R.id.zigbee_RadioButton20);
		zigbeeRadioButton21 = (RadioButton)findViewById(R.id.zigbee_RadioButton21);
		zigbeeRadioButton22 = (RadioButton)findViewById(R.id.zigbee_RadioButton22);
		zigbeeRadioButton23 = (RadioButton)findViewById(R.id.zigbee_RadioButton23);
		zigbeeRadioButton24 = (RadioButton)findViewById(R.id.zigbee_RadioButton24);
		zigbeeRadioButton25 = (RadioButton)findViewById(R.id.zigbee_RadioButton25);
		zigbeeRadioButton26 = (RadioButton)findViewById(R.id.zigbee_RadioButton26);
		zigbeeQueryButton1 = (Button)findViewById(R.id.zigbee_queryButton1);
		zigbeeSetButton1 = (Button)findViewById(R.id.zigbee_setButton1);
		zigbeeQueryButton2 = (Button)findViewById(R.id.zigbee_queryButton2);
		zigbeeSetButton2 = (Button)findViewById(R.id.zigbee_setButton2);
		zigbeeQueryButton3 = (Button)findViewById(R.id.zigbee_queryButton3);
		zigbeeSetButton3 = (Button)findViewById(R.id.zigbee_setButton3);
		radioGroup1 = (RadioGroup)findViewById(R.id.zigbee_RadioGroup1);
		radioGroup2 = (RadioGroup)findViewById(R.id.zigbee_RadioGroup2);
		zigbeeEdit = (EditText)findViewById(R.id.zigbee_nameEdit);
		
		zigbeeCoordinatorRadioButton.setOnCheckedChangeListener(this);
		zigbeeRouterRadioButton.setOnCheckedChangeListener(this);
		zigbeeRadioButton11.setOnCheckedChangeListener(this);
		zigbeeRadioButton12.setOnCheckedChangeListener(this);
		zigbeeRadioButton13.setOnCheckedChangeListener(this);
		zigbeeRadioButton14.setOnCheckedChangeListener(this);
		zigbeeRadioButton15.setOnCheckedChangeListener(this);
		zigbeeRadioButton16.setOnCheckedChangeListener(this);
		zigbeeRadioButton17.setOnCheckedChangeListener(this);
		zigbeeRadioButton18.setOnCheckedChangeListener(this);
		zigbeeRadioButton19.setOnCheckedChangeListener(this);
		zigbeeRadioButton20.setOnCheckedChangeListener(this);
		zigbeeRadioButton21.setOnCheckedChangeListener(this);
		zigbeeRadioButton22.setOnCheckedChangeListener(this);
		zigbeeRadioButton23.setOnCheckedChangeListener(this);
		zigbeeRadioButton24.setOnCheckedChangeListener(this);
		zigbeeRadioButton25.setOnCheckedChangeListener(this);
		zigbeeRadioButton26.setOnCheckedChangeListener(this);
		zigbeeQueryButton1.setOnClickListener(this);
		zigbeeSetButton1.setOnClickListener(this);
		zigbeeQueryButton2.setOnClickListener(this);
		zigbeeSetButton2.setOnClickListener(this);
		zigbeeQueryButton3.setOnClickListener(this);
		zigbeeSetButton3.setOnClickListener(this);
		
		radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				 if (group != null && checkedId > -1 && changeGroup == false){
					 changeGroup = true;
					 radioGroup2.clearCheck();
					 changeGroup = false;					 
				 }
				
			}
		});
		radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				// TODO Auto-generated method stub
				if (group != null && checkedId > -1 && changeGroup == false){
					changeGroup = true;
					radioGroup1.clearCheck();
					changeGroup = false;
				}				
			}
		});
	}
	/**
	 * 描述：实例化bluetooth_layout组件
	 */
	public void initBluetoothView(){
		yesAAARadioButton = (RadioButton)findViewById(R.id.bluetooth_yesAAARadioButton);
		noAAARadioButton = (RadioButton)findViewById(R.id.bluetooth_noAAARadioButton);
		yesBindingRadioButton = (RadioButton)findViewById(R.id.bluetooth_yesBindingRadioButton);
		noBindingRadioButton = (RadioButton)findViewById(R.id.bluetooth_noBindingRadioButton);
		
		queryNameButton = (Button)findViewById(R.id.bluetooth_queryNameButton);
		setNameButton = (Button)findViewById(R.id.bluetooth_setNameButton);
		queryworkModeButton = (Button)findViewById(R.id.bluetooth_queryworkModeButton);
		queryPasswordButton = (Button)findViewById(R.id.bluetooth_queryPasswordButton);
		setPasswordButton = (Button)findViewById(R.id.bluetooth_setPasswordButton);
		queryWorkPatternButton = (Button)findViewById(R.id.bluetooth_queryWorkPatternButton);
		setWorkPatternButton = (Button)findViewById(R.id.bluetooth_setWorkPatternButton);
		queryAAAButton = (Button)findViewById(R.id.bluetooth_queryAAAButton);
		setAAAButton = (Button)findViewById(R.id.bluetooth_setAAAButton);
		queryBindingButton = (Button)findViewById(R.id.bluetooth_queryBindingButton);
		setBindingButton = (Button)findViewById(R.id.bluetooth_setBindingButton);
		clearButton = (Button)findViewById(R.id.bluetooth_clearButton);
		restartButton = (Button)findViewById(R.id.bluetooth_restartButton);
		nameEdit = (EditText)findViewById(R.id.bluetooth_nameEdit);
		workModeEdit = (EditText)findViewById(R.id.bluetooth_workModeEdit);
		bluetoothPasswordEdit = (EditText)findViewById(R.id.bluetooth_passwordEdit);
		workPatternEdit = (EditText)findViewById(R.id.bluetooth_workPatternEdit);
		
		yesAAARadioButton.setOnCheckedChangeListener(this);
		noAAARadioButton.setOnCheckedChangeListener(this);
		yesBindingRadioButton.setOnCheckedChangeListener(this);
		noBindingRadioButton.setOnCheckedChangeListener(this);
		queryNameButton.setOnClickListener(this);
		setNameButton.setOnClickListener(this);
		queryworkModeButton.setOnClickListener(this);
		queryPasswordButton.setOnClickListener(this);
		setPasswordButton.setOnClickListener(this);
		queryWorkPatternButton.setOnClickListener(this);
		setWorkPatternButton.setOnClickListener(this);
		queryAAAButton.setOnClickListener(this);
		setAAAButton.setOnClickListener(this);
		queryBindingButton.setOnClickListener(this);
		setBindingButton.setOnClickListener(this);
		clearButton.setOnClickListener(this);
		restartButton.setOnClickListener(this);
	}
	/**
	 * 描述：实例化cc1101_layout组件
	 */
	public void initCc1101View(){
		cc1101DataRadioButton = (RadioButton)findViewById(R.id.cc1101_dataRadioButton);
		cc1101DecodeRadioButton = (RadioButton)findViewById(R.id.cc1101_decodeRadioButton);
		cc1101QueryButton = (Button)findViewById(R.id.cc1101_queryButton);
		cc1101SetButton = (Button)findViewById(R.id.cc1101_setButton);
		cc1101SetButton1 = (Button)findViewById(R.id.cc1101_setButton1);
		cc1101Edit = (EditText)findViewById(R.id.cc1101_addressEdit);
		
		cc1101DataRadioButton.setOnCheckedChangeListener(this);
		cc1101DecodeRadioButton.setOnCheckedChangeListener(this);
		cc1101QueryButton.setOnClickListener(this);
		cc1101SetButton.setOnClickListener(this);
		cc1101SetButton1.setOnClickListener(this);
	}
	/**
	 * 描述：实例化can_layout组件
	 */
	public void initCanView(){
		canRadioButton100 = (RadioButton)findViewById(R.id.can_100RadioButton);
		canRadioButton200 = (RadioButton)findViewById(R.id.can_200RadioButton);
		canRadioButton250 = (RadioButton)findViewById(R.id.can_250RadioButton);
		canRadioButton500 = (RadioButton)findViewById(R.id.can_500RadioButton);
		cannormRadioButton = (RadioButton)findViewById(R.id.can_normRadioButton);
		canexpendRadioButton = (RadioButton)findViewById(R.id.can_expandRadioButton);
		queryButton2 = (Button)findViewById(R.id.can_queryButton2);
		setButton1 = (Button)findViewById(R.id.can_setButton1);
		setButton2 = (Button)findViewById(R.id.can_setButton2);
		canEdit = (EditText)findViewById(R.id.can_addressEdit);
		
		canRadioButton100.setOnCheckedChangeListener(this);
		canRadioButton200.setOnCheckedChangeListener(this);
		canRadioButton250.setOnCheckedChangeListener(this);
		canRadioButton500.setOnCheckedChangeListener(this);
		cannormRadioButton.setOnCheckedChangeListener(this);
		canexpendRadioButton.setOnCheckedChangeListener(this);
		queryButton2.setOnClickListener(this);
		setButton1.setOnClickListener(this);
		setButton2.setOnClickListener(this);
		canEdit.setOnClickListener(this);
	}
	/**
	 * 描述：实例化rs485组件
	 */
	public void initRs485View(){
		rs485RadioButton2400 = (RadioButton)findViewById(R.id.rs485_2400RadioButton);
		rs485RadioButton4800 = (RadioButton)findViewById(R.id.rs485_4800RadioButton);
		rs485RadioButton9600 = (RadioButton)findViewById(R.id.rs485_9600RadioButton);
		rs485RadioButton19200 = (RadioButton)findViewById(R.id.rs485_19200RadioButton);
		rs485RadioButton38400 = (RadioButton)findViewById(R.id.rs485_38400RadioButton);
		rs485RadioButton8 = (RadioButton)findViewById(R.id.rs485_8RadioButton);
		rs485RadioButton9 = (RadioButton)findViewById(R.id.rs485_9RadioButton);
		rs485RadioButtonno = (RadioButton)findViewById(R.id.rs485_noRadioButton);
		rs485RadioButtonji = (RadioButton)findViewById(R.id.rs485_jiRadioButton);
		rs485RadioButtonou = (RadioButton)findViewById(R.id.rs485_ouRadioButton);
		rs485RadioButton2 = (RadioButton)findViewById(R.id.rs485_2RadioButton);
		rs485RadioButton3 = (RadioButton)findViewById(R.id.rs485_3RadioButton);
		rs485RadioButton4 = (RadioButton)findViewById(R.id.rs485_4RadioButton);
		rs485RadioButtonin = (RadioButton)findViewById(R.id.rs485_inRadioButton);
		rs485RadioButtonout = (RadioButton)findViewById(R.id.rs485_outRadioButton);
		rs485SetButton1 = (Button)findViewById(R.id.rs485_setButton1);
		rs485SetButton2 = (Button)findViewById(R.id.rs485_setButton2);
		rs485QueryButton3 = (Button)findViewById(R.id.rs485_queryButton3);
		rs485SetButton3 = (Button)findViewById(R.id.rs485_setButton3);	
		rs485EditText = (EditText)findViewById(R.id.rs485_addressEdit);
		
		rs485RadioButton2400.setOnCheckedChangeListener(this);
		rs485RadioButton4800.setOnCheckedChangeListener(this);
		rs485RadioButton9600.setOnCheckedChangeListener(this);
		rs485RadioButton19200.setOnCheckedChangeListener(this);
		rs485RadioButton38400.setOnCheckedChangeListener(this);
		rs485RadioButton8.setOnCheckedChangeListener(this);
		rs485RadioButton9.setOnCheckedChangeListener(this);
		rs485RadioButtonno.setOnCheckedChangeListener(this);
		rs485RadioButtonji.setOnCheckedChangeListener(this);
		rs485RadioButtonou.setOnCheckedChangeListener(this);
		rs485RadioButton2.setOnCheckedChangeListener(this);
		rs485RadioButton3.setOnCheckedChangeListener(this);
		rs485RadioButton4.setOnCheckedChangeListener(this);
		rs485RadioButtonin.setOnCheckedChangeListener(this);
		rs485RadioButtonout.setOnCheckedChangeListener(this);
		rs485SetButton1.setOnClickListener(this);
		rs485SetButton2.setOnClickListener(this);
		rs485QueryButton3.setOnClickListener(this);
		rs485SetButton3.setOnClickListener(this);
	}
    /**
     * 描述：实例化组件
     */
    public void initView(){
    	backButton = (Button)findViewById(R.id.systemset_backButton);
    	radioButton0 = (RadioButton)findViewById(R.id.radio_button0);
    	radioButton1 = (RadioButton)findViewById(R.id.radio_button1);
    	radioButton2 = (RadioButton)findViewById(R.id.radio_button2);
    	bindButton = (Button)findViewById(R.id.homeset_bindButton);
    	phoneEdit = (EditText)findViewById(R.id.homeset_phEdit);
    	
    	zigbeeRadioButton = (RadioButton)findViewById(R.id.zigbee_radioButton);
    	bluetoothRadioButton = (RadioButton)findViewById(R.id.bluetooth_radioButton);
    	cc1101RadioButton = (RadioButton)findViewById(R.id.cc1101_radioButton);
    	rs485RadioButton = (RadioButton)findViewById(R.id.rs485_radioButton);
    	canRadioButton = (RadioButton)findViewById(R.id.can_radioButton);
    	
    	homesetLLayout = (LinearLayout)findViewById(R.id.homeset_layout);
    	systemsetLLayout = (LinearLayout)findViewById(R.id.systemset_layout);
    	phoneRLayout = (RelativeLayout)findViewById(R.id.taskset_phoneRlayout);
    	alertingRLayout = (RelativeLayout)findViewById(R.id.taskset_alertingRlayout);
    	setRLayout = (RelativeLayout)findViewById(R.id.taskset_setRlayout);
    	zigbeeLLayout = (LinearLayout)findViewById(R.id.zigbee_layout);
    	bluetoothLLayout = (LinearLayout)findViewById(R.id.bluetooth_layout);
    	cc1101LLayout = (LinearLayout)findViewById(R.id.cc1101_layout);
    	rs485LLayout = (LinearLayout)findViewById(R.id.rs485_layout);
    	canLLayout = (LinearLayout)findViewById(R.id.can_layout);
    	
    	passwordEdit = (EditText)findViewById(R.id.taskset_passEdit);
    	loginButton = (Button)findViewById(R.id.taskset_loginButton);
    	//为组件添加监听
    	loginButton.setOnClickListener(this);
    	backButton.setOnClickListener(this);
    	bindButton.setOnClickListener(this);
    	
    	radioButton0.setOnCheckedChangeListener(this);
		radioButton1.setOnCheckedChangeListener(this);
		radioButton2.setOnCheckedChangeListener(this);
		zigbeeRadioButton.setOnCheckedChangeListener(this);
		bluetoothRadioButton.setOnCheckedChangeListener(this);
		cc1101RadioButton.setOnCheckedChangeListener(this);
		rs485RadioButton.setOnCheckedChangeListener(this);
		canRadioButton.setOnCheckedChangeListener(this);
		
		sharedPreferences = getSharedPreferences("data", MODE_WORLD_READABLE);
		phone = sharedPreferences.getString("phone", "");
		phoneEdit.setText(phone);
    }
    /**
     *描述：单选按钮的单击事件
     */
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if(isChecked){
			switch (buttonView.getId()) {
			//绑定号码
			case R.id.radio_button0:
				phoneRLayout.setVisibility(View.VISIBLE);
				alertingRLayout.setVisibility(View.INVISIBLE);
				setRLayout.setVisibility(View.INVISIBLE);
				break;
			//选择报警方式
			case R.id.radio_button1:
				phoneRLayout.setVisibility(View.INVISIBLE);
				alertingRLayout.setVisibility(View.VISIBLE);
				setRLayout.setVisibility(View.INVISIBLE);
				break;
			
			//进入系统设置登陆
			case R.id.radio_button2:
				phoneRLayout.setVisibility(View.INVISIBLE);
				alertingRLayout.setVisibility(View.INVISIBLE);
				setRLayout.setVisibility(View.VISIBLE);
				break;
			
			//进入ZigBee配置
			case R.id.zigbee_radioButton:
				zigbeeLLayout.setVisibility(View.VISIBLE);
				bluetoothLLayout.setVisibility(View.INVISIBLE);
				cc1101LLayout.setVisibility(View.INVISIBLE);
				rs485LLayout.setVisibility(View.INVISIBLE);
				canLLayout.setVisibility(View.INVISIBLE);
				break;
			//进入蓝牙配置
			case R.id.bluetooth_radioButton:
				zigbeeLLayout.setVisibility(View.INVISIBLE);
				bluetoothLLayout.setVisibility(View.VISIBLE);
				cc1101LLayout.setVisibility(View.INVISIBLE);
				rs485LLayout.setVisibility(View.INVISIBLE);
				canLLayout.setVisibility(View.INVISIBLE);
				break;
			//进入CC1101配置
			case R.id.cc1101_radioButton:
				zigbeeLLayout.setVisibility(View.INVISIBLE);
				bluetoothLLayout.setVisibility(View.INVISIBLE);
				cc1101LLayout.setVisibility(View.VISIBLE);
				rs485LLayout.setVisibility(View.INVISIBLE);
				canLLayout.setVisibility(View.INVISIBLE);
				break;
			//进入RS485配置
			case R.id.rs485_radioButton:
				zigbeeLLayout.setVisibility(View.INVISIBLE);
				bluetoothLLayout.setVisibility(View.INVISIBLE);
				cc1101LLayout.setVisibility(View.INVISIBLE);
				rs485LLayout.setVisibility(View.VISIBLE);
				canLLayout.setVisibility(View.INVISIBLE);
				break;
			//进入CAN配置
			case R.id.can_radioButton:
				zigbeeLLayout.setVisibility(View.INVISIBLE);
				bluetoothLLayout.setVisibility(View.INVISIBLE);
				cc1101LLayout.setVisibility(View.INVISIBLE);
				rs485LLayout.setVisibility(View.INVISIBLE);
				canLLayout.setVisibility(View.VISIBLE);
				break;
			/*
			 * zigbee
			 */
			case R.id.zigbee_coordinatorRadioButton:
				ZNODE_M = "C";
				break;
			case R.id.zigbee_routerRadioButton:
				ZNODE_M = "R";
				break;
			case R.id.zigbee_RadioButton11:
				ZCHANNEL_N = "11";
				break;
			case R.id.zigbee_RadioButton12:
				ZCHANNEL_N = "12";
				break;
			case R.id.zigbee_RadioButton13:
				ZCHANNEL_N = "13";
				break;
			case R.id.zigbee_RadioButton14:
				ZCHANNEL_N = "14";
				break;
			case R.id.zigbee_RadioButton15:
				ZCHANNEL_N = "15";
				break;
			case R.id.zigbee_RadioButton16:
				ZCHANNEL_N = "16";
				break;
			case R.id.zigbee_RadioButton17:
				ZCHANNEL_N = "17";
				break;
			case R.id.zigbee_RadioButton18:
				ZCHANNEL_N = "18";
				break;
			case R.id.zigbee_RadioButton19:
				ZCHANNEL_N = "19";
				break;
			case R.id.zigbee_RadioButton20:
				ZCHANNEL_N = "20";
				break;
			case R.id.zigbee_RadioButton21:
				ZCHANNEL_N = "21";
				break;
			case R.id.zigbee_RadioButton22:
				ZCHANNEL_N = "22";
				break;
			case R.id.zigbee_RadioButton23:
				ZCHANNEL_N = "23";
				break;
			case R.id.zigbee_RadioButton24:
				ZCHANNEL_N = "24";
				break;
			case R.id.zigbee_RadioButton25:
				ZCHANNEL_N = "25";
				break;
			case R.id.zigbee_RadioButton26:
				ZCHANNEL_N = "26";
				break;
			/*
			 * 蓝牙
			 */
			
			case R.id.bluetooth_yesAAARadioButton:
				AUTH_enable = "1";
				break;
			case R.id.bluetooth_noAAARadioButton:
				AUTH_enable = "0";
				break;
			case R.id.bluetooth_yesBindingRadioButton:
				BIND_enable = "1";
				break;
			case R.id.bluetooth_noBindingRadioButton:
				BIND_enable = "0";
				break;
			/*
			 * CAN
			 */
			case R.id.can_100RadioButton:
				CANSET_B = "1";
				break;
			case R.id.can_200RadioButton:
				CANSET_B = "2";
				break;
			case R.id.can_250RadioButton:
				CANSET_B = "3";
				break;
			case R.id.can_500RadioButton:
				CANSET_B = "4";
				break;
			case R.id.can_normRadioButton:
				CANSET_D = "1";
			case R.id.can_expandRadioButton:
				CANSET_D = "2";
				break;
			/*
			 * CC1101
			 */
			case R.id.cc1101_dataRadioButton:
				MODE_Str = "DATA";
				break;
			case R.id.cc1101_decodeRadioButton:
				MODE_Str = "DECODE";
				break;
			/*
			 * RS485
			 */
			case R.id.rs485_2400RadioButton:
				RS485SET_B = "1";
				break;
			case R.id.rs485_4800RadioButton:
				RS485SET_B = "2";
				break;
			case R.id.rs485_9600RadioButton:
				RS485SET_B = "3";
				break;
			case R.id.rs485_19200RadioButton:
				RS485SET_B = "4";
				break;
			case R.id.rs485_38400RadioButton:
				RS485SET_B = "5";
				break;
			case R.id.rs485_8RadioButton:
				RS485SET_D = "8";
				break;
			case R.id.rs485_9RadioButton:
				RS485SET_D = "9";
				break;
			case R.id.rs485_noRadioButton:
				RS485SET_P = "0";
				break;
			case R.id.rs485_jiRadioButton:
				RS485SET_P = "1";
				break;
			case R.id.rs485_ouRadioButton:
				RS485SET_P = "2";
				break;
			case R.id.rs485_2RadioButton:
				RS485SET_S = "2";
				break;
			case R.id.rs485_3RadioButton:
				RS485SET_S = "3";
				break;
			case R.id.rs485_4RadioButton:
				RS485SET_S = "4";
				break;
			case R.id.rs485_inRadioButton:
				RS485MODE_mode = "0";
				break;
			case R.id.rs485_outRadioButton:
				RS485MODE_mode = "1";
				break;
			default:
				break;
			}
		}
	}
	/**
	 * 描述：点击监听方法
	 */
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		//绑定手机号	
		case R.id.homeset_bindButton:
			phone = phoneEdit.getText().toString().trim();
			//判断手机号是否合法
			if (Utils.isMobile(phone)) {
				Editor editor = sharedPreferences.edit();
				editor.putString("phone", phone);
				editor.commit();
				Toast.makeText(TaskSetActivity.this, 
						"绑定成功",
						Toast.LENGTH_SHORT).show();
			}else{
				Toast.makeText(TaskSetActivity.this, 
						"手机号格式不正确，请仔细检查！",
						Toast.LENGTH_SHORT).show();
			}						
			break;
		//系统设置登陆
		case R.id.taskset_loginButton:
			password = passwordEdit.getText().toString().trim();
			String str = getString(R.string.manage_passwod).toString().trim();
			if (password.equals(str)) {
				homesetLLayout.setVisibility(View.INVISIBLE);
				systemsetLLayout.setVisibility(View.VISIBLE);
				
			}else{
				Toast.makeText(TaskSetActivity.this, "密码输入错误", Toast.LENGTH_LONG).show();
			}
			break;
		//返回家居基本设置
		case R.id.systemset_backButton:
			homesetLLayout.setVisibility(View.VISIBLE);
			systemsetLLayout.setVisibility(View.INVISIBLE);
			break;
		/*
		 * zigbee
		 */
		//查询PANID名称
		case R.id.zigbee_queryButton1:
			write("AT+R_AA_Z_PAN_ID\r");
			break;
		//设置PANID名称
		case R.id.zigbee_setButton1:
			write("AT+AA_Z_PAN_ID="+zigbeeEdit.getText().toString().trim()+"\r");
			break;
		//查询节点类型
		case R.id.zigbee_queryButton2:
			write("AT+R_AA_Z_NODE\r");
			break;
		//设置节点类型
		case R.id.zigbee_setButton2:
			write("AT+AA_Z_NODE="+ZNODE_M+"\r");
			break;
		//查询信号道
		case R.id.zigbee_queryButton3:
			write("AT+R_AA_Z_CHANNEL\r");
			break;
		//设置信号道
		case R.id.zigbee_setButton3:
			write("AT+AA_Z_CHANNEL="+ZCHANNEL_N+"\r");
			break;
		/*
		 * BLUETOOTH
		 */
		//查询蓝牙名称
		case R.id.bluetooth_queryNameButton:
			write("AT+AA_B_NAME?\r");
			break;
		//设置蓝牙名称
		case R.id.bluetooth_setNameButton:
			write("AT+AA_B_CHANGE_NAME="+nameEdit.getText().toString().trim()+"\r");
			break;
		//查询工作状态
		case R.id.bluetooth_queryworkModeButton:
			write("AT+AA_B_LINK?\r");
			break;
		//查询密码
		case R.id.bluetooth_queryPasswordButton:
			write("AT+AA_B_PASSWORD?\r");
			break;
		//设置密码
		case R.id.bluetooth_setPasswordButton:
			write("AT+AA_B_SET_PASSWORD="+bluetoothPasswordEdit.getText().toString().trim()+"\r");
			break;
		//查询工作模式
		case R.id.bluetooth_queryWorkPatternButton:
			write("AT+AA_B_ROLE?\r");
			break;
		//设置工作模式
		case R.id.bluetooth_setWorkPatternButton:
			CANID_M = "1";
			write("AT+AA_B_SET_ROLE="+workPatternEdit.getText().toString().trim()+"\r");
			break;
		//查询鉴权
		case R.id.bluetooth_queryAAAButton:
			write("AT+AA_B_AUTH?\r");
			break;
		//设置鉴权
		case R.id.bluetooth_setAAAButton:
			write("AT+AA_B_SET_AUTH="+AUTH_enable+"\r");
			break;
		//查询是否绑定
		case R.id.bluetooth_queryBindingButton:
			write("AT+AA_B_BIND?\r");
			break;
		//设置是否绑定
		case R.id.bluetooth_setBindingButton:
			write("AT+AA_B_SET_BIND="+BIND_enable+"\r");
			break;
		//清楚记忆
		case R.id.bluetooth_clearButton:
			write("AT+AA_B_CLEAR_ALL_ADDR\r");
			break;
		//蓝牙重启
		case R.id.bluetooth_restartButton:
			write("AT+AA_B_RESET\r");
			break;
		/*
		 * CAN
		 */
		//查询CAN地址
		case R.id.can_queryButton2:
			CANID_M = "1";
			write("AT+AA_CANID="+CANID_M+"\r");
			break;
		//设置基本参数
		case R.id.can_setButton1:
			write("AT+AA_CANSET=1,"+CANSET_B+","+CANSET_D+"\r");
			break;
		//设置CAN地址
		case R.id.can_setButton2:
			CANID_M = "0";
			CANID_id = canEdit.getText().toString().trim();
			write("AT+AA_CANID="+CANID_M+","+CANID_id+"\r");
			break;
		/*
		 * CC1101
		 */
			
		//查询cc01地址
		case R.id.cc1101_queryButton:
			ADDRESS_M = "1";
			write("AT+AA_C_ADDRESS="+ADDRESS_M+"\r");
			break;
		//设置cc01地址
		case R.id.cc1101_setButton:
			ADDRESS_M = "0";
			ADDRESS_addr = cc1101Edit.getText().toString().trim();
			write("AT+AA_C_ADDRESS="+ADDRESS_M+","+ADDRESS_addr+"\r");
			break;
		//设置工作模式
		case R.id.cc1101_setButton1:
			write("AT+AA_C_MODE="+MODE_Str+"\r");
			break;
		/*
		 * RS485
		 */
		//设置基本参数
		case R.id.rs485_setButton1:
			write("AT+AA_RS485_SET="+RS485SET_N+","+RS485SET_B+","
					+RS485SET_D+","+RS485SET_P+","+RS485SET_S+","+RS485SET_F+"\r");
//			ADDRESS_addr = cc1101Edit.getText().toString().trim();
//			write("AT+AA_C_ADDRESS="+ADDRESS_M+","+ADDRESS_addr+"\r");
			break;
		//设置模式
		case R.id.rs485_setButton2:
			write("AT+AA_RS485_MODE="+RS485MODE_N+","+RS485MODE_mode+"\r");
			break;
		//查地址
		case R.id.rs485_queryButton3:
			RS485ADDR_M = "1";
			write("AT+AA_RS485_ADDR="+RS485ADDR_M+"\r");
			break;
		//设置地址
		case R.id.rs485_setButton3:
			RS485ADDR_M = "0";
			RS485ADDR_addr = rs485EditText.getText().toString().trim();
			write("AT+AA_RS485_ADDR="+RS485ADDR_M+","+RS485ADDR_addr+"\r");
			break;
		default:
			break;
		}
	}
	/**
	 * 描述：向串口发指令
	 * @param str
	 */
	public void write(String str){
		try {
			HardwareControler.write(Configuration.fd, str.getBytes("utf-8"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
    Handler handler = new Handler() {
        public void handleMessage(Message msg) {

            switch (msg.arg1) {

            case 0:
            	try {	
        		    Thread.sleep(90);
        		
        		   } catch(InterruptedException e) {	
        		    e.printStackTrace();	
        		   }
                int len = HardwareControler.read(Configuration.fd, buf, buf.length);    
                readStr = new String(buf, 0, len).replaceAll("\r","").trim();               
                /*
                 * CAN
                 */
                if (readStr.startsWith("AT+AA_CANID")) {
                	String string = readStr.substring(readStr.indexOf("=")+1, readStr.length());
                	canEdit.setText(string);
				}
                /*
                 * zigbee
                 */
                else if (readStr.startsWith("AT+AA_Z_PAN_ID")) {
                	String string = readStr.substring(readStr.indexOf("=")+1, readStr.length());
                	zigbeeEdit.setText(string);
				}
                else if (readStr.startsWith("AT+AA_Z_NODE")) {
                	String string = readStr.substring(readStr.indexOf("=")+1, readStr.length());
                	if (string.equals("C")) {
                		zigbeeCoordinatorRadioButton.setChecked(true);
					}else{
						zigbeeRouterRadioButton.setChecked(true);
					}
				}
                else if (readStr.startsWith("AT+AA_Z_CHANNEL")) {
                	String string = readStr.substring(readStr.indexOf("=")+1, readStr.length());
                	if (string.equals("11")) {
                		zigbeeRadioButton11.setChecked(true);
					}
                	else if(string.equals("12")){
                		zigbeeRadioButton12.setChecked(true);
					}
                	else if(string.equals("13")){
                		zigbeeRadioButton13.setChecked(true);
					}
                	else if(string.equals("14")){
                		zigbeeRadioButton14.setChecked(true);
					}
                	else if(string.equals("15")){
                		zigbeeRadioButton15.setChecked(true);
					}
                	else if(string.equals("16")){
                		zigbeeRadioButton16.setChecked(true);
					}
                	else if(string.equals("17")){
                		zigbeeRadioButton17.setChecked(true);
					}
                	else if(string.equals("18")){
                		zigbeeRadioButton18.setChecked(true);
					}
                	else if(string.equals("19")){
                		zigbeeRadioButton19.setChecked(true);
					}
                	else if(string.equals("20")){
                		zigbeeRadioButton20.setChecked(true);
					}
                	else if(string.equals("21")){
                		zigbeeRadioButton21.setChecked(true);
					}
                	else if(string.equals("22")){
                		zigbeeRadioButton22.setChecked(true);
					}
                	else if(string.equals("23")){
                		zigbeeRadioButton23.setChecked(true);
					}
                	else if(string.equals("24")){
                		zigbeeRadioButton24.setChecked(true);
					}
                	else if(string.equals("25")){
                		zigbeeRadioButton25.setChecked(true);
					}
                	else if(string.equals("26")){
                		zigbeeRadioButton26.setChecked(true);
					}
				}
                /*
                 * CC1101
                 */
                else if (readStr.startsWith("AT+AA_C_ADDRESS")) {
                	String string = readStr.substring(readStr.indexOf("=")+1, readStr.length());
                	cc1101Edit.setText(string);
				}
                /*
                 * RS485 
                 */
                else if (readStr.startsWith("AT+AA_RS485_ADDR")) {
                	String string = readStr.substring(readStr.indexOf("=")+1, readStr.length());
                	rs485EditText.setText(string);
				}
                /*
                 * 蓝牙
                 */
        		
                else if (readStr.startsWith("AT+AA_B_NAME")) {
                	String string = readStr.substring(readStr.indexOf("=")+1, readStr.length());
                	nameEdit.setText(string);
				}
                else if (readStr.startsWith("AT+AA_B_LINK")) {
                	String string = readStr.substring(readStr.indexOf("=")+1, readStr.length());
                	if (string.equals("0")) {
                		workModeEdit.setText("未连接");
					}else{
						workModeEdit.setText("已连接");
					}
                	
				}
                else if (readStr.startsWith("AT+AA_B_PASSWORD")) {
                	String string = readStr.substring(readStr.indexOf("=")+1, readStr.length());
                	bluetoothPasswordEdit.setText(string);
				}
                else if (readStr.startsWith("AT+AA_B_ROLE")) {
                	String string = readStr.substring(readStr.indexOf("=")+1, readStr.length());
                	workPatternEdit.setText(string);
				}
                else if (readStr.startsWith("AT+AA_B_AUTH")) {
                	String string = readStr.substring(readStr.indexOf("=")+1, readStr.length());
                	if (string.equals("0")) {
                		noAAARadioButton.setChecked(true);
					}else{
						yesAAARadioButton.setChecked(true);
					}
				}
                else if (readStr.startsWith("AT+AA_B_BIND")) {
                	String string = readStr.substring(readStr.indexOf("=")+1, readStr.length());
                	if (string.equals("0")) {
                		noBindingRadioButton.setChecked(true);
					}else{
						yesBindingRadioButton.setChecked(true);
					}
				}             
                /**
                 * 报警信息
                 * 注意：需要先判断是否布防(人体红外探测器和门磁等防盗设备受布撤防控制，
                 * 		其余环境设备不受不撤防控制)
                 */
                //无线报警按钮
                else if (readStr.startsWith("AT+AA_C_315=04")){
                	write("AT+AA_RS485TX=01050013FF007DFF"+"\r");
//                	UDPClientSocket.send("AT+AA_RS485TX=01050013FF007DFF",Configuration.PC_HOST,Configuration.PC_PORT);
//                	Utils.sendSms(Configuration.BIND_PHONE, "无线报警按钮发送报警信息");
                	setDialog("无线报警按钮","AT+AA_RS485TX=0105001300003C0F");
                	writeNewsToSql("无线报警按钮");
                	UDPClientSocket.send(readStr,Configuration.PAD_HOST,Configuration.PAD_PORT);
                	UDPClientSocket.send(readStr,Configuration.PC_HOST,Configuration.PC_PORT);
				}
                //有线按钮报警
                else if (readStr.startsWith("AT+AA_Z_RX_DT=Z2012,5,1")) {
                	write("AT+AA_RS485TX=01050013FF007DFF"+"\r");
//                	UDPClientSocket.send("AT+AA_RS485TX=01050013FF007DFF",Configuration.PC_HOST,Configuration.PC_PORT);
//                	Utils.sendSms(Configuration.BIND_PHONE, "有线报警按钮发送报警信息");
                	writeNewsToSql("有线报警按钮");
//                	setDialog("有线报警按钮","AT+AA_RS485TX=0105001300003C0F");
                	UDPClientSocket.send(readStr,Configuration.PAD_HOST,Configuration.PAD_PORT);
                	UDPClientSocket.send("AT+AA_Z_RX_DT=Z2012,5,1",Configuration.PC_HOST,Configuration.PC_PORT);
				}
              //烟雾探测器报警
                else if (readStr.startsWith("AT+AA_Z_RX_DT=Z2010,5,1")) {
                	write("AT+AA_RS485TX=01050013FF007DFF"+"\r");
//                	UDPClientSocket.send("AT+AA_RS485TX=01050013FF007DFF",Configuration.PC_HOST,Configuration.PC_PORT);
//                	Utils.sendSms(Configuration.BIND_PHONE, "烟雾探测器发送报警信息");
                	writeNewsToSql("烟雾探测器");
                	setDialog("烟雾探测器","AT+AA_RS485TX=0105001300003C0F");
                	UDPClientSocket.send(readStr,Configuration.PAD_HOST,Configuration.PAD_PORT);
                	UDPClientSocket.send(readStr,Configuration.PC_HOST,Configuration.PC_PORT);
				}
                //有线按钮取消报警
                else if (readStr.startsWith("AT+AA_Z_RX_DT=Z2012,5,0")) {
                	write("AT+AA_RS485TX=0105001300003C0F"+"\r");
//                	UDPClientSocket.send("AT+AA_RS485TX=0105001300003C0F",Configuration.PC_HOST,Configuration.PC_PORT);
                	UDPClientSocket.send(readStr,Configuration.PAD_HOST,Configuration.PAD_PORT);
                	UDPClientSocket.send("AT+AA_Z_RX_DT=Z2012,5,0",Configuration.PC_HOST,Configuration.PC_PORT);
				}
                //烟雾探测器取消报警
                else if (readStr.startsWith("AT+AA_Z_RX_DT=Z2010,5,0")) {
                	write("AT+AA_RS485TX=0105001300003C0F"+"\r");
//                	UDPClientSocket.send("AT+AA_RS485TX=0105001300003C0F",Configuration.PC_HOST,Configuration.PC_PORT);
                	UDPClientSocket.send(readStr,Configuration.PC_HOST,Configuration.PC_PORT);
				}
                //判断是否撤防
                if (Configuration.isDefend) {
                	//红外人体探测器报警信息
                    if (readStr.startsWith("AT+AA_C_315=00")) {
                    	write("AT+AA_RS485TX=01050013FF007DFF"+"\r");
//                    	UDPClientSocket.send("AT+AA_RS485TX=01050013FF007DFF",Configuration.PC_HOST,Configuration.PC_PORT);
//                    	Utils.sendSms(Configuration.BIND_PHONE, "红外人体探测器发送报警信息");
                    	setDialog("红外人体探测器","AT+AA_RS485TX=0105001300003C0F");
                    	writeNewsToSql("红外人体探测器");
                    	UDPClientSocket.send(readStr,Configuration.PAD_HOST,Configuration.PAD_PORT);
                    	UDPClientSocket.send(readStr,Configuration.PC_HOST,Configuration.PC_PORT);
    				}                  
                    
                   //门磁报警信息
                    else if (readStr.startsWith("AT+AA_Z_RX_DT=Z2013,5,1")) {
                    	write("AT+AA_RS485TX=01050013FF007DFF"+"\r");
//                    	UDPClientSocket.send("AT+AA_RS485TX=01050013FF007DFF",Configuration.PC_HOST,Configuration.PC_PORT);
                    	UDPClientSocket.send(readStr,Configuration.PAD_HOST,Configuration.PAD_PORT);
                    	UDPClientSocket.send(readStr,Configuration.PC_HOST,Configuration.PC_PORT);
    				}
                    
                    //门磁关闭报警信息
                   
                    else if (readStr.startsWith("AT+AA_Z_RX_DT=Z2013,5,0")) {
                    	write("AT+AA_RS485TX=0105001300003C0F"+"\r"); 
//                    	UDPClientSocket.send("AT+AA_RS485TX=0105001300003C0F",Configuration.PC_HOST,Configuration.PC_PORT);
                    	UDPClientSocket.send(readStr,Configuration.PC_HOST,Configuration.PC_PORT);
    				}                    
				}               
                Toast.makeText(TaskSetActivity.this, readStr, Toast.LENGTH_SHORT).show();
                new readThread().start();//处理完消息后立即开启监听线程
                Log.d(thread,"接收到数据，新线程启动");
                break;
            case 1:
                HardwareControler.setLedState(1, 0);
                new readThread().start();
//                Log.d(thread,"没有数据，新线程启动");
                break;
            default:
            	
                break;
            }
        }
    };  
    /**
     * 描述：读取串口信息线程
     * @author Administrator
     *
     */
    class readThread extends Thread
    {        
        public void run()
        {
            Message msg = new Message();
            HardwareControler.setLedState(0, 0);
            if (HardwareControler.select(Configuration.fd,2, 0)==1) {            
                msg.arg1 = 0;            
            }
            else {
                msg.arg1 =1;
                HardwareControler.setLedState(0, 1);
            }
            handler.sendMessage(msg);
        }
    }
    /**
     * 描述：报警提示对话框
     */
    public void setDialog(String news,final String order){
		final Builder builder = new AlertDialog.Builder(TaskSetActivity.this);
		
		builder.setTitle("报警提示");
		builder.setMessage(news+"正在报警……");
		builder.setPositiveButton("关闭报警器", new AlertDialog.OnClickListener() {
			
			public void onClick(DialogInterface dialog, int which) {
				write(order+"\r");
				UDPClientSocket.send(order,Configuration.PC_HOST,Configuration.PC_PORT);
			}
		});
		builder.create().show();
	}
    /**
     * 描述：向数据库写报警信息
     */
    public void writeNewsToSql(String strNews){
    	Mysqlite mySqlite=new Mysqlite(TaskSetActivity.this, "users.db", 1);
    	SQLiteDatabase db=mySqlite.getWritableDatabase();
		ContentValues values = new ContentValues();
		values.put("time", Utils.getTime());
		values.put("news", strNews);
		db.insert("alerting_table", null, values);
		db.close();
    }
}