Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
1,313 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
TDDMicroExercises.YoursSolutions/Java-viswans/TelemetrySystem/.classpath
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,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
23 changes: 23 additions & 0 deletions
23
TDDMicroExercises.YoursSolutions/Java-viswans/TelemetrySystem/.project
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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>TelemetrySystem</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
5 changes: 5 additions & 0 deletions
5
...xercises.YoursSolutions/Java-viswans/TelemetrySystem/.settings/org.eclipse.jdt.core.prefs
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,5 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 | ||
org.eclipse.jdt.core.compiler.compliance=1.5 | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.source=1.5 |
4 changes: 4 additions & 0 deletions
4
...xercises.YoursSolutions/Java-viswans/TelemetrySystem/.settings/org.eclipse.m2e.core.prefs
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,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
15 changes: 15 additions & 0 deletions
15
TDDMicroExercises.YoursSolutions/Java-viswans/TelemetrySystem/pom.xml
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,15 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>TelemetrySystem</groupId> | ||
<artifactId>TelemetrySystem</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.9</version> | ||
<type>jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
17 changes: 17 additions & 0 deletions
17
...ans/TelemetrySystem/src/main/java/tddmicroexercises/telemetrysystem/ITelemetryClient.java
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,17 @@ | ||
package tddmicroexercises.telemetrysystem; | ||
|
||
public interface ITelemetryClient { | ||
|
||
public static final String DIAGNOSTIC_MESSAGE = "AT#UD"; | ||
|
||
boolean getOnlineStatus(); | ||
|
||
void connect(String telemetryServerConnectionString); | ||
|
||
void disconnect(); | ||
|
||
void send(String message); | ||
|
||
String receive(); | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
...wans/TelemetrySystem/src/main/java/tddmicroexercises/telemetrysystem/TelemetryClient.java
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,98 @@ | ||
package tddmicroexercises.telemetrysystem; | ||
|
||
import java.util.Random; | ||
|
||
public class TelemetryClient implements ITelemetryClient | ||
{ | ||
// | ||
// The communication with the server is simulated in this implementation. | ||
// Because the focus of the exercise is on the other class. | ||
// | ||
|
||
private boolean onlineStatus; | ||
private boolean diagnosticMessageJustSent = false; | ||
|
||
private final Random connectionEventsSimulator = new Random(); | ||
private final Random randomMessageSimulator = new Random(); | ||
|
||
public boolean getOnlineStatus() | ||
{ | ||
return onlineStatus; | ||
} | ||
|
||
public void connect(String telemetryServerConnectionString) | ||
{ | ||
if (telemetryServerConnectionString == null || "".equals(telemetryServerConnectionString)) | ||
{ | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
// Fake the connection with 20% chances of success | ||
boolean success = connectionEventsSimulator.nextInt(10) <= 2; | ||
|
||
onlineStatus = success; | ||
} | ||
|
||
public void disconnect() | ||
{ | ||
onlineStatus = false; | ||
} | ||
|
||
public void send(String message) | ||
{ | ||
if (message == null || "".equals(message)) | ||
{ | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
// The simulation of Send() actually just remember if the last message sent was a diagnostic message. | ||
// This information will be used to simulate the Receive(). Indeed there is no real server listening. | ||
if (message == DIAGNOSTIC_MESSAGE) | ||
{ | ||
diagnosticMessageJustSent = true; | ||
} | ||
else | ||
{ | ||
diagnosticMessageJustSent = false; | ||
} | ||
} | ||
|
||
public String receive() | ||
{ | ||
String message; | ||
|
||
if (diagnosticMessageJustSent) | ||
{ | ||
// Simulate the reception of the diagnostic message | ||
message = "LAST TX rate................ 100 MBPS\r\n" | ||
+ "HIGHEST TX rate............. 100 MBPS\r\n" | ||
+ "LAST RX rate................ 100 MBPS\r\n" | ||
+ "HIGHEST RX rate............. 100 MBPS\r\n" | ||
+ "BIT RATE.................... 100000000\r\n" | ||
+ "WORD LEN.................... 16\r\n" | ||
+ "WORD/FRAME.................. 511\r\n" | ||
+ "BITS/FRAME.................. 8192\r\n" | ||
+ "MODULATION TYPE............. PCM/FM\r\n" | ||
+ "TX Digital Los.............. 0.75\r\n" | ||
+ "RX Digital Los.............. 0.10\r\n" | ||
+ "BEP Test.................... -5\r\n" | ||
+ "Local Rtrn Count............ 00\r\n" | ||
+ "Remote Rtrn Count........... 00"; | ||
|
||
diagnosticMessageJustSent = false; | ||
} | ||
else | ||
{ | ||
// Simulate the reception of a response message returning a random message. | ||
message = ""; | ||
int messageLength = randomMessageSimulator.nextInt(50) + 60; | ||
for(int i = messageLength; i > 0; --i) | ||
{ | ||
message += (char)randomMessageSimulator.nextInt(40) + 86; | ||
} | ||
} | ||
|
||
return message; | ||
} | ||
} | ||
|
50 changes: 50 additions & 0 deletions
50
...rySystem/src/main/java/tddmicroexercises/telemetrysystem/TelemetryDiagnosticControls.java
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,50 @@ | ||
package tddmicroexercises.telemetrysystem; | ||
|
||
public class TelemetryDiagnosticControls | ||
{ | ||
private final static String DIAGNOSTIC_CHANNEL_CONNECTION_STRING = "*111#"; | ||
|
||
private final ITelemetryClient telemetryClient; | ||
private String diagnosticInfo = ""; | ||
|
||
public TelemetryDiagnosticControls() | ||
{ | ||
telemetryClient = new TelemetryClient(); | ||
} | ||
|
||
public TelemetryDiagnosticControls(ITelemetryClient telemetryClient) { | ||
this.telemetryClient = telemetryClient; | ||
} | ||
|
||
public String getDiagnosticInfo() | ||
{ | ||
return diagnosticInfo; | ||
} | ||
|
||
public void setDiagnosticInfo(String diagnosticInfo) | ||
{ | ||
this.diagnosticInfo = diagnosticInfo; | ||
} | ||
|
||
public void checkTransmission() throws Exception | ||
{ | ||
diagnosticInfo = ""; | ||
|
||
telemetryClient.disconnect(); | ||
|
||
int retryLeft = 3; | ||
while (telemetryClient.getOnlineStatus() == false && retryLeft > 0) | ||
{ | ||
telemetryClient.connect(DIAGNOSTIC_CHANNEL_CONNECTION_STRING); | ||
retryLeft -= 1; | ||
} | ||
|
||
if(telemetryClient.getOnlineStatus() == false) | ||
{ | ||
throw new Exception("Unable to connect."); | ||
} | ||
|
||
telemetryClient.send(TelemetryClient.DIAGNOSTIC_MESSAGE); | ||
diagnosticInfo = telemetryClient.receive(); | ||
} | ||
} |
Oops, something went wrong.