private void ProcessEvent(byte[] content) { var eventType = (AciEventType)content[0]; AciEvent aciEvent = null; switch (eventType) { case AciEventType.BondStatus: aciEvent = new BondStatusEvent(content); HandleBondStatusEvent((BondStatusEvent)aciEvent); break; case AciEventType.CommandResponse: aciEvent = new CommandResponseEvent(content); HandleCommandResponseEvent((CommandResponseEvent)aciEvent); break; case AciEventType.Connected: aciEvent = new AciEvent(content); State = Nrf8001State.Connected; break; case AciEventType.DataCredit: aciEvent = new DataCreditEvent(content); HandleDataCreditEvent((DataCreditEvent)aciEvent); break; case AciEventType.DataReceived: aciEvent = new DataReceivedEvent(content); HandleDataReceivedEvent((DataReceivedEvent)aciEvent); break; case AciEventType.DeviceStarted: aciEvent = new DeviceStartedEvent(content); HandleDeviceStartedEvent((DeviceStartedEvent)aciEvent); break; case AciEventType.Disconnected: aciEvent = new AciEvent(content); State = Nrf8001State.Standby; break; case AciEventType.PipeStatus: aciEvent = new AciEvent(content); OpenPipesBitmap = aciEvent.Content.ToUnsignedLong(1); ClosedPipesBitmap = aciEvent.Content.ToUnsignedLong(9); break; default: aciEvent = new AciEvent(content); break; } Debug.Print("Event: " + eventType.GetName()); if (AciEventReceived != null) { AciEventReceived(aciEvent); } }
private void HandleCommandResponseEvent(CommandResponseEvent aciEvent) { if (aciEvent.Command == AciOpCode.Setup) { if (aciEvent.StatusCode == AciStatusCode.TransactionContinue) { Setup(_setupData[_setupIndex++]); } else if (aciEvent.StatusCode != AciStatusCode.TransactionComplete) { throw new Nrf8001Exception("Setup data invalid."); } } }