Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #include <QFile>
  2. #include <QBitArray>
  3. #include <QDesktopServices>
  4. #include <QUrl>
  5. #include <QSettings>
  6. #include "CVCODEC.H" // The Convolution codec
  7.  
  8. #define ReadSize 524288 // bytes to read
  9.  
  10. bool needReverseBytes = true;
  11. bool needDiff = true;
  12.  
  13. ULONG poly_1 = 0x3c; // == 0111100
  14. ULONG poly_2 = 0x73; // == 1110011
  15.  
  16. const int MyDataSize = ReadSize / 2;
  17.  
  18. QFile file("data.raw"); // open input raw data file
  19. if(file.open(QIODevice::ReadOnly))
  20. {
  21. QFile file_output("result.bin"); // output file
  22. if(file_output.open(QIODevice::WriteOnly))
  23. {
  24. // polynoms
  25. const ULONG nasa_param[2][1] =
  26. {
  27. { poly_1 },
  28. { poly_2 }
  29. };
  30.  
  31. ConvolutionalCodec<2,1,7,8> TerraCodec(nasa_param); // Convolution codec object
  32. /*
  33. Where the template parameters:
  34. 2 - number of output streams
  35. 1 - number of input streams (bits/msg symbol)
  36. 7 - constraint length
  37. 8 - symbols per encoding group
  38. (I don't know what is it. I tried to change it, but the result does not change)
  39. */
  40. const int encodedlen = TerraCodec.getEncodedLength(MyDataSize);
  41.  
  42. QByteArray ba = file.read(ReadSize); // read raw data
  43.  
  44. if(needReverseBytes)
  45. reverseBytes(ba); // reverse bits in every byte
  46.  
  47. QBitArray bit = bytesToBits(ba); // represent data as bit array
  48. QBitArray bit_diff(bit.size(), 0);
  49.  
  50. // sum mod2
  51. if(needDiff)
  52. {
  53. for(int i=0; i<bit.size()-1; i++ )
  54. bit_diff[i] = bit[i] ^ bit[i+1];
  55. }
  56. else
  57. {
  58. for(int i=0; i<bit.size(); i++ )
  59. bit_diff[i] = bit[i];
  60. }
  61.  
  62. ba = bitsToBytes(bit_diff); // write bits into byte array
  63.  
  64. QByteArray decoded(MyDataSize, 0); // byte array for result
  65.  
  66. TerraCodec.decode((const UBYTE*)ba.constData(), (UBYTE*)decoded.data(), MyDataSize);
  67.  
  68. file_output.write(decoded); // write the result
  69. file_output.close();
  70.  
  71. // Open the result in a default system viewer:
  72. QDesktopServices::openUrl(QUrl::fromLocalFile(file_output.fileName()));
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement