Ejemplo n.º 1
0
        /// <summary>
        /// Send command to gateway
        /// </summary>
        /// <returns></returns>
        public void SendCommand(CommandType cmd, string sid, Dictionary <string, object> lParam)
        {
            Equipment model = lEquipements.SingleOrDefault(cur => cur.Sid != null && cur.Sid.Equals(sid));

            // Add key to command data
            lParam?.Add("key", this.GetActualKey());
            Command command = new Command
            {
                Cmd      = cmd.GetRealName(),
                Model    = model?.Model.GetRealName(),
                Sid      = sid,
                Short_id = model?.ShortId,
                Key      = model?.Model == EquipmentType.Gateway ? "8" : null, // Why 8 ? what if not present ?
                Data     = lParam
            };

            string sCommand = JsonConvert.SerializeObject(command, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            ProcessUdpDiagram(this.udpClientWrapper.SendToGateway(Encoding.ASCII.GetBytes(sCommand)));
        }