Esempio n. 1
0
 protected override void SetCallback(Myro.Services.Generic.Vector.SetRequestInfo request)
 {
     if (request is vector.SetAllRequestInfo)
     {
         Activate(Arbiter.Choice(
                      _scribblerPort.SetAllLEDs(new brick.SetAllLedsBody()
         {
             LeftLED = _state.GetBool(0), CenterLED = _state.GetBool(1), RightLED = _state.GetBool(2)
         }),
                      delegate(DefaultUpdateResponseType success) { },
                      delegate(Fault failure) { LogError(failure); }));
     }
     else if (request is vector.SetElementsRequestInfo)
     {
         vector.SetElementsRequestInfo info = (vector.SetElementsRequestInfo)request;
         if (info.Indices.Count > 1)
         {
             Activate(Arbiter.Choice(
                          _scribblerPort.SetAllLEDs(new brick.SetAllLedsBody()
             {
                 LeftLED = _state.GetBool(0), CenterLED = _state.GetBool(1), RightLED = _state.GetBool(2)
             }),
                          delegate(DefaultUpdateResponseType success) { },
                          delegate(Fault failure) { LogError(failure); }));
         }
         else if (info.Indices.Count == 1)
         {
             Activate(Arbiter.Choice(
                          _scribblerPort.SetLED(new brick.SetLedBody()
             {
                 LED = info.Indices[0], State = _state.GetBool(info.Indices[0])
             }),
                          delegate(DefaultUpdateResponseType success) { },
                          delegate(Fault failure) { LogError(failure); }));
         }
     }
 }
Esempio n. 2
0
 protected override IEnumerator <ITask> SetCallback(vector.SetRequestInfo request, PortSet <vector.CallbackResponseType, Fault> responsePort)
 {
     if (request is vector.SetAllRequestInfo)
     {
         Activate(Arbiter.Choice(
                      _scribblerPort.SetAllLEDs(new brick.SetAllLedsBody()
         {
             LeftLED = _state.GetBool(0), CenterLED = _state.GetBool(1), RightLED = _state.GetBool(2)
         }),
                      delegate(DefaultUpdateResponseType success) { responsePort.Post(vector.CallbackResponseType.Instance); },
                      delegate(Fault failure) { responsePort.Post(failure); }));
     }
     else if (request is vector.SetElementsRequestInfo)
     {
         vector.SetElementsRequestInfo info = (vector.SetElementsRequestInfo)request;
         int setLEDScribblerIndex           = -1; // will be set to -2 for set all
         var responses  = new PortSet <DefaultUpdateResponseType, Fault>();
         int nResponses = 0;
         foreach (int i in info.Indices)
         {
             if (i >= 0)
             {
                 if (i <= 2)
                 {
                     if (setLEDScribblerIndex >= 0)
                     {
                         setLEDScribblerIndex = -2;
                     }
                     else
                     {
                         setLEDScribblerIndex = i;
                     }
                 }
                 else if (i == 3)
                 {
                     nResponses++;
                     Activate(Arbiter.Choice(_scribblerPort.SetLEDFront(_state.GetBool(3)),
                                             delegate(DefaultUpdateResponseType s) { responses.Post(DefaultUpdateResponseType.Instance); },
                                             delegate(Fault f) { responses.Post(f); }));
                 }
                 else if (i == 4)
                 {
                     nResponses++;
                     Activate(Arbiter.Choice(_scribblerPort.SetLEDBack(RSUtils.UnnormalizeDouble(_state.Get(4))),
                                             delegate(DefaultUpdateResponseType s) { responses.Post(DefaultUpdateResponseType.Instance); },
                                             delegate(Fault f) { responses.Post(f); }));
                 }
             }
         }
         if (setLEDScribblerIndex == -2)
         {
             nResponses++;
             Activate(Arbiter.Choice(
                          _scribblerPort.SetAllLEDs(new brick.SetAllLedsBody()
             {
                 LeftLED = _state.GetBool(0), CenterLED = _state.GetBool(1), RightLED = _state.GetBool(2)
             }),
                          delegate(DefaultUpdateResponseType s) { responses.Post(DefaultUpdateResponseType.Instance); },
                          delegate(Fault f) { responses.Post(f); }));
         }
         else if (setLEDScribblerIndex >= 0)
         {
             nResponses++;
             Activate(Arbiter.Choice(
                          _scribblerPort.SetLED(new brick.SetLedBody()
             {
                 LED = setLEDScribblerIndex, State = _state.GetBool(setLEDScribblerIndex)
             }),
                          delegate(DefaultUpdateResponseType s) { responses.Post(DefaultUpdateResponseType.Instance); },
                          delegate(Fault f) { responses.Post(f); }));
         }
         Activate(Arbiter.MultipleItemReceive(responses, nResponses,
                                              delegate(ICollection <DefaultUpdateResponseType> ss, ICollection <Fault> fs)
         {
             if (fs.Count == 0)
             {
                 responsePort.Post(vector.CallbackResponseType.Instance);
             }
             else
             {
                 responsePort.Post(fs.First());
                 ////f.Readon could be null
                 //var reasons = new List<ReasonText>();
                 //foreach (var f in fs)
                 //    if (f.Reason != null)
                 //        reasons.AddRange(f.Reason.AsEnumerable());
                 //responsePort.Post(new Fault() { Detail = new Detail() { Any = fs.ToArray() }, Reason = reasons.ToArray() });
             }
         }));
     }
     yield break;
 }