Skip to content
Browse files

Ruby version of original problem for TelemetrySystem

  • Loading branch information...
1 parent eb660e8 commit bd16ef2956995e25d1b265573f6e426db87ac953 @Sam-Serpoosh Sam-Serpoosh committed Sep 9, 2012
View
61 TDDMicroExercises/Ruby/telemetry_system/telemetry_client.rb
@@ -0,0 +1,61 @@
+class TelemetryClient
+ DIAGNOSTICMESSAGE = "AT#UD"
+
+ def initialize
+ @online_status = false
+ @diagnostic_message_result = ""
+ end
+
+ def online_status
+ @online_status
+ end
+
+ def connect(telemetry_server_connection_string)
+ if (telemetry_server_connection_string.nil? || telemetry_server_connection_string == "")
+ raise Exception, "Argument Null"
+ end
+
+ #simulate the operation on a real modem
+ success = (1 + rand(10)) <= 8
+
+ @online_status = success
+ end
+
+ def disconnect
+ @online_status = false
+ end
+
+ def send(message)
+ if (message.nil? || message == "")
+ raise Exception, "Argument Null"
+ end
+
+ if (message == DIAGNOSTICMESSAGE)
+ #simulate a status report
+ @diagnostic_message_result =
+ "LAST TX rate................ 100 MBPS\nHIGHEST TX rate............. 100 MBPS\nLAST RX rate................ 100 MBPS\nHIGHEST RX rate............. 100 MBPS\nBIT RATE.................... 100000000\nWORD LEN.................... 16\nWORD/FRAME.................. 511\nBITS/FRAME.................. 8192\nMODULATION TYPE............. PCM/FM\nTX Digital Los.............. 0.75\nRX Digital Los.............. 0.10\nBEP Test.................... -5\nLocal Rtrn Count............ 00\nRemote Rtrn Count........... 00"
+
+ return
+ end
+
+ #here should go the real Send operation
+ end
+
+ def receive
+ if (!@diagnostic_message_result.nil? && @diagnostic_message_result != "")
+ message = @diagnostic_message_result
+ @diagnostic_message_result = ""
+ else
+ #simulate a received message
+ message = ""
+ messageLength = 50 + rand(110)
+ i = messageLength
+ while i >= 0
+ message += (40 + rand(126)).chr
+ i -= 1
+ end
+ end
+
+ return message
+ end
+end
View
32 TDDMicroExercises/Ruby/telemetry_system/telemetry_diagnostic_controls.rb
@@ -0,0 +1,32 @@
+require_relative "./telemetry_client"
+
+class TelemetryDiagnosticControls
+ DIAGNOSTICCHANNELCONNECTIONSTRING = "*111#"
+
+ attr_accessor :diagnostic_info
+
+ def initialize
+ @telemetry_client = TelemetryClient.new
+ @diagnostic_info = ""
+ end
+
+ def check_transmission
+ @diagnostic_info = ""
+ @telemetry_client.disconnect
+
+ retry_left = 3
+ while (@telemetry_client.online_status == false && retry_left > 0)
+ @telemetry_client.connect(DIAGNOSTICCHANNELCONNECTIONSTRING)
+ retry_left -= 1
+ end
+
+ if(@telemetry_client.online_status == false)
+ raise Exception, "Unable to connect."
+ end
+
+ @telemetry_client.send(TelemetryClient::DIAGNOSTICMESSAGE)
+ @diagnostic_info = @telemetry_client.receive
+ end
+end
+
+TelemetryDiagnosticControls.new.check_transmission

0 comments on commit bd16ef2

Please sign in to comment.
Something went wrong with that request. Please try again.