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 @@
1
+ # nothing to here as gem process will execute `make` and `make install`
@@ -0,0 +1,271 @@
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(){ return 0;}
40
+ int simuDoLoop(){ return 0;}
41
+ void simuSetLed(vub i,vub val){}
42
+ void simuSetMotor(vub i,vub val){}
43
+
44
+ #else
45
+ #include<stdio.h>
46
+ #include<stdlib.h>
47
+ #include<string.h>
48
+ #include<time.h>
49
+
50
+ #include "linux_simuaudio.h"
51
+ #include "linux_simunet.h"
52
+ #include "log.h"
53
+
54
+ // définition de l'échelle d'affichage de la simulation
55
+ #define SCALE 2
56
+
57
+ #define NBHOLES 20
58
+ #define MASKEDHOLES 3
59
+ // MAXMOTORVAL doit être inférieur à 256
60
+ #define MAXMOTORVAL 100
61
+
62
+ int motorwheel[256];
63
+
64
+ // gestion des couleurs
65
+ // ---------------------
66
+ uchar coloradd[256*256];
67
+ uchar colormul[256*256];
68
+
69
+ #define COLORADD(x,y) (coloradd[(x)+((y)<<8)])
70
+ #define COLORMUL(x,y) (colormul[(x)+((y)<<8)])
71
+
72
+ #define RGBTOINT(r,g,b) (( (((int)r)&255)<<16)+((((int)g)&255)<<8)+(((int)b)&255))
73
+ #define INTTOR(c) ((c>>16)&255)
74
+ #define INTTOG(c) ((c>>8)&255)
75
+ #define INTTOB(c) (c&255)
76
+
77
+ // initialisation des tables de couleur
78
+ void colortabInit()
79
+ {
80
+ int i,j,k;
81
+
82
+ for(i=0;i<256;i++)
83
+ for(j=0;j<256;j++)
84
+ {
85
+ k=i+j;
86
+ coloradd[i+(j<<8)]=(k<=255)?k:255;
87
+
88
+ k=i*j/255;
89
+ colormul[i+(j<<8)]=k;
90
+ }
91
+ }
92
+
93
+ // définition physique des leds
94
+
95
+ // en fait il y a NBLED/3 leds, mais on en met 3 fois plus pour
96
+ // pouvoir séparer chacune des composantes rgb de la couleur de chaque
97
+ // led
98
+ int diodeval[NBLED];
99
+ #ifdef VL_MOTORS
100
+ int motorval[NBMOTOR];
101
+ int motorcount[NBMOTOR];
102
+ int motordir[NBMOTOR];
103
+ #endif
104
+
105
+ int xclicsimu=-1;
106
+ int yclicsimu=-1;
107
+ int rclicsimu=0;
108
+ int movesimu=0;
109
+
110
+ int lastmovex=0;
111
+ int lastmovey=0;
112
+
113
+ #ifdef PROTORABBIT
114
+ int diodex[NBLED]={80,80,80,40,40,40,80,80,80,120,120,120,80,80,80};
115
+ int diodey[NBLED]={40,40,40,90,90,90,90,90,90,90,90,90,130,130,130};
116
+ int diodergb[NBLED]=
117
+ {0x0000ff,0x00ff00,0xff0000,
118
+ 0x0000ff,0x00ff00,0xff0000,
119
+ 0x0000ff,0x00ff00,0xff0000,
120
+ 0x0000ff,0x00ff00,0xff0000,
121
+ 0x0000ff,0x00ff00,0xff0000
122
+ };
123
+ #endif
124
+
125
+ #ifdef PROTODAL
126
+ 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};
127
+ 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};
128
+ int diodergb[NBLED]=
129
+ {0x0000ff,0x00ff00,0xff0000,
130
+ 0x0000ff,0x00ff00,0xff0000,
131
+ 0x0000ff,0x00ff00,0xff0000,
132
+ 0x0000ff,0x00ff00,0xff0000,
133
+ 0x0000ff,0x00ff00,0xff0000,
134
+ 0x0000ff,0x00ff00,0xff0000,
135
+ 0x0000ff,0x00ff00,0xff0000,
136
+ 0x0000ff,0x00ff00,0xff0000,
137
+ 0x0000ff,0x00ff00,0xff0000
138
+ };
139
+ #endif
140
+
141
+
142
+ // TODO
143
+ int getButton() { return 0; }
144
+
145
+ // fonction d'affichage des diodes
146
+ int simuDisplay(int* intensity)
147
+ {
148
+ // TODO afficher l'état du lapin
149
+ return 0;
150
+ }
151
+
152
+
153
+ // initialisation du simulateur
154
+ vsd simuInit()
155
+ {
156
+ int i;
157
+ colortabInit();
158
+
159
+ for(i=0;i<NBLED;i++) diodeval[i]=255;
160
+ srand(clock());
161
+ #ifdef VL_MOTORS
162
+ for(i=0;i<NBMOTOR;i++)
163
+ {
164
+ motorval[i]=60;//(rand()&255)*MAXMOTORVAL/256;
165
+ motorcount[i]=motordir[i]=0;
166
+ }
167
+ for(i=0;i<256;i++) motorwheel[i]=0;
168
+ for(i=0;i<MAXMOTORVAL;i++)
169
+ {
170
+ if ((i*2*NBHOLES/MAXMOTORVAL)&1) motorwheel[i]=1;
171
+ if (i*NBHOLES/MAXMOTORVAL>=NBHOLES-MASKEDHOLES) motorwheel[i]=1;
172
+ }
173
+ #endif
174
+ // setButton(1);
175
+ simuaudioinit();
176
+ simunetinit();
177
+ return 0;
178
+ }
179
+
180
+
181
+
182
+ // fonction à appeler régulièrement, pour traiter les messages de la fenêtre du simulateur
183
+ vsd simuDoLoop()
184
+ {
185
+ #ifdef VL_MOTORS
186
+ int i,last;
187
+ #endif
188
+
189
+ checkAllEvents();
190
+
191
+ #ifdef VL_MOTORS
192
+ for(i=0;i<NBMOTOR;i++)
193
+ {
194
+ last=motorwheel[motorval[i]];
195
+ if (1) motorval[i]+=motordir[i];
196
+ if (motorval[i]<0) motorval[i]+=MAXMOTORVAL;
197
+ if (motorval[i]>=MAXMOTORVAL) motorval[i]-=MAXMOTORVAL;
198
+ if (last<motorwheel[motorval[i]]) motorcount[i]++;
199
+ }
200
+ #endif
201
+ simuDisplay(diodeval);
202
+ return 0;
203
+ }
204
+
205
+
206
+ /**
207
+ Vérifie tous les évènements et fait les actions appropriées
208
+ */
209
+ void checkAllEvents(void)
210
+ {
211
+ checkNetworkEvents();
212
+ }
213
+
214
+
215
+ // réglagle d'une led
216
+ void simuSetLed(int i,int val)
217
+ {
218
+ i*=3;
219
+ if ((i<0)||(i>=NBLED)) return;
220
+ diodeval[i]=(val>>16)&255;
221
+ diodeval[i+1]=(val>>8)&255;
222
+ diodeval[i+2]=(val)&255;
223
+
224
+ my_printf(LOG_SIMULEDS, "Setting led %d: [%d %d %d]\n", i/3, diodeval[i], diodeval[i+1], diodeval[i+2]);
225
+ my_printf(LOG_SIMULEDS, "All leds state:", i/3, diodeval[i], diodeval[i+1], diodeval[i+2]);
226
+ for (i=0; i<NBLED/3; ++i)
227
+ {
228
+ my_printf(LOG_SIMULEDS, " [%3d %3d %3d]", diodeval[3*i], diodeval[3*i+1], diodeval[3*i+2]);
229
+ }
230
+ my_printf(LOG_SIMULEDS, "\n");
231
+ }
232
+
233
+ #ifdef VL_MOTORS
234
+ // réglagle d'un moteur
235
+ void set_motor_dir(int num_motor, int sens)
236
+ {
237
+ int tmp_num, tmp_sens;
238
+ tmp_num = num_motor?1:0;
239
+ tmp_sens = (sens==0)?0:((sens==1)?1:-1);
240
+ motordir[tmp_num]=tmp_sens;
241
+
242
+ my_printf(LOG_SIMUMOTORS, "Setting motor %d, direction %d (pos: %d)\n", tmp_num, tmp_sens);
243
+ }
244
+
245
+ int get_motor_val(int i)
246
+ {
247
+ int tmp_num = i?1:0;
248
+ my_printf(LOG_SIMUMOTORS, "Getting value for motor %d: %d\n", tmp_num, motorcount[tmp_num]);
249
+ return motorcount[tmp_num];
250
+ }
251
+ #else
252
+ int get_motor_val(int i)
253
+ {
254
+ return 128;
255
+ }
256
+ #endif
257
+
258
+ int get_button3()
259
+ {
260
+ // TODO
261
+ return 0;
262
+ }
263
+
264
+ char buf_rfid[256];
265
+
266
+ char* get_rfid()
267
+ {
268
+ // TODO
269
+ return NULL;
270
+ }
271
+ #endif
@@ -0,0 +1,16 @@
1
+ #include <stdio.h>
2
+
3
+ #include "log.h"
4
+
5
+ #define A() my_printf(LOG_SIMUAUDIO, "[[%s]]\n", __func__);
6
+
7
+ int simuaudioinit() { A(); return 0; }
8
+
9
+ int PlayStart() { A(); return 0; }
10
+ int PlayStop() { A(); return 0; }
11
+ int PlayEof() { A(); return 0; }
12
+
13
+ int RecStart(int rate,int ChannelSize,int nbBuffers) { A(); return 0; }
14
+ int RecStop() { A(); return 0; }
15
+
16
+ void audioSetVolume(int vol) { A(); return ; }
@@ -0,0 +1,18 @@
1
+ #ifndef MY_SIMUAUDIO_H_
2
+ # define MY_SIMUAUDIO_H_
3
+
4
+ int PlayStart();
5
+ int PlayStop();
6
+ int PlayEof();
7
+
8
+ int RecStart(int rate,int ChannelSize,int nbBuffers);
9
+ int RecStop();
10
+ int RecData(int i);
11
+
12
+ int audioEventPlayData(int eventId, int wParam, int lParam);
13
+ int audioEventRecData(int eventId, int wParam, int lParam);
14
+ void audioSetVolume(int vol);
15
+ int simuaudioinit();
16
+
17
+
18
+ #endif // ! MY_SIMUAUDIO_H_