Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Ruby version of original problem for TelemetrySystem

  • Loading branch information...
commit bd16ef2956995e25d1b265573f6e426db87ac953 1 parent eb660e8
Sam Sam-Serpoosh authored
61 TDDMicroExercises/Ruby/telemetry_system/telemetry_client.rb
... ... @@ -0,0 +1,61 @@
  1 +class TelemetryClient
  2 + DIAGNOSTICMESSAGE = "AT#UD"
  3 +
  4 + def initialize
  5 + @online_status = false
  6 + @diagnostic_message_result = ""
  7 + end
  8 +
  9 + def online_status
  10 + @online_status
  11 + end
  12 +
  13 + def connect(telemetry_server_connection_string)
  14 + if (telemetry_server_connection_string.nil? || telemetry_server_connection_string == "")
  15 + raise Exception, "Argument Null"
  16 + end
  17 +
  18 + #simulate the operation on a real modem
  19 + success = (1 + rand(10)) <= 8
  20 +
  21 + @online_status = success
  22 + end
  23 +
  24 + def disconnect
  25 + @online_status = false
  26 + end
  27 +
  28 + def send(message)
  29 + if (message.nil? || message == "")
  30 + raise Exception, "Argument Null"
  31 + end
  32 +
  33 + if (message == DIAGNOSTICMESSAGE)
  34 + #simulate a status report
  35 + @diagnostic_message_result =
  36 + "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"
  37 +
  38 + return
  39 + end
  40 +
  41 + #here should go the real Send operation
  42 + end
  43 +
  44 + def receive
  45 + if (!@diagnostic_message_result.nil? && @diagnostic_message_result != "")
  46 + message = @diagnostic_message_result
  47 + @diagnostic_message_result = ""
  48 + else
  49 + #simulate a received message
  50 + message = ""
  51 + messageLength = 50 + rand(110)
  52 + i = messageLength
  53 + while i >= 0
  54 + message += (40 + rand(126)).chr
  55 + i -= 1
  56 + end
  57 + end
  58 +
  59 + return message
  60 + end
  61 +end
32 TDDMicroExercises/Ruby/telemetry_system/telemetry_diagnostic_controls.rb
... ... @@ -0,0 +1,32 @@
  1 +require_relative "./telemetry_client"
  2 +
  3 +class TelemetryDiagnosticControls
  4 + DIAGNOSTICCHANNELCONNECTIONSTRING = "*111#"
  5 +
  6 + attr_accessor :diagnostic_info
  7 +
  8 + def initialize
  9 + @telemetry_client = TelemetryClient.new
  10 + @diagnostic_info = ""
  11 + end
  12 +
  13 + def check_transmission
  14 + @diagnostic_info = ""
  15 + @telemetry_client.disconnect
  16 +
  17 + retry_left = 3
  18 + while (@telemetry_client.online_status == false && retry_left > 0)
  19 + @telemetry_client.connect(DIAGNOSTICCHANNELCONNECTIONSTRING)
  20 + retry_left -= 1
  21 + end
  22 +
  23 + if(@telemetry_client.online_status == false)
  24 + raise Exception, "Unable to connect."
  25 + end
  26 +
  27 + @telemetry_client.send(TelemetryClient::DIAGNOSTICMESSAGE)
  28 + @diagnostic_info = @telemetry_client.receive
  29 + end
  30 +end
  31 +
  32 +TelemetryDiagnosticControls.new.check_transmission

0 comments on commit bd16ef2

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