nabaztag_hack_kit 0.1.0.alpha2 → 0.1.0.alpha3

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.
@@ -10,12 +10,26 @@ unless ARGV.size == 1
10
10
  end
11
11
 
12
12
  file = ARGV.first
13
+ BASE_DIR = File.dirname(file)
14
+ BASE_DIR_LIB = File.dirname(File.dirname(__FILE__))
15
+
16
+ def mtl_file(name)
17
+ "#{name}.mtl"
18
+ end
19
+
20
+ def src_file(name)
21
+ [BASE_DIR, BASE_DIR_LIB].each do |dir|
22
+ if (path = File.join(dir, name)) && File.exists?(path)
23
+ return path
24
+ end
25
+ end
26
+ raise "LIB FILE #{name} not found"
27
+ end
13
28
 
14
- dir = File.dirname(file)
15
29
  File.open(TMP, 'w') do |out|
16
30
  File.open(file).each_line do |line|
17
31
  if line =~ /\A#include "([^"]+)"/
18
- line = `cat #{dir}/#{$1}.mtl`
32
+ line = `cat #{src_file(mtl_file($1))}`
19
33
  end
20
34
  out.puts line
21
35
  end
@@ -4,7 +4,12 @@
4
4
  const BUTTON_REBOOT = 3000;; //ms MIN 50ms
5
5
  var button_pressed = 0;;
6
6
 
7
- fun checkButton=
7
+ fun buttonPressedUrl data=
8
+ strcatlist confGetServerUrl::apiPath::"/button-pressed.jsp?duration="::(itoa data)::nil;;
9
+
10
+ //-------------------------------------------------------------
11
+
12
+ fun buttonCheck =
8
13
  if (button2 > 0) then
9
14
  (
10
15
  if button_pressed == 0 then
@@ -1,16 +1,3 @@
1
- var logs = "";;
2
-
3
- fun log t tab=
4
- let "|"::nil -> all in
5
- (
6
- for i = tablen tab; i > 0 ; i - 1 do
7
- (
8
- let itoa tab.(i - 1) -> data in
9
- set all = data::","::all
10
- );
11
- set logs = strcatlist logs::t::","::(itoa time_ms)::","::all
12
- )
13
- ;;
14
1
 
15
2
  fun TLtoS tlist=
16
3
  if tlist == nil then
@@ -0,0 +1,23 @@
1
+ //###############################################
2
+ //------------------ LOGGER ----------------------
3
+
4
+ var logs = "";;
5
+
6
+ fun logUrl =
7
+ strcatlist confGetServerUrl::apiPath::"/log.jsp?"::nil;;
8
+
9
+ fun log t tab=
10
+ let "|"::nil -> all in
11
+ (
12
+ for i = tablen tab; i > 0 ; i - 1 do
13
+ (
14
+ let itoa tab.(i - 1) -> data in
15
+ set all = data::","::all
16
+ );
17
+ set logs = strcatlist logs::t::","::(itoa time_ms)::","::all
18
+ )
19
+ ;;
20
+
21
+ fun sendLogs=
22
+ httprequest "POST" logUrl (strcat "logs=" logs) #_cbDummyHttp HTTP_NORMAL;
23
+ set logs = "";;
@@ -1,10 +1,16 @@
1
1
  //###############################################
2
2
  //------------------ PING ----------------------
3
+
3
4
  const PING_CHECK_FQ = 5000;; //ms -> 5s
4
5
  const PING_PARAMS = "";;
5
6
 
6
7
  var ping_last_check = 0;;
7
8
 
9
+ fun pingUrl params=
10
+ strcatlist confGetServerUrl::apiPath::"/ping.jsp?"::params::nil;;
11
+
12
+ //-------------------------------------------------------------
13
+
8
14
  fun pingCheck=
9
15
  let PING_CHECK_FQ -> ping_check_fq in
10
16
  if ((time_ms - ping_last_check) > ping_check_fq) then
@@ -0,0 +1,33 @@
1
+ //###############################################
2
+ //------------------- Playback --------------------
3
+
4
+ fun playbackFinishedUrl =
5
+ strcatlist confGetServerUrl::apiPath::"/playback-finished.jsp?"::nil;;
6
+
7
+ fun playbackLoadFinishedUrl =
8
+ strcatlist confGetServerUrl::apiPath::"/playback-load-finished.jsp?"::nil;;
9
+
10
+ fun streamUrl filename=
11
+ strcatlist confGetServerUrl::"/streams/"::filename::nil;;
12
+
13
+ // var playback_fifo = nil;;
14
+
15
+ // fun playbackStart =
16
+ // ;;
17
+
18
+ // fun playbackStop =
19
+ // ;;
20
+
21
+ // fun _playbackLoadCB httpreq req=
22
+ // if req != nil then
23
+ // (
24
+ // set wav_fifo=conc playback_fifo req::nil;
25
+ // )
26
+ // ;;
27
+
28
+
29
+ // fun playbackLoad val=
30
+ // httprequest "GET" (streamUrl val) nil #_playbackLoadCB HTTP_NORMAL //HTTP_STREAM
31
+ // ;;
32
+
33
+ // fun playbackStream val=
@@ -1,3 +1,6 @@
1
+ //###############################################
2
+ //------------------- Record --------------------
3
+
1
4
  var lrec;;
2
5
  var recording = 0;;
3
6
  var recordingStartedAt = 0;;
@@ -7,6 +10,9 @@ var buff;;
7
10
  var buffx;;
8
11
  var buffy;;
9
12
 
13
+ fun recordingFinishedUrl =
14
+ strcatlist confGetServerUrl::apiPath::"/recording-finished.jsp?"::nil;;
15
+
10
16
  //-------------------------------------------------------------
11
17
 
12
18
  fun sqrt_ i i0 i1=
@@ -10,7 +10,10 @@ const RFID_ID_ERROR = "\69\114\114\111\114\0\0\0\v";; // 0x45 72 72 6f 72 00 00
10
10
  var rfid_last_check = 0;;
11
11
  var rfid_data = "";;
12
12
 
13
- fun checkRFID=
13
+ fun rfidUrl tag=
14
+ strcatlist confGetServerUrl::apiPath::"/rfid.jsp?id="::(webmac tag)::nil;;
15
+
16
+ fun rfidCheck=
14
17
  if ((time_ms - rfid_last_check) > RFID_CHECK_FQ) then
15
18
  (
16
19
  let rfidGet -> rfid in
data/bytecode/main.mtl CHANGED
@@ -14,46 +14,38 @@ proto evalTrame 1;;
14
14
  #include "src/lib/http"
15
15
  #include "src/lib/dhcp"
16
16
  #include "src/lib/wav"
17
- #include "lib/data_helper"
18
- #include "lib/buffer"
19
17
  #include "src/lib/wifi"
20
18
 
21
- //-------------------- HTTP Endpoints
22
- fun logUrl=
23
- strcatlist confGetServerUrl::"/api/log.jsp"::nil;;
24
-
25
- fun buttonPressedUrl data=
26
- strcatlist confGetServerUrl::"/api/button-pressed.jsp?duration="::(itoa data)::nil;;
27
-
28
- fun recordingFinishedUrl =
29
- strcatlist confGetServerUrl::"/api/recording-finished.jsp"::nil;;
30
-
31
- fun playbackFinishedUrl =
32
- strcatlist confGetServerUrl::"/api/playback-finished.jsp"::nil;;
33
-
34
- fun playbackLoadFinishedUrl =
35
- strcatlist confGetServerUrl::"/api/playback-load-finished.jsp"::nil;;
36
-
37
- fun rfidUrl tag=
38
- strcatlist confGetServerUrl::"/api/rfid.jsp?id="::(webmac tag)::nil;;
19
+ #include "lib/data_helper"
39
20
 
40
- fun pingUrl params=
41
- strcatlist confGetServerUrl::"/api/ping.jsp?"::params::nil;;
21
+ //-------------------- HTTP Endpoints
22
+ fun bunnyId =
23
+ netMac;;
42
24
 
43
- fun streamUrl filename=
44
- strcatlist confGetServerUrl::"/streams/"::filename::nil;;
25
+ fun apiPath =
26
+ strcatlist "/api/"::(webmac bunnyId)::nil;;
45
27
 
46
28
  //-------------------- HTTP
47
-
48
- fun _cbdummyhttp http res=
29
+ fun _cbDummyHttp http res=
49
30
  0;;
50
31
 
51
32
  fun _cbHttp http res=
52
33
  evalTrame res;
53
34
  0;;
54
35
 
55
- #include "lib/record"
36
+ #include "lib/buffer"
56
37
  #include "lib/ping"
38
+ #include "lib/logger"
39
+
40
+ //inputs
41
+ // #include "lib/rfid"
42
+ #include "lib/record"
43
+ #include "lib/button"
44
+
45
+ //outputs
46
+ #include "lib/playback"
47
+ #include "lib/led"
48
+ #include "lib/ear"
57
49
 
58
50
  fun evalTrame res=
59
51
  let parseResponse httpgetcontent res -> bufferlist in
@@ -73,8 +65,7 @@ fun evalTrame res=
73
65
  )
74
66
  else if code == 17 then // LOG
75
67
  (
76
- httprequest "POST" logUrl (strcat "logs=" logs) #_cbdummyhttp HTTP_NORMAL;
77
- set logs = "";
68
+ sendLogs;
78
69
  0
79
70
  )
80
71
  else if code == 18 then // ERROR
@@ -141,29 +132,21 @@ fun evalTrame res=
141
132
  )
142
133
  ;;
143
134
 
144
- //inputs
145
- // #include "lib/rfid"
146
- #include "lib/button"
147
-
148
- //outputs
149
- #include "lib/led"
150
- #include "lib/ear"
151
-
152
135
  //###############################################
153
136
  //-------------------- LOOP ---------------------
154
137
  fun loop=
155
138
  wifiRun;
156
139
  wifiCheck;
157
140
 
158
- // checkRFID;
159
- checkButton;
141
+ // rfidCheck;
142
+ buttonCheck;
160
143
 
161
144
  setLeds;
162
145
  earRead 0;
163
146
  earRead 1;
164
147
 
165
148
  pingCheck;
166
- // wavtime;
149
+ wavtime;
167
150
 
168
151
  recordingCheck;
169
152
  0;;
@@ -5,8 +5,6 @@ require "echonest"
5
5
 
6
6
  class Server < NabaztagHackKit::Server
7
7
 
8
- REC_FILE = "rec.wav"
9
-
10
8
  def initialize(echonest_cfg, soundcloud_cfg)
11
9
  super('bytecode.bin')
12
10
  @@echonest = Echonest(echonest_cfg[:key])
@@ -7,12 +7,16 @@ module NabaztagHackKit
7
7
  class Server < Sinatra::Base
8
8
  include Message::Api
9
9
 
10
- PREFIX = "/api"
10
+ configure :production, :development do
11
+ enable :logging
12
+ end
13
+
14
+ REC_FILE = "rec.wav"
15
+ PREFIX = "/api/:bunnyid"
11
16
 
12
17
  def initialize(bytecode_path = nil)
13
18
  super
14
- @bytecode_path = bytecode_path || File.expand_path(File.join('../', 'public', 'bytecode.bin'), __FILE__)
15
- puts "Serving Bytecode from #{@bytecode_path}"
19
+ @bytecode_path = bytecode_path || public_file('bytecode.bin')
16
20
  end
17
21
 
18
22
  class << self
@@ -46,27 +50,26 @@ module NabaztagHackKit
46
50
  if callback = self.class.callbacks[action.to_s]
47
51
  instance_exec data, request, &callback
48
52
  else
49
- # puts "no callback found for #{action}"
53
+ logger.warn "no callback found for #{action}"
50
54
  send_nabaztag OK
51
55
  end
52
56
  end
53
57
 
54
58
  get "/" do
55
- path = File.expand_path(File.join('../', 'public', 'index.html'), __FILE__)
56
- puts path
57
- File.read(path)
59
+ File.read public_file("index.html")
58
60
  end
59
61
 
60
62
  get "/bc.jsp" do
61
- # TODO recompile if changed
63
+ logger.info "Serving Bytecode from #{@bytecode_path}"
62
64
  send_file @bytecode_path
63
65
  end
64
66
 
65
67
  post "#{PREFIX}/log.jsp" do
66
- @logs = parse_log params[:logs]
67
- puts "#########################"
68
- puts @logs.join("\n")
69
- puts "#########################"
68
+ parse_log(params[:logs]).tap do |logs|
69
+ logger.info "#########################"
70
+ logger.info logs.join("\n")
71
+ logger.info "#########################"
72
+ end
70
73
  send_nabaztag OK
71
74
  end
72
75
 
@@ -86,11 +89,26 @@ module NabaztagHackKit
86
89
  callback('button-pressed', params[:duration], request)
87
90
  end
88
91
 
92
+ get "/streams/:file.mp3" do
93
+ File.read public_file("#{params[:file]}.mp3")
94
+ end
95
+
89
96
  # generic callback
90
97
  %w(get post).each do |method|
91
98
  send(method, "#{PREFIX}/:action.jsp") do
92
99
  callback(params[:action], params, request)
93
100
  end
94
101
  end
102
+
103
+ # generic catchall
104
+ get "/*" do
105
+ logger.warn "no route found for #{params[:splat]}"
106
+ status 404
107
+ end
108
+
109
+ protected
110
+ def public_file(name)
111
+ File.expand_path(File.join('..', 'public', name), __FILE__)
112
+ end
95
113
  end
96
114
  end
@@ -1,3 +1,3 @@
1
1
  module NabaztagHackKit
2
- VERSION = "0.1.0.alpha2"
2
+ VERSION = "0.1.0.alpha3"
3
3
  end
@@ -21,26 +21,26 @@ describe NabaztagHackKit::Server do
21
21
  it_behaves_like :successful_route
22
22
  end
23
23
 
24
- describe "/api/log.jsp" do
25
- let(:route) { "/api/log.jsp" }
24
+ describe "log.jsp" do
25
+ let(:route) { "/api/bunnyid/log.jsp" }
26
26
 
27
27
  it_behaves_like :successful_route
28
28
  end
29
29
 
30
- describe "/api/rfid.jsp" do
31
- let(:route) { "/api/rfid.jsp" }
30
+ describe "rfid.jsp" do
31
+ let(:route) { "/api/bunnyid/rfid.jsp" }
32
32
 
33
33
  it_behaves_like :successful_route
34
34
  end
35
35
 
36
- describe "/api/recording-finished.jsp" do
37
- let(:route) { "/api/recording-finished.jsp" }
36
+ describe "recording-finished.jsp" do
37
+ let(:route) { "/api/bunnyid/recording-finished.jsp" }
38
38
 
39
39
  it_behaves_like :successful_route
40
40
  end
41
41
 
42
42
  describe "catch all route" do
43
- let(:route) { "/api/custom.jsp" }
43
+ let(:route) { "/api/bunnyid/custom.jsp" }
44
44
 
45
45
  it_behaves_like :successful_route
46
46
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nabaztag_hack_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha2
4
+ version: 0.1.0.alpha3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bytecode/bin
11
11
  cert_chain: []
12
- date: 2012-09-11 00:00:00.000000000Z
12
+ date: 2012-09-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &70237085758020 !ruby/object:Gem::Requirement
16
+ requirement: &70172330100880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70237085758020
24
+ version_requirements: *70172330100880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70237085757480 !ruby/object:Gem::Requirement
27
+ requirement: &70172330100340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70237085757480
35
+ version_requirements: *70172330100340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70237085757020 !ruby/object:Gem::Requirement
38
+ requirement: &70172330099880 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70237085757020
46
+ version_requirements: *70172330099880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rack-test
49
- requirement: &70237085756560 !ruby/object:Gem::Requirement
49
+ requirement: &70172330099420 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70237085756560
57
+ version_requirements: *70172330099420
58
58
  description: Sinatra server api framework to run custom bytecode on Nabaztag v1/v2.
59
59
  Sources + Compiler included (linux only)
60
60
  email:
@@ -84,7 +84,9 @@ files:
84
84
  - bytecode/lib/data_helper.mtl
85
85
  - bytecode/lib/ear.mtl
86
86
  - bytecode/lib/led.mtl
87
+ - bytecode/lib/logger.mtl
87
88
  - bytecode/lib/ping.mtl
89
+ - bytecode/lib/playback.mtl
88
90
  - bytecode/lib/record.mtl
89
91
  - bytecode/lib/rfid.mtl
90
92
  - bytecode/main.mtl