nabaztag_hack_kit 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +7 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +4 -0
- data/README.md +119 -0
- data/Rakefile +21 -0
- data/bin/mtl_comp +41 -0
- data/bin/mtl_merge +22 -0
- data/bin/mtl_simu +40 -0
- data/bytecode/lib/buffer.mtl +109 -0
- data/bytecode/lib/button.mtl +27 -0
- data/bytecode/lib/data_helper.mtl +88 -0
- data/bytecode/lib/ear.mtl +90 -0
- data/bytecode/lib/led.mtl +33 -0
- data/bytecode/lib/rfid.mtl +50 -0
- data/bytecode/main.mtl +129 -0
- data/config.ru +6 -0
- data/ext/bytecode/Commands.md +172 -0
- data/ext/bytecode/Docs.md +488 -0
- data/ext/bytecode/README.md +5 -0
- data/ext/bytecode/lib/arp.mtl +159 -0
- data/ext/bytecode/lib/cfg.mtl +74 -0
- data/ext/bytecode/lib/choreos.mtl +1487 -0
- data/ext/bytecode/lib/dhcp.mtl +152 -0
- data/ext/bytecode/lib/dns.mtl +89 -0
- data/ext/bytecode/lib/http.mtl +84 -0
- data/ext/bytecode/lib/tcp.mtl +340 -0
- data/ext/bytecode/lib/udp.mtl +49 -0
- data/ext/bytecode/lib/util.mtl +74 -0
- data/ext/bytecode/lib/var.mtl +15 -0
- data/ext/bytecode/lib/wifi.mtl +243 -0
- data/ext/bytecode/nominal-ping.mtl +5828 -0
- data/ext/mtl/Makefile +42 -0
- data/ext/mtl/README.md +13 -0
- data/ext/mtl/bc.cpp +1891 -0
- data/ext/mtl/conf.bin.sans_password +0 -0
- data/ext/mtl/config.txt +5 -0
- data/ext/mtl/dumpbc.c +2566 -0
- data/ext/mtl/extconf.rb +1 -0
- data/ext/mtl/linux_simu.c +271 -0
- data/ext/mtl/linux_simuaudio.c +16 -0
- data/ext/mtl/linux_simuaudio.h +18 -0
- data/ext/mtl/linux_simunet.c +620 -0
- data/ext/mtl/linux_simunet.h +7 -0
- data/ext/mtl/log.c +297 -0
- data/ext/mtl/log.h +20 -0
- data/ext/mtl/main_compiler.cpp +104 -0
- data/ext/mtl/main_simu.cpp +221 -0
- data/ext/mtl/mp3/GTKANAL.H +97 -0
- data/ext/mtl/mp3/LAYER3.C +2090 -0
- data/ext/mtl/mp3/TABINIT.C +82 -0
- data/ext/mtl/mp3/common.c +265 -0
- data/ext/mtl/mp3/dct64_i386.c +316 -0
- data/ext/mtl/mp3/decode_i386.c +155 -0
- data/ext/mtl/mp3/huffman.h +332 -0
- data/ext/mtl/mp3/interface.c +258 -0
- data/ext/mtl/mp3/mpg123.h +182 -0
- data/ext/mtl/mp3/mpglib.h +44 -0
- data/ext/mtl/properties.c +293 -0
- data/ext/mtl/properties.h +10 -0
- data/ext/mtl/simu.c +750 -0
- data/ext/mtl/simuaudio.c +662 -0
- data/ext/mtl/simuaudio.h +74 -0
- data/ext/mtl/simunet.c +400 -0
- data/ext/mtl/simunet.h +30 -0
- data/ext/mtl/utils/correct_const.sh +34 -0
- data/ext/mtl/vaudio.c +677 -0
- data/ext/mtl/vaudio.h +46 -0
- data/ext/mtl/vbc.h +160 -0
- data/ext/mtl/vbc_str.h +166 -0
- data/ext/mtl/vcomp/Makefile +29 -0
- data/ext/mtl/vcomp/bootstrap.cpp +89 -0
- data/ext/mtl/vcomp/compiler.cpp +470 -0
- data/ext/mtl/vcomp/compiler.h +200 -0
- data/ext/mtl/vcomp/compiler_file.cpp +929 -0
- data/ext/mtl/vcomp/compiler_prog.cpp +250 -0
- data/ext/mtl/vcomp/compiler_term.cpp +1053 -0
- data/ext/mtl/vcomp/compiler_type.cpp +872 -0
- data/ext/mtl/vcomp/compiler_var.cpp +289 -0
- data/ext/mtl/vcomp/file.cpp +79 -0
- data/ext/mtl/vcomp/file.h +39 -0
- data/ext/mtl/vcomp/filesystem.h +14 -0
- data/ext/mtl/vcomp/interpreter.cpp +85 -0
- data/ext/mtl/vcomp/interpreter.h +121 -0
- data/ext/mtl/vcomp/memory.cpp +241 -0
- data/ext/mtl/vcomp/memory.h +326 -0
- data/ext/mtl/vcomp/param.h +95 -0
- data/ext/mtl/vcomp/parser.cpp +427 -0
- data/ext/mtl/vcomp/parser.h +97 -0
- data/ext/mtl/vcomp/parser_xml.cpp +124 -0
- data/ext/mtl/vcomp/prodbuffer.cpp +125 -0
- data/ext/mtl/vcomp/prodbuffer.h +42 -0
- data/ext/mtl/vcomp/resource.h +17 -0
- data/ext/mtl/vcomp/stdlib_core.cpp +122 -0
- data/ext/mtl/vcomp/terminal.cpp +73 -0
- data/ext/mtl/vcomp/terminal.h +30 -0
- data/ext/mtl/vcomp/util.cpp +48 -0
- data/ext/mtl/vcomp/util.h +31 -0
- data/ext/mtl/vinterp.c +1349 -0
- data/ext/mtl/vinterp.h +11 -0
- data/ext/mtl/vloader.c +127 -0
- data/ext/mtl/vloader.h +31 -0
- data/ext/mtl/vlog.c +589 -0
- data/ext/mtl/vlog.h +69 -0
- data/ext/mtl/vmem.c +424 -0
- data/ext/mtl/vmem.h +107 -0
- data/ext/mtl/vnet.c +255 -0
- data/ext/mtl/vnet.h +19 -0
- data/lib/nabaztag_hack_kit/message/api.rb +39 -0
- data/lib/nabaztag_hack_kit/message/helper.rb +39 -0
- data/lib/nabaztag_hack_kit/message.rb +36 -0
- data/lib/nabaztag_hack_kit/server.rb +50 -0
- data/lib/nabaztag_hack_kit/version.rb +3 -0
- data/lib/nabaztag_hack_kit.rb +4 -0
- data/nabaztag_hack_kit.gemspec +29 -0
- data/public/bytecode.bin +0 -0
- data/test/bytecode/helper.mtl +60 -0
- data/test/bytecode/native.mtl +28 -0
- data/test/bytecode/test.mtl +221 -0
- data/test/spec_helper.rb +5 -0
- data/test/unit/message_spec.rb +56 -0
- metadata +209 -0
data/ext/mtl/vlog.c
ADDED
@@ -0,0 +1,589 @@
|
|
1
|
+
// VLISP Virtual Machine - 2006 - by Sylvain Huet
|
2
|
+
// Lowcost IS Powerfull
|
3
|
+
|
4
|
+
#include <string.h>
|
5
|
+
|
6
|
+
#include"vmem.h"
|
7
|
+
#include"vloader.h"
|
8
|
+
#ifdef VSIMU
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include<stdio.h>
|
11
|
+
#include<time.h>
|
12
|
+
#include <sys/time.h>
|
13
|
+
#endif
|
14
|
+
#ifdef VREAL
|
15
|
+
#include "ML674061.h"
|
16
|
+
#include "common.h"
|
17
|
+
#include "irq.h"
|
18
|
+
#include "spi.h"
|
19
|
+
#include "led.h"
|
20
|
+
#include "mem.h"
|
21
|
+
#include "uart.h"
|
22
|
+
#include "debug.h"
|
23
|
+
#include "usbh.h"
|
24
|
+
|
25
|
+
#include "delay.h"
|
26
|
+
#include "audio.h"
|
27
|
+
#include "motor.h"
|
28
|
+
#include "usbctrl.h"
|
29
|
+
#include "ml60842.h"
|
30
|
+
#include "hcdmem.h"
|
31
|
+
#include "hcd.h"
|
32
|
+
#include "inarm.h"
|
33
|
+
#include "i2c.h"
|
34
|
+
#include "rt2501usb.h"
|
35
|
+
#include "mem.h"
|
36
|
+
#include<stdio.h>
|
37
|
+
#include<string.h>
|
38
|
+
|
39
|
+
#include"led.h"
|
40
|
+
#include"motor.h"
|
41
|
+
#include"delay.h"
|
42
|
+
#include"rfid.h"
|
43
|
+
#endif
|
44
|
+
#include"vlog.h"
|
45
|
+
|
46
|
+
void logSecho(int p,int nl)
|
47
|
+
{
|
48
|
+
if (p==NIL) consolestr("NIL");
|
49
|
+
else consolebin((unsigned char*)VSTARTBIN(VALTOPNT(p)),VSIZEBIN(VALTOPNT(p)));
|
50
|
+
if (nl) consolestr(ENDLINE);
|
51
|
+
}
|
52
|
+
|
53
|
+
void logIecho(int i,int nl)
|
54
|
+
{
|
55
|
+
if (i==NIL) consolestr("NIL");
|
56
|
+
else consoleint(VALTOINT(i));
|
57
|
+
if (nl) consolestr(ENDLINE);
|
58
|
+
}
|
59
|
+
|
60
|
+
extern int currentop;
|
61
|
+
void logGC()
|
62
|
+
{
|
63
|
+
consolestr("#GC : sp=");consoleint(-vmem_stack);
|
64
|
+
consolestr(" hp=");consoleint(vmem_heapindex);
|
65
|
+
consolestr(" used=");consoleint((vmem_heapindex-vmem_stack)*100/VMEM_LENGTH);
|
66
|
+
consolestr("%"ENDLINE);
|
67
|
+
consolestr(" b:");consolehx((int)vmem_heap);
|
68
|
+
consolestr(" bc:");consolehx((int)bytecode);
|
69
|
+
consolestr(" st:");consolehx(vmem_start);
|
70
|
+
consolestr(" op:");consolehx(currentop);
|
71
|
+
consolestr(ENDLINE);
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
// pour le firmware, le "fichier" ouvert est toujours l'eeprom
|
77
|
+
|
78
|
+
int sysLoad(char *dst,int i,int ldst,char *filename,int j,int len)
|
79
|
+
{
|
80
|
+
#ifdef VSIMU
|
81
|
+
FILE *f;
|
82
|
+
if ((j<0)||(i<0)||(len<=0)) return 0;
|
83
|
+
if (i+len>ldst) len=ldst-i;
|
84
|
+
if (len<=0) return 0;
|
85
|
+
f=fopen(filename,"rb");
|
86
|
+
if (!f) return 0;
|
87
|
+
fseek(f,j,SEEK_SET);
|
88
|
+
len=fread(dst,1,len,f);
|
89
|
+
fclose(f);
|
90
|
+
return len;
|
91
|
+
#endif
|
92
|
+
#ifdef VREAL
|
93
|
+
/* set_vlsi_volume(0); //volume on 8bits, 0x00 => maximum
|
94
|
+
encode_adpcm((UBYTE*)dst+i,(ldst-i-256)>>8, j);
|
95
|
+
return 0;
|
96
|
+
*/
|
97
|
+
if ((j<0)||(i<0)||(len<=0)) return 0;
|
98
|
+
if (i+len>ldst) len=ldst-i;
|
99
|
+
if (len<=0) return 0;
|
100
|
+
if (j+len>4096) len=4096-j;
|
101
|
+
if (len<=0) return 0;
|
102
|
+
read_uc_flash(j,(unsigned char*)dst,len);
|
103
|
+
return len;
|
104
|
+
#endif
|
105
|
+
}
|
106
|
+
|
107
|
+
uchar buffer_temp[4096];
|
108
|
+
|
109
|
+
// pour le firmware, le "fichier" ouvert est toujours l'eeprom
|
110
|
+
int sysSave(char *dst,int i,int ldst,char *filename,int j,int len)
|
111
|
+
{
|
112
|
+
#ifdef VSIMU
|
113
|
+
FILE *f;
|
114
|
+
if ((j<0)||(i<0)||(len<=0)) return 0;
|
115
|
+
if (i+len>ldst) len=ldst-i;
|
116
|
+
if (len<=0) return 0;
|
117
|
+
f=fopen(filename,"rb+");
|
118
|
+
if (!f) f=fopen(filename,"wb+");
|
119
|
+
if (!f) return 0;
|
120
|
+
fseek(f,j,SEEK_SET);
|
121
|
+
len=fwrite(dst,1,len,f);
|
122
|
+
fclose(f);
|
123
|
+
return len;
|
124
|
+
#endif
|
125
|
+
#ifdef VREAL
|
126
|
+
if ((j<0)||(i<0)||(len<=0)) return 0;
|
127
|
+
if (i+len>ldst) len=ldst-i;
|
128
|
+
if (len<=0) return 0;
|
129
|
+
if (j+len>4096) len=4096-j;
|
130
|
+
if (len<=0) return 0;
|
131
|
+
__disable_interrupt();
|
132
|
+
write_uc_flash(j,(unsigned char*)dst,len,buffer_temp);
|
133
|
+
__enable_interrupt();
|
134
|
+
return len;
|
135
|
+
#endif
|
136
|
+
}
|
137
|
+
|
138
|
+
static int firstTimeSet = 0;
|
139
|
+
static struct timeval firstTime;
|
140
|
+
|
141
|
+
int sysTimems()
|
142
|
+
{
|
143
|
+
#ifdef VSIMU
|
144
|
+
int res;
|
145
|
+
struct timeval tv;
|
146
|
+
if (firstTimeSet) {
|
147
|
+
gettimeofday(&tv, NULL);
|
148
|
+
res = (tv.tv_sec - firstTime.tv_sec) * 1000;
|
149
|
+
res += (tv.tv_usec - firstTime.tv_usec) / 1000;
|
150
|
+
} else {
|
151
|
+
gettimeofday(&firstTime, NULL);
|
152
|
+
firstTimeSet = 1;
|
153
|
+
res = 0;
|
154
|
+
}
|
155
|
+
return res;
|
156
|
+
#endif // ! VSIMU
|
157
|
+
#ifdef VREAL
|
158
|
+
return counter_timer;
|
159
|
+
#endif
|
160
|
+
}
|
161
|
+
|
162
|
+
int sysTime()
|
163
|
+
{
|
164
|
+
#ifdef VSIMU
|
165
|
+
int res;
|
166
|
+
static int firstTimeSet = 0;
|
167
|
+
static struct timeval firstTime;
|
168
|
+
struct timeval tv;
|
169
|
+
if (firstTimeSet) {
|
170
|
+
gettimeofday(&tv, NULL);
|
171
|
+
res = (tv.tv_sec - firstTime.tv_sec);
|
172
|
+
res += (tv.tv_usec >= firstTime.tv_usec) ? 0 : -1;
|
173
|
+
} else {
|
174
|
+
gettimeofday(&firstTime, NULL);
|
175
|
+
firstTimeSet = 1;
|
176
|
+
res = 0;
|
177
|
+
}
|
178
|
+
return res;
|
179
|
+
#endif
|
180
|
+
#ifdef VREAL
|
181
|
+
return counter_timer_s;
|
182
|
+
#endif
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
int rndval;
|
187
|
+
|
188
|
+
// retourne une valeur al�atoire entre 0 et 65535
|
189
|
+
int sysRand()
|
190
|
+
{
|
191
|
+
rndval=rndval*0x1234567+11;
|
192
|
+
return (rndval>>8)&0xffff;
|
193
|
+
}
|
194
|
+
void sysSrand(int seed)
|
195
|
+
{
|
196
|
+
rndval=seed;
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
void sysCpy(char *dst,int i,int ldst,char *src,int j,int lsrc,int len)
|
201
|
+
{
|
202
|
+
if ((i<0)||(j<0)||(len<=0)) return;
|
203
|
+
if (i+len>ldst) len=ldst-i;
|
204
|
+
if (len<=0) return;
|
205
|
+
if (j+len>lsrc) len=lsrc-j;
|
206
|
+
if (len<=0) return;
|
207
|
+
dst+=i;
|
208
|
+
src+=j;
|
209
|
+
while((len--)>0) *(dst++)=*(src++);
|
210
|
+
}
|
211
|
+
|
212
|
+
int sysCmp(char *dst,int i,int ldst,char *src,int j,int lsrc,int len)
|
213
|
+
{
|
214
|
+
if ((i<0)||(j<0)||(len<=0)) return 0;
|
215
|
+
if ((i+len>ldst)&&(j+len>lsrc))
|
216
|
+
{
|
217
|
+
if (ldst-i>lsrc-j) len=ldst-i;
|
218
|
+
else len=lsrc-j;
|
219
|
+
}
|
220
|
+
dst+=i;
|
221
|
+
src+=j;
|
222
|
+
while((len--)>0) if (((unsigned char)*dst)>((unsigned char)*src)) return 1;
|
223
|
+
else if (((unsigned char)*(dst++))<((unsigned char)*(src++))) return -1;
|
224
|
+
return 0;
|
225
|
+
}
|
226
|
+
|
227
|
+
int mystrcmp(char *dst,char *src,int len)
|
228
|
+
{
|
229
|
+
while((len--)>0) if ((*(dst++))!=(*(src++))) return 1;
|
230
|
+
return 0;
|
231
|
+
}
|
232
|
+
|
233
|
+
void mystrcpy(char *dst,char *src,int len)
|
234
|
+
{
|
235
|
+
while((len--)>0) *(dst++)=*(src++);
|
236
|
+
}
|
237
|
+
|
238
|
+
int sysFind(char *dst,int i,int ldst,char *src,int j,int lsrc,int len)
|
239
|
+
{
|
240
|
+
if ((j<0)||(j+len>lsrc)) return NIL;
|
241
|
+
src+=j;
|
242
|
+
if (i<0) i=0;
|
243
|
+
while(i+len<=ldst)
|
244
|
+
{
|
245
|
+
if (!mystrcmp(dst+i,src,len)) return INTTOVAL(i);
|
246
|
+
i++;
|
247
|
+
}
|
248
|
+
return NIL;
|
249
|
+
}
|
250
|
+
|
251
|
+
int sysFindrev(char *dst,int i,int ldst,char *src,int j,int lsrc,int len)
|
252
|
+
{
|
253
|
+
if ((j<0)||(j+len>lsrc)) return NIL;
|
254
|
+
src+=j;
|
255
|
+
if(i+len>ldst) i=ldst-len;
|
256
|
+
while(i>=0)
|
257
|
+
{
|
258
|
+
if (!mystrcmp(dst+i,src,len)) return INTTOVAL(i);
|
259
|
+
i--;
|
260
|
+
}
|
261
|
+
return NIL;
|
262
|
+
}
|
263
|
+
|
264
|
+
int sysStrgetword(unsigned char *src,int len,int ind)
|
265
|
+
{
|
266
|
+
int n;
|
267
|
+
if ((ind<0)||(ind+2>len)) return -1;
|
268
|
+
n=(src[ind]<<8)+src[ind+1];
|
269
|
+
return n;
|
270
|
+
}
|
271
|
+
|
272
|
+
void sysStrputword(unsigned char *src,int len,int ind,int val)
|
273
|
+
{
|
274
|
+
if ((ind<0)||(ind+2>len)) return;
|
275
|
+
src[ind+1]=val; val>>=8;
|
276
|
+
src[ind]=val;
|
277
|
+
}
|
278
|
+
|
279
|
+
// lecture d'une cha�ne d�cimale (s'arr�te au premier caract�re incorrect)
|
280
|
+
int sysAtoi(char* src)
|
281
|
+
{
|
282
|
+
int x,c,s;
|
283
|
+
x=s=0;
|
284
|
+
if ((*src)=='-') { s=1; src++; }
|
285
|
+
while(c=*src++)
|
286
|
+
{
|
287
|
+
if ((c>='0')&&(c<='9')) x=(x*10)+c-'0';
|
288
|
+
else return (s?(-x):x);
|
289
|
+
}
|
290
|
+
return (s?(-x):x);
|
291
|
+
}
|
292
|
+
|
293
|
+
// lecture d'une cha�ne hexad�cimale (s'arr�te au premier caract�re incorrect)
|
294
|
+
int sysHtoi(char* src)
|
295
|
+
{
|
296
|
+
int x,c;
|
297
|
+
x=0;
|
298
|
+
while(c=*src++)
|
299
|
+
{
|
300
|
+
if ((c>='0')&&(c<='9')) x=(x<<4)+c-'0';
|
301
|
+
else if ((c>='A')&&(c<='F')) x=(x<<4)+c-'A'+10;
|
302
|
+
else if ((c>='a')&&(c<='f')) x=(x<<4)+c-'a'+10;
|
303
|
+
else return x;
|
304
|
+
}
|
305
|
+
return x;
|
306
|
+
}
|
307
|
+
void sysCtoa(int c)
|
308
|
+
{
|
309
|
+
unsigned char res[1];
|
310
|
+
res[0]=c;
|
311
|
+
VPUSH(PNTTOVAL(VMALLOCSTR((char*)res,1)));
|
312
|
+
}
|
313
|
+
|
314
|
+
const int itoarsc[10]={
|
315
|
+
1000000000,100000000,10000000,
|
316
|
+
1000000 ,100000 ,10000,
|
317
|
+
1000 ,100 ,10,
|
318
|
+
1
|
319
|
+
};;
|
320
|
+
void sysItoa(int v)
|
321
|
+
{
|
322
|
+
char res[16];
|
323
|
+
int ires=0;
|
324
|
+
if (v==0)
|
325
|
+
{
|
326
|
+
res[ires++]='0';
|
327
|
+
}
|
328
|
+
else
|
329
|
+
{
|
330
|
+
int start=1;
|
331
|
+
int imul=0;
|
332
|
+
if (v<0)
|
333
|
+
{
|
334
|
+
v=-v;
|
335
|
+
res[ires++]='-';
|
336
|
+
}
|
337
|
+
while(imul<10)
|
338
|
+
{
|
339
|
+
int k=0;
|
340
|
+
while(v>=itoarsc[imul])
|
341
|
+
{
|
342
|
+
k++;
|
343
|
+
v-=itoarsc[imul];
|
344
|
+
}
|
345
|
+
if ((k)||(!start))
|
346
|
+
{
|
347
|
+
start=0;
|
348
|
+
res[ires++]='0'+k;
|
349
|
+
}
|
350
|
+
imul++;
|
351
|
+
}
|
352
|
+
}
|
353
|
+
|
354
|
+
VPUSH(PNTTOVAL(VMALLOCSTR(res,ires)));
|
355
|
+
|
356
|
+
}
|
357
|
+
|
358
|
+
void sysItoh(int v)
|
359
|
+
{
|
360
|
+
char res[16];
|
361
|
+
int ires=0;
|
362
|
+
if (v==0)
|
363
|
+
{
|
364
|
+
res[ires++]='0';
|
365
|
+
}
|
366
|
+
else
|
367
|
+
{
|
368
|
+
int start=1;
|
369
|
+
int imul=28;
|
370
|
+
while(imul>=0)
|
371
|
+
{
|
372
|
+
int c=(v>>imul)&15;
|
373
|
+
if ((c)||(!start))
|
374
|
+
{
|
375
|
+
start=0;
|
376
|
+
res[ires++]=(c<10)?'0'+c:'a'+c-10;
|
377
|
+
}
|
378
|
+
imul-=4;
|
379
|
+
}
|
380
|
+
}
|
381
|
+
VPUSH(PNTTOVAL(VMALLOCSTR(res,ires)));
|
382
|
+
}
|
383
|
+
|
384
|
+
void sysCtoh(int c)
|
385
|
+
{
|
386
|
+
unsigned char res[2];
|
387
|
+
int v=(c>>4)&15;
|
388
|
+
res[0]=(v<10)?'0'+v:'a'+v-10;
|
389
|
+
v=c&15;
|
390
|
+
res[1]=(v<10)?'0'+v:'a'+v-10;
|
391
|
+
VPUSH(PNTTOVAL(VMALLOCSTR((char*)res,2)));
|
392
|
+
}
|
393
|
+
|
394
|
+
void sysItobin2(int c)
|
395
|
+
{
|
396
|
+
unsigned char res[2];
|
397
|
+
res[1]=c;
|
398
|
+
c>>=8;
|
399
|
+
res[0]=c;
|
400
|
+
VPUSH(PNTTOVAL(VMALLOCSTR((char*)res,2)));
|
401
|
+
}
|
402
|
+
|
403
|
+
int sysListswitch(int p,int key)
|
404
|
+
{
|
405
|
+
while(p!=NIL)
|
406
|
+
{
|
407
|
+
int q=VALTOPNT(VFETCH(p,0));
|
408
|
+
if ((q!=NIL)&&(VFETCH(q,0)==key)) return VFETCH(q,1);
|
409
|
+
p=VALTOPNT(VFETCH(p,1));
|
410
|
+
}
|
411
|
+
return NIL;
|
412
|
+
}
|
413
|
+
|
414
|
+
int sysListswitchstr(int p,char* key)
|
415
|
+
{
|
416
|
+
while(p!=NIL)
|
417
|
+
{
|
418
|
+
int q=VALTOPNT(VFETCH(p,0));
|
419
|
+
if (q!=NIL)
|
420
|
+
{
|
421
|
+
int r=VALTOPNT(VFETCH(q,0));
|
422
|
+
if ((r!=NIL)&&(!strcmp(VSTARTBIN(r),key))) return VFETCH(q,1);
|
423
|
+
}
|
424
|
+
p=VALTOPNT(VFETCH(p,1));
|
425
|
+
}
|
426
|
+
return NIL;
|
427
|
+
}
|
428
|
+
|
429
|
+
void simuSetLed(int i,int val);
|
430
|
+
void set_motor_dir(int num_motor, int sens);
|
431
|
+
int get_motor_val(int i);
|
432
|
+
int getButton();
|
433
|
+
int get_button3();
|
434
|
+
char* get_rfid();
|
435
|
+
|
436
|
+
void sysLed(int led,int col)
|
437
|
+
{
|
438
|
+
#ifdef VSIMU
|
439
|
+
simuSetLed(led,col);
|
440
|
+
#endif
|
441
|
+
#ifdef VREAL
|
442
|
+
set_led((UWORD)led,(UWORD)col);
|
443
|
+
#endif
|
444
|
+
}
|
445
|
+
|
446
|
+
void sysMotorset(int motor,int sens)
|
447
|
+
{
|
448
|
+
#ifdef VSIMU
|
449
|
+
set_motor_dir(motor,sens);
|
450
|
+
#endif
|
451
|
+
#ifdef VREAL
|
452
|
+
// char buffer[256];
|
453
|
+
motor=1+(motor&1);
|
454
|
+
|
455
|
+
// sprintf(buffer,"setmotor %d sens %d\r\n",motor,sens);
|
456
|
+
// consolestr(buffer);
|
457
|
+
|
458
|
+
if (sens==0) stop_motor(motor);
|
459
|
+
else run_motor(motor,255,(sens>0)?REVERSE:FORWARD/*:REVERSE*/);
|
460
|
+
#endif
|
461
|
+
}
|
462
|
+
|
463
|
+
int kmotor[3];
|
464
|
+
int kvmotor[3];
|
465
|
+
|
466
|
+
int sysMotorget(int motor)
|
467
|
+
{
|
468
|
+
#ifdef VSIMU
|
469
|
+
return get_motor_val(motor);
|
470
|
+
#endif
|
471
|
+
#ifdef VREAL
|
472
|
+
// char buffer[256];
|
473
|
+
int k,kx;
|
474
|
+
motor=1+(motor&1);
|
475
|
+
kx=(int)get_motor_position(motor);
|
476
|
+
/* k=(int)get_motor_position(motor);
|
477
|
+
if (kmotor[motor]!=k)
|
478
|
+
{
|
479
|
+
kmotor[motor]=k;
|
480
|
+
kvmotor[motor]++;
|
481
|
+
}
|
482
|
+
kx=kvmotor[motor];
|
483
|
+
*/
|
484
|
+
|
485
|
+
// sprintf(buffer,"getmotor %d pos %x / %x\r\n",motor,k,kx);
|
486
|
+
// if(motor==2)
|
487
|
+
// consolestr(buffer);
|
488
|
+
return kx;
|
489
|
+
#endif
|
490
|
+
}
|
491
|
+
|
492
|
+
int sysButton2()
|
493
|
+
{
|
494
|
+
#ifdef VSIMU
|
495
|
+
return getButton();
|
496
|
+
#endif
|
497
|
+
#ifdef VREAL
|
498
|
+
return push_button_value();
|
499
|
+
#endif
|
500
|
+
}
|
501
|
+
|
502
|
+
int sysButton3()
|
503
|
+
{
|
504
|
+
#ifdef VSIMU
|
505
|
+
return get_button3();
|
506
|
+
#endif
|
507
|
+
#ifdef VREAL
|
508
|
+
return 255-get_adc_value();
|
509
|
+
#endif
|
510
|
+
}
|
511
|
+
|
512
|
+
char* sysRfidget()
|
513
|
+
{
|
514
|
+
#ifdef VSIMU
|
515
|
+
return get_rfid();
|
516
|
+
#endif
|
517
|
+
#ifdef VREAL
|
518
|
+
return get_rfid_first_device();
|
519
|
+
#endif
|
520
|
+
}
|
521
|
+
|
522
|
+
void sysReboot()
|
523
|
+
{
|
524
|
+
#ifdef VSIMU
|
525
|
+
printf("REBOOT NOW.....");
|
526
|
+
getchar();
|
527
|
+
exit(0);
|
528
|
+
#endif
|
529
|
+
#ifdef VREAL
|
530
|
+
reset_uc();
|
531
|
+
#endif
|
532
|
+
|
533
|
+
}
|
534
|
+
|
535
|
+
void sysFlash(char* firmware,int len)
|
536
|
+
{
|
537
|
+
#ifdef VSIMU
|
538
|
+
printf("REBOOT AND FLASH NOW.....");
|
539
|
+
getchar();
|
540
|
+
exit(0);
|
541
|
+
#endif
|
542
|
+
#ifdef VREAL
|
543
|
+
__disable_interrupt();
|
544
|
+
flash_uc((unsigned char*)firmware,len,buffer_temp);
|
545
|
+
#endif
|
546
|
+
|
547
|
+
}
|
548
|
+
|
549
|
+
const uchar inv8[128]=
|
550
|
+
{
|
551
|
+
1,171,205,183,57,163,197,239,241,27,61,167,41,19,53,223,225,139,173,151,25,131,165,207,209,251,29,135,9,243,21,191,193,107,141,119,249,99,133,175,177,219,253,103,233,211,245,159,161,75,109,87,217,67,101,143,145,187,221,71,201,179,213,127,129,43,77,55,185,35,69,111,113,155,189,39,169,147,181,95,97,11,45,23,153,3,37,79,81,123,157,7,137,115,149,63,65,235,13,247,121,227,5,47,49,91,125,231,105,83,117,31,33,203,237,215,89,195,229,15,17,59,93,199,73,51,85,255
|
552
|
+
};
|
553
|
+
|
554
|
+
int decode8(uchar* src,int len,uchar key,uchar alpha)
|
555
|
+
{
|
556
|
+
while(len--)
|
557
|
+
{
|
558
|
+
uchar v=((*src)-alpha)*key;
|
559
|
+
*(src++)=v;
|
560
|
+
key=v+v+1;
|
561
|
+
}
|
562
|
+
return key;
|
563
|
+
}
|
564
|
+
|
565
|
+
int encode8(uchar* src,int len,uchar key,uchar alpha)
|
566
|
+
{
|
567
|
+
while(len--)
|
568
|
+
{
|
569
|
+
uchar v=*src;
|
570
|
+
*(src++)=alpha+(v*inv8[key>>1]);
|
571
|
+
key=v+v+1;
|
572
|
+
}
|
573
|
+
return key;
|
574
|
+
}
|
575
|
+
|
576
|
+
|
577
|
+
|
578
|
+
int sysCrypt(char* src,int indexsrc,int len,int lensrc,unsigned int key,int alpha)
|
579
|
+
{
|
580
|
+
if ((indexsrc<0)||(indexsrc+len>lensrc)||(len<=0)) return -1;
|
581
|
+
return encode8(src+indexsrc,len,key,alpha);
|
582
|
+
}
|
583
|
+
int sysUncrypt(char* src,int indexsrc,int len,int lensrc,unsigned int key,int alpha)
|
584
|
+
{
|
585
|
+
if ((indexsrc<0)||(indexsrc+len>lensrc)||(len<=0)) return -1;
|
586
|
+
return decode8(src+indexsrc,len,key,alpha);
|
587
|
+
}
|
588
|
+
|
589
|
+
|
data/ext/mtl/vlog.h
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
// VLISP Virtual Machine - 2006 - by Sylvain Huet
|
2
|
+
// Lowcost IS Powerfull
|
3
|
+
|
4
|
+
#ifndef _LOGGER_
|
5
|
+
#define _LOGGER_
|
6
|
+
|
7
|
+
#include "log.h"
|
8
|
+
|
9
|
+
#ifdef VSIMU
|
10
|
+
#define consolestr(val) my_printf(LOG_VM, "%s",val)
|
11
|
+
#define consolebin(val,len) my_printf(LOG_VM, "%s",val)
|
12
|
+
#define consoleint(val) my_printf(LOG_VM, "%d",val)
|
13
|
+
#define consolehx(val) my_printf(LOG_VM, "%x",val)
|
14
|
+
#endif
|
15
|
+
#ifdef VREAL
|
16
|
+
#define consolestr(val) putst_uart(val)
|
17
|
+
#define consolebin(val,len) putbin_uart(val,len)
|
18
|
+
#define consoleint(val) putint_uart(val)
|
19
|
+
#define consolehx(val) puthx_uart(val)
|
20
|
+
#endif
|
21
|
+
|
22
|
+
void logSecho(int p,int nl);
|
23
|
+
void logIecho(int i,int nl);
|
24
|
+
void logGC();
|
25
|
+
|
26
|
+
void dump(uchar *src,int len);
|
27
|
+
|
28
|
+
int sysLoad(char *dst,int i,int ldst,char *filename,int j,int len);
|
29
|
+
int sysSave(char *dst,int i,int ldst,char *filename,int j,int len);
|
30
|
+
|
31
|
+
int sysTimems();
|
32
|
+
int sysTime();
|
33
|
+
int sysRand();
|
34
|
+
void sysSrand(int seed);
|
35
|
+
void sysReboot();
|
36
|
+
void sysFlash(char* firmware,int len);
|
37
|
+
|
38
|
+
void mystrcpy(char *dst,char *src,int len);
|
39
|
+
|
40
|
+
void sysCpy(char *dst,int i,int ldst,char *src,int j,int lsrc,int len);
|
41
|
+
int sysCmp(char *dst,int i,int ldst,char *src,int j,int lsrc,int len);
|
42
|
+
int sysFind(char *dst,int i,int ldst,char *src,int j,int lsrc,int len);
|
43
|
+
int sysFindrev(char *dst,int i,int ldst,char *src,int j,int lsrc,int len);
|
44
|
+
int sysStrgetword(unsigned char *src,int len,int ind);
|
45
|
+
void sysStrputword(unsigned char *src,int len,int ind,int val);
|
46
|
+
int sysAtoi(char* src);
|
47
|
+
int sysHtoi(char* src);
|
48
|
+
void sysCtoa(int c);
|
49
|
+
void sysItoa(int v);
|
50
|
+
void sysItoh(int v);
|
51
|
+
void sysCtoh(int c);
|
52
|
+
void sysItobin2(int c);
|
53
|
+
int sysListswitch(int p,int key);
|
54
|
+
int sysListswitchstr(int p,char* key);
|
55
|
+
|
56
|
+
|
57
|
+
void sysLed(int led,int col);
|
58
|
+
void sysMotorset(int motor,int sens);
|
59
|
+
int sysMotorget(int motor);
|
60
|
+
int sysButton2();
|
61
|
+
int sysButton3();
|
62
|
+
|
63
|
+
char* sysRfidget();
|
64
|
+
|
65
|
+
int sysCrypt(char* src,int indexsrc,int len,int lensrc,unsigned int key,int alpha);
|
66
|
+
int sysUncrypt(char* src,int indexsrc,int len,int lensrc,unsigned int key,int alpha);
|
67
|
+
|
68
|
+
#endif
|
69
|
+
|