151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/cwmp/acs.rb', line 151
def start_cli
list = [
'GetParameterValues', 'SetParameterValues', 'Reboot', 'FactoryReset', 'Download', 'AddObject', 'DeleteObject',
'help', 'list', 'quit', "waitMessage"
].sort
comp = proc { |s| list.grep(/^#{Regexp.escape(s)}/) }
::Readline.completion_append_character = " "
::Readline.completion_proc = comp
while line = ::Readline.readline('> ', true)
case line
when "quit", "exit"
puts "Bye"
exit(0)
when "help"
puts "help not available"
when "list games"
puts ["FALKEN'S MAZE", "BLACK JACK", "GIN RUMMY", "HEARTS", "BRIDGE", "CHECKERS", "CHESS", "POKER", "FIGHTER COMBAT", "GUERRILLA ENGAGEMENT", "DESERT WARFARE" "AIR-TO-GROUND ACTIONS", "THEATERWIDE TACTICAL WARFARE", "THEATERWIDE BIOTOXIC AND CHEMICAL WARFARE", "GLOBAL THERMONUCLEAR WAR"].join "\n"
when "help games"
puts "Games refers to models, simulations and games which have strategic applications"
when "list"
p @cpes
when /send (\w+) (\w+) (.+)/
message_type = $1
serial = $2
args = $3.split(" ")
cpe = @cpes[serial]
if !cpe
puts "cpe #{serial} unknown"
next
end
mess = Object.const_get("Cwmp").const_get("Message").send(message_type, args)
cpe.queue << Cwmp::Request.new(mess) do |resp|
puts "arrived #{resp}"
end
cpe.do_connection_request
when "run"
begin
require './examples/api_usage'
rescue LoadError
puts "file not found"
rescue SyntaxError => e
puts "file contains syntax errors: #{e.message}"
rescue Exception => e
puts "runtime error: #{e.message}"
end
else
puts "unknown command <#{line}>" if line != ""
end
end
end
|