|
@@ -2,10 +2,8 @@ package QuickVerifyCrap;
|
|
|
|
|
|
import com.fazecast.jSerialComm.SerialPort;
|
|
import com.fazecast.jSerialComm.SerialPort;
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.InputStream;
|
|
|
|
-import java.io.OutputStream;
|
|
|
|
-import java.io.RandomAccessFile;
|
|
|
|
|
|
+import javax.sql.rowset.serial.SQLOutputImpl;
|
|
|
|
+import java.io.*;
|
|
|
|
|
|
enum NextChunkAction
|
|
enum NextChunkAction
|
|
{
|
|
{
|
|
@@ -17,88 +15,137 @@ enum NextChunkAction
|
|
|
|
|
|
public class SerialSpammer
|
|
public class SerialSpammer
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ static InputStream in = null;
|
|
|
|
+ static OutputStream o = null;
|
|
|
|
+ static NextChunkAction nextChunkReady = NextChunkAction.WAIT;
|
|
public static void main(String[] args)
|
|
public static void main(String[] args)
|
|
{
|
|
{
|
|
|
|
+ boolean startedStreamPlayback = false;
|
|
System.out.println("Gobblygob");
|
|
System.out.println("Gobblygob");
|
|
RandomAccessFile streamfile = null;
|
|
RandomAccessFile streamfile = null;
|
|
int sendOffset = 0;
|
|
int sendOffset = 0;
|
|
- NextChunkAction nextChunkReady = NextChunkAction.WAIT;
|
|
|
|
-
|
|
|
|
SerialPort comPort = SerialPort.getCommPort("ttyACM0");
|
|
SerialPort comPort = SerialPort.getCommPort("ttyACM0");
|
|
comPort.openPort();
|
|
comPort.openPort();
|
|
comPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0);
|
|
comPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0);
|
|
- InputStream in = comPort.getInputStream();
|
|
|
|
- OutputStream o = comPort.getOutputStream();
|
|
|
|
|
|
+ in = comPort.getInputStream();
|
|
|
|
+ o = comPort.getOutputStream();
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- while(true)
|
|
|
|
|
|
+ new Thread(()->
|
|
|
|
+
|
|
{
|
|
{
|
|
- int chara = System.in.read();
|
|
|
|
- if(chara ==-1)
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- if(chara == '>')
|
|
|
|
|
|
+ System.out.println("MunchMunchMunch");
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- char[] filepath = new char[4096];
|
|
|
|
- int pathptr = 0;
|
|
|
|
- chara = System.in.read();
|
|
|
|
- while(chara != '\n'&&pathptr<4096)
|
|
|
|
- {
|
|
|
|
- filepath[pathptr]=(char)chara;
|
|
|
|
- pathptr++;
|
|
|
|
- chara = System.in.read();
|
|
|
|
- }
|
|
|
|
- if(pathptr==4096)
|
|
|
|
|
|
+ while (true)
|
|
{
|
|
{
|
|
- System.out.println("Zarf, pathdork");
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- String path = new String(filepath);
|
|
|
|
- System.out.println("Streaming: "+path);
|
|
|
|
- if(new File(path).exists())
|
|
|
|
|
|
+ if(in.available()<1)
|
|
|
|
+ {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ int read = in.read();
|
|
|
|
+ if (read == '~')
|
|
|
|
+ {
|
|
|
|
+ nextChunkReady = NextChunkAction.CONTINUE;
|
|
|
|
+ }
|
|
|
|
+ if (read == '<')
|
|
{
|
|
{
|
|
- streamfile = new RandomAccessFile(path,"r");
|
|
|
|
- nextChunkReady=NextChunkAction.CONTINUE;
|
|
|
|
|
|
+ nextChunkReady = NextChunkAction.REPEAT;
|
|
}
|
|
}
|
|
|
|
+ System.out.write(read);
|
|
|
|
+ System.out.flush();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(streamfile!=null)
|
|
|
|
|
|
+ catch (IOException e)
|
|
|
|
+ {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }).start();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ while(true)
|
|
|
|
+ {
|
|
|
|
+ if(System.in.available()>0)
|
|
{
|
|
{
|
|
- switch(nextChunkReady)
|
|
|
|
|
|
+ int chara = System.in.read();
|
|
|
|
+ if(chara ==-1)
|
|
|
|
+ {
|
|
|
|
+ System.out.println("ZÖINKS");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if(chara == '>')
|
|
{
|
|
{
|
|
- case REPEAT:
|
|
|
|
- if(streamfile.getFilePointer()>=64)
|
|
|
|
|
|
+ char[] filepath = new char[4096];
|
|
|
|
+ int pathptr = 0;
|
|
|
|
+ chara = System.in.read();
|
|
|
|
+ while(chara != '\n'&&pathptr<4096)
|
|
|
|
+ {
|
|
|
|
+ filepath[pathptr]=(char)chara;
|
|
|
|
+ pathptr++;
|
|
|
|
+ chara = System.in.read();
|
|
|
|
+ }
|
|
|
|
+ if(pathptr==4096)
|
|
|
|
+ {
|
|
|
|
+ System.out.println("Zarf, pathdork");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ String path = new String(filepath).split("\u0000")[0];
|
|
|
|
+ System.out.println("Streaming: "+path);
|
|
|
|
+ if(new File(path).exists())
|
|
{
|
|
{
|
|
- streamfile.seek(streamfile.getFilePointer()-64);
|
|
|
|
|
|
+ streamfile = new RandomAccessFile(path,"r");
|
|
|
|
+ nextChunkReady=NextChunkAction.CONTINUE;
|
|
}
|
|
}
|
|
- case CONTINUE:
|
|
|
|
- byte[] readbfr = new byte[64];
|
|
|
|
- streamfile.read(readbfr);
|
|
|
|
- o.write('>');
|
|
|
|
- o.write(readbfr);
|
|
|
|
- nextChunkReady=NextChunkAction.WAIT;
|
|
|
|
- break;
|
|
|
|
- case WAIT:
|
|
|
|
- //NOP;
|
|
|
|
- break;
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ System.out.println("Fuick");
|
|
|
|
+ o.write(chara);
|
|
|
|
+ o.flush();
|
|
|
|
+ System.out.println("ZilseZilse");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- while(in.available()>0)
|
|
|
|
|
|
+ if(streamfile!=null)
|
|
{
|
|
{
|
|
- int read = in.read();
|
|
|
|
- if( read == '~')
|
|
|
|
|
|
+
|
|
|
|
+ if(streamfile.getFilePointer()>=streamfile.length())
|
|
{
|
|
{
|
|
- nextChunkReady=NextChunkAction.CONTINUE;
|
|
|
|
|
|
+ streamfile.close();
|
|
|
|
+ streamfile=null;
|
|
}
|
|
}
|
|
- if(read == '<')
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- nextChunkReady=NextChunkAction.REPEAT;
|
|
|
|
|
|
+ if((!startedStreamPlayback)&&(streamfile.getFilePointer()==192||streamfile.getFilePointer()==streamfile.length()))
|
|
|
|
+ {
|
|
|
|
+ System.out.println("PLAY");
|
|
|
|
+ o.write('|');
|
|
|
|
+ startedStreamPlayback=true;
|
|
|
|
+ }
|
|
|
|
+ switch(nextChunkReady)
|
|
|
|
+ {
|
|
|
|
+ case REPEAT:
|
|
|
|
+ if(streamfile.getFilePointer()>=64)
|
|
|
|
+ {
|
|
|
|
+ streamfile.seek(streamfile.getFilePointer()-64);
|
|
|
|
+ }
|
|
|
|
+ case CONTINUE:
|
|
|
|
+ System.out.println("STR=("+streamfile.getFilePointer()+")");
|
|
|
|
+ byte[] readbfr = new byte[64];
|
|
|
|
+ streamfile.read(readbfr);
|
|
|
|
+ o.write('>');
|
|
|
|
+ o.write(readbfr);
|
|
|
|
+ nextChunkReady=NextChunkAction.WAIT;
|
|
|
|
+ break;
|
|
|
|
+ case WAIT:
|
|
|
|
+ //NOP;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
catch (Exception e) { e.printStackTrace(); }
|
|
catch (Exception e) { e.printStackTrace(); }
|
|
comPort.closePort();
|
|
comPort.closePort();
|