예제 #1
0
        public virtual IEnumerator <ITask> ReceiveBluetoothMessageHandler(ReceiveBluetoothMessage query)
        {
            BluetoothMessage response = new BluetoothMessage();
            int inbox = Math.Max(1, Math.Min(10, query.Body.Mailbox)) - 1;

            nxtcmd.LegoMessageRead cmd = new nxtcmd.LegoMessageRead(inbox + 10, inbox, true);
            yield return(Arbiter.Choice(_legoBrickPort.SendNxtCommand(cmd),
                                        delegate(nxtcmd.LegoResponse ok)
            {
                nxtcmd.LegoResponseMessageRead queryResponse = nxtcmd.LegoResponse.Upcast <nxtcmd.LegoResponseMessageRead>(ok);
                if (queryResponse.Success)
                {
                    response.Mailbox = query.Body.Mailbox;
                    response.Message = queryResponse.Message;
                    query.ResponsePort.Post(response);
                }
                else
                {
                    query.ResponsePort.Post(Fault.FromException(new System.IO.IOException(queryResponse.ErrorCode.ToString())));
                }
            },
                                        delegate(Fault fault)
            {
                query.ResponsePort.Post(fault);
            }));

            yield break;
        }
        public virtual IEnumerator<ITask> ReceiveBluetoothMessageHandler(ReceiveBluetoothMessage query)
        {
            BluetoothMessage response = new BluetoothMessage();
            int inbox = Math.Max(1, Math.Min(10, query.Body.Mailbox)) - 1;

            nxtcmd.LegoMessageRead cmd = new nxtcmd.LegoMessageRead(inbox + 10, inbox, true);
            yield return Arbiter.Choice(_legoBrickPort.SendNxtCommand(cmd),
                delegate(nxtcmd.LegoResponse ok)
                {
                    nxtcmd.LegoResponseMessageRead queryResponse = nxtcmd.LegoResponse.Upcast<nxtcmd.LegoResponseMessageRead>(ok);
                    if (queryResponse.Success)
                    {
                        response.Mailbox = query.Body.Mailbox;
                        response.Message = queryResponse.Message;
                        query.ResponsePort.Post(response);
                    }
                    else
                    {
                        query.ResponsePort.Post(Fault.FromException(new System.IO.IOException(queryResponse.ErrorCode.ToString())));
                    }
                },
                delegate(Fault fault)
                {
                    query.ResponsePort.Post(fault);
                });

            yield break;
        }