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
@@ -0,0 +1,258 @@
1
+ //#ifdef HAVEGTK
2
+ #include <stdlib.h>
3
+ #include <stdio.h>
4
+
5
+ #include "mpg123.h"
6
+ #include "mpglib.h"
7
+
8
+
9
+ /* Global mp .. it's a hack */
10
+ struct mpstr *gmp;
11
+
12
+
13
+ BOOL InitMP3(struct mpstr *mp)
14
+ {
15
+ memset(mp,0,sizeof(struct mpstr));
16
+
17
+ mp->framesize = 0;
18
+ mp->fsizeold = -1;
19
+ mp->bsize = 0;
20
+ mp->head = mp->tail = NULL;
21
+ mp->fr.single = -1;
22
+ mp->bsnum = 0;
23
+ mp->synth_bo = 1;
24
+
25
+ make_decode_tables(32767);
26
+ init_layer3(SBLIMIT);
27
+
28
+ return !0;
29
+ }
30
+
31
+ void ExitMP3(struct mpstr *mp)
32
+ {
33
+ struct buf *b,*bn;
34
+
35
+ b = mp->tail;
36
+ while(b) {
37
+ free(b->pnt);
38
+ bn = b->next;
39
+ free(b);
40
+ b = bn;
41
+ }
42
+ }
43
+
44
+ static struct buf *addbuf(struct mpstr *mp,char *buf,int size)
45
+ {
46
+ struct buf *nbuf;
47
+
48
+ nbuf = malloc( sizeof(struct buf) );
49
+ if(!nbuf) {
50
+ fprintf(stderr,"Out of memory!\n");
51
+ return NULL;
52
+ }
53
+ nbuf->pnt = malloc(size);
54
+ if(!nbuf->pnt) {
55
+ free(nbuf);
56
+ return NULL;
57
+ }
58
+ nbuf->size = size;
59
+ memcpy(nbuf->pnt,buf,size);
60
+ nbuf->next = NULL;
61
+ nbuf->prev = mp->head;
62
+ nbuf->pos = 0;
63
+
64
+ if(!mp->tail) {
65
+ mp->tail = nbuf;
66
+ }
67
+ else {
68
+ mp->head->next = nbuf;
69
+ }
70
+
71
+ mp->head = nbuf;
72
+ mp->bsize += size;
73
+
74
+ return nbuf;
75
+ }
76
+
77
+ static void remove_buf(struct mpstr *mp)
78
+ {
79
+ struct buf *buf = mp->tail;
80
+
81
+ mp->tail = buf->next;
82
+ if(mp->tail)
83
+ mp->tail->prev = NULL;
84
+ else {
85
+ mp->tail = mp->head = NULL;
86
+ }
87
+
88
+ free(buf->pnt);
89
+ free(buf);
90
+
91
+ }
92
+
93
+ static int read_buf_byte(struct mpstr *mp)
94
+ {
95
+ unsigned int b;
96
+
97
+ int pos;
98
+
99
+ pos = mp->tail->pos;
100
+ while(pos >= mp->tail->size) {
101
+ remove_buf(mp);
102
+ pos = mp->tail->pos;
103
+ if(!mp->tail) {
104
+ fprintf(stderr,"Fatal error!\n");
105
+ // exit(1);
106
+ return 0;
107
+ }
108
+ }
109
+
110
+ b = mp->tail->pnt[pos];
111
+ mp->bsize--;
112
+ mp->tail->pos++;
113
+
114
+
115
+ return b;
116
+ }
117
+
118
+ static void read_head(struct mpstr *mp)
119
+ {
120
+ unsigned long head;
121
+
122
+ mp->header<<=8;
123
+ head = read_buf_byte(mp);
124
+ mp->header+=(head&255);
125
+
126
+ /* head <<= 8;
127
+ head |= read_buf_byte(mp);
128
+ head <<= 8;
129
+ head |= read_buf_byte(mp);
130
+ head <<= 8;
131
+ head |= read_buf_byte(mp);
132
+
133
+ mp->header = head;
134
+ */
135
+ }
136
+
137
+ int checkmp3header(head)
138
+ {
139
+ if (
140
+ ((head & 0xffe00000) == 0xffe00000)
141
+ &&((head>>17)&3)
142
+ &&(((head>>12)&0xf) != 0xf)
143
+ &&(((head>>10)&0x3) != 0x3 )
144
+ &&((4-((head>>17)&3)) == 3)
145
+ ) return 1;
146
+ return 0;
147
+ }
148
+
149
+ int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,int osize,int *done)
150
+ {
151
+ int len;
152
+
153
+ gmp = mp;
154
+
155
+ if(osize < 4608)
156
+ {
157
+ fprintf(stderr,"To less out space\n");
158
+ return MP3_ERR;
159
+ }
160
+
161
+ if(in)
162
+ {
163
+ if(addbuf(mp,in,isize) == NULL)
164
+ {
165
+ return MP3_ERR;
166
+ }
167
+ }
168
+
169
+
170
+ /* First decode header */
171
+ while(mp->framesize == 0)
172
+ {
173
+ if(mp->bsize < 1)
174
+ {
175
+ return MP3_NEED_MORE;
176
+ }
177
+ read_head(mp);
178
+ if ((checkmp3header(mp->header))&&(decode_header(&mp->fr,mp->header)==1))
179
+ {
180
+ mp->framesize = mp->fr.framesize;
181
+ }
182
+ }
183
+ /*
184
+ if(mp->framesize == 0)
185
+ {
186
+ if(mp->bsize < 4)
187
+ {
188
+ return MP3_NEED_MORE;
189
+ }
190
+ read_head(mp);
191
+ decode_header(&mp->fr,mp->header);
192
+ mp->framesize = mp->fr.framesize;
193
+ }
194
+ */
195
+ /* printf(" fr.framesize = %i \n",mp->fr.framesize);
196
+ printf(" bsize = %i \n",mp->bsize);
197
+ */
198
+
199
+ if(mp->fr.framesize > mp->bsize)
200
+ {
201
+ return MP3_NEED_MORE;
202
+ }
203
+ wordpointer = mp->bsspace[mp->bsnum] + 512;
204
+ mp->bsnum = (mp->bsnum + 1) & 0x1;
205
+ bitindex = 0;
206
+
207
+ len = 0;
208
+ while(len < mp->framesize)
209
+ {
210
+ int nlen;
211
+ int blen = mp->tail->size - mp->tail->pos;
212
+ if( (mp->framesize - len) <= blen)
213
+ {
214
+ nlen = mp->framesize-len;
215
+ }
216
+ else
217
+ {
218
+ nlen = blen;
219
+ }
220
+ memcpy(wordpointer+len,mp->tail->pnt+mp->tail->pos,nlen);
221
+ len += nlen;
222
+ mp->tail->pos += nlen;
223
+ mp->bsize -= nlen;
224
+ if(mp->tail->pos == mp->tail->size)
225
+ {
226
+ remove_buf(mp);
227
+ }
228
+ }
229
+
230
+ *done = 0;
231
+ if(mp->fr.error_protection)
232
+ getbits(16);
233
+ do_layer3(&mp->fr,(unsigned char *) out,done);
234
+
235
+ mp->fsizeold = mp->framesize;
236
+ mp->framesize = 0;
237
+ return MP3_OK;
238
+ }
239
+
240
+ int set_pointer(long backstep)
241
+ {
242
+ unsigned char *bsbufold;
243
+ if(gmp->fsizeold < 0 && backstep > 0) {
244
+ fprintf(stderr,"Can't step back %ld!\n",backstep);
245
+ return MP3_ERR;
246
+ }
247
+ bsbufold = gmp->bsspace[gmp->bsnum] + 512;
248
+ wordpointer -= backstep;
249
+ if (backstep)
250
+ memcpy(wordpointer,bsbufold+gmp->fsizeold-backstep,backstep);
251
+ bitindex = 0;
252
+ return MP3_OK;
253
+ }
254
+
255
+ //#endif
256
+
257
+
258
+
@@ -0,0 +1,182 @@
1
+ #include <stdio.h>
2
+ #include <string.h>
3
+ #include <signal.h>
4
+
5
+ #ifndef WIN32
6
+ #include <sys/signal.h>
7
+ #include <unistd.h>
8
+ #endif
9
+
10
+ #include <math.h>
11
+
12
+ #ifdef _WIN32
13
+ # undef WIN32
14
+ # define WIN32
15
+
16
+ # define M_PI 3.14159265358979323846
17
+ # define M_SQRT2 1.41421356237309504880
18
+ # define REAL_IS_FLOAT
19
+ # define NEW_DCT9
20
+
21
+ # define random rand
22
+ # define srandom srand
23
+
24
+ #endif
25
+
26
+ #ifdef REAL_IS_FLOAT
27
+ # define real float
28
+ #elif defined(REAL_IS_LONG_DOUBLE)
29
+ # define real long double
30
+ #else
31
+ # define real double
32
+ #endif
33
+
34
+ #ifdef __GNUC__
35
+ #define INLINE inline
36
+ #else
37
+ #define INLINE
38
+ #endif
39
+
40
+ /* AUDIOBUFSIZE = n*64 with n=1,2,3 ... */
41
+ #define AUDIOBUFSIZE 16384
42
+
43
+ #define FALSE 0
44
+ #define TRUE 1
45
+
46
+ #define SBLIMIT 32
47
+ #define SSLIMIT 18
48
+
49
+ #define MPG_MD_STEREO 0
50
+ #define MPG_MD_JOINT_STEREO 1
51
+ #define MPG_MD_DUAL_CHANNEL 2
52
+ #define MPG_MD_MONO 3
53
+
54
+ #define MAXFRAMESIZE 1792
55
+
56
+
57
+ /* Pre Shift fo 16 to 8 bit converter table */
58
+ #define AUSHIFT (3)
59
+
60
+ extern int tabsel_123[2][3][16];
61
+
62
+ struct frame {
63
+ int stereo;
64
+ int jsbound;
65
+ int single;
66
+ int lsf;
67
+ int mpeg25;
68
+ int header_change;
69
+ int lay;
70
+ int error_protection;
71
+ int bitrate_index;
72
+ int sampling_frequency;
73
+ int padding;
74
+ int extension;
75
+ int mode;
76
+ int mode_ext;
77
+ int copyright;
78
+ int original;
79
+ int emphasis;
80
+ int framesize; /* computed framesize */
81
+ };
82
+
83
+ struct parameter {
84
+ int quiet; /* shut up! */
85
+ int tryresync; /* resync stream after error */
86
+ int verbose; /* verbose level */
87
+ int checkrange;
88
+ };
89
+
90
+ /* extern unsigned int get1bit(void); */
91
+ extern unsigned int getbits(int);
92
+ extern unsigned int getbits_fast(int);
93
+ extern int set_pointer(long);
94
+
95
+ extern unsigned char *wordpointer;
96
+ extern int bitindex;
97
+
98
+ extern void make_decode_tables(long scaleval);
99
+ extern int do_layer3(struct frame *fr,unsigned char *,int *);
100
+ extern int decode_header(struct frame *fr,unsigned long newhead);
101
+
102
+
103
+
104
+ struct gr_info_s {
105
+ int scfsi;
106
+ unsigned part2_3_length;
107
+ unsigned big_values;
108
+ unsigned scalefac_compress;
109
+ unsigned block_type;
110
+ unsigned mixed_block_flag;
111
+ unsigned table_select[3];
112
+ unsigned subblock_gain[3];
113
+ unsigned maxband[3];
114
+ unsigned maxbandl;
115
+ unsigned maxb;
116
+ unsigned region1start;
117
+ unsigned region2start;
118
+ unsigned preflag;
119
+ unsigned scalefac_scale;
120
+ unsigned count1table_select;
121
+ real *full_gain[3];
122
+ real *pow2gain;
123
+ };
124
+
125
+ struct III_sideinfo
126
+ {
127
+ unsigned main_data_begin;
128
+ unsigned private_bits;
129
+ struct {
130
+ struct gr_info_s gr[2];
131
+ } ch[2];
132
+ };
133
+
134
+ extern int synth_1to1 (real *,int,unsigned char *,int *);
135
+ extern int synth_1to1_8bit (real *,int,unsigned char *,int *);
136
+ extern int synth_1to1_mono (real *,unsigned char *,int *);
137
+ extern int synth_1to1_mono2stereo (real *,unsigned char *,int *);
138
+ extern int synth_1to1_8bit_mono (real *,unsigned char *,int *);
139
+ extern int synth_1to1_8bit_mono2stereo (real *,unsigned char *,int *);
140
+
141
+ extern int synth_2to1 (real *,int,unsigned char *,int *);
142
+ extern int synth_2to1_8bit (real *,int,unsigned char *,int *);
143
+ extern int synth_2to1_mono (real *,unsigned char *,int *);
144
+ extern int synth_2to1_mono2stereo (real *,unsigned char *,int *);
145
+ extern int synth_2to1_8bit_mono (real *,unsigned char *,int *);
146
+ extern int synth_2to1_8bit_mono2stereo (real *,unsigned char *,int *);
147
+
148
+ extern int synth_4to1 (real *,int,unsigned char *,int *);
149
+ extern int synth_4to1_8bit (real *,int,unsigned char *,int *);
150
+ extern int synth_4to1_mono (real *,unsigned char *,int *);
151
+ extern int synth_4to1_mono2stereo (real *,unsigned char *,int *);
152
+ extern int synth_4to1_8bit_mono (real *,unsigned char *,int *);
153
+ extern int synth_4to1_8bit_mono2stereo (real *,unsigned char *,int *);
154
+
155
+ extern int synth_ntom (real *,int,unsigned char *,int *);
156
+ extern int synth_ntom_8bit (real *,int,unsigned char *,int *);
157
+ extern int synth_ntom_mono (real *,unsigned char *,int *);
158
+ extern int synth_ntom_mono2stereo (real *,unsigned char *,int *);
159
+ extern int synth_ntom_8bit_mono (real *,unsigned char *,int *);
160
+ extern int synth_ntom_8bit_mono2stereo (real *,unsigned char *,int *);
161
+
162
+ extern void rewindNbits(int bits);
163
+ extern int hsstell(void);
164
+ extern int get_songlen(struct frame *fr,int no);
165
+
166
+ extern void init_layer3(int);
167
+ extern void init_layer2(void);
168
+ extern void make_decode_tables(long scale);
169
+ extern void make_conv16to8_table(int);
170
+ extern void dct64(real *,real *,real *);
171
+
172
+ extern void synth_ntom_set_step(long,long);
173
+
174
+ extern unsigned char *conv16to8;
175
+ extern long freqs[9];
176
+ extern real muls[27][64];
177
+ extern real decwin[512+32];
178
+ extern real *pnts[5];
179
+
180
+ extern struct parameter param;
181
+
182
+
@@ -0,0 +1,44 @@
1
+
2
+ struct buf {
3
+ unsigned char *pnt;
4
+ long size;
5
+ long pos;
6
+ struct buf *next;
7
+ struct buf *prev;
8
+ };
9
+
10
+ struct framebuf {
11
+ struct buf *buf;
12
+ long pos;
13
+ struct frame *next;
14
+ struct frame *prev;
15
+ };
16
+
17
+ struct mpstr {
18
+ struct buf *head,*tail;
19
+ int bsize;
20
+ int framesize;
21
+ int fsizeold;
22
+ struct frame fr;
23
+ unsigned char bsspace[2][MAXFRAMESIZE+512]; /* MAXFRAMESIZE */
24
+ real hybrid_block[2][2][SBLIMIT*SSLIMIT];
25
+ int hybrid_blc[2];
26
+ unsigned long header;
27
+ int bsnum;
28
+ real synth_buffs[2][2][0x110];
29
+ int synth_bo;
30
+
31
+ };
32
+
33
+ #define BOOL int
34
+
35
+ #define MP3_ERR -1
36
+ #define MP3_OK 0
37
+ #define MP3_NEED_MORE 1
38
+
39
+
40
+ BOOL InitMP3(struct mpstr *mp);
41
+ int decodeMP3(struct mpstr *mp,char *inmemory,int inmemsize,
42
+ char *outmemory,int outmemsize,int *done);
43
+ void ExitMP3(struct mpstr *mp);
44
+