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,288 @@
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
53
+ {
54
+ printf(" ");
55
+ }
56
+ for(j=0; j<16; j++) if (i+j<len)
57
+ {
58
+ printf("%c",(((src[i+j]>=32)&&(src[i+j]<128))?src[i+j]:'.'));
59
+ }
60
+ printf("\n");
61
+ // DelayMs(100);
62
+ }
63
+ }
64
+
65
+
66
+ void loadbytecode(const char *src)
67
+ {
68
+ FILE *f;
69
+ int i,n;
70
+ f=fopen(src,"rb");
71
+ if (!f)
72
+ {
73
+ printf("file %s not found\n",src);
74
+ return;
75
+ }
76
+ n=fread(srcbytecode,1,MAXSIZE_BYTECODE,f);
77
+ fclose(f);
78
+
79
+ #ifdef DUMPBC
80
+ f=fopen("dumpbc.c","wb");
81
+ if (f)
82
+ {
83
+ fprintf(f,"const unsigned char dumpbc[%d]={\n",n);
84
+ for(i=0; i<n; i++)
85
+ {
86
+ fprintf(f,"0x%02x",srcbytecode[i]&255);
87
+ if (i+1<n)
88
+ {
89
+ fprintf(f,",");
90
+ }
91
+ if (!((i+1)&0xf))
92
+ {
93
+ fprintf(f,"\n");
94
+ }
95
+ }
96
+ fprintf(f,"\n};\n");
97
+ fclose(f);
98
+ }
99
+ #endif
100
+ }
101
+
102
+
103
+ int vcompDoit(char *starter);
104
+
105
+ extern unsigned char dumpbc[];
106
+
107
+ int main(int argc,char **argv)
108
+ {
109
+ PropLoad("config.txt");
110
+
111
+ if (!handle_options(argc, argv))
112
+ {
113
+ return -1;
114
+ }
115
+
116
+ PropDump();
117
+
118
+ if (!vcompDoit(PropGet("SOURCE")))
119
+ {
120
+ loadbytecode("foo.bin");
121
+
122
+ vmemInit(0);
123
+
124
+ if (!strcmp(PropGet("BOOT"),"firmware"))
125
+ {
126
+ loaderInit((char*)dumpbc);
127
+ }
128
+ else
129
+ {
130
+ loaderInit(srcbytecode);
131
+ }
132
+ vmemDumpShort();
133
+ getchar();
134
+
135
+
136
+ simuInit();
137
+
138
+ VPUSH(INTTOVAL(0));
139
+ interpGo();
140
+ VPULL();
141
+ while(1)
142
+ {
143
+ simuDoLoop();
144
+ VPUSH(VCALLSTACKGET(sys_start,SYS_CBLOOP));
145
+ if (VSTACKGET(0)!=NIL)
146
+ {
147
+ interpGo();
148
+ }
149
+ VPULL();
150
+
151
+ usleep(50 * 1000);
152
+ }
153
+ getchar();
154
+ }
155
+ return 0;
156
+ }
157
+
158
+
159
+ /**
160
+ Retourne une valeur diff�rente de 0 si la cha�ne non vide pass�e en argument
161
+ repr�sente un nombre, 0 sinon
162
+ */
163
+ static int my_is_number(const char *s)
164
+ {
165
+ while ('\0'!=*s && (*s>='0' && *s<='9'))
166
+ {
167
+ s++;
168
+ }
169
+ return (*s == '\0');
170
+ }
171
+
172
+ /**
173
+ G�re les options qui sont pass�es en ligne de commande
174
+ */
175
+ int handle_options(int argc, char **argv)
176
+ {
177
+ int i=1;
178
+ int res=1;
179
+
180
+ while (i<argc)
181
+ {
182
+ if (!strcmp(argv[i], "--help"))
183
+ {
184
+ usage();
185
+ res=0;
186
+ break;
187
+ }
188
+ else if (!strcmp(argv[i], "--mac"))
189
+ {
190
+ ++i;
191
+ if (i>=argc)
192
+ {
193
+ usage();
194
+ return 0;
195
+ }
196
+ PropSet("MAC", argv[i]);
197
+ }
198
+ else if (!strcmp(argv[i], "--boot"))
199
+ {
200
+ PropSet("BOOT", "firmware");
201
+ }
202
+ else if (!strcmp(argv[i], "--source"))
203
+ {
204
+ ++i;
205
+ if (i>=argc)
206
+ {
207
+ usage();
208
+ return 0;
209
+ }
210
+ PropSet("SOURCE", argv[i]);
211
+ }
212
+ else if (!strcmp(argv[i], "--logs"))
213
+ {
214
+ ++i;
215
+ if (i>=argc)
216
+ {
217
+ usage();
218
+ return 0;
219
+ }
220
+ my_printf_set_options(argv[i]);
221
+ }
222
+ else if (!strcmp(argv[i], "--logfile"))
223
+ {
224
+ ++i;
225
+ if (i>=argc)
226
+ {
227
+ usage();
228
+ return 0;
229
+ }
230
+ if (my_printf_set_logfile(argv[i]))
231
+ {
232
+ res=0;
233
+ break;
234
+ }
235
+ }
236
+ else if (!strcmp(argv[i], "--maxlogsize"))
237
+ {
238
+ ++i;
239
+ if (i>=argc || !my_is_number(argv[i]))
240
+ {
241
+ usage();
242
+ return 0;
243
+ }
244
+ my_printf_set_max_log_size(atoi(argv[i]));
245
+ }
246
+ else if (!strcmp(argv[i], "--maxlogtime"))
247
+ {
248
+ ++i;
249
+ if (i>=argc || !my_is_number(argv[i]))
250
+ {
251
+ usage();
252
+ return 0;
253
+ }
254
+ my_printf_set_max_log_time(atoi(argv[i]));
255
+ }
256
+ else if (!strcmp(argv[i], "--dologtime"))
257
+ {
258
+ my_printf_set_do_log_time(1);
259
+ }
260
+ else
261
+ {
262
+ usage();
263
+ res=0;
264
+ break;
265
+ }
266
+ ++i;
267
+ }
268
+
269
+ return res;
270
+ }
271
+
272
+ /**
273
+ Affiche les options disponibles pour le logiciel
274
+ */
275
+ void usage()
276
+ {
277
+ printf("Usage: mtl_simy [--help] [--mac MACADDR] [--boot] [--source SOURCE]\n" \
278
+ " --help: affiche cette aide et quitte\n" \
279
+ " --mac MACADDR: permet de preciser une adresse mac pour le lapin\n" \
280
+ " --boot: comme si on mettait \"BOOT firmware\" dans config.txt\n" \
281
+ " --source SOURCE: compile et charge le bytecode present dans le fichier SOURCE\n" \
282
+ " --logs <log1>,...,<logn>: specifie les types de logs qu'on veut afficher, entre init,vm,simunet,simuleds et simuaudio, separes par des virgules\n" \
283
+ " --logfile <filename>: specifie le fichier dans lequel ecrire les logs du lapin\n" \
284
+ " --maxlogsize <n>: specifie qu'un fichier de log ne peut depasser <n> octets\n" \
285
+ " --maxlogtime <n>: specifie qu'il doit y avoir une rotation du fichier de log au moins toutes les <n> secondes\n" \
286
+ " --dologtime: specifie qu'on doit afficher sur chaque ligne de log le nombre de secondes ecoulees depuis le lancement du simulateur\n" \
287
+ "Toutes les options sont prioritaires sur les valeurs contenues dans config.txt\n");
288
+ }
@@ -0,0 +1,309 @@
1
+ #define PROTORABBIT
2
+ //#define PROTODAL
3
+
4
+ // commenter la ligne suivante pour la version windows
5
+ //#define VMICROCHIP
6
+
7
+ typedef unsigned char uchar;
8
+ typedef unsigned long ulong;
9
+
10
+ #define vub unsigned char
11
+ #define vsb signed char
12
+
13
+ #define vuw unsigned short int
14
+ #define vsw signed short int
15
+
16
+ #define vud unsigned long
17
+ #define vsd signed long
18
+
19
+
20
+ void checkAllEvents(void);
21
+
22
+
23
+ #ifdef PROTORABBIT
24
+ #define VLISP_HARDWARE "NAB2"
25
+ #define NBLED 15
26
+ #define VL_MOTORS
27
+ #define VL_MUSIC
28
+ #define VL_3STATE
29
+ #define NBMOTOR 2
30
+ #endif
31
+
32
+ #ifdef PROTODAL
33
+ #define VLISP_HARDWARE "4"
34
+ #define NBLED 27
35
+ #define VL_PRESS
36
+ #endif
37
+
38
+ #ifdef VMICROCHIP
39
+ int simuInit()
40
+ {
41
+ return 0;
42
+ }
43
+ int simuDoLoop()
44
+ {
45
+ return 0;
46
+ }
47
+ void simuSetLed(vub i,vub val) {}
48
+ void simuSetMotor(vub i,vub val) {}
49
+
50
+ #else
51
+ #include<stdio.h>
52
+ #include<stdlib.h>
53
+ #include<string.h>
54
+ #include<time.h>
55
+
56
+ #include "simuaudio.h"
57
+ #include "simunet.h"
58
+ #include "log.h"
59
+
60
+ // définition de l'échelle d'affichage de la simulation
61
+ #define SCALE 2
62
+
63
+ #define NBHOLES 20
64
+ #define MASKEDHOLES 3
65
+ // MAXMOTORVAL doit être inférieur à 256
66
+ #define MAXMOTORVAL 100
67
+
68
+ int motorwheel[256];
69
+
70
+ // gestion des couleurs
71
+ // ---------------------
72
+ uchar coloradd[256*256];
73
+ uchar colormul[256*256];
74
+
75
+ #define COLORADD(x,y) (coloradd[(x)+((y)<<8)])
76
+ #define COLORMUL(x,y) (colormul[(x)+((y)<<8)])
77
+
78
+ #define RGBTOINT(r,g,b) (( (((int)r)&255)<<16)+((((int)g)&255)<<8)+(((int)b)&255))
79
+ #define INTTOR(c) ((c>>16)&255)
80
+ #define INTTOG(c) ((c>>8)&255)
81
+ #define INTTOB(c) (c&255)
82
+
83
+ // initialisation des tables de couleur
84
+ void colortabInit()
85
+ {
86
+ int i,j,k;
87
+
88
+ for(i=0; i<256; i++)
89
+ for(j=0; j<256; j++)
90
+ {
91
+ k=i+j;
92
+ coloradd[i+(j<<8)]=(k<=255)?k:255;
93
+
94
+ k=i*j/255;
95
+ colormul[i+(j<<8)]=k;
96
+ }
97
+ }
98
+
99
+ // définition physique des leds
100
+
101
+ // en fait il y a NBLED/3 leds, mais on en met 3 fois plus pour
102
+ // pouvoir séparer chacune des composantes rgb de la couleur de chaque
103
+ // led
104
+ int diodeval[NBLED];
105
+ #ifdef VL_MOTORS
106
+ int motorval[NBMOTOR];
107
+ int motorcount[NBMOTOR];
108
+ int motordir[NBMOTOR];
109
+ #endif
110
+
111
+ int xclicsimu=-1;
112
+ int yclicsimu=-1;
113
+ int rclicsimu=0;
114
+ int movesimu=0;
115
+
116
+ int lastmovex=0;
117
+ int lastmovey=0;
118
+
119
+ #ifdef PROTORABBIT
120
+ int diodex[NBLED]= {80,80,80,40,40,40,80,80,80,120,120,120,80,80,80};
121
+ int diodey[NBLED]= {40,40,40,90,90,90,90,90,90,90,90,90,130,130,130};
122
+ int diodergb[NBLED]=
123
+ {
124
+ 0x0000ff,0x00ff00,0xff0000,
125
+ 0x0000ff,0x00ff00,0xff0000,
126
+ 0x0000ff,0x00ff00,0xff0000,
127
+ 0x0000ff,0x00ff00,0xff0000,
128
+ 0x0000ff,0x00ff00,0xff0000
129
+ };
130
+ #endif
131
+
132
+ #ifdef PROTODAL
133
+ int diodex[NBLED]= {40,40,40,80,80,80,120,120,120,40,40,40,80,80,80,120,120,120,40,40,40,80,80,80,120,120,120};
134
+ int diodey[NBLED]= {40,40,40,40,40,40,40,40,40,80,80,80,80,80,80,80,80,80,120,120,120,120,120,120,120,120,120};
135
+ int diodergb[NBLED]=
136
+ {
137
+ 0x0000ff,0x00ff00,0xff0000,
138
+ 0x0000ff,0x00ff00,0xff0000,
139
+ 0x0000ff,0x00ff00,0xff0000,
140
+ 0x0000ff,0x00ff00,0xff0000,
141
+ 0x0000ff,0x00ff00,0xff0000,
142
+ 0x0000ff,0x00ff00,0xff0000,
143
+ 0x0000ff,0x00ff00,0xff0000,
144
+ 0x0000ff,0x00ff00,0xff0000,
145
+ 0x0000ff,0x00ff00,0xff0000
146
+ };
147
+ #endif
148
+
149
+
150
+ // TODO
151
+ int getButton()
152
+ {
153
+ return 0;
154
+ }
155
+
156
+ // fonction d'affichage des diodes
157
+ int simuDisplay(int* intensity)
158
+ {
159
+ // TODO afficher l'état du lapin
160
+ return 0;
161
+ }
162
+
163
+
164
+ // initialisation du simulateur
165
+ vsd simuInit()
166
+ {
167
+ int i;
168
+ colortabInit();
169
+
170
+ for(i=0; i<NBLED; i++)
171
+ {
172
+ diodeval[i]=255;
173
+ }
174
+ srand(clock());
175
+ #ifdef VL_MOTORS
176
+ for(i=0; i<NBMOTOR; i++)
177
+ {
178
+ motorval[i]=60;//(rand()&255)*MAXMOTORVAL/256;
179
+ motorcount[i]=motordir[i]=0;
180
+ }
181
+ for(i=0; i<256; i++)
182
+ {
183
+ motorwheel[i]=0;
184
+ }
185
+ for(i=0; i<MAXMOTORVAL; i++)
186
+ {
187
+ if ((i*2*NBHOLES/MAXMOTORVAL)&1)
188
+ {
189
+ motorwheel[i]=1;
190
+ }
191
+ if (i*NBHOLES/MAXMOTORVAL>=NBHOLES-MASKEDHOLES)
192
+ {
193
+ motorwheel[i]=1;
194
+ }
195
+ }
196
+ #endif
197
+ // setButton(1);
198
+ simuaudioinit();
199
+ simunetinit();
200
+ return 0;
201
+ }
202
+
203
+
204
+
205
+ // fonction à appeler régulièrement, pour traiter les messages de la fenêtre du simulateur
206
+ vsd simuDoLoop()
207
+ {
208
+ #ifdef VL_MOTORS
209
+ int i,last;
210
+ #endif
211
+
212
+ checkAllEvents();
213
+
214
+ #ifdef VL_MOTORS
215
+ for(i=0; i<NBMOTOR; i++)
216
+ {
217
+ last=motorwheel[motorval[i]];
218
+ if (1)
219
+ {
220
+ motorval[i]+=motordir[i];
221
+ }
222
+ if (motorval[i]<0)
223
+ {
224
+ motorval[i]+=MAXMOTORVAL;
225
+ }
226
+ if (motorval[i]>=MAXMOTORVAL)
227
+ {
228
+ motorval[i]-=MAXMOTORVAL;
229
+ }
230
+ if (last<motorwheel[motorval[i]])
231
+ {
232
+ motorcount[i]++;
233
+ }
234
+ }
235
+ #endif
236
+ simuDisplay(diodeval);
237
+ return 0;
238
+ }
239
+
240
+
241
+ /**
242
+ Vérifie tous les évènements et fait les actions appropriées
243
+ */
244
+ void checkAllEvents(void)
245
+ {
246
+ checkNetworkEvents();
247
+ }
248
+
249
+
250
+ // réglagle d'une led
251
+ void simuSetLed(int i,int val)
252
+ {
253
+ i*=3;
254
+ if ((i<0)||(i>=NBLED))
255
+ {
256
+ return;
257
+ }
258
+ diodeval[i]=(val>>16)&255;
259
+ diodeval[i+1]=(val>>8)&255;
260
+ diodeval[i+2]=(val)&255;
261
+
262
+ my_printf(LOG_SIMULEDS, "Setting led %d: [%d %d %d]\n", i/3, diodeval[i], diodeval[i+1], diodeval[i+2]);
263
+ my_printf(LOG_SIMULEDS, "All leds state:", i/3, diodeval[i], diodeval[i+1], diodeval[i+2]);
264
+ for (i=0; i<NBLED/3; ++i)
265
+ {
266
+ my_printf(LOG_SIMULEDS, " [%3d %3d %3d]", diodeval[3*i], diodeval[3*i+1], diodeval[3*i+2]);
267
+ }
268
+ my_printf(LOG_SIMULEDS, "\n");
269
+ }
270
+
271
+ #ifdef VL_MOTORS
272
+ // réglagle d'un moteur
273
+ void set_motor_dir(int num_motor, int sens)
274
+ {
275
+ int tmp_num, tmp_sens;
276
+ tmp_num = num_motor?1:0;
277
+ tmp_sens = (sens==0)?0:((sens==1)?1:-1);
278
+ motordir[tmp_num]=tmp_sens;
279
+
280
+ my_printf(LOG_SIMUMOTORS, "Setting motor %d, direction %d (pos: %d)\n", tmp_num, tmp_sens);
281
+ }
282
+
283
+ int get_motor_val(int i)
284
+ {
285
+ int tmp_num = i?1:0;
286
+ my_printf(LOG_SIMUMOTORS, "Getting value for motor %d: %d\n", tmp_num, motorcount[tmp_num]);
287
+ return motorcount[tmp_num];
288
+ }
289
+ #else
290
+ int get_motor_val(int i)
291
+ {
292
+ return 128;
293
+ }
294
+ #endif
295
+
296
+ int get_button3()
297
+ {
298
+ // TODO
299
+ return 0;
300
+ }
301
+
302
+ char buf_rfid[256];
303
+
304
+ char* get_rfid()
305
+ {
306
+ // TODO
307
+ return NULL;
308
+ }
309
+ #endif
@@ -0,0 +1,44 @@
1
+ #include <stdio.h>
2
+
3
+ #include "log.h"
4
+
5
+ #define A() my_printf(LOG_SIMUAUDIO, "[[%s]]\n", __func__);
6
+
7
+ int simuaudioinit()
8
+ {
9
+ A();
10
+ return 0;
11
+ }
12
+
13
+ int PlayStart()
14
+ {
15
+ A();
16
+ return 0;
17
+ }
18
+ int PlayStop()
19
+ {
20
+ A();
21
+ return 0;
22
+ }
23
+ int PlayEof()
24
+ {
25
+ A();
26
+ return 0;
27
+ }
28
+
29
+ int RecStart(int rate,int ChannelSize,int nbBuffers)
30
+ {
31
+ A();
32
+ return 0;
33
+ }
34
+ int RecStop()
35
+ {
36
+ A();
37
+ return 0;
38
+ }
39
+
40
+ void audioSetVolume(int vol)
41
+ {
42
+ A();
43
+ return ;
44
+ }