This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
OutgoingLink.java
119 lines (94 loc) · 3.17 KB
/
OutgoingLink.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.util.*;
import java.io.*;
import java.net.*;
/**
* @author Angelo DiNardi ([email protected])
*/
class OutgoingLink extends Thread {
Socket socket = null;
DataOutputStream out = null;
public OutgoingLink( Socket socket ) {
this.socket = socket;
}
public void run() {
//do stuff
}
public void sendLogin() {
try {
out = new DataOutputStream(socket.getOutputStream());
out.writeBytes( "0" );
//this should eventually pull from a config
out.writeBytes( ConfigMgr.getInstance().getPassword() );
out.writeBytes( "\n" );
out.flush();
}catch( Exception e ) {
e.printStackTrace();
CommLink.getInstance().Reconnect();
}
}
public void sendDropACK() {
try {
System.out.println("Sending Drop ACK");
out = new DataOutputStream(socket.getOutputStream());
System.out.println("Writing 4");
out.writeBytes( "4\n" );
out.flush();
}catch( Exception e ) {
e.printStackTrace();
CommLink.getInstance().Reconnect();
}
System.out.println("ack'ed");
}
public void sendTemp( double temp ) {
try {
System.out.println( "Temp: " + (new Double(temp)).toString() );
out = new DataOutputStream( socket.getOutputStream() );
out.writeBytes( "8" );
out.writeBytes( (new Double(temp)).toString() );
out.writeBytes( "\n" );
out.flush();
}catch( Exception e ) {
CommLink.getInstance().Reconnect();
}
}
public void sendDropNACK() {
try {
out = new DataOutputStream( socket.getOutputStream() );
out.writeBytes( "5\n" );
out.flush();
}catch( Exception e ) {
CommLink.getInstance().Reconnect();
}
}
public void sendSlotInfo( int slot, boolean empty ) {
try {
out = new DataOutputStream( socket.getOutputStream() );
out.writeBytes( "7" );
out.writeBytes( "" + slot + " " + (empty ? 0 : 1) );
out.writeBytes( "\n" );
out.flush();
}catch( Exception e ) {
CommLink.getInstance().Reconnect();
}
}
public void sendSlotInfo( boolean[] empty ) {
//If the empty info hasn't been scanned from the machine yet, ignore.
if( empty[0] == false ) { return; }
System.out.println( "Sending Complete Slot Info" );
try {
out = new DataOutputStream( socket.getOutputStream() );
out.writeBytes( "7" );
int slots = ConfigMgr.getInstance().getNumSlots() + 1;
for( int x = 1; x < slots; x++ ) {
if( x > 1 ) {
out.writeBytes( "`" );
}
out.writeBytes( "" + x + " " + ( empty[x] ? 0 : 1 ) );
}
out.writeBytes( "\n" );
out.flush();
}catch( Exception e ) {
CommLink.getInstance().Reconnect();
}
}
}