Beispiel #1
0
            public override string ToString()
            {
                // work around a known issue with v001 data (from JPR001.RDY)
                var recordSize = TableType == 'v' && TableId == 1 && RecordSize == 6 ? 96 : RecordSize;

                return(string.Format("{0}{1:D3}{2:D5}{3}{4:D2}{5:D2}{6}{7:D2}{8:D2}{9:D2}",
                                     TableType,
                                     TableId,
                                     TotalCharacters,
                                     TableVersion,
                                     HeaderSize,
                                     recordSize,
                                     SynelNumericFormat.Convert(RecordCount, 3),
                                     KeyLength,
                                     KeyOffset,
                                     (Packed ? 1 : 0) + (Sorted ? 2 : 0)));
            }
Beispiel #2
0
        private ProgrammingStatus(string data)
        {
            _operationStatus = (ProgrammingOperationStatus)data[0];

            if (data.Length == 1)
            {
                return;
            }

            _operationType        = data[1];
            _fileName             = data.Substring(2, 4);
            _terminalMode         = data[6];
            _programmingModeState = data[7];
            _previousBlockNumber  = SynelNumericFormat.Convert(data.Substring(8, 2));
            _currentBlockNumber   = SynelNumericFormat.Convert(data.Substring(10, 2));
            _debugInfo            = data.Substring(12, 3);

            // Workaround for some terminals that don't always report the correct operation status code.
            if (_fileName == "Run_")
            {
                _operationStatus = ProgrammingOperationStatus.InRunMode;
            }
        }
Beispiel #3
0
            internal static RdyHeader Parse(string data, bool force)
            {
                var header = new RdyHeader();

                if (data == null)
                {
                    throw new ArgumentNullException("data");
                }

                if (data.Length != HeaderSize && !force)
                {
                    throw new ArgumentException(string.Format("The header must consist of exactly {0} characters.", HeaderSize));
                }

                header.TableType = data[0];

                int i;

                if (!int.TryParse(data.Substring(1, 3), NumberStyles.None, CultureInfo.InvariantCulture, out i) && !force)
                {
                    throw new InvalidDataException("Couldn't parse the table ID from the RDY header.");
                }
                header.TableId = i;

                if (!int.TryParse(data.Substring(4, 5), NumberStyles.None, CultureInfo.InvariantCulture, out i) && !force)
                {
                    throw new InvalidDataException("Couldn't parse the total number of characters from the RDY header.");
                }
                header.TotalCharacters = i;

                if (header.TableType == 'z')
                {
                    // z indicates a "directory file", which has a truncated header.  Exit early.
                    return(header);
                }

                header.TableVersion = data[9];

                if (!int.TryParse(data.Substring(10, 2), NumberStyles.None, CultureInfo.InvariantCulture, out i) && !force)
                {
                    throw new InvalidDataException("Couldn't parse the header size from the RDY header.");
                }
                if (i != HeaderSize && !force)
                {
                    throw new InvalidDataException(string.Format("The header size in the RDY file should state {0} but it was {1} instead.", HeaderSize, i));
                }

                if (!int.TryParse(data.Substring(12, 2), NumberStyles.None, CultureInfo.InvariantCulture, out i) && !force)
                {
                    throw new InvalidDataException("Couldn't parse the record size from the RDY header.");
                }
                header.RecordSize = i;

                // work around a known issue with v001 data (from JPR001.RDY)
                if (header.TableType == 'v' && header.TableId == 1 && header.RecordSize == 96)
                {
                    header.RecordSize = 6;
                }

                header.RecordCount = SynelNumericFormat.Convert(data.Substring(14, 3));

                if (!int.TryParse(data.Substring(17, 2), NumberStyles.None, CultureInfo.InvariantCulture, out i) && !force)
                {
                    throw new InvalidDataException("Couldn't parse the key length from the RDY header.");
                }
                header.KeyLength = i;

                if (!int.TryParse(data.Substring(19, 2), NumberStyles.None, CultureInfo.InvariantCulture, out i) && !force)
                {
                    throw new InvalidDataException("Couldn't parse the key offset from the RDY header.");
                }
                header.KeyOffset = i;

                if (!int.TryParse(data.Substring(21, 2), NumberStyles.None, CultureInfo.InvariantCulture, out i) && !force)
                {
                    throw new InvalidDataException("Couldn't parse the sorted/packed flags from the RDY header.");
                }
                header.Sorted = i == 2 || i == 3;
                header.Packed = i == 1 || i == 3;

                // Make sure the character count makes sense
                var expectedChars = HeaderSize + header.RecordCount * header.RecordSize;

                if (header.TotalCharacters != expectedChars && !force)
                {
                    throw new InvalidDataException(string.Format("The total character count doesn't match.  It was reported as {0}, but calculated as {1}.",
                                                                 header.TotalCharacters, expectedChars));
                }

                return(header);
            }
Beispiel #4
0
        public void Convert_From_SynelNumeric3_1()
        {
            var i = SynelNumericFormat.Convert("001");

            Assert.AreEqual(1, i);
        }
Beispiel #5
0
        private TerminalStatus(string data)
        {
            if (!byte.TryParse(data.Substring(0, 1), NumberStyles.None, CultureInfo.InvariantCulture, out _hardwareModel))
            {
                throw new InvalidDataException("Couldn't parse hardware model from terminal status data.");
            }

            if (!byte.TryParse(data.Substring(1, 1), NumberStyles.None, CultureInfo.InvariantCulture, out _hardwareRevision))
            {
                throw new InvalidDataException("Couldn't parse hardware revision from terminal status data.");
            }

            if (!int.TryParse(data.Substring(2, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _firmwareVersion))
            {
                throw new InvalidDataException("Couldn't parse firmware version from terminal status data.");
            }

            if (!DateTime.TryParseExact(data.Substring(7, 10), "yyMMddHHmm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _timestamp))
            {
                throw new InvalidDataException("Couldn't parse timestamp from terminal status data.");
            }

            _activeFunction = data[17];

            _buffersFull        = SynelNumericFormat.Convert(data.Substring(18, 3));
            _buffersFaulty      = SynelNumericFormat.Convert(data.Substring(21, 3));
            _buffersTransmitted = SynelNumericFormat.Convert(data.Substring(24, 3));
            _buffersEmpty       = SynelNumericFormat.Convert(data.Substring(27, 3));

            if (data[34] == 'K')
            {
                int mem;
                if (!int.TryParse(data.Substring(30, 4), NumberStyles.None, CultureInfo.InvariantCulture, out mem))
                {
                    throw new InvalidDataException("Couldn't parse memory used from terminal status data.");
                }
                _memoryUsed = mem * 1024; // assuming 'K' means KiB rather than KB
            }
            else
            {
                if (!int.TryParse(data.Substring(30, 4), NumberStyles.None, CultureInfo.InvariantCulture, out _memoryUsed))
                {
                    throw new InvalidDataException("Couldn't parse memory used from terminal status data.");
                }
            }

            _terminalType = (TerminalTypes)data[35];
            _poweredOn    = data[36] == '1';

            // TODO: what does 37-38 represent?

            _userDefinedField = data.Substring(39, 4);

            _transportType = data[43] == 'T' ? TransportType.Tcp : data[43] == 'U' ? TransportType.Udp : 0;

            int i;

            if (!int.TryParse(data.Substring(44, 2), NumberStyles.None, CultureInfo.InvariantCulture, out i))
            {
                throw new InvalidDataException("Couldn't parse the polling interval from terminal status data.");
            }
            _pollingInterval = TimeSpan.FromSeconds(i);

            _fingerprintUnitMode = (FingerprintUnitModes)data[46];
        }
Beispiel #6
0
        public void Convert_To_SynelNumeric1_0()
        {
            var s = SynelNumericFormat.Convert(0, 1);

            Assert.AreEqual("0", s);
        }
Beispiel #7
0
        public void Convert_To_SynelNumeric3_1()
        {
            var s = SynelNumericFormat.Convert(1, 3);

            Assert.AreEqual("001", s);
        }
Beispiel #8
0
        public void Convert_From_SynelNumeric3_7899()
        {
            var i = SynelNumericFormat.Convert("~99");

            Assert.AreEqual(7899, i);
        }
Beispiel #9
0
        public void Convert_From_SynelNumeric2_0()
        {
            var i = SynelNumericFormat.Convert("00");

            Assert.AreEqual(0, i);
        }
Beispiel #10
0
        public void Convert_To_SynelNumeric3_7899()
        {
            var s = SynelNumericFormat.Convert(7899, 3);

            Assert.AreEqual("~99", s);
        }
Beispiel #11
0
        public void Convert_From_SynelNumeric3_1000()
        {
            var i = SynelNumericFormat.Convert(":00");

            Assert.AreEqual(1000, i);
        }
Beispiel #12
0
        public void Convert_To_SynelNumeric3_1000()
        {
            var s = SynelNumericFormat.Convert(1000, 3);

            Assert.AreEqual(":00", s);
        }
Beispiel #13
0
        public void Convert_To_SynelNumeric2_222()
        {
            var s = SynelNumericFormat.Convert(222, 2);

            Assert.AreEqual("F2", s);
        }
Beispiel #14
0
        public void Convert_To_SynelNumeric2_200()
        {
            var s = SynelNumericFormat.Convert(200, 2);

            Assert.AreEqual("D0", s);
        }