10
0
Fork 0

TODO list

client.disconnect implemented
This commit is contained in:
kevredon 2011-02-04 23:16:09 +01:00
parent 86675204cb
commit 478c3f654c
4 changed files with 39 additions and 19 deletions

View File

@ -3,7 +3,10 @@
require 'common'
# this is an abstract class
# TODO : verify state before sending, respect max size
# TODO :
# - verify state before sending
# - respect max size (and require min size)
# - ERROR_RESP handling
class Client < SAP
# make the class abstract
@ -45,7 +48,7 @@ class Client < SAP
# verify response
if connection_status==0x00 and message[:payload].size==2 then
# OK, Server can fulfill requirements
log("client","connection to server succeded",3)
log("client","connected",3)
set_state :idle
elsif connection_status==0x02 and message[:payload].size==2 then
# Error, Server does not support maximum message size
@ -56,12 +59,15 @@ class Client < SAP
set_state :not_connected
raise "connection error"
end
when "DISCONNECT_RESP"
log("client","disconnected",3)
set_state :not_connected
@end=true
else
raise "not implemented or unknown message type : #{message[:name]}"
end
end
# send CONNECT_REQ
def connect
log("client","connecting",3)
until @state==:idle do
@ -81,15 +87,18 @@ class Client < SAP
return true
end
# send TRANSFER_ATR_REQ
def get_atr
if @state == :idle then
connect = create_message("TRANSFER_ATR_REQ",[])
def disconnect
log("client","disconnecting",3)
if @state==:not_connected or @state==:connection_under_negociation then
raise "can not disconnect. must be connected, current state : #{@state}"
return false
else # send DISCONNECT_REQ
connect = create_message("DISCONNECT_REQ")
send(connect)
@state = :processing_atr_request
else
@sap.close
raise "can request ATR. required state : idle, current state : #{@sate}"
until @state==:not_connected
sleep 0.1
end
return true
end
end

View File

@ -156,9 +156,9 @@ class SAP
# start listening the connection
def start
until @end do
log("task","select",3)
log("IO","select",3)
activity = IO.select([@io])
log("task","activity",3)
log("IO","activity",3)
begin
input = activity[0][0].readpartial(4096)
rescue EOFError
@ -237,7 +237,7 @@ class SAP
# create a message
# - type : message id or name
# - payload : array [parameter id or name, content]
def create_message(type,payload)
def create_message(type,payload=nil)
# the type
msg_type = nil
@ -253,6 +253,7 @@ class SAP
# the parameters
message[:payload] = []
payload = [] unless payload
payload.each do |parameter|
param_type = nil
if parameter[0].kind_of?(Fixnum) then

View File

@ -12,4 +12,5 @@ end
io = TCPSocket.open("localhost",1234)
client = DemoClient.new(io)
client.start
client.connect
client.connect
client.disconnect

View File

@ -4,7 +4,13 @@
require 'common'
# this is an bastract class
# TODO : respect max message size
# TODO (not implemented) :
# - respect max message size (and check minimum)
# - refuse connection if card is missing
# - server initiated disconnect (when programm want to exit or card is lost)
# - transport protocol change
# - power sim on/off or reset
# - ERROR_RESP sending (instead of exception)
class Server < SAP
# make the class abstract
@ -25,7 +31,7 @@ class Server < SAP
# initiate the state machine (connect_req)
set_state :not_connected
@max_msg_size = 0x0fff
@max_msg_size = 0xffff
end
@ -68,8 +74,11 @@ class Server < SAP
set_state :idle
log("server","connection established",3)
end
when "STATUS_IND"
when "DISCONNECT_REQ"
log("server","client disconneting",3)
response = create_message("DISCONNECT_RESP")
send(response)
set_state :not_connected
else
raise "not implemented or unknown message type : #{message[:name]}"
end