public HomeController(LakeLabDbContext context, ValueStorage vs, DeviceStorage ds, UserManager <AppUser> um)
 {
     _dbContext     = context;
     _valueStorage  = vs;
     _deviceStorage = ds;
     _userManager   = um;
 }
 public apiController(LakeLabDbContext context, LoggingDbContext logginContext, ValueStorage vs, DeviceStorage ds)
 {
     _dbContext        = context;
     _loggingDbContext = logginContext;
     _valueStorage     = vs;
     _deviceStorage    = ds;
 }
Example #3
0
        /*****************************************************************************************************/
        static void StartActivity()
        {
            // Load the device descriptor from the external file
            m_storage = DeviceStorage.Load("DeviceDescriptor.xml");

            RaspberryGpioConfig();

            // Bacnet on UDP/IP/Ethernet
            bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));

            // Bacnet Mstp using an Usb to Rs485 adapter :
            //      bacnet_client = new BacnetClient(new BacnetMstpProtocolTransport("/dev/ttyUSB0", 38400,4,10));
            // Master id 4, Max master 10, usb adapter attached on ttyUSB0
            // For MSTP, you should :
            //      1) avoid using the JIT compiler (since token passing timing will be unpredicable when accessing the first time bacnet objects)
            //      for that provide a native code in place of the CLI one using this command line :
            //           mono --aot ./RaspberrySample.exe
            //      this will create a file RaspberrySample.exe.so, let it close to the original CLI .exe code
            //      2) launch the process with a high priority :
            //          sudo nice --20 mono ./RaspberrySample.exe or LANG="en-US.UTF8" sudo nice --20 mono ./RaspberrySample.exe
            // Tested with Ftdi Usb/Rs485 adapter, Trane UC800 devices & Contemporary Control Bacnet router
            // ... sometimes Rs845 activity is lost ! So not fiable today, only for learing purpose.

            bacnet_client.OnWhoIs += new BacnetClient.WhoIsHandler(handler_OnWhoIs);
            bacnet_client.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(handler_OnReadPropertyRequest);
            bacnet_client.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(handler_OnReadPropertyMultipleRequest);
            bacnet_client.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(handler_OnWritePropertyRequest);
            bacnet_client.OnTimeSynchronize             += new BacnetClient.TimeSynchronizeHandler(handler_OnTimeSynchronize);

            bacnet_client.Start();    // go
            // Send Iam
            bacnet_client.Iam(m_storage.DeviceId);
        }
Example #4
0
        /*****************************************************************************************************/
        static void StartActivity()
        {
            // Load the device descriptor from the embedded resource file
            // Get myId as own device id
            m_storage = DeviceStorage.Load("BasicServer.DeviceDescriptor.xml");

            // Bacnet on UDP/IP/Ethernet
            bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));
            // or Bacnet Mstp on COM4 à 38400 bps, own master id 8
            // m_bacnet_client = new BacnetClient(new BacnetMstpProtocolTransport("COM4", 38400, 8);
            // Or Bacnet Ethernet
            // bacnet_client = new BacnetClient(new BacnetEthernetProtocolTransport("Connexion au réseau local"));
            // Or Bacnet on IPV6
            // bacnet_client = new BacnetClient(new BacnetIpV6UdpProtocolTransport(0xBAC0));

            bacnet_client.OnWhoIs += new BacnetClient.WhoIsHandler(handler_OnWhoIs);
            bacnet_client.OnIam   += new BacnetClient.IamHandler(bacnet_client_OnIam);
            bacnet_client.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(handler_OnReadPropertyRequest);
            bacnet_client.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(handler_OnReadPropertyMultipleRequest);
            bacnet_client.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(handler_OnWritePropertyRequest);

            bacnet_client.Start();    // go
            // Send Iam
            bacnet_client.Iam(m_storage.DeviceId, new BacnetSegmentations());
        }
        public List <ModuleModel> GenerateModuleModel(string deviceName)
        {
            var mModel = new List <ModuleModel>();

            foreach (var m in DeviceStorage.GetDeviceByName(deviceName).Modules)
            {
                var buf = new ModuleModel();
                buf.module     = m;
                buf.DeviceName = deviceName;
                if (buf.module is Trigger)
                {
                    buf.Type   = "Simple Trigger";
                    buf.StrVal = Utility.UnWrapStates((buf.module as Trigger).State);
                }
                if (buf.module is VariadicTrigger)
                {
                    buf.Type   = "Variadic Trigger";
                    buf.StrVal = (buf.module as VariadicTrigger).State.ToString();
                }
                if (buf.module is Sensor)
                {
                    buf.Type = (buf.module as Sensor).State.ToString();
                }
                mModel.Add(buf);
                // mModel[0].Module.
            }
            return(mModel);
        }
        public IActionResult Register(string deviceName)
        {
            DeviceStorage.RegisterDevice(DeviceStorage.GetDeviceByName(deviceName));
            ViewData["Message"] = "Settings general page.";

            return(View("Devices", DevModelHandler.deviceModel));
        }
Example #7
0
        /*****************************************************************************************************/
        static void StartActivity()
        {
            // Load the device descriptor from the embedded resource file
            // Get myId as own device id
            m_storage = DeviceStorage.Load("BasicAlarmListener.DeviceDescriptor.xml", myId);
            // A fast way to change the PROP_OBJECT_LIST
            Property Prop = Array.Find <Property>(m_storage.Objects[0].Properties, p => p.Id == BacnetPropertyIds.PROP_OBJECT_LIST);

            Prop.Value[0] = "OBJECT_DEVICE:" + myId.ToString();

            // Bacnet on UDP/IP/Ethernet
            bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));
            // or Bacnet Mstp on COM4 à 38400 bps, own master id 8
            // m_bacnet_client = new BacnetClient(new BacnetMstpProtocolTransport("COM4", 38400, 8);

            bacnet_client.OnWhoIs       += new BacnetClient.WhoIsHandler(handler_OnWhoIs);
            bacnet_client.OnEventNotify += new BacnetClient.EventNotificationCallbackHandler(handler_OnEventNotify);

            // ReadProperties handlers are not absolutly required. Only whois (... and event !) handlers could be used,
            // and m_storage object could be removed in this case.
            bacnet_client.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(handler_OnReadPropertyRequest);
            bacnet_client.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(handler_OnReadPropertyMultipleRequest);

            bacnet_client.Start();    // go
        }
        // Quite all the code here came from DemoServer
        // Only COV, Write & Files operations have been commented
        // To activate BBMD services and Foreign Devices Acceptation
        // the only thinks to do is to call udp_transport.Bvlc.AddBBMDPeer(BBMD, Mask);
        // at least one time
        static BacnetActivity()
        {
            try
            {
                // resource is embedded in the project
                m_storage = DeviceStorage.Load("DemoBBMD.DeviceStorage.xml");

                m_storage.ChangeOfValue += new DeviceStorage.ChangeOfValueHandler(m_storage_ChangeOfValue);
                m_storage.ReadOverride  += new DeviceStorage.ReadOverrideHandler(m_storage_ReadOverride);

                // create udp service point
                // certainly here exclusive_port usage could be set to true
                // in order to be sure to be accepted by all the BBMD who are checking the
                // endpoint where the requests are arriving and or sending to preconfigured port
                // Needed with Wago 750-830, Contemporary Controls, Newron, ...

                // not specifying the local_endpoint_ip is a little bugy problem for broadcast when exists multiple active interfaces
                // with some chance it's Ok !

                using (var loggerFactory = LoggerFactory.Create(b =>
                {
                    b.AddConsole(c =>
                    {
                        c.TimestampFormat = "[yyyy-MM-dd HH:mm:ss] ";
                    });
                }))
                {
                    udp_transport = new BacnetIpUdpProtocolTransport(port: 0xBAC0, loggerFactory: loggerFactory, useExclusivePort: true);

                    // For IPV6, uncomment this, and comment out the previous line
                    // 187 is the device id : see DeviceStorage.xml
                    //udp_transportV6 = new BacnetIpV6UdpProtocolTransport(0xBAC0, 187, true);


                    m_ip_server = new BacnetClient(udp_transport, loggerFactory: loggerFactory);
                }

                m_ip_server.OnWhoIs += new BacnetClient.WhoIsHandler(OnWhoIs);
                m_ip_server.OnReadPropertyRequest += new BacnetClient.ReadPropertyRequestHandler(OnReadPropertyRequest);
                //m_ip_server.OnWritePropertyRequest += new BacnetClient.WritePropertyRequestHandler(OnWritePropertyRequest);
                m_ip_server.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(OnReadPropertyMultipleRequest);
                //m_ip_server.OnWritePropertyMultipleRequest += new BacnetClient.WritePropertyMultipleRequestHandler(OnWritePropertyMultipleRequest);
                //m_ip_server.OnAtomicWriteFileRequest += new BacnetClient.AtomicWriteFileRequestHandler(OnAtomicWriteFileRequest);
                //m_ip_server.OnAtomicReadFileRequest += new BacnetClient.AtomicReadFileRequestHandler(OnAtomicReadFileRequest);
                //m_ip_server.OnSubscribeCOV += new BacnetClient.SubscribeCOVRequestHandler(OnSubscribeCOV);
                //m_ip_server.OnSubscribeCOVProperty += new BacnetClient.SubscribeCOVPropertyRequestHandler(OnSubscribeCOVProperty);
                m_ip_server.OnTimeSynchronize            += new BacnetClient.TimeSynchronizeHandler(OnTimeSynchronize);
                m_ip_server.OnDeviceCommunicationControl += new BacnetClient.DeviceCommunicationControlRequestHandler(OnDeviceCommunicationControl);
                m_ip_server.OnReinitializedDevice        += new BacnetClient.ReinitializedRequestHandler(OnReinitializedDevice);
                m_ip_server.Start();

                //send greeting
                m_ip_server.Iam(m_storage.DeviceId, m_supported_segmentation);
            }
            catch
            {
                OpenError = true;
            }
        }
Example #9
0
 public AdminController(UserManager <AppUser> usrMgr, IUserValidator <AppUser> userValid, IPasswordValidator <AppUser> passValid, IPasswordHasher <AppUser> passwordHash, LakeLabDbContext dbContext, DeviceStorage deviceStorage)
 {
     _userManager       = usrMgr;
     _userValidator     = userValid;
     _passwordValidator = passValid;
     _passwordHasher    = passwordHash;
     _dbContext         = dbContext;
     _deviceStorage     = deviceStorage;
 }
Example #10
0
        static BacnetActivity()
        {
            try
            {
                //init

                PhysicalAddress macAddr =
                    (
                        from netiface in NetworkInterface.GetAllNetworkInterfaces()
                        where ((netiface.OperationalStatus == OperationalStatus.Up) && ((netiface.NetworkInterfaceType == NetworkInterfaceType.Ethernet) || (netiface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)))
                        select netiface.GetPhysicalAddress()
                    ).FirstOrDefault();

                if (macAddr != null)
                {
                    byte[] mac = macAddr.GetAddressBytes();
                    DeviceId = ((uint)mac[5] + (uint)((mac[4] << 8) & 0x3F)) << 6;
                }

                if (App.Current.CurrentCulture == "fr")
                {
                    Storage = DeviceStorage.Load("RoomSimulator.DeviceStorage.xml", DeviceId);
                }
                else
                {
                    Storage = DeviceStorage.Load("RoomSimulator.DeviceStorageUs.xml", DeviceId);
                }

                Storage.ChangeOfValue += new DeviceStorage.ChangeOfValueHandler(m_storage_ChangeOfValue);
                Storage.ReadOverride  += new DeviceStorage.ReadOverrideHandler(m_storage_ReadOverride);

                //create udp service point
                var udp_transport = new BacnetIpUdpProtocolTransport(0xBAC0, false);       //set to true to force "single socket" usage
                udp_transport.Log = new DebugLogger();
                m_ip_server       = new BacnetClient(udp_transport);
                m_ip_server.Log   = new DebugLogger();

                m_ip_server.OnWhoIs += new BacnetClient.WhoIsHandler(OnWhoIs);
                m_ip_server.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(OnReadPropertyRequest);
                m_ip_server.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(OnWritePropertyRequest);
                m_ip_server.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(OnReadPropertyMultipleRequest);
                m_ip_server.OnSubscribeCOV               += new BacnetClient.SubscribeCOVRequestHandler(OnSubscribeCOV);
                m_ip_server.OnSubscribeCOVProperty       += new BacnetClient.SubscribeCOVPropertyRequestHandler(OnSubscribeCOVProperty);
                m_ip_server.OnTimeSynchronize            += new BacnetClient.TimeSynchronizeHandler(OnTimeSynchronize);
                m_ip_server.OnDeviceCommunicationControl += new BacnetClient.DeviceCommunicationControlRequestHandler(OnDeviceCommunicationControl);
                m_ip_server.OnReinitializedDevice        += new BacnetClient.ReinitializedRequestHandler(OnReinitializedDevice);
                m_ip_server.Start();

                //send greeting
                m_ip_server.Iam(Storage.DeviceId, m_supported_segmentation);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public IActionResult SaveName(string deviceName, string IP)
        {
            DevModelHandler.deviceModel.Find(x => x.DeviceInfo.Device.Name == deviceName).EditShow = false;
            DeviceStorage.ChangeExternalNameOfDevice(deviceName, IP);
            // DevModelHandler.deviceModel.Find(x => x.DeviceInfo.Device.Name == deviceName).DeviceInfo.Device.ExternalName = "Tesst";
            //var test = Request
            ViewData["Message"] = "Settings general page.";

            return(View("Devices", DevModelHandler.deviceModel));
        }
        public IActionResult DeleteDevice(string deviceName)
        {
            var tr = DevModelHandler.deviceModel.Find(x => x.DeviceInfo.Device.Name == deviceName);

            DevModelHandler.deviceModel.Remove(tr);
            DeviceStorage.DeleteDevice(deviceName);
            ViewData["Message"] = "Modules";

            return(View("Devices", DevModelHandler.deviceModel));
        }
        static BacnetActivity()
        {
            try
            {
                //init

                PhysicalAddress macAddr =
                    (
                        from netiface in NetworkInterface.GetAllNetworkInterfaces()
                        where ((netiface.OperationalStatus == OperationalStatus.Up) && ((netiface.NetworkInterfaceType == NetworkInterfaceType.Ethernet) || (netiface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)))
                        select netiface.GetPhysicalAddress()
                    ).FirstOrDefault();

                if (macAddr != null)
                {
                    byte[] mac = macAddr.GetAddressBytes();
                    deviceId = (uint)mac[5] + (uint)((mac[4] << 8) << 6);
                }
                // Un bricollage du dimanche vite fait ici !
                deviceId = deviceId + ((uint)(Program.Count & 0x3F));

                if (Application.CurrentCulture.TwoLetterISOLanguageName == "fr")
                {
                    m_storage = DeviceStorage.Load("Bacnet.Room.Simulator.DeviceStorage.xml", deviceId);
                }
                else
                {
                    m_storage = DeviceStorage.Load("Bacnet.Room.Simulator.DeviceStorageUs.xml", deviceId);
                }

                m_storage.ChangeOfValue += new DeviceStorage.ChangeOfValueHandler(m_storage_ChangeOfValue);
                m_storage.ReadOverride  += new DeviceStorage.ReadOverrideHandler(m_storage_ReadOverride);

                //create udp service point
                BacnetIpUdpProtocolTransport udp_transport = new BacnetIpUdpProtocolTransport(0xBAC0, false);       //set to true to force "single socket" usage
                m_ip_server = new BacnetClient(udp_transport);

                m_ip_server.OnWhoIs += new BacnetClient.WhoIsHandler(OnWhoIs);
                m_ip_server.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(OnReadPropertyRequest);
                m_ip_server.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(OnWritePropertyRequest);
                m_ip_server.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(OnReadPropertyMultipleRequest);
                m_ip_server.OnSubscribeCOV               += new BacnetClient.SubscribeCOVRequestHandler(OnSubscribeCOV);
                m_ip_server.OnSubscribeCOVProperty       += new BacnetClient.SubscribeCOVPropertyRequestHandler(OnSubscribeCOVProperty);
                m_ip_server.OnTimeSynchronize            += new BacnetClient.TimeSynchronizeHandler(OnTimeSynchronize);
                m_ip_server.OnDeviceCommunicationControl += new BacnetClient.DeviceCommunicationControlRequestHandler(OnDeviceCommunicationControl);
                m_ip_server.OnReinitializedDevice        += new BacnetClient.ReinitializedRequestHandler(OnReinitializedDevice);
                m_ip_server.Start();

                //send greeting
                m_ip_server.Iam(m_storage.DeviceId, m_supported_segmentation);
            }
            catch
            {
            }
        }
Example #14
0
        /// <summary>
        /// 启动服务
        /// </summary>
        public void Start()
        {
            try
            {
                //init

                PhysicalAddress macAddr =
                    (
                        from netiface in NetworkInterface.GetAllNetworkInterfaces()
                        where ((netiface.OperationalStatus == OperationalStatus.Up) && ((netiface.NetworkInterfaceType == NetworkInterfaceType.Ethernet) || (netiface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)))
                        select netiface.GetPhysicalAddress()
                    ).FirstOrDefault();

                if (macAddr != null)
                {
                    byte[] mac = macAddr.GetAddressBytes();
                    deviceId = ((uint)mac[5] + (uint)((mac[4] << 8) & 0x3F)) << 6;
                }
                // Un bricollage du dimanche vite fait ici !
                deviceId = deviceId + increaseId++;

                m_storage = DeviceStorage.Load("IoTServer.DeviceStorage.xml", deviceId);

                var str = JsonConvert.SerializeObject(m_storage);

                m_storage.ChangeOfValue += new DeviceStorage.ChangeOfValueHandler(m_storage_ChangeOfValue);
                m_storage.ReadOverride  += new DeviceStorage.ReadOverrideHandler(m_storage_ReadOverride);

                //create udp service point
                BacnetIpUdpProtocolTransport udp_transport = new BacnetIpUdpProtocolTransport(47808, false);       //set to true to force "single socket" usage
                m_ip_server = new BacnetClient(udp_transport);

                m_ip_server.OnWhoIs += new BacnetClient.WhoIsHandler(OnWhoIs);
                m_ip_server.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(OnReadPropertyRequest);
                m_ip_server.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(OnWritePropertyRequest);
                m_ip_server.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(OnReadPropertyMultipleRequest);
                m_ip_server.OnSubscribeCOV               += new BacnetClient.SubscribeCOVRequestHandler(OnSubscribeCOV);
                m_ip_server.OnSubscribeCOVProperty       += new BacnetClient.SubscribeCOVPropertyRequestHandler(OnSubscribeCOVProperty);
                m_ip_server.OnTimeSynchronize            += new BacnetClient.TimeSynchronizeHandler(OnTimeSynchronize);
                m_ip_server.OnDeviceCommunicationControl += new BacnetClient.DeviceCommunicationControlRequestHandler(OnDeviceCommunicationControl);
                m_ip_server.OnReinitializedDevice        += new BacnetClient.ReinitializedRequestHandler(OnReinitializedDevice);
                m_ip_server.Start();

                //send greeting
                m_ip_server.Iam(m_storage.DeviceId, m_supported_segmentation);
            }
            catch (Exception e)
            {
            }
        }
        public IActionResult ScheduleTimeBased(string deviceName, string moduleName)
        {
            var      module   = DeviceStorage.GetDeviceByName(deviceName).GetModuleByName(moduleName);
            Random   rand     = new Random();
            SmSEvent smSEvent = new TimeEvent("AutoGeneratedEvent", module, rand.Next(1, 250));
            var      time     = DateTime.Now.AddSeconds(5);

            (smSEvent as TimeEvent).TriggerAt(time);
            Scheduler.AddEvent(smSEvent);
            // DevModelHandler.deviceModel.Find(x => x.DeviceInfo.Device.Name == deviceName).DeviceInfo.Device.ExternalName = "Tesst";
            //var test = Request
            ViewData["Message"] = "Settings general page.";

            return(View("Devices", DevModelHandler.deviceModel));
        }
Example #16
0
 public static void Main(string[] args)
 {
     DeviceStorage.LoadDevicesFromDb();
     new Thread(() =>
     {
         TcpServer server = new TcpServer(5555);
     }).Start();
     new Thread(() =>
     {
         while (true)
         {
             Scheduler.InvokeReadyEvents();
             Thread.Sleep(500);
         }
     }).Start();
     BuildWebHost(args).Run();
 }
Example #17
0
        private string HandleDump()
        {
            Device buf = new Device(_headers["device_name"], "Empty");

            buf.CurrentTime = Int64.Parse(_headers["local_time"]);
            if (!DeviceStorage.Contains(_headers["device_name"]))
            {
                _resultInfo.Code    = 404;
                _resultInfo.Message = "Device not found";
            }
            else
            {
                buf = DeviceStorage.GetDeviceByName(_headers["device_name"]);
                if (!_headers.ContainsKey("auth"))
                {
                    _resultInfo.Code    = (int)RetCodes.UNAUTHORIZED;
                    _resultInfo.Message = "No auth header";
                }
                else
                {
                    if (_headers["auth"] == buf.AuthToken)
                    {
                        var modules = ParseModulesFromHeaders();
                        foreach (var m in modules)
                        {
                            if (buf.IsModuleExist(m.Name))
                            {
                                buf.ChangeModuleFromDevice(buf.GetModuleByName(m.Name), m);
                            }
                            else
                            {
                                buf.AddModule(m);
                            }
                        }
                        _resultInfo.Code    = (int)RetCodes.OK;
                        _resultInfo.Message = "Ok";
                    }
                    else
                    {
                        _resultInfo.Code    = (int)RetCodes.UNAUTHORIZED;
                        _resultInfo.Message = "Auth token is wrong.";
                    }
                }
            }
            return(buf.GetQueueMessage() + BuildValidationString(buf));
        }
        private static void StartActivity()
        {
            m_storage = DeviceStorage.Load("Ths_BTLServer.DeviceDescriptor.xml", null);
            m_storage.ChangeOfValue                     += new DeviceStorage.ChangeOfValueHandler(Program.m_storage_ChangeOfValue);
            m_subscriptions                              = new Dictionary <BacnetObjectId, List <Subscription> >();
            bacnet_client                                = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));
            bacnet_client.OnWhoIs                       += new BacnetClient.WhoIsHandler(Program.handler_OnWhoIs);
            bacnet_client.OnIam                         += new BacnetClient.IamHandler(bacnet_client_OnIam);
            bacnet_client.OnWhoHas                      += new BacnetClient.WhoHasHandler(Program.bacnet_client_OnWhoHas);
            bacnet_client.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(Program.handler_OnReadPropertyRequest);
            bacnet_client.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(Program.handler_OnReadPropertyMultipleRequest);
            bacnet_client.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(Program.handler_OnWritePropertyRequest);
            bacnet_client.OnSubscribeCOV                += new BacnetClient.SubscribeCOVRequestHandler(Program.bacnet_client_OnSubscribeCOV);
            bacnet_client.OnSubscribeCOVProperty        += new BacnetClient.SubscribeCOVPropertyRequestHandler(Program.bacnet_client_OnSubscribeCOVProperty);
            bacnet_client.Retries                        = 10;
            bacnet_client.Start();
            uint deviceId = m_storage.DeviceId;

            bacnet_client.WhoIs(-1, -1, null);
            bacnet_client.Iam(m_storage.DeviceId, BacnetSegmentations.SEGMENTATION_BOTH);
        }
Example #19
0
        private string HandleAck()
        {
            Device buf = new Device(_headers["device_name"], "Empty");

            buf.LastSync = DateTime.Now;
            if (DeviceStorage.Contains(_headers["device_name"]))
            {
                buf = DeviceStorage.GetDeviceByName(_headers["device_name"]);
            }
            else
            {
                if (DatabaseWrapper.IsDeviceExist(_headers["device_name"]))
                {
                    buf = DatabaseWrapper.LoadDeviceFromDB(_headers["device_name"]).Device;
                }
            }

            buf.CurrentTime = Int64.Parse(_headers["local_time"]);
            var modules = ParseModulesFromHeaders();

            foreach (var m in modules)
            {
                if (buf.IsModuleExist(m.Name))
                {
                    buf.ChangeModuleFromDevice(buf.GetModuleByName(m.Name), m);
                }
                else
                {
                    buf.AddModule(m);
                }
            }
            if (!DeviceStorage.DeviceExists(_headers["device_name"]))
            {
                DeviceStorage.AddDevice(buf);
            }

            _resultInfo.Code    = (int)RetCodes.OK;
            _resultInfo.Message = "Ok";
            return(buf.GetQueueMessage());
        }
        private static void m_storage_ChangeOfValue(DeviceStorage sender, BacnetObjectId object_id, BacnetPropertyIds property_id, uint array_index, IList <BacnetValue> value)
        {
            System.Threading.ThreadPool.QueueUserWorkItem((o) =>
            {
                lock (m_lockObject)
                {
                    //remove old leftovers
                    RemoveOldSubscriptions();

                    //find subscription
                    if (!m_subscriptions.ContainsKey(object_id))
                    {
                        return;
                    }
                    List <Subscription> subs = m_subscriptions[object_id];

                    //convert
                    List <BacnetPropertyValue> values = new List <BacnetPropertyValue>();
                    BacnetPropertyValue tmp           = new BacnetPropertyValue();
                    tmp.property = new BacnetPropertyReference((uint)property_id, array_index);
                    tmp.value    = value;
                    values.Add(tmp);

                    //send to all
                    foreach (Subscription sub in subs)
                    {
                        if (sub.monitoredProperty.propertyIdentifier == (uint)BacnetPropertyIds.PROP_ALL || sub.monitoredProperty.propertyIdentifier == (uint)property_id)
                        {
                            //send notify
                            if (!sub.reciever.Notify(sub.reciever_address, sub.subscriberProcessIdentifier, m_storage.DeviceId, sub.monitoredObjectIdentifier, (uint)sub.GetTimeRemaining(), sub.issueConfirmedNotifications, values))
                            {
                                Trace.TraceError("Couldn't send notify");
                            }
                        }
                    }
                }
            }, null);
        }
Example #21
0
 public DevicesController(DeviceStorage deviceStorage)
 {
     Storage = deviceStorage;
 }
Example #22
0
 public DevicesController(DeviceStorage storage)
 {
     Storage = storage;
 }
 public DevicesController(LakeLabDbContext context, AppIdentityDbContext identityDbContext, DeviceStorage deviceStorage)
 {
     _dbContext         = context;
     _identityDbContext = identityDbContext;
     _deviceStorage     = deviceStorage;
 }
Example #24
0
        public void GetDevices()
        {
            try
            {
                //var bne = new BACnetNetworkEvents(this);


                //start BACnet
                BacnetClient.ProposedWindowSize = Yabe.Properties.Settings.Default.Segments_ProposedWindowSize;
                BacnetClient.Retries            = (int)Yabe.Properties.Settings.Default.DefaultRetries;
                BacnetClient.Timeout            = (int)Yabe.Properties.Settings.Default.DefaultTimeout;
                BacnetClient.MaxSegments        = BacnetClient.GetSegmentsCount(Yabe.Properties.Settings.Default.Segments_Max);
                if (Yabe.Properties.Settings.Default.YabeDeviceId >= 0) // If Yabe get a Device id
                {
                    if (BACnetGlobalNetwork.m_storage == null)
                    {
                        lock (BACnetGlobalNetwork.m_storage)
                        {
                            // Load descriptor from the embedded xml resource
                            BACnetGlobalNetwork.m_storage = DeviceStorage.Load("Yabe.YabeDeviceDescriptor.xml", (uint)Yabe.Properties.Settings.Default.YabeDeviceId);
                            // A fast way to change the PROP_OBJECT_LIST
                            Property Prop = Array.Find <Property>(BACnetGlobalNetwork.m_storage.Objects[0].Properties, p => p.Id == BacnetPropertyIds.PROP_OBJECT_LIST);
                            Prop.Value[0] = "OBJECT_DEVICE:" + Yabe.Properties.Settings.Default.YabeDeviceId.ToString();
                            // change PROP_FIRMWARE_REVISION
                            Prop          = Array.Find <Property>(BACnetGlobalNetwork.m_storage.Objects[0].Properties, p => p.Id == BacnetPropertyIds.PROP_FIRMWARE_REVISION);
                            Prop.Value[0] = this.GetType().Assembly.GetName().Version.ToString();
                            // change PROP_APPLICATION_SOFTWARE_VERSION
                            Prop          = Array.Find <Property>(BACnetGlobalNetwork.m_storage.Objects[0].Properties, p => p.Id == BacnetPropertyIds.PROP_APPLICATION_SOFTWARE_VERSION);
                            Prop.Value[0] = this.GetType().Assembly.GetName().Version.ToString();
                        }
                    }
                    BacnetClient.OnWhoIs += new BacnetClient.WhoIsHandler(OnWhoIs);    //maybe this can't be static...does anything need to be stored in it?
                    BacnetClient.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(OnReadPropertyRequest);
                    BacnetClient.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(OnReadPropertyMultipleRequest);
                }
                else
                {
                    BacnetClient.OnWhoIs += new BacnetClient.WhoIsHandler(OnWhoIsIgnore);
                }
                BacnetClient.OnIam += new BacnetClient.IamHandler(OnIam);

                // Not sure if we need these; implement later
                //BacnetClient.OnCOVNotification += new BacnetClient.COVNotificationHandler(bne.OnCOVNotification);
                //BacnetClient.OnEventNotify += new BacnetClient.EventNotificationCallbackHandler(bne.OnEventNotify);

                BacnetClient.Start();


                Console.WriteLine("type:" + BacnetClient.Transport.Type);

                //start search
                if (BacnetClient.Transport.Type == BacnetAddressTypes.IP || BacnetClient.Transport.Type == BacnetAddressTypes.Ethernet ||
                    BacnetClient.Transport.Type == BacnetAddressTypes.IPV6 ||
                    (BacnetClient.Transport is BacnetMstpProtocolTransport && ((BacnetMstpProtocolTransport)BacnetClient.Transport).SourceAddress != -1) ||
                    BacnetClient.Transport.Type == BacnetAddressTypes.PTP)
                {
                    Console.WriteLine("Starting device search");
                    System.Threading.ThreadPool.QueueUserWorkItem((o) =>
                    {
                        for (int i = 0; i < BacnetClient.Retries; i++)
                        {
                            BacnetClient.WhoIs();
                            Console.WriteLine("Sent WhoIs"); //OK, So we do WhoIs, write this line, and then sleep
                            System.Threading.Thread.Sleep(BacnetClient.Timeout);
                        }
                    }, null);
                }

                //special MSTP auto discovery
                if (BacnetClient.Transport is BacnetMstpProtocolTransport)
                {
                    //not sure this is needed...
                    //((BacnetMstpProtocolTransport)BacnetClient.Transport).FrameRecieved += new BacnetMstpProtocolTransport.FrameRecievedHandler(bne.MSTP_FrameRecieved);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error getting devices:" + ex.Message + "\n" + ex.StackTrace);
                Instance.hspi.Log("BACnetDevice Exception in GetDevices " + ex.Message, 2);

                //m_devices.Remove(bacnetClient);
                //node.Remove();
                //MessageBox.Show(this, "Couldn't start Bacnet bacnetClientunication: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //BacnetClient.WhoIs();
            //System.Threading.Thread.Sleep(BacnetClient.Timeout);

            //not actually waiting for this, just getting here right away
            Console.WriteLine("Done getting devices");
        }