Commit 006350c2 authored by Xiaoying Pu's avatar Xiaoying Pu

added some listener events for received MT messages; still need a counter or...

added some listener events for received MT messages; still need a counter or something to have multiple decisions made in between digit tasks
parent d8b8aedc
......@@ -32,6 +32,7 @@ public class PrimaryTaskController {
this.eventListenerList = new ArrayList<>();
if (turnUDPOn) {
this.udpHandle = new UDPController();// should set up the UDP connection
this.udpHandle.addListener(new UDPListener());
}
}
......@@ -82,7 +83,12 @@ public class PrimaryTaskController {
@Override
public void run(EventType type) {
eventListenerList.stream().forEach((listener) -> {
listener.run(EventType.UDPMSG_FROM_MT);
System.out.println("hey UDPListner is working\n");
// TODO or type, right?
// should have multiple MT trials run
// before telling the MouseTrackerFacade that it's done
// like a counter here
listener.run(EventType.END_MULTI_DECISION);
});
}
}
......
......@@ -2,6 +2,8 @@ package tracker;
import java.util.Arrays;
import network.UDPHandler;
import util.EventListener;
import util.EventType;
import util.Persistence;
import static util.UDPConstants.HOST;
import static util.UDPConstants.INTERFACE_ID;
......@@ -18,17 +20,22 @@ import static util.UDPConstants.UDP_TIMEOUT;
* @author Xiaoying Pu <xp002@bucknell.edu>
*/
public class UDPController {
private EventListener theListener;
private String message_received = "";
private String messageToSend = "";
private Persistence persisHandle;
private final String[] HEADER = new String[]{"interface", "response_#", "incorrect?", "init_time", "response_time"};
public UDPController() {
this.persisHandle = new Persistence("recv.csv", HEADER);
//setUp(); NOTE: should not be called at init
}
public void addListener(EventListener l) {
this.theListener = l;
}
public void setUp() {
initialWaitSignal();
startSignalFromThis();
......@@ -106,6 +113,7 @@ public class UDPController {
Object[] data = UDPHandler.receive(HOST, RECEIVE_PORT, UDP_TIMEOUT, PACKET_LENGTH);
message_received = (String) data[0];
}
this.theListener.run(EventType.UDPMSG_FROM_MT);
// TODO: What is this doing????
String[] tempParts = message_received.split(",");
......@@ -117,7 +125,7 @@ public class UDPController {
*/
MESSAGE_ID++;
System.out.println("<<<" + message_received);
}
/**
......@@ -126,7 +134,7 @@ public class UDPController {
public void endExperiment() {
messageToSend = INTERFACE_ID + "," + MESSAGE_ID + "," + "END";
UDPHandler.send(messageToSend, HOST, SEND_PORT);
System.out.println(">>>" + messageToSend);
}
}
......@@ -10,5 +10,7 @@ public enum ActionType {
START_LWL_DIGIT,
QUIT_TRIAL,
CONNECT_UDP,
START_ONE_DECISION,
START_MULTI_DECISION,
END_SHOWING_DIGIT;
}
......@@ -14,5 +14,6 @@ public enum EventType {
DECISION_FINISHED,
DIGITINPUT_TO_CONTROLLER,
UDPMSG_FROM_MT,
END_MULTI_DECISION,
DIGITINPUT_FINISHED;
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tracker;
import org.junit.Test;
/**
*
* @author pxy
*/
public class DecisionTest {
public DecisionTest() {
}
/**
* Test of getCategory1 method, of class Decision.
*/
@Test
public void testGetCategory1() {
System.out.println("getCategory1");
String condition = "HWL";
Decision instance = new Decision();
String expResult = "";
String result = instance.getCategory1(condition);
System.out.println(result);
}
/**
* Test of getCategory2 method, of class Decision.
*/
@Test
public void testGetCategory2() {
System.out.println("getCategory2");
String condition = "LWL";
Decision instance = new Decision();
String expResult = "";
String result = instance.getCategory2(condition);
System.out.println(result);
}
/**
* Test of getMix method, of class Decision.
*/
@Test
public void testGetMix() {
System.out.println("getMix");
Decision instance = new Decision();
String expResult = "";
String result = instance.getMix();
System.out.println(result);
}
/**
* Test of getBreak method, of class Decision.
*/
@Test
public void testGetBreak() {
System.out.println("getBreak");
Decision instance = new Decision();
String expResult = "";
String result = instance.getBreak();
System.out.println(result);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment