Esempio n. 1
0
        protected override void Start()
        {
            // Alternate Port Operations handlers
            Activate(Arbiter.ReceiveWithIterator <analog.Get>(true, _alternatePort, AlternateGetHandler));

            //configure default state
            if (_state == null)
            {
                _state = new SoundState();
                _state.HardwareIdentifier = 2;

                SaveState(_state);
            }

            // Listen on the main port for requests and call the appropriate handler.
            ActivateDsspOperationHandlers();

            // Publish the service to the local Node Directory
            DirectoryInsert();

            // display HTTP service Uri
            LogInfo(LogGroups.Console, "Service uri: ");

            // Subscribe to NXT for sound sensor notifications
            if (ValidState(_state))
            {
                SubscribeToNXT();
            }
        }
Esempio n. 2
0
 private static bool ValidState(SoundState state)
 {
     if (state != null)
     {
         if (state.HardwareIdentifier >= 1 && state.HardwareIdentifier <= 4)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 3
0
        public virtual IEnumerator <ITask> ReplaceHandler(Replace replace)
        {
            if (_subscribed)
            {
                throw new Exception("Already subscribed");
            }
            else if (ValidState(replace.Body))
            {
                _state = replace.Body;
                SaveState(_state);
                replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
                SubscribeToNXT();
            }
            else
            {
                throw new Exception("State not valid");
            }

            yield break;
        }
Esempio n. 4
0
 /// <summary>
 /// Initialization Constructor
 /// </summary>
 public Replace(SoundState state)
 {
     this.Body = state;
 }