/// <summary> /// Creates the ECC200 error correction for an encoded message. /// </summary> /// <param name="codewords">The codewords.</param> /// <param name="symbolInfo">information about the symbol to be encoded</param> /// <returns>the codewords with interleaved error correction.</returns> public static String encodeECC200(String codewords, SymbolInfo symbolInfo) { if (codewords.Length != symbolInfo.dataCapacity) { throw new ArgumentException( "The number of codewords does not match the selected symbol"); } var sb = new StringBuilder(symbolInfo.dataCapacity + symbolInfo.errorCodewords); sb.Append(codewords); int blockCount = symbolInfo.getInterleavedBlockCount(); if (blockCount == 1) { String ecc = createECCBlock(codewords, symbolInfo.errorCodewords); sb.Append(ecc); } else { sb.Length = sb.Capacity; int[] dataSizes = new int[blockCount]; int[] errorSizes = new int[blockCount]; int[] startPos = new int[blockCount]; for (int i = 0; i < blockCount; i++) { dataSizes[i] = symbolInfo.getDataLengthForInterleavedBlock(i + 1); errorSizes[i] = symbolInfo.getErrorLengthForInterleavedBlock(i + 1); startPos[i] = 0; if (i > 0) { startPos[i] = startPos[i - 1] + dataSizes[i]; } } for (int block = 0; block < blockCount; block++) { var temp = new StringBuilder(dataSizes[block]); for (int d = block; d < symbolInfo.dataCapacity; d += blockCount) { temp.Append(codewords[d]); } String ecc = createECCBlock(temp.ToString(), errorSizes[block]); int pos = 0; for (int e = block; e < errorSizes[block] * blockCount; e += blockCount) { sb[symbolInfo.dataCapacity + e] = ecc[pos++]; } } } return(sb.ToString()); }
/// <summary> /// Creates the ECC200 error correction for an encoded message. /// </summary> /// <param name="codewords">The codewords.</param> /// <param name="symbolInfo">information about the symbol to be encoded</param> /// <returns>the codewords with interleaved error correction.</returns> public static String encodeECC200(String codewords, SymbolInfo symbolInfo) { if (codewords.Length != symbolInfo.dataCapacity) { throw new ArgumentException( "The number of codewords does not match the selected symbol"); } var sb = new StringBuilder(symbolInfo.dataCapacity + symbolInfo.errorCodewords); sb.Append(codewords); int blockCount = symbolInfo.getInterleavedBlockCount(); if (blockCount == 1) { String ecc = createECCBlock(codewords, symbolInfo.errorCodewords); sb.Append(ecc); } else { sb.Length = sb.Capacity; int[] dataSizes = new int[blockCount]; int[] errorSizes = new int[blockCount]; int[] startPos = new int[blockCount]; for (int i = 0; i < blockCount; i++) { dataSizes[i] = symbolInfo.getDataLengthForInterleavedBlock(i + 1); errorSizes[i] = symbolInfo.getErrorLengthForInterleavedBlock(i + 1); startPos[i] = 0; if (i > 0) { startPos[i] = startPos[i - 1] + dataSizes[i]; } } for (int block = 0; block < blockCount; block++) { var temp = new StringBuilder(dataSizes[block]); for (int d = block; d < symbolInfo.dataCapacity; d += blockCount) { temp.Append(codewords[d]); } String ecc = createECCBlock(temp.ToString(), errorSizes[block]); int pos = 0; for (int e = block; e < errorSizes[block] * blockCount; e += blockCount) { sb[symbolInfo.dataCapacity + e] = ecc[pos++]; } } } return sb.ToString(); }