/// <summary> /// Generates the EEPROM configuration. /// </summary> /// <param name="home">The home.</param> /// <returns>A tuple containing the checksum (Item1) and the raw bytes (Item2)</returns> public Tuple<ushort, byte[]> GenerateEEPROM(Home home) { _tempMemory = new List<Byte>(); //Generar toda la memoria (la memoria se genera con CRC16 a "00 00") //ConfigHeader _tempMemory.AddRange(ConfigHeader()); //NetworkConfig _tempMemory.AddRange(NetworkConfig(home)); ushort pointerStartDinamicIndex = (ushort)_tempMemory.Count; _dinamicIndex = new List<ushort>(); //fill with 00 in memory for Dinamic Index for (int i = 0; i < 13; i++) { _tempMemory.Add(0x00); _tempMemory.Add(0x00); } //DevicesConfig DevicesConfig(); //TimeOperation _dinamicIndex.Add((ushort)_tempMemory.Count); _tempMemory.AddRange(TimeOperation()); //Operation _dinamicIndex.Add((ushort)_tempMemory.Count); _tempMemory.AddRange(Operation((ushort)_tempMemory.Count)); //OperationTimeRestriction _dinamicIndex.Add((ushort)_tempMemory.Count); _tempMemory.AddRange(OperationTimeRestriction()); //OperationConditionRestrictions _dinamicIndex.Add((ushort)_tempMemory.Count); //TODO //free region _dinamicIndex.Add((ushort)_tempMemory.Count); //change directions of DinamicIndex using the DinamicIndexList DinamicIndex(pointerStartDinamicIndex); //DINAMIC END byte[] memory = _tempMemory.ToArray(); //Calculamos el tamaño en bytes ushort sizeMemory = (ushort)memory.Length; memory[3] = sizeMemory.UshortToByte(_baseConfiguration.LittleEndian)[0]; memory[4] = sizeMemory.UshortToByte(_baseConfiguration.LittleEndian)[1]; //Generar el CRC byte[] crc = new Crc16().ComputeChecksumBytes(memory, _baseConfiguration.LittleEndian); //sustituimos el valor de CRC que esta en la posicion de memoria 0x05 0x06, no hace falta contar con endianidad memory[5] = crc[0]; memory[6] = crc[1]; ushort crcResult = BitConverter.ToUInt16(crc, 0); return new Tuple<ushort,byte[]>(crcResult, memory); }
/// <summary> /// Generates the EEPROM configuration. /// </summary> /// <param name="home">The home.</param> /// <returns>A tuple containing the checksum (Item1) and the raw bytes (Item2)</returns> public Tuple <ushort, byte[]> GenerateEEPROM(Home home) { _tempMemory = new List <Byte>(); //Generar toda la memoria (la memoria se genera con CRC16 a "00 00") //ConfigHeader _tempMemory.AddRange(ConfigHeader()); //NetworkConfig _tempMemory.AddRange(NetworkConfig(home)); ushort pointerStartDinamicIndex = (ushort)_tempMemory.Count; _dinamicIndex = new List <ushort>(); //fill with 00 in memory for Dinamic Index for (int i = 0; i < 13; i++) { _tempMemory.Add(0x00); _tempMemory.Add(0x00); } //DevicesConfig DevicesConfig(); //TimeOperation _dinamicIndex.Add((ushort)_tempMemory.Count); _tempMemory.AddRange(TimeOperation()); //Operation _dinamicIndex.Add((ushort)_tempMemory.Count); _tempMemory.AddRange(Operation((ushort)_tempMemory.Count)); //OperationTimeRestriction _dinamicIndex.Add((ushort)_tempMemory.Count); _tempMemory.AddRange(OperationTimeRestriction()); //OperationConditionRestrictions _dinamicIndex.Add((ushort)_tempMemory.Count); //TODO //free region _dinamicIndex.Add((ushort)_tempMemory.Count); //change directions of DinamicIndex using the DinamicIndexList DinamicIndex(pointerStartDinamicIndex); //DINAMIC END byte[] memory = _tempMemory.ToArray(); //Calculamos el tamaño en bytes ushort sizeMemory = (ushort)memory.Length; memory[3] = sizeMemory.UshortToByte(_baseConfiguration.LittleEndian)[0]; memory[4] = sizeMemory.UshortToByte(_baseConfiguration.LittleEndian)[1]; //Generar el CRC byte[] crc = new Crc16().ComputeChecksumBytes(memory, _baseConfiguration.LittleEndian); //sustituimos el valor de CRC que esta en la posicion de memoria 0x05 0x06, no hace falta contar con endianidad memory[5] = crc[0]; memory[6] = crc[1]; ushort crcResult = BitConverter.ToUInt16(crc, 0); return(new Tuple <ushort, byte[]>(crcResult, memory)); }