Permalink
Browse files

read default var from file

  • Loading branch information...
1 parent 85e83dc commit 7b364af76f35957543dbd95c02668adbb6a3d068 Tobias Bielohlawek committed Aug 17, 2012
Showing with 50 additions and 64 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 Rakefile
  3. +5 −0 bin/mtl_comp
  4. +5 −0 bin/mtl_simu
  5. +4 −3 bytecode/lib/button.mtl
  6. +2 −20 bytecode/lib/rfid.mtl
  7. +9 −20 bytecode/main.mtl
  8. +23 −20 lib/nabaztag_hack_kit/server.rb
View
@@ -6,3 +6,4 @@ pkg/*
*.bin
*.o
examples/record/config.ru
+.mtlrc
View
@@ -8,7 +8,7 @@ end
namespace :test do
desc "Test bytcode"
task :bytecode do
- puts `bin/mtl_simu test/bytecode/test.mtl`
+ puts `bin/mtl_simu spec/bytecode/test.mtl`
end
end
View
@@ -1,5 +1,10 @@
#!/usr/bin/env ruby
+File.read(".mtlrc").split("\n").each do |line|
+ var, *data = line.split("=")
+ ENV[var] = data.join
+end
+
BIN_NAME = File.basename(__FILE__)
BIN_PATH = File.dirname(__FILE__)
BIN = File.join( File.expand_path("../ext/mtl", BIN_PATH), BIN_NAME)
View
@@ -1,5 +1,10 @@
#!/usr/bin/env ruby
+File.read(".mtlrc").split("\n").each do |line|
+ var, *data = line.split("=")
+ ENV[var] = data.join
+end
+
BIN_NAME = File.basename(__FILE__)
BIN_PATH = File.dirname(__FILE__)
BIN = File.join( File.expand_path("../ext/mtl", BIN_PATH), BIN_NAME)
View
@@ -9,7 +9,7 @@ fun checkButton=
set button_pressed = button_pressed + 1;
if button_pressed == 1 then
(
- httprequest "GET" buttonUrl (itoa time_ms) "" #_cbHttp HTTP_NORMAL;
+ httprequest "GET" buttonPressedUrl button_pressed "" #_cbHttp HTTP_NORMAL;
0
) else if button_pressed == BUTTON_REBOOT then
(
@@ -19,8 +19,9 @@ fun checkButton=
//reboot only when button not pressed, otherwise we get into setup mode
else if button_pressed > BUTTON_REBOOT then
(
- httprequest "GET" startUrl "" #_cbHttp HTTP_NORMAL;
- set button_pressed = 0;
+ // httprequest "GET" startUrl "" #_cbHttp HTTP_NORMAL;
+ //set button_pressed = 0;
+ exit;
0
)
else (
View
@@ -16,31 +16,13 @@ fun checkRFID=
let rfidGet -> rfid in
if (rfid != nil) then
(
- if ((strstr rfid RFID_ID_START 0) == 0) then
- (
- httprequest "PUT" playerUrl rfid "" #_cbHttp HTTP_NORMAL;
- 0
- )
- else if ((strstr rfid RFID_ID_FALSE 0) == 0) then
+ if ((strstr rfid RFID_ID_FALSE 0) == 0) then
(
0
)
else
(
- let strlen rfid -> len in //usually that's 8
- for index = 0; index < len; index + 1 do
- (
- let strget rfid index -> data_byte in
- (
- if (data_byte != RFID_STOP_BYTE) then
- set rfid_data = strcat rfid_data ctoh data_byte
- else if ((strlen rfid_data) > 0) then
- (
- httprequest "POST" eventUrl rfid_data "" #_cbHttp HTTP_NORMAL;
- set rfid_data = ""
- )
- )
- );
+ httprequest "PUT" rfidUrl rfid "" #_cbHttp HTTP_NORMAL;
0
)
);
View
@@ -21,38 +21,27 @@ var recordingStartedAt = 0;;
var bmp = 0;;
var recSeconds = 0;;
-//-------------------- HTTP
+//-------------------- HTTP Endpoints
fun logUrl=
- strcatlist confGetServerUrl::"/vl/log.jsp"::nil;;
+ strcatlist confGetServerUrl::"/api/log.jsp"::nil;;
-fun buttonUrl data=
- strcatlist confGetServerUrl::"/vl/button.jsp?"::data::nil;;
+fun buttonPressedUrl data=
+ strcatlist confGetServerUrl::"/api/button-pressed.jsp?duration="::(itoa data)::nil;;
fun recordingFinishedUrl =
- strcatlist confGetServerUrl::"/vl/recording-finished.jsp"::nil
-;;
+ strcatlist confGetServerUrl::"/api/recording-finished.jsp"::nil;;
fun rfidUrl tag=
- strcatlist confGetServerUrl::"/vl/rfid"::(webmac tag)::".jsp"::nil;;
-
-fun eventUrl data=
- strcatlist confGetServerUrl::"/events.jsp"::"?event[data]="::data::nil;;
-
-
-
-fun startUrl =
- strcatlist confGetServerUrl::"/vl/start.jsp"::nil
-;;
+ strcatlist confGetServerUrl::"/api/rfid.jsp?id="::(webmac tag)::nil;;
+//-------------------- HTTP
fun _cbdummyhttp http res=
- 0
-;;
+ 0;;
fun _cbHttp http res=
evalTrame res;
- 0
-;;
+ 0;;
#include "lib/record"
@@ -14,6 +14,7 @@ class Server < Sinatra::Base
def initialize(bytecode_path = nil)
super
@bytecode_path = bytecode_path || File.join('public', 'bytecode.bin')
+ @@callbacks = {}
puts "Serving Bytecode from #{@bytecode_path}"
end
@@ -34,11 +35,11 @@ def parse_log(logs)
end
end
- def callback(action, params, request)
- if callback = @callbacks[:action]
- send(callback, params, request)
+ def callback(action, data, request)
+ if callback = @@callbacks[action.to_s]
+ send(callback, data, request)
else
-
+ puts "no callback found for #{action}"
send_nabaztag OK
end
end
@@ -52,17 +53,6 @@ def callback(action, params, request)
send_file @bytecode_path
end
- post "#{PREFIX}/recording-finished.jsp" do
- File.open(REC_FILE, "w+") do |f|
- f.write request.body.read
- end
- callback('recording-finished', REC_FILE)
- end
-
- get "#{PREFIX}/rfid.jsp" do
- callback('rfid', params[:id])
- end
-
post "#{PREFIX}/log.jsp" do
@logs = parse_log params[:logs]
puts "#########################"
@@ -71,13 +61,26 @@ def callback(action, params, request)
send_nabaztag OK
end
- get "#{PREFIX}/:action.jsp" do
- callback(params[:action], params, request)
+ post "#{PREFIX}/recording-finished.jsp" do
+ file_name = REC_FILE # TODO add timestamp??
+ File.open(file_name, "w+") do |f|
+ f.write request.body.read
+ end
+ callback('recording-finished', file_name, request)
end
- post "#{PREFIX}/:action.jsp" do
- callback(params[:action], params, request)
+ get "#{PREFIX}/rfid.jsp" do
+ callback('rfid', params[:id], request)
end
- end
+ get "#{PREFIX}/button-pressed.jsp" do
+ callback('button-pressed', params[:duration], request)
+ end
+
+ %w(get post).each do |method|
+ send(method, "#{PREFIX}/:action.jsp" do
+ callback(params[:action], params, request)
+ end
+ end
+ end
end

0 comments on commit 7b364af

Please sign in to comment.