-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed a bug where suggested speed would not go to 0 when authority was 0.
- Loading branch information
1 parent
df67379
commit 1fd0ac4
Showing
13 changed files
with
215 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Example Messages: | ||
|
||
Track Controller : Train 0 : set, Location = 7 | ||
Track Controller : Red 27 : set, Switch = [28, 76] | ||
Track Controller : Red 47 : set, Crossing = Closed | ||
Track Controller : Green 3 : set, Status = Italian_flag | ||
Track Controller : Green 4 : set, Heater = On | ||
Track Controller : Green 5 : set, Lights = Green |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.net.*; | ||
|
||
import com.sun.net.httpserver.HttpExchange; | ||
import com.sun.net.httpserver.HttpHandler; | ||
import com.sun.net.httpserver.HttpServer; | ||
|
||
public class MessageLibrary { | ||
|
||
public class MessageQueue { | ||
|
||
|
||
|
||
} | ||
|
||
// Sends a message to another module with the specified hostname (localhost) and port. | ||
public static void sendMessage(String hostName, int portNumber, String message) { | ||
new MessageSender(hostName, portNumber, message).start(); | ||
} | ||
|
||
// Assumes host is localhost | ||
public static void sendMessage(int portNumber, String message) { | ||
new MessageSender("localhost", portNumber, message).start(); | ||
} | ||
|
||
static class MessageSender extends Thread { | ||
|
||
String hostName; | ||
int portNumber; | ||
String message; | ||
|
||
public MessageSender(String hostName, int portNumber, String message) { | ||
this.hostName = hostName; | ||
this.portNumber = portNumber; | ||
this.message = message; | ||
} | ||
|
||
public void run() { | ||
Socket hostSocket = null; | ||
PrintWriter out = null; | ||
BufferedReader in = null; | ||
String line = null; | ||
|
||
// Open connection and wait for host | ||
do { | ||
try { | ||
hostSocket = new Socket(hostName, portNumber); | ||
out = new PrintWriter(hostSocket.getOutputStream(), true); | ||
in = new BufferedReader(new InputStreamReader(hostSocket.getInputStream())); | ||
line = in.readLine(); | ||
} | ||
catch (Exception e) {} | ||
} while (line == null); | ||
|
||
// Send message | ||
out.println(this.message); | ||
|
||
// Close resources | ||
try { | ||
hostSocket.close(); | ||
out.close(); | ||
in.close(); | ||
} | ||
catch (Exception e) {} | ||
} | ||
} | ||
|
||
// Read the contents of a file into a string. | ||
public static byte[] readFile(String fileName) throws IOException { | ||
File file = new File(fileName); | ||
byte fileContent[] = new byte[(int) file.length()]; | ||
FileInputStream input = new FileInputStream(file); | ||
input.read(fileContent); | ||
return fileContent; | ||
} | ||
|
||
|
||
// Sends an HTTP response given a string of bytes | ||
public static void sendHttpResponse(HttpExchange exchange, byte response[]) throws IOException { | ||
exchange.sendResponseHeaders(200, response.length); | ||
OutputStream os = exchange.getResponseBody(); | ||
os.write(response); | ||
os.close(); | ||
} | ||
|
||
// Reconstructs a hash table given an input string. | ||
public static Hashtable<String, String> stringToHashtable(String input) { | ||
Hashtable<String, String> result = new Hashtable<String, String>(); | ||
String tuples[] = input.replace(", ", ",").split(","); | ||
for (int index = 0; index < tuples.length; index++) { | ||
String pair[] = tuples[index].split("="); | ||
result.put(pair[0], pair[1]); | ||
} | ||
return result; | ||
} | ||
|
||
// Sends an HTTP response given a string | ||
public static void sendHttpResponse(HttpExchange exchange, String response) throws IOException { | ||
exchange.sendResponseHeaders(200, response.length()); | ||
OutputStream os = exchange.getResponseBody(); | ||
os.write(response.getBytes()); | ||
os.close(); | ||
} | ||
|
||
public static void httpAcknowledge(HttpExchange exchange) throws IOException { | ||
sendHttpResponse(exchange, "OK"); | ||
} | ||
|
||
public static Hashtable<String, String> getHttpGetParams(HttpExchange exchange) { | ||
Hashtable<String, String> paramTable = new Hashtable<String, String>(); | ||
String paramString = exchange.getRequestURI().getQuery(); | ||
if (paramString != null) { | ||
String[] paramList = paramString.split("&"); | ||
for (String s : paramList) { | ||
String[] param = s.split("="); | ||
paramTable.put(param[0], param[1]); | ||
} | ||
} | ||
return paramTable; | ||
} | ||
|
||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.