line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Device::MindWave::Tester; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1867
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
110
|
|
4
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
89
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
2693
|
use IO::File; |
|
3
|
|
|
|
|
7052
|
|
|
3
|
|
|
|
|
455
|
|
7
|
3
|
|
|
3
|
|
23
|
use Device::MindWave::Utils qw(packet_to_bytes); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1001
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new |
10
|
|
|
|
|
|
|
{ |
11
|
3
|
|
|
3
|
1
|
1306
|
my $class = shift; |
12
|
3
|
|
|
|
|
890
|
my $self = { buffer => IO::File->new_tmpfile(), |
13
|
|
|
|
|
|
|
read_index => 0, |
14
|
|
|
|
|
|
|
write_index => 0 }; |
15
|
3
|
|
|
|
|
11
|
bless $self, $class; |
16
|
3
|
|
|
|
|
15
|
return $self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub push_packet |
20
|
|
|
|
|
|
|
{ |
21
|
87
|
|
|
87
|
1
|
248
|
my ($self, $packet) = @_; |
22
|
|
|
|
|
|
|
|
23
|
87
|
|
|
|
|
306
|
return $self->push_bytes(packet_to_bytes($packet)); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub push_bytes |
27
|
|
|
|
|
|
|
{ |
28
|
94
|
|
|
94
|
1
|
5280
|
my ($self, $bytes) = @_; |
29
|
|
|
|
|
|
|
|
30
|
94
|
|
|
|
|
624
|
$self->{'buffer'}->seek($self->{'write_index'}, 0); |
31
|
94
|
|
|
|
|
1493
|
for my $byte (@{$bytes}) { |
|
94
|
|
|
|
|
171
|
|
32
|
2654
|
|
|
|
|
22931
|
$self->{'buffer'}->syswrite(chr $byte); |
33
|
2654
|
|
|
|
|
43347
|
$self->{'write_index'}++; |
34
|
|
|
|
|
|
|
} |
35
|
94
|
|
|
|
|
353
|
$self->{'buffer'}->flush(); |
36
|
|
|
|
|
|
|
|
37
|
94
|
|
|
|
|
283
|
return 1; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub read |
41
|
|
|
|
|
|
|
{ |
42
|
2460
|
|
|
2460
|
1
|
2884
|
my $self = $_[0]; |
43
|
|
|
|
|
|
|
|
44
|
2460
|
|
|
|
|
6683
|
$self->{'buffer'}->seek($self->{'read_index'}, 0); |
45
|
2460
|
|
|
|
|
31692
|
my $bytes = $self->{'buffer'}->read($_[1], $_[2], 0); |
46
|
2460
|
|
|
|
|
27391
|
$self->{'read_index'} += $bytes; |
47
|
2460
|
|
|
|
|
5621
|
return $bytes; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub write |
51
|
|
|
|
|
|
|
{ |
52
|
16
|
|
|
16
|
1
|
35
|
return 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |