Пример #1
0
 public Ds18b20Sensor(string iddevice, byte index, string name, string description, string location, ushort interval, Scheduler scheduler)
 {
   Index = index;
   Name = name;
   Description = description;
   Location = location;
   Interval = interval;
   Unit = "°C";
   Hardware = "ds18b20";
   MinRange = -55;
   MaxRange = 125;
   Scale = 1.0f;
   Function = FunctionType.None;
   _iddevice = iddevice;
   _scheduler = scheduler;
 }
Пример #2
0
    public HBusProcessor(BusController hbus)
    {
      _bus = hbus;
      _bus.CommandReceived += OnCommandReceived;
      _bus.AckReceived += OnAckReceived;
      _scheduler = Scheduler.GetScheduler();
      _hbusEvents = new Dictionary<string, IList<Event>>();
      //Event from ep source
      OnSourceEvent = (@event, point) =>
      {
        if (@event.Channel != Channel && !string.IsNullOrEmpty(@event.Channel)) return;

        var address = !string.IsNullOrEmpty(@event.Address) ? Address.Parse(@event.Address) : Address.BroadcastAddress;

        var stack = new SimpleStack();

        ////Create new page event list
        //if (!_hbusEvents.ContainsKey(@event.Subscriber))
        //    _hbusEvents.Add(@event.Subscriber, new List<Event>());

        switch (@event.Name)
        {
          case "node-subscribe":
            _bus.SendCommand(NodeCommands.CMD_ADD_NODE_LISTENER, address);
            break;
          case "node-unsubscribe":
            _bus.SendCommand(NodeCommands.CMD_DELETE_NODE_LISTENER, address);
            break;
          case "pin-activate":
            stack.PushName(@event.Source);
            _bus.SendCommand(NodeCommands.CMD_ACTIVATE, address, stack.Data);
            break;
          case "pin-deactivate":
            stack.PushName(@event.Source);
            _bus.SendCommand(NodeCommands.CMD_DEACTIVATE, address, stack.Data);
            break;
          case "pin-subscribe":
            stack.PushName(@event.Source);
            _bus.SendCommand(NodeCommands.CMD_ADD_PIN_LISTENER, address, stack.Data);
            break;
          case "pin-unsubscribe":
            stack.PushName(@event.Source);
            _bus.SendCommand(NodeCommands.CMD_DELETE_PIN_LISTENER, address, stack.Data);
            break;
          case "device-subscribe":
            stack.PushName(@event.Source);
            _bus.SendCommand(NodeCommands.CMD_ADD_DEVICE_LISTENER, address, stack.Data);
            break;
          case "device-unsubscribe":
            stack.PushName(@event.Source);
            _bus.SendCommand(NodeCommands.CMD_DELETE_DEVICE_LISTENER, address, stack.Data);
            break;
          case "sensor-subscribe":
            //This is extracted only for explantion
            //@event.Data could be used as it is
            var interval = @event.Data[0];
            var expires = (ushort) (@event.Data[2] << 8 + @event.Data[1]);
            stack.PushName(@event.Source);
            stack.Push(interval);
            stack.Push(expires);
            _bus.SendCommand(NodeCommands.CMD_ADD_SENSOR_LISTENER, address, stack.Data);
            break;
          case "sensor-unsubscribe":
            stack.PushName(@event.Source);
            _bus.SendCommand(NodeCommands.CMD_DELETE_SENSOR_LISTENER, address, stack.Data);
            break;
          case "sensor-read":
            stack.PushName(@event.Source);
            _bus.SendCommand(NodeCommands.CMD_READ_SENSOR, address, stack.Data);
            break;
          //TODO: other HBus commands
          default:
            if (@event.Name.IndexOf("device-") == 0)
            {
              //Send device action
              var devaction = new DeviceAction(@event.Source, @event.Name.Substring(7), @event.Data);
              _bus.SendCommand(NodeCommands.CMD_EXECUTE_DEVICE_ACTION, address, devaction.ToArray());
            }
            break;
        }
      };

      //Error from ep source
      OnSourceError = (exception, sender) =>
      {
        Log.Error("Error from source endpoint", exception);
      };

      //Close connection with ep source
      OnSourceClose = (sender) =>
      {
        //Close HBus endpoint
        Stop();

        Log.Debug("closed on source close");
      };
    }
Пример #3
0
 public static Scheduler GetScheduler()
 {
     return _scheduler ?? (_scheduler = new Scheduler());
 }