//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);
     }
 }
Example #2
0
        /// <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;
            }
        }