Example #1
0
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
            if (_state == null)
            {
                //initialize state
                _state           = new ScribblerState();
                _state.ComPort   = 0;
                _state.RobotName = null;

                //motors initially stopped
                _state.MotorLeft  = 100;
                _state.MotorRight = 100;

                SaveState(_state);
            }

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

            //for HttpPost
            _httpUtilities = DsspHttpUtilitiesService.Create(Environment);

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

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

            //open Scribbler Communications port
            if (ConnectToScribbler())
            {
                // Listen for a single Serial port request with an acknowledgement
                Activate(Arbiter.ReceiveWithIterator <SendScribblerCommand>(false, _scribblerComPort, SendScribblerCommandHandler));

                PollTimer           = new System.Timers.Timer();
                PollTimer.Interval  = TimerDelay;
                PollTimer.AutoReset = true;
                PollTimer.Elapsed  += new System.Timers.ElapsedEventHandler(PollTimer_Elapsed);
                PollTimer.Start();


                //play startup tone
                PlayToneBody startTone = new PlayToneBody(200, 1000, 2000);
                _mainPort.Post(new PlayTone(startTone));

                //debug
                //ScribblerCommand cmd = new ScribblerCommand((byte)ScribblerHelper.Commands.GET_INFO);
                //SendScribblerCommand sendcmd = new SendScribblerCommand(cmd);
                //_scribblerComPort.Post(sendcmd);


                //fix state
                _state.MotorLeft  = 100;
                _state.MotorRight = 100;
                _state.LEDLeft    = false;
                _state.LEDRight   = false;
                _state.LEDCenter  = false;
            }
            else
            {
                //no scribbler found. Open state page for manual settings.
                OpenServiceInBrowser();
            }

            //add custom handlers to interleave
            mainInterleave.CombineWith(new Interleave(
                                           new TeardownReceiverGroup(),
                                           new ExclusiveReceiverGroup(
                                               Arbiter.ReceiveWithIterator <SetMotors>(true, _mainPort, SetMotorHandler),
                                               Arbiter.ReceiveWithIterator <SetLED>(true, _mainPort, SetLEDHandler),
                                               Arbiter.ReceiveWithIterator <SetAllLEDs>(true, _mainPort, SetAllLEDsHandler),
                                               Arbiter.ReceiveWithIterator <PlayTone>(true, _mainPort, PlayToneHandler),
                                               Arbiter.ReceiveWithIterator <SetName>(true, _mainPort, SetNameHandler),
                                               Arbiter.ReceiveWithIterator <ScribblerResponseMessage>(true, _mainPort, ScribblerResponseHandler)
                                               ),
                                           new ConcurrentReceiverGroup()
                                           ));
        }
Example #2
0
 public virtual IEnumerator <ITask> ReplaceHandler(Replace replace)
 {
     _state = replace.Body;
     replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
     yield break;
 }
Example #3
0
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
            if (_state == null)
            {
                //initialize state
                _state = new ScribblerState();
                _state.ComPort = 0;
                _state.RobotName = null;

                //motors initially stopped
                _state.MotorLeft = 100;
                _state.MotorRight = 100;

                //_state.LightLeftConfig = new SensorConfig();
                //_state.LightRightConfig = new SensorConfig();
                //_state.LightCenterConfig = new SensorConfig();

                SaveState(_state);
            }

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

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

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

            //open Scribbler Communications port
            if (ConnectToScribbler())
            {

                // Listen for a single Serial port request with an acknowledgement
                Activate(Arbiter.ReceiveWithIterator<SendScribblerCommand>(false, _scribblerComPort, SendScribblerCommandHandler));


                //add custom handlers to interleave
                mainInterleave.CombineWith(new Interleave(
                    new TeardownReceiverGroup(),
                    new ExclusiveReceiverGroup(
                        Arbiter.ReceiveWithIterator<SetMotor>(true, _mainPort, SetMotorHandler),
                        Arbiter.ReceiveWithIterator<SetLED>(true, _mainPort, SetLEDHandler),
                        Arbiter.ReceiveWithIterator<PlayTone>(true, _mainPort, PlayToneHandler),
                        //Arbiter.ReceiveWithIterator<ConfigureSensor>(true, _mainPort, ConfigureSensorHandler),
                        Arbiter.ReceiveWithIterator<SetName>(true, _mainPort, SetNameHandler)
                    ),
                    new ConcurrentReceiverGroup()
                ));


                PollTimer = new System.Timers.Timer();
                PollTimer.Interval = TimerDelay;
                PollTimer.AutoReset = true;
                PollTimer.Elapsed += new System.Timers.ElapsedEventHandler(PollTimer_Elapsed);
                PollTimer.Start();


                //play startup tone
                PlayToneBody startTone = new PlayToneBody(200, 1000, 2000);
                PlayTone sendcmd = new PlayTone();
                sendcmd.Body = startTone;
                _mainPort.Post(sendcmd);
            }

        }
Example #4
0
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
            if (_state == null)
            {
                //initialize state
                _state           = new ScribblerState();
                _state.ComPort   = 0;
                _state.RobotName = null;

                //motors initially stopped
                _state.MotorLeft  = 100;
                _state.MotorRight = 100;

                //_state.LightLeftConfig = new SensorConfig();
                //_state.LightRightConfig = new SensorConfig();
                //_state.LightCenterConfig = new SensorConfig();

                SaveState(_state);
            }

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

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

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

            //open Scribbler Communications port
            if (ConnectToScribbler())
            {
                // Listen for a single Serial port request with an acknowledgement
                Activate(Arbiter.ReceiveWithIterator <SendScribblerCommand>(false, _scribblerComPort, SendScribblerCommandHandler));


                //add custom handlers to interleave
                mainInterleave.CombineWith(new Interleave(
                                               new TeardownReceiverGroup(),
                                               new ExclusiveReceiverGroup(
                                                   Arbiter.ReceiveWithIterator <SetMotor>(true, _mainPort, SetMotorHandler),
                                                   Arbiter.ReceiveWithIterator <SetLED>(true, _mainPort, SetLEDHandler),
                                                   Arbiter.ReceiveWithIterator <PlayTone>(true, _mainPort, PlayToneHandler),
                                                   //Arbiter.ReceiveWithIterator<ConfigureSensor>(true, _mainPort, ConfigureSensorHandler),
                                                   Arbiter.ReceiveWithIterator <SetName>(true, _mainPort, SetNameHandler)
                                                   ),
                                               new ConcurrentReceiverGroup()
                                               ));


                PollTimer           = new System.Timers.Timer();
                PollTimer.Interval  = TimerDelay;
                PollTimer.AutoReset = true;
                PollTimer.Elapsed  += new System.Timers.ElapsedEventHandler(PollTimer_Elapsed);
                PollTimer.Start();


                //play startup tone
                PlayToneBody startTone = new PlayToneBody(200, 1000, 2000);
                PlayTone     sendcmd   = new PlayTone();
                sendcmd.Body = startTone;
                _mainPort.Post(sendcmd);
            }
        }
Example #5
0
 public virtual IEnumerator<ITask> ReplaceHandler(Replace replace)
 {
     _state = replace.Body;
     replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
     yield break;
 }