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
@@ -0,0 +1,74 @@
1
+ fun setleds col= for i=0;i<5 do led i col;;
2
+
3
+ // --------------- UTIL
4
+ fun strstr s p i=strfind s i p 0 nil;;
5
+ fun listlen l=if l==nil then 0 else 1+listlen tl l;;
6
+ fun listrem l x=if l!=nil then if x==hd l then tl l else (hd l)::listrem tl l x;;
7
+
8
+ fun listtostr l=
9
+ let strnew listlen l -> s in
10
+ let 0->i in
11
+ (
12
+ for p=l;p!=nil;tl p do
13
+ (
14
+ strset s i hd p;
15
+ set i=i+1
16
+ );
17
+ s
18
+ );;
19
+
20
+
21
+ fun countpattern s p i=
22
+ let strstr s p i -> j in
23
+ if j==nil then 0
24
+ else 1+countpattern s p j+strlen p;;
25
+
26
+ fun strreplace2 sn s p v i id=
27
+ if i<strlen s then
28
+ let strstr s p i -> j in
29
+ let if j==nil then strlen s else j -> k in
30
+ (
31
+ strcpy sn id s i k-i;
32
+ if j!=nil then strcpy sn id+k-i v 0 nil;
33
+ strreplace2 sn s p v k+strlen p id+k-i+strlen v
34
+ );;
35
+
36
+ fun strreplace s p v=
37
+ let countpattern s p 0 -> i in
38
+ if !i then s
39
+ else let strnew (strlen s) + ((strlen v)-(strlen p))*i -> sn in
40
+ (
41
+ strreplace2 sn s p v 0 0;
42
+ sn
43
+ );;
44
+
45
+ fun rev p q=if p==nil then q else rev tl p (hd p)::q;;
46
+
47
+ // remfromlist same as listrem!!!
48
+ fun remfromlist l t= if l!=nil then if t==hd l then tl l else (hd l)::remfromlist tl l t;;
49
+
50
+ fun insert x l f=
51
+ if l==nil then x::nil
52
+ else let call f [x hd l] -> r in
53
+ if r>0 then (hd l)::insert x tl l f
54
+ else if r<0 then x::l
55
+ else insert x tl l f;;
56
+
57
+ fun sort l f= if l!=nil then insert hd l sort tl l f f;;
58
+
59
+ fun select l a f= if l!=nil then let hd l-> x in if call f [x a] then x::select tl l a f else select tl l a f;;
60
+
61
+ fun _useparamip s i val j=
62
+ if i<4 then
63
+ let strstr val "." j -> k in
64
+ (
65
+ strset s i atoi strsub val j if k==nil then nil else k-j;
66
+ _useparamip s i+1 val if k==nil then strlen val else k+1
67
+ );;
68
+
69
+ fun useparamip val=
70
+ let strnew 4 -> ip in
71
+ (
72
+ _useparamip ip 0 val 0;
73
+ ip
74
+ );;
@@ -0,0 +1,15 @@
1
+ var http_prefurl="http://";;
2
+
3
+ const HTTP_NORMAL=0;;
4
+ const HTTP_STREAM=1;;
5
+ const HTTP_DIRECT=2;;
6
+
7
+ const HTTP_SOLVE=0;;
8
+ const HTTP_REACH=1;;
9
+ const HTTP_CONNECTED=2;;
10
+
11
+ var lasthttpevent;;
12
+
13
+ type Httpreq=[cnxH inputH outputH indexH cbH typeH stateH aliveH];;
14
+
15
+ const DNSLOCAL=1597;;
@@ -0,0 +1,243 @@
1
+ // ------------- Wifi
2
+
3
+ type Wifi=initW | gomasterW | masterW | gostationW _ | dhcpW _| stationW | reconnectW;;
4
+ var wifi;;
5
+ var wifitry;;
6
+ var wifiscans;;
7
+
8
+ const RT2501_S_BROKEN=0;;
9
+ const RT2501_S_IDLE=1;;
10
+ const RT2501_S_SCAN=2;;
11
+ const RT2501_S_CONNECTING=3;;
12
+ const RT2501_S_CONNECTED=4;;
13
+ const RT2501_S_MASTER=5;;
14
+
15
+ const IEEE80211_CRYPT_NONE=0;;
16
+ const IEEE80211_CRYPT_WEP64=1;;
17
+ const IEEE80211_CRYPT_WEP128=2;;
18
+ const IEEE80211_CRYPT_WPA=3;;
19
+ const IEEE80211_CRYPT_WPA_UNSUPPORTED=4;;
20
+
21
+ const IEEE80211_M_MANAGED=0;;
22
+ const IEEE80211_M_MASTER=1;;
23
+
24
+ const IEEE80211_AUTH_OPEN=0;;
25
+ const IEEE80211_AUTH_SHARED=1;;
26
+
27
+ fun _scanserialize l=
28
+ if l!=nil then
29
+ let hd l->[ssid mac bssid rssi channel rateset encryption] in
30
+ ssid::"\0"::mac::bssid::(itoh4 rssi)::(itoh4 channel)::(itoh4 rateset)::(itoh4 encryption)::
31
+ _scanserialize tl l;;
32
+
33
+ fun scanserialize l=
34
+ (itoh4 listlen l)::_scanserialize l;;
35
+
36
+
37
+ fun ssidlen s i=
38
+ if i>=strlen s then i
39
+ else if !strget s i then i
40
+ else ssidlen s i+1;;
41
+
42
+ fun scanunserialize s n i0=
43
+ if n>0 then
44
+ let ssidlen s i0 -> j in
45
+ let j+1->i in
46
+ [
47
+ strsub s i0 j-i0
48
+ strsub s i 6
49
+ strsub s i+6 6
50
+ htoi strsub s i+12 8
51
+ htoi strsub s i+20 8
52
+ htoi strsub s i+28 8
53
+ htoi strsub s i+36 8
54
+ ]::scanunserialize s n-1 i+44;;
55
+
56
+
57
+ fun envmake =
58
+ strcatlist netip::netmask::netgateway::netdns::scanserialize wifiscans;;
59
+
60
+ fun envrestore s =
61
+ if s!=nil then
62
+ (
63
+ set netip=strsub s 0 4;
64
+ set netmask=strsub s 4 4;
65
+ set netgateway=strsub s 8 4;
66
+ set netdns=strsub s 12 4;
67
+ let htoi strsub s 16 8 -> nscan in
68
+ set wifiscans=scanunserialize s nscan 24;
69
+ 0
70
+ );;
71
+
72
+ fun scancmpssid a b=
73
+ let a->[sa _ _ _ _ _ _] in
74
+ let b->[sb _ _ _ _ _ _] in
75
+ strcmp sa sb;;
76
+
77
+
78
+ fun wifiInit rescan=
79
+ set wifitry=nil;
80
+ let envget -> env in
81
+ if env==nil then
82
+ (
83
+ setleds 0xff00ff;
84
+ set wifi=initW;
85
+ if rescan then set wifiscans=nil;
86
+ if confGetDhcp then set netip=netip_empty
87
+ else
88
+ (
89
+ set netmask=confGetNetmask;
90
+ set netgateway=confGetNetgateway;
91
+ set netdns=confGetNetdns;
92
+ set netip=confGetNetip
93
+ );
94
+ 0
95
+ )
96
+ else
97
+ (
98
+ setleds 0x00ff00;
99
+ set mymac=netMac;
100
+ set wifi=stationW;
101
+ envrestore env;
102
+ envset nil;
103
+ nil
104
+ );
105
+ 0;;
106
+
107
+ var laststate;;
108
+
109
+ fun wifibyssid x v=let x->[s _ _ _ _ _ _] in (s!=nil)&& !strcmp v s;;
110
+
111
+
112
+ var retrytime;;
113
+
114
+ fun _wifiwepkey val i len=
115
+ if i<len then
116
+ (htoi strsub val i 2)::_wifiwepkey val i+2 len;;
117
+
118
+ fun wifiwepkey val=
119
+ let strlen val -> len in
120
+ if len==5 || len==13 then val
121
+ else let strreplace val ":" "" -> val in
122
+ let if len<10 then 0 else if len<26 then 5 else 13 -> len in
123
+ listtostr _wifiwepkey val 0 len<<1;;
124
+
125
+ fun wificrypttype crypt key=
126
+ if crypt==1 then if 5==strlen key then IEEE80211_CRYPT_WEP64 else IEEE80211_CRYPT_WEP128
127
+ else if crypt==2 then IEEE80211_CRYPT_WPA
128
+ else IEEE80211_CRYPT_NONE;;
129
+
130
+ fun wifiAuth=
131
+ setleds 0xff8000;
132
+ if wifiscans==nil then 0
133
+ else
134
+ let Iecholn confGetWificrypt -> crypt in
135
+ let confGetWifiauth -> auth in
136
+ let if crypt==1 then wifiwepkey confGetWifikey0
137
+ else if crypt==2 then confGetWifipmk -> key in
138
+ (
139
+ dump key;
140
+ set wifitry=time;
141
+ netAuth hd wifiscans Iecholn auth (Iecholn wificrypttype crypt key) key; //## ajouter les paramètres de crypto
142
+ 1
143
+ );;
144
+
145
+ var master=0;;
146
+
147
+ fun wifiRun=
148
+ let netState -> state in
149
+ (
150
+ if state!=laststate then (Secho "wifi state=";Iecholn state);
151
+ let match wifi with
152
+ (stationW -> nil)
153
+ |(initW -> if state==RT2501_S_IDLE then
154
+ (
155
+ set mymac=MACecho netMac 0 1;
156
+ setleds 0xff8000;
157
+ if wifiscans==nil then
158
+ (
159
+ let confGetWifissid -> ssid in
160
+ let if strlen ssid then ssid else nil -> ssid in
161
+ let netScan ssid -> lscan in
162
+ let sort lscan #scancmpssid -> l in
163
+ let if ssid==nil then l else select l ssid #wifibyssid-> l in
164
+ dumpscan set wifiscans=l
165
+ );
166
+ if wifiAuth then
167
+ (
168
+ Secho confGetWifissid; Secholn ":-------------gostation";
169
+ gostationW [0 time]
170
+ )
171
+ )
172
+ )
173
+ |(gomasterW -> if state==RT2501_S_MASTER then
174
+ (
175
+ setleds 0x0000ff;
176
+ Secholn "-------------master";
177
+ startdhcpserver;
178
+ // startconfigserver 80;
179
+ masterW)
180
+ )
181
+ |(masterW -> if !master then
182
+ (
183
+ wifiInit 1;
184
+ resetudp;
185
+ netSetmode IEEE80211_M_MANAGED nil 11;
186
+ nil)
187
+ )
188
+ |(gostationW x-> if state==RT2501_S_CONNECTED then
189
+ (
190
+ Secholn "-------------dhcp";
191
+ if confGetDhcp then startdhcp;
192
+ startdnsclient;
193
+ dhcpW time
194
+ )
195
+ )
196
+ |(dhcpW t-> if netip!=netip_empty then
197
+ (
198
+ Secholn "-------------station";
199
+ stationW
200
+ )
201
+ else if (time-t)>3 then // retry dhcp client
202
+ (
203
+ startdhcp;
204
+ dhcpW time
205
+ )
206
+ )
207
+ |(reconnectW ->
208
+ netSetmode IEEE80211_M_MANAGED nil 11;
209
+ if wifiAuth then
210
+ (
211
+ Secho confGetWifissid; Secholn ":-------------gostation";
212
+ gostationW [0 time]
213
+ )
214
+ )
215
+ -> nwifi in
216
+ if nwifi!=nil then set wifi=nwifi;
217
+ set laststate=state
218
+ );
219
+ if retrytime!=time then
220
+ (
221
+ set retrytime=time;
222
+ nettime;
223
+ dnstime;
224
+ 0
225
+ )
226
+ ;;
227
+
228
+ fun wifiReady= match wifi with (stationW -> 1)|(_ -> 0);;
229
+
230
+ fun wifiConnected= match wifi with (stationW -> 1)|(_ -> 0);;
231
+
232
+ fun wifiCheck=
233
+ if (netState == RT2501_S_IDLE) then
234
+ match wifi with
235
+ (initW -> nil)
236
+ |(_ ->
237
+ Secholn "######### wifi lost";
238
+ set wifi=reconnectW;
239
+ 0
240
+ )
241
+ ;;
242
+
243
+