Commit c275b0d9 authored by Xiaoying Pu's avatar Xiaoying Pu

wired in a simple example, need to reinstall stuff on windows to test it out

parent 180222ac
......@@ -19,7 +19,8 @@ public class TestUDPController {
UDPController cntrl = new UDPController();
cntrl.setUp();
for (int i = 0; i < util.UDPConstants.TrialSet.length; i++) {
cntrl.sendTrialAndRecvResponse(i);
// not useable any more because of the interface change
// cntrl.sendTrialAndRecvResponse(i);
}
cntrl.endExperiment();
}
......
......@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import util.DecisionType;
import util.EventListener;
import util.EventType;
......@@ -54,7 +55,10 @@ public class PrimaryTaskController {
}
public void startDecision() {
//TODO need to fix this
this.udpHandle.sendTrialAndRecvResponse(this.theModel.getDecision(DecisionType.GETMIXATYPICAL, "HWL"));
System.out.println("Decision started, waiting for response.. ");
}
public void connect() {
......
......@@ -2,6 +2,7 @@ package tracker;
import java.util.List;
import util.Configurator;
import util.DecisionType;
import util.Task;
/**
......@@ -19,18 +20,30 @@ public class PrimaryTaskModel {
//TODO Need a COLLECTION of potential tasks to choose from, right?
private List taskPool;
private Decision decision;
/**
* Needs a counter to keep track of UDP messages
*/
private int udpCount;
public PrimaryTaskModel() {
// TODO Read constant from configurator
this.taskPool = generateTasks();
this.curTask = new Task();
this.tTask = Configurator.gettPTask();
this.tPause = Configurator.gettPause();
this.decision = new Decision();
}
private List generateTasks() {
return null;
}
public int getCurUDPCount() {
return udpCount++;
}
/**
*
* @return
......@@ -47,4 +60,25 @@ public class PrimaryTaskModel {
return tTask;
}
public String getDecision(DecisionType type, String condition) {
String result;
switch (type) {
case GETCATAGORY1:
result = this.decision.getCategory1(condition);
break;
case GETCATAGORY2:
result = this.decision.getCategory2(condition);
break;
case GETMIXTYPICAL:
result = this.decision.getMixTypical(condition);
break;
case GETMIXATYPICAL:
result = this.decision.getMixAtypical(condition);
break;
default:
result = "??????";
System.out.println("ACHTUNG");
}
return result;
}
}
......@@ -11,7 +11,6 @@ import static util.UDPConstants.MESSAGE_ID;
import static util.UDPConstants.PACKET_LENGTH;
import static util.UDPConstants.RECEIVE_PORT;
import static util.UDPConstants.SEND_PORT;
import static util.UDPConstants.TrialSet;
import static util.UDPConstants.UDP_TIMEOUT;
/**
......@@ -20,22 +19,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();
......@@ -90,16 +89,16 @@ public class UDPController {
* Loop between Step 4-5 for every trial (Send Stimuli to MouseTracker and
* Receive Responses)
*
* @param i the counter, from 1 to 10, say
*
* @param stimuli the string generated by Decision class
*/
public void sendTrialAndRecvResponse(int i) {
public void sendTrialAndRecvResponse(String stimuli) {
/*
STEP 4: MATLAB sends trial information
*/
// String strTrialInfo = TrialSet[i] + currentResp1 + "," + currentResp2;
String strTrialInfo = TrialSet[i];
messageToSend = INTERFACE_ID + "," + MESSAGE_ID + "," + strTrialInfo;
messageToSend = INTERFACE_ID + "," + MESSAGE_ID + "," + stimuli;
UDPHandler.send(messageToSend, HOST, SEND_PORT);
MESSAGE_ID++;
System.out.println(">>>" + messageToSend);
......@@ -125,7 +124,7 @@ public class UDPController {
*/
MESSAGE_ID++;
System.out.println("<<<" + message_received);
}
/**
......@@ -134,7 +133,7 @@ public class UDPController {
public void endExperiment() {
messageToSend = INTERFACE_ID + "," + MESSAGE_ID + "," + "END";
UDPHandler.send(messageToSend, HOST, SEND_PORT);
System.out.println(">>>" + messageToSend);
}
}
package util;
/**
*
* @author pxy
*/
public enum DecisionType {
GETCATAGORY1,
GETCATAGORY2,
GETMIXTYPICAL,
GETMIXATYPICAL;
}
......@@ -23,7 +23,7 @@ public class UDPConstants {
public static int RECEIVE_PORT = 9223; // recv for this prgm, output port for MouseTracker
public static int SEND_PORT = 9001; // input port for mousetracker
public static String HOST = "134.82.96.217";// TO MouseTracker
public static String HOST = "127.0.0.1";// TO MouseTracker
public static int UDP_TIMEOUT = 20 * 1000; // in millisecond
public static int PACKET_LENGTH = 512;
......
......@@ -6,4 +6,7 @@ tPTask = 100
tSTask = 1000
# duration of the pause, for both primary and secondary tasks
tPause = 4000
\ No newline at end of file
tPause = 4000
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