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.
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/log.c ADDED
@@ -0,0 +1,297 @@
1
+ /**
2
+ Routines simples pour pouvoir logger les sorties du compilateur
3
+ */
4
+
5
+ #include <stdio.h>
6
+ #include <string.h>
7
+ #include <stdarg.h>
8
+ #include <sys/stat.h>
9
+ #include <time.h>
10
+ #include <stdlib.h>
11
+
12
+ #include "log.h"
13
+
14
+ static int my_msk = LOG_INIT | LOG_VM | LOG_SIMUNET;
15
+ #define BUFSIZE 16384
16
+ static char tmpbuf[BUFSIZE];
17
+
18
+ // siml : Stopped In the Midle of a Line. A 1 quand on a pas affiché
19
+ // tout le buffer parce qu'il ne se terminait pas par '\n'
20
+ static int siml=0;
21
+ static e_logtypes siml_t=LOG_INIT;
22
+ static int siml_idx=0;
23
+
24
+ // infos concernant le log
25
+ static FILE *outstream=NULL; // flux vers lequel on logge
26
+ static char *outfilename=NULL; // nom de fichier correspondant
27
+ static int max_log_size=0; // taille max d'un fichier de log
28
+ static int max_log_time=0; // temps max de log par fichier, en secondes
29
+ static time_t last_log_roll=0; // depuis quand on logge dans le fichier de log courant
30
+ static int current_log_size=0; // la taille courant du log
31
+ static time_t time_first_log=0; // la date du premier log enregistre
32
+ static int do_log_time=0; // si 1, on ajoute le nombre de secondes depuis le reveil du lapin au debut de chaque ligne
33
+
34
+ static void my_printf_check_log_roll(void);
35
+
36
+ /**
37
+ Renvoie, selon le type passé en argument, le préfixe à utiliser dans le log
38
+ */
39
+ static const char *get_prefix(e_logtypes t)
40
+ {
41
+ const char *res = NULL;
42
+ int i;
43
+ switch (t) {
44
+ case LOG_INIT:
45
+ res = "init"; break;
46
+ case LOG_VM:
47
+ res = "vm"; break;
48
+ case LOG_SIMUNET:
49
+ res = "simunet"; break;
50
+ case LOG_SIMUAUDIO:
51
+ res = "simuaudio"; break;
52
+ case LOG_SIMULEDS:
53
+ res = "simuleds"; break;
54
+ case LOG_SIMUMOTORS:
55
+ res = "simumotors"; break;
56
+ }
57
+ return res;
58
+ }
59
+
60
+ /**
61
+ Affiche s en ajoutant [pfx] au début de chaque ligne.
62
+
63
+ Si force==1, on affiche même s'il n'y a pas de '\n' (et on en rajoute un)
64
+ */
65
+ static int print_line_by_line(e_logtypes t, char *s, int force)
66
+ {
67
+ char *tmp;
68
+ int nbwritten=0;
69
+ char pfx[256];
70
+ if (do_log_time)
71
+ snprintf(pfx,255, "%06d %s", time(NULL) - time_first_log, get_prefix(t));
72
+ else
73
+ strncpy(pfx, get_prefix(t), 255);
74
+ while (*s!='\0')
75
+ {
76
+ tmp = strchr(s, '\n');
77
+ if (NULL!=tmp) {
78
+ *tmp='\0';
79
+ current_log_size += fprintf(outstream, "[%s] %s\n", pfx, s);
80
+ *tmp='\n';
81
+ nbwritten+=(tmp-s)+1;
82
+ s=tmp+1;
83
+ }
84
+ else {
85
+ if (force) {
86
+ current_log_size += fprintf(outstream, "[%s] %s\n", pfx, s);
87
+ nbwritten+=strlen(s);
88
+ }
89
+ break;
90
+ }
91
+ }
92
+ return nbwritten;
93
+ }
94
+
95
+ /**
96
+ Comme printf, filtré par les paramètrages du log.
97
+
98
+ t : le type de message affiché
99
+ */
100
+ void my_printf(e_logtypes t, const char *fmt, ...)
101
+ {
102
+ if (NULL==outstream)
103
+ outstream = stdout;
104
+
105
+ my_printf_check_log_roll();
106
+
107
+ if (0==time_first_log && do_log_time)
108
+ {
109
+ char tmp[256];
110
+ time_first_log = time(NULL);
111
+ snprintf(tmp, 255, "First log time: %s", ctime(&time_first_log));
112
+ print_line_by_line(LOG_INIT, tmp, 0);
113
+ }
114
+
115
+ int len, nbwritten;
116
+
117
+ if (0==((int)t & my_msk))
118
+ return;
119
+
120
+ if (siml && siml_t!=t)
121
+ {
122
+ // il faut "flusher" ce qu'il reste dans le buffer
123
+ print_line_by_line(siml_t, tmpbuf, 1);
124
+ siml=0;
125
+ siml_idx=0;
126
+ }
127
+
128
+ va_list args;
129
+ va_start(args, fmt);
130
+ len=vsnprintf(tmpbuf+siml_idx, BUFSIZE-1-siml_idx, fmt , args);
131
+ va_end(args);
132
+
133
+ // make_writeable(tmpbuf); ? s'il y a des caractères non imprimables ?
134
+ nbwritten=print_line_by_line(t, tmpbuf, 0);
135
+
136
+ len += siml_idx;
137
+ if(nbwritten<len)
138
+ {
139
+ siml=1;
140
+ siml_t=t;
141
+ siml_idx=len-nbwritten; // +siml_idx au cas ou ce n'est pas la premiere fois qu'on rajoute qqe chose dans le buffer.
142
+ if (nbwritten!=0)
143
+ // on déplace ce qu'il reste à écrire au début de tmpbuf
144
+ memmove(tmpbuf, tmpbuf+nbwritten, len-nbwritten);
145
+ }
146
+ else
147
+ {
148
+ siml=0;
149
+ siml_idx=0;
150
+ }
151
+ }
152
+
153
+ /**
154
+ Permet de contrôler les logs qu'on veut afficher (ils s'affichent
155
+ tous par défaut)
156
+ */
157
+ void my_printf_set_options(const char *s)
158
+ {
159
+ my_msk=0;
160
+
161
+ char *token, *cpy;
162
+
163
+ cpy = token = strdup(s);
164
+ token = strtok(cpy, ",");
165
+ while (NULL!=token) {
166
+ if (!strcmp(token,"init"))
167
+ my_msk |= LOG_INIT;
168
+ else if (!strcmp(token,"vm"))
169
+ my_msk |= LOG_VM;
170
+ else if (!strcmp(token,"simunet"))
171
+ my_msk |= LOG_SIMUNET;
172
+ else if (!strcmp(token,"simuaudio"))
173
+ my_msk |= LOG_SIMUAUDIO;
174
+ else if (!strcmp(token,"simuleds"))
175
+ my_msk |= LOG_SIMULEDS;
176
+ else if (!strcmp(token,"simumotors"))
177
+ my_msk |= LOG_SIMUMOTORS;
178
+ else {
179
+ fprintf(stderr, "erreur: %s n'est pas une option valide pour les logs\n");
180
+ break;
181
+ }
182
+ token = strtok(NULL, ",");
183
+ }
184
+ free(cpy);
185
+ }
186
+
187
+ /**
188
+ Spécifie le nom du fichier dans lequel on veut logger la sortie du lapin
189
+
190
+ retourne 0 si tout s'est bien passé, 1 sinon
191
+ */
192
+ int my_printf_set_logfile(const char *filename)
193
+ {
194
+ FILE *f = fopen(filename, "w");
195
+
196
+ if (NULL==f)
197
+ {
198
+ fprintf(stderr, "Could not open file %s to log in it.\n", filename);
199
+ return 1;
200
+ }
201
+
202
+ if (NULL!=outstream)
203
+ {
204
+ fclose(outstream);
205
+ outstream=NULL;
206
+ }
207
+ if (NULL!=outfilename)
208
+ {
209
+ free(outfilename);
210
+ outfilename=NULL;
211
+ }
212
+
213
+ outstream=f;
214
+ outfilename=strdup(filename);
215
+ current_log_size=0;
216
+ last_log_roll=time(NULL);
217
+
218
+ return 0;
219
+ }
220
+
221
+
222
+ static int my_printf_rotate_log_n(int n);
223
+
224
+ /**
225
+ Effectue la rotation des logs
226
+
227
+ - on decale tous les <log>.<n> existants en <log>.<n+1>
228
+ - le log courant devient <log>.0
229
+ - on reouvre le fichier <log> pour logger dedans
230
+ */
231
+ static int my_printf_rotate_log(void)
232
+ {
233
+ // décaler tous les logs existants et <log> en <log>.0
234
+ my_printf_rotate_log_n(-1);
235
+ char *tmp;
236
+ tmp=strdup(outfilename);
237
+ my_printf_set_logfile(tmp);
238
+ free(tmp);
239
+ }
240
+
241
+ /**
242
+ si n==-1, alors déplace <log> en <log>.0
243
+
244
+ renomme le fichier <log>.<n> en fichier <log>.<n+1>, et pareil pour
245
+ tous les suivants.
246
+
247
+ /!\ fonction réentrante
248
+ */
249
+ static int my_printf_rotate_log_n(int n)
250
+ {
251
+ char tmpn[255];
252
+ char tmpnplusun[255];
253
+ struct stat ststat;
254
+
255
+ if (n<0)
256
+ strcpy(tmpn, outfilename);
257
+ else
258
+ snprintf(tmpn, 255, "%s.%d", outfilename, n);
259
+ snprintf(tmpnplusun, 255, "%s.%d", outfilename, n+1);
260
+
261
+ if (!stat(tmpnplusun, &ststat))
262
+ my_printf_rotate_log_n(n+1);
263
+ rename(tmpn, tmpnplusun);
264
+ }
265
+
266
+ /**
267
+ Effectue la rotation des logs si besoin
268
+ */
269
+ static void my_printf_check_log_roll(void)
270
+ {
271
+ int need_roll=0;
272
+
273
+ if (0!=max_log_size)
274
+ need_roll += (current_log_size > max_log_size);
275
+ if (0!=max_log_time)
276
+ {
277
+ need_roll += (((int)time(NULL) - last_log_roll) > max_log_time);
278
+ }
279
+
280
+ if (need_roll)
281
+ my_printf_rotate_log();
282
+ }
283
+
284
+ void my_printf_set_max_log_size(int n)
285
+ {
286
+ max_log_size=n;
287
+ }
288
+
289
+ void my_printf_set_max_log_time(int n)
290
+ {
291
+ max_log_time=n;
292
+ }
293
+
294
+ void my_printf_set_do_log_time(int n)
295
+ {
296
+ do_log_time=n;
297
+ }
data/ext/mtl/log.h ADDED
@@ -0,0 +1,20 @@
1
+ #ifndef _LOG_H_
2
+ # define _LOG_H_
3
+
4
+ typedef enum {
5
+ LOG_INIT = 1, // les messages écrits pendant l'init
6
+ LOG_VM = 2, // les messages écrits par le lapin
7
+ LOG_SIMUNET = 4, // les logs de simulation réseau
8
+ LOG_SIMUAUDIO = 8, // les logs de simulation audio
9
+ LOG_SIMULEDS = 16, // les logs de simulation des leds
10
+ LOG_SIMUMOTORS = 32 // les messages écrits pendant l'init
11
+ } e_logtypes;
12
+
13
+ void my_printf(e_logtypes t, const char *fmt, ...);
14
+ void my_printf_set_options(const char *s);
15
+ int my_printf_set_logfile(const char *filename);
16
+ void my_printf_set_max_log_size(int n);
17
+ void my_printf_set_max_log_time(int n);
18
+ void my_printf_set_do_log_time(int n);
19
+
20
+ #endif // ! _LOG_H_
@@ -0,0 +1,104 @@
1
+ // VLISP Virtual Machine - 2006 - by Sylvain Huet
2
+ // Lowcost IS Powerfull
3
+
4
+
5
+ #define DUMPBC
6
+
7
+
8
+ #include<stdio.h>
9
+ #include <string.h>
10
+ #include <unistd.h>
11
+ extern "C" {
12
+ #include"vmem.h"
13
+ #include"vloader.h"
14
+ #include"vinterp.h"
15
+ #include"properties.h"
16
+
17
+ char srcbytecode[65536];
18
+
19
+
20
+ void dump(uchar *src,int len)
21
+ {
22
+ int i,j;
23
+ char buffer[64];
24
+ printf("\n");
25
+ for(i=0;i<len;i+=16)
26
+ {
27
+ printf("%04x ",i);
28
+ for(j=0;j<16;j++) if (i+j<len)
29
+ {
30
+ printf(buffer,"%02x ",src[i+j]);
31
+ }
32
+ else printf(" ");
33
+ for(j=0;j<16;j++) if (i+j<len) printf("%c",(((src[i+j]>=32)&&(src[i+j]<128))?src[i+j]:'.'));
34
+ printf("\n");
35
+ // DelayMs(100);
36
+ }
37
+ }
38
+
39
+
40
+ void loadbytecode(char *src)
41
+ {
42
+ FILE *f;
43
+ int i,n;
44
+ f=fopen(src,"rb");
45
+ if (!f)
46
+ {
47
+ printf("file %s not found\n",src);
48
+ return;
49
+ }
50
+ n=fread(srcbytecode,1,65536,f);
51
+ fclose(f);
52
+
53
+ #ifdef DUMPBC
54
+ f=fopen("dumpbc.c","wb");
55
+ if (f)
56
+ {
57
+ fprintf(f,"const unsigned char dumpbc[%d]={\n",n);
58
+ for(i=0;i<n;i++)
59
+ {
60
+ fprintf(f,"0x%02x",srcbytecode[i]&255);
61
+ if (i+1<n) fprintf(f,",");
62
+ if (!((i+1)&0xf)) fprintf(f,"\n");
63
+ }
64
+ fprintf(f,"\n};\n");
65
+ fclose(f);
66
+ }
67
+ #endif
68
+ }
69
+
70
+ }
71
+
72
+
73
+ int StartMetal(const char *starter, const char* output, bool inSign);
74
+
75
+ extern unsigned char dumpbc[];
76
+
77
+ void usage(char* inProgram) {
78
+ printf("Syntaxe: %s [-s] source output\n", inProgram);
79
+ }
80
+
81
+ int main(int argc,char **argv)
82
+ {
83
+ bool signBinary = false;
84
+ char* source = argv[1];
85
+ char* output = argv[2];
86
+ if ((argc != 3) && (argc != 4)) {
87
+ usage(argv[0]);
88
+ return 1;
89
+ }
90
+ if (argc == 4) {
91
+ if (strcmp(argv[1], "-s") == 0) {
92
+ signBinary = true;
93
+ source = argv[2];
94
+ output = argv[3];
95
+ } else {
96
+ usage(argv[0]);
97
+ return 1;
98
+ }
99
+ }
100
+
101
+ StartMetal(source, output, signBinary);
102
+ return 0;
103
+ }
104
+
@@ -0,0 +1,221 @@
1
+ // VLISP Virtual Machine - 2006 - by Sylvain Huet
2
+ // Lowcost IS Powerfull
3
+
4
+
5
+ // #define DUMPBC
6
+
7
+ #define MAXSIZE_BYTECODE (128*1024)
8
+
9
+ #include<stdio.h>
10
+ #include <string.h>
11
+ #include <unistd.h>
12
+ #include <stdlib.h>
13
+ extern "C" {
14
+ #include"vmem.h"
15
+ #include"vloader.h"
16
+ #include"vinterp.h"
17
+ #include"properties.h"
18
+ #include "log.h"
19
+
20
+ int simuInit();
21
+
22
+ // fonction � appeler r�guli�rement, pour traiter les messages de la fen�tre du simulateur
23
+ int simuDoLoop();
24
+
25
+ // r�glagle d'une led
26
+ void simuSetLed(int i,int val);
27
+
28
+ // r�glagle d'un moteur
29
+ void simuSetMotor(int i,int val);
30
+
31
+ }
32
+
33
+ int handle_options(int argc, char **argv);
34
+ void usage();
35
+
36
+
37
+ char srcbytecode[MAXSIZE_BYTECODE];
38
+
39
+
40
+ void dump(uchar *src,int len)
41
+ {
42
+ int i,j;
43
+ char buffer[64];
44
+ printf("\n");
45
+ for(i=0;i<len;i+=16)
46
+ {
47
+ printf("%04x ",i);
48
+ for(j=0;j<16;j++) if (i+j<len)
49
+ {
50
+ printf(buffer,"%02x ",src[i+j]);
51
+ }
52
+ else printf(" ");
53
+ for(j=0;j<16;j++) if (i+j<len) printf("%c",(((src[i+j]>=32)&&(src[i+j]<128))?src[i+j]:'.'));
54
+ printf("\n");
55
+ // DelayMs(100);
56
+ }
57
+ }
58
+
59
+
60
+ void loadbytecode(const char *src)
61
+ {
62
+ FILE *f;
63
+ int i,n;
64
+ f=fopen(src,"rb");
65
+ if (!f)
66
+ {
67
+ printf("file %s not found\n",src);
68
+ return;
69
+ }
70
+ n=fread(srcbytecode,1,MAXSIZE_BYTECODE,f);
71
+ fclose(f);
72
+
73
+ #ifdef DUMPBC
74
+ f=fopen("dumpbc.c","wb");
75
+ if (f)
76
+ {
77
+ fprintf(f,"const unsigned char dumpbc[%d]={\n",n);
78
+ for(i=0;i<n;i++)
79
+ {
80
+ fprintf(f,"0x%02x",srcbytecode[i]&255);
81
+ if (i+1<n) fprintf(f,",");
82
+ if (!((i+1)&0xf)) fprintf(f,"\n");
83
+ }
84
+ fprintf(f,"\n};\n");
85
+ fclose(f);
86
+ }
87
+ #endif
88
+ }
89
+
90
+
91
+ int vcompDoit(char *starter);
92
+
93
+ extern unsigned char dumpbc[];
94
+
95
+ int main(int argc,char **argv)
96
+ {
97
+ PropLoad("config.txt");
98
+
99
+ if (!handle_options(argc, argv))
100
+ return -1;
101
+
102
+ PropDump();
103
+
104
+ if (!vcompDoit(PropGet("SOURCE")))
105
+ {
106
+ loadbytecode("foo.bin");
107
+
108
+ vmemInit(0);
109
+
110
+ if (!strcmp(PropGet("BOOT"),"firmware"))
111
+ {
112
+ loaderInit((char*)dumpbc);
113
+ }
114
+ else
115
+ {
116
+ loaderInit(srcbytecode);
117
+ }
118
+ vmemDumpShort();
119
+ getchar();
120
+
121
+
122
+ simuInit();
123
+
124
+ VPUSH(INTTOVAL(0));
125
+ interpGo();
126
+ VPULL();
127
+ while(1)
128
+ {
129
+ simuDoLoop();
130
+ VPUSH(VCALLSTACKGET(sys_start,SYS_CBLOOP));
131
+ if (VSTACKGET(0)!=NIL) interpGo();
132
+ VPULL();
133
+
134
+ usleep(50 * 1000);
135
+ }
136
+ getchar();
137
+ }
138
+ return 0;
139
+ }
140
+
141
+
142
+ /**
143
+ Retourne une valeur diff�rente de 0 si la cha�ne non vide pass�e en argument
144
+ repr�sente un nombre, 0 sinon
145
+ */
146
+ static int my_is_number(const char *s)
147
+ {
148
+ while ('\0'!=*s && (*s>='0' && *s<='9')) s++;
149
+ return (*s == '\0');
150
+ }
151
+
152
+ /**
153
+ G�re les options qui sont pass�es en ligne de commande
154
+ */
155
+ int handle_options(int argc, char **argv)
156
+ {
157
+ int i=1;
158
+ int res=1;
159
+
160
+ while (i<argc) {
161
+ if (!strcmp(argv[i], "--help")) {
162
+ usage();
163
+ res=0;
164
+ break;
165
+ } else if (!strcmp(argv[i], "--mac")) {
166
+ ++i;
167
+ if (i>=argc) { usage(); return 0; }
168
+ PropSet("MAC", argv[i]);
169
+ } else if (!strcmp(argv[i], "--boot")) {
170
+ PropSet("BOOT", "firmware");
171
+ } else if (!strcmp(argv[i], "--source")) {
172
+ ++i;
173
+ if (i>=argc) { usage(); return 0; }
174
+ PropSet("SOURCE", argv[i]);
175
+ } else if (!strcmp(argv[i], "--logs")) {
176
+ ++i;
177
+ if (i>=argc) { usage(); return 0; }
178
+ my_printf_set_options(argv[i]);
179
+ } else if (!strcmp(argv[i], "--logfile")) {
180
+ ++i;
181
+ if (i>=argc) { usage(); return 0; }
182
+ if (my_printf_set_logfile(argv[i]))
183
+ { res=0; break; }
184
+ } else if (!strcmp(argv[i], "--maxlogsize")) {
185
+ ++i;
186
+ if (i>=argc || !my_is_number(argv[i])) { usage(); return 0; }
187
+ my_printf_set_max_log_size(atoi(argv[i]));
188
+ } else if (!strcmp(argv[i], "--maxlogtime")) {
189
+ ++i;
190
+ if (i>=argc || !my_is_number(argv[i])) { usage(); return 0; }
191
+ my_printf_set_max_log_time(atoi(argv[i]));
192
+ } else if (!strcmp(argv[i], "--dologtime")) {
193
+ my_printf_set_do_log_time(1);
194
+ } else {
195
+ usage();
196
+ res=0;
197
+ break;
198
+ }
199
+ ++i;
200
+ }
201
+
202
+ return res;
203
+ }
204
+
205
+ /**
206
+ Affiche les options disponibles pour le logiciel
207
+ */
208
+ void usage()
209
+ {
210
+ printf("Usage: mtl_simy [--help] [--mac MACADDR] [--boot] [--source SOURCE]\n" \
211
+ " --help: affiche cette aide et quitte\n" \
212
+ " --mac MACADDR: permet de preciser une adresse mac pour le lapin\n" \
213
+ " --boot: comme si on mettait \"BOOT firmware\" dans config.txt\n" \
214
+ " --source SOURCE: compile et charge le bytecode present dans le fichier SOURCE\n" \
215
+ " --logs <log1>,...,<logn>: specifie les types de logs qu'on veut afficher, entre init,vm,simunet,simuleds et simuaudio, separes par des virgules\n" \
216
+ " --logfile <filename>: specifie le fichier dans lequel ecrire les logs du lapin\n" \
217
+ " --maxlogsize <n>: specifie qu'un fichier de log ne peut depasser <n> octets\n" \
218
+ " --maxlogtime <n>: specifie qu'il doit y avoir une rotation du fichier de log au moins toutes les <n> secondes\n" \
219
+ " --dologtime: specifie qu'on doit afficher sur chaque ligne de log le nombre de secondes ecoulees depuis le lancement du simulateur\n" \
220
+ "Toutes les options sont prioritaires sur les valeurs contenues dans config.txt\n");
221
+ }