Navigation Menu

Skip to content

Commit

Permalink
set things up so you can specify a particular rig using the global va…
Browse files Browse the repository at this point in the history
…r. wrote spec tests
  • Loading branch information
dougsko committed Sep 8, 2009
1 parent bfec3c5 commit 68f8bd6
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 105 deletions.
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2009 dougsko

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Empty file removed README
Empty file.
18 changes: 18 additions & 0 deletions README.rdoc
@@ -0,0 +1,18 @@
= rham

A ruby wrapper for libham.

== Note on Patches/Pull Requests

* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
(if you want to have your own version, that is fine but
bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.

== Copyright

Copyright (c) 2009 dougsko. See LICENSE for details.
126 changes: 41 additions & 85 deletions Rakefile
@@ -1,94 +1,50 @@
#!/usr/bin/env ruby

require 'rake/rdoctask'
require 'rake/testtask'
require 'rake/gempackagetask'

# Define global vars
PROJECT = "Rham"
MY_NAME = "Doug Prostko"
MY_EMAIL = "dougtko@gmail.com"
PROJECT_SUMMARY = "libham wrapper"
UNIX_NAME = "rham"
WEBSITE_DIR = "."
RDOC_HTML_DIR = "#{WEBSITE_DIR}/rdoc"
DEPS = ""

# Find version info
REQUIRE_PATHS = ["."]
$LOAD_PATH.concat(REQUIRE_PATHS)
# This library file defines the MyProject::VERSION constant.
require_files = FileList["ext/*.so", "lib/*.rb"]
require_files.each do |file|
require file
require 'rubygems'
require 'rake'

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "rham"
gem.summary = %Q{A ruby wrapper for libham}
gem.description = %Q{ruby wrapper for libham}
gem.email = "dougtko@gmail.com"
gem.homepage = "http://github.com/dougsko/rham"
gem.authors = ["dougsko"]
gem.add_development_dependency "rspec"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
PROJECT_VERSION = eval("#{PROJECT}::VERSION")

# Options common to RDocTask AND Gem::Specification.
# The --main argument specifies which file appears on the index.html page
GENERAL_RDOC_OPTS = {
"--title" => "#{PROJECT} Documentation",
"--main" => "README",
}

# Extra RDOC files
RDOC_FILES = FileList["README", "LICENSE"]

# Filelist with Test::Unit test cases.
TEST_FILES = FileList["test/**/*.rb"]

# Executable scripts, all non-garbage files under bin/.
BIN_FILES = FileList["**/*.rb"]

# This filelist is used to create source packages.
# Include all Ruby and RDoc files.
DIST_FILES = FileList["**/*.rdoc", "README", "LICENSE"]
DIST_FILES.include("Rakefile")
DIST_FILES.include(BIN_FILES)
DIST_FILES.include("ext/*.so", "lib/*.rb", "lib/*.so")

# Run the tests if rake is invoked without arguments.
task "default" => ["test"]
test_task_name = "test"
Rake::TestTask.new(test_task_name) do |t|
t.test_files = TEST_FILES
t.libs = REQUIRE_PATHS
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
spec.spec_opts = ['--color']
end

# The "rdoc" task generates API documentation.
Rake::RDocTask.new("rdoc") do |t|
t.rdoc_files = RDOC_FILES + BIN_FILES
t.title = GENERAL_RDOC_OPTS["--title"]
t.main = GENERAL_RDOC_OPTS["--main"]
t.rdoc_dir = RDOC_HTML_DIR
Spec::Rake::SpecTask.new(:rcov) do |spec|
spec.libs << 'lib' << 'spec'
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
spec.spec_opts = ['--color']
end

GEM_SPEC = Gem::Specification.new do |s|
s.name = UNIX_NAME
s.version = PROJECT_VERSION
s.summary = PROJECT_SUMMARY
s.author = MY_NAME
s.email = MY_EMAIL
s.files = DIST_FILES
s.test_files = TEST_FILES
s.has_rdoc = true
s.extra_rdoc_files = RDOC_FILES
s.rdoc_options = GENERAL_RDOC_OPTS.to_a.flatten
s.add_dependency(DEPS)
end
task :spec => :check_dependencies

# Now we can generate the package-related tasks.
Rake::GemPackageTask.new(GEM_SPEC) do |pkg|
pkg.need_zip = true
pkg.need_tar = true
end
task :default => :spec

# The "prepare-release" task makes sure your tests run, and then generates
# files for a new release.
desc "Run tests, generate RDoc and create packages."
task "prepare-release" => ["clobber"] do
puts "Preparing release of #{PROJECT} version #{PROJECT_VERSION}"
Rake::Task["test"].invoke
Rake::Task["rdoc"].invoke
Rake::Task["package"].invoke
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
if File.exist?('VERSION')
version = File.read('VERSION')
else
version = ""
end

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "rham #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb, ext/**/*.c')
end
20 changes: 16 additions & 4 deletions ext/rham.c
Expand Up @@ -13,8 +13,20 @@ static void rig_free(RIG *my_rig){

static VALUE rig_allocate(VALUE self){
RIG *my_rig;
//rig_model_t my_model = RIG_MODEL_DUMMY;
rig_model_t my_model = RIG_MODEL_FT847;
rig_model_t my_model;
char *model;

if(model = STR2CSTR(rb_gv_get("$model"))){
if(model == "ft847"){
my_model = RIG_MODEL_FT847;
}
else{
my_model = RIG_MODEL_DUMMY;
}
}
else{
fprintf(stderr,"You must define the global variable, $model, somewhere in your script");
}

rig_set_debug(RIG_DEBUG_NONE);
my_rig = rig_init(my_model);
Expand All @@ -29,7 +41,7 @@ static VALUE rb_rig_open(VALUE self){
int ret;

Data_Get_Struct(self, RIG, my_rig);

if((ret = rig_open(my_rig)) != RIG_OK)
printf("rig_open: error = %s\n", rigerror(ret));
else
Expand All @@ -43,7 +55,7 @@ static VALUE rb_rig_close(VALUE self){
Data_Get_Struct(self, RIG, my_rig);

if((ret = rig_close(my_rig)) != RIG_OK)
printf("rig_open: error = %s\n", rigerror(ret));
printf("rig_close: error = %s\n", rigerror(ret));
else
return Qnil;
}
Expand Down
2 changes: 0 additions & 2 deletions lib/rham.rb
Expand Up @@ -6,8 +6,6 @@
require 'ext/rham'

class Rham
Rham::VERSION = "0.0.1"

def stats
stats = {}
stats["freq"] = rig_get_freq
Expand Down
45 changes: 45 additions & 0 deletions spec/rham_spec.rb
@@ -0,0 +1,45 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "Rham" do
before(:all) do
$model = "dummy"
@rig = Rham.new
@rig.rig_open
end

after(:all) do
@rig.rig_close
end

it "setsi/gets the mode" do
@rig.rig_set_mode("AM", "normal")
@rig.rig_get_mode.should == "AM"
end

it "sets/gets the freq" do
@rig.rig_set_freq(20000)
@rig.rig_get_freq.should == "20000.000000"
end

it "checks stats" do
stats = @rig.stats
stats["mode"].should == "AM"
stats["freq"].should == "20000.000000"
end

it "checks powerstat" do
@rig.rig_get_powerstat.should == "on"
end

it "checks vfo" do
@rig.rig_get_vfo.should == 0
end

it "checks info" do
@rig.rig_get_info.should == "Nothing much (dummy)"
end

it "checks strength" do
@rig.rig_get_strength.should == 0
end
end
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,9 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'rham'
require 'spec'
require 'spec/autorun'

Spec::Runner.configure do |config|

end
14 changes: 0 additions & 14 deletions test/test.rb

This file was deleted.

0 comments on commit 68f8bd6

Please sign in to comment.