예제 #1
0
        public DataPacket GetFlowDataPacket(string deviceKey, Dictionary<string, object> data, bool realTime = false)
        {
            if (data.Count == 0)
            {
                return null;
            }
            DataPacket dp = new DataPacket(deviceKey, realTime, true);
            // Adjust 'CN' !!
            if (realTime)
            {
                dp.Cn = string.Format("{0}", (int)SentCommand.FlowData);
            }
            else
            {
                dp.Cn = string.Format("{0}", (int)ReceivedCommand.GetFlowData);
            }

            dp.Settings = Settings.Instance;
            dp.St = Value.SysSend;
            string sno = Settings.Instance.Sno;
            string eno = Settings.Instance.GetEquipNumber(deviceKey);
            string timeStr = (string)data["time"];
            string dataTime = DeviceTime.Convert(DateTime.Parse(timeStr));
            dp.SetContent(sno, eno, dataTime, data);
            dp.Build();
            return dp;
        }
예제 #2
0
 public DataPacket GetKeepAlivePacket()
 {
     DataPacket dp = new DataPacket(SentCommand.KeepAlive);
     dp.Settings = Settings.Instance;
     dp.St = Value.SysSend;
     dp.Build();
     return dp;
 }
예제 #3
0
 public DataPacket GetFlowDataPacket(string deviceKey, Dictionary<string, object> data, bool realTime = false)
 {
     if (data.Count == 0)
     {
         return null;
     }
     DataPacket dp = new DataPacket(deviceKey, realTime, true);
     dp.Settings = Settings.Instance;
     dp.St = Value.SysSend;
     string sno = Settings.Instance.Sno;
     string eno = Settings.Instance.GetEquipNumber(deviceKey);
     string timeStr = (string)data["time"];
     string dataTime = DeviceTime.Convert(DateTime.Parse(timeStr));
     dp.SetContent(sno, eno, dataTime, data);
     dp.Build();
     return dp;
 }
예제 #4
0
 public DataPacket GetShelterPacket(string deviceKey, Dictionary<string, object> data, bool realTime = false)
 {
     if (data.Count == 0)
     {
         return null;
     }
     DataPacket dp = new DataPacket(deviceKey, realTime);
     dp.Cn = string.Format("{0}", (int)SentCommand.DoorState);
     dp.Settings = Settings.Instance;
     dp.St = Value.SysSend;
     string sno = Settings.Instance.Sno;
     string eno = Settings.Instance.GetEquipNumber(deviceKey);
     string timeStr = string.Empty;
     if (data.ContainsKey("time"))
     {
         timeStr = (string)data["time"];
     }
     string dataTime = DeviceTime.Convert(DateTime.Parse(timeStr));
     dp.SetContent(sno, eno, dataTime, data);
     dp.Build();
     return dp;
 }
예제 #5
0
 public DataPacket GetRunStatusPacket(string qn, string[] devices, string[] status)
 {
     DataPacket dp = new DataPacket(SentCommand.RunStatus);
     dp.QN = qn;
     dp.Settings = Settings.Instance;
     dp.St = Value.SysSend;
     string sno = Settings.Instance.Sno;
     string dateTime = DeviceTime.Convert(DateTime.Now);
     dp.SetRunStatusContent(sno, dateTime, devices, status);
     dp.Build();
     return dp;
 }
예제 #6
0
 internal DataPacket GetTimePacket(string qn)
 {
     DataPacket dp = new DataPacket(SentCommand.GetTime);
     dp.Settings = Settings.Instance;
     dp.QN = qn;
     dp.St = Value.SysSend;
     dp.BuildGetTime(DeviceTime.Convert(DateTime.Now));
     return dp;
 }
예제 #7
0
 internal DataPacket GetResultPacket(string qn, int result = 1)
 {
     DataPacket dp = new DataPacket(SentCommand.Result);
     dp.Settings = Settings.Instance;
     dp.BuildResult(qn, result);
     return dp;
 }
예제 #8
0
 internal DataPacket GetReplyPacket(string qn)
 {
     DataPacket dp = new DataPacket(SentCommand.Reply);
     dp.Settings = Settings.Instance;
     dp.BuildReply(qn, 1);
     return dp;
 }
예제 #9
0
 internal DataPacket GetNotifyPacket(string qn)
 {
     DataPacket dp = new DataPacket(SentCommand.Notify);
     dp.Settings = Settings.Instance;
     dp.BuildNotify(qn);
     return dp;
 }
예제 #10
0
파일: Agent.cs 프로젝트: mrddos/planisphere
 internal void SendReplyPacket(DataPacket p, DateTime time)
 {
     string s = p.ToString();
     this.Send(Encoding.ASCII.GetBytes(s));
 }
예제 #11
0
파일: Agent.cs 프로젝트: mrddos/planisphere
 internal void SendPacket(DataPacket p)
 {
     this.SendPacket(p, default(DateTime));
 }
예제 #12
0
파일: Agent.cs 프로젝트: mrddos/planisphere
 internal void SendDataPacket(DataPacket p, DateTime time)
 {
     if (p == null)
         return;
     // Only start or history.
     if (this.SendDataStarted || this.OnHistoryData)
     {
         string s = p.ToString();
         this.Send(Encoding.ASCII.GetBytes(s));
     }
 }
예제 #13
0
파일: Agent.cs 프로젝트: oisy/scada
 internal bool SendPacket(DataPacket p)
 {
     return this.SendPacket(p, default(DateTime));
 }
예제 #14
0
파일: Agent.cs 프로젝트: oisy/scada
        internal bool SendDataPacket(DataPacket p)
        {
            if (p == null)
                return false;

            if (this.SendDataStarted)
            {
                string s = p.ToString();
                return this.Send(Encoding.ASCII.GetBytes(s));
            }
            return false;
        }
예제 #15
0
        internal DataPacket GetDoorStatePacket(string state)
        {
            DataPacket dp = new DataPacket(SentCommand.DoorState);
            dp.Settings = Settings.Instance;

            string sno = Settings.Instance.Sno;
            string dateTime = DeviceTime.Convert(DateTime.Now);
            dp.St = Value.SysSend;
            dp.SetDoorStateContent(sno, dateTime, state);
            dp.Build();
            return dp;
        }
예제 #16
0
        internal DataPacket GetThresholdPacket(string polId, string eno, string v1, string v2)
        {
            DataPacket dp = new DataPacket(SentCommand.GetAlertThreshold);
            dp.Settings = Settings.Instance;

            string sno = Settings.Instance.Sno;
            string dateTime = DeviceTime.Convert(DateTime.Now);
            dp.St = Value.SysSend;
            dp.SetThresholdContent(sno, eno, polId, v1, v2);
            dp.Build();
            return dp;
        }
예제 #17
0
 internal DataPacket GetExceptionNotifyPacket(string deviceKey, bool p)
 {
     DataPacket dp = new DataPacket(p ? SentCommand.WentException : SentCommand.AfterException);
     dp.Settings = Settings.Instance;
     
     string sno = Settings.Instance.Sno;
     string dateTime = DeviceTime.Convert(DateTime.Now);
     dp.St = Value.SysSend;
     dp.Flag = "1";
     dp.SetExceptionNotifyContent(sno, dateTime, deviceKey, (p ? "0" : "1"));
     dp.Build();
     return dp;
 }
예제 #18
0
파일: Agent.cs 프로젝트: oisy/scada
 internal void SendExceptionNotify(DataPacket packet)
 {
     this.SendPacket(packet);
 }
예제 #19
0
파일: Agent.cs 프로젝트: oisy/scada
        internal bool SendHistoryDataPacket(DataPacket p)
        {
            if (p == null)
                return false;
            bool result = false;

            string s = p.ToString();
            result = this.Send(Encoding.ASCII.GetBytes(s));
            if (result)
            {
                if (this.NotifyEvent != null && !string.IsNullOrEmpty(p.DeviceKey))
                {
                    this.NotifyEvent(this, NotifyEvents.HistoryDataSent, p.DeviceKey, s);
                }
            }
            return result;
        }
예제 #20
0
        internal List<DataPacket> GetDataPackets(string deviceKey, DateTime dateTime, string content, bool history = false, string qn = null)
        {
            List<DataPacket> rets = new List<DataPacket>();
            int from = 0;
            const int MaxContent = 920;
            int count = content.Length / MaxContent + 2;
            int index = 1;

            string sno = Settings.Instance.Sno;
            string eno = Settings.Instance.GetEquipNumber(deviceKey);

            string dataTime = DeviceTime.Convert(dateTime);

            // Header packet
            DataPacket dp = null;
            if (!history)
                dp = new DataPacket(SentCommand.Data);
            else
                dp = new DataPacket(SentCommand.HistoryData);
            // Set settings
            dp.Settings = Settings.Instance;

            dp.Splitted = true;
            dp.PacketCount = count;
            dp.PacketIndex = index;
            dp.St = Value.SysSend;
            Dictionary<string, object> data = new Dictionary<string, object>();
            List<Settings.DeviceCode> codes = Settings.Instance.GetCodes(deviceKey);
            string contentCode = codes[0].Code;
            data.Add(contentCode, string.Empty);
            data.Add("time", dateTime.ToString());
            dp.SetContent(sno, eno, dataTime, data);
            dp.Build();
            rets.Add(dp);

            string pqn = dp.QN;

            while (true)
            {
                index += 1;
                dp = null;

                if (!history)
                    dp = new DataPacket(SentCommand.Data);
                else
                    dp = new DataPacket(SentCommand.HistoryData);
                dp.Settings = Settings.Instance;
                dp.Splitted = true;
                dp.PacketCount = count;
                dp.PacketIndex = index;
                dp.St = Value.SysSend;

                string c = content.Substring(from, Math.Min(MaxContent, content.Length - from));
                dp.QN = pqn;
                dp.SetContent(sno, eno, dataTime, c);
                dp.Build();

                rets.Add(dp);

                from += c.Length;
                if (from >= content.Length)
                    break;

            }
            return rets;
        }
예제 #21
0
파일: Agent.cs 프로젝트: oisy/scada
 internal bool SendPacket(DataPacket p, DateTime time)
 {
     string s = p.ToString();
     // TODO:!
     this.DoLog(Agent.ScadaDataClient, string.Format("-->: {0}", s));
     return this.Send(Encoding.ASCII.GetBytes(s));
 }