nabaztag_hack_kit 0.1.0.beta3 → 0.1.0.beta8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -2
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +2 -2
  5. data/CHANGELOG.md +17 -2
  6. data/LICENSE +21 -0
  7. data/README.md +115 -44
  8. data/Rakefile +2 -6
  9. data/bytecode/{Commands.md → _docs/commands.md} +0 -0
  10. data/bytecode/{Docs.md → _docs/grammar.md} +0 -0
  11. data/bytecode/_docs/grammar.pdf +0 -0
  12. data/bytecode/{src → _original}/README.md +0 -0
  13. data/bytecode/{src → _original}/lib/arp.mtl +0 -0
  14. data/bytecode/{src → _original}/lib/cfg.mtl +0 -0
  15. data/bytecode/{src → _original}/lib/choreos.mtl +0 -0
  16. data/bytecode/{src → _original}/lib/dhcp.mtl +0 -0
  17. data/bytecode/{src → _original}/lib/dns.mtl +0 -0
  18. data/bytecode/{src → _original}/lib/http.mtl +0 -0
  19. data/bytecode/{src → _original}/lib/tcp.mtl +0 -0
  20. data/bytecode/{src → _original}/lib/udp.mtl +0 -0
  21. data/bytecode/{src → _original}/lib/util.mtl +0 -0
  22. data/bytecode/{src → _original}/lib/var.mtl +0 -0
  23. data/bytecode/{src → _original}/lib/wav.mtl +0 -0
  24. data/bytecode/{src → _original}/lib/wifi.mtl +0 -0
  25. data/bytecode/{src → _original}/nominal-ping.mtl +0 -0
  26. data/bytecode/main.mtl +11 -11
  27. data/bytecode/test/test.mtl +8 -8
  28. data/examples/basic/Gemfile +1 -3
  29. data/examples/basic/config.ru +14 -4
  30. data/examples/record/Gemfile +0 -5
  31. data/examples/record/{config.ru.example → config.ru} +2 -2
  32. data/examples/record/server.rb +0 -2
  33. data/ext/Makefile +10 -0
  34. data/ext/bin/mtl_comp +29 -0
  35. data/{bytecode → ext}/bin/mtl_merge +0 -0
  36. data/ext/bin/mtl_simu +29 -0
  37. data/{bytecode/src/mtl → ext}/extconf.rb +0 -0
  38. data/ext/mtl_linux/.gitignore +7 -0
  39. data/ext/mtl_linux/LICENSE +21 -0
  40. data/ext/mtl_linux/Makefile +116 -0
  41. data/ext/mtl_linux/MetalC.project +196 -0
  42. data/ext/mtl_linux/conf.bin +0 -0
  43. data/{bytecode/src/mtl → ext/mtl_linux}/conf.bin.sans_password +0 -0
  44. data/{bytecode/src/mtl → ext/mtl_linux}/config.txt +0 -0
  45. data/ext/mtl_linux/inc/log.h +21 -0
  46. data/{bytecode/src/mtl → ext/mtl_linux/inc}/properties.h +0 -0
  47. data/{bytecode/src/mtl/linux_simuaudio.h → ext/mtl_linux/inc/simu/linux/simuaudio.h} +0 -0
  48. data/{bytecode/src/mtl/linux_simunet.h → ext/mtl_linux/inc/simu/linux/simunet.h} +0 -0
  49. data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simuaudio.h +18 -18
  50. data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simunet.h +0 -0
  51. data/ext/mtl_linux/inc/vcomp/compiler.h +200 -0
  52. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/file.h +11 -11
  53. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/filesystem.h +0 -0
  54. data/ext/mtl_linux/inc/vcomp/interpreter.h +121 -0
  55. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/memory.h +120 -92
  56. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/param.h +0 -0
  57. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/parser.h +27 -27
  58. data/ext/mtl_linux/inc/vcomp/prodbuffer.h +42 -0
  59. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/resource.h +1 -1
  60. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/terminal.h +8 -8
  61. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/util.h +7 -7
  62. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vaudio.h +0 -0
  63. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vbc.h +1 -1
  64. data/ext/mtl_linux/inc/vm/vbc_str.h +167 -0
  65. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vinterp.h +0 -0
  66. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vloader.h +0 -0
  67. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vlog.h +0 -0
  68. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vmem.h +0 -0
  69. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vnet.h +0 -0
  70. data/ext/mtl_linux/nominal.mtl +3959 -0
  71. data/ext/mtl_linux/src/comp/main.cpp +123 -0
  72. data/ext/mtl_linux/src/simu/dumpbc.c +2566 -0
  73. data/ext/mtl_linux/src/simu/linux/main.cpp +288 -0
  74. data/ext/mtl_linux/src/simu/linux/simu.c +309 -0
  75. data/ext/mtl_linux/src/simu/linux/simuaudio.c +44 -0
  76. data/ext/mtl_linux/src/simu/linux/simunet.c +707 -0
  77. data/ext/mtl_linux/src/simu/log.c +340 -0
  78. data/ext/mtl_linux/src/simu/properties.c +368 -0
  79. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/GTKANAL.H +0 -0
  80. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/LAYER3.C +0 -0
  81. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/TABINIT.C +0 -0
  82. data/ext/mtl_linux/src/simu/win/mp3/common.c +302 -0
  83. data/ext/mtl_linux/src/simu/win/mp3/dct64_i386.c +316 -0
  84. data/ext/mtl_linux/src/simu/win/mp3/decode_i386.c +160 -0
  85. data/ext/mtl_linux/src/simu/win/mp3/huffman.h +332 -0
  86. data/ext/mtl_linux/src/simu/win/mp3/interface.c +276 -0
  87. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/mpg123.h +34 -30
  88. data/ext/mtl_linux/src/simu/win/mp3/mpglib.h +47 -0
  89. data/ext/mtl_linux/src/simu/win/simu.c +819 -0
  90. data/ext/mtl_linux/src/simu/win/simuaudio.c +787 -0
  91. data/ext/mtl_linux/src/simu/win/simunet.c +489 -0
  92. data/ext/mtl_linux/src/vcomp/bootstrap.cpp +95 -0
  93. data/ext/mtl_linux/src/vcomp/compiler.cpp +587 -0
  94. data/ext/mtl_linux/src/vcomp/compiler_file.cpp +1253 -0
  95. data/ext/mtl_linux/src/vcomp/compiler_prog.cpp +437 -0
  96. data/ext/mtl_linux/src/vcomp/compiler_term.cpp +1500 -0
  97. data/ext/mtl_linux/src/vcomp/compiler_type.cpp +1238 -0
  98. data/ext/mtl_linux/src/vcomp/compiler_var.cpp +502 -0
  99. data/ext/mtl_linux/src/vcomp/file.cpp +100 -0
  100. data/ext/mtl_linux/src/vcomp/interpreter.cpp +93 -0
  101. data/ext/mtl_linux/src/vcomp/memory.cpp +313 -0
  102. data/ext/mtl_linux/src/vcomp/parser.cpp +584 -0
  103. data/ext/mtl_linux/src/vcomp/parser_xml.cpp +137 -0
  104. data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/prodbuffer.cpp +57 -36
  105. data/ext/mtl_linux/src/vcomp/stdlib_core.cpp +130 -0
  106. data/ext/mtl_linux/src/vcomp/terminal.cpp +80 -0
  107. data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/util.cpp +18 -11
  108. data/ext/mtl_linux/src/vm/vaudio.c +830 -0
  109. data/ext/mtl_linux/src/vm/vinterp.c +1780 -0
  110. data/ext/mtl_linux/src/vm/vloader.c +139 -0
  111. data/ext/mtl_linux/src/vm/vlog.c +782 -0
  112. data/ext/mtl_linux/src/vm/vmem.c +461 -0
  113. data/ext/mtl_linux/src/vm/vnet.c +298 -0
  114. data/{bytecode/src/mtl → ext/mtl_linux}/utils/correct_const.sh +0 -0
  115. data/lib/nabaztag_hack_kit/server.rb +4 -7
  116. data/lib/nabaztag_hack_kit/version.rb +1 -1
  117. data/lib/nabaztag_hack_kit.rb +2 -2
  118. data/nabaztag_hack_kit.gemspec +10 -11
  119. data/spec/integration/server_spec.rb +3 -3
  120. data/spec/spec_helper.rb +2 -0
  121. data/spec/unit/message_spec.rb +12 -18
  122. data/spec/unit/server_spec.rb +13 -10
  123. metadata +145 -137
  124. data/bytecode/bin/mtl_comp +0 -50
  125. data/bytecode/bin/mtl_simu +0 -49
  126. data/bytecode/src/mtl/Makefile +0 -42
  127. data/bytecode/src/mtl/README.md +0 -13
  128. data/bytecode/src/mtl/bc.cpp +0 -1891
  129. data/bytecode/src/mtl/dumpbc.c +0 -2566
  130. data/bytecode/src/mtl/linux_simu.c +0 -271
  131. data/bytecode/src/mtl/linux_simuaudio.c +0 -16
  132. data/bytecode/src/mtl/linux_simunet.c +0 -620
  133. data/bytecode/src/mtl/log.c +0 -297
  134. data/bytecode/src/mtl/log.h +0 -20
  135. data/bytecode/src/mtl/main_compiler.cpp +0 -104
  136. data/bytecode/src/mtl/main_simu.cpp +0 -221
  137. data/bytecode/src/mtl/mp3/common.c +0 -265
  138. data/bytecode/src/mtl/mp3/dct64_i386.c +0 -316
  139. data/bytecode/src/mtl/mp3/decode_i386.c +0 -155
  140. data/bytecode/src/mtl/mp3/huffman.h +0 -332
  141. data/bytecode/src/mtl/mp3/interface.c +0 -258
  142. data/bytecode/src/mtl/mp3/mpglib.h +0 -44
  143. data/bytecode/src/mtl/properties.c +0 -293
  144. data/bytecode/src/mtl/simu.c +0 -750
  145. data/bytecode/src/mtl/simuaudio.c +0 -662
  146. data/bytecode/src/mtl/simunet.c +0 -400
  147. data/bytecode/src/mtl/vaudio.c +0 -677
  148. data/bytecode/src/mtl/vbc_str.h +0 -166
  149. data/bytecode/src/mtl/vcomp/Makefile +0 -29
  150. data/bytecode/src/mtl/vcomp/bootstrap.cpp +0 -89
  151. data/bytecode/src/mtl/vcomp/compiler.cpp +0 -470
  152. data/bytecode/src/mtl/vcomp/compiler.h +0 -200
  153. data/bytecode/src/mtl/vcomp/compiler_file.cpp +0 -929
  154. data/bytecode/src/mtl/vcomp/compiler_prog.cpp +0 -250
  155. data/bytecode/src/mtl/vcomp/compiler_term.cpp +0 -1053
  156. data/bytecode/src/mtl/vcomp/compiler_type.cpp +0 -872
  157. data/bytecode/src/mtl/vcomp/compiler_var.cpp +0 -289
  158. data/bytecode/src/mtl/vcomp/file.cpp +0 -79
  159. data/bytecode/src/mtl/vcomp/interpreter.cpp +0 -85
  160. data/bytecode/src/mtl/vcomp/interpreter.h +0 -121
  161. data/bytecode/src/mtl/vcomp/memory.cpp +0 -241
  162. data/bytecode/src/mtl/vcomp/parser.cpp +0 -427
  163. data/bytecode/src/mtl/vcomp/parser_xml.cpp +0 -124
  164. data/bytecode/src/mtl/vcomp/prodbuffer.h +0 -42
  165. data/bytecode/src/mtl/vcomp/stdlib_core.cpp +0 -122
  166. data/bytecode/src/mtl/vcomp/terminal.cpp +0 -73
  167. data/bytecode/src/mtl/vinterp.c +0 -1349
  168. data/bytecode/src/mtl/vloader.c +0 -127
  169. data/bytecode/src/mtl/vlog.c +0 -589
  170. data/bytecode/src/mtl/vmem.c +0 -424
  171. data/bytecode/src/mtl/vnet.c +0 -255
  172. data/examples/basic/Procfile +0 -2
  173. data/examples/basic/server.rb +0 -14
@@ -0,0 +1,298 @@
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)
38
+ {
39
+ return -1;
40
+ }
41
+ if (indexsrc+lentosend>lensrc)
42
+ {
43
+ lentosend=lensrc-indexsrc;
44
+ }
45
+ if (lentosend<=0)
46
+ {
47
+ return -1;
48
+ }
49
+ if (inddst<0)
50
+ {
51
+ return -1;
52
+ }
53
+ if (inddst+6>lendst)
54
+ {
55
+ return -1;
56
+ }
57
+ return rt2501_send((const unsigned char *)(src+indexsrc),lentosend,(const unsigned char *)(macdst+inddst),speed,1);
58
+ #endif
59
+ }
60
+
61
+ int netCb(char* src,int lensrc,char* macsrc)
62
+ {
63
+ VPUSH(PNTTOVAL(VMALLOCSTR(src,lensrc)));
64
+ VPUSH(PNTTOVAL(VMALLOCSTR(macsrc,6)));
65
+ VPUSH(VCALLSTACKGET(sys_start,SYS_CBTCP));
66
+ if (VSTACKGET(0)!=NIL)
67
+ {
68
+ interpGo();
69
+ }
70
+ else
71
+ {
72
+ VPULL();
73
+ VPULL();
74
+ }
75
+ VPULL();
76
+ return 0;
77
+ }
78
+
79
+ extern unsigned char rt2501_mac[6];
80
+
81
+ #ifdef VSIMU
82
+ int htoi2(char* src)
83
+ {
84
+ char buf[3];
85
+ buf[0]=src[0];
86
+ buf[1]=src[1];
87
+ buf[2]=0;
88
+ return sysHtoi(buf);
89
+ }
90
+ #endif
91
+
92
+ char mac[6];
93
+
94
+ char* netMac()
95
+ {
96
+ #ifdef VSIMU
97
+ int i;
98
+ char *p=PropGet("MAC");
99
+ for(i=0; i<6; i++)
100
+ {
101
+ mac[i]=htoi2(&p[i*2]);
102
+ }
103
+ return mac;
104
+ // return "abcdef";
105
+ #endif
106
+ #ifdef VREAL
107
+ return (char*) rt2501_mac;
108
+ #endif
109
+ }
110
+
111
+ int netChk(char* src,int indexsrc,int lentosend,int lensrc,unsigned int val)
112
+ {
113
+ unsigned short* p;
114
+
115
+ if (indexsrc<0)
116
+ {
117
+ return val;
118
+ }
119
+ if (indexsrc+lentosend>lensrc)
120
+ {
121
+ lentosend=lensrc-indexsrc;
122
+ }
123
+ if (lentosend<=0)
124
+ {
125
+ return val;
126
+ }
127
+
128
+ src+=indexsrc;
129
+ p=(unsigned short*)src;
130
+
131
+ val=((val<<8)&0xff00)+((val>>8)&0xff);
132
+ while(lentosend>1)
133
+ {
134
+ val+=*(p++);
135
+ lentosend-=2;
136
+ }
137
+ if (lentosend)
138
+ {
139
+ val+=*(unsigned char*)p;
140
+ }
141
+
142
+ val=(val>>16)+(val&0xffff);
143
+ val=(val>>16)+(val&0xffff);
144
+ val=((val<<8)&0xff00)+((val>>8)&0xff);
145
+ return val;
146
+ }
147
+
148
+ void netSetmode(int mode,char* ssid,int chn)
149
+ {
150
+ #ifdef VSIMU
151
+ my_printf(LOG_SIMUNET, "xxxx netSetmode %d %s %d\n",mode,ssid,chn);
152
+ netstatesimu=(mode)?5:4;
153
+ #endif
154
+ #ifdef VREAL
155
+ rt2501_setmode(mode,ssid,chn);
156
+ #endif
157
+ }
158
+
159
+
160
+ int nscan;
161
+ #ifdef VREAL
162
+ void netScan_(struct rt2501_scan_result *scan_result, void *userparam)
163
+ {
164
+ char buf[256];
165
+ sprintf(buf,">>> %s %d %d %d %d\n",scan_result->ssid,scan_result->rssi,scan_result->channel,scan_result->rateset,scan_result->encryption);
166
+ consolestr((UBYTE*)buf);
167
+ VPUSH(PNTTOVAL(VMALLOCSTR(scan_result->ssid,strlen(scan_result->ssid))));
168
+ VPUSH(PNTTOVAL(VMALLOCSTR((char*)scan_result->mac,6)));
169
+ VPUSH(PNTTOVAL(VMALLOCSTR((char*)scan_result->bssid,6)));
170
+ VPUSH(INTTOVAL(scan_result->rssi));
171
+ VPUSH(INTTOVAL(scan_result->channel));
172
+ VPUSH(INTTOVAL(scan_result->rateset));
173
+ VPUSH(INTTOVAL(scan_result->encryption));
174
+ VMKTAB(7);
175
+ nscan++;
176
+ }
177
+ #endif
178
+
179
+ void netScan(char* ssid)
180
+ {
181
+ nscan=0;
182
+ #ifdef VSIMU
183
+ VPUSH(PNTTOVAL(VMALLOCSTR("foo",3)));
184
+ VPUSH(PNTTOVAL(VMALLOCSTR("xyzxyz",6)));
185
+ VPUSH(PNTTOVAL(VMALLOCSTR("765432",6)));
186
+ VPUSH(INTTOVAL(-20));
187
+ VPUSH(INTTOVAL(11));
188
+ VPUSH(INTTOVAL(1));
189
+ VPUSH(INTTOVAL(0));
190
+ VMKTAB(7);
191
+ nscan++;
192
+ VPUSH(PNTTOVAL(VMALLOCSTR("foo",3)));
193
+ VPUSH(PNTTOVAL(VMALLOCSTR("xyzxyz",6)));
194
+ VPUSH(PNTTOVAL(VMALLOCSTR("765432",6)));
195
+ VPUSH(INTTOVAL(-10));
196
+ VPUSH(INTTOVAL(11));
197
+ VPUSH(INTTOVAL(1));
198
+ VPUSH(INTTOVAL(0));
199
+ VMKTAB(7);
200
+ nscan++;
201
+ VPUSH(PNTTOVAL(VMALLOCSTR("zzzz",3)));
202
+ VPUSH(PNTTOVAL(VMALLOCSTR("xyzxyz",6)));
203
+ VPUSH(PNTTOVAL(VMALLOCSTR("765432",6)));
204
+ VPUSH(INTTOVAL(-10));
205
+ VPUSH(INTTOVAL(11));
206
+ VPUSH(INTTOVAL(1));
207
+ VPUSH(INTTOVAL(0));
208
+ VMKTAB(7);
209
+ nscan++;
210
+ VPUSH(PNTTOVAL(VMALLOCSTR("",3)));
211
+ VPUSH(PNTTOVAL(VMALLOCSTR("xyzxyz",6)));
212
+ VPUSH(PNTTOVAL(VMALLOCSTR("765432",6)));
213
+ VPUSH(INTTOVAL(-10));
214
+ VPUSH(INTTOVAL(11));
215
+ VPUSH(INTTOVAL(1));
216
+ VPUSH(INTTOVAL(0));
217
+ VMKTAB(7);
218
+ nscan++;
219
+ VPUSH(PNTTOVAL(VMALLOCSTR("a\"a<a'a a\\a",strlen("a\"a<a'a a\\a"))));
220
+ VPUSH(PNTTOVAL(VMALLOCSTR("xyzxyz",6)));
221
+ VPUSH(PNTTOVAL(VMALLOCSTR("765432",6)));
222
+ VPUSH(INTTOVAL(-10));
223
+ VPUSH(INTTOVAL(11));
224
+ VPUSH(INTTOVAL(1));
225
+ VPUSH(INTTOVAL(3));
226
+ VMKTAB(7);
227
+ nscan++;
228
+ VPUSH(PNTTOVAL(VMALLOCSTR("foo",3)));
229
+ VPUSH(PNTTOVAL(VMALLOCSTR("xyzxyz",6)));
230
+ VPUSH(PNTTOVAL(VMALLOCSTR("765432",6)));
231
+ VPUSH(INTTOVAL(-30));
232
+ VPUSH(INTTOVAL(11));
233
+ VPUSH(INTTOVAL(1));
234
+ VPUSH(INTTOVAL(0));
235
+ VMKTAB(7);
236
+ nscan++;
237
+ #endif
238
+ #ifdef VREAL
239
+ rt2501_scan(ssid, netScan_, NULL);
240
+ #endif
241
+ VPUSH(NIL);
242
+ while(nscan--)
243
+ {
244
+ VMKTAB(2);
245
+ }
246
+ }
247
+
248
+ void netAuth(char* ssid,char* mac,char* bssid,int chn,int rate,int authmode,int encrypt,char* key)
249
+ {
250
+ #ifdef VSIMU
251
+ my_printf(LOG_SIMUNET, "xxxx netAuth %s %d %d %d %d\n",ssid,chn,rate,authmode,encrypt);
252
+ netstatesimu=4;
253
+ #endif
254
+ #ifdef VREAL
255
+ rt2501_auth((const char*)ssid,(const unsigned char*)mac,(const unsigned char*)bssid,chn,rate,authmode,encrypt,(const unsigned char*)key);
256
+ #endif
257
+ }
258
+
259
+ void netSeqAdd(unsigned char* seq,int n)
260
+ {
261
+ unsigned char res[4];
262
+ unsigned int val;
263
+ val=(seq[0]<<24)+(seq[1]<<16)+(seq[2]<<8)+seq[3];
264
+ val+=n;
265
+ res[3]=val;
266
+ val>>=8;
267
+ res[2]=val;
268
+ val>>=8;
269
+ res[1]=val;
270
+ val>>=8;
271
+ res[0]=val;
272
+ VPUSH(PNTTOVAL(VMALLOCSTR((char*)res,4)));
273
+ }
274
+
275
+ void mypassword_to_pmk(const char *password, char *ssid, int ssidlength, unsigned char *pmk);
276
+
277
+ void netPmk(char* ssid,char* key,char* buf)
278
+ {
279
+ #ifdef VSIMU
280
+ my_printf(LOG_SIMUNET, "xxxx netPmk %s %s\n",ssid,key);
281
+ strcpy(buf,"01234567012345670123456701234567");
282
+ #endif
283
+ #ifdef VREAL
284
+ // strcpy(buf,"01234567012345670123456701234567");
285
+ mypassword_to_pmk(key,ssid,strlen(ssid), (unsigned char*)buf);
286
+ #endif
287
+ }
288
+
289
+ int netRssi()
290
+ {
291
+ #ifdef VSIMU
292
+ return -20;
293
+ #endif
294
+ #ifdef VREAL
295
+ return rt2501_rssi_average();
296
+ #endif
297
+ }
298
+
@@ -12,16 +12,13 @@ module NabaztagHackKit
12
12
  def initialize(opts = {})
13
13
  super
14
14
  @base_file = opts.fetch(:base_file, __FILE__)
15
- @bytecode_file = opts.fetch(:bytecode_file, public_file('bytecode.bin'))
15
+ @bytecode_file = opts.fetch(:bytecode_file, public_file('bytecode.bin')).to_s
16
+ abort("Couldn't find Bytecode file. Pls compile first") unless File.exists?(@bytecode_file)
17
+ puts "Serving Bytecode from #{@bytecode_file}"
16
18
  end
17
19
 
18
20
  get "/bc.jsp" do
19
- if File.exists?(@bytecode_file)
20
- logger.info "Serving Bytecode from #{@bytecode_file}"
21
- send_file @bytecode_file
22
- else
23
- status 404
24
- end
21
+ send_file @bytecode_file
25
22
  end
26
23
 
27
24
  get "/" do
@@ -1,3 +1,3 @@
1
1
  module NabaztagHackKit
2
- VERSION = "0.1.0.beta3"
2
+ VERSION = "0.1.0.beta8"
3
3
  end
@@ -1,4 +1,4 @@
1
- require "nabaztag_hack_kit/version"
1
+ require 'nabaztag_hack_kit/version'
2
2
 
3
3
  module NabaztagHackKit
4
- end
4
+ end
@@ -6,25 +6,24 @@ Gem::Specification.new do |s|
6
6
  s.name = "nabaztag_hack_kit"
7
7
  s.version = NabaztagHackKit::VERSION
8
8
  s.authors = ["RngTng - Tobias Bielohlawek"]
9
- s.email = ["tobi@soundcloud.com"]
10
- s.homepage = "https://github.com/rngtng/nabaztag_hack_kit"
9
+ s.email = ["tobi@rngtng.com"]
10
+ s.homepage = "https://github.com/rngtng/NabaztagHackKit"
11
11
  s.summary = %q{Sinatra server to run custom Nabaztag bytecode}
12
12
  s.description = %q{Sinatra server api framework to run custom bytecode on Nabaztag v1/v2. Sources + Compiler included (linux only)}
13
13
 
14
- s.files = `git ls-files`.split("\n")
14
+ s.files = `git ls-files --recurse-submodules`.split("\n")
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.extensions = ['bytecode/src/mtl/extconf.rb']
16
+ s.extensions = ['ext/extconf.rb']
17
17
 
18
- s.bindir = 'bytecode/bin'
18
+ s.bindir = 'ext/bin'
19
19
  s.executables = ['mtl_comp', 'mtl_simu', 'mtl_merge']
20
20
 
21
21
  s.require_paths = ["lib"]
22
22
 
23
- ["sinatra"].each do |gem|
24
- s.add_dependency *gem.split(' ')
25
- end
23
+ s.add_dependency 'sinatra', '>= 2.0'
24
+ s.add_dependency 'rack', '>= 2.0'
26
25
 
27
- ["rake", "rspec", "rack-test"].each do |gem|
28
- s.add_development_dependency *gem.split(' ')
29
- end
26
+ s.add_development_dependency 'rake', '>= 11.2'
27
+ s.add_development_dependency 'rspec', '>= 3.5'
28
+ s.add_development_dependency 'rack-test', '>= 0.6'
30
29
  end
@@ -6,14 +6,14 @@ require "rack/test"
6
6
  shared_examples_for :successful_route do
7
7
  it "returns 200" do
8
8
  get route
9
- last_response.should be_ok
9
+ expect(last_response).to be_ok
10
10
  end
11
11
  end
12
12
 
13
13
  shared_examples_for :notfound_route do
14
14
  it "returns 404" do
15
15
  get route
16
- last_response.status.should == 404
16
+ expect(last_response.status).to eq 404
17
17
  end
18
18
  end
19
19
 
@@ -53,7 +53,7 @@ describe NabaztagHackKit::Server do
53
53
 
54
54
  it "execute callback" do
55
55
  get route
56
- last_response.body.should == ""
56
+ expect(last_response.body).to eq ""
57
57
  end
58
58
  end
59
59
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require 'bundler/setup'
1
2
  require 'rspec'
2
3
 
4
+
3
5
  $: << File.expand_path("../../lib", __FILE__)
4
6
 
5
7
  require "nabaztag_hack_kit"
@@ -1,5 +1,4 @@
1
1
  require "spec_helper"
2
-
3
2
  require "nabaztag_hack_kit/message"
4
3
 
5
4
  describe NabaztagHackKit::Message do
@@ -9,58 +8,53 @@ describe NabaztagHackKit::Message do
9
8
  let(:size) { NabaztagHackKit::Message.to_3b(data.size) }
10
9
 
11
10
  before do
12
- NabaztagHackKit::Message.stub!(:full_message).and_return do |data|
13
- data
14
- end
15
-
16
- NabaztagHackKit::Message.stub!(:pack).and_return do |data|
17
- data
18
- end
11
+ allow(NabaztagHackKit::Message).to receive(:full_message) { |data| data }
12
+ allow(NabaztagHackKit::Message).to receive(:pack) { |data| data }
19
13
  end
20
14
 
21
15
  describe ".build" do
22
16
  it "accepts single input" do
23
- NabaztagHackKit::Message.build(*[["40"], ["40", "2", "3", "4"]]).should == [[40, 0, 0, 0], [40, 0, 0, 1, 50]]
17
+ expect(NabaztagHackKit::Message.build(*[["40"], ["40", "2", "3", "4"]])).to eq [[40, 0, 0, 0], [40, 0, 0, 1, 50]]
24
18
  end
25
19
 
26
20
  it "accepts single input" do
27
- NabaztagHackKit::Message.build(CMD).should == [[CMD, 0, 0, 0]]
21
+ expect(NabaztagHackKit::Message.build(CMD)).to eq [[CMD, 0, 0, 0]]
28
22
  end
29
23
 
30
24
  it "accepts flat input" do
31
- NabaztagHackKit::Message.build(CMD, *data).should == [[CMD, *size, *data]]
25
+ expect(NabaztagHackKit::Message.build(CMD, *data)).to eq [[CMD, *size, *data]]
32
26
  end
33
27
 
34
28
  it "accepts array input" do
35
- NabaztagHackKit::Message.build([CMD, *data]).should == [[CMD, *size, *data]]
29
+ expect(NabaztagHackKit::Message.build([CMD, *data])).to eq [[CMD, *size, *data]]
36
30
  end
37
31
 
38
32
  it "accepts multiple array input" do
39
- NabaztagHackKit::Message.build([CMD, *data], [CMD1, *data]).should == [[CMD, *size, *data], [CMD1, *size, *data]]
33
+ expect(NabaztagHackKit::Message.build([CMD, *data], [CMD1, *data])).to eq [[CMD, *size, *data], [CMD1, *size, *data]]
40
34
  end
41
35
 
42
36
  it "accepts hash input" do
43
- NabaztagHackKit::Message.build(CMD => data, CMD1 => data).should == [[CMD, *size, *data], [CMD1, *size, *data]]
37
+ expect(NabaztagHackKit::Message.build(CMD => data, CMD1 => data)).to eq [[CMD, *size, *data], [CMD1, *size, *data]]
44
38
  end
45
39
 
46
40
  context "as string" do
47
41
  it "accepts hash input" do
48
- NabaztagHackKit::Message.build(CMD.to_s => data.map(&:to_s), CMD1.to_s => data).should == [[CMD, *size, *data], [CMD1, *size, *data]]
42
+ expect(NabaztagHackKit::Message.build(CMD.to_s => data.map(&:to_s), CMD1.to_s => data)).to eq [[CMD, *size, *data], [CMD1, *size, *data]]
49
43
  end
50
44
  end
51
45
  end
52
46
 
53
47
  describe ".to_3b" do
54
48
  it "accepts zero" do
55
- NabaztagHackKit::Message.to_3b(0).should == [0, 0, 0]
49
+ expect(NabaztagHackKit::Message.to_3b(0)).to eq [0, 0, 0]
56
50
  end
57
51
 
58
52
  it "accepts 2 byte input" do
59
- NabaztagHackKit::Message.to_3b(511).should == [0, 1, 255]
53
+ expect(NabaztagHackKit::Message.to_3b(511)).to eq [0, 1, 255]
60
54
  end
61
55
 
62
56
  it "accepts 3 byte input" do
63
- NabaztagHackKit::Message.to_3b(6334239).should == [96, 167, 31]
57
+ expect(NabaztagHackKit::Message.to_3b(6334239)).to eq [96, 167, 31]
64
58
  end
65
59
  end
66
60
  end
@@ -14,27 +14,30 @@ describe NabaztagHackKit::Server do
14
14
  })
15
15
  end
16
16
 
17
- it "reads from public/bytecode.bin" do
18
- pending
19
- app.should_receive(:send_file).with("public/bytecode.bin")
20
- do_action '/bc.jsp'
17
+ xit "reads from public/bytecode.bin" do
18
+ expect(app).to_receive(:send_file).with("public/bytecode.bin")
19
+ begin
20
+ do_action '/bc.jsp'
21
+ rescue SystemExit
22
+ end
21
23
  end
22
24
 
23
25
  context "with custom bin code route" do
24
26
  let(:app) { NabaztagHackKit::Server.new(custom_route) }
25
27
  let(:custom_route) { "bytecode.bin" }
26
28
 
27
- it "reads from" do
28
- pending
29
- app.should_receive(:send_file).with(custom_route)
30
- do_action '/bc.jsp'
29
+ xit "reads from" do
30
+ expect(app).to_receive(:send_file).with(custom_route)
31
+ begin
32
+ do_action '/bc.jsp'
33
+ rescue SystemExit
34
+ end
31
35
  end
32
36
  end
33
37
  end
34
38
 
35
39
  describe "#on" do
36
- it "accepts" do
37
- pending
40
+ xit "accepts" do
38
41
  end
39
42
  end
40
43
  end