Ejemplo n.º 1
0
        private void Validate(string chanLstBinPath)
        {
            var    baseDir = Path.GetDirectoryName(chanLstBinPath);
            string errors  = "";

            foreach (var entry in crcOffsetByRelPath)
            {
                var crcOffset   = entry.Value;
                var expectedCrc = BitConverter.ToUInt16(this.content, crcOffset);
                if (expectedCrc == 0)
                {
                    continue;
                }

                var filePath = baseDir + entry.Key;
                if (!File.Exists(filePath))
                {
                    continue;
                }
                var data      = File.ReadAllBytes(filePath);
                var length    = Math.Min(data.Length, versionMajor <= 12 ? 0x6000 : 0x145A00);
                var actualCrc = ModbusCrc16.Calc(data, 0, length);
                if (actualCrc != expectedCrc)
                {
                    var msg = $"chanLst.bin: stored CRC for {entry.Key} is {expectedCrc:x4} but calculated {actualCrc:x4}";
                    errors += "\n" + msg;
                }
            }

            if (errors != "")
            {
                this.log.Invoke(errors);
                //throw new FileLoadException(errors);
            }
        }
Ejemplo n.º 2
0
        public void Save(string chanLstBinPath)
        {
            var baseDir = Path.GetDirectoryName(chanLstBinPath);

            foreach (var entry in crcOffsetByRelPath)
            {
                var path   = baseDir + entry.Key;
                var data   = File.ReadAllBytes(path);
                var length = Math.Min(data.Length, versionMajor <= 12 ? 0x6000 : 0x145A00);
                var crc    = ModbusCrc16.Calc(data, 0, length);
                var off    = entry.Value;
                content[off]     = (byte)crc;
                content[off + 1] = (byte)(crc >> 8);
            }
            File.WriteAllBytes(chanLstBinPath, content);
        }