Example #1
0
        protected override bool LookForBlock()
        {
            var opm = new Regex(@"(OP: *01\r?\n)+");
            var rm  = new Regex(@"[a-fA-F0-9]+\r?\n");

            var ds = string.Join("", Data.ToArray());

            if (opm.Match(ds).Success)
            {
                Data.Clear();
                return(false);
            }

            var match = rm.Match(ds);

            if (match.Success)
            {
                var end  = @"\r?\n";
                var endM = new Regex(end);

                var endMatch  = endM.Match(match.Value);
                var hexString = match.Value.Substring(0, endMatch.Index);

                Data.Clear();

                LastBlockBytes = AxLEHelper.StringToByteArray(hexString);

                return(true);
            }

            return(false);
        }
        protected override bool LookForBlock()
        {
            // Old "OP: 01\r\n", New: "OP: 01, 50, 8\r\n"
            var opm = new Regex(@"(OP: *01,? ?\d*,? ?\d*\r?\n)+");
            var rm  = new Regex(@"[a-fA-F0-9]+\r?\n");

            var ds = string.Join("", Data.ToArray());

            if (opm.Match(ds).Success)
            {
                Data.Clear();
                return(false);
            }

            var match = rm.Match(ds);

            if (match.Success)
            {
                var end  = @"\r?\n";
                var endM = new Regex(end);

                var endMatch = endM.Match(match.Value);
                var endIndex = endMatch.Index;

                var nibbleCount = endIndex;
                if ((nibbleCount & 1) != 0)
                {
                    Console.WriteLine($"WARNING: Packet contained odd number of nibbles, ignoring last: {nibbleCount}");
                    nibbleCount &= ~1;
                }
                var hexString = match.Value.Substring(0, nibbleCount);

                LastBlockBytes = AxLEHelper.StringToByteArray(hexString);

                Data.Clear();

                // Consume line ending
                if (ds[endIndex] == '\r')
                {
                    endIndex++;
                }
                if (ds[endIndex] == '\n')
                {
                    endIndex++;
                }

                // Keep any residual characters for next packet
                if (endIndex < ds.Length)
                {
                    Data.Add(ds.Substring(endIndex));
                }

                return(true);
            }

            return(false);
        }
Example #3
0
        public override async Task SendCommand()
        {
            string cmd;

            if (_start >= 0 && _height >= 0)
            {
                cmd = $"OI{AxLEHelper.ShortToHexWordsLE((ushort)_offset)}{AxLEHelper.ByteToHex((byte)_start)}{AxLEHelper.ByteToHex((byte)_height)}";
            }
            else
            {
                cmd = $"OI{AxLEHelper.ShortToHexWordsLE((ushort)_offset)}";
            }
            await Device.TxUart(cmd);
        }
Example #4
0
 public WriteBitmap(byte[] data, int offset = 0)
 {
     //commandStrings.Add($"OIFFFF");  // Temporarily disable icon (in case of interruption)
     if (offset < 0 || offset % 8 != 0)
     {
         throw new ArgumentException("Offset must be a positive multiple of 8");
     }
     if (data.Length % 8 != 0)
     {
         throw new ArgumentException("Data length must be a multiple of 8");
     }
     for (var i = 0; i < data.Length; i += 8)
     {
         commandStrings.Add($"OW{(offset + i) / 8:X2}{AxLEHelper.ByteArrayToString(data, i, 8)}");
     }
     //commandStrings.Add($"OI{AxLEHelper.ShortToHexWordsLE((ushort)offset)}");
 }
Example #5
0
        protected override bool LookForEnd()
        {
            // Check for end
            var regex = @"[a-fA-F0-9]*\r?\n";

            var rm      = new Regex(regex);
            var matches = rm.Matches(Data.Last());

            if (matches.Count == 0)
            {
                return(false);
            }

            // Match entire block and process
            var ds = string.Join("", Data.ToArray());

            regex = @"[a-fA-F0-9]+\r?\n";

            rm      = new Regex(regex);
            matches = rm.Matches(ds);
            if (matches.Count > 0)
            {
                var match = matches[0].Value;
                var end   = @"\r?\n";
                var endM  = new Regex(end);

                var endMatch  = endM.Matches(match)[0];
                var hexString = match.Substring(0, endMatch.Index);

                BlockBytes = AxLEHelper.StringToByteArray(hexString);

                return(BlockBytes.Length == 512);
            }

            return(false);
        }
Example #6
0
 public override async Task SendCommand()
 {
     await Device.TxUart($"S{AxLEHelper.ShortToHexWordsLE(_offset)}");
 }
Example #7
0
 public override async Task SendCommand()
 {
     await Device.TxUart(AxLEHelper.IntToHexWordsLE(_epochPeriod));
 }
 public override async Task SendCommand()
 {
     await Device.TxUart($"OD{AxLEHelper.ShortToHexWordsLE(_offset)}{_startCol:X2}{_startRow:X2}{_cols:X2}{_rows:X2}{_span:X2}");
 }