Permalink
Browse files

added ping

  • Loading branch information...
1 parent 12bf5a4 commit 3eddceb864da2c2ca55f255171fb2cc81ecce3df Tobias Bielohlawek committed Sep 3, 2012
View
@@ -1,30 +1,33 @@
//###############################################
//------------------- Button --------------------
-const BUTTON_REBOOT = 30;; //ms MIN 50ms
+const BUTTON_REBOOT = 3000;; //ms MIN 50ms
var button_pressed = 0;;
+
fun checkButton=
if (button2 > 0) then
(
- set button_pressed = button_pressed + 1;
- if button_pressed == 1 then
+ if button_pressed == 0 then
(
- httprequest "GET" buttonPressedUrl button_pressed "" #_cbHttp HTTP_NORMAL;
- 0
- ) else if button_pressed == BUTTON_REBOOT then
+ set button_pressed = time_ms
+ )
+ else if (time_ms - button_pressed) > BUTTON_REBOOT then
(
- buffersFill 0 4 "\0\255\0\255\0\255\255\255"
+ buffersFill 0 4 "\255"
)
)
//reboot only when button not pressed, otherwise we get into setup mode
- else if button_pressed > BUTTON_REBOOT then
+ else if button_pressed > 0 then
(
- // httprequest "GET" startUrl "" #_cbHttp HTTP_NORMAL;
- //set button_pressed = 0;
- exit;
- 0
- )
- else (
- set button_pressed = 0
+ if (time_ms - button_pressed) > BUTTON_REBOOT then
+ (
+ exit;
+ set button_pressed = 0
+ )
+ else
+ (
+ httprequest "GET" buttonPressedUrl (time_ms - button_pressed) "" #_cbHttp HTTP_NORMAL;
+ set button_pressed = 0
+ )
)
;;
View
@@ -14,7 +14,7 @@ fun ledBufferRead index=
;;
fun setLeds=
- //LED_CHECK_FQ
+ // let LED_CHECK_FQ -> led_check_fq in
let (button3 + 1) * 3 -> led_check_fq in
if ((time_ms - led_last_check) > led_check_fq) then
(
View
@@ -0,0 +1,16 @@
+//###############################################
+//------------------ PING ----------------------
+
+const PING_CHECK_FQ = 3000;; //ms MIN 50ms
+var ping_last_check = 0;;
+
+fun pingCheck=
+ let PING_CHECK_FQ -> ping_check_fq in
+ //let (button3 + 1) * 3 -> ping_check_fq in
+ if ((time_ms - ping_last_check) > ping_check_fq) then
+ (
+ httprequest "GET" pingUrl "" #_cbHttp HTTP_NORMAL;
+ set ping_last_check = time_ms
+ )
+;;
+
View
@@ -4,21 +4,20 @@ proto main 0;;
proto earsInit 0;;
proto evalTrame 1;;
-#include "../ext/bytecode/lib/var"
-#include "../ext/bytecode/lib/util"
-#include "../ext/bytecode/lib/cfg"
-#include "../ext/bytecode/lib/arp"
-#include "../ext/bytecode/lib/udp"
-#include "../ext/bytecode/lib/tcp"
-#include "../ext/bytecode/lib/dns"
-#include "../ext/bytecode/lib/http"
-#include "../ext/bytecode/lib/dhcp"
+#include "src/bytecode/lib/var"
+#include "src/bytecode/lib/util"
+#include "src/bytecode/lib/cfg"
+#include "src/bytecode/lib/arp"
+#include "src/bytecode/lib/udp"
+#include "src/bytecode/lib/tcp"
+#include "src/bytecode/lib/dns"
+#include "src/bytecode/lib/http"
+#include "src/bytecode/lib/dhcp"
#include "lib/data_helper"
#include "lib/buffer"
-#include "../ext/bytecode/lib/wifi"
+#include "src/bytecode/lib/wifi"
var recordingStartedAt = 0;;
-var bmp = 0;;
var recSeconds = 0;;
//-------------------- HTTP Endpoints
@@ -34,6 +33,9 @@ fun recordingFinishedUrl =
fun rfidUrl tag=
strcatlist confGetServerUrl::"/api/rfid.jsp?id="::(webmac tag)::nil;;
+fun pingUrl =
+ strcatlist confGetServerUrl::"/api/ping.jsp"::nil;;
+
//-------------------- HTTP
fun _cbdummyhttp http res=
@@ -44,6 +46,7 @@ fun _cbHttp http res=
0;;
#include "lib/record"
+#include "lib/ping"
fun evalTrame res=
let parseResponse httpgetcontent res -> bufferlist in
@@ -93,27 +96,19 @@ fun evalTrame res=
_bufferFill index+10 step loop val;
0
)
- // recodring
+ // recording start
else if code == 50 then
(
set recSeconds = strget val 0;
set recSeconds = 1000 * recSeconds;
recordingStart;
set recordingStartedAt = time_ms
)
+ // recording stop
else if code == 51 then
(
recordingStop
)
- else if code == 60 then
- (
- led 0 0;
- set bmp = strget val 0;
- if bmp > 0 then
- (
- set bmp = 60000 / bmp
- )
- )
)
)
;;
@@ -126,9 +121,6 @@ fun evalTrame res=
#include "lib/led"
#include "lib/ear"
-var n = 0;;
-var last = 0;;
-
//###############################################
//-------------------- LOOP ---------------------
fun loop=
@@ -142,30 +134,12 @@ fun loop=
earRead 0;
earRead 1;
- if button3 > 254 then
- (
- exit
- );
+ pingCheck;
if recording == 1 && recSeconds > 0 && (time_ms - recordingStartedAt) > recSeconds then
(
recordingStop
);
-
- if bmp > 0 && time_ms - last > bmp then
- (
- if n > 10 then
- (
- set n = 0
- )
- else
- (
- set n = 255
- );
- led 0 n;
- set last = time_ms;
- 0
- );
0;;
//###############################################
View
@@ -1,19 +1,31 @@
require "nabaztag_hack_kit/server"
+require 'nabaztag_hack_kit/message/helper'
+
class Server < NabaztagHackKit::Server
def initialize
- super('bytecode.bin')
+ super #('bytecode.bin')
end
- on "button-pressed" do
+ on "button-pressed" do |data, request|
send_nabaztag({
- LED_L1 => [100,0,0,0],
- LED_L2 => [0,100,0,100],
- LED_L3 => [0,0,100,0]
+ LED_L1 => [0],
+ LED_L2 => [0],
+ LED_L3 => [0],
+ LED_L4 => [0,0,0,0,100],
})
end
+ on "ping" do |data, request|
+ #send_nabaztag NabaztagHackKit::Message::Helper::fire
+ # ({
+ # LED_L1 => [0],
+ # LED_L2 => [0,100, 200, 300],
+ # LED_L3 => [0],
+ # LED_L4 => [0,0,0,0,100],
+ # })
+ end
end
@@ -1,5 +1,6 @@
module NabaztagHackKit
module Message
+ extend self
def build(*commands)
commands = if commands.first.is_a?(Hash)
@@ -14,23 +15,19 @@ def build(*commands)
[cmd] + to_3b(data.flatten.size) + data.flatten
}
end
- module_function(:build)
def to_3b(int)
[int >> 16, int >> 8, int].map { |i| i & 0xFF }
end
- module_function(:to_3b)
private
def full_message(*data)
[0x7F] + data.flatten + [0xFF, 0x0A]
end
- module_function(:full_message)
def pack(message)
message.pack('c*')
end
- module_function(:pack)
end
end
@@ -28,8 +28,6 @@ module Api
REC_START = 50
REC_STOP = 51
- BMP = 60
-
F = 1
B = 2
@@ -1,6 +1,8 @@
module NabaztagHackKit
module Message
module Helper
+ extend self
+
#blink
def bl(loops = 1, color_on = 0xFF, color_off = 0x00)
repeat(loops, [color_on, color_off])
@@ -11,9 +11,18 @@ 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}"
+ @bytecode_path = bytecode_path || File.expand_path("../../../" + File.join('public', 'bytecode.bin'), __FILE__)
+ puts "Serving Bytecode from #{@bytecode_path}"
+ end
+
+ class << self
+ def callbacks
+ @@callbacks ||= {}
+ end
+
+ def on(callback, &block)
+ callbacks[callback] = block
+ end
end
def send_nabaztag(*data)
@@ -35,7 +44,7 @@ def parse_log(logs)
def callback(action, data, request)
if callback = @@callbacks[action.to_s]
- send(callback, data, request)
+ instance_exec data, request, &callback
else
# puts "no callback found for #{action}"
send_nabaztag OK
@@ -13,8 +13,9 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- s.executables = `git ls-files -- bytecode/bin/*`.split("\n").map{ |f| File.basename(f) }
s.extensions = ['bytecode/src/mtl/extconf.rb']
+
+ s.bindir = 'bytecode/bin'
s.executables = ['mtl_comp', 'mtl_simu', 'mtl_merge']
s.require_paths = ["lib"]
View
Binary file not shown.

0 comments on commit 3eddceb

Please sign in to comment.