-
Notifications
You must be signed in to change notification settings - Fork 12
/
IdleState.cs
79 lines (71 loc) · 2.45 KB
/
IdleState.cs
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
namespace UniversaLIS
{
public class IdleState : ILISState
{
public IdleState(CommFacilitator comm)
{
this.comm = comm;
}
private readonly CommFacilitator comm;
public void RcvInput(string InputString)
{
switch (InputString)
{
case Constants.ACK:
RcvACK();
break;
case Constants.NAK:
RcvNAK();
break;
case Constants.ENQ:
RcvENQ();
break;
case Constants.EOT:
RcvEOT();
break;
default:
RcvData(InputString);
break;
}
}
public void RcvACK()
{
// Bask in the praise of the instrument? It's acknowledging us for no reason!
// Seriously though, maybe we should add inappropriate incoming transmissions to the log file.
UniversaLIService.AppendToLog("ACK received in idle state...?");
}
public void RcvData(string InputString)
{
// Ignore... Possibly log the input for later reference?
UniversaLIService.AppendToLog("Data received in idle state: " + InputString);
}
public void RcvENQ()
{
comm.Send(Constants.ACK);
}
public void RcvEOT()
{
// Ignore, but log it.
UniversaLIService.AppendToLog("EOT received in idle state.");
}
public void RcvNAK()
{
// Ignore. It's just trying to get a rise out of you.
UniversaLIService.AppendToLog("NAK received in idle state.");
}
public void HaveData()
{
// If there's data to send, check the timers before sending.
if (comm.ContentTimer.RemainingDuration <= 0 && comm.BusyTimer.RemainingDuration <= 0)
{
// Send ENQ
comm.Send(Constants.ENQ);
// Set transTimer = 15
comm.TransTimer.Reset(15);
#if DEBUG
UniversaLIService.AppendToLog("Transaction timer reset: 15.");
#endif
}
}
}
}