Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-levy committed Mar 13, 2023
1 parent 8aaabd4 commit 30387c3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
40 changes: 40 additions & 0 deletions src/connection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ end

struct TimeoutError <: Exception end

"""
open_connection(ip::String, port::Integer)
Open a connection to a TCP server and return the `Connection`.
The `ip` must be a string formatted as `"123.123.123.123"`
"""
function open_connection(ip::String, port::Integer)
return Connection(ip, port)
end
Expand All @@ -40,10 +47,38 @@ function connection_task(socket, command_channel, data_channel)
@info "Connection task completed"
end

"""
send(connection::Connection, msg::String)
Send a message.
# Arguments
- `connection`: the `Connection` obtained from `open_connection`.
- `msg`: the message to be sent. Note: some TCP servers may be require the
message be formatted a certain way (such as JSON), and may also require an
end of line character, such as `\\n`, to terminate the message.
"""
function send(connection::Connection, msg::String)
put!(connection.command_channel, (:send, msg))
end

"""
send_receive(connection::Connection, msg::String, timeout::Real = 10.0)
Sends a message and waits for a response, which is then returned. This function
blocks execution while waiting, up to the timeout duration provided. If the
timeout duration elapses without the arrival of data, throws a TimeoutError
exception. Note: the payload which is returned will be in a raw format. To
convert to a string, use `String(payload)`. This string may further converted to
other formats such as JSON.
# Arguments
- `connection`: the `Connection` obtained from `open_connection`.
- `msg`: the message to be sent. Note: some TCP servers may be require the
message be formatted a certain way (such as JSON), and may also require an
end of line character, such as `\\n`, to terminate the message.
- `timeout`: maximum time in seconds to wait for data.
"""
function send_receive(connection::Connection, msg::String, timeout::Real = 10.0)
t = Timer(_ -> timeout_callback(connection), timeout)
payload = nothing
Expand All @@ -67,6 +102,11 @@ function timeout_callback(connection::Connection)
throw(TimeoutError())
end

"""
close_connection(connection::Connection)
Close the connection to the TCP server.
"""
function close_connection(connection::Connection)
@info "Stopping server ..."
put!(connection.command_channel, (:close, ""))
Expand Down
4 changes: 2 additions & 2 deletions src/state_feedback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end
Open a connection to the ROS node and return the `FeedbackConnection`.
The `ip` must be a string formated as `"123.123.123.123"`
The `ip` must be a string formatted as `"123.123.123.123"`
"""
function open_feedback_connection(ip::String, port::Integer)
return open_connection(ip, port)
Expand All @@ -33,7 +33,7 @@ end
Waits for data to arrive from the ROS node and returns a struct of the data with
the following fields: position, orientation, linear_vel, angular_vel. This
function blocks execution while waiting, up to the timout duration provided. If
function blocks execution while waiting, up to the timeout duration provided. If
the timeout duration elapses without the arrival of data, throws a TimeoutError
exception.
Expand Down
2 changes: 1 addition & 1 deletion src/velocity_control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Open a connection to the ROS node and return the `RobotConnection`.
The `ip` must be a string formated as `"123.123.123.123"`
The `ip` must be a string formatted as `"123.123.123.123"`
"""
function open_robot_connection(ip::String, port::Integer)
return open_connection(ip, port)
Expand Down

0 comments on commit 30387c3

Please sign in to comment.