public override 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);
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        /// <summary>
        ///     Get signed bytes.
        /// </summary>
        /// <returns>signed bytes</returns>
        public byte[] GetSignedBytes()
        {
            using (TlvWriter writer = new TlvWriter(new MemoryStream()))
            {
                writer.Write(FileBeginningMagicBytes);

                // get all but last tag
                for (int i = 0; i < Count - 1; i++)
                {
                    writer.WriteTag(this[i]);
                }
                return(((MemoryStream)writer.BaseStream).ToArray());
            }
        }
        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 (IntegerResource item in this.Children)
                    {
                        item.Serialise(childWriter, true);
                    }
                    writer.Write(TTlvTypeIdentifier.MultipleResources, identifier, steam.ToArray());
                }
            }
        }
Exemple #5
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);
        }
Exemple #6
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);
     }
 }