Model for reading created

State pattern implemented
This commit is contained in:
Aart van Halteren
2013-06-26 15:05:20 +02:00
parent e6fc705e6a
commit 58eee12fb5
13 changed files with 236 additions and 18 deletions

View File

@@ -2,17 +2,27 @@ require "rubygems"
require "bundler/setup"
require "active_record"
require "serialport"
require "state_pattern"
project_root = File.dirname(File.absolute_path(__FILE__))
Dir.glob(project_root + "/app/models/*.rb").each{|f| require f}
Dir.glob(project_root + "/app/helpers/*.rb").each{|f| require f}
connection_details = YAML::load(File.open('config/database.yml'))
ActiveRecord::Base.establish_connection(connection_details)
# Open connection to serial port
ser = SerialPort.new("/dev/ttyUSB1", 9600, 7, 1, SerialPort::EVEN)
# # Open connection to serial port
# ser = SerialPort.new("/dev/ttyUSB1", 9600, 7, 1, SerialPort::EVEN)
#
# # read until newline
# response = ser.readline("\r")
# response.chomp!
# print "#{response}\n"
# read until newline
response = ser.readline("\r")
response.chomp!
print "#{response}\n"
sync = Synchronizer.new
lines = File.read("example_blurp.txt")[rand(500)..-1]
while (lines.length > 0)
lines = sync.handle_byte_stream(lines)
end
p sync