/// <summary> /// Boc tach du lieu cua ban tin gia nhap mang /// </summary> /// <param name="data"></param> public void convertDataJoinNetwork(string data) { try { string mac = null; string ip = null; db = new Database(); mac = data.Substring(8, 2); ip = data.Substring(4, 4); if (mac == "00" || mac == "B1") { checkSensor = false; actor.Mac = mac; actor.Ip = ip; if (db.CheckActor(mac) == "true") { db.setNetworkIpActor(mac, ip); db.setStatusActor(mac, true); } else { db.setNodeActor(mac, ip, true); } } else if (mac[0] == '3') { checkSensor = true; sensor.Mac = mac; sensor.Ip = ip; if (db.CheckSensorBC(mac) == "true") { db.setNetworkIpSensorBC(mac, ip); db.setStatusSensorBC(mac, true); } else { db.setSensor_bc(mac, ip, true); } } else { checkSensor = true; sensor.Mac = mac; sensor.Ip = ip; if (db.CheckSensor(mac) == "true") { db.setNetworkIpSensor(sensor.Mac, sensor.Ip); db.setActiveSensor(sensor.Mac, true); } else { db.setNodeSensor(sensor.Mac, sensor.Ip, true); } } } catch (Exception ex) { ERR = ex.Message; } }
//Ham boc tach thong so khi join mang public void JoinMang(string mesg) { try { Database mydatabase = new Database(); string check = mesg.Substring(8, 2); int chck = int.Parse(check, System.Globalization.NumberStyles.HexNumber); if (chck < 160 && chck > 0) { DisplayData("(" + DateTime.Now + "): Thong tin gia nhap mang: \r\n Sensor " + mesg.Substring(4, 4) + " (" + check + ") " + " : \r\n Da gia nhap vao mang !!!\r\n", tb); if (check[0] == '3') { if (mydatabase.CheckSensorBC(check) == "true") { mydatabase.setNetworkIpSensorBC(check, mesg.Substring(4, 4)); mydatabase.setStatusSensorBC(check, true); } else { mydatabase.setSensor_bc(check, mesg.Substring(4, 4), true); } } else { timePing[chck] = 0; if (mydatabase.CheckSensor(check) == "true") { mydatabase.setNetworkIpSensor(check, mesg.Substring(4, 4)); mydatabase.setActiveSensor(check, true); } else { mydatabase.setNodeSensor(check, mesg.Substring(4, 4), true); } } } if ((160 < chck && chck < 255) || chck == 0) { DisplayData("(" + DateTime.Now + "): Thong tin trang thai Actor: \r\n Actor " + mesg.Substring(4, 4) + " (" + check + ") " + " : \r\n Van hoat dong trong mang !!!\r\n", tb); if (mydatabase.CheckActor(check) == "true") { mydatabase.setNetworkIpActor(check, mesg.Substring(4, 4)); mydatabase.setStatusActor(check, true); } else { mydatabase.setNodeActor(check, mesg.Substring(4, 4), true); } } } catch { DisplayData("Error Join mang", tb); } }
//**************************************************** private void Emboard_Load(object sender,EventArgs e) { Database myDatabase = new Database(); send = new Thread(new ThreadStart(comPort.SendRS)); send.Start(); comPort.TimerInt(); #if ACTOR_COOR myDatabase.setAllFalse(); cbMalenh.Items.Clear(); cbMalenh.Items.Add("Lay nhiet do, do am"); cbMalenh.Items.Add("Bat van so 1"); cbMalenh.Items.Add("Bat van so 2"); cbMalenh.Items.Add("Bat van so 3"); cbMalenh.Items.Add("Bat van so 4"); cbMalenh.Items.Add("Bat van so 5"); cbMalenh.Items.Add("Bat van so 6"); cbMalenh.Items.Add("Bat tat ca cac van"); cbMalenh.Items.Add("Tat van so 1"); cbMalenh.Items.Add("Tat van so 2"); cbMalenh.Items.Add("Tat van so 3"); cbMalenh.Items.Add("Tat van so 4"); cbMalenh.Items.Add("Tat van so 5"); cbMalenh.Items.Add("Tat van so 6"); cbMalenh.Items.Add("Tat tat ca cac van"); #endif #if BC_COOR myDatabase.setFalseActor(); myDatabase.setNetworkIpActor("B1","0000"); cbMalenh.Items.Clear(); cbMalenh.Items.Add("Lay nhiet do, do am"); cbMalenh.Items.Add("Bat canh bao muc 1"); cbMalenh.Items.Add("Bat canh bao muc 2"); cbMalenh.Items.Add("Bat canh bao muc 3"); cbMalenh.Items.Add("Bat canh bao muc 4"); cbMalenh.Items.Add("Bat canh bao muc 5"); #endif myDatabase.setFalseBC(); myDatabase.setValOff(); myDatabase.setTimeVan(1, 0); myDatabase.setTimeVan(2, 0); myDatabase.setTimeVan(3, 0); myDatabase.setTimeVan(4,0); myDatabase.setTimeVan(5, 0); comPort.Time_alarm = myDatabase.getTimeAlarm(); comPort.Time_control = myDatabase.getTimeActor(); comPort.mypanel = pnShow; comPort.mytext = txtshow; comPort.tb = tbShow; txtmac.Hide(); pnShow.Hide(); btexit.Enabled = true; try { comPort.pictureBox = pictureBox1; comPort.reload(comPort.pictureBox); } catch { MessageBox.Show("Khong the load ban do"); } }