attempting unit test
parent
cd325239d1
commit
0a9158a97f
|
@ -41,4 +41,4 @@ config.yml
|
|||
credentials.yml
|
||||
settings.rb
|
||||
/lib/.build
|
||||
|
||||
write_db_settings.rb
|
||||
|
|
50
Gemfile
50
Gemfile
|
@ -3,58 +3,18 @@ source 'https://rubygems.org'
|
|||
# Enable db migration without rails
|
||||
gem 'active_record_migrations'
|
||||
|
||||
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
||||
gem 'rails', '4.0.4'
|
||||
|
||||
# Use sqlite3 as the database for Active Record
|
||||
gem 'sqlite3'
|
||||
|
||||
# Use SCSS for stylesheets
|
||||
gem 'sass-rails', '~> 4.0.2'
|
||||
|
||||
# Use Uglifier as compressor for JavaScript assets
|
||||
gem 'uglifier', '>= 1.3.0'
|
||||
|
||||
# Use CoffeeScript for .js.coffee assets and views
|
||||
gem 'coffee-rails', '~> 4.0.0'
|
||||
|
||||
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
||||
gem 'therubyracer', platforms: :ruby
|
||||
|
||||
# Use jquery as the JavaScript library
|
||||
gem 'jquery-rails'
|
||||
|
||||
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
|
||||
gem 'turbolinks'
|
||||
|
||||
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
||||
gem 'jbuilder', '~> 1.2'
|
||||
|
||||
group :doc do
|
||||
# bundle exec rake doc:rails generates the API under doc/api.
|
||||
gem 'sdoc', require: false
|
||||
end
|
||||
|
||||
# Use bson for database functionality
|
||||
gem 'bson'
|
||||
# Use skynet machine instant messaging
|
||||
gem 'socket.io-client-simple'
|
||||
|
||||
# serial port
|
||||
gem 'serialport'
|
||||
|
||||
# polyglot
|
||||
gem 'polyglot'
|
||||
|
||||
# httparty
|
||||
gem 'httparty'
|
||||
|
||||
# Use ActiveModel has_secure_password
|
||||
# gem 'bcrypt', '~> 3.1.7'
|
||||
|
||||
# Use unicorn as the app server
|
||||
# gem 'unicorn'
|
||||
|
||||
# Use Capistrano for deployment
|
||||
# gem 'capistrano', group: :development
|
||||
|
||||
# Use debugger
|
||||
# gem 'debugger', group: [:development, :test]
|
||||
# Dev / Test stuff
|
||||
# TODO : Setup dev / test / production env.
|
||||
gem 'pry'
|
||||
|
|
57
README.md
57
README.md
|
@ -20,29 +20,28 @@ Raspberry PI
|
|||
------------
|
||||
|
||||
Update the RPi, install ruby, firmate and the arduino IDE
|
||||
|
||||
```
|
||||
sudo apt-get update
|
||||
sudo apt-get install git-core
|
||||
sudo apt-get install ruby-dev
|
||||
sudo apt-get install sqlite3-dev
|
||||
sudo apt-get install arduino
|
||||
sudo apt-get install git-core ruby-dev sqlite3 arduino bundler
|
||||
```
|
||||
|
||||
retrieving code from github:
|
||||
|
||||
```
|
||||
git clone https://github.com/FarmBot/farmbot-raspberry-pi-controller
|
||||
|
||||
```
|
||||
prepping ruby:
|
||||
```
|
||||
cd farmbot-raspberry-pi-controller
|
||||
'bundle install --without test development' from the project directory
|
||||
OR
|
||||
'bundle install' (for developers)
|
||||
|
||||
temporary:
|
||||
- gem install bson
|
||||
- gem install firmata
|
||||
- gem install socket.io-client-simple
|
||||
sudo gem install bundler
|
||||
sudo gem install sqlite3 -v '1.3.10'
|
||||
bundler update
|
||||
bundle install
|
||||
```
|
||||
|
||||
Setup the database
|
||||
```
|
||||
rake db:migrate
|
||||
```
|
||||
|
||||
Arduino
|
||||
-------
|
||||
|
@ -56,12 +55,34 @@ Upload to the arduino
|
|||
Usage
|
||||
=====
|
||||
|
||||
Use "ruby sync.rb" to start the skybet communiation ans synchronisation with the farmbot back end
|
||||
|
||||
Use "ruby runtime.rb" to start the runtime part of the software. This will read the datbase and send commands to the hardware.
|
||||
Use "ruby farmbot.rb" to start hardware control and skynet communiation
|
||||
|
||||
Use "ruby menu.rb" to start the interface. A menu will appear. Type the command needed and press enter. It is also possible to add a list of commands to the file 'testcommands.csv' and use the menu to execute the file.
|
||||
|
||||
To change parameters manually, edit the file "write_db_settings.rb" and run the command "ruby write_db_settings.rb"
|
||||
|
||||
Duriing running in the console, a few basic staatus parameters are displayed:
|
||||
|
||||
x 0000 *- y 0000 -- z 0000 *-
|
||||
|
||||
For each axis, the coordinates are shown and the status of the end stops. A "-" means the end stop is not activared, a "*" means the and stop is activated. First the home end point is displayed, then the end-of-line end stop.
|
||||
|
||||
Main software structure
|
||||
=======================
|
||||
|
||||
```
|
||||
/farmbot.rb +-----> /lib/messaging.rb
|
||||
|
|
||||
| /lib/messaging/messaging.rb
|
||||
|
|
||||
| /lib/messaging/messagehandler.rb
|
||||
|
|
||||
+-----> /lib/controller.rb
|
||||
|
|
||||
|
|
||||
+-----> /hardware/gcode/ramps.rb
|
||||
```
|
||||
|
||||
Author
|
||||
------
|
||||
|
||||
|
|
11
Rakefile
11
Rakefile
|
@ -1,4 +1,5 @@
|
|||
require 'active_record_migrations'
|
||||
require 'rake/testtask'
|
||||
|
||||
ActiveRecordMigrations.configure do |c|
|
||||
c.database_configuration = {
|
||||
|
@ -6,7 +7,7 @@ ActiveRecordMigrations.configure do |c|
|
|||
'database' => 'db/db.sqlite3'},
|
||||
}
|
||||
# Other settings:
|
||||
#c.schema_format = :sql # default is :ruby
|
||||
# c.schema_format = :sql # default is :ruby
|
||||
# c.yaml_config = 'db/config.yml'
|
||||
# c.environment = ENV['db']
|
||||
# c.db_dir = 'db'
|
||||
|
@ -15,3 +16,11 @@ ActiveRecordMigrations.configure do |c|
|
|||
end
|
||||
|
||||
ActiveRecordMigrations.load_tasks
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
t.libs << 'test'
|
||||
t.test_files = Dir.glob('test/**/*_test.rb')
|
||||
end
|
||||
|
||||
desc "Run tests"
|
||||
task :default => :test
|
||||
|
|
|
@ -21,7 +21,7 @@ $db_write_sync = Mutex.new
|
|||
print 'database '
|
||||
require 'active_record'
|
||||
require_relative 'lib/database/dbaccess'
|
||||
$bot_dbaccess = DbAccess.new
|
||||
$bot_dbaccess = DbAccess.new('development')
|
||||
puts 'OK'
|
||||
|
||||
print 'synchronization '
|
||||
|
|
|
@ -8,7 +8,11 @@ class ControllerCommandProc
|
|||
end
|
||||
|
||||
def whitelist
|
||||
['MOVE ABSOLUTE','MOVE RELATIVE','HOME X','HOME Y','HOME Z','CALIBRATE X','CALIBRATE Y','CALIBRATE Z','DOSE WATER','SET SPEED','PIN WRITE','PIN READ','PIN MODE','PIN PULSE','SERVO MOVE']
|
||||
['move_absolute','move_relative','home_x','home_y','home_z','calibrate_x','calibrate_y','calibrate_z','dose_water','set_speed','pin_write','pin_read','pin_mode','pin_pulse','servo_move']
|
||||
end
|
||||
|
||||
def check_whitelist(function)
|
||||
raise "UNAUTHORIZED" unless whitelist.include?(function.upcase)
|
||||
end
|
||||
|
||||
def process_command( cmd )
|
||||
|
@ -30,7 +34,8 @@ class ControllerCommandProc
|
|||
def send_command(command_line)
|
||||
if $hardware_sim == 0
|
||||
function = command_line.action.downcase.sub(' ','_')
|
||||
puts function
|
||||
#puts function
|
||||
check_whitelist(function)
|
||||
send(function, command_line)
|
||||
else
|
||||
@bot_dbaccess.write_to_log(1,'>simulating hardware<')
|
||||
|
|
|
@ -15,9 +15,9 @@ require_relative 'dbaccess_measurements.rb'
|
|||
|
||||
class DbAccess
|
||||
|
||||
def initialize
|
||||
def initialize(environemnt)
|
||||
config = YAML::load(File.open('./config/database.yml'))
|
||||
ActiveRecord::Base.establish_connection(config["development"])
|
||||
ActiveRecord::Base.establish_connection(config[environment])
|
||||
|
||||
@commands = DbAccessCommands.new
|
||||
@refreshes = DbAccessRefreshes.new
|
||||
|
|
|
@ -21,9 +21,13 @@ class DbAccessLogs
|
|||
# write a line to the log
|
||||
#
|
||||
def write_to_log(module_id,text)
|
||||
|
||||
puts "[LOG] #{text}"
|
||||
|
||||
log = Log.new
|
||||
log.text = text
|
||||
log.module_id = module_id
|
||||
|
||||
$db_write_sync.synchronize do
|
||||
log.save
|
||||
end
|
||||
|
|
43
protocols.md
43
protocols.md
|
@ -84,17 +84,30 @@ z |decimal|same as x
|
|||
speed |string |speed for movements, as text. for example 'traveling', 'manouvering'
|
||||
amount |decimal|amount of mililiter of water to dose. always add parameter with default value
|
||||
delay |decimal|amount in seconds to delay the execution of a command
|
||||
pin_nr |decimal|the number of the pin to change or pin for servo, using arduino numbering
|
||||
pin_value1|decimal|the value for the pin, for servo movement the angle
|
||||
pin_value2|decimal|when using a pulse, this is the value for the second flank of the pulse
|
||||
pin_mode |decimal|for setting the I/O mode, 0 is input, 1 is output. For reading and writing, 0 is digital and 1 is analog
|
||||
pin_time |decimal||the time im seconds for a pulse
|
||||
|
||||
|
||||
|
||||
actions and parameters used:
|
||||
|
||||
action |x |y |z |speed|amount|delay
|
||||
-------------|-------|-------|-------|-----|------|-----
|
||||
MOVE RELATIVE|X |X |X |X | |X
|
||||
MOVE ABSOLUTE|X |X |X |X | |X
|
||||
DOSE WATER | | | | |X |X
|
||||
HOME X | | | |X | |X
|
||||
HOME Y | | | |X | |X
|
||||
HOME Z | | | |X | |X
|
||||
action |x |y |z |speed|amount|delay|pin_nr|pin_value1|pin_value2|pin_mode|pin_time
|
||||
-------------|-------|-------|-------|-----|------|-----|------|----------|----------|--------|--------
|
||||
MOVE RELATIVE|X |X |X |X | |X | | | | |
|
||||
MOVE ABSOLUTE|X |X |X |X | |X | | | | |
|
||||
DOSE WATER | | | | |X |X | | | | |
|
||||
HOME X | | | |X | |X | | | | |
|
||||
HOME Y | | | |X | |X | | | | |
|
||||
HOME Z | | | |X | |X | | | | |
|
||||
PIN WRITE | | | | | |X |X |X | |X |
|
||||
PIN READ | | | | | |X |X | | |X |
|
||||
PIN MODE | | | | | |X |X | | |X |
|
||||
PIN PULSE | | | | | |X |X |X |X |X |X
|
||||
SERVO MOVE | | | | | |X |X |X | | |
|
||||
|
||||
|
||||
Device status
|
||||
=============
|
||||
|
@ -118,7 +131,19 @@ Read status
|
|||
"status_movement" => "idle",
|
||||
"status_last_command_executed" => "2014/06/26 20:05:08 -0100",
|
||||
"status_next_command_scheduled" => nil,
|
||||
"status_nr_of_commands_executed" => 1
|
||||
"status_nr_of_commands_executed" => 1,
|
||||
"status_current_x" => 10,
|
||||
"status_current_y" => 20,
|
||||
"status_current_z" => 30,
|
||||
"status_target_x" => 40,
|
||||
"status_target_y" => 50,
|
||||
"status_target_z" => 60,
|
||||
"status_end_stop_x_a" => true,
|
||||
"status_end_stop_x_b" => false,
|
||||
"status_end_stop_y_a" => true,
|
||||
"status_end_stop_y_b" => false,
|
||||
"status_end_stop_z_a" => true,
|
||||
"status_end_stop_z_b" => false
|
||||
}
|
||||
```
|
||||
|
||||
|
|
10
settings.rb
10
settings.rb
|
@ -1,7 +1,7 @@
|
|||
$status_debug_msg = false
|
||||
$hardware_sim = 0
|
||||
#$hardware_type = "lib/hardware/firmata/ramps"
|
||||
$hardware_type = "lib/hardware/gcode/ramps"
|
||||
#$hardware_type = nil
|
||||
$status_debug_msg = false
|
||||
$hardware_sim = 0
|
||||
#$hardware_type = "lib/hardware/firmata/ramps"
|
||||
$hardware_type = "lib/hardware/gcode/ramps"
|
||||
#$hardware_type = nil
|
||||
|
||||
$controller_disable = 0
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
require 'test_helper'
|
||||
require 'test/unit'
|
||||
#require 'rake/testtask'
|
||||
#require 'lib/database/dbaccess.rb'
|
||||
require './lib/database/dbaccess.rb'
|
||||
|
||||
class TestCredentials < Minitest::Test
|
||||
def setup
|
||||
@db = DbAccess.new('test')
|
||||
end
|
||||
|
||||
def teardown
|
||||
end
|
||||
|
||||
|
||||
def test_dbaccess_increment_parameters_versoin
|
||||
param_name = 'PARAM_VERSION'
|
||||
write_parameter(param_name, 1)
|
||||
@db.increment_parameters_version
|
||||
return_val = read_parameter(param_name)
|
||||
assert_equal return_val, 2
|
||||
end
|
||||
|
||||
def test_something
|
||||
# assert(false,"this should be true")
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_create_credentials_test_test
|
||||
assert_equal true, false
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
require 'pry'
|
||||
require 'minitest/spec'
|
||||
require 'minitest/autorun'
|
||||
require 'minitest'
|
Loading…
Reference in New Issue