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
data/.gitignore CHANGED
@@ -5,3 +5,5 @@ pkg/*
5
5
  .rvmrc
6
6
  *.bin
7
7
  *.o
8
+ examples/record/config.ru
9
+ .mtlrc
data/.travis.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  rvm:
2
2
  - 1.9.2
3
- script: "bundle exec rake test"
3
+ script: "bundle exec rake spec"
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changes
2
2
 
3
+ ## v0.1.0 - xx-09-2012
4
+
5
+ * files restructured, speration byte & ruby code
6
+ * update server for generic structure, added callback
7
+ * mtl binaires respect defaults from local `.mtlrc` file
8
+
3
9
  ## v0.0.2 - 29-01-2012
4
10
 
5
11
  * rename to NabaztagHackKit
@@ -8,4 +14,4 @@
8
14
 
9
15
  ## v0.0.1 - 28-01-2012
10
16
 
11
- * inital release
17
+ * inital release
data/Rakefile CHANGED
@@ -1,21 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
-
3
2
  require 'rspec/core/rake_task'
4
- RSpec::Core::RakeTask.new("unit") do |t|
5
- t.pattern = "./test/**/*_spec.rb" # don't need this, it's default.
6
- end
7
-
8
- namespace :test do
9
- desc "Test bytcode"
10
- task :bytecode do
11
- puts `bin/mtl_simu test/bytecode/test.mtl`
12
- end
13
- end
14
3
 
15
- task :test => [:unit]
16
- task :default => :test
4
+ RSpec::Core::RakeTask.new(:spec)
17
5
 
18
- desc "start server on port 9090"
19
- task :run do
20
- `rackup -p 9090`
21
- end
6
+ task :default => :spec
@@ -433,7 +433,7 @@ On suppose l’existence d’une fonction ‘rand’ qui retourne un nombre alé
433
433
  Random notes of stuff I came accross while developing
434
434
 
435
435
  ### Leds
436
- Thank god it's RGB: Led 0 - 4, Color RGB
436
+ Thank good it's RGB: Led 0 - 4, Color RGB
437
437
 
438
438
  led 0 0x000000; //black
439
439
  led 0 0x0000FF; //blue
@@ -446,6 +446,7 @@ Thank god it's RGB: Led 0 - 4, Color RGB
446
446
 
447
447
 
448
448
  ### Ears
449
+ One loop is 15 ticks
449
450
 
450
451
  ### Custom functions
451
452
 
data/bytecode/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+
2
+ desc "Test bytcode"
3
+ task :test do
4
+ puts `bin/mtl_simu test/test.mtl`
5
+ end
6
+
7
+ task :default => :test
@@ -1,5 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ MTL_FILE = ".mtlrc"
4
+
5
+ if File.exists?(MTL_FILE)
6
+ File.read(MTL_FILE).split("\n").each do |line|
7
+ var, *data = line.split("=")
8
+ ENV[var] = data.join
9
+ end
10
+ end
11
+
3
12
  BIN_NAME = File.basename(__FILE__)
4
13
  BIN_PATH = File.dirname(__FILE__)
5
14
  BIN = File.join( File.expand_path("../ext/mtl", BIN_PATH), BIN_NAME)
@@ -14,9 +14,9 @@ file = ARGV.first
14
14
  dir = File.dirname(file)
15
15
  File.open(TMP, 'w') do |out|
16
16
  File.open(file).each_line do |line|
17
- if line =~ /#include "([^"]+)"/
17
+ if line =~ /\A#include "([^"]+)"/
18
18
  line = `cat #{dir}/#{$1}.mtl`
19
19
  end
20
20
  out.puts line
21
21
  end
22
- end
22
+ end
@@ -1,5 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ MTL_FILE = ".mtlrc"
4
+
5
+ if File.exists?(MTL_FILE)
6
+ File.read(MTL_FILE).split("\n").each do |line|
7
+ var, *data = line.split("=")
8
+ ENV[var] = data.join
9
+ end
10
+ end
11
+
3
12
  BIN_NAME = File.basename(__FILE__)
4
13
  BIN_PATH = File.dirname(__FILE__)
5
14
  BIN = File.join( File.expand_path("../ext/mtl", BIN_PATH), BIN_NAME)
@@ -1,6 +1,12 @@
1
1
  //###############################################
2
2
  //---------------------- Buffer -------------------------------
3
3
 
4
+ // #### LEDS
5
+ // Buffers 0 - 9, where 0-4 are used for onetime, and 5-9 for loop playback.
6
+
7
+ // #### EARS
8
+ // Buffers 10 - 13, where 10 & 11 are used for onetime, and 12 & 13 for loop playback.
9
+
4
10
  var buffers;;
5
11
  type BUFFER=[valB stepB lenB posB loopB];;
6
12
 
@@ -1,27 +1,33 @@
1
1
  //###############################################
2
2
  //------------------- Button --------------------
3
3
 
4
- const BUTTON_REBOOT = 30;; //ms MIN 50ms
4
+ const BUTTON_REBOOT = 3000;; //ms MIN 50ms
5
5
  var button_pressed = 0;;
6
+
6
7
  fun checkButton=
7
8
  if (button2 > 0) then
8
9
  (
9
- set button_pressed = button_pressed + 1;
10
- if button_pressed == 1 then
10
+ if button_pressed == 0 then
11
11
  (
12
- httprequest "GET" buttonUrl (itoa time_ms) "" #_cbHttp HTTP_NORMAL;
13
- 0
14
- ) else if button_pressed == BUTTON_REBOOT then
12
+ set button_pressed = time_ms
13
+ )
14
+ else if (time_ms - button_pressed) > BUTTON_REBOOT then
15
15
  (
16
- buffersFill 0 4 "\0\255\0\255\0\255\255\255"
16
+ buffersFill 0 4 "\255"
17
17
  )
18
18
  )
19
19
  //reboot only when button not pressed, otherwise we get into setup mode
20
- else if button_pressed > BUTTON_REBOOT then
20
+ else if button_pressed > 0 then
21
21
  (
22
- exit
23
- )
24
- else (
25
- set button_pressed = 0
22
+ if (time_ms - button_pressed) > BUTTON_REBOOT then
23
+ (
24
+ exit;
25
+ set button_pressed = 0
26
+ )
27
+ else
28
+ (
29
+ httprequest "GET" buttonPressedUrl (time_ms - button_pressed) "" #_cbHttp HTTP_NORMAL;
30
+ set button_pressed = 0
31
+ )
26
32
  )
27
33
  ;;
data/bytecode/lib/ear.mtl CHANGED
@@ -46,10 +46,10 @@ fun earRead index=
46
46
  if ear.dir != EAR_STOP && lastDuration > 1000 && totalDuration < 1450 then
47
47
  (
48
48
  set ear.pos = earNorm (ear.dir - 1) / 2; // either 0 or 16
49
- bufferFill 0 "\100";
50
- log "reset" {index lastDuration totalDuration ear.dir ear.pos}
49
+ bufferFill 0 "\100"
50
+ // log "reset" {index lastDuration totalDuration ear.dir ear.pos}
51
51
  );
52
- log "moved" {index ear.lastTime ear.lastTime2 ear.lastRead ear.pos ear.shouldPos ear.dir };
52
+ // log "moved" {index ear.lastTime ear.lastTime2 ear.lastRead ear.pos ear.shouldPos ear.dir };
53
53
 
54
54
  set ear.lastTime2 = ear.lastTime;
55
55
  set ear.lastTime = currentTime
data/bytecode/lib/led.mtl CHANGED
@@ -14,7 +14,7 @@ fun ledBufferRead index=
14
14
  ;;
15
15
 
16
16
  fun setLeds=
17
- //LED_CHECK_FQ
17
+ // let LED_CHECK_FQ -> led_check_fq in
18
18
  let (button3 + 1) * 3 -> led_check_fq in
19
19
  if ((time_ms - led_last_check) > led_check_fq) then
20
20
  (
@@ -0,0 +1,16 @@
1
+ //###############################################
2
+ //------------------ PING ----------------------
3
+ const PING_CHECK_FQ = 5000;; //ms -> 5s
4
+ const PING_PARAMS = "";;
5
+
6
+ var ping_last_check = 0;;
7
+
8
+ fun pingCheck=
9
+ let PING_CHECK_FQ -> ping_check_fq in
10
+ if ((time_ms - ping_last_check) > ping_check_fq) then
11
+ (
12
+ httprequest "GET" (pingUrl PING_PARAMS) "" #_cbHttp HTTP_NORMAL;
13
+ set ping_last_check = time_ms
14
+ )
15
+ ;;
16
+
@@ -0,0 +1,87 @@
1
+ var lrec;;
2
+ var recording = 0;;
3
+ var recordingStartedAt = 0;;
4
+ var recSeconds = 0;;
5
+
6
+ var buff;;
7
+ var buffx;;
8
+ var buffy;;
9
+
10
+ //-------------------------------------------------------------
11
+
12
+ fun sqrt_ i i0 i1=
13
+ let (i0+i1)>>1 -> m in
14
+ if m==i0 then i0
15
+ else if m*m>i then sqrt_ i i0 m else sqrt_ i m i1;;
16
+
17
+ fun sqrt i=
18
+ sqrt_ i 0 256;;
19
+
20
+ fun _cbrec s=
21
+ let 255-(Iecholn sqrt recVol s 0) -> vol in
22
+ let 255-((vol*vol)>>8) -> vol in
23
+ let vol<<16 -> vol in
24
+ (
25
+ led 1 vol; led 2 vol; led 3 vol
26
+ );
27
+ set lrec=s::lrec;
28
+ 0;;
29
+
30
+ fun itobin4 i=
31
+ let strnew 4 -> s in
32
+ (
33
+ strset s 0 i;
34
+ strset s 1 i>>8;
35
+ strset s 2 i>>16;
36
+ strset s 3 i>>24;
37
+ s
38
+ );;
39
+
40
+ fun liststrlen l r= if l==nil then r else liststrlen tl l r+strlen hd l;;
41
+
42
+ fun mkriff ldata=
43
+ let Iecholn liststrlen ldata 0 -> len in
44
+ (strcatlist "RIFF"::(itobin4 len+52)::"WAVEfmt \$14\0\0\0\$11\0\1\0\$40\$1f\0\0\$d7\$0f\0\0\0\1\4\0\2\0\$f9\01"::
45
+ "fact\4\0\0\0"::(itobin4 (len>>8)*505)::"data"::(itobin4 len)::nil)::ldata
46
+ ;;
47
+
48
+ fun recriff =
49
+ // rev -> reverse list
50
+ let mkriff rev lrec nil -> res in
51
+ (
52
+ set lrec=nil;
53
+ res
54
+ )
55
+ ;;
56
+
57
+ fun recordingStart sec=
58
+ recStop;
59
+ loopBufferFill 9 "\0\200";
60
+ set recording = 1;
61
+ set recSeconds =sec;
62
+ set lrec = nil;
63
+ set recordingStartedAt = time_ms;
64
+ recStart 8000 0 #_cbrec
65
+ ;;
66
+
67
+ fun httprequestBinary url postdata cb type=
68
+ httprequestRaw "POST" url "Content-Type:application/octet-stream\13\nContent-Disposition: attachment;filename=recording\13\nContent-Transfer-Encoding: binary\13\n" postdata cb type
69
+ ;;
70
+
71
+ fun recordingStop =
72
+ set recording = 0;
73
+ recStop;
74
+ loopBufferFill 9 "\0";
75
+ let recriff -> wavfile in
76
+ (
77
+ httprequestBinary recordingFinishedUrl strcatlist wavfile #_cbHttp HTTP_NORMAL;
78
+ 0
79
+ )
80
+ ;;
81
+
82
+ fun recordingCheck =
83
+ if recording == 1 && recSeconds > 0 && (time_ms - recordingStartedAt) > recSeconds then
84
+ (
85
+ recordingStop
86
+ )
87
+ ;;
@@ -1,7 +1,7 @@
1
1
  //###############################################
2
2
  //--------------- RFID ------------------------
3
3
 
4
- const RFID_CHECK_FQ = 500;; //ms MIN 50ms
4
+ const RFID_CHECK_FQ = 200;; //ms MIN 50ms
5
5
  const RFID_STOP_BYTE = 0xFF;;
6
6
  const RFID_ID_START = "\208\2\26";; // 0xd0 0x02 0x1a
7
7
  const RFID_ID_FALSE = "\0\0\0\0\0\0\0\0\v";;
@@ -16,31 +16,13 @@ fun checkRFID=
16
16
  let rfidGet -> rfid in
17
17
  if (rfid != nil) then
18
18
  (
19
- if ((strstr rfid RFID_ID_START 0) == 0) then
20
- (
21
- httprequest "PUT" playerUrl rfid "" #_cbHttp HTTP_NORMAL;
22
- 0
23
- )
24
- else if ((strstr rfid RFID_ID_FALSE 0) == 0) then
19
+ if ((strstr rfid RFID_ID_FALSE 0) == 0) then
25
20
  (
26
21
  0
27
22
  )
28
23
  else
29
24
  (
30
- let strlen rfid -> len in //usually that's 8
31
- for index = 0; index < len; index + 1 do
32
- (
33
- let strget rfid index -> data_byte in
34
- (
35
- if (data_byte != RFID_STOP_BYTE) then
36
- set rfid_data = strcat rfid_data ctoh data_byte
37
- else if ((strlen rfid_data) > 0) then
38
- (
39
- httprequest "POST" eventUrl rfid_data "" #_cbHttp HTTP_NORMAL;
40
- set rfid_data = ""
41
- )
42
- )
43
- );
25
+ httprequest "PUT" rfidUrl rfid "" #_cbHttp HTTP_NORMAL;
44
26
  0
45
27
  )
46
28
  );
data/bytecode/main.mtl CHANGED
@@ -2,36 +2,58 @@
2
2
 
3
3
  proto main 0;;
4
4
  proto earsInit 0;;
5
-
6
- #include "../ext/bytecode/lib/var"
7
- #include "../ext/bytecode/lib/util"
8
- #include "../ext/bytecode/lib/cfg"
9
- #include "../ext/bytecode/lib/arp"
10
- #include "../ext/bytecode/lib/udp"
11
- #include "../ext/bytecode/lib/tcp"
12
- #include "../ext/bytecode/lib/dns"
13
- #include "../ext/bytecode/lib/http"
14
- #include "../ext/bytecode/lib/dhcp"
5
+ proto evalTrame 1;;
6
+
7
+ #include "src/lib/var"
8
+ #include "src/lib/util"
9
+ #include "src/lib/cfg"
10
+ #include "src/lib/arp"
11
+ #include "src/lib/udp"
12
+ #include "src/lib/tcp"
13
+ #include "src/lib/dns"
14
+ #include "src/lib/http"
15
+ #include "src/lib/dhcp"
16
+ #include "src/lib/wav"
15
17
  #include "lib/data_helper"
16
18
  #include "lib/buffer"
17
- #include "../ext/bytecode/lib/wifi"
19
+ #include "src/lib/wifi"
18
20
 
19
- //-------------------- HTTP
20
- fun playerUrl tag=
21
- strcatlist confGetServerUrl::"/players/"::(webmac tag)::".jsp"::nil;;
21
+ //-------------------- HTTP Endpoints
22
+ fun logUrl=
23
+ strcatlist confGetServerUrl::"/api/log.jsp"::nil;;
22
24
 
23
- fun eventUrl data=
24
- strcatlist confGetServerUrl::"/events.jsp"::"?event[data]="::data::nil;;
25
+ fun buttonPressedUrl data=
26
+ strcatlist confGetServerUrl::"/api/button-pressed.jsp?duration="::(itoa data)::nil;;
25
27
 
26
- fun buttonUrl data=
27
- strcatlist confGetServerUrl::"/vl/button.jsp?"::data::nil;;
28
+ fun recordingFinishedUrl =
29
+ strcatlist confGetServerUrl::"/api/recording-finished.jsp"::nil;;
28
30
 
29
- fun logUrl=
30
- strcatlist confGetServerUrl::"/vl/log.jsp"::nil;;
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;;
39
+
40
+ fun pingUrl params=
41
+ strcatlist confGetServerUrl::"/api/ping.jsp?"::params::nil;;
42
+
43
+ fun streamUrl filename=
44
+ strcatlist confGetServerUrl::"/streams/"::filename::nil;;
45
+
46
+ //-------------------- HTTP
31
47
 
32
48
  fun _cbdummyhttp http res=
33
- 0
34
- ;;
49
+ 0;;
50
+
51
+ fun _cbHttp http res=
52
+ evalTrame res;
53
+ 0;;
54
+
55
+ #include "lib/record"
56
+ #include "lib/ping"
35
57
 
36
58
  fun evalTrame res=
37
59
  let parseResponse httpgetcontent res -> bufferlist in
@@ -81,17 +103,46 @@ fun evalTrame res=
81
103
  _bufferFill index+10 step loop val;
82
104
  0
83
105
  )
106
+ // recording start
107
+ else if code == 50 then
108
+ (
109
+ recordingStart 1000 * (strget val 0) //TODO only 1 - 9 possible??
110
+ )
111
+ // recording stop
112
+ else if code == 51 then
113
+ (
114
+ recordingStop
115
+ )
116
+ // play start
117
+ else if code == 60 then
118
+ (
119
+ // playbackStart
120
+ 0
121
+ )
122
+ // play stop
123
+ else if code == 61 then
124
+ (
125
+ // playbackStop
126
+ 0
127
+ )
128
+ // play load
129
+ else if code == 62 then
130
+ (
131
+ // playbackLoad val
132
+ 0
133
+ )
134
+ // play stream
135
+ else if code == 63 then
136
+ (
137
+ // playbackStream val
138
+ 0
139
+ )
84
140
  )
85
141
  )
86
142
  ;;
87
143
 
88
- fun _cbHttp http res=
89
- evalTrame res;
90
- 0
91
- ;;
92
-
93
144
  //inputs
94
- #include "lib/rfid"
145
+ // #include "lib/rfid"
95
146
  #include "lib/button"
96
147
 
97
148
  //outputs
@@ -104,11 +155,17 @@ fun loop=
104
155
  wifiRun;
105
156
  wifiCheck;
106
157
 
107
- checkRFID;
158
+ // checkRFID;
108
159
  checkButton;
160
+
109
161
  setLeds;
110
162
  earRead 0;
111
163
  earRead 1;
164
+
165
+ pingCheck;
166
+ // wavtime;
167
+
168
+ recordingCheck;
112
169
  0;;
113
170
 
114
171
  //###############################################
@@ -30,7 +30,9 @@ fun httpsendreq ip x=
30
30
  );
31
31
  0;;
32
32
 
33
- fun httprequest verb url postdata cb type=
33
+ fun httprequestRaw verb url header postdata cb type=
34
+ //set postdata = strcatlist "--AaB03x\13\ncontent-disposition: form-dataContent-Transfer-Encoding: binary\13\n\13\n"::postdata::"\13\n--AaB03x--"::nil;
35
+ // Content-Type:application/octet-stream\13\nContent-Disposition: attachment;filename=recording\13\nContent-Transfer-Encoding: binary\13\n
34
36
  let cuturl url ->[host port path] in
35
37
  //let if confGetProxy then strcatlist "http://"::host::":"::(itoa port)::path::nil else path -> path in //Icy-MetaData:1\13\n
36
38
  //let if confGetProxy then webip confGetProxyip else host -> host in
@@ -38,12 +40,11 @@ fun httprequest verb url postdata cb type=
38
40
 
39
41
  let strcatlist verb::" "::path::" HTTP/1.0\13\nUser-Agent: MTL\13\nPragma: no-cache\13\nIcy-MetaData:1\13\nHost: "::host::"\13\n"::
40
42
  if postdata==nil then "\13\n"::nil
41
- else "Content-length: "::(itoa strlen postdata)::"\13\n\13\n"::postdata::nil
43
+ else header::"Content-length: "::(itoa strlen postdata)::"\13\n\13\n"::postdata::nil
42
44
  -> request in // création de la chaîne requête
43
45
 
44
46
  let [outputH:request indexH:0 cbH:cb typeH:type stateH:HTTP_SOLVE aliveH:time_ms] -> httpreq in // création de la structure requête
45
47
  (
46
- // Secho "HTTPREQUEST host =";Secholn host;
47
48
  if isip host 0 then httpsendreq host [port httpreq]
48
49
  else
49
50
  (
@@ -53,6 +54,9 @@ fun httprequest verb url postdata cb type=
53
54
  httpreq // on retourne la structure requête pour pouvoir éventuellement l'interrompre en cours de route
54
55
  );;
55
56
 
57
+ fun httprequest verb url postdata cb type=
58
+ httprequestRaw verb url "" postdata cb type
59
+ ;;
56
60
 
57
61
  var http_sep="\13\n\13\n";; // séparateur entre l'en-tête et le corps de la réponse à une requête
58
62
 
@@ -69,6 +73,14 @@ fun httpgetcontent res =
69
73
  if i==nil then nil
70
74
  else strsub res i+strlen http_sep strlen res;;
71
75
 
76
+ fun httpabort httpreq=
77
+ closetcp httpreq.cnxH;; // on ferme la socket de la requête
78
+
79
+ fun httpenable httpreq v=
80
+ enabletcp httpreq.cnxH v;;
81
+ fun httpenabledP httpreq=
82
+ enabledtcpP httpreq.cnxH;;
83
+
72
84
  // Cryptage des trames
73
85
  fun bintoi3 s x=((strget s x)<<16)+((strget s x+1)<<8)+(strget s x+2);;
74
86
 
@@ -19,7 +19,7 @@ fun mkudp ipsrc ipdst portsrc portdst content=
19
19
  );;
20
20
 
21
21
  fun udpSend2 mac udp=
22
- Secho ">u";
22
+ // Secho ">u";
23
23
  // dump udp;
24
24
  netSend udp 0 nil (/*MACecho*/ mac /*0 1*/) 0 1;;
25
25
 
@@ -4,6 +4,7 @@ fun setleds col= for i=0;i<5 do led i col;;
4
4
  fun strstr s p i=strfind s i p 0 nil;;
5
5
  fun listlen l=if l==nil then 0 else 1+listlen tl l;;
6
6
  fun listrem l x=if l!=nil then if x==hd l then tl l else (hd l)::listrem tl l x;;
7
+ fun slistlen l= if l==nil then 0 else (strlen hd l)+slistlen tl l;;
7
8
 
8
9
  fun listtostr l=
9
10
  let strnew listlen l -> s in
@@ -71,4 +72,6 @@ fun useparamip val=
71
72
  (
72
73
  _useparamip ip 0 val 0;
73
74
  ip
74
- );;
75
+ );;
76
+
77
+ fun conc p q=if p==nil then q else (hd p)::conc tl p q;;