/// <summary>
 /// Adds the close request.
 /// </summary>
 /// <param name="reqFile">The req file.</param>
 private void AddCloseRequest(SmlFile reqFile)
 {
     var msg = new Core.Sml.Messages.Message()
     {
         TransactionId = new[] { (byte)(reqFile.Count + 1) },
         GroupNo = 0x00,
         CloseRequest = new Core.Sml.Messages.CloseRequest()
     };
     //var msg = SmlMessageFactory.CloseReq();
     //var transactionId = new byte[] { (byte)(reqFile.Count + 1) };
     //msg.TransactionId = new SmlOctetstring(transactionId);
     //msg.GroupNo = 0x00;
     reqFile.Add(msg);
 }
        /// <summary>
        /// Adds the set date time param request.
        /// </summary>
        /// <param name="reqFile">The req file.</param>
        /// <param name="param">The param.</param>
        private void AddSetDateTimeParamRequest(SmlFile reqFile, DateTimeParam param)
        {
            var timeToSet = param.Data.Value;
            var localOffset = (short)TimeZoneInfo.Local.BaseUtcOffset.TotalMinutes;
            var seasonTimeOffset = timeToSet.IsDaylightSavingTime() ? (short)60 : (short)0;

            var msg = new Core.Sml.Messages.Message()
            {
                TransactionId = new[] { (byte)(reqFile.Count + 1) },
                GroupNo = 0x00,
                SetProcParameterRequest = new Core.Sml.Messages.SetProcParameterRequest()
                {
                    TreePath = new List<Core.Obis.ObisId>()
                    {
                        new Core.Obis.ObisId((ulong)param.ObisCode)
                    },
                    Tree = new Tree(new Core.Obis.ObisId((ulong)param.ObisCode), new Time(timeToSet.ToUniversalTime())
                    {
                        Type = TimeType.LocalTimestamp,
                        LocalOffset = localOffset,
                        SeasonTimeOffset = seasonTimeOffset
                    })
                }
            };
            //var obisId = (ObisId)param.ObisCode;
            //var paramTreePath = new SmlTreePath(obisId);
            //var tree = new SmlTree { ParameterName = new SmlOctetstring(ObisUtil.GetBytes(obisId)) };
            //if (param.Data.HasValue == false)
            //{
            //    throw new ArgumentNullException("param");
            //}

            //var smlTime = new SmlTime { Type = SmlTime.Choice.LocalTimestamp, UtcTime = param.Data.Value };
            //tree.ParameterValue = new SmlProcParValue(smlTime);
            //var msg = SmlMessageFactory.SetProcParamReq(paramTreePath, tree);

            //var transactionId = new byte[] { (byte)(reqFile.Count + 1) };
            //msg.TransactionId = new SmlOctetstring(transactionId);
            //msg.GroupNo = 0x00;
            reqFile.Add(msg);
        }
        /// <summary>
        /// Adds the set unsigned param request.
        /// </summary>
        /// <param name="reqFile">The req file.</param>
        /// <param name="param">The param.</param>
        private void AddSetUnsignedParamRequest(SmlFile reqFile, UnsignedParam param)
        {
            var msg = new Core.Sml.Messages.Message()
            {
                TransactionId = new[] { (byte)(reqFile.Count + 1) },
                GroupNo = 0x00,
                SetProcParameterRequest = new Core.Sml.Messages.SetProcParameterRequest()
                {
                    TreePath = new List<Core.Obis.ObisId>()
                    {
                        new Core.Obis.ObisId((ulong)param.ObisCode)
                    },
                    Tree = new Tree(new Core.Obis.ObisId((ulong)param.ObisCode), param.Data.Value)
                }
            };
            //var obisId = (ObisId)param.ObisCode;
            //var paramTreePath = new SmlTreePath(obisId);
            //var tree = new SmlTree { ParameterName = new SmlOctetstring(ObisUtil.GetBytes(obisId)) };
            //if (param.Data.HasValue == false)
            //{
            //    throw new ArgumentNullException("param");
            //}

            //// TODO: check if casting is obsolete
            //if (obisId == ObisId.EdlActiveTariffAplus || obisId == ObisId.EdlActiveTariffAminus)
            //{
            //    tree.ParameterValue = new SmlProcParValue(new SmlUnsigned8((byte)param.Data.Value));
            //}
            //else
            //{
            //    tree.ParameterValue = new SmlProcParValue(new SmlUnsigned64(param.Data.Value));
            //}

            //var msg = SmlMessageFactory.SetProcParamReq(paramTreePath, tree);

            //var transactionId = new byte[] { (byte)(reqFile.Count + 1) };
            //msg.TransactionId = new SmlOctetstring(transactionId);
            //msg.GroupNo = 0x00;
            reqFile.Add(msg);
        }
        /// <summary>
        /// Adds the set integer param request.
        /// </summary>
        /// <param name="reqFile">The req file.</param>
        /// <param name="param">The param.</param>
        private void AddSetIntegerParamRequest(SmlFile reqFile, IntegerParam param)
        {
            var msg = new Core.Sml.Messages.Message()
            {
                TransactionId = new[] { (byte)(reqFile.Count + 1) },
                GroupNo = 0x00,
                SetProcParameterRequest = new Core.Sml.Messages.SetProcParameterRequest()
                {
                    TreePath = new List<Core.Obis.ObisId>()
                    {
                        new Core.Obis.ObisId((ulong)param.ObisCode)
                    },
                    Tree = new Tree(new Core.Obis.ObisId((ulong)param.ObisCode), param.Data.Value)

                }
            };

            //var obisId = (ObisId)param.ObisCode;
            //var paramTreePath = new SmlTreePath(obisId);
            //var tree = new SmlTree { ParameterName = new SmlOctetstring(ObisUtil.GetBytes(obisId)) };
            //if (param.Data.HasValue == false)
            //{
            //    throw new ArgumentNullException("param");
            //}

            //tree.ParameterValue = new SmlProcParValue(new SmlInteger64(param.Data.Value));
            //var msg = SmlMessageFactory.SetProcParamReq(paramTreePath, tree);

            //var transactionId = new byte[] { (byte)(reqFile.Count + 1) };
            //msg.TransactionId = new SmlOctetstring(transactionId);
            //msg.GroupNo = 0x00;
            reqFile.Add(msg);
        }
        /// <summary>
        /// Adds the get profile request.
        /// </summary>
        /// <param name="reqFile">The req file.</param>
        /// <param name="obisId">The obis id.</param>
        private void AddGetProfileRequest(SmlFile reqFile, ObisId obisId)
        {
            var msg = new Core.Sml.Messages.Message()
            {
                TransactionId = new[] { (byte)(reqFile.Count + 1) },
                GroupNo = 0x00,
                GetProfileListRequest = new Core.Sml.Messages.GetProfileListRequest()
                {
                    TreePath = new List<Core.Obis.ObisId>()
                    {
                        Core.Obis.ObisId.Parse(ObisUtil.GetBytes(obisId))
                    }
                }
            };

            //var paramTreePath = new SmlTreePath(obisId);
            //var msg = SmlMessageFactory.GetProfileListReq(paramTreePath);

            //var transactionId = new byte[] { (byte)(reqFile.Count + 1) };
            //msg.TransactionId = new SmlOctetstring(transactionId);
            //msg.GroupNo = 0x00;
            reqFile.Add(msg);
        }
        /// <summary>
        /// Adds the open request.
        /// </summary>
        /// <param name="reqFile">The req file.</param>
        private void AddOpenRequest(SmlFile reqFile)
        {
            var msg = new Core.Sml.Messages.Message
            {
                TransactionId = new byte[] { (byte)(reqFile.Count + 1) },
                GroupNo = 0x00,
                OpenRequest = new Core.Sml.Messages.OpenRequest()
                {
                    ClientId = this.clientId,
                    ReqFileId = new byte[] { this.requestIndex++ },
                }
            };
            //var msg = Sml.SmlMessageFactory.OpenReq(this.clientId, new byte[] { this.requestIndex++ });
            //var transactionId = new byte[] { (byte)(reqFile.Count + 1) };
            //msg.TransactionId = new SmlOctetstring(transactionId);
            //msg.GroupNo = 0x00;
            reqFile.Add(msg);

            if (this.requestIndex > 200)
            {
                this.requestIndex = 0;
            }
        }