/// <summary>
        /// Initialize depthcam state.
        /// </summary>
        private void DoInitializeDepthCamAlternate()
        {
            this.cachedProcessedFrames.DepthImage =
                new short[this.kinectSensor.DepthStream.FrameWidth * this.kinectSensor.DepthStream.FrameHeight];

            this.utilitiesPort = DsspHttpUtilitiesService.Create(Environment);

            this.depthCamState = new depth.DepthCamSensorState
            {
                FieldOfView = KinectCameraConstants.HorizontalFieldOfViewRadians,

                ImageMode = depth.DepthCamSensorImageMode.Rgb,

                DepthImageSize =
                    new Size(
                        this.kinectSensor.DepthStream.FrameWidth,
                        this.kinectSensor.DepthStream.FrameHeight),

                MaximumRange = KinectCameraConstants.MaximumRangeMeters,

                TimeStamp = DateTime.MinValue,

                Pose = new Microsoft.Robotics.PhysicalModel.Pose(
                    new Microsoft.Robotics.PhysicalModel.Vector3(0, 0, 0),
                    new Microsoft.Robotics.PhysicalModel.Quaternion()),

                DepthImage =
                    new short[this.kinectSensor.DepthStream.FrameWidth * this.kinectSensor.DepthStream.FrameHeight]
            };
        }
Пример #2
0
        /// <summary>
        /// Service start
        /// </summary>
        protected override void Start()
        {
            Tracer.Trace("TrackRoamerUsrfService::Start()");

            _httpUtilities = DsspHttpUtilitiesService.Create(Environment);

            base.Start();       // fire up MainPortInterleave; wireup [ServiceHandler] methods

            MainPortInterleave.CombineWith(new Interleave(
                                               new ExclusiveReceiverGroup(
                                                   Arbiter.ReceiveWithIterator <sicklrf.Subscribe>(true, _mainPort, SubscribeHandler),
                                                   Arbiter.ReceiveWithIterator <sicklrf.ReliableSubscribe>(true, _mainPort, ReliableSubscribeHandler),
                                                   Arbiter.Receive <sicklrf.Get>(true, _mainPort, GetHandler),
                                                   Arbiter.Receive <sicklrf.Reset>(true, _mainPort, ResetHandler),
                                                   Arbiter.Receive <proxibrick.UpdateSonarData>(true, _trackRoamerBrickProximityBoardServiceNotify, trpbUpdateSonarNotification)
                                                   ),
                                               new ConcurrentReceiverGroup()
                                               ));

            Tracer.Trace("TrackRoamerUsrfService:  calling Subscribe() for UpdateSonarData");

            Type[] notifyMeOf = new Type[] { typeof(proxibrick.UpdateSonarData) };

            _trackRoamerBrickProximityBoardServicePort.Subscribe(_trackRoamerBrickProximityBoardServiceNotify, notifyMeOf);
        }
Пример #3
0
        IEnumerator <ITask> DoStart()
        {
            try
            {
                _utilities = DsspHttpUtilitiesService.Create(Environment);

                RunForm runForm = new RunForm(CreateForm);

                WinFormsServicePort.Post(runForm);
                yield return(Arbiter.Choice(
                                 runForm.pResult,
                                 EmptyHandler,
                                 EmptyHandler
                                 ));

                FormInvoke invoke = new FormInvoke(
                    delegate
                {
                    _form.Initialize(_state);
                }
                    );

                WinFormsServicePort.Post(invoke);
                yield return(Arbiter.Choice(
                                 invoke.ResultPort,
                                 EmptyHandler,
                                 EmptyHandler
                                 ));
            }
            finally
            {
                FinishStarting();
            }
        }
Пример #4
0
        /// <summary>
        /// Service Startup Handler
        /// </summary>
        protected override void Start()
        {
            InitState();

            // send configuration commands to partner services
            SpawnIterator(ConfigureDrive);

            _state.TimeStamp = DateTime.Now;

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

            // Listen for each operation type and call its Service Handler
            ActivateDsspOperationHandlers();

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

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

            //for XSLT and images
            MountEmbeddedResources("/RoboticsCommon");

            // Interleave to manage internal drive operations (driveDistance and RotateDegrees)
            Activate(
                new Interleave(
                    new ExclusiveReceiverGroup(
                        Arbiter.ReceiveWithIteratorFromPortSet <drive.DriveDistance>(true, _internalDriveOperationsPort, InternalDriveDistanceHandler),
                        Arbiter.ReceiveWithIteratorFromPortSet <drive.RotateDegrees>(true, _internalDriveOperationsPort, InternalRotateDegreesHandler)
                        ),
                    new ConcurrentReceiverGroup())
                );
        }
Пример #5
0
        /// <summary>
        /// Service start
        /// </summary>
        /// <summary>
        /// Send phase of construction.
        /// </summary>
        protected override void Start()
        {
            //if (_state == null)
            //{
            //    _state = new TrackRoamerBrickProximityBoardState();
            //}

            Tracer.Trace("TrackRoamerBrickProximityBoardService::Start()");

            LogInfo("TrackRoamerBrickProximityBoardService::Start");

            _httpUtilities = DsspHttpUtilitiesService.Create(Environment);

            //
            // Kick off the connection to the Proximity Board device.
            //
            SpawnIterator(0, StartProximityBoard);

            // This service does not use base.Start() because of the way that
            // the handlers are hooked up. Also, because of this, there are
            // explicit Get and HttpGet handlers instead of using the default ones.
            // Handlers that need write or Exclusive access to state go under
            // the Exclusive group. Handlers that need read or shared access, and can be
            // Concurrent to other readers, go to the Concurrent group.
            // Other internal ports can be included in interleave so you can coordinate
            // intermediate computation with top level handlers.
            Activate(
                Arbiter.Interleave(
                    new TeardownReceiverGroup(
                        Arbiter.Receive <DsspDefaultDrop>(false, _mainPort, DropHandler)),
                    new ExclusiveReceiverGroup(
                        Arbiter.Receive <Replace>(true, _mainPort, ReplaceHandler),
                        Arbiter.Receive <SonarData>(true, _pbCommanderDataEventsPort, SonarMeasurementHandler),
                        Arbiter.Receive <DirectionData>(true, _pbCommanderDataEventsPort, DirectionMeasurementHandler),
                        Arbiter.Receive <AccelerometerData>(true, _pbCommanderDataEventsPort, AccelerometerMeasurementHandler),
                        Arbiter.Receive <ProximityData>(true, _pbCommanderDataEventsPort, ProximityMeasurementHandler),
                        Arbiter.Receive <ParkingSensorData>(true, _pbCommanderDataEventsPort, ParkingSensorMeasurementHandler),
                        Arbiter.Receive <AnalogData>(true, _pbCommanderDataEventsPort, AnalogMeasurementHandler),
                        Arbiter.ReceiveWithIterator <ProximityBoardUsbDeviceAttached>(true, _pbCommanderDataEventsPort, UsbDeviceAttached),
                        Arbiter.ReceiveWithIterator <ProximityBoardUsbDeviceDetached>(true, _pbCommanderDataEventsPort, UsbDeviceDetached),
                        Arbiter.ReceiveWithIterator <Exception>(true, _pbCommanderDataEventsPort, ExceptionHandler)),
                    new ConcurrentReceiverGroup(
                        Arbiter.Receive <DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler),
                        Arbiter.ReceiveWithIterator <Subscribe>(true, _mainPort, SubscribeHandler),
                        Arbiter.Receive <Get>(true, _mainPort, GetHandler),
                        Arbiter.Receive <HttpGet>(true, _mainPort, HttpGetHandler),
                        Arbiter.Receive <Reset>(true, _mainPort, ResetHandler))
                    )
                );

            DirectoryInsert();

            //base.Start();
        }
        /// <summary>
        /// Initialize webcam state.
        /// </summary>
        private void DoInitializeWebcamAlternate()
        {
            this.cachedProcessedFrames.VisibleImage =
                new byte[this.kinectSensor.ColorStream.FrameWidth * this.kinectSensor.ColorStream.FrameHeight
                         * 3];

            this.webCamState = new webcam.WebCamSensorState
            {
                DeviceName = "Kinect",
                Width      = this.kinectSensor.ColorStream.FrameWidth,
                Height     = this.kinectSensor.ColorStream.FrameHeight
            };

            this.utilitiesPort = DsspHttpUtilitiesService.Create(Environment);
        }
Пример #7
0
        /// <summary>
        /// Send phase of construction.
        /// </summary>
        protected override void Start()
        {
            if (_state == null)
            {
                _state = new State();
            }

            Tracer.Trace("SickLRF::Start()");

            LogInfo("Start");

            _httpUtilities = DsspHttpUtilitiesService.Create(Environment);

            //
            // Kick off the connection to the Laser Range Finder device.
            //
            SpawnIterator(0, _state.ComPort, StartLRF);

            // This service does not use base.Start() because of the way that
            // the handlers are hooked up. Also, because of this, there are
            // explicit Get and HttpGet handlers instead of using the default ones.
            // Handlers that need write or Exclusive access to state go under
            // the Exclusive group. Handlers that need read or shared access, and can be
            // Concurrent to other readers, go to the Concurrent group.
            // Other internal ports can be included in interleave so you can coordinate
            // intermediate computation with top level handlers.
            Activate(
                Arbiter.Interleave(
                    new TeardownReceiverGroup(
                        Arbiter.Receive <DsspDefaultDrop>(false, _mainPort, DropHandler)
                        ),
                    new ExclusiveReceiverGroup(
                        Arbiter.Receive <Replace>(true, _mainPort, ReplaceHandler),
                        Arbiter.Receive <LinkMeasurement>(true, _internalPort, MeasurementHandler),
                        Arbiter.ReceiveWithIterator <LinkPowerOn>(true, _internalPort, PowerOn),
                        Arbiter.ReceiveWithIterator <Exception>(true, _internalPort, ExceptionHandler)),
                    new ConcurrentReceiverGroup(
                        Arbiter.Receive <DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler),
                        Arbiter.ReceiveWithIterator <Subscribe>(true, _mainPort, SubscribeHandler),
                        Arbiter.ReceiveWithIterator <ReliableSubscribe>(true, _mainPort, ReliableSubscribeHandler),
                        Arbiter.Receive <Get>(true, _mainPort, GetHandler),
                        Arbiter.Receive <HttpGet>(true, _mainPort, HttpGetHandler),
                        Arbiter.Receive <Reset>(true, _mainPort, ResetHandler))
                    )
                );

            DirectoryInsert();
        }
Пример #8
0
        /// <summary>
        /// Service start
        /// </summary>
        protected override void Start()
        {
            base.Start();   // start MainPortInterleave; wireup [ServiceHandler] methods

            if (_state == null)
            {
                _state = new AnimatedHeadServiceState();
                _state.AnimatedHeadServiceConfig          = new AnimatedHeadConfig();
                _state.AnimatedHeadServiceConfig.CommPort = 0;

                SaveState(_state);
            }
            else
            {
                // Clear old Animated Head readings
                //_state.Quaternion = null;
                _state.Connected = false;
            }

            _httpUtilities = DsspHttpUtilitiesService.Create(Environment);

            if (_state.AnimatedHeadServiceConfig == null)
            {
                _state.AnimatedHeadServiceConfig = new AnimatedHeadConfig();
            }

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

            _ahConnection = new AnimatedHeadConnection(_state.AnimatedHeadServiceConfig, _ahDataPort);

            SpawnIterator(ConnectToAnimatedHead);

            //SpawnIterator(TestAnimatedHead);

            // if we have anything coming from Arduino - the _ahDataPort Arbiter.Receive<string[]> and others must be operational:

            // Listen on the main port for requests and call the appropriate handler.

            MainPortInterleave.CombineWith(new Interleave(new ExclusiveReceiverGroup(
                                                              Arbiter.Receive <string[]>(true, _ahDataPort, DataReceivedHandler),
                                                              Arbiter.Receive <Exception>(true, _ahDataPort, ExceptionHandler),
                                                              Arbiter.Receive <string>(true, _ahDataPort, MessageHandler)
                                                              ),
                                                          new ConcurrentReceiverGroup()));

            //base.Start(); // can't have it here, we already started mainInterleave and added to directory via DirectoryInsert
        }
Пример #9
0
        protected override void Start()
        {
            if (_state == null)
            {
                _state = new ColorSegmentState();
            }
            else
            {
                for (int set = 0; set < _state.Colors.Count; set++)
                {
                    ColorSet colorSet = _state.Colors[set];

                    for (int index = 0; index < colorSet.Colors.Count; index++)
                    {
                        ColorDefinition color = colorSet.Colors[index];
                        if (!color.Validate())
                        {
                            colorSet.Colors.RemoveAt(index);
                            index--;
                        }
                    }

                    if (colorSet.Colors.Count == 0)
                    {
                        _state.Colors.RemoveAt(set);
                        set--;
                    }
                }
                _state.UpdateColorSetMap();
                _state.ImageSource     = null;
                _state.Processing      = false;
                _state.FrameCount      = 0;
                _state.DroppedFrames   = 0;
                _state.FoundColorAreas = null;
            }

            _utilitiesPort = DsspHttpUtilitiesService.Create(Environment);

            _fwdPort = ServiceForwarder <ColorSegmentOperations>(ServiceInfo.Service);

            base.Start();

            Activate <ITask>(
                Arbiter.Receive <webcam.UpdateFrame>(true, _webcamNotify, OnWebcamUpdateFrame)
                );
            _webcamPort.Subscribe(_webcamNotify, typeof(webcam.UpdateFrame));
        }
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
            _notificationTarget = new simengine.SimulationEnginePort();
            _utilitiesPort      = DsspHttpUtilitiesService.Create(Environment);
            simengine.SimulationEngine.GlobalInstancePort.Subscribe(ServiceInfo.PartnerList, _notificationTarget);

            // dont start listening to DSSP operations, other than drop, until notification of entity
            Activate(new Interleave(
                         new TeardownReceiverGroup
                         (
                             Arbiter.Receive <simengine.InsertSimulationEntity>(false, _notificationTarget, InsertEntityNotificationHandlerFirstTime),
                             Arbiter.Receive <dssp.DsspDefaultDrop>(false, _mainPort, DefaultDropHandler)
                         ),
                         new ExclusiveReceiverGroup(),
                         new ConcurrentReceiverGroup()
                         ));
        }
        /// <summary>
        /// The startup method for the text to speech service
        /// </summary>
        protected override void Start()
        {
            if (_state == null)
            {
                _state        = new TextToSpeechState();
                _state.Volume = TextToSpeechState.DefaultVolume;
            }

            InitTextToSpeech();

            _utilities = DsspHttpUtilitiesService.Create(Environment);

            // Set up internal port
            Activate(
                Arbiter.Receive <SayTextSynch>(true, _sayTextSynchPort, InternalSayTextSynchHandler)
                );

            base.Start();
        }
        /// <summary>
        /// Service start
        /// </summary>
        protected override void Start()
        {
            base.Start();

            // Needed for HttpPost
            this.httpUtilities = DsspHttpUtilitiesService.Create(Environment);

            // Register handlers for notification from speech recognizer
            MainPortInterleave.CombineWith(new Interleave(
                                               new ExclusiveReceiverGroup(
                                                   Arbiter.Receive <sr.Replace>(true, this.speechRecoNotifyPort, this.SpeechRecognizerReplaceHandler),
                                                   Arbiter.Receive <sr.SpeechDetected>(true, this.speechRecoNotifyPort, this.SpeechDetectedHandler),
                                                   Arbiter.Receive <sr.SpeechRecognized>(true, this.speechRecoNotifyPort, this.SpeechRecognizedHandler),
                                                   Arbiter.Receive <sr.SpeechRecognitionRejected>(true, this.speechRecoNotifyPort, this.SpeechRecognitionRejectedHandler),
                                                   Arbiter.Receive <sr.BeamDirectionChanged>(true, this.speechRecoNotifyPort, this.BeamDirectionChangedHandler)),
                                               new ConcurrentReceiverGroup()));

            this.speechRecoPort.Subscribe(this.speechRecoNotifyPort);
        }
Пример #13
0
        /// <summary>
        /// Service start
        /// </summary>
        protected override void Start()
        {
            if (_state == null)
            {
                _state = new ChrUm6OrientationSensorState();
                _state.ChrUm6OrientationSensorConfig          = new ChrUm6OrientationSensorConfig();
                _state.ChrUm6OrientationSensorConfig.CommPort = 0;

                SaveState(_state);
            }
            else
            {
                // Clear old Chr readings
                _state.Quaternion = null;
            }

            _httpUtilities = DsspHttpUtilitiesService.Create(Environment);

            if (_state.ChrUm6OrientationSensorConfig == null)
            {
                _state.ChrUm6OrientationSensorConfig = new ChrUm6OrientationSensorConfig();
            }

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

            _chrConnection = new ChrConnection(_state.ChrUm6OrientationSensorConfig, _chrDataPort);

            SpawnIterator(ConnectToChrUm6OrientationSensor);

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

            mainInterleave.CombineWith(new Interleave(new ExclusiveReceiverGroup(
                                                          Arbiter.Receive <short[]>(true, _chrDataPort, DataReceivedHandler),
                                                          Arbiter.Receive <Exception>(true, _chrDataPort, ExceptionHandler),
                                                          Arbiter.Receive <string>(true, _chrDataPort, MessageHandler)
                                                          ),
                                                      new ConcurrentReceiverGroup()));

            //base.Start(); -- can't have it here, we already started mainInterleave and added to directory via DirectoryInsert
        }
Пример #14
0
        /// <summary>
        /// Service startup
        /// </summary>
        protected override void Start()
        {
            _fwdPort       = ServiceForwarder <webcam.WebCamOperations>(ServiceInfo.Service);
            _utilitiesPort = DsspHttpUtilitiesService.Create(Environment);

            Uri httpAlias = ServiceInfo.HttpServiceAlias;

            if (httpAlias != null)
            {
                _prefix            = httpAlias.AbsolutePath;
                _alternatePrefixes = AlternateContractServiceInfo.ConvertAll <string>(
                    delegate(ServiceInfoType alternate)
                {
                    return(alternate.HttpServiceAlias.AbsolutePath);
                }
                    );
            }

            try
            {
                _streamPort = mdwebcam.ReadStream.Create(_state.CaptureFile, Environment.TaskQueue);
            }
            catch (Exception e)
            {
                LogError("Unable to open stream file: " + e.Message);
                base.StartFailed();
                return;
            }

            base.Start();

            base.MainPortInterleave.CombineWith(
                new Interleave(
                    new ExclusiveReceiverGroup(
                        Arbiter.Receive <mdwebcam.Frame>(true, _streamPort, ReadFrameHandler)
                        ),
                    new ConcurrentReceiverGroup()
                    )
                );
        }
Пример #15
0
        /// <summary>
        /// Complete second phase startup for this service
        /// </summary>
        protected override void Start()
        {
            _fwdPort    = ServiceForwarder <WebCamServiceOperations>(ServiceInfo.Service);
            _altFwdPort = ServiceForwarder <webcam.WebCamOperations>(AlternateContractServiceInfo[0].Service);

            _utilitiesPort = DsspHttpUtilitiesService.Create(Environment);

            _prefix          = new Uri(ServiceInfo.Service).AbsolutePath;
            _alternatePrefix = new Uri(AlternateContractServiceInfo[0].Service).AbsolutePath;

            if (_state == null)
            {
                _state = new WebCamState();
            }

            base.ActivateDsspOperationHandlers();

            if (_state.FramesOnDemand)
            {
                _framesOnDemand = true;
                Activate(Arbiter.ReceiveWithIterator(true, _framePort, OnDemandFrameHandler));
            }
            else
            {
                base.MainPortInterleave.CombineWith(
                    Arbiter.Interleave(
                        new TeardownReceiverGroup(),
                        new ExclusiveReceiverGroup
                        (
                            Arbiter.Receive(true, _framePort, FrameHandler)
                        ),
                        new ConcurrentReceiverGroup()
                        )
                    );
            }

            StartPipeServer();

            SpawnIterator(_state, GetInitialState);
        }
Пример #16
0
        /// <summary>
        /// Service start method
        /// </summary>
        protected override void Start()
        {
            if (_state == null)
            {
                _state = new IpCameraState();
            }

            _utilitiesPort = DsspHttpUtilitiesService.Create(Environment);

            Uri httpAlias = ServiceInfo.HttpServiceAlias;

            if (httpAlias != null)
            {
                _prefix          = httpAlias.AbsolutePath;
                _alternatePrefix = AlternateContractServiceInfo[0].HttpServiceAlias.AbsolutePath;
            }
            else
            {
                LogError(LogGroups.Activation, "Service requires HTTP transport");
                DefaultDropHandler(new DsspDefaultDrop());
                return;
            }

            base.Start();

            MainPortInterleave.CombineWith(
                new Interleave(
                    new ExclusiveReceiverGroup(
                        Arbiter.Receive <Bitmap>(true, _imagePort, ImageHandler)
                        ),
                    new ConcurrentReceiverGroup(
                        Arbiter.Receive <DateTime>(true, _imagePort, GetImageHandler)
                        )
                    )
                );

            _imagePort.Post(DateTime.UtcNow);
        }
Пример #17
0
        /// <summary>
        /// Start initializes SimulatedDepthcamService and listens for drop messages
        /// </summary>
        protected override void Start()
        {
            const double KinectMaxValidDepthMm = 4000.0;
            const double KinectMinValidDepthMm = 800.0;

            if (this._state == null)
            {
                // no config file found, initialize default state according to KinectReservedSampleValues
                this._state = new DepthCamSensorState();
                this._state.MaximumRange             = KinectMaxValidDepthMm / 1000.0;
                this._state.MinimumRange             = KinectMinValidDepthMm / 1000.0;
                this._state.FurtherThanMaxDepthValue = (short)4095.0;
                this._state.NearerThanMinDepthValue  = (short)0.0;

                this.SaveState(this._state);
            }

            this._physicsEngine = physics.PhysicsEngine.GlobalInstance;
            _notificationTarget = new simengine.SimulationEnginePort();

            utilitiesPort = DsspHttpUtilitiesService.Create(Environment);

            // PartnerType.Service is the entity instance name.
            simengine.SimulationEngine.GlobalInstancePort.Subscribe(ServiceInfo.PartnerList, _notificationTarget);


            // dont start listening to DSSP operations, other than drop, until notification of entity
            Activate(new Interleave(
                         new TeardownReceiverGroup
                         (
                             Arbiter.Receive <simengine.InsertSimulationEntity>(false, _notificationTarget, InsertEntityNotificationHandlerFirstTime),
                             Arbiter.Receive <dssp.DsspDefaultDrop>(false, _mainPort, DefaultDropHandler)
                         ),
                         new ExclusiveReceiverGroup(),
                         new ConcurrentReceiverGroup()
                         ));
        }
Пример #18
0
        private void StartBehavior()
        {
            _fwdPort       = ServiceForwarder <Srv1CameraServiceOperations>(ServiceInfo.Service);
            _utilitiesPort = DsspHttpUtilitiesService.Create(Environment);

            if (_state == null)
            {
                _state = new Srv1CameraState();
            }
            // Listen on the main port for requests and call the appropriate handler.

            Activate(
                Arbiter.Interleave(
                    new TeardownReceiverGroup(
                        Arbiter.Receive <DsspDefaultDrop>(false, _mainPort, DropHandler)
                        ),
                    new ExclusiveReceiverGroup
                    (
                        Arbiter.ReceiveWithIterator <Replace>(true, _mainPort, ReplaceHandler),
                        Arbiter.ReceiveWithIterator <UpdateDevice>(true, _mainPort, UpdateDeviceHandler),
                        Arbiter.ReceiveWithIterator <UpdateFormat>(true, _mainPort, UpdateFormatHandler),
                        Arbiter.Receive(true, _framePort, FrameHandler),
                        Arbiter.ReceiveWithIterator <HttpPost>(true, _mainPort, HttpPostHandler)
                    ),
                    new ConcurrentReceiverGroup
                    (
                        Arbiter.ReceiveWithIterator <Get>(true, _mainPort, GetHandler),
                        Arbiter.ReceiveWithIterator <QueryFrame>(true, _mainPort, QueryFrameHandler),
                        Arbiter.ReceiveWithIterator <UpdateFrame>(true, _mainPort, UpdateFrameHandler),
                        Arbiter.ReceiveWithIterator <HttpGet>(true, _mainPort, HttpGetHandler),
                        Arbiter.ReceiveWithIterator <Subscribe>(true, _mainPort, SubscribeHandler),
                        Arbiter.Receive <DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler)
                    ))
                );

            SpawnIterator(_state, GetInitialState);
        }
Пример #19
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);
            }

            // 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();
            }


            // 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();

            //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()
                                           ));
        }