//Ham boc tach du lieu khi nhan du lieu dinh ky public void AutoData(string mesg) { try { Database mydatabase = new Database(); string mac = mesg.Substring(8, 2); DataSensor(mesg, ref temperature, ref humidity, ref energy); DisplayData("(" + DateTime.Now + "): Du lieu dinh ky :\r\n Sensor " + mesg.Substring(4, 4) + "(" + mac + "): \r\n Nhiet do: " + Temperature + "\r\n Do am: " + Humidity + "\r\n Nang luong : " + Energy + "\r\n", tb); string time = DateTime.Now.ToString(); if (mac[0] == '3') { if (mydatabase.CheckSensorBC(mac) == "true") { mydatabase.setNetworkIpSensorBC(mac, mesg.Substring(4, 4)); mydatabase.setStatusSensorBC(mac, true); } else { mydatabase.setSensor_bc(mac, mesg.Substring(4, 4), true); } mydatabase.SaveDataDB(Temperature, Humidity); } else { int iIndex = int.Parse(mac,System.Globalization.NumberStyles.HexNumber); timePing[iIndex] = 0; if (mydatabase.CheckSensor(mac) == "true") { mydatabase.setNetworkIpSensor(mac, mesg.Substring(4, 4)); mydatabase.setActiveSensor(mac, true); } else { mydatabase.setNodeSensor(mac, mesg.Substring(4, 4), true); } string Val = mydatabase.getVanSensor(mac); int van = Int32.Parse(Val.Substring(1,1)); float tempmax = mydatabase.getTempVan(van); float humimax = mydatabase.getHumiVan(van); bool test = ((Temperature > tempmax) && (Humidity < humimax)); if (test) //Dieu kien thoa man { if (DateTime.Now.Hour >= mydatabase.getTimeStart() && DateTime.Now.Hour < mydatabase.getTimeFinish()) { #if USE_CANBANGTAI DisplayData("Thoa man dieu kien bat van (" + mydatabase.getTimeStart() + " h - " + mydatabase.getTimeFinish() + " h)", tb); if(Val == "V6") { DisplayData("Thoa man dieu kien bat van 6 (" + mydatabase.getTimeStart() + " h - " + mydatabase.getTimeFinish() + " h)", tb); AutoBatVan(Val, mesg); } else if (Val == "V5") { int tvan4 = mydatabase.getTimeVan(4); int tvan5 = mydatabase.getTimeVan(5); if (tvan4 > 60) { int tv4phut = tvan4 / 60; int tv4giay = tvan4 - tv4phut * 60; DisplayData("Thoi gian da bat van 4 la:" + tv4phut + " phut "+ tv4giay + " giay", tb); } else { DisplayData("Thoi gian da bat van 4 la:" + tvan4 + " giay", tb); } if (tvan5 > 60) { int tv5phut = tvan5 / 60; int tv5giay = tvan5 - tv5phut * 60; DisplayData("Thoi gian da bat van 5 la:" + tv5phut + " phut " + tv5giay + " giay", tb); } else { DisplayData("Thoi gian da bat van 5 la:" + tvan5 + " giay", tb); } if (tvan4 > tvan5) { DisplayData("Quyet dinh ban van 5:", tb); AutoBatVan("V5", mesg); } else { DisplayData("Quyet dinh ban van 4:", tb); AutoBatVan("V4", mesg); Val = "V4"; } } else if (Val == "V1") { int tvan1 = mydatabase.getTimeVan(1); int tvan2 = mydatabase.getTimeVan(2); if (tvan1 > 60) { int tv1phut = tvan1 / 60; int tv1giay = tvan1 - tv1phut * 60; DisplayData("Thoi gian da bat van 1 la:" + tv1phut + " phut " + tv1giay + " giay", tb); } else { DisplayData("Thoi gian da bat van 1 la:" + tvan1 + " giay", tb); } if (tvan2 > 60) { int tv2phut = tvan2 / 60; int tv2giay = tvan2 - tv2phut * 60; DisplayData("Thoi gian da bat van 2 la:" + tv2phut + " phut " + tv2giay + " giay", tb); } else { DisplayData("Thoi gian da bat van 2 la:" + tvan2 + " giay", tb); } if (tvan1 > tvan2) { DisplayData("Quyet dinh ban van 2:", tb); AutoBatVan("V2", mesg); Val = "V2"; } else { DisplayData("Quyet dinh ban van 1:", tb); AutoBatVan("V1", mesg); } } else { string val = Val.Substring(1,1); //int van = int.Parse(val); int vantruoc = van - 1; int vansau = van + 1; int timevan = mydatabase.getTimeVan(van); int timevanTruoc = mydatabase.getTimeVan(vantruoc); int timevanSau = mydatabase.getTimeVan(vansau); if (timevan > 60) { int tvphut = timevan / 60; int tvgiay = timevan - tvphut * 60; DisplayData("Thoi gian da bat van "+van+" la:" + tvphut + " phut " + tvgiay + " giay", tb); } else { DisplayData("Thoi gian da bat van " + van+" la:" + timevan + " giay", tb); } if (timevanTruoc > 60) { int tvTphut = timevanTruoc / 60; int tvTgiay = timevanTruoc - tvTphut * 60; DisplayData("Thoi gian da bat van " + vantruoc + " la:" + tvTphut + " phut " + tvTgiay + " giay", tb); } else { DisplayData("Thoi gian da bat van "+ vantruoc +" la:" + timevanTruoc + " giay", tb); } if (timevanSau > 60) { int tvSphut = timevanSau / 60; int tvSgiay = timevanSau - tvSphut * 60; DisplayData("Thoi gian da bat van " + vansau + " la:" + tvSphut + " phut " + tvSgiay + " giay", tb); } else { DisplayData("Thoi gian da bat van " + vansau + " la:" + timevanSau + " giay", tb); } if(timevan > timevanTruoc) { if(timevanTruoc > timevanSau) { DisplayData("Quyet dinh bat van"+vansau+":",tb); AutoBatVan("V"+vansau,mesg); Val = "V" + vansau; } else { DisplayData("Quyet dinh bat van" + vantruoc + ":", tb); AutoBatVan("V" + vantruoc, mesg); Val = "V" + vantruoc; } } else { if (timevan > timevanSau) { DisplayData("Quyet dinh bat van" + vansau + ":", tb); AutoBatVan("V" + vansau, mesg); Val = "V" + vansau; } else { DisplayData("Quyet dinh bat van" + van + ":", tb); AutoBatVan("V" + van, mesg); Val = "V" + van; } } } int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - 1; timeDapung.Remove(Val); timeDapung.Add(Val, timenow); #endif #if NO_CANBANGTAI DisplayData("Thoa man dieu kien bat van "+id+" (" + mydatabase.getTimeStart() + " h - " + mydatabase.getTimeFinish() + " h)", tb); AutoBatVan(Val, mesg); #endif } else { DisplayData("Khong phai khoang thoi gian bat bom (" + mydatabase.getTimeStart() + " h - "+mydatabase.getTimeFinish()+" h)",tb); } } } } catch { } }
public void ThongTinActor(string mesg) { try { Database mydatabase = new Database(); string ss1 = mesg.Substring(10, 2); string mac_actor = mesg.Substring(8, 2); int tt = int.Parse(ss1, System.Globalization.NumberStyles.HexNumber); int vanbom = tt - 128; if (tt > 128 && tt < 170) { if (vanbom == 15) { #if USE_CANBANGTAI if (mydatabase.getStateVal(1) == "off" || mydatabase.getStateVal(1) == "Off") { timeval1 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; } if (mydatabase.getStateVal(2) == "off" || mydatabase.getStateVal(2) == "Off") { timeval2 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; } if (mydatabase.getStateVal(3) == "off" || mydatabase.getStateVal(3) == "Off") { timeval3 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; } if (mydatabase.getStateVal(4) == "off" || mydatabase.getStateVal(4) == "Off") { timeval4 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; } if (mydatabase.getStateVal(5) == "off" || mydatabase.getStateVal(5) == "Off") { timeval5 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; } #endif try { int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; int dapung = 0; dapung = timenow - (int)timeDapung[mac_actor]; timeDapung.Remove(mac_actor); DisplayData("(" + DateTime.Now + "):Tat ca cac van da bat! \r\n(Dap ung dieu khien bang tay: " + dapung + " giay)\r\n", tb); } catch { DisplayData("(" + DateTime.Now + "):Tat ca cac van da bat!\r\n", tb); } mydatabase.setValOn(); } else { if (mac_actor == "00") { #if USE_CANBANGTAI switch (vanbom) { case 1: if (mydatabase.getStateVal(1) == "off" || mydatabase.getStateVal(1) == "Off") { timeval1 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; } break; case 2: if (mydatabase.getStateVal(2) == "off" || mydatabase.getStateVal(2) == "Off") { timeval2 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; } break; case 3: if (mydatabase.getStateVal(3) == "off" || mydatabase.getStateVal(3) == "Off") { timeval3 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; } break; case 4: if (mydatabase.getStateVal(4) == "off" || mydatabase.getStateVal(4) == "Off") { timeval4 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; } break; case 5: if (mydatabase.getStateVal(5) == "off" || mydatabase.getStateVal(5) == "Off") { timeval5 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; } break; } #endif int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; int dapung = 0; try { dapung = timenow - (int)timeDapung[mac_actor]; timeDapung.Remove(mac_actor); DisplayData("(" + DateTime.Now + "): Van so " + vanbom.ToString() + " da bat!\r\n(Dap ung dieu khien bang tay: " + dapung + " giay)\r\n", tb); } catch { try { dapung = timenow - (int)timeDapung["V" + vanbom.ToString()]; timeDapung.Remove("V" + vanbom.ToString()); DisplayData("(" + DateTime.Now + "): Van so " + vanbom.ToString() + " da bat!\r\n(Dap ung dieu khien tu dong: " + dapung + " giay)\r\n", tb); } catch { DisplayData("(" + DateTime.Now + "): Van so " + vanbom.ToString() + " da bat!\r\n", tb); } } mydatabase.setStateVal(vanbom, "on"); } if (mac_actor == "B1") { //DisplayData(MessageType.Incoming, comread, tb); int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; int dapung = 0; try { dapung = timenow - (int)timeDapung[mac_actor]; timeDapung.Remove(mac_actor); DisplayData("(" + DateTime.Now + "): Da bat canh bao muc " + vanbom.ToString() + "\r\n(Dap ung dieu khien bang tay: " + dapung + " giay)\r\n", tb); } catch { try { dapung = timenow - (int)timeDapung["V5"]; timeDapung.Remove("V5"); DisplayData("(" + DateTime.Now + "): Da bat canh bao muc " + vanbom.ToString() + "\r\n(Dap ung phat hien chay: " + dapung + "giay)", tb); } catch { DisplayData("(" + DateTime.Now + "): Da bat canh bao muc " + vanbom.ToString() + "\r\n", tb); } } } } showVanOn(vanbom, mac_actor, mytext); } else { if (tt > 64 && tt < 128) { int vantat = tt - 64; if (vantat == 15) { DisplayData("(" + DateTime.Now + "): Tat ca cac van da tat tu dong!\r\n", tb); mydatabase.setValOff(); } else { DisplayData("(" + DateTime.Now + "): Van so " + vantat.ToString() + " da tat tu dong!\r\n", tb); mydatabase.setStateVal(vantat, "off"); } } if(tt < 64) { if (tt == 15) { #if USE_CANBANGTAI if (mydatabase.getStateVal(1) == "on") { int time1 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval1; time1 = time1 + mydatabase.getTimeVan(1); mydatabase.setTimeVan(1, time1); } if (mydatabase.getStateVal(2) == "on") { int time2 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval2; time2 = time2 + mydatabase.getTimeVan(2); mydatabase.setTimeVan(2, time2); } if (mydatabase.getStateVal(3) == "on") { int time3 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval3; time3 = time3 + mydatabase.getTimeVan(3); mydatabase.setTimeVan(3, time3); } if (mydatabase.getStateVal(4) == "on") { int time4 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval4; time4 = time4 + mydatabase.getTimeVan(4); mydatabase.setTimeVan(4, time4); } if (mydatabase.getStateVal(5) == "on") { int time5 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval5; time5 = time5 + mydatabase.getTimeVan(5); mydatabase.setTimeVan(5, time5); } #endif int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; int dapung = 0; try { dapung = timenow - (int)timeDapung[mac_actor]; timeDapung.Remove(mac_actor); DisplayData("(" + DateTime.Now + "): Tat ca cac van da tat!\r\n(Dap ung dieu khien bang tay: " + dapung + " giay)\r\n", tb); } catch { DisplayData("(" + DateTime.Now + "): Tat ca cac van da tat!\r\n", tb); } mydatabase.setValOff(); } else { #if USE_CANBANGTAI switch (tt) { case 1: if (mydatabase.getStateVal(1) == "on") { int time1 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval1; time1 = time1 + mydatabase.getTimeVan(1); mydatabase.setTimeVan(1, time1); } break; case 2: if (mydatabase.getStateVal(2) == "on") { int time2 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval2; time2 = time2 + mydatabase.getTimeVan(2); mydatabase.setTimeVan(2, time2); } break; case 3: if (mydatabase.getStateVal(3) == "on") { int time3 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval3; time3 = time3 + mydatabase.getTimeVan(3); mydatabase.setTimeVan(3, time3); } break; case 4: if (mydatabase.getStateVal(4) == "on") { int time4 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval4; time4 = time4 + mydatabase.getTimeVan(4); mydatabase.setTimeVan(4, time4); } break; case 5: if (mydatabase.getStateVal(5) == "on") { int time5 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval5; time5 = time5 + mydatabase.getTimeVan(5); mydatabase.setTimeVan(5, time5); } break; } #endif int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; int dapung = 0; try { dapung = timenow - (int)timeDapung[mac_actor]; timeDapung.Remove(mac_actor); DisplayData("(" + DateTime.Now + "): Van so " + tt.ToString() + " da tat!\r\n(Dap ung dieu khien bang tay: " + dapung + " giay)\r\n", tb); } catch { DisplayData("(" + DateTime.Now + "): Van so " + tt.ToString() + " da tat\r\n", tb); } mydatabase.setStateVal(tt, "off"); } showVanOff(tt, mytext); if (tt == 1) { onofVal1 = false; } if (tt == 2) { onofVal2 = false; } if (tt == 3) { onofVal3 = false; } if (tt == 4) { onofVal4 = false; } if (tt == 5) { onofVal5 = false; } if (tt == 6) { onofVal6 = false; } if (tt == 15) { onofVal1 = false; onofVal2 = false; onofVal3 = false; onofVal4 = false; onofVal5 = false; onofVal6 = false; } } } } catch {} }
/// <summary> /// Ham boc tach du lieu tu cong COM /// Dinh dang ban tin tra ve: /// #JN:NNNN MM Ban tin join mang /// #AD:NNNN MM D1D2D3D4 D5D6D7D8 E1E2E3E4 Ban tin du lieu dinh ky /// #RD:NNNN MM D1D2D3D4 D5D6D7D8 E1E2E3E4 Ban tin du lieu theo yeu cau /// #RP:FFFF NN NN NN NN Ban tin danh sach cac node /// #RI:FFFF ... Ban tin hinh anh /// #VL:MM Ban tin thong bao ngu cua mot sensor /// #OK:NNNN MM SS Ban tin thong bao trang thai actor /// #SN: NNNN MM SS Ban tin thong bao trang thai sensor /// </summary> /// <param name="data"></param> public void convertData(string data) { try { switch (data[1]) { case 'M': MessageBox.Show(data); break; case 'J': Data.convertDataJoinNetwork(data); if (Data.checkSensor == false) { DisplayData("(" +showTime()+ "): Thong tin trang thai Actor: \r\n Actor " + actor.Ip + " (" + actor.Mac + ") " + " : \r\n Van hoat dong trong mang !!!\r\n", txtShowData); } else { DisplayData("(" + showTime() + "): Thong tin gia nhap mang: \r\n Sensor " + sensor.Ip + " (" + sensor.Mac + ") " + " : \r\n Da gia nhap vao mang !!!\r\n", txtShowData); } drawImage.reload(pic); break; case 'A': db = new Database(); Data.convertDataSensor(data); DisplayData("(" + showTime() + "): Du lieu dinh ky :\r\n Sensor " + sensor.Ip + "(" + sensor.Mac + "): \r\n Nhiet do: " + sensor.Temperature + "\r\n Do am: " + sensor.Humidity + "\r\n Nang luong : " + sensor.Energy + "\r\n", txtShowData); sensor.saveDataSensor(sensor.Mac, sensor.Ip, sensor.Temperature, sensor.Humidity, sensor.Energy); if(sensor.Mac[0] == '0') { int time_now_batvan = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; string _van = db.getVanSensor(sensor.Mac); int id = int.Parse(_van.Substring(1, 1)); //int id_van_bat = 0; if (sensor.Temperature > db.getTempVan(id) && sensor.Humidity < db.getHumiVan(id)) { if (DateTime.Now.Hour >= db.getTimeStart() && DateTime.Now.Hour < db.getTimeFinish()) { if (id == 1) { int time_van_sau = db.getTimeVan(2); int time_van = db.getTimeVan(1); int van_bat = van.selectVanOn(id, time_van,time_van_sau); DisplayData("Thoi gian bat van 1 la: " + van.getTimeFormat(time_van), txtShowData); DisplayData("Thoi gian bat van 2 la: " + van.getTimeFormat(time_van_sau), txtShowData); DisplayData("Quyet dinh bat van: " + van_bat, txtShowData); DisplayData("Gui lenh bat van " + van_bat + " tu dong!", txtShowData); id_van_bat = van_bat; string command = actor.commandOnActor(van_bat, "0000"); byte[] byteCommand = ConvertTobyte(command); writeByteData(byteCommand); } else if(id == 5){ int time_van_truoc = db.getTimeVan(4); int time_van = db.getTimeVan(5); int van_bat = van.selectVanOn(id, time_van, time_van_truoc); DisplayData("Thoi gian bat van 5 la: " + van.getTimeFormat(time_van), txtShowData); DisplayData("Thoi gian bat van 4 la: " + van.getTimeFormat(time_van_truoc), txtShowData); DisplayData("Quyet dinh bat van: " + van_bat, txtShowData); DisplayData("Gui lenh bat van " + van_bat + " tu dong!", txtShowData); id_van_bat = van_bat; string command = actor.commandOnActor(van_bat, "0000"); byte[] byteCommand = ConvertTobyte(command); writeByteData(byteCommand); } else if (id == 6) { DisplayData("Gui lenh bat van 6 tu dong!", txtShowData); id_van_bat = 6; string command = actor.commandOnActor(6, "0000"); byte[] byteCommand = ConvertTobyte(command); writeByteData(byteCommand); } else { int van_truoc = id - 1; int van_sau = id + 1; int time_van = db.getTimeVan(id); int time_van_truoc = db.getTimeVan(van_truoc); int time_van_sau = db.getTimeVan(van_sau); int van_bat = van.selectVanOn(id, time_van, time_van_truoc,time_van_sau); DisplayData("Thoi gian bat van " + id + " la: " + van.getTimeFormat(time_van), txtShowData); DisplayData("Thoi gian bat van " + van_truoc + " la: " + van.getTimeFormat(time_van_truoc), txtShowData); DisplayData("Thoi gian bat van " + van_sau + " la: " + van.getTimeFormat(time_van_sau), txtShowData); DisplayData("Quyet dinh bat van: " + van_bat, txtShowData); DisplayData("Gui lenh bat van " + van_bat + " tu dong!", txtShowData); id_van_bat = van_bat; string command = actor.commandOnActor(van_bat, "0000"); byte[] byteCommand = ConvertTobyte(command); writeByteData(byteCommand); } Van.statusVan[id_van_bat] = true; Van.countTimeOnVan[id_van_bat] = 0; InformationNode.timeDapUng.Remove(id_van_bat); InformationNode.timeDapUng.Add(id_van_bat,time_now_batvan); } else { DisplayData("Khong phai khoang thoi gian bat bom (" + db.getTimeStart() + " h - " + db.getTimeFinish() + " h)", txtShowData); } } } drawImage.reload(pic); break; case 'R': switch(data[2]) { case 'D': Data.convertDataSensor(data); DisplayData("(" + showTime() + "): Du lieu theo yeu cau :\r\n Sensor " + sensor.Ip + "(" + sensor.Mac + "): \r\n Nhiet do: " + sensor.Temperature + "\r\n Do am: " + sensor.Humidity + "\r\n Nang luong : " + sensor.Energy, txtShowData); try { int time = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - (int)InformationNode.timeDapUng[sensor.Mac]; InformationNode.timeDapUng.Remove(sensor.Mac); DisplayData("Thoi gian dap ung lay du lieu: " + time + " giay\r\n", txtShowData); if (time < 60) { #if ACTOR_BAOCHAY string timeSendToWeb = "DB" + time; #else string timeSendToWeb = "DA" + time; #endif WebServer.dataSendToWeb.Enqueue(timeSendToWeb); } } catch { DisplayData("", txtShowData); } sensor.saveDataSensor(sensor.Mac, sensor.Ip, sensor.Temperature, sensor.Humidity, sensor.Humidity); break; case 'P': //neu du lieu gui ve la dia chi cac node gan thiet bi android Data.convertDataSensorNeibor(data); DisplayData("(" + showTime() + "): Du lieu list sensor :\r\n ", txtShowData); foreach (string node in sensor.SensorIsArranged) { DisplayData(node.ToString() + "\r\n", txtShowData); } // try // { // int time = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - (int)ImformationNode.timeDapUng[sensor.Mac]; // ImformationNode.timeDapUng.Remove(sensor.Mac); // DisplayData("Thoi gian dap ung lay du lieu: " + time + " giay\r\n", txtShowData); // if (time < 60) // { //#if ACTOR_BAOCHAY // string timeSendToWeb = "DB" + time; //#else // string timeSendToWeb = "DA" + time; //#endif // WebServer.dataSendToWeb.Enqueue(timeSendToWeb); // } // } // catch { DisplayData("", txtShowData); } break; case 'I': //neu du lieu gui ve la hinh anh Data.convertDataPicture(data); Bitmap bmImg = Data.byteArrayToBitmap(sensor.Picture); DisplayPicture(bmImg, PicboxImage); //picBoxImage.Image = bmImg; //hien thi anh tren PicboxImage //////////////////////hien thi anh////////// //string filepath = null; //OpenFileDialog ofdImages = new OpenFileDialog(); //if (ofdImages.ShowDialog() == DialogResult.OK) //{ // filepath = ofdImages.FileName; //} //pictureBox2.Image = Img; //pictureBox2.SizeMode = PictureBoxSizeMode.Normal; ///////////////////////////////////////////// DisplayData("(" + showTime() + "): Du lieu hinh anh :\r\n "+data, txtShowData); break; } break; case 'S': db = new Database(); Data.convertStateNode(data); if (sensor.StateSensor == "02") { try { int time_now_canhbao = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; InformationNode.timeDapUng.Remove("warning"); InformationNode.timeDapUng.Add("warning", time_now_canhbao); } catch { } DisplayData("(" + showTime() + "):Canh bao chay tai node " + sensor.Mac, txtShowData); string phone_number = db.getPhoneNumber(); DisplayData("Gui tin nhan den so " + phone_number, txtShowData); if (COMSMS.IsOpen == false) { COMSMS.Open(); } COMSMS.Write("AT+CMGS=" + phone_number + "\r\n"); COMSMS.Write("Da canh bao chay o sensor co dia chi MAC " + sensor.Mac + (char)26 + (char)13); //COMSMS.Write("Da canh bao chay o sensor co dia chi MAC " + sensor.Mac + (char)26 + (char)13); COMSMS.DiscardInBuffer(); COMSMS.DiscardOutBuffer(); COMSMS.Close(); } else if (sensor.StateSensor == "03") { DisplayData("(" + showTime() + "):Het nang luong tai node " + sensor.Mac + "\r\n", txtShowData); } else { DisplayData("(" + DateTime.Now + "): Phat hien xam nhap tai node " + sensor.Mac + "\r\n", txtShowData); } break; case 'V': Data.convertImformationSleep(data); DisplayData("(" + showTime() + "): Sensor " + sensor.Mac + " da vao che do ngu\r\n", txtShowData); drawImage.reload(pic); break; case 'O': Data.convertImformationActor(data); if (actor.StatusActor) { if (van.VanID == 15) { DisplayData("(" + showTime() + "): Da bat tat ca cac van", txtShowData); } else { #if ACTOR_BAOCHAY DisplayData("(" + showTime() + "): Da bat canh bao muc " + van.VanID, txtShowData); try { int time_canhbao = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - (int)InformationNode.timeDapUng["warning"]; InformationNode.timeDapUng.Remove("warning"); DisplayData("Thoi gian dap ung canh bao chay "+time_canhbao+" giay", txtShowData); if (time_canhbao < 60) { string timeSendToWeb = "F" + time_canhbao; WebServer.dataSendToWeb.Enqueue(timeSendToWeb); } } catch{} #else DisplayData("(" + showTime() + "): Da bat van so " + van.VanID , txtShowData); //bat dau tinh thoi gian bat bơm int time_on = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; string keyVan = "0" + van.VanID; Van.TimeOnVan.Remove(keyVan); Van.TimeOnVan.Add(keyVan, time_on); try { int time_dapung_tuoicay = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - (int)ImformationNode.timeDapUng[van.VanID]; ImformationNode.timeDapUng.Remove(van.VanID); DisplayData("Thoi gian dap ung tuoi cay tu dong " + time_dapung_tuoicay + " giay", txtShowData); if(time_dapung_tuoicay < 60) { string timeSendToWeb = "T" + time_dapung_tuoicay; WebServer.dataSendToWeb.Enqueue(timeSendToWeb); } } catch {} #endif } } else { if (van.VanID == 15) { DisplayData("(" + showTime() + "): Da tat tat ca cac van", txtShowData); } else { DisplayData("(" + showTime() + "): Da tat van so " + van.VanID, txtShowData); try { db = new Database(); string keyVanOff = "0" + van.VanID; int timeOnVan = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - (int)Van.TimeOnVan[keyVanOff]; int timeOn = db.getTimeVan(van.VanID); int timeAll = timeOnVan + timeOn; db.setTimeVan(van.VanID, timeAll); string timeSendToWeb = "V" + van.VanID + timeAll; WebServer.dataSendToWeb.Enqueue(timeSendToWeb); } catch { } } } try { int time_actor = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - (int)InformationNode.timeDapUng[actor.Mac]; InformationNode.timeDapUng.Remove(actor.Mac); DisplayData("Thoi gian dap ung dieu khien actor "+time_actor+" giay\r\n", txtShowData); if (time_actor < 60) { #if ACTOR_BAOCHAY string timeSendToWeb = "CB" + time_actor; #else string timeSendToWeb = "CA" + time_actor; #endif WebServer.dataSendToWeb.Enqueue(timeSendToWeb); } } catch { DisplayData("", txtShowData); } drawImage.reload(pic); break; case 'P': Data.convertDataJoinNetwork(data); DisplayData("(" + showTime() + "): Thong tin trang thai sensor: \r\n Sensor " + sensor.Ip + " (" + sensor.Mac + ") " + " : \r\n Van hoat dong trong mang !!!\r\n", txtShowData); break; } } catch (Exception ex) { ERR = ex.Message; DisplayData(ERR, txtShowData); } }