Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
firmware/http-firmware-script.inc@49:66f5471a19dc, 2019-02-28 (annotated)
- Committer:
- andrewboyson
- Date:
- Thu Feb 28 14:45:37 2019 +0000
- Revision:
- 49:66f5471a19dc
- Parent:
- 48:4e678727c4c9
- Child:
- 50:edd44fe9320f
Corrected some styling and the firmware ajax information
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andrewboyson | 48:4e678727c4c9 | 1 | "var file;\n" |
| andrewboyson | 46:1822fdbe6c0c | 2 | "var xhr;\n" |
| andrewboyson | 48:4e678727c4c9 | 3 | "var fr;\n" |
| andrewboyson | 48:4e678727c4c9 | 4 | "var checksum;\n" |
| andrewboyson | 48:4e678727c4c9 | 5 | "\n" |
| andrewboyson | 46:1822fdbe6c0c | 6 | "function xhrOnLoad()\n" |
| andrewboyson | 46:1822fdbe6c0c | 7 | "{\n" |
| andrewboyson | 46:1822fdbe6c0c | 8 | " if (xhr.status == 200) document.getElementById('result').innerHTML = xhr.responseText;\n" |
| andrewboyson | 46:1822fdbe6c0c | 9 | " else document.getElementById('result').innerHTML = 'Upload failed';\n" |
| andrewboyson | 46:1822fdbe6c0c | 10 | "}\n" |
| andrewboyson | 46:1822fdbe6c0c | 11 | "function xhrOnError()\n" |
| andrewboyson | 46:1822fdbe6c0c | 12 | "{\n" |
| andrewboyson | 46:1822fdbe6c0c | 13 | " document.getElementById('result').innerHTML = 'Upload error';\n" |
| andrewboyson | 46:1822fdbe6c0c | 14 | "}\n" |
| andrewboyson | 48:4e678727c4c9 | 15 | "function startXhr()\n" |
| andrewboyson | 48:4e678727c4c9 | 16 | "{\n" |
| andrewboyson | 48:4e678727c4c9 | 17 | " document.getElementById('result').innerHTML = 'Uploading...';\n" |
| andrewboyson | 48:4e678727c4c9 | 18 | " \n" |
| andrewboyson | 48:4e678727c4c9 | 19 | " xhr = new XMLHttpRequest();\n" |
| andrewboyson | 48:4e678727c4c9 | 20 | "\n" |
| andrewboyson | 48:4e678727c4c9 | 21 | " xhr.onload = xhrOnLoad;\n" |
| andrewboyson | 48:4e678727c4c9 | 22 | " xhr.onerror = xhrOnError;\n" |
| andrewboyson | 48:4e678727c4c9 | 23 | "\n" |
| andrewboyson | 49:66f5471a19dc | 24 | " xhr.open('POST', '/firmware-ajax?checksum=' + checksum, true);\n" |
| andrewboyson | 48:4e678727c4c9 | 25 | " xhr.send(file);\n" |
| andrewboyson | 48:4e678727c4c9 | 26 | "}\n" |
| andrewboyson | 48:4e678727c4c9 | 27 | "\n" |
| andrewboyson | 48:4e678727c4c9 | 28 | "function frOnLoad()\n" |
| andrewboyson | 48:4e678727c4c9 | 29 | "{\n" |
| andrewboyson | 48:4e678727c4c9 | 30 | " var arrayBuffer = fr.result;\n" |
| andrewboyson | 48:4e678727c4c9 | 31 | " var bytes = new Uint8Array(arrayBuffer);\n" |
| andrewboyson | 48:4e678727c4c9 | 32 | " for ( i = 0; i < bytes.length; ++i )\n" |
| andrewboyson | 48:4e678727c4c9 | 33 | " {\n" |
| andrewboyson | 48:4e678727c4c9 | 34 | " checksum = (checksum + bytes[i]) >>> 0;\n" |
| andrewboyson | 48:4e678727c4c9 | 35 | " }\n" |
| andrewboyson | 48:4e678727c4c9 | 36 | " startXhr();\n" |
| andrewboyson | 48:4e678727c4c9 | 37 | "}\n" |
| andrewboyson | 48:4e678727c4c9 | 38 | "function frOnError()\n" |
| andrewboyson | 48:4e678727c4c9 | 39 | "{\n" |
| andrewboyson | 48:4e678727c4c9 | 40 | " document.getElementById('result').innerHTML = 'Check sum calculation error';\n" |
| andrewboyson | 48:4e678727c4c9 | 41 | "}\n" |
| andrewboyson | 48:4e678727c4c9 | 42 | "function startChecksumCalculation()\n" |
| andrewboyson | 48:4e678727c4c9 | 43 | "{\n" |
| andrewboyson | 48:4e678727c4c9 | 44 | " document.getElementById('result').innerHTML = 'Calculating checksum...';\n" |
| andrewboyson | 48:4e678727c4c9 | 45 | " \n" |
| andrewboyson | 48:4e678727c4c9 | 46 | " checksum = 0;\n" |
| andrewboyson | 48:4e678727c4c9 | 47 | " \n" |
| andrewboyson | 48:4e678727c4c9 | 48 | " fr = new FileReader();\n" |
| andrewboyson | 48:4e678727c4c9 | 49 | " fr.onload = frOnLoad;\n" |
| andrewboyson | 48:4e678727c4c9 | 50 | " fr.onerror = frOnError;\n" |
| andrewboyson | 48:4e678727c4c9 | 51 | " \n" |
| andrewboyson | 48:4e678727c4c9 | 52 | " fr.readAsArrayBuffer(file);\n" |
| andrewboyson | 48:4e678727c4c9 | 53 | "}\n" |
| andrewboyson | 46:1822fdbe6c0c | 54 | "\n" |
| andrewboyson | 46:1822fdbe6c0c | 55 | "function startUpload()\n" |
| andrewboyson | 46:1822fdbe6c0c | 56 | "{\n" |
| andrewboyson | 46:1822fdbe6c0c | 57 | " var fileInput = document.getElementById('fileInput');\n" |
| andrewboyson | 46:1822fdbe6c0c | 58 | "\n" |
| andrewboyson | 46:1822fdbe6c0c | 59 | " if (fileInput.files.length == 0)\n" |
| andrewboyson | 46:1822fdbe6c0c | 60 | " {\n" |
| andrewboyson | 46:1822fdbe6c0c | 61 | " document.getElementById('result').innerHTML = 'Please choose a file';\n" |
| andrewboyson | 46:1822fdbe6c0c | 62 | " return;\n" |
| andrewboyson | 46:1822fdbe6c0c | 63 | " }\n" |
| andrewboyson | 46:1822fdbe6c0c | 64 | "\n" |
| andrewboyson | 46:1822fdbe6c0c | 65 | " if (fileInput.files.length > 1)\n" |
| andrewboyson | 46:1822fdbe6c0c | 66 | " {\n" |
| andrewboyson | 46:1822fdbe6c0c | 67 | " document.getElementById('result').innerHTML = 'Please choose just one file';\n" |
| andrewboyson | 46:1822fdbe6c0c | 68 | " return;\n" |
| andrewboyson | 46:1822fdbe6c0c | 69 | " }\n" |
| andrewboyson | 48:4e678727c4c9 | 70 | " \n" |
| andrewboyson | 48:4e678727c4c9 | 71 | " file = fileInput.files[0];\n" |
| andrewboyson | 48:4e678727c4c9 | 72 | " \n" |
| andrewboyson | 48:4e678727c4c9 | 73 | " startChecksumCalculation();\n" |
| andrewboyson | 48:4e678727c4c9 | 74 | "}\n" |
| andrewboyson | 48:4e678727c4c9 | 75 | "" |