|
@@ -18,13 +18,15 @@ public class SerialSpammer
|
|
static InputStream in = null;
|
|
static InputStream in = null;
|
|
static OutputStream o = null;
|
|
static OutputStream o = null;
|
|
static NextChunkAction nextChunkReady = NextChunkAction.WAIT;
|
|
static NextChunkAction nextChunkReady = NextChunkAction.WAIT;
|
|
|
|
+ static int waitCtr = 0;
|
|
|
|
+ static Object workaround = new Object();
|
|
public static void main(String[] args)
|
|
public static void main(String[] args)
|
|
{
|
|
{
|
|
boolean startedStreamPlayback = false;
|
|
boolean startedStreamPlayback = false;
|
|
System.out.println("Gobblygob");
|
|
System.out.println("Gobblygob");
|
|
RandomAccessFile streamfile = null;
|
|
RandomAccessFile streamfile = null;
|
|
int sendOffset = 0;
|
|
int sendOffset = 0;
|
|
- SerialPort comPort = SerialPort.getCommPort("ttyACM0");
|
|
|
|
|
|
+ SerialPort comPort = SerialPort.getCommPort("COM20");
|
|
comPort.openPort();
|
|
comPort.openPort();
|
|
comPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0);
|
|
comPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0);
|
|
in = comPort.getInputStream();
|
|
in = comPort.getInputStream();
|
|
@@ -46,12 +48,25 @@ public class SerialSpammer
|
|
int read = in.read();
|
|
int read = in.read();
|
|
if (read == '~')
|
|
if (read == '~')
|
|
{
|
|
{
|
|
|
|
+ System.out.println("RSME");
|
|
nextChunkReady = NextChunkAction.CONTINUE;
|
|
nextChunkReady = NextChunkAction.CONTINUE;
|
|
|
|
+ synchronized (workaround)
|
|
|
|
+ {
|
|
|
|
+ System.out.println("POKE");
|
|
|
|
+ workaround.notify();
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
if (read == '<')
|
|
if (read == '<')
|
|
{
|
|
{
|
|
nextChunkReady = NextChunkAction.REPEAT;
|
|
nextChunkReady = NextChunkAction.REPEAT;
|
|
|
|
+ synchronized (workaround)
|
|
|
|
+ {
|
|
|
|
+ System.out.println("POKE");
|
|
|
|
+ workaround.notify();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
System.out.write(read);
|
|
System.out.write(read);
|
|
System.out.flush();
|
|
System.out.flush();
|
|
}
|
|
}
|
|
@@ -96,6 +111,11 @@ public class SerialSpammer
|
|
{
|
|
{
|
|
streamfile = new RandomAccessFile(path,"r");
|
|
streamfile = new RandomAccessFile(path,"r");
|
|
nextChunkReady=NextChunkAction.CONTINUE;
|
|
nextChunkReady=NextChunkAction.CONTINUE;
|
|
|
|
+ synchronized (workaround)
|
|
|
|
+ {
|
|
|
|
+ System.out.println("POKE");
|
|
|
|
+ workaround.notify();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -104,6 +124,10 @@ public class SerialSpammer
|
|
//System.out.println("Fuick");
|
|
//System.out.println("Fuick");
|
|
o.write(chara);
|
|
o.write(chara);
|
|
o.flush();
|
|
o.flush();
|
|
|
|
+ if(chara=='\n')
|
|
|
|
+ {
|
|
|
|
+ System.out.println("waitctr="+waitCtr);
|
|
|
|
+ }
|
|
//System.out.println("ZilseZilse");
|
|
//System.out.println("ZilseZilse");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -112,13 +136,15 @@ public class SerialSpammer
|
|
|
|
|
|
if(streamfile.getFilePointer()>=streamfile.length())
|
|
if(streamfile.getFilePointer()>=streamfile.length())
|
|
{
|
|
{
|
|
|
|
+ System.out.println("FINI");
|
|
|
|
+ System.err.println("FINI");
|
|
streamfile.close();
|
|
streamfile.close();
|
|
streamfile=null;
|
|
streamfile=null;
|
|
startedStreamPlayback=false;
|
|
startedStreamPlayback=false;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- if((!startedStreamPlayback)&&(streamfile.getFilePointer()==192||streamfile.getFilePointer()==streamfile.length()))
|
|
|
|
|
|
+ if((!startedStreamPlayback)&&(streamfile.getFilePointer()==8192||streamfile.getFilePointer()==streamfile.length()))
|
|
{
|
|
{
|
|
System.out.println("PLAY");
|
|
System.out.println("PLAY");
|
|
o.write('|');
|
|
o.write('|');
|
|
@@ -127,21 +153,30 @@ public class SerialSpammer
|
|
switch(nextChunkReady)
|
|
switch(nextChunkReady)
|
|
{
|
|
{
|
|
case REPEAT:
|
|
case REPEAT:
|
|
|
|
+ System.out.println("RTRY=("+streamfile.getFilePointer()+")");
|
|
|
|
+ waitCtr=0;
|
|
if(streamfile.getFilePointer()>=64)
|
|
if(streamfile.getFilePointer()>=64)
|
|
{
|
|
{
|
|
streamfile.seek(streamfile.getFilePointer()-64);
|
|
streamfile.seek(streamfile.getFilePointer()-64);
|
|
}
|
|
}
|
|
case CONTINUE:
|
|
case CONTINUE:
|
|
|
|
+ waitCtr=0;
|
|
System.out.println("STR=("+streamfile.getFilePointer()+")");
|
|
System.out.println("STR=("+streamfile.getFilePointer()+")");
|
|
byte[] readbfr = new byte[64];
|
|
byte[] readbfr = new byte[64];
|
|
streamfile.read(readbfr);
|
|
streamfile.read(readbfr);
|
|
o.write('>');
|
|
o.write('>');
|
|
- o.write(readbfr);
|
|
|
|
nextChunkReady=NextChunkAction.WAIT;
|
|
nextChunkReady=NextChunkAction.WAIT;
|
|
|
|
+ o.write(readbfr);
|
|
|
|
+
|
|
break;
|
|
break;
|
|
- case WAIT:
|
|
|
|
- //NOP;
|
|
|
|
- break;
|
|
|
|
|
|
+ }
|
|
|
|
+ synchronized (workaround)
|
|
|
|
+ {
|
|
|
|
+ if(nextChunkReady==NextChunkAction.WAIT)
|
|
|
|
+ {
|
|
|
|
+ System.out.println("GOTO WAIT");
|
|
|
|
+ workaround.wait();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|