コード例 #1
0
ファイル: Program.cs プロジェクト: Necat0r/Automation
        public Program()
        {
            mServiceManager = new ServiceManager();
            mDeviceManager = new DeviceManager();

            string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Automation";
            Settings settings = new Settings(path, "settings.xml");

            var config = settings.GetConfig();
            if (config.ContainsKey("port"))
                mPort = UInt16.Parse(config["port"]);

            CreateSystemService();

            // Create services
            var serviceConfigs = settings.GetServiceConfigs();
            CreateServices(serviceConfigs);

            // Create devices
            var deviceConfigs = settings.GetDeviceConfigs();
            CreateDevices(deviceConfigs);

            Log.Info("Number of services: " + mServiceManager.Services.Count);
            Log.Info("Number of devices: " + mDeviceManager.Devices.Count);

            mLogic = new Logic(mDeviceManager, mServiceManager);

            InitSpeechCommands();

            // createStatusWindow

            startWebEndpoint();

            StartUIThread();
        }
コード例 #2
0
ファイル: RfxComService.cs プロジェクト: Necat0r/Automation
        public RfxComService(ServiceCreationInfo info)
            : base("rfxcom", info)
        {
            mDeviceManager = info.DeviceManager;

            int port = int.Parse(info.Configuration["port"]);

            mSerialHelper = new SerialHelper("rfxcom", (uint)port, 38400);
            mRadioLock = RadioLock.Instance;
            mEvents = new EventWaitHandle[] { mActionEvent, mSerialEvent, mStopEvent };

            mRfxThread = new Thread(Tick);
            mRfxThread.Start();
        }
コード例 #3
0
        public static NexaEvent HandlePackage(DeviceManager deviceManager, IntPtr memory)
        {
            var package = (LIGHTING2)Marshal.PtrToStructure(memory, typeof(LIGHTING2));

            //    //id1, id2, id3, id4, unit, command, level, rssi = struct.unpack(b'xxxxBBBBBBBB', package)

            int address = package.id1 << 24 | package.id2 << 16 | package.id3 << 8 | package.id4;

            // Make unit start at index zero
            int unit = package.unitcode - 1;

            Log.Debug("Got Nexa event. Address: {0}, unit: {1}, command: {2}, level: {3}, rssi: {4}", address, unit, package.cmnd, package.level, package.rssi);

            //0x00 = off
            //0x01 = on
            //0x02 = set level
            //0x03 = group off
            //0x04 = group on
            //0x05 = group set level
            var isGroupCommand = (package.cmnd >= 0x03);
            var isOnCommand = package.level > 0;

            // TODO - Use a pre-calculated lookup for finding devices

            NexaSensorDevice device = null;
            foreach (var entry in deviceManager.Devices)
            {
                NexaSensorDevice nexaDevice = entry.Value as NexaSensorDevice;
                if (nexaDevice == null)
                    continue;

                if (nexaDevice.Address == address && nexaDevice.Unit == unit)
                {
                    device = nexaDevice;
                    break;
                }
            }

            // Convert level to 0-1 range
            float level = (float)package.level;
            level = level / 15.0f;

            return new NexaEvent(device, isOnCommand, level);
        }
コード例 #4
0
 public DeviceManagerService(ServiceCreationInfo info)
     : base("device", info)
 {
     mDeviceManager = info.DeviceManager;
 }
コード例 #5
0
ファイル: Bootstrapper.cs プロジェクト: Necat0r/Automation
 public Bootstrapper(ServiceManager serviceManager, DeviceManager deviceManager)
 {
     mServiceManager = serviceManager;
     mDeviceManager = deviceManager;
 }
コード例 #6
0
 public DeviceCreationInfo(dynamic configuation, ServiceManager serviceManager, DeviceManager deviceManager)
 {
     this.Configuration = configuation;
     this.ServiceManager = serviceManager;
     this.DeviceManager = deviceManager;
 }
コード例 #7
0
 public static EverflourishEvent HandlePackage(DeviceManager deviceManager, IntPtr memory)
 {
     return null;
 }