Logic2PWMMassageliege.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package QuickVerifyCrap;
  2. import java.io.FileNotFoundException;
  3. import java.io.RandomAccessFile;
  4. import java.math.BigInteger;
  5. import java.nio.ByteBuffer;
  6. import java.util.ArrayList;
  7. import java.util.LinkedList;
  8. import java.util.List;
  9. public class Logic2PWMMassageliege
  10. {
  11. static final int REFRATE = 500_000_000;
  12. static final int SAMPLELENGTH=REFRATE/32_000;//500MS samplerate/32KHz
  13. static final int SAMPLELENGTH_BUFFERED= (int) (SAMPLELENGTH*1.1);//500MS samplerate/32KHz
  14. public static void main(String[] args) throws Exception
  15. {
  16. long[] edges_ch1 = null;
  17. long[] edges_ch2 = null;
  18. String basepath = "/home/tgoerner/loa/000034/export/";
  19. RandomAccessFile ch1 = new RandomAccessFile(basepath+"digital_0.bin","r");
  20. RandomAccessFile ch2 = new RandomAccessFile(basepath+"digital_1.bin","r");
  21. ch1.readLong(); //magic LMAA
  22. ch1.readInt();
  23. ch1.readInt();
  24. boolean initialHigh1 = (ch1.readInt()!=0);
  25. ch1.readDouble();
  26. ch1.readDouble();
  27. int countEdges1 = (int) Long.reverseBytes(ch1.readLong());
  28. if(initialHigh1)
  29. {
  30. countEdges1++;
  31. }
  32. int writeptr = 0;
  33. edges_ch1 = new long[countEdges1+1];
  34. if(initialHigh1)
  35. {
  36. edges_ch1[0]=-1;
  37. writeptr++;
  38. }
  39. while(writeptr<countEdges1)
  40. {
  41. long temp = Long.reverseBytes(ch1.readLong());
  42. ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
  43. buffer.putLong(temp);
  44. buffer.rewind();
  45. edges_ch1[writeptr]=(long)(buffer.getDouble()*REFRATE);
  46. writeptr++;
  47. }
  48. edges_ch1[writeptr] = edges_ch1[writeptr-1]+REFRATE;
  49. ch2.readLong(); //magic LMAA
  50. ch2.readInt();
  51. ch2.readInt();
  52. boolean initialHigh2 = (ch2.readInt()!=0);
  53. ch2.readDouble();
  54. ch2.readDouble();
  55. int countEdges2 = (int) Long.reverseBytes(ch2.readLong());
  56. if(initialHigh2)
  57. {
  58. countEdges2++;
  59. }
  60. writeptr = 0;
  61. edges_ch2 = new long[countEdges2+1];
  62. if(initialHigh2)
  63. {
  64. edges_ch1[0]=-1;
  65. writeptr++;
  66. }
  67. while(writeptr<countEdges2)
  68. {
  69. long temp = Long.reverseBytes(ch2.readLong());
  70. ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
  71. buffer.putLong(temp);
  72. buffer.rewind();
  73. edges_ch2[writeptr]=(long)(buffer.getDouble()*REFRATE);
  74. writeptr++;
  75. }
  76. edges_ch2[writeptr] = edges_ch2[writeptr-1]+REFRATE;
  77. List<List<Short>> lst= new LinkedList<>();
  78. List<Short> samples = new LinkedList<>();
  79. int c1 = 1; //zeit zur ersten flanke weg, die ist bullshit.exe da zeit vor erster messung
  80. int c2 = 1;
  81. while(c1<edges_ch1.length-2||c2<edges_ch2.length-2)
  82. {
  83. boolean cutoff = false;
  84. //triggert wenn beide signale länger als
  85. if(c1<edges_ch1.length&&c2<edges_ch2.length&&(edges_ch1[c1+1]>SAMPLELENGTH_BUFFERED)&&(edges_ch2[c2+1]>SAMPLELENGTH_BUFFERED))
  86. {
  87. cutoff=true;
  88. }
  89. if(c1<edges_ch1.length-2&&edges_ch1[c1]<edges_ch2[c2]&&c2<edges_ch2.length-2) //channel1 hat den nächsten höcker
  90. {
  91. long samplesize = edges_ch1[c1]+edges_ch1[c1+1];
  92. if(edges_ch1[c1+1]>SAMPLELENGTH_BUFFERED)
  93. {
  94. samplesize=SAMPLELENGTH;
  95. }
  96. short sample = (short)((edges_ch1[c1]*32768)/samplesize);
  97. samples.add(sample);
  98. c1+=2;
  99. }
  100. else if(c2<edges_ch2.length-2&&edges_ch2[c2]<edges_ch1[c1]&&c1<edges_ch1.length-2) //channel1 hat den nächsten höcker
  101. {
  102. long samplesize = edges_ch2[c2]+edges_ch2[c2+1];
  103. if(edges_ch2[c2+1]>SAMPLELENGTH_BUFFERED)
  104. {
  105. samplesize=SAMPLELENGTH;
  106. }
  107. short sample = (short)(((edges_ch2[c2]*32768)/samplesize)*-1);
  108. samples.add(sample);
  109. c2+=2;
  110. }
  111. else
  112. {
  113. System.out.println("ZÖINKS");
  114. c1=edges_ch1.length;
  115. c2=edges_ch2.length;
  116. }
  117. if(cutoff)
  118. {
  119. lst.add(samples);
  120. samples = new LinkedList<>();
  121. }
  122. }
  123. for(int i=0;i<lst.size();i++)
  124. {
  125. RandomAccessFile out = new RandomAccessFile(basepath+"track"+i+".raw","rw");
  126. List<Short> file = lst.get(i);
  127. for(int j=0;j<file.size();j++)
  128. {
  129. out.writeShort(file.get(j));
  130. }
  131. out.close();
  132. }
  133. }
  134. }