Exemplo n.º 1
0
        // if XNA is being used, we need to do quite a bit of logic to make sure that the correct characters are output
        private static void KeyDownHandler(Keys key)
        {
            switch (key)
            {
            case Keys.LeftShift:
            case Keys.RightShift:
                Shift = true;
                Alt   = true;
                break;

            case Keys.CapsLock:
                Caps = true;
                Alt  = true;
                break;
            }
            CharReceived?.Invoke(ResolveChar(@key));
        }
Exemplo n.º 2
0
        public async void ReceiveMessages()
        {
            try
            {
                while (isListening)
                {
                    uint sizeFieldCount = 0;
                    try
                    {
                        sizeFieldCount = await dataReader.LoadAsync(1);
                    }
                    catch (Exception e)
                    {
                        // ignore normal socket disconnections
                        if (e.HResult != -2147023901)
                        {
                            throw;
                        }

                        continue;
                    }

                    if (sizeFieldCount != 1)
                    {
                        isListening = false;
                        this.OnDisconnected?.Invoke(this.currentConnection);
                        break;
                    }

                    uint val = dataReader.ReadByte();
                    if (val < 255)
                    {
                        CharReceived?.Invoke((char)val);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                this.Terminate();
            }
        }
Exemplo n.º 3
0
        private void SendBack()
        {
            byte[] data = receiveFifo.ToArray();
            switch (data[2])
            {
            case 0x20:     // SYSLINK_OW_SCAN
                byte[] OwScanData = CreateMessage(0x20, 0x01, new byte[] { 0x00 });
                for (int i = 0; i < OwScanData.Length; ++i)
                {
                    CharReceived?.Invoke((byte)OwScanData[i]);
                }
                receiveFifo.Clear();
                break;

            default:
                while (receiveFifo.Count > 0)
                {
                    CharReceived?.Invoke((byte)receiveFifo.Dequeue());
                }
                break;
            }

            this.Log(LogLevel.Noisy, "Complete data sent back!");
        }
Exemplo n.º 4
0
 protected void TransmitCharacter(byte character)
 {
     CharReceived?.Invoke(character);
 }
Exemplo n.º 5
0
 private void DefineRegisters()
 {
     Register.Status.Define(this, 0xC0, "USART_SR")
     .WithTaggedFlag("PE", 0)
     .WithTaggedFlag("FE", 1)
     .WithTaggedFlag("NF", 2)
     .WithFlag(3, FieldMode.Read, valueProviderCallback: _ => false, name: "ORE")     // we assume no receive overruns
     .WithTaggedFlag("IDLE", 4)
     .WithFlag(5, FieldMode.Read | FieldMode.WriteZeroToClear, name: "RXNE", valueProviderCallback: _ =>
     {
         return(readFifoNotEmpty);
     })                                                                          // as these two flags are WZTC, we cannot just calculate their results
     .WithFlag(6, out transmissionComplete, FieldMode.Read | FieldMode.WriteZeroToClear, name: "TC")
     .WithFlag(7, FieldMode.Read, valueProviderCallback: _ => true, name: "TXE") // we always assume "transmit data register empty"
     .WithTaggedFlag("LBD", 8)
     .WithTaggedFlag("CTS", 9)
     .WithReservedBits(10, 22)
     .WithWriteCallback((_, __) => Update())
     ;
     Register.Data.Define(this, name: "USART_DR")
     .WithValueField(0, 9, valueProviderCallback: _ =>
     {
         byte value = 0;
         lock (receiveFifo)
         {
             if (receiveFifo.Count > 0)
             {
                 value = receiveFifo.Dequeue();
                 Update();
             }
             readFifoNotEmpty = receiveFifo.Count > 0;
         }
         return(value);
     }, writeCallback: (_, value) =>
     {
         if (!usartEnabled.Value && !transmitterEnabled.Value)
         {
             this.Log(LogLevel.Warning, "Trying to transmit a character, but the transmitter is not enabled. dropping.");
             return;
         }
         CharReceived?.Invoke((byte)value);
         transmissionComplete.Value = true;
         Update();
     }, name: "DR"
                     )
     ;
     Register.BaudRate.Define(this, name: "USART_BRR")
     .WithValueField(0, 4, out dividerFraction, name: "DIV_Fraction")
     .WithValueField(4, 12, out dividerMantissa, name: "DIV_Mantissa")
     ;
     Register.Control1.Define(this, name: "USART_CR1")
     .WithTaggedFlag("SBK", 0)
     .WithTaggedFlag("RWU", 1)
     .WithFlag(2, out receiverEnabled, name: "RE")
     .WithFlag(3, out transmitterEnabled, name: "TE")
     .WithTaggedFlag("IDLEIE", 4)
     .WithFlag(5, out receiverNotEmptyInterruptEnabled, name: "RXNEIE")
     .WithFlag(6, out transmissionCompleteInterruptEnabled, name: "TCIE")
     .WithFlag(7, out transmitDataRegisterEmptyInterruptEnabled, name: "TXEIE")
     .WithTaggedFlag("PEIE", 8)
     .WithEnumField(9, 1, out paritySelection, name: "PS")
     .WithFlag(10, out parityControlEnabled, name: "PCE")
     .WithTaggedFlag("WAKE", 11)
     .WithTaggedFlag("M", 12)
     .WithFlag(13, out usartEnabled, name: "UE")
     .WithReservedBits(14, 1)
     .WithEnumField(15, 1, out oversamplingMode, name: "OVER8")
     .WithReservedBits(16, 16)
     .WithWriteCallback((_, __) => Update())
     ;
     Register.Control2.Define(this, name: "USART_CR2")
     .WithTag("ADD", 0, 4)
     .WithReservedBits(5, 1)
     .WithTaggedFlag("LBDIE", 6)
     .WithReservedBits(7, 1)
     .WithTaggedFlag("LBCL", 8)
     .WithTaggedFlag("CPHA", 9)
     .WithTaggedFlag("CPOL", 10)
     .WithTaggedFlag("CLKEN", 11)
     .WithEnumField(12, 2, out stopBits, name: "STOP")
     .WithTaggedFlag("LINEN", 14)
     .WithReservedBits(15, 17)
     ;
 }
Exemplo n.º 6
0
 // If MonoGame is in use, we can easily take advantage of its build-in input handler
 private static void TextInputHandler(object s, EventArgs e)
 {
     CharReceived?.Invoke((char)e.GetType().GetField("Character").GetValue(e));
 }
Exemplo n.º 7
0
 private static void KeyHeldHandler(Keys key)
 {
     CharReceived?.Invoke(ResolveChar(key));
 }
Exemplo n.º 8
0
 public void WriteDoubleWord(long offset, uint value)
 {
     this.NoisyLog("Received 0x{0:X}", value);
     CharReceived?.Invoke((byte)value);
 }