示例#1
0
 /// <summary>
 /// Get last read time.
 /// </summary>
 private static DateTime GetReadTime(GXObject obj)
 {
     int index = GetAttributeIndex(obj, 4);
     if (index == -1)
     {
         return DateTime.MinValue;
     }
     return obj.Attributes[index].Read;
 }
示例#2
0
 /// <summary>
 /// Get capture period of the profile generic.
 /// </summary>
 private static int GetCapturePeriod(GXObject obj)
 {
     int index = GetAttributeIndex(obj, 4);
     if (index == -1)
     {
         return -1;
     }
     return Convert.ToInt32(obj.Attributes[index].Value);
 }
示例#3
0
 private static int GetAttributeIndex(GXObject obj, int index)
 {
     int index2 = 0;
     foreach (GXAttribute it in obj.Attributes)
     {
         if (it.Index == index)
         {
             return index2;
         }
         ++index2;
     }
     return -1;
 }
示例#4
0
 /// <summary>
 /// Is profile generic object sorted using date time.
 /// </summary>
 private static bool IsSortedByDateTime(GXObject obj)
 {
     int index = GetAttributeIndex(obj, 3);
     if (index == -1)
     {
         return false;
     }
     try
     {
         GXArray tmp = GXDLMSTranslator.XmlToValue(obj.Attributes[index].Value) as GXArray;
         if (tmp != null)
         {
             //If interface type is clock.
             return (UInt16)((GXStructure)tmp[0])[0] == 8;
         }
     }
     catch(Exception)
     {
         //It's OK if this fails.
     }
     return false;
 }
示例#5
0
        public ActionResult <UpdateDeviceResponse> Post(UpdateDevice request)
        {
            if (request.Device.TemplateId == 0)
            {
                return(BadRequest("Device template ID is unknown."));
            }
            bool newDevice = request.Device.Id == 0;

            if (request.Device.DeviceSystemTitle != null)
            {
                request.Device.DeviceSystemTitle = request.Device.DeviceSystemTitle.Replace(" ", "");
            }
            if (request.Device.AuthenticationKey != null)
            {
                request.Device.AuthenticationKey = request.Device.AuthenticationKey.Replace(" ", "");
            }
            if (request.Device.BlockCipherKey != null)
            {
                request.Device.BlockCipherKey = request.Device.BlockCipherKey.Replace(" ", "");
            }
            if (newDevice)
            {
                DateTime now = DateTime.Now;
                request.Device.Generation = now;
                //Add new DC.
                List <GXObject> tmp = request.Device.Objects;
                request.Device.Objects    = null;
                request.Device.Generation = now;
                host.Connection.Insert(GXInsertArgs.Insert(request.Device));

                //Add default objects.
                GXSelectArgs arg = GXSelectArgs.SelectAll <GXObjectTemplate>(q => q.DeviceTemplateId == request.Device.TemplateId && q.Removed == DateTime.MinValue);
                arg.Columns.Add <GXAttributeTemplate>();
                arg.Joins.AddLeftJoin <GXObjectTemplate, GXAttributeTemplate>(o => o.Id, a => a.ObjectTemplateId);
                arg.Where.And <GXAttributeTemplate>(q => q.Removed == DateTime.MinValue);
                List <GXObjectTemplate> l = host.Connection.Select <GXObjectTemplate>(arg);
                foreach (GXObjectTemplate it in l)
                {
                    GXObject obj = new GXObject()
                    {
                        TemplateId  = it.Id,
                        Generation  = now,
                        DeviceId    = request.Device.Id,
                        ObjectType  = it.ObjectType,
                        Name        = it.Name,
                        LogicalName = it.LogicalName,
                        ShortName   = it.ShortName,
                    };
                    host.Connection.Insert(GXInsertArgs.Insert(obj));
                    foreach (GXAttributeTemplate ait in it.Attributes)
                    {
                        GXAttribute a = new GXAttribute();
                        a.ObjectId       = obj.Id;
                        a.Index          = ait.Index;
                        a.TemplateId     = ait.Id;
                        a.AccessLevel    = ait.AccessLevel;
                        a.DataType       = ait.DataType;
                        a.UIDataType     = ait.UIDataType;
                        a.Generation     = now;
                        a.ExpirationTime = ait.ExpirationTime;
                        obj.Attributes.Add(a);
                    }
                    ;
                    host.Connection.Insert(GXInsertArgs.InsertRange(obj.Attributes));
                }
                host.SetChange(TargetType.ObjectTemplate, DateTime.Now);
            }
            else
            {
                request.Device.Updated = DateTime.Now;
                host.Connection.Update(GXUpdateArgs.Update(request.Device));
                host.SetChange(TargetType.DeviceTemplate, DateTime.Now);
            }
            return(new UpdateDeviceResponse()
            {
                DeviceId = request.Device.Id
            });
        }
示例#6
0
 private static int GetBufferIndex(GXObject obj)
 {
     return GetAttributeIndex(obj, 2);
 }
        public ActionResult <AddTestDeviceResponse> Post(AddTestDevice request)
        {
            if (request.Device.TemplateId == 0)
            {
                return(BadRequest("Device template ID is unknown."));
            }
            if (request.Device.DeviceSystemTitle != null)
            {
                request.Device.DeviceSystemTitle = request.Device.DeviceSystemTitle.Replace(" ", "");
            }
            if (request.Device.AuthenticationKey != null)
            {
                request.Device.AuthenticationKey = request.Device.AuthenticationKey.Replace(" ", "");
            }
            if (request.Device.BlockCipherKey != null)
            {
                request.Device.BlockCipherKey = request.Device.BlockCipherKey.Replace(" ", "");
            }
            DateTime now = DateTime.Now;

            //Add new DC.
            request.Device.Generation = now;
            //We are accessing meters using serial number when test mode is used.
            request.Device.HDLCAddressing = ManufacturerSettings.HDLCAddressType.SerialNumber;
            request.Device.LogicalAddress = request.Index;
            for (UInt16 pos = 0; pos != request.Count; ++pos)
            {
                request.Device.Objects = null;
                request.Device.Name    = "Test_" + request.Device.LogicalAddress;
                ++request.Device.LogicalAddress;
                request.Device.Id = 0;

                host.Connection.Insert(GXInsertArgs.Insert(request.Device));
                //Add default objects.
                GXSelectArgs arg = GXSelectArgs.SelectAll <GXObjectTemplate>(q => q.DeviceTemplateId == request.Device.TemplateId);
                arg.Columns.Add <GXAttributeTemplate>();
                arg.Joins.AddLeftJoin <GXObjectTemplate, GXAttributeTemplate>(o => o.Id, a => a.ObjectTemplateId);
                List <GXObjectTemplate> l = host.Connection.Select <GXObjectTemplate>(arg);
                foreach (GXObjectTemplate it in l)
                {
                    GXObject obj = new GXObject()
                    {
                        TemplateId  = it.Id,
                        Generation  = now,
                        DeviceId    = request.Device.Id,
                        ObjectType  = it.ObjectType,
                        Name        = it.Name,
                        LogicalName = it.LogicalName,
                        ShortName   = it.ShortName,
                    };
                    host.Connection.Insert(GXInsertArgs.Insert(obj));
                    foreach (GXAttributeTemplate ait in it.Attributes)
                    {
                        GXAttribute a = new GXAttribute();
                        a.ObjectId       = obj.Id;
                        a.Index          = ait.Index;
                        a.TemplateId     = ait.Id;
                        a.AccessLevel    = ait.AccessLevel;
                        a.DataType       = ait.DataType;
                        a.UIDataType     = ait.UIDataType;
                        a.Generation     = now;
                        a.ExpirationTime = ait.ExpirationTime;
                        obj.Attributes.Add(a);
                    }
                    ;
                    host.Connection.Insert(GXInsertArgs.InsertRange(obj.Attributes));
                }
            }
            host.SetChange(TargetType.Device, DateTime.Now);
            return(new AddTestDeviceResponse());
        }