nabaztag_hack_kit 0.0.3 → 0.1.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +7 -1
  4. data/Rakefile +2 -17
  5. data/{ext/bytecode → bytecode}/Docs.md +2 -1
  6. data/bytecode/Rakefile +7 -0
  7. data/{bin → bytecode/bin}/mtl_comp +9 -0
  8. data/{bin → bytecode/bin}/mtl_merge +2 -2
  9. data/{bin → bytecode/bin}/mtl_simu +9 -0
  10. data/bytecode/lib/buffer.mtl +6 -0
  11. data/bytecode/lib/button.mtl +18 -12
  12. data/bytecode/lib/ear.mtl +3 -3
  13. data/bytecode/lib/led.mtl +1 -1
  14. data/bytecode/lib/ping.mtl +16 -0
  15. data/bytecode/lib/record.mtl +87 -0
  16. data/bytecode/lib/rfid.mtl +3 -21
  17. data/bytecode/main.mtl +86 -29
  18. data/{ext/bytecode → bytecode/src}/lib/http.mtl +15 -3
  19. data/{ext/bytecode → bytecode/src}/lib/udp.mtl +1 -1
  20. data/{ext/bytecode → bytecode/src}/lib/util.mtl +4 -1
  21. data/bytecode/src/lib/wav.mtl +223 -0
  22. data/{ext → bytecode/src}/mtl/README.md +2 -2
  23. data/{ext/bytecode → bytecode/src}/nominal-ping.mtl +123 -124
  24. data/{test/bytecode → bytecode/test}/native.mtl +11 -1
  25. data/{test/bytecode → bytecode/test}/test.mtl +3 -3
  26. data/examples/record/Gemfile +5 -0
  27. data/examples/record/config.ru.example +19 -0
  28. data/examples/record/server.rb +112 -0
  29. data/examples/simple/Gemfile +6 -0
  30. data/examples/simple/Procfile +3 -0
  31. data/{config.ru → examples/simple/config.ru} +3 -1
  32. data/lib/nabaztag_hack_kit/message/api.rb +8 -0
  33. data/lib/nabaztag_hack_kit/message/helper.rb +26 -2
  34. data/lib/nabaztag_hack_kit/message.rb +11 -5
  35. data/lib/nabaztag_hack_kit/public/index.html +5 -0
  36. data/lib/nabaztag_hack_kit/server.rb +54 -8
  37. data/lib/nabaztag_hack_kit/version.rb +1 -1
  38. data/nabaztag_hack_kit.gemspec +4 -3
  39. data/spec/integration/server_spec.rb +50 -0
  40. data/{test → spec}/spec_helper.rb +1 -1
  41. data/{test → spec}/unit/message_spec.rb +2 -2
  42. data/spec/unit/server_spec.rb +40 -0
  43. metadata +140 -119
  44. data/public/bytecode.bin +0 -0
  45. /data/{ext/bytecode → bytecode}/Commands.md +0 -0
  46. /data/{ext/bytecode → bytecode/src}/README.md +0 -0
  47. /data/{ext/bytecode → bytecode/src}/lib/arp.mtl +0 -0
  48. /data/{ext/bytecode → bytecode/src}/lib/cfg.mtl +0 -0
  49. /data/{ext/bytecode → bytecode/src}/lib/choreos.mtl +0 -0
  50. /data/{ext/bytecode → bytecode/src}/lib/dhcp.mtl +0 -0
  51. /data/{ext/bytecode → bytecode/src}/lib/dns.mtl +0 -0
  52. /data/{ext/bytecode → bytecode/src}/lib/tcp.mtl +0 -0
  53. /data/{ext/bytecode → bytecode/src}/lib/var.mtl +0 -0
  54. /data/{ext/bytecode → bytecode/src}/lib/wifi.mtl +0 -0
  55. /data/{ext → bytecode/src}/mtl/Makefile +0 -0
  56. /data/{ext → bytecode/src}/mtl/bc.cpp +0 -0
  57. /data/{ext → bytecode/src}/mtl/conf.bin.sans_password +0 -0
  58. /data/{ext → bytecode/src}/mtl/config.txt +0 -0
  59. /data/{ext → bytecode/src}/mtl/dumpbc.c +0 -0
  60. /data/{ext → bytecode/src}/mtl/extconf.rb +0 -0
  61. /data/{ext → bytecode/src}/mtl/linux_simu.c +0 -0
  62. /data/{ext → bytecode/src}/mtl/linux_simuaudio.c +0 -0
  63. /data/{ext → bytecode/src}/mtl/linux_simuaudio.h +0 -0
  64. /data/{ext → bytecode/src}/mtl/linux_simunet.c +0 -0
  65. /data/{ext → bytecode/src}/mtl/linux_simunet.h +0 -0
  66. /data/{ext → bytecode/src}/mtl/log.c +0 -0
  67. /data/{ext → bytecode/src}/mtl/log.h +0 -0
  68. /data/{ext → bytecode/src}/mtl/main_compiler.cpp +0 -0
  69. /data/{ext → bytecode/src}/mtl/main_simu.cpp +0 -0
  70. /data/{ext → bytecode/src}/mtl/mp3/GTKANAL.H +0 -0
  71. /data/{ext → bytecode/src}/mtl/mp3/LAYER3.C +0 -0
  72. /data/{ext → bytecode/src}/mtl/mp3/TABINIT.C +0 -0
  73. /data/{ext → bytecode/src}/mtl/mp3/common.c +0 -0
  74. /data/{ext → bytecode/src}/mtl/mp3/dct64_i386.c +0 -0
  75. /data/{ext → bytecode/src}/mtl/mp3/decode_i386.c +0 -0
  76. /data/{ext → bytecode/src}/mtl/mp3/huffman.h +0 -0
  77. /data/{ext → bytecode/src}/mtl/mp3/interface.c +0 -0
  78. /data/{ext → bytecode/src}/mtl/mp3/mpg123.h +0 -0
  79. /data/{ext → bytecode/src}/mtl/mp3/mpglib.h +0 -0
  80. /data/{ext → bytecode/src}/mtl/properties.c +0 -0
  81. /data/{ext → bytecode/src}/mtl/properties.h +0 -0
  82. /data/{ext → bytecode/src}/mtl/simu.c +0 -0
  83. /data/{ext → bytecode/src}/mtl/simuaudio.c +0 -0
  84. /data/{ext → bytecode/src}/mtl/simuaudio.h +0 -0
  85. /data/{ext → bytecode/src}/mtl/simunet.c +0 -0
  86. /data/{ext → bytecode/src}/mtl/simunet.h +0 -0
  87. /data/{ext → bytecode/src}/mtl/utils/correct_const.sh +0 -0
  88. /data/{ext → bytecode/src}/mtl/vaudio.c +0 -0
  89. /data/{ext → bytecode/src}/mtl/vaudio.h +0 -0
  90. /data/{ext → bytecode/src}/mtl/vbc.h +0 -0
  91. /data/{ext → bytecode/src}/mtl/vbc_str.h +0 -0
  92. /data/{ext → bytecode/src}/mtl/vcomp/Makefile +0 -0
  93. /data/{ext → bytecode/src}/mtl/vcomp/bootstrap.cpp +0 -0
  94. /data/{ext → bytecode/src}/mtl/vcomp/compiler.cpp +0 -0
  95. /data/{ext → bytecode/src}/mtl/vcomp/compiler.h +0 -0
  96. /data/{ext → bytecode/src}/mtl/vcomp/compiler_file.cpp +0 -0
  97. /data/{ext → bytecode/src}/mtl/vcomp/compiler_prog.cpp +0 -0
  98. /data/{ext → bytecode/src}/mtl/vcomp/compiler_term.cpp +0 -0
  99. /data/{ext → bytecode/src}/mtl/vcomp/compiler_type.cpp +0 -0
  100. /data/{ext → bytecode/src}/mtl/vcomp/compiler_var.cpp +0 -0
  101. /data/{ext → bytecode/src}/mtl/vcomp/file.cpp +0 -0
  102. /data/{ext → bytecode/src}/mtl/vcomp/file.h +0 -0
  103. /data/{ext → bytecode/src}/mtl/vcomp/filesystem.h +0 -0
  104. /data/{ext → bytecode/src}/mtl/vcomp/interpreter.cpp +0 -0
  105. /data/{ext → bytecode/src}/mtl/vcomp/interpreter.h +0 -0
  106. /data/{ext → bytecode/src}/mtl/vcomp/memory.cpp +0 -0
  107. /data/{ext → bytecode/src}/mtl/vcomp/memory.h +0 -0
  108. /data/{ext → bytecode/src}/mtl/vcomp/param.h +0 -0
  109. /data/{ext → bytecode/src}/mtl/vcomp/parser.cpp +0 -0
  110. /data/{ext → bytecode/src}/mtl/vcomp/parser.h +0 -0
  111. /data/{ext → bytecode/src}/mtl/vcomp/parser_xml.cpp +0 -0
  112. /data/{ext → bytecode/src}/mtl/vcomp/prodbuffer.cpp +0 -0
  113. /data/{ext → bytecode/src}/mtl/vcomp/prodbuffer.h +0 -0
  114. /data/{ext → bytecode/src}/mtl/vcomp/resource.h +0 -0
  115. /data/{ext → bytecode/src}/mtl/vcomp/stdlib_core.cpp +0 -0
  116. /data/{ext → bytecode/src}/mtl/vcomp/terminal.cpp +0 -0
  117. /data/{ext → bytecode/src}/mtl/vcomp/terminal.h +0 -0
  118. /data/{ext → bytecode/src}/mtl/vcomp/util.cpp +0 -0
  119. /data/{ext → bytecode/src}/mtl/vcomp/util.h +0 -0
  120. /data/{ext → bytecode/src}/mtl/vinterp.c +0 -0
  121. /data/{ext → bytecode/src}/mtl/vinterp.h +0 -0
  122. /data/{ext → bytecode/src}/mtl/vloader.c +0 -0
  123. /data/{ext → bytecode/src}/mtl/vloader.h +0 -0
  124. /data/{ext → bytecode/src}/mtl/vlog.c +0 -0
  125. /data/{ext → bytecode/src}/mtl/vlog.h +0 -0
  126. /data/{ext → bytecode/src}/mtl/vmem.c +0 -0
  127. /data/{ext → bytecode/src}/mtl/vmem.h +0 -0
  128. /data/{ext → bytecode/src}/mtl/vnet.c +0 -0
  129. /data/{ext → bytecode/src}/mtl/vnet.h +0 -0
  130. /data/{test/bytecode → bytecode/test}/helper.mtl +0 -0
@@ -18,6 +18,16 @@ let test "strcatlist" -> t in
18
18
  assert_equalS "313233" strcatlist "31"::"32"::"33"::nil
19
19
  );
20
20
 
21
+ let test "rev" -> t in
22
+ (
23
+ assert_equalL 3::2::1::nil rev 1::2::3::nil nil
24
+ );
25
+
26
+ let test "rev" -> t in
27
+ (
28
+ assert_equalS "ABC" "\65\66\67"
29
+ );
30
+
21
31
  // remfromlist same as listrem!!!
22
32
  //let test "remfromlist" -> t in
23
33
  //(
@@ -25,4 +35,4 @@ let test "strcatlist" -> t in
25
35
  // Lecho (remfromlist l (listlen l) - 1)
26
36
  // //assert_equalS "0A000"
27
37
  // assert_equalL 48::49::50::nil listrem 48::49::50::nil 49
28
- //);
38
+ //);
@@ -1,8 +1,8 @@
1
1
  proto main 0;;
2
2
 
3
- #include "../../ext/bytecode/lib/util"
4
- #include "../../bytecode/lib/data_helper"
5
- #include "../../bytecode/lib/buffer"
3
+ #include "../src/lib/util"
4
+ #include "../lib/data_helper"
5
+ #include "../lib/buffer"
6
6
 
7
7
  #include "./helper"
8
8
 
@@ -0,0 +1,5 @@
1
+ # A sample Gemfile
2
+ source "http://rubygems.org"
3
+
4
+ gem "nabaztag_hack_kit"
5
+ gem "ruby-echonest"
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift ::File.expand_path(::File.dirname(__FILE__) + '/lib')
4
+ require './server'
5
+
6
+ use Rack::Reloader, 0
7
+
8
+ ECHONEST_CFG = {
9
+ :key => "",
10
+ }
11
+
12
+ SOUNDCLOUD_CFG = {
13
+ :client_id => "",
14
+ :client_secret => "",
15
+ :username => "",
16
+ :password => "",
17
+ }
18
+
19
+ run Record::Server.new(ECHONEST_CFG, SOUNDCLOUD_CFG)
@@ -0,0 +1,112 @@
1
+
2
+ require "nabaztag_hack_kit/server"
3
+ require "soundcloud"
4
+ require "echonest"
5
+
6
+ class Server < NabaztagHackKit::Server
7
+
8
+ REC_FILE = "rec.wav"
9
+
10
+ def initialize(echonest_cfg, soundcloud_cfg)
11
+ super('bytecode.bin')
12
+ @@echonest = Echonest(echonest_cfg[:key])
13
+ @@soundcloud = Soundcloud.new(soundcloud_cfg)
14
+ end
15
+
16
+ def analyse(file_name)
17
+ @@echonest.track.analysis(file_name)
18
+ end
19
+
20
+ def riff2mp3(file_name)
21
+ `sox #{file_name} -e signed-integer out.wav && lame --quiet --alt-preset standard out.wav out.mp3`
22
+ 'out.mp3'
23
+ end
24
+
25
+ def norm(a, n = 255)
26
+ min = a.min
27
+ max = a.max - min
28
+ a.map do |i|
29
+ (n * ((i - min) / max)).to_i
30
+ end
31
+ end
32
+
33
+ def dance(file_name)
34
+ an = analyse riff2mp3(file_name)
35
+
36
+ puts beats = an.tempo.to_i
37
+ loud = an.loudness.to_i
38
+
39
+ if beats > 0
40
+ {
41
+ REC_START => [3],
42
+ EAR_L => norm(an.segments.first.timbre, 16),
43
+ EAR_R => norm(an.segments.first.pitches, 16),
44
+ BMP => [beats],
45
+ LED_L1 => norm(an.segments.first.timbre, 255),
46
+ LED_L2 => norm([beats, beats, beats, beats, loud, loud, loud, loud], 255),
47
+ LED_L3 => norm(norm an.segments.first.pitches, 255),
48
+ }
49
+ else
50
+ {
51
+ REC_START => [3],
52
+ EAR_L => [0],
53
+ EAR_R => [0],
54
+ BMP => [0],
55
+ LED_L1 => [0],
56
+ LED_L2 => [0],
57
+ LED_L3 => [0]
58
+ }
59
+ end
60
+ end
61
+
62
+ def upload(file)
63
+ @@soundcloud.post('/tracks', :track => {
64
+ :title => 'Bunny Boogie',
65
+ :asset_data => File.new(file)
66
+ })
67
+ {
68
+ EAR_L => [16,0,16,0,16,0],
69
+ LED_L1 => [0],
70
+ LED_L2 => [0],
71
+ LED_L3 => [0]
72
+ }
73
+ end
74
+
75
+ on :start do
76
+ @@dance = true
77
+ if @@recording
78
+ @@recording = false
79
+ end
80
+ send_nabaztag({
81
+ REC_STOP => []
82
+ })
83
+ end
84
+
85
+ on "button-pressed" do
86
+ send_nabaztag if @@recording
87
+ @@recording = false
88
+ {
89
+ REC_STOP => [],
90
+ LED_L1 => [100,0,0,0],
91
+ LED_L2 => [0,100,0,100],
92
+ LED_L3 => [0,0,100,0]
93
+ }
94
+ else
95
+ @@recording = true
96
+ sec = @@dance ? 3 : 0
97
+ {
98
+ REC_START => [sec]
99
+ }
100
+ end
101
+ end
102
+
103
+ on "recording-finished" do |file_name|
104
+ @@recording = false
105
+ send_nabaztag if @@dance
106
+ dance
107
+ else
108
+ upload(file_name)
109
+ end
110
+ end
111
+ end
112
+
@@ -0,0 +1,6 @@
1
+ # A sample Gemfile
2
+ source "http://rubygems.org"
3
+
4
+ gem "foreman"
5
+ gem "heroku"
6
+
@@ -0,0 +1,3 @@
1
+ web: bundle exec rackup config.ru -p $PORT
2
+ dev: bundle exec rackup config.ru -p 9292
3
+ tunnel: ssh ssh-21560@warteschlange.de -N -R 9092:localhost:9292
@@ -3,4 +3,6 @@
3
3
  $LOAD_PATH.unshift ::File.expand_path(::File.dirname(__FILE__) + '/lib')
4
4
  require 'nabaztag_hack_kit/server'
5
5
 
6
- run NabaztagHackKit::Server.new
6
+ use Rack::Reloader, 0
7
+
8
+ run NabaztagHackKit::Server.new
@@ -25,6 +25,14 @@ module NabaztagHackKit
25
25
  EAR_LL = 42
26
26
  EAR_LR = 43
27
27
 
28
+ REC_START = 50
29
+ REC_STOP = 51
30
+
31
+ PLAY_START = 60
32
+ PLAY_STOP = 61
33
+ PLAY_LOAD = 62
34
+ PLAY_STREAM = 63
35
+
28
36
  F = 1
29
37
  B = 2
30
38
 
@@ -1,6 +1,9 @@
1
1
  module NabaztagHackKit
2
2
  module Message
3
3
  module Helper
4
+ extend self
5
+ include Api
6
+
4
7
  #blink
5
8
  def bl(loops = 1, color_on = 0xFF, color_off = 0x00)
6
9
  repeat(loops, [color_on, color_off])
@@ -13,7 +16,7 @@ module NabaztagHackKit
13
16
  alias_method :sl, :rp #sleep
14
17
 
15
18
  #knight rider
16
- def kr(color = 0xFF, led1 = Api::LED_L1, led2 = Api::LED_L2, led3 = Api::LED_L3)
19
+ def kr(color = 0xFF, led1 = LED_L1, led2 = LED_L2, led3 = LED_L3)
17
20
  {
18
21
  led1 => [color,0,0,0],
19
22
  led2 => [0,color],
@@ -21,7 +24,7 @@ module NabaztagHackKit
21
24
  }
22
25
  end
23
26
 
24
- def fire(color = 0x110000, led1 = Api::LED_L1, led2 = Api::LED_L2, led3 = Api::LED_L3)
27
+ def fire(color = 0x110000, led1 = LED_L1, led2 = LED_L2, led3 = LED_L3)
25
28
  data = Array.new(16) do |i|
26
29
  Message.to_3b(i * color)
27
30
  end + Array.new(8) do |i|
@@ -35,6 +38,22 @@ module NabaztagHackKit
35
38
  }
36
39
  end
37
40
 
41
+ def wink(s = 1, e = 4, times = 5)
42
+ {
43
+ EAR_L => ([s,e] * times) + [s],
44
+ EAR_R => [s] + ([s,e] * times)
45
+ }
46
+ end
47
+
48
+ def circle(times = 15)
49
+ {
50
+ LED_0 => [r,0,0,0] * times,
51
+ LED_1 => [0,r,0,0] * times,
52
+ LED_4 => [0,0,r,0] * times,
53
+ LED_3 => [0,0,0,r] * times,
54
+ }
55
+ end
56
+
38
57
  def stop
39
58
  {
40
59
  LED_0 => 0,
@@ -53,6 +72,11 @@ module NabaztagHackKit
53
72
  EAR_LR => 0,
54
73
  }
55
74
  end
75
+
76
+ private
77
+ def r
78
+ rand(255)
79
+ end
56
80
  end
57
81
  end
58
82
  end
@@ -1,5 +1,6 @@
1
1
  module NabaztagHackKit
2
2
  module Message
3
+ extend self
3
4
 
4
5
  def build(*commands)
5
6
  commands = if commands.first.is_a?(Hash)
@@ -11,26 +12,31 @@ module NabaztagHackKit
11
12
  end
12
13
 
13
14
  pack full_message commands.map { |cmd, *data|
14
- [cmd] + to_3b(data.flatten.size) + data.flatten
15
+ data = convert_data(data)
16
+ [cmd] + to_3b(data.size) + data
15
17
  }
16
18
  end
17
- module_function(:build)
18
19
 
19
20
  def to_3b(int)
20
21
  [int >> 16, int >> 8, int].map { |i| i & 0xFF }
21
22
  end
22
- module_function(:to_3b)
23
+
24
+ def convert_data(data)
25
+ if data.first.is_a?(String)
26
+ data.first.each_byte.to_a
27
+ else
28
+ data.flatten
29
+ end
30
+ end
23
31
 
24
32
  private
25
33
  def full_message(*data)
26
34
  [0x7F] + data.flatten + [0xFF, 0x0A]
27
35
  end
28
- module_function(:full_message)
29
36
 
30
37
  def pack(message)
31
38
  message.pack('c*')
32
39
  end
33
- module_function(:pack)
34
40
  end
35
41
 
36
42
  end
@@ -0,0 +1,5 @@
1
+ <h1>Welcome to Nabaztag Hack Kit</h1>
2
+
3
+ Hurray, your server is successful running! Now point your bunny to this url and you're ready to go!
4
+
5
+ Check the <a href="https://github.com/rngtng/NabaztagHackKit">Docs</a> how to integrate...
@@ -7,9 +7,22 @@ module NabaztagHackKit
7
7
  class Server < Sinatra::Base
8
8
  include Message::Api
9
9
 
10
+ PREFIX = "/api"
11
+
10
12
  def initialize(bytecode_path = nil)
11
13
  super
12
- @bytecode_path = bytecode_path || File.join('public', 'bytecode.bin')
14
+ @bytecode_path = bytecode_path || File.expand_path(File.join('../', 'public', 'bytecode.bin'), __FILE__)
15
+ puts "Serving Bytecode from #{@bytecode_path}"
16
+ end
17
+
18
+ class << self
19
+ def callbacks
20
+ @@callbacks ||= {}
21
+ end
22
+
23
+ def on(callback, &block)
24
+ callbacks[callback] = block
25
+ end
13
26
  end
14
27
 
15
28
  def send_nabaztag(*data)
@@ -29,22 +42,55 @@ module NabaztagHackKit
29
42
  end
30
43
  end
31
44
 
32
- get '/bc.jsp' do
33
- # TODO recompile if changed
34
- send_file @bytecode_path
45
+ def callback(action, data, request)
46
+ if callback = self.class.callbacks[action.to_s]
47
+ instance_exec data, request, &callback
48
+ else
49
+ # puts "no callback found for #{action}"
50
+ send_nabaztag OK
51
+ end
35
52
  end
36
53
 
37
- get '/vl/button.jsp' do
38
- send_nabaztag EAR_L => [12,0,16,0,16,0,16,0]
54
+ get "/" do
55
+ path = File.expand_path(File.join('../', 'public', 'index.html'), __FILE__)
56
+ puts path
57
+ File.read(path)
58
+ end
59
+
60
+ get "/bc.jsp" do
61
+ # TODO recompile if changed
62
+ send_file @bytecode_path
39
63
  end
40
64
 
41
- post '/vl/log.jsp' do
65
+ post "#{PREFIX}/log.jsp" do
42
66
  @logs = parse_log params[:logs]
43
67
  puts "#########################"
44
68
  puts @logs.join("\n")
45
69
  puts "#########################"
46
70
  send_nabaztag OK
47
71
  end
48
- end
49
72
 
73
+ post "#{PREFIX}/recording-finished.jsp" do
74
+ file_name = REC_FILE # TODO add timestamp??
75
+ File.open(file_name, "w+") do |f|
76
+ f.write request.body.read
77
+ end
78
+ callback('recording-finished', file_name, request)
79
+ end
80
+
81
+ get "#{PREFIX}/rfid.jsp" do
82
+ callback('rfid', params[:id], request)
83
+ end
84
+
85
+ get "#{PREFIX}/button-pressed.jsp" do
86
+ callback('button-pressed', params[:duration], request)
87
+ end
88
+
89
+ # generic callback
90
+ %w(get post).each do |method|
91
+ send(method, "#{PREFIX}/:action.jsp") do
92
+ callback(params[:action], params, request)
93
+ end
94
+ end
95
+ end
50
96
  end
@@ -1,3 +1,3 @@
1
1
  module NabaztagHackKit
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0.alpha1"
3
3
  end
@@ -13,8 +13,9 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
- s.extensions = ['ext/mtl/extconf.rb']
16
+ s.extensions = ['bytecode/src/mtl/extconf.rb']
17
+
18
+ s.bindir = 'bytecode/bin'
18
19
  s.executables = ['mtl_comp', 'mtl_simu', 'mtl_merge']
19
20
 
20
21
  s.require_paths = ["lib"]
@@ -23,7 +24,7 @@ Gem::Specification.new do |s|
23
24
  s.add_dependency *gem.split(' ')
24
25
  end
25
26
 
26
- ["rake", "rspec"].each do |gem|
27
+ ["rake", "rspec", "rack-test"].each do |gem|
27
28
  s.add_development_dependency *gem.split(' ')
28
29
  end
29
30
  end
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ require "nabaztag_hack_kit/server"
4
+ require "rack/test"
5
+
6
+ shared_examples_for :successful_route do
7
+ it "returns 200" do
8
+ get route
9
+ last_response.should be_ok
10
+ end
11
+ end
12
+
13
+ describe NabaztagHackKit::Server do
14
+ include Rack::Test::Methods
15
+
16
+ let(:app) { NabaztagHackKit::Server.new }
17
+
18
+ describe "/bc.jsp" do
19
+ let(:route) { "/bc.jsp" }
20
+
21
+ it_behaves_like :successful_route
22
+ end
23
+
24
+ describe "/api/log.jsp" do
25
+ let(:route) { "/api/log.jsp" }
26
+
27
+ it_behaves_like :successful_route
28
+ end
29
+
30
+ describe "/api/rfid.jsp" do
31
+ let(:route) { "/api/rfid.jsp" }
32
+
33
+ it_behaves_like :successful_route
34
+ end
35
+
36
+ describe "/api/recording-finished.jsp" do
37
+ let(:route) { "/api/recording-finished.jsp" }
38
+
39
+ it_behaves_like :successful_route
40
+ end
41
+
42
+ describe "catch all route" do
43
+ let(:route) { "/api/custom.jsp" }
44
+
45
+ it_behaves_like :successful_route
46
+
47
+ it "execute callback" do
48
+ end
49
+ end
50
+ end
@@ -2,4 +2,4 @@ require 'rspec'
2
2
 
3
3
  $: << File.expand_path("../../lib", __FILE__)
4
4
 
5
- require "nabaztag_hack_kit"
5
+ require "nabaztag_hack_kit"
@@ -1,4 +1,4 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
1
+ require "spec_helper"
2
2
 
3
3
  require "nabaztag_hack_kit/message"
4
4
 
@@ -53,4 +53,4 @@ describe NabaztagHackKit::Message do
53
53
  NabaztagHackKit::Message.to_3b(6334239).should == [96, 167, 31]
54
54
  end
55
55
  end
56
- end
56
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ require "nabaztag_hack_kit/server"
4
+
5
+ describe NabaztagHackKit::Server do
6
+ let(:app) { NabaztagHackKit::Server.new }
7
+
8
+ describe "#bc.jsp" do
9
+ def do_action(path)
10
+ app.call({
11
+ 'REQUEST_METHOD' => 'GET',
12
+ 'PATH_INFO' => path,
13
+ 'rack.input' => StringIO.new
14
+ })
15
+ end
16
+
17
+ it "reads from public/bytecode.bin" do
18
+ pending
19
+ app.should_receive(:send_file).with("public/bytecode.bin")
20
+ do_action '/bc.jsp'
21
+ end
22
+
23
+ context "with custom bin code route" do
24
+ let(:app) { NabaztagHackKit::Server.new(custom_route) }
25
+ let(:custom_route) { "bytecode.bin" }
26
+
27
+ it "reads from" do
28
+ pending
29
+ app.should_receive(:send_file).with(custom_route)
30
+ do_action '/bc.jsp'
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "#on" do
36
+ it "accepts" do
37
+ pending
38
+ end
39
+ end
40
+ end