Skip to content

Commit d4dd766

Browse files
authored
Merge pull request #44 from PropGit/add_codes
Enabled coded download messages
2 parents e98efa3 + a1bec4d commit d4dd766

File tree

4 files changed

+121
-22
lines changed

4 files changed

+121
-22
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<link rel="stylesheet" href="index.css">
55
<script src="sha1.js"></script>
6+
<script src="messages.js"></script>
67
<script src="http.js"></script>
78
<script src="serial.js"></script>
89
<script src="parser.js"></script>

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "BlocklyProp Launcher",
33
"description": "A Chrome application that connects your Propeller-Powered Hardware to the BlocklyProp website.",
4-
"version": "0.7.4",
4+
"version": "0.7.5",
55
"manifest_version": 2,
66
"minimum_chrome_version": "45",
77

messages.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
Notices
3+
4+
This is a list of notices (messages) generated during the Propeller loading process. They match the PropLoader message values and meaning as closely as possible.
5+
6+
A numeric code is prepended to each notice in the format ###-<text_notice>.
7+
8+
There are three categories of notices and notice codes:
9+
10+
* Status - These express state/progress/event information and are given codes 001 through 099.
11+
* Error - These express fatal problems and are given codes 100 and beyond.
12+
* Verbose - These are for seasoned developers. They may express state information or specific deep error information that is usually only helpful to a small
13+
set of users, thus, they are only shown in debug output. These are all automatically given the code 000.
14+
15+
Code numbers ARE NEVER REUSED for a condition that means something different than what was first intended by a notice. When a new Status or Error notice
16+
is created, it simply takes on the next available code number even if it's logically related to another far away notice.
17+
*/
18+
19+
// Status Notice IDs ("rsvd" are reserved by PropLoader and/or for future use)
20+
//rsvd nsOpeningFile = 001;
21+
const nsDownloading = 002;
22+
const nsVerifyingRAM = 003;
23+
//rsvd nsOpeningFile = 004;
24+
const nsDownloadSuccessful = 005;
25+
//rsvd nsTerminalMode = 006;
26+
//rsvd nsWritingToSDCard = 007;
27+
//rsvd nsBytesRemaining = 008;
28+
//rsvd nsBytesSent = 009;
29+
//rsvd nsSettingModuleName = 010;
30+
//rsvd nsUsingAlternatePort = 011;
31+
//rsvd nsSteppingDownBaudRate = 012;
32+
//rsvd nsUsingSingleStageLoader = 013;
33+
const nsVerifyingEEPROM = 014;
34+
35+
// Error Notice IDs
36+
//rsvd neCanOnlyNameWIFIModules = 100;
37+
//rsvd neInvalidModuleAddress = 101;
38+
const neDownloadFailed = 102;
39+
//rsvd neCantOpenFile = 103;
40+
const nePropellerNotFound = 104;
41+
//rsvd neFailedToEnterTerminalMode = 105;
42+
//rsvd neWrongWIFIModuleFirmware = 106;
43+
//rsvd neFailedToWriteToSDCard = 107;
44+
//rsvd neInvalidModuleName = 108;
45+
//rsvd neFailedToSetModuleName = 109;
46+
//rsvd neFileTruncated = 110;
47+
//rsvd neFileCorrupted = 111;
48+
//rsvd neCantReadPropellerAppFile = 112;
49+
//rsvd neWIFIModuleDiscoveryFailed = 113;
50+
//rsvd neNoWIFIModulesFound = 114;
51+
//rsvd neSerialPortDiscoveryFailed = 115;
52+
//rsvd neNoSerialPortsFound = 116;
53+
const neCanNotOpenPort = 117;
54+
//rsvd neCanNotConnectToModule = 118;
55+
const neCanNotSetBaudrate = 119;
56+
//rsvd neInternalCodeError = 120;
57+
//rsvd neInsufficientMemory = 121;
58+
//rsvd neNoResetMethod = 122;
59+
//rsvd neResetFailed = 123;
60+
const neUnknownPropellerVersion = 124;
61+
const neRAMChecksumFailed = 125;
62+
//rsvd neEEPROMChecksumFailed = 126;
63+
const neEEPROMVerifyFailed = 127;
64+
const neCommunicationLost = 128;
65+
const neLoaderFailed = 129;
66+
const neCommunicationFailed = 199;
67+
68+
// Notices, by ID
69+
notices = {
70+
[nsDownloading] : "Downloading",
71+
[nsVerifyingRAM] : "Verifying RAM",
72+
[nsDownloadSuccessful] : "Download successful!",
73+
[nsVerifyingEEPROM] : "Programming and verifying EEPROM",
74+
[neDownloadFailed] : "Download failed!",
75+
[nePropellerNotFound] : "Propeller not found",
76+
[neCanNotOpenPort] : "Can not open port %s",
77+
[neCanNotSetBaudrate] : "Can not set port %s to baudrate %s",
78+
[neUnknownPropellerVersion] : "Found Propeller version %d - expected version 1",
79+
[neRAMChecksumFailed] : "RAM checksum failed",
80+
[neEEPROMVerifyFailed] : "EEPROM verify failed",
81+
[neCommunicationLost] : "Communication lost", /*No response*/
82+
[neLoaderFailed] : "Loader failed",
83+
[neCommunicationFailed] : "Communication failed" /*Response unexpected*/
84+
};
85+
86+
function notice(noticeId = 0, values = []) {
87+
/* Notice (message) retriever. Returns textual message indicated by the noticeId, inserts the optional values into it, and prepends with the noticeId value
88+
in the form ###-<message>.
89+
noticeId is the identifier of the notice; ex: nsDownloading.
90+
values is an optional array of values to stuff into notice.*/
91+
//Retrieve notice; if undefined,
92+
nMsg = notices[noticeId];
93+
//Fill in variables if needed; if notice undefined, use first values element as notice.
94+
values.forEach(function(x){nMsg = (nMsg) ? nMsg.replace(/%s/, x) : x;});
95+
if (noticeId >= 100) {nMsg = "Error: " + nMsg;}
96+
noticeId = "000" + noticeId;
97+
nMsg = noticeId.substr(noticeId.length-3) + '-' + nMsg;
98+
return nMsg;
99+
}

serial.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function openPort(sock, portPath, baudrate, connMode) {
130130
resolve(openInfo.connectionId);
131131
} else {
132132
// Error
133-
reject(Error("Could not open port " + portPath));
133+
reject(Error(notice(neCanNotOpenPort, [portPath])));
134134
}
135135
}
136136
);
@@ -173,7 +173,7 @@ function changeBaudrate(cid, baudrate) {
173173
port.baud = baudrate;
174174
resolve(cid);
175175
} else {
176-
reject(Error("Can not set port " + port.path + " to baudrate " + baudrate));
176+
reject(Error(notice(neCanNotSetBaudrate, [port.path, baudrate])));
177177
}
178178
});
179179
} else {
@@ -192,7 +192,7 @@ function setControl(cid, options) {
192192
if (controlResult) {
193193
resolve();
194194
} else {
195-
reject(Error("Can not set port " + findPort(cid).path + "'s options: " + options));
195+
reject(Error(notice(000, ["Can not set port " + findPort(cid).path + "'s options: " + options])));
196196
}
197197
});
198198
});
@@ -206,7 +206,7 @@ function flush(cid) {
206206
if (flushResult) {
207207
resolve();
208208
} else {
209-
reject(Error("Can not flush port " + findPort(cid).path + "'s transmit/receive buffer"));
209+
reject(Error(notice(000, ["Can not flush port " + findPort(cid).path + "'s transmit/receive buffer"])));
210210
}
211211
});
212212
});
@@ -2928,19 +2928,19 @@ function loadPropeller(sock, portPath, action, payload, debug) {
29282928
connect()
29292929
.then(function(id) {cid = id}) //Save cid from connection (whether new or existing)
29302930
.then(function() {listen(true)}) //Enable listener
2931-
.then(function() {log("Scanning port " + findPortPath(cid), mUser, sock)}) //Notify what port we're using
2931+
.then(function() {log(notice(000, ["Scanning port " + findPortPath(cid)]), mUser, sock)}) //Notify what port we're using
29322932
.then(function() {return talkToProp(sock, cid, binImage, action === 'EEPROM')}) //Download user application to RAM or EEPROM
29332933
.then(function() {return changeBaudrate(cid, originalBaudrate)}) //Restore original baudrate
29342934
.then(function() { //Success! Open terminal or graph if necessary
29352935
listen(false); //Disable listener
29362936
findPort(cid).mode = (debug !== "none") ? "debug" : "programming";
2937-
log("Download successful.", mUser+mStat, sock);
2937+
log(notice(nsDownloadSuccessful), mAll, sock);
29382938
if (sock && debug !== "none") {
29392939
sock.send(JSON.stringify({type:"ui-command", action:(debug === "term") ? "open-terminal" : "open-graph"}));
29402940
sock.send(JSON.stringify({type:"ui-command", action:"close-compile"}));
29412941
}
29422942
}) //Error? Disable listener and display error
2943-
.catch(function(e) {listen(false); log("Error: " + e.message, mAll, sock); if (cid) {changeBaudrate(cid, originalBaudrate)}});
2943+
.catch(function(e) {listen(false); log(e.message, mAll, sock); log(notice(neDownloadFailed), mAll, sock); if (cid) {changeBaudrate(cid, originalBaudrate)}});
29442944
}
29452945

29462946
function listen(engage) {
@@ -2986,15 +2986,15 @@ function talkToProp(sock, cid, binImage, toEEPROM) {
29862986
function verifier() {
29872987
log("Verifying package delivery", mDeep);
29882988
//Check handshake and version
2989-
if (propComm.handshake === stValidating || propComm.handshake === stInvalid || propComm.version === stValidating) {reject(Error("Propeller not found.")); return;}
2989+
if (propComm.handshake === stValidating || propComm.handshake === stInvalid || propComm.version === stValidating) {reject(Error(notice(nePropellerNotFound))); return;}
29902990
//Check for proper version
2991-
if (propComm.version !== 1) {reject(Error("Found Propeller version " + propComm.version + " - expected version 1.")); return;}
2991+
if (propComm.version !== 1) {reject(Error(notice(neUnknownPropellerVersion, [propComm.version]))); return;}
29922992
//Check RAM checksum
2993-
if (propComm.ramCheck === stValidating) {reject(Error("Propeller communication lost while delivering loader.")); return;}
2994-
if (propComm.ramCheck === stInvalid) {reject(Error("Unable to deliver loader.")); return;}
2993+
if (propComm.ramCheck === stValidating) {reject(Error(notice(neCommunicationLost))); return;}
2994+
if (propComm.ramCheck === stInvalid) {reject(Error(notice(neCommunicationFailed))); return;}
29952995
//Check Micro Boot Loader Ready Signal
2996-
if (propComm.mblResponse !== stValid || (propComm.mblPacketId[0]^packetId) + (propComm.mblTransId[0]^transmissionId) !== 0) {reject(Error("Loader failed.")); return;}
2997-
log("Found Propeller", mUser+mStat, sock);
2996+
if (propComm.mblResponse !== stValid || (propComm.mblPacketId[0]^packetId) + (propComm.mblTransId[0]^transmissionId) !== 0) {reject(Error(notice(neLoaderFailed))); return;}
2997+
log(notice(000, ["Found Propeller"]), mUser+mStat, sock);
29982998
resolve();
29992999
}
30003000
log("Waiting " + Math.trunc(waittime) + " ms for package delivery", mDeep);
@@ -3020,7 +3020,7 @@ function talkToProp(sock, cid, binImage, toEEPROM) {
30203020
function sendUA() {
30213021
return new Promise(function(resolve, reject) {
30223022
log("Delivering user application packet " + (totalPackets-packetId+1) + " of " + totalPackets, mDbug);
3023-
log(".", mUser, sock);
3023+
log(notice(nsDownloading), mUser, sock);
30243024
prepForMBLResponse();
30253025
var txPacketLength = 2 + //Determine packet length (in longs); header + packet limit or remaining data length
30263026
Math.min(Math.trunc(maxDataSize / 4) - 2, Math.trunc(binImage.byteLength / 4) - pIdx);
@@ -3045,7 +3045,7 @@ function talkToProp(sock, cid, binImage, toEEPROM) {
30453045
log("Verifying loader acknowledgement " + (totalPackets-packetId+0) + " of " + totalPackets, mDeep);
30463046
//Check Micro Boot Loader response
30473047
if (propComm.mblResponse !== stValid || (propComm.mblPacketId[0]^packetId) + (propComm.mblTransId[0]^transmissionId) !== 0) {
3048-
reject(Error("Download failed.")); return
3048+
reject(Error(notice(neCommunicationFailed))); return
30493049
}
30503050
log("Packet delivered.", mDeep);
30513051
resolve();
@@ -3064,12 +3064,12 @@ function talkToProp(sock, cid, binImage, toEEPROM) {
30643064

30653065
function* packetGenerator() {
30663066
//Packet specification generator; generates details for the next packet
3067-
yield {type: ltVerifyRAM, nextId: -checksum, sendLog: "Verifying RAM", recvTime: 800, recvErr: "RAM checksum failure!"};
3067+
yield {type: ltVerifyRAM, nextId: -checksum, sendLog: notice(nsVerifyingRAM), recvTime: 800, recvErr: notice(neRAMChecksumFailed)};
30683068
if (toEEPROM) {
3069-
yield {type: ltProgramEEPROM, nextId: -checksum*2, sendLog: "Programming and verifying EEPROM", recvTime: 4500, recvErr: "EEPROM verify failure!"};
3069+
yield {type: ltProgramEEPROM, nextId: -checksum*2, sendLog: notice(nsVerifyingEEPROM), recvTime: 4500, recvErr: notice(neEEPROMVerifyFailed)};
30703070
}
3071-
yield {type: ltReadyToLaunch, nextId: packetId-1, sendLog: "Ready for Launch", recvTime: 800, recvErr: "Communication failed!"};
3072-
yield {type: ltLaunchNow, nextId: -1, sendLog: "Launching", recvTime: 0, recvErr: ""};
3071+
yield {type: ltReadyToLaunch, nextId: packetId-1, sendLog: notice(000, ["Ready for Launch"]), recvTime: 800, recvErr: notice(neCommunicationLost)};
3072+
yield {type: ltLaunchNow, nextId: -1, sendLog: notice(000, ["Launching"]), recvTime: 0, recvErr: ""};
30733073
}
30743074

30753075
//TODO lower waittime
@@ -3080,7 +3080,7 @@ function talkToProp(sock, cid, binImage, toEEPROM) {
30803080
function sendInstructionPacket() {
30813081
return new Promise(function(resolve, reject) {
30823082
next = instPacket.next();
3083-
log(next.value.sendLog, mDbug);
3083+
log(next.value.sendLog, mAll, sock);
30843084
prepForMBLResponse();
30853085
generateLoaderPacket(next.value.type, packetId); //Generate VerifyRAM executable packet
30863086
transmissionId = Math.floor(Math.random()*4294967296); //Create next random Transmission ID
@@ -3150,7 +3150,6 @@ function talkToProp(sock, cid, binImage, toEEPROM) {
31503150
.then(function() {return sendLoader(postResetDelay);} ) //After Post-Reset-Delay, send package: Calibration Pulses+Handshake through Micro Boot Loader application+RAM Checksum Polls
31513151
.then(function() {return isLoaderReady(packetId, deliveryTime);} ) //Verify package accepted
31523152
.then(function() {return changeBaudrate(cid, finalBaudrate);} ) //Bump up to faster finalBaudrate
3153-
.then(function() { log("Downloading", mUser, sock);} )
31543153
.then(function() {return sendUserApp();} ) //Send user application
31553154
.then(function() {return finalizeDelivery();} ) //Finalize delivery and launch user application
31563155
.then(function() {return resolve();} ) //Success!

0 commit comments

Comments
 (0)