-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmessages.js
More file actions
133 lines (119 loc) · 3.41 KB
/
Copy pathmessages.js
File metadata and controls
133 lines (119 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*jshint expr: true*/
var chai = require('chai'),
expect = chai.expect,
sinon = require('sinon'),
Wii = require('../../');
chai.use(require('sinon-chai'));
describe('\u2b50 messages', function () {
var proxyConnection, sandbox, wii;
beforeEach(function () {
proxyConnection = {
on: sinon.stub(),
removeListener: sinon.stub(),
write: sinon.stub(),
close: sinon.spy()
};
sandbox = sinon.sandbox.create();
wii = new Wii(proxyConnection);
});
afterEach(function () {
sandbox.restore();
});
describe('ident', function () {
it('parses the message correctly', function () {
var listener = sinon.spy();
wii.on('ident', listener);
proxyConnection.on.withArgs('data').yield(new Buffer([0, 0, 0, 7, 100, 2, 1, 1, 0, 0, 0, 0]));
expect(listener).calledWith({
version: 2,
multitype: 'TRI',
mspVersion: 1,
capability: 0
});
});
});
describe('rc', function () {
it('sends the read command correctly', function () {
sinon.stub(wii, 'send');
wii.read('rc');
expect(wii.send).calledWith(105);
wii.send.restore();
});
it('parses the message correctly', function () {
var listener = sinon.spy();
wii.on('rc', listener);
proxyConnection.on.withArgs('data').yield(new Buffer([0, 0, 0, 16, 105,
0, 1, // roll
1, 1, // pitch
2, 1, // yaw
3, 1, // throttle
4, 1, // aux1
5, 1, // aux2
6, 1, // aux3
7, 1 // aux4
]));
expect(listener).calledWith({
roll: 256,
pitch: 257,
yaw: 258,
throttle: 259,
aux1: 260,
aux2: 261,
aux3: 262,
aux4: 263
});
});
});
describe('status', function () {
it('parses the message correctly', function () {
var listener = sinon.spy();
wii.on('status', listener);
proxyConnection.on.withArgs('data').yield(new Buffer([0, 0, 0, 11, 101,
0, 1, // cycleTime
1, 1, // i2cErrorCount
2, 1, // sensor
3, 1, 0, 0 // flags
]));
expect(listener).calledWith({
cycleTime: 256,
i2cErrorCount: 257,
sensor: 258,
flags: 259
});
});
});
describe('servo', function () {
it('parses the message correctly', function () {
var listener = sinon.spy();
wii.on('servo', listener);
proxyConnection.on.withArgs('data').yield(new Buffer([0, 0, 0, 16, 103,
0, 1, // servo[0]
1, 1, // servo[1]
2, 1, // servo[2]
3, 1, // servo[3]
4, 1, // servo[4]
5, 1, // servo[5]
6, 1, // servo[6]
7, 1 // servo[7]
]));
expect(listener).calledWith([256, 257, 258, 259, 260, 261, 262, 263]);
});
});
describe('motor', function () {
it('parses the message correctly', function () {
var listener = sinon.spy();
wii.on('motor', listener);
proxyConnection.on.withArgs('data').yield(new Buffer([0, 0, 0, 16, 104,
0, 1, // motor[0]
1, 1, // motor[1]
2, 1, // motor[2]
3, 1, // motor[3]
4, 1, // motor[4]
5, 1, // motor[5]
6, 1, // motor[6]
7, 1 // motor[7]
]));
expect(listener).calledWith([256, 257, 258, 259, 260, 261, 262, 263]);
});
});
});