Skip to content

Commit 7ff489f

Browse files
James SmithJames Smith
authored andcommitted
Fixed issues with tests
1 parent f4a8cde commit 7ff489f

File tree

1 file changed

+82
-51
lines changed

1 file changed

+82
-51
lines changed

docs/webusb/application.js

Lines changed: 82 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,11 +1394,14 @@
13941394
class BasicTestStateMachine extends ProfilingStateMachine {
13951395
static START_ADDR = 50;
13961396
static SET_SCREEN_ADDR = BasicTestStateMachine.START_ADDR;
1397-
static VIBRATE_ADDR = 51;
1397+
static VIBRATE_START_ADDR = 51;
1398+
static VIBRATE_END_ADDR = 52;
13981399

13991400
constructor() {
14001401
super("Basic Test");
14011402
this.timeoutId = -1;
1403+
this.retries = 0;
1404+
this.resendFn = null;
14021405
}
14031406

14041407
done(reason) {
@@ -1409,6 +1412,42 @@
14091412
super.done(reason);
14101413
}
14111414

1415+
sendScreenCmd() {
1416+
this.resendFn = this.sendScreenCmd.bind(this);
1417+
let hostAddr = getMapleHostAddr(this.currentIdx);
1418+
let destAddr = hostAddr | (1 << (this.currentPeripheralIdx - 1));
1419+
send(BasicTestStateMachine.SET_SCREEN_ADDR, '0'.charCodeAt(0), [
1420+
0x0C, destAddr, hostAddr, 0x32, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
1421+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x18, 0x00,
1422+
0x00, 0x00, 0x00, 0xC0, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0xFF, 0xC0, 0x00, 0x00, 0xC0,
1423+
0x01, 0xFF, 0xE0, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x70, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x38, 0x1C,
1424+
0x00, 0xC0, 0x00, 0x00, 0x18, 0x38, 0x00, 0xC0, 0x00, 0x00, 0x1D, 0xF0, 0x00, 0xC0, 0x07, 0x80,
1425+
0x0F, 0xE0, 0x00, 0xFE, 0x3F, 0x80, 0x07, 0x00, 0x1F, 0xFC, 0x7C, 0x00, 0x00, 0x00, 0x0F, 0xC0,
1426+
0xE0, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x60, 0x00, 0x60, 0x00,
1427+
0x00, 0x00, 0x7C, 0x00, 0x61, 0x80, 0x00, 0x00, 0x3E, 0x01, 0xE1, 0x80, 0x00, 0x00, 0x07, 0x01,
1428+
0xE1, 0x80, 0x00, 0x00, 0x07, 0x00, 0x61, 0x80, 0x00, 0x00, 0xFE, 0x00, 0x61, 0x80, 0x1F, 0xE0,
1429+
0x7C, 0x0F, 0xE1, 0x80, 0x0F, 0xF0, 0x30, 0x07, 0xC1, 0x80, 0x00, 0x38, 0x00, 0x00, 0x01, 0x80,
1430+
0x00, 0x18, 0x00, 0x00, 0x01, 0x80, 0x00, 0x18, 0x00, 0x00, 0x01, 0x80, 0x00, 0x1C, 0x00, 0x00,
1431+
0x7F, 0xFC, 0x00, 0x0E, 0x00, 0x00, 0x3F, 0xF8, 0x00, 0x07, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x01,
1432+
0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1433+
]);
1434+
}
1435+
1436+
sendVibeStart() {
1437+
this.resendFn = this.sendVibeStart.bind(this);
1438+
let hostAddr = getMapleHostAddr(this.currentIdx);
1439+
let destAddr = hostAddr | (1 << (this.currentPeripheralIdx - 1));
1440+
const VIBE_POWER = 4; // 1 to 7
1441+
send(BasicTestStateMachine.VIBRATE_START_ADDR, '0'.charCodeAt(0), [0x0E, destAddr, hostAddr, 2, 0x00, 0x00, 0x01, 0x00, 0x11, (VIBE_POWER << 4), 59, 0x00]);
1442+
}
1443+
1444+
sendVibeEnd() {
1445+
this.resendFn = this.sendVibeEnd.bind(this);
1446+
let hostAddr = getMapleHostAddr(this.currentIdx);
1447+
let destAddr = hostAddr | (1 << (this.currentPeripheralIdx - 1));
1448+
send(BasicTestStateMachine.VIBRATE_END_ADDR, '0'.charCodeAt(0), [0x0E, destAddr, hostAddr, 2, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 59, 0x00]);
1449+
}
1450+
14121451
sendNext() {
14131452
if (this.currentIdx < 0) {
14141453
while (!(++this.currentIdx in this.allData) && this.currentIdx < 4) {}
@@ -1437,35 +1476,11 @@
14371476
let fns = periphData["functions"];
14381477
for (let i = 0; i < fns.length; i++) {
14391478
let fnId = fns[i]["id"];
1440-
let hostAddr = getMapleHostAddr(this.currentIdx);
1441-
let destAddr = hostAddr | (1 << (this.currentPeripheralIdx - 1));
14421479
if (fnId == 0x00000004) {
1443-
// Send screen update
1444-
send(BasicTestStateMachine.SET_SCREEN_ADDR, '0'.charCodeAt(0), [
1445-
0x0C, destAddr, hostAddr, 0x32, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
1446-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1447-
0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
1448-
0x00, 0x0F, 0xC0, 0x00, 0x00, 0x18, 0x00, 0x07, 0xF0, 0x00, 0x00, 0x18, 0x00, 0x00, 0x7C, 0x00,
1449-
0x00, 0x18, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x18, 0x00, 0x00, 0x07, 0x00, 0x00, 0x18, 0x00, 0x00,
1450-
0x03, 0x80, 0x00, 0x18, 0x07, 0xE0, 0x01, 0xE0, 0x00, 0x18, 0x1F, 0xC0, 0x00, 0x70, 0x00, 0x18,
1451-
0x3C, 0x00, 0x00, 0x3C, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x00, 0x18, 0x1C, 0x00, 0x00, 0x00,
1452-
0x07, 0xFF, 0x8F, 0x9F, 0xC0, 0x00, 0x03, 0xFF, 0x03, 0x8F, 0xE0, 0x00, 0x00, 0x00, 0x01, 0x80,
1453-
0x79, 0x80, 0x00, 0x00, 0x07, 0x80, 0x39, 0x80, 0x00, 0x00, 0x3F, 0x07, 0xD9, 0x80, 0x00, 0x00,
1454-
0x1C, 0x07, 0xB9, 0x80, 0x00, 0x00, 0x00, 0x06, 0x71, 0x80, 0x00, 0x00, 0x00, 0x07, 0xE1, 0x80,
1455-
0x00, 0x00, 0x00, 0x03, 0xC1, 0x80, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFC, 0x00, 0x00, 0x00, 0x00,
1456-
0x0F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1457-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1458-
]);
1459-
this.timeoutId = setTimeout(this.sendNext.bind(this), 100);
1460-
resetSmTimeout(200);
1480+
this.sendScreenCmd();
14611481
return;
14621482
} else if (fnId == 0x00000100) {
1463-
// Send vibration update
1464-
const VIBE_POWER = 4; // 1 to 7
1465-
const VIBE_TIME_MS = 250;
1466-
send(BasicTestStateMachine.VIBRATE_ADDR, '0'.charCodeAt(0), [0x0E, destAddr, hostAddr, 2, 0x00, 0x00, 0x01, 0x00, 0x11, (VIBE_POWER << 4), 59, 0x00]);
1467-
this.timeoutId = setTimeout(this.vibrationDone.bind(this), VIBE_TIME_MS);
1468-
resetSmTimeout(VIBE_TIME_MS + 150);
1483+
this.sendVibeStart();
14691484
return;
14701485
}
14711486
}
@@ -1474,13 +1489,6 @@
14741489
}
14751490
}
14761491

1477-
vibrationDone() {
1478-
let hostAddr = getMapleHostAddr(this.currentIdx);
1479-
let destAddr = hostAddr | (1 << (this.currentPeripheralIdx - 1));
1480-
send(BasicTestStateMachine.VIBRATE_ADDR, '0'.charCodeAt(0), [0x0E, destAddr, hostAddr, 2, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 59, 0x00]);
1481-
this.sendNext();
1482-
}
1483-
14841492
complete() {
14851493
super.complete();
14861494
this.currentIdx = -1;
@@ -1492,20 +1500,37 @@
14921500
if (addr < BasicTestStateMachine.START_ADDR) {
14931501
super.process(addr, cmd, payload);
14941502
} else if (cmd != CMD_OK){
1503+
if (++this.retries <= 2 && this.resendFn != null) {
1504+
this.resendFn();
1505+
return;
1506+
}
14951507
this.stop('Basic test failed: maple command failure', 'red', 'bold')
1508+
} else {
1509+
this.retries = 0;
1510+
if (addr == BasicTestStateMachine.SET_SCREEN_ADDR || addr == BasicTestStateMachine.VIBRATE_END_ADDR) {
1511+
resetSmTimeout(150);
1512+
this.sendNext();
1513+
} else if (addr = BasicTestStateMachine.VIBRATE_START_ADDR) {
1514+
const VIBE_TIME_MS = 250;
1515+
this.timeoutId = setTimeout(this.sendVibeEnd.bind(this), VIBE_TIME_MS);
1516+
resetSmTimeout(VIBE_TIME_MS + 150);
1517+
}
14961518
}
14971519
}
14981520
}
14991521

15001522
class StressTestStateMachine extends ProfilingStateMachine {
15011523
static START_ADDR = 60;
15021524
static SET_SCREEN_ADDR = BasicTestStateMachine.START_ADDR;
1503-
static VIBRATE_ADDR = 61;
1525+
static VIBRATE_START_ADDR = 61;
1526+
static VIBRATE_END_ADDR = 62;
15041527

15051528
constructor() {
15061529
super("Stress Test");
15071530
this.timeoutId = -1;
15081531
this.vibrationAddrs = [];
1532+
this.retries = 0;
1533+
this.resendFn = null;
15091534
}
15101535

15111536
done(reason) {
@@ -1554,25 +1579,25 @@
15541579
let destAddr = hostAddr | (1 << (this.currentPeripheralIdx - 1));
15551580
if (fnId == 0x00000004) {
15561581
// Send screen update
1557-
send(BasicTestStateMachine.SET_SCREEN_ADDR, '0'.charCodeAt(0), [
1582+
send(StressTestStateMachine.SET_SCREEN_ADDR, '0'.charCodeAt(0), [
15581583
0x0C, destAddr, hostAddr, 0x32, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
1559-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1560-
0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
1561-
0x00, 0x0F, 0xC0, 0x00, 0x00, 0x18, 0x00, 0x07, 0xF0, 0x00, 0x00, 0x18, 0x00, 0x00, 0x7C, 0x00,
1562-
0x00, 0x18, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x18, 0x00, 0x00, 0x07, 0x00, 0x00, 0x18, 0x00, 0x00,
1563-
0x03, 0x80, 0x00, 0x18, 0x07, 0xE0, 0x01, 0xE0, 0x00, 0x18, 0x1F, 0xC0, 0x00, 0x70, 0x00, 0x18,
1564-
0x3C, 0x00, 0x00, 0x3C, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x00, 0x18, 0x1C, 0x00, 0x00, 0x00,
1565-
0x07, 0xFF, 0x8F, 0x9F, 0xC0, 0x00, 0x03, 0xFF, 0x03, 0x8F, 0xE0, 0x00, 0x00, 0x00, 0x01, 0x80,
1566-
0x79, 0x80, 0x00, 0x00, 0x07, 0x80, 0x39, 0x80, 0x00, 0x00, 0x3F, 0x07, 0xD9, 0x80, 0x00, 0x00,
1567-
0x1C, 0x07, 0xB9, 0x80, 0x00, 0x00, 0x00, 0x06, 0x71, 0x80, 0x00, 0x00, 0x00, 0x07, 0xE1, 0x80,
1568-
0x00, 0x00, 0x00, 0x03, 0xC1, 0x80, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFC, 0x00, 0x00, 0x00, 0x00,
1569-
0x0F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1570-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1584+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x18, 0x00,
1585+
0x00, 0x00, 0x00, 0xC0, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0xFF, 0xC0, 0x00, 0x00, 0xC0,
1586+
0x01, 0xFF, 0xE0, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x70, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x38, 0x1C,
1587+
0x00, 0xC0, 0x00, 0x00, 0x18, 0x38, 0x00, 0xC0, 0x00, 0x00, 0x1D, 0xF0, 0x00, 0xC0, 0x07, 0x80,
1588+
0x0F, 0xE0, 0x00, 0xFE, 0x3F, 0x80, 0x07, 0x00, 0x1F, 0xFC, 0x7C, 0x00, 0x00, 0x00, 0x0F, 0xC0,
1589+
0xE0, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x60, 0x00, 0x60, 0x00,
1590+
0x00, 0x00, 0x7C, 0x00, 0x61, 0x80, 0x00, 0x00, 0x3E, 0x01, 0xE1, 0x80, 0x00, 0x00, 0x07, 0x01,
1591+
0xE1, 0x80, 0x00, 0x00, 0x07, 0x00, 0x61, 0x80, 0x00, 0x00, 0xFE, 0x00, 0x61, 0x80, 0x1F, 0xE0,
1592+
0x7C, 0x0F, 0xE1, 0x80, 0x0F, 0xF0, 0x30, 0x07, 0xC1, 0x80, 0x00, 0x38, 0x00, 0x00, 0x01, 0x80,
1593+
0x00, 0x18, 0x00, 0x00, 0x01, 0x80, 0x00, 0x18, 0x00, 0x00, 0x01, 0x80, 0x00, 0x1C, 0x00, 0x00,
1594+
0x7F, 0xFC, 0x00, 0x0E, 0x00, 0x00, 0x3F, 0xF8, 0x00, 0x07, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x01,
1595+
0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
15711596
]);
15721597
} else if (fnId == 0x00000100) {
15731598
// Send vibration update
15741599
const VIBE_POWER = 7; // 1 to 7
1575-
send(BasicTestStateMachine.VIBRATE_ADDR, '0'.charCodeAt(0), [0x0E, destAddr, hostAddr, 2, 0x00, 0x00, 0x01, 0x00, 0x11, (VIBE_POWER << 4), 59, 0x00]);
1600+
send(StressTestStateMachine.VIBRATE_START_ADDR, '0'.charCodeAt(0), [0x0E, destAddr, hostAddr, 2, 0x00, 0x00, 0x01, 0x00, 0x11, (VIBE_POWER << 4), 59, 0x00]);
15761601
this.vibrationAddrs.push([destAddr, hostAddr])
15771602
}
15781603
}
@@ -1581,14 +1606,20 @@
15811606
}
15821607
}
15831608

1609+
delayToDone() {
1610+
this.stop("Stress test complete");
1611+
}
1612+
15841613
vibrationDone() {
15851614
for (let i = 0; i < this.vibrationAddrs.length; ++i) {
15861615
let addrs = this.vibrationAddrs[i];
15871616
let hostAddr = addrs[1];
15881617
let destAddr = addrs[0];
1589-
send(BasicTestStateMachine.VIBRATE_ADDR, '0'.charCodeAt(0), [0x0E, destAddr, hostAddr, 2, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 59, 0x00]);
1618+
send(StressTestStateMachine.VIBRATE_END_ADDR, '0'.charCodeAt(0), [0x0E, destAddr, hostAddr, 2, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 59, 0x00]);
15901619
}
1591-
this.stop("Stress test complete");
1620+
const DELAY_TIME_MS = 100;
1621+
this.timeoutId = setTimeout(this.delayToDone.bind(this), DELAY_TIME_MS);
1622+
resetSmTimeout(DELAY_TIME_MS + 150);
15921623
}
15931624

15941625
complete() {

0 commit comments

Comments
 (0)