nabaztag_hack_kit 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitignore +7 -0
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +11 -0
  4. data/Gemfile +4 -0
  5. data/README.md +119 -0
  6. data/Rakefile +21 -0
  7. data/bin/mtl_comp +41 -0
  8. data/bin/mtl_merge +22 -0
  9. data/bin/mtl_simu +40 -0
  10. data/bytecode/lib/buffer.mtl +109 -0
  11. data/bytecode/lib/button.mtl +27 -0
  12. data/bytecode/lib/data_helper.mtl +88 -0
  13. data/bytecode/lib/ear.mtl +90 -0
  14. data/bytecode/lib/led.mtl +33 -0
  15. data/bytecode/lib/rfid.mtl +50 -0
  16. data/bytecode/main.mtl +129 -0
  17. data/config.ru +6 -0
  18. data/ext/bytecode/Commands.md +172 -0
  19. data/ext/bytecode/Docs.md +488 -0
  20. data/ext/bytecode/README.md +5 -0
  21. data/ext/bytecode/lib/arp.mtl +159 -0
  22. data/ext/bytecode/lib/cfg.mtl +74 -0
  23. data/ext/bytecode/lib/choreos.mtl +1487 -0
  24. data/ext/bytecode/lib/dhcp.mtl +152 -0
  25. data/ext/bytecode/lib/dns.mtl +89 -0
  26. data/ext/bytecode/lib/http.mtl +84 -0
  27. data/ext/bytecode/lib/tcp.mtl +340 -0
  28. data/ext/bytecode/lib/udp.mtl +49 -0
  29. data/ext/bytecode/lib/util.mtl +74 -0
  30. data/ext/bytecode/lib/var.mtl +15 -0
  31. data/ext/bytecode/lib/wifi.mtl +243 -0
  32. data/ext/bytecode/nominal-ping.mtl +5828 -0
  33. data/ext/mtl/Makefile +42 -0
  34. data/ext/mtl/README.md +13 -0
  35. data/ext/mtl/bc.cpp +1891 -0
  36. data/ext/mtl/conf.bin.sans_password +0 -0
  37. data/ext/mtl/config.txt +5 -0
  38. data/ext/mtl/dumpbc.c +2566 -0
  39. data/ext/mtl/extconf.rb +1 -0
  40. data/ext/mtl/linux_simu.c +271 -0
  41. data/ext/mtl/linux_simuaudio.c +16 -0
  42. data/ext/mtl/linux_simuaudio.h +18 -0
  43. data/ext/mtl/linux_simunet.c +620 -0
  44. data/ext/mtl/linux_simunet.h +7 -0
  45. data/ext/mtl/log.c +297 -0
  46. data/ext/mtl/log.h +20 -0
  47. data/ext/mtl/main_compiler.cpp +104 -0
  48. data/ext/mtl/main_simu.cpp +221 -0
  49. data/ext/mtl/mp3/GTKANAL.H +97 -0
  50. data/ext/mtl/mp3/LAYER3.C +2090 -0
  51. data/ext/mtl/mp3/TABINIT.C +82 -0
  52. data/ext/mtl/mp3/common.c +265 -0
  53. data/ext/mtl/mp3/dct64_i386.c +316 -0
  54. data/ext/mtl/mp3/decode_i386.c +155 -0
  55. data/ext/mtl/mp3/huffman.h +332 -0
  56. data/ext/mtl/mp3/interface.c +258 -0
  57. data/ext/mtl/mp3/mpg123.h +182 -0
  58. data/ext/mtl/mp3/mpglib.h +44 -0
  59. data/ext/mtl/properties.c +293 -0
  60. data/ext/mtl/properties.h +10 -0
  61. data/ext/mtl/simu.c +750 -0
  62. data/ext/mtl/simuaudio.c +662 -0
  63. data/ext/mtl/simuaudio.h +74 -0
  64. data/ext/mtl/simunet.c +400 -0
  65. data/ext/mtl/simunet.h +30 -0
  66. data/ext/mtl/utils/correct_const.sh +34 -0
  67. data/ext/mtl/vaudio.c +677 -0
  68. data/ext/mtl/vaudio.h +46 -0
  69. data/ext/mtl/vbc.h +160 -0
  70. data/ext/mtl/vbc_str.h +166 -0
  71. data/ext/mtl/vcomp/Makefile +29 -0
  72. data/ext/mtl/vcomp/bootstrap.cpp +89 -0
  73. data/ext/mtl/vcomp/compiler.cpp +470 -0
  74. data/ext/mtl/vcomp/compiler.h +200 -0
  75. data/ext/mtl/vcomp/compiler_file.cpp +929 -0
  76. data/ext/mtl/vcomp/compiler_prog.cpp +250 -0
  77. data/ext/mtl/vcomp/compiler_term.cpp +1053 -0
  78. data/ext/mtl/vcomp/compiler_type.cpp +872 -0
  79. data/ext/mtl/vcomp/compiler_var.cpp +289 -0
  80. data/ext/mtl/vcomp/file.cpp +79 -0
  81. data/ext/mtl/vcomp/file.h +39 -0
  82. data/ext/mtl/vcomp/filesystem.h +14 -0
  83. data/ext/mtl/vcomp/interpreter.cpp +85 -0
  84. data/ext/mtl/vcomp/interpreter.h +121 -0
  85. data/ext/mtl/vcomp/memory.cpp +241 -0
  86. data/ext/mtl/vcomp/memory.h +326 -0
  87. data/ext/mtl/vcomp/param.h +95 -0
  88. data/ext/mtl/vcomp/parser.cpp +427 -0
  89. data/ext/mtl/vcomp/parser.h +97 -0
  90. data/ext/mtl/vcomp/parser_xml.cpp +124 -0
  91. data/ext/mtl/vcomp/prodbuffer.cpp +125 -0
  92. data/ext/mtl/vcomp/prodbuffer.h +42 -0
  93. data/ext/mtl/vcomp/resource.h +17 -0
  94. data/ext/mtl/vcomp/stdlib_core.cpp +122 -0
  95. data/ext/mtl/vcomp/terminal.cpp +73 -0
  96. data/ext/mtl/vcomp/terminal.h +30 -0
  97. data/ext/mtl/vcomp/util.cpp +48 -0
  98. data/ext/mtl/vcomp/util.h +31 -0
  99. data/ext/mtl/vinterp.c +1349 -0
  100. data/ext/mtl/vinterp.h +11 -0
  101. data/ext/mtl/vloader.c +127 -0
  102. data/ext/mtl/vloader.h +31 -0
  103. data/ext/mtl/vlog.c +589 -0
  104. data/ext/mtl/vlog.h +69 -0
  105. data/ext/mtl/vmem.c +424 -0
  106. data/ext/mtl/vmem.h +107 -0
  107. data/ext/mtl/vnet.c +255 -0
  108. data/ext/mtl/vnet.h +19 -0
  109. data/lib/nabaztag_hack_kit/message/api.rb +39 -0
  110. data/lib/nabaztag_hack_kit/message/helper.rb +39 -0
  111. data/lib/nabaztag_hack_kit/message.rb +36 -0
  112. data/lib/nabaztag_hack_kit/server.rb +50 -0
  113. data/lib/nabaztag_hack_kit/version.rb +3 -0
  114. data/lib/nabaztag_hack_kit.rb +4 -0
  115. data/nabaztag_hack_kit.gemspec +29 -0
  116. data/public/bytecode.bin +0 -0
  117. data/test/bytecode/helper.mtl +60 -0
  118. data/test/bytecode/native.mtl +28 -0
  119. data/test/bytecode/test.mtl +221 -0
  120. data/test/spec_helper.rb +5 -0
  121. data/test/unit/message_spec.rb +56 -0
  122. metadata +209 -0
data/ext/mtl/vnet.c ADDED
@@ -0,0 +1,255 @@
1
+ // VLISP Virtual Machine - 2006 - by Sylvain Huet
2
+ // Lowcost IS Powerfull
3
+ #include"vmem.h"
4
+ #include"properties.h"
5
+
6
+ #ifdef VSIMU
7
+ #include <string.h>
8
+ #include<stdio.h>
9
+ #include<time.h>
10
+ #include "log.h"
11
+ int netstatesimu=1;
12
+ #endif
13
+ #ifdef VREAL
14
+ #include "rt2501usb.h"
15
+ #endif
16
+ #include"vloader.h"
17
+ #include"vnet.h"
18
+ #include"vlog.h"
19
+ #include"vinterp.h"
20
+ int netState()
21
+ {
22
+ #ifdef VSIMU
23
+ return netstatesimu;
24
+ #endif
25
+ #ifdef VREAL
26
+ return rt2501_state();
27
+ #endif
28
+ }
29
+
30
+ int netSend(char* src,int indexsrc,int lentosend,int lensrc,char* macdst,int inddst,int lendst,int speed)
31
+ {
32
+ #ifdef VSIMU
33
+ my_printf(LOG_SIMUNET, "xxxx netSend\n");
34
+ return -1;
35
+ #endif
36
+ #ifdef VREAL
37
+ if (indexsrc<0) return -1;
38
+ if (indexsrc+lentosend>lensrc) lentosend=lensrc-indexsrc;
39
+ if (lentosend<=0) return -1;
40
+ if (inddst<0) return -1;
41
+ if (inddst+6>lendst) return -1;
42
+ return rt2501_send((const unsigned char *)(src+indexsrc),lentosend,(const unsigned char *)(macdst+inddst),speed,1);
43
+ #endif
44
+ }
45
+
46
+ int netCb(char* src,int lensrc,char* macsrc)
47
+ {
48
+ VPUSH(PNTTOVAL(VMALLOCSTR(src,lensrc)));
49
+ VPUSH(PNTTOVAL(VMALLOCSTR(macsrc,6)));
50
+ VPUSH(VCALLSTACKGET(sys_start,SYS_CBTCP));
51
+ if (VSTACKGET(0)!=NIL) interpGo();
52
+ else { VPULL();VPULL();}
53
+ VPULL();
54
+ return 0;
55
+ }
56
+
57
+ extern unsigned char rt2501_mac[6];
58
+
59
+ #ifdef VSIMU
60
+ int htoi2(char* src)
61
+ {
62
+ char buf[3];
63
+ buf[0]=src[0];
64
+ buf[1]=src[1];
65
+ buf[2]=0;
66
+ return sysHtoi(buf);
67
+ }
68
+ #endif
69
+
70
+ char mac[6];
71
+
72
+ char* netMac()
73
+ {
74
+ #ifdef VSIMU
75
+ int i;
76
+ char *p=PropGet("MAC");
77
+ for(i=0;i<6;i++) mac[i]=htoi2(&p[i*2]);
78
+ return mac;
79
+ // return "abcdef";
80
+ #endif
81
+ #ifdef VREAL
82
+ return (char*) rt2501_mac;
83
+ #endif
84
+ }
85
+
86
+ int netChk(char* src,int indexsrc,int lentosend,int lensrc,unsigned int val)
87
+ {
88
+ unsigned short* p;
89
+
90
+ if (indexsrc<0) return val;
91
+ if (indexsrc+lentosend>lensrc) lentosend=lensrc-indexsrc;
92
+ if (lentosend<=0) return val;
93
+
94
+ src+=indexsrc;
95
+ p=(unsigned short*)src;
96
+
97
+ val=((val<<8)&0xff00)+((val>>8)&0xff);
98
+ while(lentosend>1)
99
+ {
100
+ val+=*(p++);
101
+ lentosend-=2;
102
+ }
103
+ if (lentosend) val+=*(unsigned char*)p;
104
+
105
+ val=(val>>16)+(val&0xffff);
106
+ val=(val>>16)+(val&0xffff);
107
+ val=((val<<8)&0xff00)+((val>>8)&0xff);
108
+ return val;
109
+ }
110
+
111
+ void netSetmode(int mode,char* ssid,int chn)
112
+ {
113
+ #ifdef VSIMU
114
+ my_printf(LOG_SIMUNET, "xxxx netSetmode %d %s %d\n",mode,ssid,chn);
115
+ netstatesimu=(mode)?5:4;
116
+ #endif
117
+ #ifdef VREAL
118
+ rt2501_setmode(mode,ssid,chn);
119
+ #endif
120
+ }
121
+
122
+
123
+ int nscan;
124
+ #ifdef VREAL
125
+ void netScan_(struct rt2501_scan_result *scan_result, void *userparam)
126
+ {
127
+ char buf[256];
128
+ sprintf(buf,">>> %s %d %d %d %d\n",scan_result->ssid,scan_result->rssi,scan_result->channel,scan_result->rateset,scan_result->encryption);
129
+ consolestr((UBYTE*)buf);
130
+ VPUSH(PNTTOVAL(VMALLOCSTR(scan_result->ssid,strlen(scan_result->ssid))));
131
+ VPUSH(PNTTOVAL(VMALLOCSTR((char*)scan_result->mac,6)));
132
+ VPUSH(PNTTOVAL(VMALLOCSTR((char*)scan_result->bssid,6)));
133
+ VPUSH(INTTOVAL(scan_result->rssi));
134
+ VPUSH(INTTOVAL(scan_result->channel));
135
+ VPUSH(INTTOVAL(scan_result->rateset));
136
+ VPUSH(INTTOVAL(scan_result->encryption));
137
+ VMKTAB(7);
138
+ nscan++;
139
+ }
140
+ #endif
141
+
142
+ void netScan(char* ssid)
143
+ {
144
+ nscan=0;
145
+ #ifdef VSIMU
146
+ VPUSH(PNTTOVAL(VMALLOCSTR("foo",3)));
147
+ VPUSH(PNTTOVAL(VMALLOCSTR("xyzxyz",6)));
148
+ VPUSH(PNTTOVAL(VMALLOCSTR("765432",6)));
149
+ VPUSH(INTTOVAL(-20));
150
+ VPUSH(INTTOVAL(11));
151
+ VPUSH(INTTOVAL(1));
152
+ VPUSH(INTTOVAL(0));
153
+ VMKTAB(7);
154
+ nscan++;
155
+ VPUSH(PNTTOVAL(VMALLOCSTR("foo",3)));
156
+ VPUSH(PNTTOVAL(VMALLOCSTR("xyzxyz",6)));
157
+ VPUSH(PNTTOVAL(VMALLOCSTR("765432",6)));
158
+ VPUSH(INTTOVAL(-10));
159
+ VPUSH(INTTOVAL(11));
160
+ VPUSH(INTTOVAL(1));
161
+ VPUSH(INTTOVAL(0));
162
+ VMKTAB(7);
163
+ nscan++;
164
+ VPUSH(PNTTOVAL(VMALLOCSTR("zzzz",3)));
165
+ VPUSH(PNTTOVAL(VMALLOCSTR("xyzxyz",6)));
166
+ VPUSH(PNTTOVAL(VMALLOCSTR("765432",6)));
167
+ VPUSH(INTTOVAL(-10));
168
+ VPUSH(INTTOVAL(11));
169
+ VPUSH(INTTOVAL(1));
170
+ VPUSH(INTTOVAL(0));
171
+ VMKTAB(7);
172
+ nscan++;
173
+ VPUSH(PNTTOVAL(VMALLOCSTR("",3)));
174
+ VPUSH(PNTTOVAL(VMALLOCSTR("xyzxyz",6)));
175
+ VPUSH(PNTTOVAL(VMALLOCSTR("765432",6)));
176
+ VPUSH(INTTOVAL(-10));
177
+ VPUSH(INTTOVAL(11));
178
+ VPUSH(INTTOVAL(1));
179
+ VPUSH(INTTOVAL(0));
180
+ VMKTAB(7);
181
+ nscan++;
182
+ VPUSH(PNTTOVAL(VMALLOCSTR("a\"a<a'a a\\a",strlen("a\"a<a'a a\\a"))));
183
+ VPUSH(PNTTOVAL(VMALLOCSTR("xyzxyz",6)));
184
+ VPUSH(PNTTOVAL(VMALLOCSTR("765432",6)));
185
+ VPUSH(INTTOVAL(-10));
186
+ VPUSH(INTTOVAL(11));
187
+ VPUSH(INTTOVAL(1));
188
+ VPUSH(INTTOVAL(3));
189
+ VMKTAB(7);
190
+ nscan++;
191
+ VPUSH(PNTTOVAL(VMALLOCSTR("foo",3)));
192
+ VPUSH(PNTTOVAL(VMALLOCSTR("xyzxyz",6)));
193
+ VPUSH(PNTTOVAL(VMALLOCSTR("765432",6)));
194
+ VPUSH(INTTOVAL(-30));
195
+ VPUSH(INTTOVAL(11));
196
+ VPUSH(INTTOVAL(1));
197
+ VPUSH(INTTOVAL(0));
198
+ VMKTAB(7);
199
+ nscan++;
200
+ #endif
201
+ #ifdef VREAL
202
+ rt2501_scan(ssid, netScan_, NULL);
203
+ #endif
204
+ VPUSH(NIL);
205
+ while(nscan--) VMKTAB(2);
206
+ }
207
+
208
+ void netAuth(char* ssid,char* mac,char* bssid,int chn,int rate,int authmode,int encrypt,char* key)
209
+ {
210
+ #ifdef VSIMU
211
+ my_printf(LOG_SIMUNET, "xxxx netAuth %s %d %d %d %d\n",ssid,chn,rate,authmode,encrypt);
212
+ netstatesimu=4;
213
+ #endif
214
+ #ifdef VREAL
215
+ rt2501_auth((const char*)ssid,(const unsigned char*)mac,(const unsigned char*)bssid,chn,rate,authmode,encrypt,(const unsigned char*)key);
216
+ #endif
217
+ }
218
+
219
+ void netSeqAdd(unsigned char* seq,int n)
220
+ {
221
+ unsigned char res[4];
222
+ unsigned int val;
223
+ val=(seq[0]<<24)+(seq[1]<<16)+(seq[2]<<8)+seq[3];
224
+ val+=n;
225
+ res[3]=val; val>>=8;
226
+ res[2]=val; val>>=8;
227
+ res[1]=val; val>>=8;
228
+ res[0]=val;
229
+ VPUSH(PNTTOVAL(VMALLOCSTR((char*)res,4)));
230
+ }
231
+
232
+ void mypassword_to_pmk(const char *password, char *ssid, int ssidlength, unsigned char *pmk);
233
+
234
+ void netPmk(char* ssid,char* key,char* buf)
235
+ {
236
+ #ifdef VSIMU
237
+ my_printf(LOG_SIMUNET, "xxxx netPmk %s %s\n",ssid,key);
238
+ strcpy(buf,"01234567012345670123456701234567");
239
+ #endif
240
+ #ifdef VREAL
241
+ // strcpy(buf,"01234567012345670123456701234567");
242
+ mypassword_to_pmk(key,ssid,strlen(ssid), (unsigned char*)buf);
243
+ #endif
244
+ }
245
+
246
+ int netRssi()
247
+ {
248
+ #ifdef VSIMU
249
+ return -20;
250
+ #endif
251
+ #ifdef VREAL
252
+ return rt2501_rssi_average();
253
+ #endif
254
+ }
255
+
data/ext/mtl/vnet.h ADDED
@@ -0,0 +1,19 @@
1
+ // VLISP Virtual Machine - 2006 - by Sylvain Huet
2
+ // Lowcost IS Powerfull
3
+
4
+ #ifndef _NET_
5
+ #define _NET_
6
+
7
+ int netState();
8
+ int netSend(char* src,int indexsrc,int lentosend,int lensrc,char* macdst,int inddst,int lendst,int speed);
9
+ int netCb(char* src,int lensrc,char* macsrc);
10
+ char* netMac();
11
+ int netChk(char* src,int indexsrc,int lentosend,int lensrc,unsigned int val);
12
+ void netSetmode(int mode,char* ssid,int chn);
13
+ void netScan(char* ssid);
14
+ void netAuth(char* ssid,char* mac,char* bssid,int chn,int rate,int authmode,int encrypt,char* key);
15
+ void netSeqAdd(unsigned char* seq,int n);
16
+ void netPmk(char* ssid,char* key,char* buf);
17
+ int netRssi();
18
+ #endif
19
+
@@ -0,0 +1,39 @@
1
+ module NabaztagHackKit
2
+ module Message
3
+ module Api
4
+ # 0 - 10 reserved for violet backwards compatibility
5
+
6
+ OK = 12
7
+ INIT = 16
8
+ LOG = 17
9
+ ERROR = 18
10
+ REBOOT = 19
11
+
12
+ LED_0 = 20
13
+ LED_1 = 21
14
+ LED_2 = 22
15
+ LED_3 = 23
16
+ LED_4 = 24
17
+ LED_L0 = 25
18
+ LED_L1 = 26
19
+ LED_L2 = 27
20
+ LED_L3 = 28
21
+ LED_L4 = 29
22
+
23
+ EAR_L = 40
24
+ EAR_R = 41
25
+ EAR_LL = 42
26
+ EAR_LR = 43
27
+
28
+ F = 1
29
+ B = 2
30
+
31
+ def rgb(values)
32
+ values.map do |value|
33
+ Message.to_3b(value)
34
+ end.flatten
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ module NabaztagHackKit
2
+ module Message
3
+ module Helper
4
+ #blink
5
+ def bl(loops = 1, color_on = 0xFF, color_off = 0x00)
6
+ repeat(loops, [color_on, color_off])
7
+ end
8
+
9
+ #repeat
10
+ def rp(loops, pattern = 0)
11
+ Array.new(loops, pattern).flatten
12
+ end
13
+ alias_method :sl, :rp #sleep
14
+
15
+ #knight rider
16
+ def kr(color = 0xFF, led1 = Api::LED_L1, led2 = Api::LED_L2, led3 = Api::LED_L3)
17
+ {
18
+ led1 => [color,0,0,0],
19
+ led2 => [0,color],
20
+ led3 => [0,0,color,0]
21
+ }
22
+ end
23
+
24
+ def fire(color = 0x110000, led1 = Api::LED_L1, led2 = Api::LED_L2, led3 = Api::LED_L3)
25
+ data = Array.new(16) do |i|
26
+ Message.to_3b(i * color)
27
+ end + Array.new(8) do |i|
28
+ Message.to_3b((15-i) * 2 * color)
29
+ end
30
+
31
+ {
32
+ (led1+10) => data + [0,0,0] + [0,0,0],
33
+ (led2+10) => [0,0,0] + data + [0,0,0],
34
+ (led3+10) => [0,0,0] + [0,0,0] + data
35
+ }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,36 @@
1
+ module NabaztagHackKit
2
+ module Message
3
+
4
+ def build(*commands)
5
+ commands = if commands.first.is_a?(Hash)
6
+ commands.first
7
+ elsif !commands.first.is_a?(Array)
8
+ [commands]
9
+ else
10
+ commands
11
+ end
12
+
13
+ pack full_message commands.map { |cmd, *data|
14
+ [cmd] + to_3b(data.flatten.size) + data.flatten
15
+ }
16
+ end
17
+ module_function(:build)
18
+
19
+ def to_3b(int)
20
+ [int >> 16, int >> 8, int].map { |i| i & 0xFF }
21
+ end
22
+ module_function(:to_3b)
23
+
24
+ private
25
+ def full_message(*data)
26
+ [0x7F] + data.flatten + [0xFF, 0x0A]
27
+ end
28
+ module_function(:full_message)
29
+
30
+ def pack(message)
31
+ message.pack('c*')
32
+ end
33
+ module_function(:pack)
34
+ end
35
+
36
+ end
@@ -0,0 +1,50 @@
1
+ require 'sinatra/base'
2
+
3
+ require 'nabaztag_hack_kit/message'
4
+ require 'nabaztag_hack_kit/message/api'
5
+
6
+ module NabaztagHackKit
7
+ class Server < Sinatra::Base
8
+ include Message::Api
9
+
10
+ def initialize(bytecode_path = nil)
11
+ super
12
+ @bytecode_path = bytecode_path || File.join('public', 'bytecode.bin')
13
+ end
14
+
15
+ def send_nabaztag(*data)
16
+ Message.build(*data)
17
+ end
18
+
19
+ def parse_log(logs)
20
+ logs.to_s.split("|").map do |line|
21
+ type, time, *values = line.split(",")
22
+ time = time.to_i
23
+ values = values.map &:to_i
24
+
25
+ if type == "moved"
26
+ values << (time - values[1]) << (values[1] - values[2]) << (time - values[2]) << (time - values[3])
27
+ end
28
+ "#{type}-#{time}: #{values.join("\t")}"
29
+ end
30
+ end
31
+
32
+ get '/bc.jsp' do
33
+ # TODO recompile if changed
34
+ send_file @bytecode_path
35
+ end
36
+
37
+ get '/vl/button.jsp' do
38
+ send_nabaztag EAR_L => [12,0,16,0,16,0,16,0]
39
+ end
40
+
41
+ post '/vl/log.jsp' do
42
+ @logs = parse_log params[:logs]
43
+ puts "#########################"
44
+ puts @logs.join("\n")
45
+ puts "#########################"
46
+ send_nabaztag OK
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,3 @@
1
+ module NabaztagHackKit
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "nabaztag_hack_kit/version"
2
+
3
+ module NabaztagHackKit
4
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "nabaztag_hack_kit/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "nabaztag_hack_kit"
7
+ s.version = NabaztagHackKit::VERSION
8
+ s.authors = ["RngTng - Tobias Bielohlawek"]
9
+ s.email = ["tobi@soundcloud.com"]
10
+ s.homepage = "https://github.com/rngtng/nabaztag_hack_kit"
11
+ s.summary = %q{Sinatra server to run custom Nabaztag bytecode}
12
+ s.description = %q{Sinatra server api framework to run custom bytecode on Nabaztag v1/v2. Sources + Compiler included (linux only)}
13
+
14
+ s.files = `git ls-files`.split("\n")
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']
18
+ s.executables = ['mtl_comp', 'mtl_simu', 'mtl_merge']
19
+
20
+ s.require_paths = ["lib"]
21
+
22
+ ["sinatra"].each do |gem|
23
+ s.add_dependency *gem.split(' ')
24
+ end
25
+
26
+ ["rake", "rspec"].each do |gem|
27
+ s.add_development_dependency *gem.split(' ')
28
+ end
29
+ end
Binary file
@@ -0,0 +1,60 @@
1
+ //----- asserts
2
+ fun test name=
3
+ SLecholn "\n"::name::": "::nil
4
+ ;;
5
+
6
+ fun ok should=
7
+ SLecholn " "::should::" is valid"::nil
8
+ ;;
9
+
10
+ fun failed should is=
11
+ SLecholn "!! "::" "::should::" expected but got "::is::nil
12
+ ;;
13
+
14
+ fun assert_nil should=
15
+ if(should == nil) then
16
+ ok ""
17
+ else
18
+ failed "nil" "not nil"
19
+ ;;
20
+
21
+ fun assert_equal should=
22
+ if(should == 1) then
23
+ ok ""
24
+ else
25
+ failed "true" "false"
26
+ ;;
27
+
28
+ fun assert_not_equal should=
29
+ if(should != 1) then
30
+ ok ""
31
+ else
32
+ failed "false" "true"
33
+ ;;
34
+
35
+ fun assert_equalI should is=
36
+ if(should == is) then
37
+ ok itoa should
38
+ else
39
+ failed itoa should itoa is
40
+ ;;
41
+
42
+ fun assert_equalS should is=
43
+ let strcat should "\v" -> shouldn in
44
+ if(strcmp should is) == 0 then
45
+ ok should
46
+ else
47
+ failed should is
48
+ ;;
49
+
50
+ fun assert_equalIL should is=
51
+ assert_equalS listtostr should listtostr is
52
+ ;;
53
+
54
+ fun assert_equalSL should is=
55
+ assert_equalS strcatlist should strcatlist is
56
+ ;;
57
+
58
+ fun assert_equalTL should is=
59
+ assert_equalS TLtoS should TLtoS is
60
+ ;;
@@ -0,0 +1,28 @@
1
+ //-------- test for native function
2
+
3
+ let test "listlen" -> t in
4
+ (
5
+ assert_equalI 0 listlen nil ;
6
+ assert_equalI 1 listlen "test"::nil
7
+ );
8
+
9
+ let test "listtostr" -> t in
10
+ (
11
+ assert_equalS "\49" listtostr 49::nil;
12
+ assert_equalS "\51\52\53" listtostr 51::52::53::nil
13
+ );
14
+
15
+ let test "strcatlist" -> t in
16
+ (
17
+ assert_equalS "\54" strcatlist "\54"::nil;
18
+ assert_equalS "313233" strcatlist "31"::"32"::"33"::nil
19
+ );
20
+
21
+ // remfromlist same as listrem!!!
22
+ //let test "remfromlist" -> t in
23
+ //(
24
+ // let "asd"::"a"::nil -> l in
25
+ // Lecho (remfromlist l (listlen l) - 1)
26
+ // //assert_equalS "0A000"
27
+ // assert_equalL 48::49::50::nil listrem 48::49::50::nil 49
28
+ //);