nickel-silver-server 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +8 -2
- data/README.txt +13 -11
- data/lib/nickel-silver-server/version.rb +1 -1
- data/lib/nickel-silver-server.rb +50 -4
- metadata +1 -1
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 0.0.3 2008-03-19
|
2
|
+
* 1 minor enhancement:
|
3
|
+
* Tidy before first 'public' release
|
4
|
+
|
5
|
+
== 0.0.2 2008-03-19
|
6
|
+
* 1 bugfix
|
7
|
+
* Correctly load interface and server files when gem is 'require'd
|
8
|
+
|
1
9
|
== 0.0.1 2008-03-18
|
2
10
|
|
3
11
|
* 3 major enhancements:
|
@@ -5,5 +13,3 @@
|
|
5
13
|
* Complete LocoNetOverTCP version 1 implementation
|
6
14
|
* Support for the LocoBuffer-USB
|
7
15
|
|
8
|
-
* 1 bugfix
|
9
|
-
* Correctly load interface and server files when gem is 'require'd
|
data/README.txt
CHANGED
@@ -4,29 +4,31 @@
|
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
|
-
|
7
|
+
A Ruby server implementing the LocoNetOverTCP protocol allowing remote clients to connect to Digitrax based model railway layouts. Currently supports version 1 of the protocol.
|
8
8
|
|
9
9
|
== FEATURES/PROBLEMS:
|
10
10
|
|
11
11
|
* Complete support for LocoNetOverTCP version 1
|
12
|
+
* Multithreaded server based on GServer
|
13
|
+
* Easily extended to use new hardware interfaces
|
12
14
|
|
13
15
|
== SYNOPSIS:
|
14
16
|
|
15
17
|
require 'rubygems'
|
16
|
-
|
18
|
+
require 'nickel-silver-server'
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
+
# connect to a LocoBufferUSB on the virtual serial port /dev/tty.serialport
|
21
|
+
interface = LocoBufferUSB.new( '/dev/tty.serialport' )
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
# create a server using the default port (i.e. 5626, 'loco' spelt on a phone keypad)
|
24
|
+
# using our freshly connected LocoBuffer-USB
|
25
|
+
server = LocoNetServer.new( interface )
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
+
# start the server
|
28
|
+
server.start
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
+
# wait for the server to stop before exiting
|
31
|
+
server.join
|
30
32
|
|
31
33
|
== REQUIREMENTS:
|
32
34
|
|
data/lib/nickel-silver-server.rb
CHANGED
@@ -5,12 +5,58 @@ require 'loconetserver'
|
|
5
5
|
|
6
6
|
module NickelSilver
|
7
7
|
module Server
|
8
|
-
# nothing here yet
|
9
|
-
# all the action is in LocoNetServer.rb
|
10
8
|
|
9
|
+
# An interface class should provide the following:
|
10
|
+
# * Store incoming packets as FixNums representing bytes in a buffer array
|
11
|
+
# * Send outgoing bytes (represented as FixNums in a buffer array) to LocoNet
|
12
|
+
# * Use a Mutex to lock access to the buffers when in use (remember Nickel-Silver is multithreaded)
|
13
|
+
# * Provide a method that causes your interface to start collecting packets
|
14
|
+
#
|
15
|
+
# The interface is simple. Only the following public methods are needed:
|
16
|
+
# * Accessors for input_buffer, output_buffer and io_mutex
|
17
|
+
# * run() which starts buffering
|
18
|
+
#
|
19
|
+
# How you do this will depend upon your hardware. Take a look at the LocoBufferUSB class to get
|
20
|
+
# an idea of how it might be done.
|
21
|
+
#
|
22
|
+
# A stub driver might look like the following...
|
23
|
+
#
|
24
|
+
# class SomeLocoNetInterface
|
25
|
+
# attr_accessor :input_buffer, :output_buffer, :io_mutex
|
26
|
+
#
|
27
|
+
# def initialize
|
28
|
+
# # these may be modified at any time by the server
|
29
|
+
# @input_buffer = []
|
30
|
+
# @output_buffer = []
|
31
|
+
#
|
32
|
+
# # only make changes when locked using @io_mutex
|
33
|
+
# @io_mutex = Mutex.new
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# def run
|
37
|
+
# loop do
|
38
|
+
# # get incoming bytes
|
39
|
+
# if byte_waiting?
|
40
|
+
# @io_mutex.synchronize do
|
41
|
+
# # byte getting code here
|
42
|
+
# @input_buffer << get_byte
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# # send outgoing bytes
|
47
|
+
# until @output_buffer.empty? do
|
48
|
+
# @io_mutex.synchronize do
|
49
|
+
# # send a byte
|
50
|
+
# send_byte( @output_buffer.shift )
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# end
|
57
|
+
#
|
11
58
|
module Interface
|
12
|
-
# nothing here yet
|
13
|
-
# all the action is in LocoBufferUSB.rb
|
14
59
|
end
|
60
|
+
|
15
61
|
end
|
16
62
|
end
|