Ejemplo n.º 1
0
 public void SaveResources()
 {
     foreach (IResource resource in _Root.Children)
     {
         LWM2MResources lwm2mResources = resource as LWM2MResources;
         if (lwm2mResources != null)
         {
             string directory = Path.Combine(RESOURCES_CACHE, lwm2mResources.Name);
             if (!Directory.Exists(directory))
             {
                 Directory.CreateDirectory(directory);
             }
             foreach (LWM2MResource item in lwm2mResources.Children)
             {
                 string fileName = Path.Combine(directory, string.Concat(item.Name, ".tlv"));
                 using (Stream stream = File.Create(fileName, 4096))
                 {
                     TlvWriter writer = new TlvWriter(stream);
                     item.Serialise(writer);
                     stream.Flush();
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 private byte[] SerialiseObject(ObjectDefinition objectDefinition, Model.Object item, ushort objectInstanceID)
 {
     byte[] result = null;
     using (MemoryStream steam = new MemoryStream())
     {
         TlvWriter writer    = new TlvWriter(steam);
         byte[]    objectTLV = SerialiseObject(objectDefinition, item);
         int       length    = objectTLV.Length;
         writer.WriteType(TTlvTypeIdentifier.ObjectInstance, objectInstanceID, length);
         steam.Write(objectTLV, 0, length);
         result = steam.ToArray();
     }
     return(result);
 }
Ejemplo n.º 3
0
        private byte[] SerialiseObject(ObjectDefinition objectDefinition, Model.Object item)
        {
            byte[]       result      = null;
            TlvWriter    arrayWriter = null;
            MemoryStream arraystream = null;

            using (MemoryStream steam = new MemoryStream())
            {
                TlvWriter writer = new TlvWriter(steam);
                foreach (Property property in item.Properties)
                {
                    PropertyDefinition propertyDefinition = objectDefinition.GetProperty(property.PropertyID);
                    if (propertyDefinition != null)
                    {
                        if (propertyDefinition.IsCollection)
                        {
                            if (property.Values != null)
                            {
                                ushort identifier;
                                if (ushort.TryParse(propertyDefinition.PropertyID, out identifier))
                                {
                                    if (arrayWriter == null)
                                    {
                                        arraystream = new MemoryStream();
                                        arrayWriter = new TlvWriter(arraystream);
                                    }
                                    arraystream.SetLength(0);
                                    foreach (PropertyValue propertyValue in property.Values)
                                    {
                                        WriteValue(arrayWriter, TTlvTypeIdentifier.ResourceInstance, propertyDefinition.DataType, propertyValue.PropertyValueID, propertyValue.Value);
                                    }
                                    byte[] arrayItems = arraystream.ToArray();
                                    writer.Write(TTlvTypeIdentifier.MultipleResources, identifier, arrayItems);
                                }
                            }
                        }
                        else if (property.Value != null)
                        {
                            WriteValue(writer, TTlvTypeIdentifier.ResourceWithValue, propertyDefinition.DataType, propertyDefinition.PropertyID, property.Value.Value);
                        }
                    }
                }
                result = steam.ToArray();
            }
            return(result);
        }
Ejemplo n.º 4
0
        public override void Serialise(TlvWriter writer)
        {
            ushort identifier;
            if (ushort.TryParse(Name, out identifier))
            {
                using (MemoryStream steam = new MemoryStream())
                {
                    TlvWriter childWriter = new TlvWriter(steam);
                    foreach (DateTimeResource item in this.Children)
                    {
                        item.Serialise(childWriter, true);
                    }
                    writer.Write(TTlvTypeIdentifier.MultipleResources, identifier, steam.ToArray());
                }

            }
        }
Ejemplo n.º 5
0
 public override void Serialise(TlvWriter writer)
 {
     if (_Manufacturer != null)
         _Manufacturer.Serialise(writer);
     if (_ModelNumber != null)
         _ModelNumber.Serialise(writer);
     if (_SerialNumber != null)
         _SerialNumber.Serialise(writer);
     if (_FirmwareVersion != null)
         _FirmwareVersion.Serialise(writer);
     if (_AvailablePowerSources != null)
         _AvailablePowerSources.Serialise(writer);
     if (_PowerSourceVoltages != null)
         _PowerSourceVoltages.Serialise(writer);
     if (_PowerSourceCurrents != null)
         _PowerSourceCurrents.Serialise(writer);
     if (_BatteryLevel != null)
         _BatteryLevel.Serialise(writer);
     if (_MemoryFree != null)
         _MemoryFree.Serialise(writer);
     if (_ErrorCodes != null)
         _ErrorCodes.Serialise(writer);
     if (_CurrentTime != null)
         _CurrentTime.Serialise(writer);
     if (_UTCOffset != null)
         _UTCOffset.Serialise(writer);
     if (_Timezone != null)
         _Timezone.Serialise(writer);
     if (_SupportedBindingandModes != null)
         _SupportedBindingandModes.Serialise(writer);
     if (_DeviceType != null)
         _DeviceType.Serialise(writer);
     if (_HardwareVersion != null)
         _HardwareVersion.Serialise(writer);
     if (_SoftwareVersion != null)
         _SoftwareVersion.Serialise(writer);
     if (_BatteryStatus != null)
         _BatteryStatus.Serialise(writer);
     if (_MemoryTotal != null)
         _MemoryTotal.Serialise(writer);
 }
 public override void Serialise(TlvWriter writer)
 {
     if (_SMSTxCounter != null)
         _SMSTxCounter.Serialise(writer);
     if (_SMSRxCounter != null)
         _SMSRxCounter.Serialise(writer);
     if (_TxData != null)
         _TxData.Serialise(writer);
     if (_RxData != null)
         _RxData.Serialise(writer);
     if (_MaxMessageSize != null)
         _MaxMessageSize.Serialise(writer);
     if (_AverageMessageSize != null)
         _AverageMessageSize.Serialise(writer);
 }
Ejemplo n.º 7
0
 public override void Serialise(TlvWriter writer)
 {
     if (_Latitude != null)
         _Latitude.Serialise(writer);
     if (_Longitude != null)
         _Longitude.Serialise(writer);
     if (_Altitude != null)
         _Altitude.Serialise(writer);
     if (_Uncertainty != null)
         _Uncertainty.Serialise(writer);
     if (_Velocity != null)
         _Velocity.Serialise(writer);
     if (_Timestamp != null)
         _Timestamp.Serialise(writer);
 }
Ejemplo n.º 8
0
        private void WriteValue(TlvWriter writer, TTlvTypeIdentifier typeIdentifier, TPropertyDataType dataType, string instanceID, string value)
        {
            ushort identifier;

            if (ushort.TryParse(instanceID, out identifier))
            {
                switch (dataType)
                {
                case TPropertyDataType.NotSet:
                    break;

                case TPropertyDataType.String:
                    writer.Write(typeIdentifier, identifier, value);
                    break;

                case TPropertyDataType.Boolean:
                    bool boolValue;
                    if (bool.TryParse(value, out boolValue))
                    {
                        writer.Write(typeIdentifier, identifier, boolValue);
                    }
                    break;

                case TPropertyDataType.Integer:
                    long longValue;
                    if (long.TryParse(value, out longValue))
                    {
                        writer.Write(typeIdentifier, identifier, longValue);
                    }
                    break;

                case TPropertyDataType.Float:
                    double doubleValue;
                    if (double.TryParse(value, out doubleValue))
                    {
                        writer.Write(typeIdentifier, identifier, doubleValue);
                    }
                    break;

                case TPropertyDataType.DateTime:
                    try
                    {
                        DateTime dateTimeValue = System.Xml.XmlConvert.ToDateTime(value, System.Xml.XmlDateTimeSerializationMode.Utc);
                        writer.Write(typeIdentifier, identifier, dateTimeValue);
                    }
                    catch
                    {
                    }
                    break;

                case TPropertyDataType.Opaque:
                    byte[] buffer = Convert.FromBase64String(value);
                    writer.Write(typeIdentifier, identifier, buffer);
                    break;

                case TPropertyDataType.Object:
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 9
0
 private byte[] SerialiseObject(ObjectDefinition objectDefinition, Model.Object item, ushort objectInstanceID)
 {
     byte[] result = null;
     using (MemoryStream steam = new MemoryStream())
     {
         TlvWriter writer = new TlvWriter(steam);
         byte[] objectTLV = SerialiseObject(objectDefinition, item);
         int length = objectTLV.Length;
         writer.WriteType(TTlvTypeIdentifier.ObjectInstance, objectInstanceID, length);
         steam.Write(objectTLV, 0, length);
         result = steam.ToArray();
     }
     return result;
 }
 public override void Serialise(TlvWriter writer)
 {
     if (_ObjectID != null)
         _ObjectID.Serialise(writer);
     if (_ObjectInstanceID != null)
         _ObjectInstanceID.Serialise(writer);
     if (_ACLs != null)
         _ACLs.Serialise(writer);
     if (_AccessControlOwner != null)
         _AccessControlOwner.Serialise(writer);
 }
Ejemplo n.º 11
0
 private byte[] SerialiseObject(ITlvSerialisable item)
 {
     byte[] result = null;
     using (MemoryStream steam = new MemoryStream())
     {
         TlvWriter writer = new TlvWriter(steam);
         item.Serialise(writer);
         result = steam.ToArray();
     }
     return result;
 }
 public override void Serialise(TlvWriter writer)
 {
     if (_InterfaceName != null)
         _InterfaceName.Serialise(writer);
     if (_Enable != null)
         _Enable.Serialise(writer);
     if (_RadioEnabled != null)
         _RadioEnabled.Serialise(writer);
     if (_Status != null)
         _Status.Serialise(writer);
     if (_BSSID != null)
         _BSSID.Serialise(writer);
     if (_SSID != null)
         _SSID.Serialise(writer);
     if (_BroadcastSSID != null)
         _BroadcastSSID.Serialise(writer);
     if (_BeaconEnabled != null)
         _BeaconEnabled.Serialise(writer);
     if (_Mode != null)
         _Mode.Serialise(writer);
     if (_Channel != null)
         _Channel.Serialise(writer);
     if (_SupportedChannels != null)
         _SupportedChannels.Serialise(writer);
     if (_ChannelsInUse != null)
         _ChannelsInUse.Serialise(writer);
     if (_RegulatoryDomain != null)
         _RegulatoryDomain.Serialise(writer);
     if (_Standard != null)
         _Standard.Serialise(writer);
     if (_AuthenticationMode != null)
         _AuthenticationMode.Serialise(writer);
     if (_EncryptionMode != null)
         _EncryptionMode.Serialise(writer);
     if (_WPAPreSharedKey != null)
         _WPAPreSharedKey.Serialise(writer);
     if (_WPAKeyPhrase != null)
         _WPAKeyPhrase.Serialise(writer);
     if (_WEPEncryptionType != null)
         _WEPEncryptionType.Serialise(writer);
     if (_WEPKeyIndex != null)
         _WEPKeyIndex.Serialise(writer);
     if (_WEPKeyPhrase != null)
         _WEPKeyPhrase.Serialise(writer);
     if (_WEPKey1 != null)
         _WEPKey1.Serialise(writer);
     if (_WEPKey2 != null)
         _WEPKey2.Serialise(writer);
     if (_WEPKey3 != null)
         _WEPKey3.Serialise(writer);
     if (_WEPKey4 != null)
         _WEPKey4.Serialise(writer);
     if (_RADIUSServer != null)
         _RADIUSServer.Serialise(writer);
     if (_RADIUSServerPort != null)
         _RADIUSServerPort.Serialise(writer);
     if (_RADIUSSecret != null)
         _RADIUSSecret.Serialise(writer);
     if (_WMMSupported != null)
         _WMMSupported.Serialise(writer);
     if (_WMMEnabled != null)
         _WMMEnabled.Serialise(writer);
     if (_MACControlEnabled != null)
         _MACControlEnabled.Serialise(writer);
     if (_MACAddressList != null)
         _MACAddressList.Serialise(writer);
     if (_TotalBytesSent != null)
         _TotalBytesSent.Serialise(writer);
     if (_TotalBytesReceived != null)
         _TotalBytesReceived.Serialise(writer);
     if (_TotalPacketsSent != null)
         _TotalPacketsSent.Serialise(writer);
     if (_TotalPacketsReceived != null)
         _TotalPacketsReceived.Serialise(writer);
     if (_TransmitErrors != null)
         _TransmitErrors.Serialise(writer);
     if (_ReceiveErrors != null)
         _ReceiveErrors.Serialise(writer);
     if (_UnicastPacketsSent != null)
         _UnicastPacketsSent.Serialise(writer);
     if (_UnicastPacketsReceived != null)
         _UnicastPacketsReceived.Serialise(writer);
     if (_MulticastPacketsSent != null)
         _MulticastPacketsSent.Serialise(writer);
     if (_MulticastPacketsReceived != null)
         _MulticastPacketsReceived.Serialise(writer);
     if (_BroadcastPacketsSent != null)
         _BroadcastPacketsSent.Serialise(writer);
     if (_BroadcastPacketsReceived != null)
         _BroadcastPacketsReceived.Serialise(writer);
     if (_DiscardPacketsSent != null)
         _DiscardPacketsSent.Serialise(writer);
     if (_DiscardPacketsReceived != null)
         _DiscardPacketsReceived.Serialise(writer);
     if (_UnknownPacketsReceived != null)
         _UnknownPacketsReceived.Serialise(writer);
     if (_VendorSpecificExtensions != null)
         _VendorSpecificExtensions.Serialise(writer);
 }
Ejemplo n.º 13
0
 public void Serialise(TlvWriter writer)
 {
     if (!string.IsNullOrEmpty(ServerURI))
     {
         writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.ServerURI, ServerURI);
     }
     writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.BootstrapServer, BootstrapServer);
     writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.SecurityMode, (int)SecurityMode);
     if (ClientPublicKey != null)
     {
         writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.ClientPublicKey, ClientPublicKey);
     }
     if (ServerPublicKey != null)
     {
         writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.ServerPublicKey, ServerPublicKey);
     }
     if (SecretKey != null)
     {
         writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.SecretKey, SecretKey);
     }
     if (SMSSecurityMode != TSMSSecurityMode.NotSet)
         writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.SMSSecurityMode, (int)SMSSecurityMode);
     if (SMSBindingKeyParameters != null)
     {
         writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.SMSBindingKeyParameters, SMSBindingKeyParameters);
     }
     if (SMSBindingSecretKeys != null)
     {
         writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.SMSBindingSecretKeys, SMSBindingSecretKeys);
     }
     if (ServerSMSNumber.HasValue)
     {
         writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.ServerSMSNumber, ServerSMSNumber.Value);
     }
     if (ShortServerID > 0)
     {
         writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.ShortServerID, ShortServerID);
     }
     if (ClientHoldOffTime.HasValue)
     {
         writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.ClientHoldOffTime, ClientHoldOffTime.Value);
     }
 }
Ejemplo n.º 14
0
 public override void Serialise(TlvWriter writer)
 {
     Serialise(writer, false);
 }
 public override void Serialise(TlvWriter writer)
 {
     if (_NetworkBearer != null)
         _NetworkBearer.Serialise(writer);
     if (_AvailableNetworkBearers != null)
         _AvailableNetworkBearers.Serialise(writer);
     if (_RadioSignalStrength != null)
         _RadioSignalStrength.Serialise(writer);
     if (_LinkQuality != null)
         _LinkQuality.Serialise(writer);
     if (_IPAddresses != null)
         _IPAddresses.Serialise(writer);
     if (_RouterIPAddresses != null)
         _RouterIPAddresses.Serialise(writer);
     if (_LinkUtilization != null)
         _LinkUtilization.Serialise(writer);
     if (_APNs != null)
         _APNs.Serialise(writer);
     if (_CellID != null)
         _CellID.Serialise(writer);
     if (_SMNC != null)
         _SMNC.Serialise(writer);
     if (_SMCC != null)
         _SMCC.Serialise(writer);
 }
Ejemplo n.º 16
0
 public override void Serialise(TlvWriter writer)
 {
     if (_ShortServerID != null)
         _ShortServerID.Serialise(writer);
     if (_Lifetime != null)
         _Lifetime.Serialise(writer);
     if (_DefaultMinimumPeriod != null)
         _DefaultMinimumPeriod.Serialise(writer);
     if (_DefaultMaximumPeriod != null)
         _DefaultMaximumPeriod.Serialise(writer);
     if (_DisableTimeout != null)
         _DisableTimeout.Serialise(writer);
     if (_NotificationStoringWhenDisabledorOffline != null)
         _NotificationStoringWhenDisabledorOffline.Serialise(writer);
     if (_Binding != null)
         _Binding.Serialise(writer);
 }
Ejemplo n.º 17
0
 protected override void DoGet(CoapExchange exchange)
 {
     Response response;
     if (exchange.Request.Observe.HasValue && exchange.Request.Observe.Value == 0)
     {
         response = Response.CreateResponse(exchange.Request, StatusCode.Content);
         response.MaxAge = 86400;
     }
     else
         response = Response.CreateResponse(exchange.Request, StatusCode.Content);
     using (MemoryStream steam = new MemoryStream())
     {
         TlvWriter writer = new TlvWriter(steam);
         this.Serialise(writer);
         response.Payload = steam.ToArray();
     }
     response.ContentType = TlvConstant.CONTENT_TYPE_TLV;
     exchange.Respond(response);
 }
 public override void Serialise(TlvWriter writer)
 {
     if (_Package != null)
         _Package.Serialise(writer);
     if (_PackageURI != null)
         _PackageURI.Serialise(writer);
     if (_State != null)
         _State.Serialise(writer);
     if (_UpdateSupportedObjects != null)
         _UpdateSupportedObjects.Serialise(writer);
     if (_UpdateResult != null)
         _UpdateResult.Serialise(writer);
     if (_PackageName != null)
         _PackageName.Serialise(writer);
     if (_PackageVersion != null)
         _PackageVersion.Serialise(writer);
 }
 public override void Serialise(TlvWriter writer)
 {
     if (_Property != null)
         _Property.Serialise(writer);
     if (_Group != null)
         _Group.Serialise(writer);
     if (_Description != null)
         _Description.Serialise(writer);
     if (_Attached != null)
         _Attached.Serialise(writer);
     if (_Enabled != null)
         _Enabled.Serialise(writer);
     if (_NotifyEn != null)
         _NotifyEn.Serialise(writer);
 }
Ejemplo n.º 20
0
 public void Serialise(TlvWriter writer, bool resourceInstance)
 {
     ushort identifier;
     if (ushort.TryParse(Name, out identifier))
     {
         TTlvTypeIdentifier typeIdentifier = TTlvTypeIdentifier.ResourceWithValue;
         if (resourceInstance)
             typeIdentifier = TTlvTypeIdentifier.ResourceInstance;
         writer.Write(typeIdentifier, identifier, Value);
     }
 }
Ejemplo n.º 21
0
 public virtual void Serialise(TlvWriter writer)
 {
 }
Ejemplo n.º 22
0
 private byte[] SerialiseObject(ITlvSerialisable item, ushort objectInstanceID)
 {
     byte[] result = null;
     using (MemoryStream steam = new MemoryStream())
     {
         TlvWriter writer = new TlvWriter(steam);
         item.Serialise(writer);
         byte[] objectTLV = steam.ToArray();
         int length = (int)steam.Length;
         steam.SetLength(0);
         writer.WriteType(TTlvTypeIdentifier.ObjectInstance, objectInstanceID, length);
         steam.Write(objectTLV, 0, length);
         result = steam.ToArray();
     }
     return result;
 }
Ejemplo n.º 23
0
        protected override void DoGet(CoapExchange exchange)
        {
            Response response = null;

            if (exchange.Request.Observe.HasValue && exchange.Request.Observe.Value == 0)
            {
                response = Response.CreateResponse(exchange.Request, StatusCode.Content);
                response.MaxAge = 86400;
            }
            else
                response = Response.CreateResponse(exchange.Request, StatusCode.Content);

            using (MemoryStream steam = new MemoryStream())
            {
                using (MemoryStream itemSteam = new MemoryStream())
                {
                    TlvWriter writer = new TlvWriter(steam);
                    TlvWriter itemWriter = new TlvWriter(itemSteam);

                    foreach (LWM2MResource item in Children)
                    {
                        if (ModifiedResource == null || ModifiedResource == item)
                        {
                            itemSteam.SetLength(0);
                            ushort identifier = ushort.Parse(item.Name);
                            item.Serialise(itemWriter);
                            writer.Write(TTlvTypeIdentifier.ObjectInstance, identifier, itemSteam.ToArray());
                        }
                    }
                    ModifiedResource = null;
                    response.Payload = steam.ToArray();
                }
            }
            response.ContentType = TlvConstant.CONTENT_TYPE_TLV;
            exchange.Respond(response);
        }
Ejemplo n.º 24
0
 private byte[] SerialiseObject(ObjectDefinition objectDefinition, Model.Object item)
 {
     byte[] result = null;
     TlvWriter arrayWriter = null;
     MemoryStream arraystream = null;
     using (MemoryStream steam = new MemoryStream())
     {
         TlvWriter writer = new TlvWriter(steam);
         foreach (Property property in item.Properties)
         {
             PropertyDefinition propertyDefinition = objectDefinition.GetProperty(property.PropertyID);
             if (propertyDefinition != null)
             {
                 if (propertyDefinition.IsCollection)
                 {
                     if (property.Values != null)
                     {
                         ushort identifier;
                         if (ushort.TryParse(propertyDefinition.PropertyID, out identifier))
                         {
                             if (arrayWriter == null)
                             {
                                 arraystream = new MemoryStream();
                                 arrayWriter = new TlvWriter(arraystream);
                             }
                             arraystream.SetLength(0);
                             foreach (PropertyValue propertyValue in property.Values)
                             {
                                 WriteValue(arrayWriter, TTlvTypeIdentifier.ResourceInstance, propertyDefinition.DataType, propertyValue.PropertyValueID, propertyValue.Value);
                             }
                             byte[] arrayItems = arraystream.ToArray();
                             writer.Write(TTlvTypeIdentifier.MultipleResources, identifier, arrayItems);
                         }
                     }
                 }
                 else if (property.Value != null)
                 {
                     WriteValue(writer, TTlvTypeIdentifier.ResourceWithValue, propertyDefinition.DataType, propertyDefinition.PropertyID, property.Value.Value);
                 }
             }
         }
         result = steam.ToArray();
     }
     return result;
 }
Ejemplo n.º 25
0
        /*

        public bool NotificationStoringWhenOffline { get; set; }
        public TBindingMode Binding { get; set; }
        */
        public void Serialise(TlvWriter writer)
        {
            writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.ShortServerID, ShortServerID);
            if (Lifetime > 0)
            {
                writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.Lifetime, Lifetime);
            }
            if (DefaultMinimumPeriod.HasValue)
            {
                writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.DefaultMinimumPeriod, DefaultMinimumPeriod.Value);
            }
            if (DefaultMaximumPeriod.HasValue)
            {
                writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.DefaultMaximumPeriod, DefaultMaximumPeriod.Value);
            }
            if (DisableTimeout.HasValue)
            {
                writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.DisableTimeout, DisableTimeout.Value);
            }
            writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.NotificationStoringWhenOffline, NotificationStoringWhenOffline);
            string binding = null;
            switch (Binding)
            {
                case TBindingMode.NotSet:
                    break;
                case TBindingMode.UDP:
                    binding = "U";
                    break;
                case TBindingMode.QueuedUDP:
                    binding = "UQ";
                    break;
                case TBindingMode.SMS:
                    binding = "S";
                    break;
                case TBindingMode.QueuedSMS:
                    binding = "SQ";
                    break;
                case TBindingMode.UDPSMS:
                    binding = "US";
                    break;
                case TBindingMode.QueuedUDPSMS:
                    binding = "UQS";
                    break;
                default:
                    break;
            }
            writer.Write(TTlvTypeIdentifier.ResourceWithValue, (ushort)ResourceID.Binding, binding);
        }
Ejemplo n.º 26
0
        private void WriteValue(TlvWriter writer, TTlvTypeIdentifier typeIdentifier, TPropertyDataType dataType, string instanceID, string value)
        {
            ushort identifier;
            if (ushort.TryParse(instanceID, out identifier))
            {

                switch (dataType)
                {
                    case TPropertyDataType.NotSet:
                        break;
                    case TPropertyDataType.String:
                        writer.Write(typeIdentifier, identifier, value);
                        break;
                    case TPropertyDataType.Boolean:
                        bool boolValue;
                        if (bool.TryParse(value, out boolValue))
                            writer.Write(typeIdentifier, identifier, boolValue);
                        break;
                    case TPropertyDataType.Integer:
                        long longValue;
                        if (long.TryParse(value, out longValue))
                            writer.Write(typeIdentifier, identifier, longValue);
                        break;
                    case TPropertyDataType.Float:
                        double doubleValue;
                        if (double.TryParse(value, out doubleValue))
                            writer.Write(typeIdentifier, identifier, doubleValue);
                        break;
                    case TPropertyDataType.DateTime:
                        try
                        {
                            DateTime dateTimeValue = System.Xml.XmlConvert.ToDateTime(value, System.Xml.XmlDateTimeSerializationMode.Utc);
                            writer.Write(typeIdentifier, identifier, dateTimeValue);
                        }
                        catch
                        {

                        }
                        break;
                    case TPropertyDataType.Opaque:
                        byte[] buffer = Convert.FromBase64String(value);
                        writer.Write(typeIdentifier, identifier, buffer);
                        break;
                    case TPropertyDataType.Object:
                        break;
                    default:
                        break;
                }
            }
        }
Ejemplo n.º 27
0
 public override void Serialise(TlvWriter writer)
 {
     if (_CommandID != null)
         _CommandID.Serialise(writer);
     if (_CommandTypeID != null)
         _CommandTypeID.Serialise(writer);
     if (_Status != null)
         _Status.Serialise(writer);
     if (_StatusCode != null)
         _StatusCode.Serialise(writer);
     if (_ParameterName != null)
         _ParameterName.Serialise(writer);
     if (_ParameterValue != null)
         _ParameterValue.Serialise(writer);
     if (_ResultContentType != null)
         _ResultContentType.Serialise(writer);
     if (_ResultContent != null)
         _ResultContent.Serialise(writer);
     if (_ErrorContentType != null)
         _ErrorContentType.Serialise(writer);
     if (_ErrorContent != null)
         _ErrorContent.Serialise(writer);
 }
Ejemplo n.º 28
0
        public void SaveResources()
        {
            foreach (IResource resource in _Root.Children)
            {
                LWM2MResources lwm2mResources = resource as LWM2MResources;
                if (lwm2mResources != null)
                {
                    string directory = Path.Combine(RESOURCES_CACHE, lwm2mResources.Name);
                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }
                    foreach (LWM2MResource item in lwm2mResources.Children)
                    {
                        string fileName = Path.Combine(directory, string.Concat(item.Name, ".tlv"));
                        using(Stream stream = File.Create(fileName,4096))
                        {
                            TlvWriter writer = new TlvWriter(stream);
                            item.Serialise(writer);
                            stream.Flush();
                        }
                    }

                }
            }
        }
Ejemplo n.º 29
0
 public override void Serialise(TlvWriter writer)
 {
     if (_DeviceID != null)
         _DeviceID.Serialise(writer);
     if (_ParentID != null)
         _ParentID.Serialise(writer);
     if (_DeviceType != null)
         _DeviceType.Serialise(writer);
     if (_Name != null)
         _Name.Serialise(writer);
     if (_Description != null)
         _Description.Serialise(writer);
     if (_FCAP != null)
         _FCAP.Serialise(writer);
     if (_TenantID != null)
         _TenantID.Serialise(writer);
     if (_TenantChallenge != null)
         _TenantChallenge.Serialise(writer);
     if (_HashIterations != null)
         _HashIterations.Serialise(writer);
     if (_TenantHash != null)
         _TenantHash.Serialise(writer);
     if (_Status != null)
         _Status.Serialise(writer);
 }
Ejemplo n.º 30
0
 public override void Serialise(TlvWriter writer)
 {
     if (_URL != null)
         _URL.Serialise(writer);
     if (_CustomerKey != null)
         _CustomerKey.Serialise(writer);
     if (_CustomerSecret != null)
         _CustomerSecret.Serialise(writer);
     if (_RememberMeToken != null)
         _RememberMeToken.Serialise(writer);
     if (_RememberMeTokenExpiry != null)
         _RememberMeTokenExpiry.Serialise(writer);
 }
 public override void Serialise(TlvWriter writer)
 {
     if (_LWM2MServerURI != null)
         _LWM2MServerURI.Serialise(writer);
     if (_BootstrapServer != null)
         _BootstrapServer.Serialise(writer);
     if (_SecurityMode != null)
         _SecurityMode.Serialise(writer);
     if (_PublicKeyorIdentity != null)
         _PublicKeyorIdentity.Serialise(writer);
     if (_ServerPublicKeyorIdentity != null)
         _ServerPublicKeyorIdentity.Serialise(writer);
     if (_SecretKey != null)
         _SecretKey.Serialise(writer);
     if (_SMSSecurityMode != null)
         _SMSSecurityMode.Serialise(writer);
     if (_SMSBindingKeyParameters != null)
         _SMSBindingKeyParameters.Serialise(writer);
     if (_SMSBindingSecretKeys != null)
         _SMSBindingSecretKeys.Serialise(writer);
     if (_LWM2MServerSMSNumber != null)
         _LWM2MServerSMSNumber.Serialise(writer);
     if (_ShortServerID != null)
         _ShortServerID.Serialise(writer);
     if (_ClientHoldOffTime != null)
         _ClientHoldOffTime.Serialise(writer);
 }