Exemple #1
0
 /// <summary>
 /// Switch message has been received.
 /// </summary>
 private void onSwitchMessageReceived(SwitchMessage msg)
 {
     if (msg.IsActual && msg.Sender != sender)
     {
         var @switch = RailwayState.JunctionStates.OfType <ISwitchState>().FirstOrDefault(x => (x.Address.Value == msg.Address) && (x.Address.Network.Type == AddressType.BinkyNet));
         if (@switch != null)
         {
             var direction = (msg.Direction == "off") ? SwitchDirection.Off : SwitchDirection.Straight;
             if (@switch.Invert)
             {
                 direction = direction.Invert();
             }
             @switch.Direction.Actual = direction;
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Send the direction of the given switch towards the railway.
        /// This method is called on my worker thread.
        /// </summary>
        protected override void OnSendSwitchDirection(ISwitchState @switch)
        {
            Log.Trace("OnSendSwitchDirection: {0}", @switch);

            var direction = @switch.Direction.Requested;

            if (@switch.Invert)
            {
                direction = direction.Invert();
            }
            var msg = new SwitchMessage()
            {
                Sender    = sender,
                Mode      = MessageBase.ModeRequest,
                Address   = @switch.Address.Value,
                Direction = direction.ToString().ToLower()
            };

            publishMessage(msg.Topic, msg, null);
        }