Пример #1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="forTarget"></param>
 /// <param name="forCommand"></param>
 /// <param name="forType"></param>
 public GXDLMSLongTransaction(ValueEventArgs[] forTargets, Command forCommand, GXByteBuffer forData)
 {
     targets = forTargets;
     command = forCommand;
     data = new GXByteBuffer();
     data.Set(forData.Data, forData.Position, forData.Size - forData.Position);
 }
Пример #2
0
        void PluginManager_FileInstalling(object sender, ValueEventArgs<PluginProgress> e)
        {
            if (InvokeRequired)
            {
                this.Invoke(new EventHandler<ValueEventArgs<PluginProgress>>(PluginManager_FileInstalling), sender, e);
                return;
            }

            var newTitle = string.Format(Monoflector.Properties.Resources.InstallingTitle, e.Value.Component);
            if (Text != newTitle)
                Text = newTitle;

            if (_fileLabel.Text != e.Value.File)
                _fileLabel.Text = e.Value.File;

            if (e.Value.Progress == -1)
            {
                _progressBar.Style = ProgressBarStyle.Marquee;
            }
            else
            {
                _progressBar.Style = ProgressBarStyle.Continuous;
                _progressBar.Value = e.Value.Progress;
            }
        }
Пример #3
0
 void mainSlider_ValueChange(object sender, ValueEventArgs e)
 {
     value = e.Value;
     if (SliderAxis == Axis.X && OpenNIContext.Instance.Mirror)
     {
         value = 1.0f - value;
     }
 }
Пример #4
0
        private void ListOnItemChange(object sender, ValueEventArgs<AutoCommitTask> e)
        {
            var item = e.Value ?? new AutoCommitTask();

            using (var form = new EditTaskForm())
            {
                if (form.EditTask(item, this) == DialogResult.OK)
                {
                    e.Value = item;
                }
            }
        }
Пример #5
0
 /// <summary>
 /// Get logical names from client request.
 /// </summary>
 /// <param name="nodes">XML nodes.</param>
 /// <returns>Collection of logical names.</returns>
 private static void GetLN(GXDLMSObjectCollection objects, List<ValueEventArgs> targets, XmlNodeList nodes)
 {
     List<ValueEventArgs> list = new List<ValueEventArgs>();
     foreach (XmlNode node in nodes)
     {
         ObjectType ot;
         string classId, instanceId;
         int attributeId;
         if (node.ChildNodes[1].Name == "x:cosem-attribute-descriptor")
         {
             classId = node.ChildNodes[1].ChildNodes[0].ChildNodes[0].InnerText;
             instanceId = node.ChildNodes[1].ChildNodes[1].ChildNodes[0].InnerText;
             instanceId = GXDLMSObject.ToLogicalName(GXCommon.HexToBytes(instanceId));
             attributeId = int.Parse(node.ChildNodes[1].ChildNodes[2].ChildNodes[0].InnerText);
             ot = (ObjectType)int.Parse(classId);
             GXDLMSObject t = objects.FindByLN(ot, instanceId);
             if (t == null)
             {
                 t = GXDLMSClient.CreateDLMSObject((int)ot, 0, 0, instanceId, null);
             }
             ValueEventArgs ve = new ValueEventArgs(t, attributeId, 0, null);
             targets.Add(ve);
             System.Diagnostics.Debug.WriteLine(ot + " " + instanceId);
         }
         else if ("AttributeDescriptorList".Equals(node.ChildNodes[1].Name))
         {
             foreach (XmlNode it in node.ChildNodes[1].ChildNodes)
             {
                 classId = it.ChildNodes[0].ChildNodes[0].InnerText;
                 instanceId = it.ChildNodes[0].ChildNodes[1].InnerText;
                 instanceId = GXDLMSObject.ToLogicalName(GXCommon.HexToBytes(instanceId));
                 attributeId = int.Parse(it.ChildNodes[0].ChildNodes[2].InnerText);
                 ot = (ObjectType)int.Parse(classId);
                 ValueEventArgs ve = new ValueEventArgs(objects.FindByLN(ot, instanceId), attributeId, 0, null);
                 targets.Add(ve);
                 System.Diagnostics.Debug.WriteLine(ot + " " + instanceId);
             }
         }
     }
 }
Пример #6
0
        object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            GXByteBuffer buff = new GXByteBuffer();
            object       ret;

            switch (e.Index)
            {
            case 1:
                ret = GXCommon.LogicalNameToBytes(LogicalName);
                break;

            case 2:
                ret = GetPushObjectList(settings);
                break;

            case 3:
                buff.SetUInt8(DataType.Structure);
                buff.SetUInt8(3);
                GXCommon.SetData(settings, buff, DataType.Enum, Service);
                if (Destination != null)
                {
                    GXCommon.SetData(settings, buff, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(Destination));
                }
                else
                {
                    GXCommon.SetData(settings, buff, DataType.OctetString, null);
                }
                GXCommon.SetData(settings, buff, DataType.Enum, Message);
                ret = buff.Array();
                break;

            case 4:
                buff.SetUInt8(DataType.Array);
                GXCommon.SetObjectCount(CommunicationWindow.Count, buff);
                foreach (KeyValuePair <GXDateTime, GXDateTime> it in CommunicationWindow)
                {
                    buff.SetUInt8(DataType.Structure);
                    buff.SetUInt8(2);
                    GXCommon.SetData(settings, buff, DataType.OctetString, it.Key);
                    GXCommon.SetData(settings, buff, DataType.OctetString, it.Value);
                }
                ret = buff.Array();
                break;

            case 5:
                ret = RandomisationStartInterval;
                break;

            case 6:
                ret = NumberOfRetries;
                break;

            case 7:
                ret = RepetitionDelay;
                break;

            default:
                e.Error = ErrorCode.ReadWriteDenied;
                ret     = null;
                break;
            }
            return(ret);
        }
Пример #7
0
 void PatternManager_ElementInstantiated(object sender, ValueEventArgs<IProductElement> e)
 {
     // This will be hit when creating a new solution, and
     // this event will be triggered from inside a tx
     if (e.Value == AsProduct())
     {
         InvokeAddNugetFiles();
     }
 }
Пример #8
0
 protected virtual void OnEvaluatingCategory(ValueEventArgs<string> e)
 {
     var handler = EvaluatingCategory;
     handler?.Invoke(this, e);
 }
 private void OnViewDidAppearHandlerRefresh(UIViewController sender, ValueEventArgs<bool> args)
 {
     ((IViewControllerView)sender).Mediator.ViewDidAppearHandler -= OnViewDidAppearHandlerNew;
     RaiseNavigated(sender, NavigationMode.Refresh, sender.GetNavigationParameter() as string);
 }
Пример #10
0
        public void OnPublishingStatusNotificationTests()
        {
            // arrange
            var vm = new MainViewModel();

            Mock.Arrange(() => Deployment.Current.Dispatcher.BeginInvoke((Arg.IsAny<Action>()))).DoInstead<Action>(a => a());

            var popupFactory = Mock.Create<PopupFactory>(Behavior.CallOriginal);
            Mock.Arrange(() => popupFactory.ShowBusy(Arg.IsAny<Status>(), true)).MustBeCalled();
            vm.ThePopupFactory = popupFactory;

            var e = new ValueEventArgs<PublishingStatus>(new PublishingStatus
                {
                    ProgressCompleted = 90.0,
                    Stage = "Deploying",
                    StatusText = "some additional information"
                });

            // act
            vm.OnPublishingStatusNotification(null, e);

            // assert
            Mock.Assert(popupFactory);
        }
 private void ActivityViewOnSaveInstanceState(Activity sender, ValueEventArgs<Bundle> args)
 {
     var index = _viewPager.CurrentItem;
     if (index > 0)
         args.Value.PutInt(ContentPath, index);
 }
Пример #12
0
 private void DriverResponseLogic_DriverResponseChanged(object sender, ValueEventArgs <ClientInfrastructure.ServicesEntities.DataService.IDriverResponse> e)
 {
     _model.State = e.Value.State;
 }
    byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e)
    {
        //Check reply_to_HLS_authentication
        if (e.Index == 8)
        {
            UInt32 ic = 0;
            byte[] secret;
            if (settings.Authentication == Authentication.HighGMAC)
            {
                secret = settings.SourceSystemTitle;
                GXByteBuffer bb = new GXByteBuffer(e.Parameters as byte[]);
                bb.GetUInt8();
                ic = bb.GetUInt32();
            }
            else
            {
                secret = HlsSecret;
            }
            byte[] serverChallenge = GXSecure.Secure(settings, settings.Cipher, ic, settings.StoCChallenge, secret);
            byte[] clientChallenge = (byte[])e.Parameters;
            if (GXCommon.Compare(serverChallenge, clientChallenge))
            {
                if (settings.Authentication == Authentication.HighGMAC)
                {
                    secret = settings.Cipher.SystemTitle;
                    ic = settings.Cipher.FrameCounter;
                }
                else
                {
                    secret = HlsSecret;
                }
                settings.Connected = true;
                return GXSecure.Secure(settings, settings.Cipher, ic, settings.CtoSChallenge, secret);
            }
            else
            {
                // If the password does not match.
                settings.Connected = false;
                return null;
            }

        }
        else
        {
            e.Error = ErrorCode.ReadWriteDenied;
            return null;
        }
    }
Пример #14
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(GXCommon.LogicalNameToBytes(LogicalName));
     }
     if (e.Index == 2)
     {
         return(GXCommon.LogicalNameToBytes(DataLinkLayerReference));
     }
     if (e.Index == 3)
     {
         return(FromAddressString(IPAddress));
     }
     if (e.Index == 4)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (MulticastIPAddress == null)
         {
             //Object count is zero.
             data.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(MulticastIPAddress.Length, data);
             foreach (IPAddress it in MulticastIPAddress)
             {
                 GXCommon.SetData(settings, data, DataType.UInt32, FromAddressString(it));
             }
         }
         return(data.Array());
     }
     if (e.Index == 5)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (IPOptions == null)
         {
             //Object count is zero.
             data.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(IPOptions.Length, data);
             foreach (GXDLMSIp4SetupIpOption it in IPOptions)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8(3);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Type);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Length);
                 GXCommon.SetData(settings, data, DataType.OctetString, it.Data);
             }
         }
         return(data.Array());
     }
     if (e.Index == 6)
     {
         //If subnet mask is not given.
         return(FromAddressString(SubnetMask));
     }
     if (e.Index == 7)
     {
         return(FromAddressString(GatewayIPAddress));
     }
     if (e.Index == 8)
     {
         return(this.UseDHCP);
     }
     if (e.Index == 9)
     {
         return(FromAddressString(PrimaryDNSAddress));
     }
     if (e.Index == 10)
     {
         return(FromAddressString(SecondaryDNSAddress));
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Пример #15
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         DataLinkLayerReference = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 3)
     {
         IPAddress = ToAddressString(e.Value);
     }
     else if (e.Index == 4)
     {
         List <IPAddress> data = new List <IPAddress>();
         if (e.Value is List <object> )
         {
             foreach (object it in (List <object>)e.Value)
             {
                 data.Add(ToAddressString(it));
             }
         }
         else if (e.Value is UInt16[])
         {
             //Some meters are returning wrong data here.
             foreach (UInt16 it in (UInt16[])e.Value)
             {
                 data.Add(ToAddressString(it));
             }
         }
         MulticastIPAddress = data.ToArray();
     }
     else if (e.Index == 5)
     {
         List <GXDLMSIp4SetupIpOption> data = new List <GXDLMSIp4SetupIpOption>();
         if (e.Value is List <object> )
         {
             foreach (List <object> it in (List <object>)e.Value)
             {
                 GXDLMSIp4SetupIpOption item = new GXDLMSIp4SetupIpOption();
                 item.Type   = (Ip4SetupIpOptionType)Convert.ToInt32(it[0]);
                 item.Length = Convert.ToByte(it[1]);
                 item.Data   = (byte[])it[2];
                 data.Add(item);
             }
         }
         IPOptions = data.ToArray();
     }
     else if (e.Index == 6)
     {
         SubnetMask = ToAddressString(e.Value);
     }
     else if (e.Index == 7)
     {
         GatewayIPAddress = ToAddressString(e.Value);
     }
     else if (e.Index == 8)
     {
         UseDHCP = Convert.ToBoolean(e.Value);
     }
     else if (e.Index == 9)
     {
         PrimaryDNSAddress = ToAddressString(e.Value);
     }
     else if (e.Index == 10)
     {
         SecondaryDNSAddress = ToAddressString(e.Value);
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Пример #16
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         MBusPortReference = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 3)
     {
         CaptureDefinition.Clear();
         if (e.Value != null)
         {
             foreach (object[] it in (object[])e.Value)
             {
                 CaptureDefinition.Add(new KeyValuePair <string, string>(GXDLMSClient.ChangeType((byte[])it[0], DataType.OctetString, settings.UseUtc2NormalTime).ToString(),
                                                                         GXDLMSClient.ChangeType((byte[])it[1], DataType.OctetString, settings.UseUtc2NormalTime).ToString()));
             }
         }
     }
     else if (e.Index == 4)
     {
         CapturePeriod = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 5)
     {
         PrimaryAddress = Convert.ToByte(e.Value);
     }
     else if (e.Index == 6)
     {
         IdentificationNumber = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 7)
     {
         ManufacturerID = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 8)
     {
         DataHeaderVersion = Convert.ToByte(e.Value);
     }
     else if (e.Index == 9)
     {
         DeviceType = Convert.ToByte(e.Value);
     }
     else if (e.Index == 10)
     {
         AccessNumber = Convert.ToByte(e.Value);
     }
     else if (e.Index == 11)
     {
         Status = Convert.ToByte(e.Value);
     }
     else if (e.Index == 12)
     {
         Alarm = Convert.ToByte(e.Value);
     }
     else if (Version > 0)
     {
         if (e.Index == 13)
         {
             Configuration = Convert.ToUInt16(e.Value);
         }
         else if (e.Index == 14)
         {
             EncryptionKeyStatus = (MBusEncryptionKeyStatus)Convert.ToInt32(e.Value);
         }
         else
         {
             e.Error = ErrorCode.ReadWriteDenied;
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Пример #17
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(GXCommon.LogicalNameToBytes(LogicalName));
     }
     if (e.Index == 2)
     {
         return(GXCommon.LogicalNameToBytes(MBusPortReference));
     }
     if (e.Index == 3)
     {
         GXByteBuffer buff = new GXByteBuffer();
         buff.SetUInt8((byte)DataType.Array);
         GXCommon.SetObjectCount(CaptureDefinition.Count, buff);
         foreach (KeyValuePair <string, string> it in CaptureDefinition)
         {
             buff.SetUInt8((byte)DataType.Structure);
             buff.SetUInt8(2);
             GXCommon.SetData(settings, buff, DataType.UInt8, it.Key);
             GXCommon.SetData(settings, buff, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(it.Value));
         }
         return(buff.Array());
     }
     if (e.Index == 4)
     {
         return(CapturePeriod);
     }
     if (e.Index == 5)
     {
         return(PrimaryAddress);
     }
     if (e.Index == 6)
     {
         return(IdentificationNumber);
     }
     if (e.Index == 7)
     {
         return(ManufacturerID);
     }
     if (e.Index == 8)
     {
         return(DataHeaderVersion);
     }
     if (e.Index == 9)
     {
         return(DeviceType);
     }
     if (e.Index == 10)
     {
         return(AccessNumber);
     }
     if (e.Index == 11)
     {
         return(Status);
     }
     if (e.Index == 12)
     {
         return(Alarm);
     }
     if (Version > 0)
     {
         if (e.Index == 13)
         {
             return(Configuration);
         }
         if (e.Index == 14)
         {
             return(EncryptionKeyStatus);
         }
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Пример #18
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         PushObjectList.Clear();
         if (e.Value is List <object> )
         {
             foreach (List <object> it in (List <object>)e.Value)
             {
                 ObjectType   type = (ObjectType)Convert.ToUInt16(it[0]);
                 String       ln   = GXCommon.ToLogicalName(it[1]);
                 GXDLMSObject obj  = settings.Objects.FindByLN(type, ln);
                 if (obj == null)
                 {
                     obj             = GXDLMSClient.CreateObject(type);
                     obj.LogicalName = ln;
                 }
                 GXDLMSCaptureObject co = new GXDLMSCaptureObject(Convert.ToInt32(it[2]), Convert.ToInt32(it[3]));
                 PushObjectList.Add(new KeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, co));
             }
         }
     }
     else if (e.Index == 3)
     {
         List <object> tmp = e.Value as List <object>;
         if (tmp != null)
         {
             Service = (ServiceType)Convert.ToInt32(tmp[0]);
             //LN can be used with HDLC
             if (((byte[])tmp[1]).Length == 6 && ((byte[])tmp[1])[5] == 0xFF)
             {
                 Destination = GXCommon.ToLogicalName((byte[])tmp[1]);
             }
             else
             {
                 Destination = (string)GXDLMSClient.ChangeType((byte[])tmp[1], DataType.String, settings.UseUtc2NormalTime);
             }
             Message = (MessageType)Convert.ToInt32(tmp[2]);
         }
     }
     else if (e.Index == 4)
     {
         CommunicationWindow.Clear();
         if (e.Value is List <object> )
         {
             foreach (List <object> it in e.Value as List <object> )
             {
                 GXDateTime start = GXDLMSClient.ChangeType((byte[])it[0], DataType.DateTime, settings.UseUtc2NormalTime) as GXDateTime;
                 GXDateTime end   = GXDLMSClient.ChangeType((byte[])it[1], DataType.DateTime, settings.UseUtc2NormalTime) as GXDateTime;
                 CommunicationWindow.Add(new KeyValuePair <GXDateTime, GXDateTime>(start, end));
             }
         }
     }
     else if (e.Index == 5)
     {
         RandomisationStartInterval = (UInt16)e.Value;
     }
     else if (e.Index == 6)
     {
         NumberOfRetries = (byte)e.Value;
     }
     else if (e.Index == 7)
     {
         RepetitionDelay = (UInt16)e.Value;
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
 private void ActivityViewOnSaveInstanceState(ValueEventArgs<Bundle> args)
 {
     if (!_tabLayout.IsAlive())
         return;
     var index = _tabLayout.SelectedTabPosition;
     if (index > 0)
         args.Value.PutInt(SelectedIndexKey, index);
 }
Пример #20
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(GXCommon.LogicalNameToBytes(LogicalName));
     }
     if (e.Index == 2)
     {
         return(ImageBlockSize);
     }
     if (e.Index == 3)
     {
         return(ImageTransferredBlocksStatus);
     }
     if (e.Index == 4)
     {
         return(ImageFirstNotTransferredBlockNumber);
     }
     if (e.Index == 5)
     {
         return(ImageTransferEnabled);
     }
     if (e.Index == 6)
     {
         return(ImageTransferStatus);
     }
     if (e.Index == 7)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (ImageActivateInfo == null)
         {
             GXCommon.SetObjectCount(0, data);
         }
         else
         {
             GXCommon.SetObjectCount(ImageActivateInfo.Length, data);
             foreach (GXDLMSImageActivateInfo it in ImageActivateInfo)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8(3);
                 GXCommon.SetData(settings, data, DataType.UInt32, it.Size);
                 if (it.Identification == null)
                 {
                     GXCommon.SetData(settings, data, DataType.OctetString, null);
                 }
                 else
                 {
                     GXCommon.SetData(settings, data, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(it.Identification));
                 }
                 if (it.Signature == null || it.Signature.Length == 0)
                 {
                     GXCommon.SetData(settings, data, DataType.OctetString, null);
                 }
                 else
                 {
                     GXCommon.SetData(settings, data, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(it.Signature));
                 }
             }
         }
         return(data.Array());
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Пример #21
0
        void OnLogMessage(object sender, ValueEventArgs<string> e)
        {
            this.Dispatcher.BeginInvoke((Action)delegate ()
            {
                StringValue s = new StringValue(e.Value);
                AddLineToLog(s.Text);

            });
        }
Пример #22
0
 private void Track_LengthOrOffsetChanged(object sender, ValueEventArgs <TimeSpan> e)
 {
     // if a track length or offset changes, it might affect the whole tracklist
     // TODO check if tracklist properties are affected and only fire event in these cases
     OnTrackListChanged();
 }
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (ObjectList == null)
     {
         ObjectList = new GXDLMSObjectCollection();
     }
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     else if (e.Index == 2)
     {
         return GetObjects(settings, e).Array();
     }
     else if (e.Index == 3)
     {
         bool lnExists = ObjectList.FindBySN(this.ShortName) != null;
         //Add count
         int cnt = ObjectList.Count;
         if (!lnExists)
         {
             ++cnt;
         }
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         GXCommon.SetObjectCount(cnt, data);
         foreach (GXDLMSObject it in ObjectList)
         {
             GetAccessRights(settings, it, data);
         }
         if (!lnExists)
         {
             GetAccessRights(settings, this, data);
         }
         return data.Array();
     }
     else if (e.Index == 4)
     {
         GXByteBuffer data = new GXByteBuffer();
         GXCommon.SetData(settings, data, DataType.OctetString, SecuritySetupReference);
         return data.Array();
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return null;
 }
Пример #24
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         if (Scaler != 1 && e.Value != null && !e.User)
         {
             try
             {
                 if (settings != null && settings.IsServer)
                 {
                     Value = e.Value;
                 }
                 else
                 {
                     Value = Convert.ToDouble(e.Value) * Scaler;
                 }
             }
             catch (Exception)
             {
                 //Sometimes scaler is set for wrong Object type.
                 Value = e.Value;
             }
         }
         else
         {
             Value = e.Value;
         }
     }
     else if (e.Index == 3)
     {
         if (e.Value == null)
         {
             Scaler = 1;
             Unit   = Unit.None;
         }
         else
         {
             List <object> arr;
             if (e.Value is List <object> )
             {
                 arr = (List <object>)e.Value;
             }
             else
             {
                 arr = new List <object>((object[])e.Value);
             }
             if (arr.Count != 2)
             {
                 throw new Exception("SetValue failed. Invalid scaler unit value.");
             }
             scaler = Convert.ToInt32(arr[0]);
             Unit   = (Unit)(Convert.ToInt32(arr[1]) & 0xFF);
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Пример #25
0
 /// <summary>
 /// This event handler is called when a connection has been terminated.
 /// </summary>
 void meEv_OnDisconnected(object sender, ValueEventArgs<DisconnectReason> arguments)
 {
     FLAG_connectionInProgress = false;
     appEv_Disconnected(this, EventArgs.Empty);
 }
Пример #26
0
        void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            if (e.Index == 1)
            {
                LogicalName = GXCommon.ToLogicalName(e.Value);
            }
            else if (e.Index == 2)
            {
                Scripts.Clear();
                //Fix Xemex bug here.
                //Xemex meters do not return array as they shoul be according standard.
                if (e.Value is List <object> && ((List <object>)e.Value).Count != 0)
                {
                    if (((List <object>)e.Value)[0] is List <object> )
                    {
                        foreach (List <object> item in (List <object>)e.Value)
                        {
                            GXDLMSScript script = new GXDLMSScript();
                            script.Id = Convert.ToInt32(item[0]);
                            Scripts.Add(script);
                            foreach (List <object> arr in (List <object>)item[1])
                            {
                                GXDLMSScriptAction it = new GXDLMSScriptAction();
                                it.Type = (ScriptActionType)Convert.ToInt32(arr[0]);
                                ObjectType ot = (ObjectType)Convert.ToInt32(arr[1]);
                                String     ln = GXCommon.ToLogicalName(arr[2]);
                                it.Target = settings.Objects.FindByLN(ot, ln);
                                if (it.Target == null)
                                {
#pragma warning disable CS0618
                                    it.ObjectType  = ot;
                                    it.LogicalName = ln;
#pragma warning restore CS0618
                                }

                                it.Index     = Convert.ToInt32(arr[3]);
                                it.Parameter = arr[4];
                                if (it.Parameter != null)
                                {
                                    it.ParameterDataType = GXDLMSConverter.GetDLMSDataType(it.Parameter);
                                }
                                script.Actions.Add(it);
                            }
                        }
                    }
                    else //Read Xemex meter here.
                    {
                        GXDLMSScript script = new GXDLMSScript();
                        script.Id = Convert.ToInt32(((List <object>)e.Value)[0]);
                        Scripts.Add(script);
                        List <object>      arr = (List <object>)((List <object>)e.Value)[1];
                        GXDLMSScriptAction it  = new GXDLMSScriptAction();
                        it.Type = (ScriptActionType)Convert.ToInt32(arr[0]);
                        ObjectType ot = (ObjectType)Convert.ToInt32(arr[1]);
                        String     ln = GXCommon.ToLogicalName(arr[2]);
                        it.Target = settings.Objects.FindByLN(ot, ln);
                        if (it.Target == null)
                        {
#pragma warning disable CS0618
                            it.ObjectType  = ot;
                            it.LogicalName = ln;
#pragma warning restore CS0618
                        }

                        it.Index     = Convert.ToInt32(arr[3]);
                        it.Parameter = arr[4];
                        script.Actions.Add(it);
                    }
                }
            }
            else
            {
                e.Error = ErrorCode.ReadWriteDenied;
            }
        }
Пример #27
0
 private void OnPostCreate(Activity sender, ValueEventArgs<Bundle> args)
 {
     var drawerToggle = _listener as ActionBarDrawerToggle;
     if (drawerToggle != null)
         drawerToggle.SyncState();
 }
        /// <summary>
        /// Returns buffer data.
        /// </summary>
        /// <param name="settings">DLMS settings.</param>
        /// <param name="e"></param>
        /// <param name="table"></param>
        /// <param name="columns">Columns to get. NULL if not used.</param>
        /// <returns></returns>
        byte[] GetData(GXDLMSSettings settings, ValueEventArgs e, List <object[]> table,
                       List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > columns)
        {
            int pos = 0;
            List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > cols = columns;

            if (columns == null)
            {
                cols = CaptureObjects;
            }
            DataType[] types = new DataType[cols.Count];
            foreach (GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> it in cols)
            {
                if (it.Value.AttributeIndex == 0)
                {
                    types[pos] = DataType.Structure;
                }
                else
                {
                    types[pos] = it.Key.GetDataType(it.Value.AttributeIndex);
                }
                ++pos;
            }
            UInt16 columnStart = 1, columnEnd = 0;

            if (e.Selector == 2)
            {
                List <object> arr = null;
                if (e.Parameters is List <object> )
                {
                    arr = (List <object>)e.Parameters;
                }
                else if (e.Parameters != null)
                {
                    arr = new List <object>((object[])e.Parameters);
                }
                columnStart = (UInt16)arr[2];
                columnEnd   = (UInt16)arr[3];
            }

            if (columnStart > 1 || columnEnd != 0)
            {
                pos  = 1;
                cols = new List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> >();
                foreach (GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> it in CaptureObjects)
                {
                    if (!(pos < columnStart || pos > columnEnd))
                    {
                        cols.Add(it);
                    }
                    ++pos;
                }
                pos = 0;
            }
            GXByteBuffer data = new GXByteBuffer();

            if (settings.Index == 0)
            {
                data.SetUInt8((byte)DataType.Array);
                if (e.RowEndIndex != 0)
                {
                    GXCommon.SetObjectCount((int)(e.RowEndIndex - e.RowBeginIndex), data);
                }
                else
                {
                    GXCommon.SetObjectCount(table.Count, data);
                }
            }

            foreach (object[] items in table)
            {
                data.SetUInt8((byte)DataType.Structure);
                GXCommon.SetObjectCount(cols.Count, data);
                pos = 0;
                DataType tp;
                foreach (object value in items)
                {
                    if (cols == null || cols.Contains(CaptureObjects[pos]))
                    {
                        tp = types[pos];
                        if (tp == DataType.None)
                        {
                            tp         = GXDLMSConverter.GetDLMSDataType(value);
                            types[pos] = tp;
                        }
                        if (value == null)
                        {
                            tp = DataType.None;
                        }
                        if (value is GXDLMSObject)
                        {
                            GXCommon.SetData(settings, data, tp, (value as GXDLMSObject).GetValues());
                        }
                        else
                        {
                            GXCommon.SetData(settings, data, tp, value);
                        }
                    }
                    ++pos;
                }
                ++settings.Index;
            }
            if (e.RowEndIndex != 0)
            {
                e.RowBeginIndex += (UInt32)table.Count;
            }
            else
            {
                settings.Index = 0;
            }
            return(data.Array());
        }
Пример #29
0
        private void ProcessCategoryData()
        {
            _categoryValues.Clear();
            if (DataSource != null)
            {
                var eval = !string.IsNullOrEmpty(CategoryValueMemberPath)
                               ? new BindingEvaluator(CategoryValueMemberPath)
                               : null;
                foreach (var dataItem in DataSource)
                {
                    var valueEventArgs = new ValueEventArgs<string> { Item = dataItem };
                    OnEvaluatingCategory(valueEventArgs);

                    if (valueEventArgs.IsValueSet)
                    {
                        _categoryValues.Add(valueEventArgs.Value);
                    }
                    else if (eval != null)
                    {
                        _categoryValues.Add(eval.Eval(dataItem).ToString());
                    }
                }
            }
        }
Пример #30
0
 /// <summary>
 ///         引发全局标识改变事件
 /// </summary>
 /// <param name="e">包含事件数据的<see cref="EventArgs" />实例</param>
 protected virtual void OnEffectiveChanged(ValueEventArgs <bool> e)
 {
     e.Raise(this, ref EffectiveChanged);
 }
Пример #31
0
 private void HubCommunicator_ImportStatusNotification(object sender, ValueEventArgs<ImportStatus> e)
 {
     Deployment.Current.Dispatcher.BeginInvoke(() => ShowStatus(e.Value));
 }
Пример #32
0
        void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            if (e.Index == 1)
            {
                if (e.Value is string)
                {
                    LogicalName = e.Value.ToString();
                }
                else
                {
                    LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString, settings.UseUtc2NormalTime).ToString();
                }
            }
            else if (e.Index == 2)
            {
                SetBuffer(settings, e);
            }
            else if (e.Index == 3)
            {
                Reset();
                CaptureObjects.Clear();
                GXDLMSObjectCollection objects = new GXDLMSObjectCollection();
                if (e.Value != null)
                {
                    foreach (object it in e.Value as object[])
                    {
                        object[] tmp = it as object[];
                        if (tmp.Length != 4)
                        {
                            throw new GXDLMSException("Invalid structure format.");
                        }
                        ObjectType   type           = (ObjectType)Convert.ToInt16(tmp[0]);
                        string       ln             = GXDLMSObject.ToLogicalName((byte[])tmp[1]);
                        int          attributeIndex = Convert.ToInt16(tmp[2]);
                        int          dataIndex      = Convert.ToInt16(tmp[3]);
                        GXDLMSObject obj            = null;
                        if (settings != null && settings.Objects != null)
                        {
                            obj = settings.Objects.FindByLN(type, ln);
                        }
                        if (obj == null)
                        {
                            obj = GXDLMSClient.CreateDLMSObject((int)type, null, 0, ln, 0);
                        }
                        CaptureObjects.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, new GXDLMSCaptureObject(attributeIndex, dataIndex)));
                        objects.Add(obj);
                    }
                }
            }
            else if (e.Index == 4)
            {
                //Any write access to one of the attributes will automatically call a reset
                //and this call will propagate to all other profiles capturing this profile.
                if (settings.IsServer)
                {
                    Reset();
                }
                CapturePeriod = Convert.ToInt32(e.Value);
            }
            else if (e.Index == 5)
            {
                //Any write access to one of the attributes will automatically call a reset
                //and this call will propagate to all other profiles capturing this profile.
                if (settings.IsServer)
                {
                    Reset();
                }
                SortMethod = (SortMethod)Convert.ToInt32(e.Value);
            }
            else if (e.Index == 6)
            {
                //Any write access to one of the attributes will automatically call a reset
                //and this call will propagate to all other profiles capturing this profile.
                if (settings.IsServer)
                {
                    Reset();
                }

                if (e.Value != null)
                {
                    object[] tmp = e.Value as object[];
                    if (tmp.Length != 4)
                    {
                        throw new GXDLMSException("Invalid structure format.");
                    }
                    ObjectType type = (ObjectType)Convert.ToInt16(tmp[0]);
                    string     ln   = GXDLMSObject.ToLogicalName((byte[])tmp[1]);
                    SortAttributeIndex = Convert.ToInt16(tmp[2]);
                    SortDataIndex      = Convert.ToInt16(tmp[3]);
                    SortObject         = null;
                    foreach (var it in CaptureObjects)
                    {
                        if (it.Key.ObjectType == type && it.Key.LogicalName == ln)
                        {
                            SortObject = it.Key;
                            break;
                        }
                    }
                    if (SortObject == null)
                    {
                        SortObject             = GXDLMSClient.CreateObject(type);
                        SortObject.LogicalName = ln;
                    }
                }
                else
                {
                    SortObject = null;
                }
            }
            else if (e.Index == 7)
            {
                EntriesInUse = Convert.ToInt32(e.Value);
            }
            else if (e.Index == 8)
            {
                //Any write access to one of the attributes will automatically call a reset
                //and this call will propagate to all other profiles capturing this profile.
                if (settings.IsServer)
                {
                    Reset();
                }
                ProfileEntries = Convert.ToInt32(e.Value);
            }
            else
            {
                e.Error = ErrorCode.ReadWriteDenied;
            }
        }
Пример #33
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(GXCommon.LogicalNameToBytes(LogicalName));
     }
     if (e.Index == 2)
     {
         return(ShortAddress);
     }
     if (e.Index == 3)
     {
         return(RcCoord);
     }
     if (e.Index == 4)
     {
         return(PANId);
     }
     if (e.Index == 5)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (KeyTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(KeyTable.Count, bb);
             foreach (GXKeyValuePair <byte, byte[]> it in KeyTable)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(2);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Key);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Value);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 6)
     {
         return(FrameCounter);
     }
     if (e.Index == 7)
     {
         return(ToneMask);
     }
     if (e.Index == 8)
     {
         return(TmrTtl);
     }
     if (e.Index == 9)
     {
         return(MaxFrameRetries);
     }
     if (e.Index == 10)
     {
         return(NeighbourTableEntryTtl);
     }
     if (e.Index == 11)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (NeighbourTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(NeighbourTable.Length, bb);
             foreach (GXDLMSNeighbourTable it in NeighbourTable)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(11);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.ShortAddress);
                 GXCommon.SetData(settings, bb, DataType.Boolean, it.Enabled);
                 GXCommon.SetData(settings, bb, DataType.BitString, it.ToneMap);
                 GXCommon.SetData(settings, bb, DataType.Enum, it.Modulation);
                 GXCommon.SetData(settings, bb, DataType.Int8, it.TxGain);
                 GXCommon.SetData(settings, bb, DataType.Enum, it.TxRes);
                 GXCommon.SetData(settings, bb, DataType.BitString, it.TxCoeff);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Lqi);
                 GXCommon.SetData(settings, bb, DataType.Int8, it.PhaseDifferential);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.TMRValidTime);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.NeighbourValidTime);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 12)
     {
         return(HighPriorityWindowSize);
     }
     if (e.Index == 13)
     {
         return(CscmFairnessLimit);
     }
     if (e.Index == 14)
     {
         return(BeaconRandomizationWindowLength);
     }
     if (e.Index == 15)
     {
         return(A);
     }
     if (e.Index == 16)
     {
         return(K);
     }
     if (e.Index == 17)
     {
         return(MinCwAttempts);
     }
     if (e.Index == 18)
     {
         return(CenelecLegacyMode);
     }
     if (e.Index == 19)
     {
         return(FccLegacyMode);
     }
     if (e.Index == 20)
     {
         return(MaxBe);
     }
     if (e.Index == 21)
     {
         return(MaxCsmaBackoffs);
     }
     if (e.Index == 22)
     {
         return(MinBe);
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Пример #34
0
        void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            if (e.Index == 1)
            {
                LogicalName = GXCommon.ToLogicalName(e.Value);
            }
            else if (e.Index == 2)
            {
                Scripts.Clear();
                //Fix Xemex bug here.
                //Xemex meters do not return array as they shoul be according standard.
                if (e.Value is IEnumerable <object> )
                {
                    List <object> arr, arr1;
                    if (e.Value is List <object> )
                    {
                        arr1 = (List <object>)e.Value;
                    }
                    else
                    {
                        arr1 = new List <object>((object[])e.Value);
                    }
                    if (arr1[0] is IEnumerable <object> )
                    {
                        foreach (object tmp in (IEnumerable <object>)e.Value)
                        {
                            List <object> item;
                            if (tmp is List <object> )
                            {
                                item = (List <object>)tmp;
                            }
                            else
                            {
                                item = new List <object>((object[])tmp);
                            }
                            GXDLMSScript script = new GXDLMSScript();
                            script.Id = Convert.ToInt32(item[0]);
                            Scripts.Add(script);
                            foreach (object tmp2 in (IEnumerable <object>)item[1])
                            {
                                if (tmp2 is List <object> )
                                {
                                    arr = (List <object>)tmp2;
                                }
                                else
                                {
                                    arr = new List <object>((object[])tmp2);
                                }
                                GXDLMSScriptAction it = new GXDLMSScriptAction();
                                it.Type = (ScriptActionType)Convert.ToInt32(arr[0]);
                                ObjectType ot = (ObjectType)Convert.ToInt32(arr[1]);
                                String     ln = GXCommon.ToLogicalName(arr[2]);
                                it.Target = settings.Objects.FindByLN(ot, ln);
                                if (it.Target == null)
                                {
                                    it.Target             = GXDLMSClient.CreateObject(ot);
                                    it.Target.LogicalName = ln;
                                }
                                it.Index     = Convert.ToInt32(arr[3]);
                                it.Parameter = arr[4];
                                if (it.Parameter != null)
                                {
                                    it.ParameterDataType = GXDLMSConverter.GetDLMSDataType(it.Parameter);
                                }
                                script.Actions.Add(it);
                            }
                        }
                    }
                    else //Read Xemex meter here.
                    {
                        GXDLMSScript script = new GXDLMSScript();
                        if (e.Value is List <object> )
                        {
                            arr1 = (List <object>)e.Value;
                        }
                        else
                        {
                            arr1 = new List <object>((object[])e.Value);
                        }

                        script.Id = Convert.ToInt32(arr1[0]);
                        Scripts.Add(script);
                        if (arr1[1] is List <object> )
                        {
                            arr = (List <object>)arr1[1];
                        }
                        else
                        {
                            arr = new List <object>((object[])arr1[1]);
                        }
                        GXDLMSScriptAction it = new GXDLMSScriptAction();
                        it.Type = (ScriptActionType)Convert.ToInt32(arr[0]);
                        ObjectType ot = (ObjectType)Convert.ToInt32(arr[1]);
                        String     ln = GXCommon.ToLogicalName(arr[2]);
                        it.Target = settings.Objects.FindByLN(ot, ln);
                        if (it.Target == null)
                        {
#pragma warning disable CS0618
                            it.ObjectType  = ot;
                            it.LogicalName = ln;
#pragma warning restore CS0618
                        }

                        it.Index     = Convert.ToInt32(arr[3]);
                        it.Parameter = arr[4];
                        script.Actions.Add(it);
                    }
                }
            }
            else
            {
                e.Error = ErrorCode.ReadWriteDenied;
            }
        }
 private static void ActivityViewOnSaveInstanceState(Activity sender, ValueEventArgs<Bundle> args)
 {
     var actionBar = sender.GetActionBar();
     if (actionBar == null)
         return;
     var index = actionBar.SelectedNavigationIndex;
     args.Value.PutInt(SelectedTabIndexKey, index);
 }
Пример #36
0
        void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            switch (e.Index)
            {
            case 1:
                LogicalName = GXCommon.ToLogicalName(e.Value);
                break;

            case 2:
                CurrentCreditAmount = (int)e.Value;
                break;

            case 3:
                Type = (CreditType)Convert.ToByte(e.Value);
                break;

            case 4:
                Priority = (byte)e.Value;
                break;

            case 5:
                WarningThreshold = (int)e.Value;
                break;

            case 6:
                Limit = (int)e.Value;
                break;

            case 7:
                CreditConfiguration = (CreditConfiguration)Convert.ToByte(e.Value);
                break;

            case 8:
                Status = (CreditStatus)Convert.ToByte(e.Value);
                break;

            case 9:
                PresetCreditAmount = (int)e.Value;
                break;

            case 10:
                CreditAvailableThreshold = (int)e.Value;
                break;

            case 11:
                if (e.Value == null)
                {
                    Period = new GXDateTime(DateTime.MinValue);
                }
                else
                {
                    if (e.Value is byte[])
                    {
                        e.Value = GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime);
                    }
                    else if (e.Value is string)
                    {
                        e.Value = new GXDateTime((string)e.Value);
                    }
                    if (e.Value is GXDateTime)
                    {
                        Period = (GXDateTime)e.Value;
                    }
                }
                break;

            default:
                e.Error = ErrorCode.ReadWriteDenied;
                break;
            }
        }
Пример #37
0
 void OnDisconnected(object sender, ValueEventArgs<DisconnectReason> e)
 {
     this.Dispatcher.BeginInvoke((Action)delegate ()
     {
         btnConnectDisconnect.Content = AppText.Connect;
         SetColorOfRect(false);
         isConnected = false;
         UpdateButtons();
     });
 }
Пример #38
0
        object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            if (e.Index == 1)
            {
                return(GXCommon.LogicalNameToBytes(LogicalName));
            }
            else if (e.Index == 2)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(3);
                if (MonitoredValue == null)
                {
                    GXCommon.SetData(settings, data, DataType.Int16, 0);
                    GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(null));
                    GXCommon.SetData(settings, data, DataType.UInt8, 0);
                }
                else
                {
                    GXCommon.SetData(settings, data, DataType.Int16, MonitoredValue.ObjectType);
                    GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(MonitoredValue.LogicalName));
                    GXCommon.SetData(settings, data, DataType.UInt8, MonitoredAttributeIndex);
                }
                return(data.Array());
            }
            else if (e.Index == 3)
            {
                return(ThresholdActive);
            }
            else if (e.Index == 4)
            {
                return(ThresholdNormal);
            }
            else if (e.Index == 5)
            {
                return(ThresholdEmergency);
            }
            else if (e.Index == 6)
            {
                return(MinOverThresholdDuration);
            }
            else if (e.Index == 7)
            {
                return(MinUnderThresholdDuration);
            }
            else if (e.Index == 8)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(3);
                GXCommon.SetData(settings, data, DataType.UInt16, EmergencyProfile.ID);
                GXCommon.SetData(settings, data, DataType.OctetString, EmergencyProfile.ActivationTime);
                GXCommon.SetData(settings, data, DataType.UInt32, EmergencyProfile.Duration);
                return(data.Array());
            }
            else if (e.Index == 9)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Array);
                if (EmergencyProfileGroupIDs == null)
                {
                    data.SetUInt8(0);
                }
                else
                {
                    data.SetUInt8((byte)EmergencyProfileGroupIDs.Length);
                    foreach (object it in EmergencyProfileGroupIDs)
                    {
                        GXCommon.SetData(settings, data, DataType.UInt16, it);
                    }
                }

                return(data.Array());
            }
            else if (e.Index == 10)
            {
                return(EmergencyProfileActive);
            }
            else if (e.Index == 11)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(2);
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(2);
                GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(ActionOverThreshold.LogicalName));
                GXCommon.SetData(settings, data, DataType.UInt16, ActionOverThreshold.ScriptSelector);
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(2);
                GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(ActionUnderThreshold.LogicalName));
                GXCommon.SetData(settings, data, DataType.UInt16, ActionUnderThreshold.ScriptSelector);
                return(data.Array());
            }
            e.Error = ErrorCode.ReadWriteDenied;
            return(null);
        }
 protected virtual void MultiViewModelOnViewModelClosed(object sender, ValueEventArgs<IViewModel> args)
 {
     var context = new NavigationContext(NavigationType.Tab, NavigationMode.Back, args.Value,
         MultiViewModel.SelectedItem, MultiViewModel);
     bool? result = null;
     var hasOperationResult = args.Value as IHasOperationResult;
     if (hasOperationResult != null)
         result = hasOperationResult.OperationResult;
     CallbackManager.SetResult(args.Value, OperationResult.CreateResult(OperationType.TabNavigation, args.Value, result, context));
 }
Пример #40
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         ObjectType ot       = (ObjectType)Convert.ToInt16(((object[])e.Value)[0]);
         string     ln       = GXCommon.ToLogicalName(((object[])e.Value)[1]);
         int        attIndex = Convert.ToInt32(((object[])e.Value)[2]);
         MonitoredValue          = settings.Objects.FindByLN(ot, ln);
         MonitoredAttributeIndex = attIndex;
     }
     else if (e.Index == 3)
     {
         ThresholdActive = e.Value;
     }
     else if (e.Index == 4)
     {
         ThresholdNormal = e.Value;
     }
     else if (e.Index == 5)
     {
         ThresholdEmergency = e.Value;
     }
     else if (e.Index == 6)
     {
         MinOverThresholdDuration = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 7)
     {
         MinUnderThresholdDuration = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 8)
     {
         object[] tmp = (object[])e.Value;
         EmergencyProfile.ID             = (UInt16)tmp[0];
         EmergencyProfile.ActivationTime = (GXDateTime)GXDLMSClient.ChangeType((byte[])tmp[1], DataType.DateTime, settings.UseUtc2NormalTime);
         EmergencyProfile.Duration       = (UInt32)tmp[2];
     }
     else if (e.Index == 9)
     {
         List <UInt16> list = new List <UInt16>();
         if (e.Value != null)
         {
             foreach (object it in (object[])e.Value)
             {
                 list.Add(Convert.ToUInt16(it));
             }
         }
         EmergencyProfileGroupIDs = list.ToArray();
     }
     else if (e.Index == 10)
     {
         EmergencyProfileActive = Convert.ToBoolean(e.Value);
     }
     else if (e.Index == 11)
     {
         object[] tmp  = (object[])e.Value;
         object[] tmp1 = (object[])tmp[0];
         object[] tmp2 = (object[])tmp[1];
         ActionOverThreshold.LogicalName     = GXCommon.ToLogicalName(tmp1[0]);
         ActionOverThreshold.ScriptSelector  = Convert.ToUInt16(tmp1[1]);
         ActionUnderThreshold.LogicalName    = GXCommon.ToLogicalName((byte[])tmp2[0]);
         ActionUnderThreshold.ScriptSelector = Convert.ToUInt16(tmp2[1]);
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
 /// <summary>
 /// Returns Association View.
 /// </summary>
 private GXByteBuffer GetObjects(GXDLMSSettings settings, ValueEventArgs e)
 {
     int cnt = ObjectList.Count;
     GXByteBuffer data = new GXByteBuffer();
     //Add count only for first time.
     if (settings.Index == 0)
     {
         settings.Count = (UInt16)cnt;
         data.SetUInt8((byte)DataType.Array);
         GXCommon.SetObjectCount(cnt, data);
     }
     ushort pos = 0;
     foreach (GXDLMSObject it in ObjectList)
     {
         ++pos;
         if (!(pos <= settings.Index))
         {
             data.SetUInt8((byte)DataType.Structure);
             //Count
             data.SetUInt8((byte)4);
             //base address.
             GXCommon.SetData(settings, data, DataType.Int16, it.ShortName);
             //ClassID
             GXCommon.SetData(settings, data, DataType.UInt16, it.ObjectType);
             //Version
             GXCommon.SetData(settings, data, DataType.UInt8, 0);
             //LN
             GXCommon.SetData(settings, data, DataType.OctetString, it.LogicalName);
             ++settings.Index;
             //If PDU is full.
             if (!e.SkipMaxPduSize && data.Size >= settings.MaxPduSize)
             {
                 break;
             }
         }
     }
     return data;
 }
Пример #42
0
        void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            if (e.Index == 1)
            {
                LogicalName = GXCommon.ToLogicalName(e.Value);
            }
            else if (e.Index == 2)
            {
                SetBuffer(settings, e);
            }
            else if (e.Index == 3)
            {
                Reset();
                //Clear file
                if (e.Server != null)
                {
                    ValueEventArgs[] list = new ValueEventArgs[] { new ValueEventArgs(this, 1, 0, null) };
                    e.Server.NotifyAction(list);
                    e.Server.NotifyPostAction(list);
                }
                CaptureObjects.Clear();
                if (e.Value != null)
                {
                    GetCaptureObjects(settings, CaptureObjects, e.Value as object[]);
                }
            }
            else if (e.Index == 4)
            {
                //Any write access to one of the attributes will automatically call a reset
                //and this call will propagate to all other profiles capturing this profile.
                if (settings.IsServer)
                {
                    Reset();
                }
                CapturePeriod = Convert.ToInt32(e.Value);
            }
            else if (e.Index == 5)
            {
                //Any write access to one of the attributes will automatically call a reset
                //and this call will propagate to all other profiles capturing this profile.
                if (settings.IsServer)
                {
                    Reset();
                }
                SortMethod = (SortMethod)Convert.ToInt32(e.Value);
            }
            else if (e.Index == 6)
            {
                //Any write access to one of the attributes will automatically call a reset
                //and this call will propagate to all other profiles capturing this profile.
                if (settings.IsServer)
                {
                    Reset();
                }

                if (e.Value is object[])
                {
                    object[] tmp = e.Value as object[];
                    if (tmp.Length != 4)
                    {
                        throw new GXDLMSException("Invalid structure format.");
                    }
                    ObjectType type = (ObjectType)Convert.ToInt16(tmp[0]);
                    string     ln   = GXCommon.ToLogicalName((byte[])tmp[1]);
                    SortAttributeIndex = Convert.ToInt16(tmp[2]);
                    SortDataIndex      = Convert.ToInt16(tmp[3]);
                    SortObject         = null;
                    foreach (var it in CaptureObjects)
                    {
                        if (it.Key.ObjectType == type && it.Key.LogicalName == ln)
                        {
                            SortObject = it.Key;
                            break;
                        }
                    }
                    if (SortObject == null)
                    {
                        SortObject             = GXDLMSClient.CreateObject(type);
                        SortObject.LogicalName = ln;
                    }
                }
                else
                {
                    SortObject = null;
                }
            }
            else if (e.Index == 7)
            {
                EntriesInUse = Convert.ToInt32(e.Value);
            }
            else if (e.Index == 8)
            {
                //Any write access to one of the attributes will automatically call a reset
                //and this call will propagate to all other profiles capturing this profile.
                if (settings.IsServer)
                {
                    Reset();
                }
                ProfileEntries = Convert.ToUInt32(e.Value);
            }
            else
            {
                e.Error = ErrorCode.ReadWriteDenied;
            }
        }
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         if (e.Value is string)
         {
             LogicalName = e.Value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString).ToString();
         }
     }
     else if (e.Index == 2)
     {
         ObjectList.Clear();
         if (e.Value != null)
         {
             foreach (Object[] item in (Object[])e.Value)
             {
                 ushort sn = (ushort)(Convert.ToInt32(item[0]) & 0xFFFF);
                 ObjectType type = (ObjectType)Convert.ToInt32(item[1]);
                 int version = Convert.ToInt32(item[2]);
                 String ln = GXDLMSObject.ToLogicalName((byte[])item[3]);
                 GXDLMSObject obj = null;
                 if (settings.Objects != null)
                 {
                     obj = settings.Objects.FindBySN(sn);
                 }
                 if (obj == null)
                 {
                     obj = Gurux.DLMS.GXDLMSClient.CreateObject(type);
                     if (obj != null)
                     {
                         obj.LogicalName = ln;
                         obj.ShortName = sn;
                         obj.Version = version;
                     }
                 }
                 //Unknown objects are not shown.
                 if (obj is IGXDLMSBase)
                 {
                     ObjectList.Add(obj);
                 }
             }
         }
     }
     else if (e.Index == 3)
     {
         if (e.Value == null)
         {
             foreach (GXDLMSObject it in ObjectList)
             {
                 for (int pos = 1; pos != (it as IGXDLMSBase).GetAttributeCount(); ++pos)
                 {
                     it.SetAccess(pos, AccessMode.NoAccess);
                 }
             }
         }
         else
         {
             UpdateAccessRights((Object[])e.Value);
         }
     }
     else if (e.Index == 4)
     {
         if (e.Value is string)
         {
             SecuritySetupReference = e.Value.ToString();
         }
         else
         {
             SecuritySetupReference = GXDLMSClient.ChangeType(e.Value as byte[], DataType.OctetString).ToString();
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Пример #44
0
        /// <summary>
        /// Returns buffer data.
        /// </summary>
        /// <param name="settings">DLMS settings.</param>
        /// <param name="e"></param>
        /// <param name="table"></param>
        /// <param name="columns">Columns to get. NULL if not used.</param>
        /// <returns></returns>
        byte[] GetData(GXDLMSSettings settings, ValueEventArgs e, List <object[]> table,
                       List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > columns)
        {
            int pos = 0;
            List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > cols = columns;

            if (columns == null)
            {
            }
            GXByteBuffer data = new GXByteBuffer();

            if (settings.Index == 0)
            {
                data.SetUInt8((byte)DataType.Array);
                if (e.RowEndIndex != 0)
                {
                    GXCommon.SetObjectCount((int)(e.RowEndIndex - e.RowBeginIndex), data);
                }
                else
                {
                    GXCommon.SetObjectCount(table.Count, data);
                }
            }
            DataType[] types = new DataType[CaptureObjects.Count];
            foreach (GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> it in CaptureObjects)
            {
                types[pos] = it.Key.GetDataType(it.Value.AttributeIndex);
                ++pos;
            }

            foreach (object[] items in table)
            {
                data.SetUInt8((byte)DataType.Structure);
                if (columns == null || columns.Count == 0)
                {
                    GXCommon.SetObjectCount(items.Length, data);
                }
                else
                {
                    GXCommon.SetObjectCount(columns.Count, data);
                }
                pos = 0;
                DataType tp;
                foreach (object value in items)
                {
                    if (columns == null || columns.Contains(CaptureObjects[pos]))
                    {
                        tp = types[pos];
                        if (tp == DataType.None)
                        {
                            tp         = GXDLMSConverter.GetDLMSDataType(value);
                            types[pos] = tp;
                        }
                        if (value == null)
                        {
                            tp = DataType.None;
                        }
                        GXCommon.SetData(settings, data, tp, value);
                    }
                    ++pos;
                }
                ++settings.Index;
            }
            if (e.RowEndIndex != 0)
            {
                e.RowBeginIndex += (UInt32)table.Count;
            }
            else
            {
                settings.Index = 0;
            }
            return(data.Array());
        }
Пример #45
0
        /// <summary>
        /// Event handler for DeviceDiscovered. This handler will be called when devices
        /// are discovered during asynchronous device discovery.
        /// </summary>
        void meEv_OnDeviceDiscovered(object sender, ValueEventArgs<BtDevice> arguments)
        {
            /* Avoid call after a connect procedure is being started,
             * and the discovery procedure hasn't yet been stopped. */
            if (FLAG_connectionInProgress)
            {
                return;
            }

            BtDevice device = arguments.Value;

            if (!IsEligibleForConnection(device))
            {
                return;
            }

            //FLAG_connectionInProgress = true;

            bool devInList = false;
            int i;
            for (i = 0; i < m_deviceList.Count; i++)
            {
                BtDevice d = m_deviceList[i];
                if (d.DeviceAddress.Equals(device.DeviceAddress))
                {
                    m_deviceList[i] = device; // Update (Rssi)
                    Console.WriteLine("meEv_OnDeviceDiscovered - UPDATE");
                    devInList = true;
                    break;
                }
            }

            // Get Latest Info In String Form
            String sDeviceAddress = device.DeviceAddress.Value;
            String sDevInfo_Rssi = device.DeviceInfo[DeviceInfoType.Rssi];
            String sDevInfo_CompleteLocalName;
            try
            {
                sDevInfo_CompleteLocalName = device.DeviceInfo[DeviceInfoType.CompleteLocalName];
            }
            catch //(Exception ex)
            {
                sDevInfo_CompleteLocalName = "...";
            }
            if (!devInList)
            {
                m_deviceList.Add(device);
                Console.WriteLine("meEv_OnDeviceDiscovered - Added NEW device");
            }
            if ((!devInList) || (true))//(false))
            {
                if (appEv_DeviceInfoUpdate != null)
                    appEv_DeviceInfoUpdate(this, new MinDeviceInfoEventArgs(sDevInfo_CompleteLocalName, sDeviceAddress, sDevInfo_Rssi));
            }

            if (FLAG_autoConnect == false)
                return;

            //------------------------
            //----- Auto Connect -----
            devInList = false;
            for (i = 0; i < m_deviceList.Count; i++)
            {
                device = m_deviceList[i];
                if (device.DeviceAddress.Value == m_autoConnect_sDeviceId)
                {
                    devInList = true;
                    break;
                }
            }
            if(devInList == false)
                return;

            /* Start the connection procedure in a background task to avoid
             * blocking the event caller. */
            Task.Factory.StartNew(() =>
            {
                try
                {
                    FLAG_connectionInProgress = true;
                    appEv_ConnectionStarted(this, EventArgs.Empty); // Connecting event to MainWindow
                    bool bStatus;
                    bStatus = this.Connect_to_device(device);
                    if (!bStatus)
                    {
                        FLAG_connectionInProgress = false;
                        appEv_ConnectionCancelled(this, EventArgs.Empty); // ConnectionCanceled event to MainWindow
                        return;
                    }
                }
                catch (Exception ex)
                {
                    LogErrorMessage(string.Format("Exception in OnDeviceDiscovered: {0}", ex.Message), ex.StackTrace);
                    FLAG_connectionInProgress = false;
                    appEv_ConnectionCancelled(this, EventArgs.Empty); // ConnectionCanceled event to MainWindow
                }
            });
        }
Пример #46
0
        byte[] GetProfileGenericData(GXDLMSSettings settings, ValueEventArgs e)
        {
            List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > columns = null;

            //If all data is read.
            if (e.Selector == 0 || e.Parameters == null || e.RowEndIndex != 0)
            {
                return(GetData(settings, e, Buffer, columns));
            }
            object[]        arr   = (object[])e.Parameters;
            List <object[]> table = new List <object[]>();

            lock (Buffer)
            {
                if (e.Selector == 1) //Read by range
                {
                    GXDataInfo info = new GXDataInfo();
                    info.Type = DataType.DateTime;
                    DateTime start = ((GXDateTime)GXCommon.GetData(settings, new GXByteBuffer((byte[])arr[1]), info)).Value.LocalDateTime;
                    info.Clear();
                    info.Type = DataType.DateTime;
                    DateTime end = ((GXDateTime)GXCommon.GetData(settings, new GXByteBuffer((byte[])arr[2]), info)).Value.LocalDateTime;
                    if (arr.Length > 3)
                    {
                        columns = GetColumns((Object[])((Object[])arr)[3]);
                    }
                    foreach (object[] row in Buffer)
                    {
                        DateTime tm = Convert.ToDateTime(row[0]);
                        if (tm >= start && tm <= end)
                        {
                            table.Add(row);
                        }
                    }
                }
                else if (e.Selector == 2)//Read by entry.
                {
                    int start = Convert.ToInt32(arr[0]);
                    if (start == 0)
                    {
                        start = 1;
                    }
                    int count = Convert.ToInt32(arr[1]);
                    if (count == 0)
                    {
                        count = Buffer.Count;
                    }
                    if (start + count > Buffer.Count + 1)
                    {
                        count = Buffer.Count;
                    }

                    int colStart = 1;
                    int colCount = 0;
                    if (arr.Length > 2)
                    {
                        colStart = Convert.ToUInt16(arr[2]);
                    }
                    if (arr.Length > 3)
                    {
                        colCount = Convert.ToUInt16(arr[3]);
                    }
                    else if (colStart != 1)
                    {
                        colCount = CaptureObjects.Count;
                    }
                    if (colStart != 1 || colCount != 0)
                    {
                        columns = new List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> >();
                        for (int pos = 0; pos != colCount; ++pos)
                        {
                            columns.Add(CaptureObjects[colStart + pos - 1]);
                        }
                    }

                    //Get rows.
                    // Starting index is 1.
                    for (int pos = 0; pos < count; ++pos)
                    {
                        if (pos + start - 1 == Buffer.Count)
                        {
                            break;
                        }
                        table.Add(Buffer[start + pos - 1]);
                    }
                }
                else
                {
                    throw new Exception("Invalid selector.");
                }
            }
            return(GetData(settings, e, table, columns));
        }
Пример #47
0
        //===== udEngine =====
        /*
        void OnDataReceived_Dn(Object sender, Nordicsemi.PipeDataEventArgs arguments)
        {
            udEngine.On_Dcfm( arguments.PipeData, arguments.PipeData.Length );
        }
        void OnDataReceived_Up(Object sender, Nordicsemi.PipeDataEventArgs arguments)
        {
            if( arguments.PipeNumber == pipeSetup.UcmdPipe )
                udEngine.On_Ucmd( arguments.PipeData, arguments.PipeData.Length );
            if( arguments.PipeNumber == pipeSetup.UdatPipe )
                udEngine.On_Udat( arguments.PipeData, arguments.PipeData.Length );
        }
        */
        //===== ctrlEngine =====
        /*
        void OnDataReceived_Wctrl(Object sender, Nordicsemi.PipeDataEventArgs arguments)
        {
            if (arguments.PipeNumber == pipeSetup.WctrlPipe)
                ctrlEngine.On_Wctrl(arguments.PipeData, arguments.PipeData.Length);
        }
        void OnDataReceived_Rctrl(Object sender, Nordicsemi.PipeDataEventArgs arguments)
        {
            if (arguments.PipeNumber == pipeSetup.RctrlPipe)
                //ctrlEngine.On_Rctrl(sender, arguments);
                ctrlEngine.On_Rctrl(arguments.PipeData, arguments.PipeData.Length);
        }
        */
        /// <summary>
        /// This event handler is called when data has been received on any of our pipes.
        /// </summary>
        /* REF
        void OnDataReceived_Uart(object sender, PipeDataEventArgs arguments)
        {
            if (arguments.PipeNumber != pipeSetup.UartTxPipe)
            {
                AddToLog("Received data on unknown pipe.");
                return;
            }

            StringBuilder stringBuffer = new StringBuilder();
            foreach (byte element in arguments.PipeData)
            {
                stringBuffer.AppendFormat(" 0x{0:X2}", element);
            }

            if (DebugMessagesEnabled)
            {
                AddToLog(string.Format("Data received on pipe number {0}:{1}", arguments.PipeNumber,
                    stringBuffer.ToString()));
            }

            byte[] utf8Array = arguments.PipeData;
            string convertedText = Encoding.UTF8.GetString(utf8Array);
            AddToLog(string.Format("RX: {0}", convertedText));
        }
        REF */
        /// <summary>
        /// Relay received log message events to the log method.
        /// </summary>
        void meEv_OnLogMessage(object sender, ValueEventArgs<string> arguments)
        {
            string message = arguments.Value;

            if (message.Contains("Connected to"))
            {
                /* Don't filter out */
            }
            else if (message.Contains("Disconnected"))
            {
                return;
            }
            else if (!DebugMessagesEnabled)
            {
                return;
            }

            AddToLog(string.Format("{0}", arguments.Value));
        }
Пример #48
0
        private void SetBuffer(GXDLMSSettings settings, ValueEventArgs e)
        {
            List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > cols = null;

            if (e.Parameters is List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > )
            {
                cols = (List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> >)e.Parameters;
            }
            if (cols == null)
            {
                cols = CaptureObjects;
            }
            if (e.Value != null && (e.Value as object[]).Length != 0)
            {
                int      index2   = 0;
                DateTime lastDate = DateTime.MinValue;
                foreach (object[] row in (e.Value as object[]))
                {
                    if (cols.Count != 0)
                    {
                        if ((row as object[]).Length != cols.Count)
                        {
                            throw new Exception("The number of columns does not match.");
                        }
                        for (int pos = 0; pos != row.Length; ++pos)
                        {
                            if (cols == null)
                            {
                                index2 = 0;
                            }
                            else
                            {
                                index2 = cols[pos].Value.AttributeIndex;
                            }
                            DataType type;
                            //Actaris SL 7000 and ACE 6000 returns 0.
                            if (index2 > 0)
                            {
                                type = cols[pos].Key.GetUIDataType(index2);
                            }
                            else
                            {
                                type = DataType.None;
                            }
                            if (row[pos] is byte[])
                            {
                                if (type != DataType.None && row[pos] is byte[])
                                {
                                    row[pos] = GXDLMSClient.ChangeType(row[pos] as byte[], type, settings.UseUtc2NormalTime);
                                    if (row[pos] is GXDateTime)
                                    {
                                        GXDateTime dt = (GXDateTime)row[pos];
                                        lastDate = dt.Value.LocalDateTime;
                                    }
                                }
                            }
                            else if (type == DataType.DateTime && row[pos] == null && CapturePeriod != 0)
                            {
                                if (lastDate == DateTime.MinValue && Buffer.Count != 0)
                                {
                                    lastDate = ((GXDateTime)Buffer[Buffer.Count - 1].GetValue(pos)).Value.LocalDateTime;
                                }
                                if (lastDate != DateTime.MinValue)
                                {
                                    lastDate = lastDate.AddSeconds(CapturePeriod);
                                    row[pos] = new GXDateTime(lastDate);
                                }
                            }
                            else if (type == DataType.DateTime && row[pos] is UInt32)
                            {
                                row[pos] = GXDateTime.FromUnixTime(((UInt32)row[pos]));
                            }

                            if (cols[pos].Key is GXDLMSRegister && index2 == 2)
                            {
                                double scaler = (cols[pos].Key as GXDLMSRegister).Scaler;
                                if (scaler != 1)
                                {
                                    try
                                    {
                                        row[pos] = Convert.ToDouble(row[pos]) * scaler;
                                    }
                                    catch
                                    {
                                        //Skip error
                                    }
                                }
                            }
                            else if (cols[pos].Key is GXDLMSDemandRegister && (index2 == 2 || index2 == 3))
                            {
                                double scaler = (cols[pos].Key as GXDLMSDemandRegister).Scaler;
                                if (scaler != 1)
                                {
                                    try
                                    {
                                        row[pos] = Convert.ToDouble(row[pos]) * scaler;
                                    }
                                    catch
                                    {
                                        //Skip error
                                    }
                                }
                            }
                            else if (cols[pos].Key is GXDLMSRegister && index2 == 3)
                            {
                                try
                                {
                                    GXDLMSRegister r = new GXDLMSRegister();
                                    ValueEventArgs v = new ValueEventArgs(r, 3, 0, null);
                                    v.Value = row[pos];
                                    (r as IGXDLMSBase).SetValue(null, v);
                                    row[pos] = new object[] { r.Scaler, r.Unit };
                                }
                                catch
                                {
                                    //Skip error
                                }
                            }
                        }
                    }
                    Buffer.Add(row);
                }
                EntriesInUse = Buffer.Count;
            }
        }
 private void ActivityViewOnSaveInstanceState(Activity sender, ValueEventArgs<Bundle> args)
 {
     var index = TabHost.CurrentTab;
     if (index > 0)
         args.Value.PutInt(SelectedTabIndexKey, index);
 }
Пример #50
0
 byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e)
 {
     ImageTransferStatus = ImageTransferStatus.NotInitiated;
     //Image transfer initiate
     if (e.Index == 1)
     {
         ImageFirstNotTransferredBlockNumber = 0;
         ImageTransferredBlocksStatus        = "";
         object[] value           = (object[])e.Parameters;
         string   ImageIdentifier = ASCIIEncoding.ASCII.GetString((byte[])value[0]);
         ImageSize           = (UInt32)value[1];
         ImageTransferStatus = ImageTransferStatus.TransferInitiated;
         List <GXDLMSImageActivateInfo> list = new List <GXDLMSImageActivateInfo>(ImageActivateInfo);
         GXDLMSImageActivateInfo        item = new GXDLMSImageActivateInfo();
         item.Size           = ImageSize;
         item.Identification = ImageIdentifier;
         list.Add(item);
         ImageActivateInfo = list.ToArray();
         StringBuilder sb = new StringBuilder((int)ImageSize);
         for (uint pos = 0; pos < ImageSize; ++pos)
         {
             sb.Append('0');
         }
         ImageTransferredBlocksStatus = sb.ToString();
         return(new byte[] { 0 });
     }
     //Image block transfer
     else if (e.Index == 2)
     {
         object[] value      = (object[])e.Parameters;
         uint     imageIndex = (uint)value[0];
         char[]   tmp        = ImageTransferredBlocksStatus.ToCharArray();
         tmp[(int)imageIndex]                = '1';
         ImageTransferredBlocksStatus        = new string(tmp);
         ImageFirstNotTransferredBlockNumber = imageIndex + 1;
         ImageData[imageIndex]               = (byte[])value[1];
         ImageTransferStatus = ImageTransferStatus.TransferInitiated;
         return(new byte[] { 0 });
     }
     //Image verify
     else if (e.Index == 3)
     {
         ImageTransferStatus = ImageTransferStatus.VerificationInitiated;
         //Check that size match.
         int size = 0;
         foreach (KeyValuePair <uint, byte[]> it in ImageData)
         {
             size += it.Value.Length;
         }
         if (size != ImageSize)
         {
             //Return HW error.
             ImageTransferStatus = ImageTransferStatus.VerificationFailed;
             throw new Exception("Invalid image size.");
         }
         ImageTransferStatus = ImageTransferStatus.VerificationSuccessful;
         return(new byte[] { 0 });
     }
     //Image activate.
     else if (e.Index == 4)
     {
         ImageTransferStatus = ImageTransferStatus.ActivationSuccessful;
         return(new byte[] { 0 });
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
         return(null);
     }
 }
Пример #51
0
 private void OnConfigurationChanged(Activity sender, ValueEventArgs<Configuration> args)
 {
     var drawerToggle = _listener as ActionBarDrawerToggle;
     if (drawerToggle != null)
         drawerToggle.OnConfigurationChanged(args.Value);
 }
Пример #52
0
 /// <summary>
 /// Raises the <see cref="Control.ControlRemoved"/> event.
 /// </summary>
 /// <param name="e">The <see cref="ValueEventArgs{T}"/> instance containing the event data.</param>
 protected override void OnControlRemoved(ValueEventArgs <Control> e)
 {
     base.OnControlRemoved(e);
     this.ScrollBarsNeedUpdate = true;
 }
Пример #53
0
 protected virtual void OnEvaluatingValueMember(ValueEventArgs<double?> e)
 {
     var handler = EvaluatingValueMember;
     handler?.Invoke(this, e);
 }
Пример #54
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         ShortAddress = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 3)
     {
         RcCoord = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 4)
     {
         PANId = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 5)
     {
         KeyTable.Clear();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[] tmp = (object[])v;
                 KeyTable.Add(new GXKeyValuePair <byte, byte[]>(Convert.ToByte(tmp[0]), (byte[])tmp[1]));
             }
         }
     }
     else if (e.Index == 6)
     {
         FrameCounter = Convert.ToUInt32(e.Value);
     }
     else if (e.Index == 7)
     {
         ToneMask = (string)e.Value;
     }
     else if (e.Index == 8)
     {
         TmrTtl = Convert.ToByte(e.Value);
     }
     else if (e.Index == 9)
     {
         MaxFrameRetries = Convert.ToByte(e.Value);
     }
     else if (e.Index == 10)
     {
         NeighbourTableEntryTtl = Convert.ToByte(e.Value);
     }
     else if (e.Index == 11)
     {
         List <GXDLMSNeighbourTable> list = new List <GXDLMSNeighbourTable>();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[]             tmp = (object[])v;
                 GXDLMSNeighbourTable it  = new GXDLMSNeighbourTable();
                 it.ShortAddress       = Convert.ToUInt16(tmp[0]);
                 it.Enabled            = Convert.ToBoolean(tmp[1]);
                 it.ToneMap            = (string)tmp[2];
                 it.Modulation         = (Modulation)Convert.ToInt32(tmp[3]);
                 it.TxGain             = Convert.ToSByte(tmp[4]);
                 it.TxRes              = (GainResolution)Convert.ToInt32(tmp[5]);
                 it.TxCoeff            = (string)tmp[6];
                 it.Lqi                = Convert.ToByte(tmp[7]);
                 it.PhaseDifferential  = Convert.ToSByte(tmp[8]);
                 it.TMRValidTime       = Convert.ToByte(tmp[9]);
                 it.NeighbourValidTime = Convert.ToByte(tmp[10]);
                 list.Add(it);
             }
         }
         NeighbourTable = list.ToArray();
     }
     else if (e.Index == 12)
     {
         HighPriorityWindowSize = Convert.ToByte(e.Value);
     }
     else if (e.Index == 13)
     {
         CscmFairnessLimit = Convert.ToByte(e.Value);
     }
     else if (e.Index == 14)
     {
         BeaconRandomizationWindowLength = Convert.ToByte(e.Value);
     }
     else if (e.Index == 15)
     {
         A = Convert.ToByte(e.Value);
     }
     else if (e.Index == 16)
     {
         K = Convert.ToByte(e.Value);
     }
     else if (e.Index == 17)
     {
         MinCwAttempts = Convert.ToByte(e.Value);
     }
     else if (e.Index == 18)
     {
         CenelecLegacyMode = Convert.ToByte(e.Value);
     }
     else if (e.Index == 19)
     {
         FccLegacyMode = Convert.ToByte(e.Value);
     }
     else if (e.Index == 20)
     {
         MaxBe = Convert.ToByte(e.Value);
     }
     else if (e.Index == 21)
     {
         MaxCsmaBackoffs = Convert.ToByte(e.Value);
     }
     else if (e.Index == 22)
     {
         MinBe = Convert.ToByte(e.Value);
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Пример #55
0
 private void AddSingleStepValues(IEnumerable<string> paths,
                                  Dictionary<string, BindingEvaluator> bindingEvaluators, object dataItem)
 {
     foreach (var path in paths)
     {
         var valueEventArgs = new ValueEventArgs<double?> { Item = dataItem, Path = path };
         OnEvaluatingValueMember(valueEventArgs);
         if (valueEventArgs.IsValueSet)
         {
             _values[path].Add(valueEventArgs.Value);
         }
         else
         {
             var value = bindingEvaluators[path].Eval(dataItem);
             _values[path].Add(value == null ? (double?)null : Convert.ToDouble(value));
         }
     }
 }
Пример #56
0
 byte[] IGXDLMSBase.Invoke(GXDLMSSettings settings, ValueEventArgs e)
 {
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Пример #57
0
 private void HubCommunicator_ImportReportNotification(object sender, ValueEventArgs<ImportReport> e)
 {
     Deployment.Current.Dispatcher.BeginInvoke(
          () =>
          {
              Report = e.Value;
          });
 }
Пример #58
0
        object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            switch (e.Index)
            {
            case 1:
                return(GXCommon.LogicalNameToBytes(LogicalName));

            case 2:
                if (CalendarName == null)
                {
                    return(null);
                }
                return(ASCIIEncoding.ASCII.GetBytes(CalendarName));

            case 3:
                return(Enabled);

            case 4:
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(4);
                data.SetUInt8((byte)DataType.UInt8);
                data.SetUInt8(Plan.DefaultTariffBand);

                data.SetUInt8((byte)DataType.Array);
                data.SetUInt8(2);
                GetSeason(Plan.WinterSeason, data);
                GetSeason(Plan.SummerSeason, data);

                GXCommon.SetData(null, data, DataType.BitString, Plan.WeeklyActivation);
                data.SetUInt8((byte)DataType.Array);
                if (Plan.SpecialDays == null)
                {
                    data.SetUInt8(0);
                }
                else
                {
                    data.SetUInt8((byte)Plan.SpecialDays.Length);
                    foreach (UInt16 it in Plan.SpecialDays)
                    {
                        data.SetUInt8((byte)DataType.UInt16);
                        data.SetUInt16(it);
                    }
                }
                return(data.Array());
            }

            case 5:
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Structure);
                //Count
                data.SetUInt8(2);
                if (ActivationTime == null)
                {
                    //Time
                    GXCommon.SetData(settings, data, DataType.OctetString, new GXTime());
                    //Date
                    GXCommon.SetData(settings, data, DataType.OctetString, new GXDate(DateTime.MinValue));
                }
                else
                {
                    //Time
                    GXCommon.SetData(settings, data, DataType.OctetString, new GXTime(ActivationTime));
                    //Date
                    GXCommon.SetData(settings, data, DataType.OctetString, new GXDate(ActivationTime));
                }
                return(data.Array());
            }
            }
            e.Error = ErrorCode.ReadWriteDenied;
            return(null);
        }
Пример #59
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         if (e.Value is byte[])
         {
             CalendarNameActive = ASCIIEncoding.ASCII.GetString((byte[])e.Value);
         }
         else
         {
             CalendarNameActive = Convert.ToString(e.Value);
         }
     }
     else if (e.Index == 3)
     {
         SeasonProfileActive = SetSeasonProfile(settings, e.Value);
     }
     else if (e.Index == 4)
     {
         WeekProfileTableActive = SetWeekProfileTable(settings, e.Value);
     }
     else if (e.Index == 5)
     {
         DayProfileTableActive = SetDayProfileTable(settings, e.Value);
     }
     else if (e.Index == 6)
     {
         if (e.Value is byte[])
         {
             CalendarNamePassive = ASCIIEncoding.ASCII.GetString((byte[])e.Value);
         }
         else
         {
             CalendarNamePassive = Convert.ToString(e.Value);
         }
     }
     else if (e.Index == 7)
     {
         SeasonProfilePassive = SetSeasonProfile(settings, e.Value);
     }
     else if (e.Index == 8)
     {
         WeekProfileTablePassive = SetWeekProfileTable(settings, e.Value);
     }
     else if (e.Index == 9)
     {
         DayProfileTablePassive = SetDayProfileTable(settings, e.Value);
     }
     else if (e.Index == 10)
     {
         if (e.Value is byte[])
         {
             Time = (GXDateTime)GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime);
         }
         else
         {
             Time = new GXDateTime(Convert.ToDateTime(e.Value));
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
 /* ----------------------------------------------------------------- */
 ///
 /// ShowMailView
 ///
 /// <summary>
 /// メール送信用画面を表示します。
 /// </summary>
 ///
 /// <param name="e">添付情報を保持するオブジェクト</param>
 ///
 /* ----------------------------------------------------------------- */
 public override void ShowMailView(ValueEventArgs <string> e)
 {
     Assert.That(System.IO.File.Exists(e.Value), Is.True);
 }