master
Selcuk Sari 4 years ago
parent 5e347ba806
commit e42849dc1b

@ -0,0 +1,20 @@
name: Sync issue comments to JIRA
# This workflow will be triggered when new issue comment is created (including PR comments)
on: issue_comment
jobs:
sync_issue_comments_to_jira:
name: Sync Issue Comments to Jira
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Sync issue comments to JIRA
uses: espressif/github-actions/sync_issues_to_jira@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JIRA_PASS: ${{ secrets.JIRA_PASS }}
JIRA_PROJECT: ESPTOOL
JIRA_COMPONENT: GitHub
JIRA_URL: ${{ secrets.JIRA_URL }}
JIRA_USER: ${{ secrets.JIRA_USER }}

@ -0,0 +1,20 @@
name: Sync issues to Jira
# This workflow will be triggered when a new issue is opened
on: issues
jobs:
sync_issues_to_jira:
name: Sync issues to Jira
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Sync GitHub issues to Jira project
uses: espressif/github-actions/sync_issues_to_jira@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JIRA_PASS: ${{ secrets.JIRA_PASS }}
JIRA_PROJECT: ESPTOOL
JIRA_COMPONENT: ${{ secrets.JIRA_COMPONENT }}
JIRA_URL: ${{ secrets.JIRA_URL }}
JIRA_USER: ${{ secrets.JIRA_USER }}

@ -0,0 +1,25 @@
name: Sync remain PRs to Jira
# This workflow will be triggered every hour, to sync remaining PRs (i.e. PRs with zero comment) to Jira project
# Note that, PRs can also get synced when new PR comment is created
on:
schedule:
- cron: "0 * * * *"
jobs:
sync_prs_to_jira:
name: Sync PRs to Jira
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Sync PRs to Jira project
uses: espressif/github-actions/sync_issues_to_jira@master
with:
cron_job: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JIRA_PASS: ${{ secrets.JIRA_PASS }}
JIRA_PROJECT: ESPTOOL
JIRA_COMPONENT: ${{ secrets.JIRA_COMPONENT }}
JIRA_URL: ${{ secrets.JIRA_URL }}
JIRA_USER: ${{ secrets.JIRA_USER }}

@ -0,0 +1 @@
node_modules

File diff suppressed because it is too large Load Diff

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2019 Espressif Systems (Shanghai) CO LTD
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

@ -0,0 +1,22 @@
# Javascript implementation of esptool
This repository contains a Javascript implementation of [esptool](https://github.com/espressif/esptool), a serial flasher utility for Espressif chips. Unlike the Python-based esptool, `esptool-js` doesn't implement generation of binary images out of ELF files, and doesn't include companion tools similar to [espefuse.py](https://github.com/espressif/esptool/wiki/espefuse) and [espsecure.py](https://github.com/espressif/esptool/wiki/espsecure).
`esptool-js` is based on [Web Serial API](https://wicg.github.io/serial/) and works in Google Chrome and Microsoft Edge, [version 89 or later](https://developer.mozilla.org/en-US/docs/Web/API/Serial#browser_compatibility).
## Live demo
Visit https://espressif.github.io/esptool-js/ to see this tool in action.
## Testing it locally
```
npm install
python3 -m http.server 8008
```
Then open http://localhost:8008 in Chrome or Edge.
## License
The code in this repository is Copyright (c) 2021 Espressif Systems (Shanghai) Co. Ltd. It is licensed under Apache 2.0 license, as described in [LICENSE](LICENSE) file.

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

@ -0,0 +1,94 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>ESP Tool</title>
<link rel="stylesheet" href="node_modules/xterm/css/xterm.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link
href="https://fonts.googleapis.com/css?family=Orbitron"
rel="stylesheet"
/>
<link rel="icon" href="favicon.ico" />
<script src="node_modules/xterm/lib/xterm.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.0.3/pako.js"></script>
<script src="node_modules/crypto-js/crypto-js.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<h1 align="center"><p><img src="./assets/esp-logo.png" width="42" height="42" style="vertical-align:middle"></img> ESP Tool</p></h1>
<h4 align="center">A Serial Flasher utility for Espressif chips</h4>
<div id="safariErr" style="display:none"><p align="center" style="color:red">This tool is not supported on Safari browser!</p>
</div>
<div class="container" id="main">
<hr/>
<div id="program">
<h3> Program </h3>
<label for="baudrates" id="lblBaudrate">Baudrate:</label>
<label style="display:none" id="lblConnTo">Connected to device: </label>
<select name="baudrates" id="baudrates">
<option value="921600">921600</option>
<option value="460800">460800</option>
<option value="230400">230400</option>
<option value="115200">115200</option>
</select>
<input class="btn btn-info btn-sm" type="button" id="connectButton" value="Connect" />
<input class="btn btn-warning btn-sm" type="button" id="disconnectButton" value="Disconnect" />
<input class="btn btn-danger btn-sm" type="button" id="eraseButton" value="Erase Flash" />
<br>
<div class="alert alert-danger alert-dismissible" id="alertDiv" style="display:none; margin-top:10px">
<a href="#" class="close" aria-label="close" onclick="$('.alert').hide()">&times;</a>
<span id="alertmsg"></span>
</div>
<div id="files">
<table class="table table-striped" id="fileTable">
<thead class="thead-light">
<tr>
<th>Flash Address</th>
<th>Selected File</th>
<th>Remove </th>
</tr>
</thead>
<tbody id="tableBody">
<tr id="row0">
<td><input type="text" id="offset1" name="offset1" value="0x1000"></td>
<td><input type="file" id="selectFile1" name="selected_file1"></td>
<td><button class="btn disabled"> Remove </button></td>
</tr>
</tbody>
</table>
<input class="btn btn-info btn-sm" type="button" id="addFile" value="Add File" />
<input class="btn btn-info btn-sm" type="button" id="programButton" value="Program" />
</div>
<output id="list"></output>
<hr/>
</div>
<div id="console">
<h3>Console </h3>
<label style="display:none" id="lblConsoleFor">Connected to device: </label>
<input class="btn btn-info" type="button" id="consoleStartButton" value="Start" />
<input class="btn btn-info" type="button" id="consoleStopButton" value="Stop" />
<input class="btn btn-info" type="button" id="resetButton" value="Reset" />
<hr/>
</div>
<div id="terminal"></div>
</div>
<script src="index.js" type="module"></script>
<script>
// Safari 3.0+ "[object HTMLElementConstructor]"
var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && window['safari'].pushNotification));
if(isSafari)
{
document.getElementById("safariErr").style.display = "inline";
document.getElementById("main").style.display = "none";
}
</script>
</body>
</html>

@ -0,0 +1,280 @@
const baudrates = document.getElementById("baudrates");
const connectButton = document.getElementById("connectButton");
const disconnectButton = document.getElementById("disconnectButton");
const resetButton = document.getElementById("resetButton");
const consoleStartButton = document.getElementById("consoleStartButton");
const consoleStopButton = document.getElementById("consoleStopButton");
const eraseButton = document.getElementById("eraseButton");
const programButton = document.getElementById("programButton");
const filesDiv = document.getElementById("files");
const terminal = document.getElementById("terminal");
const programDiv = document.getElementById("program");
const consoleDiv = document.getElementById("console");
const lblBaudrate = document.getElementById("lblBaudrate");
const lblConnTo = document.getElementById("lblConnTo");
const tableBody = document.getElementById("tableBody");
const table = document.getElementById("fileTable");
const alertDiv = document.getElementById("alertDiv");
//import { Transport } from './cp210x-webusb.js'
import { Transport } from "./webserial.js";
import { ESPLoader } from "./ESPLoader.js";
let term = new Terminal({ cols: 120, rows: 40 });
term.open(terminal);
let device = null;
let transport;
let chip = "deFault";
let esploader;
let file1 = null;
let connected = false;
let index = 1;
disconnectButton.style.display = "none";
eraseButton.style.display = "none";
consoleStopButton.style.display = "none";
filesDiv.style.display = "none";
function convertUint8ArrayToBinaryString(u8Array) {
var i,
len = u8Array.length,
b_str = "";
for (i = 0; i < len; i++) {
b_str += String.fromCharCode(u8Array[i]);
}
return b_str;
}
function convertBinaryStringToUint8Array(bStr) {
var i,
len = bStr.length,
u8_array = new Uint8Array(len);
for (var i = 0; i < len; i++) {
u8_array[i] = bStr.charCodeAt(i);
}
return u8_array;
}
function handleFileSelect(evt) {
var file = evt.target.files[0];
var reader = new FileReader();
reader.onload = (function (theFile) {
return function (e) {
file1 = e.target.result;
evt.target.data = file1;
};
})(file);
reader.readAsBinaryString(file);
}
document
.getElementById("selectFile1")
.addEventListener("change", handleFileSelect, false);
function _sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
connectButton.onclick = async () => {
// device = await navigator.usb.requestDevice({
// filters: [{ vendorId: 0x10c4 }]
// });
if (device === null) {
device = await navigator.serial.requestPort({
filters: [{ usbVendorId: 0x10c4 }],
});
transport = new Transport(device);
}
try {
esploader = new ESPLoader(transport, baudrates.value, term);
connected = true;
chip = await esploader.main_fn();
await esploader.flash_id();
} catch (e) {}
console.log("Settings done for :" + chip);
lblBaudrate.style.display = "none";
lblConnTo.innerHTML = "Connected to device: " + chip;
lblConnTo.style.display = "block";
baudrates.style.display = "none";
connectButton.style.display = "none";
disconnectButton.style.display = "initial";
eraseButton.style.display = "initial";
filesDiv.style.display = "initial";
consoleDiv.style.display = "none";
};
resetButton.onclick = async () => {
if (device === null) {
device = await navigator.serial.requestPort({
filters: [{ usbVendorId: 0x10c4 }],
});
transport = new Transport(device);
}
await transport.setDTR(false);
await new Promise((resolve) => setTimeout(resolve, 100));
await transport.setDTR(true);
};
eraseButton.onclick = async () => {
eraseButton.disabled = true;
await esploader.erase_flash();
eraseButton.disabled = false;
};
addFile.onclick = async () => {
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
//Column 1 - Offset
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "text";
element1.id = "offset" + rowCount;
element1.setAttribute("value", "0x8000");
cell1.appendChild(element1);
// Column 2 - File selector
var cell2 = row.insertCell(1);
var element2 = document.createElement("input");
element2.type = "file";
element2.id = "selectFile" + rowCount;
element2.name = "selected_File" + rowCount;
element2.addEventListener("change", handleFileSelect, false);
cell2.appendChild(element2);
// Column 3 - Remove File
var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "button";
var btnName = "button" + rowCount;
element3.name = btnName;
element3.setAttribute("class", "btn");
element3.setAttribute("value", "Remove"); // or element1.value = "button";
element3.onclick = function () {
removeRow(btnName);
};
cell3.appendChild(element3);
};
function removeRow(btnName) {
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var rowObj = row.cells[2].childNodes[0];
if (rowObj.name == btnName) {
table.deleteRow(i);
rowCount--;
}
}
}
disconnectButton.onclick = async () => {
await transport.disconnect();
term.clear();
connected = false;
baudrates.style.display = "initial";
connectButton.style.display = "initial";
disconnectButton.style.display = "none";
eraseButton.style.display = "none";
lblConnTo.style.display = "none";
filesDiv.style.display = "none";
alertDiv.style.display = "none";
consoleDiv.style.display = "initial";
};
consoleStartButton.onclick = async () => {
if (device === null) {
device = await navigator.serial.requestPort({
filters: [{ usbVendorId: 0x10c4 }],
});
transport = new Transport(device);
}
lblConsoleFor.style.display = "block";
consoleStartButton.style.display = "none";
consoleStopButton.style.display = "initial";
programDiv.style.display = "none";
await transport.connect();
while (true) {
let val = await transport.rawRead();
if (typeof val !== "undefined") {
term.write(val);
} else {
break;
}
}
console.log("quitting console");
};
consoleStopButton.onclick = async () => {
await transport.disconnect();
term.clear();
consoleStartButton.style.display = "initial";
consoleStopButton.style.display = "none";
programDiv.style.display = "initial";
};
function validate_program_inputs() {
let offsetArr = [];
var rowCount = table.rows.length;
var row;
let offset = 0;
let fileData = null;
// check for mandatory fields
for (let index = 1; index < rowCount; index++) {
row = table.rows[index];
//offset fields checks
var offSetObj = row.cells[0].childNodes[0];
offset = parseInt(offSetObj.value);
// Non-numeric or blank offset
if (Number.isNaN(offset))
return "Offset field in row " + index + " is not a valid address!";
// Repeated offset used
else if (offsetArr.includes(offset))
return "Offset field in row " + index + " is already in use!";
else offsetArr.push(offset);
var fileObj = row.cells[1].childNodes[0];
fileData = fileObj.data;
if (fileData == null) return "No file selected for row: " + index + "!";
}
return "success";
}
programButton.onclick = async () => {
var err = validate_program_inputs();
if (err != "success") {
const alertMsg = document.getElementById("alertmsg");
alertMsg.innerHTML = "<strong>" + err + "</strong>";
alertDiv.style.display = "block";
return;
}
let fileArr = [];
let offset = 0x1000;
var rowCount = table.rows.length;
var row;
for (let index = 1; index < rowCount; index++) {
row = table.rows[index];
var offSetObj = row.cells[0].childNodes[0];
offset = parseInt(offSetObj.value);
var fileObj = row.cells[1].childNodes[0];
fileArr.push({ data: fileObj.data, address: offset });
}
esploader.write_flash({ fileArray: fileArr, flash_size: "keep" });
};

@ -0,0 +1,35 @@
{
"name": "esptool-js-main",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"dependencies": {
"crypto-js": "^4.0.0",
"xterm": "^4.13.0"
}
},
"node_modules/crypto-js": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.0.0.tgz",
"integrity": "sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg=="
},
"node_modules/xterm": {
"version": "4.13.0",
"resolved": "https://registry.npmjs.org/xterm/-/xterm-4.13.0.tgz",
"integrity": "sha512-HVW1gdoLOTnkMaqQCr2r3mQy4fX9iSa5gWxKZ2UTYdLa4iqavv7QxJ8n1Ypse32shPVkhTYPLS6vHEFZp5ghzw=="
}
},
"dependencies": {
"crypto-js": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.0.0.tgz",
"integrity": "sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg=="
},
"xterm": {
"version": "4.13.0",
"resolved": "https://registry.npmjs.org/xterm/-/xterm-4.13.0.tgz",
"integrity": "sha512-HVW1gdoLOTnkMaqQCr2r3mQy4fX9iSa5gWxKZ2UTYdLa4iqavv7QxJ8n1Ypse32shPVkhTYPLS6vHEFZp5ghzw=="
}
}
}

@ -0,0 +1,6 @@
{
"dependencies": {
"crypto-js": "^4.0.0",
"xterm": "^4.13.0"
}
}

@ -0,0 +1,197 @@
'use strict';
class Transport {
constructor(device) {
this.device = device;
this.slip_reader_enabled = false;
}
get_info(){
const info = this.device.getInfo();
return "WebSerial VendorID 0x"+info.usbVendorId.toString(16)+ " ProductID 0x"+info.usbProductId.toString(16);
}
slip_writer(data) {
var count_esc = 0;
var i = 0, j = 0;
for (i = 0; i < data.length; i++) {
if (data[i] === 0xC0 || data[i] === 0xDB) {
count_esc++;
}
}
var out_data = new Uint8Array(2 + count_esc + data.length);
out_data[0] = 0xC0;
j = 1;
for (i = 0; i < data.length; i++, j++) {
if (data[i] === 0xC0) {
out_data[j++] = 0xDB;
out_data[j] = 0xDC;
continue;
}
if (data[i] === 0xDB) {
out_data[j++] = 0xDB;
out_data[j] = 0xDD;
continue;
}
out_data[j] = data[i];
}
out_data[j] = 0xC0;
return out_data;
}
write = async (data) => {
const writer = this.device.writable.getWriter();
var out_data = this.slip_writer(data);
await writer.write(out_data.buffer);
writer.releaseLock();
}
_appendBuffer(buffer1, buffer2) {
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
tmp.set(new Uint8Array(buffer1), 0);
tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
return tmp.buffer;
}
/* this function expects complete packet (hence reader reads for atleast 8 bytes. This function is
* stateless and returns the first wellformed packet only after replacing escape sequence */
slip_reader(data) {
var i = 0;
var data_start = 0, data_end = 0;
var state = "init";
var packet, temp_pkt;
while (i < data.length) {
if (state === "init" && data[i] == 0xC0) {
data_start = i + 1;
state = "valid_data";
i++;
continue;
}
if (state === "valid_data" && data[i] == 0xC0) {
data_end = i - 1;
state = "packet_complete";
break;
}
i++;
}
if (state !== "packet_complete") {
return new Uint8Array(0);
}
var temp_pkt = new Uint8Array(data_end - data_start + 1);
var j = 0;
for (i = data_start; i <= data_end; i++, j++) {
if (data[i] === 0xDB && data[i+1] === 0xDC) {
temp_pkt[j] = 0xC0;
i++;
continue;
}
if (data[i] === 0xDB && data[i+1] === 0xDD) {
temp_pkt[j] = 0xDB;
i++;
continue;
}
temp_pkt[j] = data[i];
}
packet = temp_pkt.slice(0, j); /* Remove unused bytes due to escape seq */
return packet;
}
read = async ({timeout=0, min_data=12} = {}) => {
let t;
let packet = null;
let value, done;
console.log("Read with timeout " + timeout);
const reader = this.device.readable.getReader();
if (timeout > 0) {
t = setTimeout(function() {
reader.cancel();
reader.releaseLock();
}, timeout);
}
do {
this.reader = reader;
var o = await reader.read();
this.reader = null;
value = o.value;
done = o.done;
if (packet == null) {
packet = value;
} else {
var p = new Uint8Array(this._appendBuffer(packet.buffer, value.buffer));
packet = p;
}
if (done) {
break;
}
} while (packet.length < min_data);
if (done) {
console.log("timed out");
throw("timeout");
} else {
if (timeout > 0) {
clearTimeout(t);
}
reader.releaseLock();
if (this.slip_reader_enabled) {
const val_final = this.slip_reader(packet);
return val_final;
} else {
return packet;
}
}
}
rawRead = async ({timeout=0} = {}) => {
let reader = this.device.readable.getReader();
let done = false;
let value = new Uint8Array(0);
this.reader = reader;
if (timeout > 0) {
t = setTimeout(function() {
reader.cancel();
reader.releaseLock();
}, timeout);
}
let o = await reader.read();
this.reader = null;
done = o.done;
if (done) {
throw("timeout");
} else {
if (timeout > 0) {
clearTimeout(t);
}
reader.releaseLock();
return o.value;
}
}
setRTS = async (state) => {
await this.device.setSignals({requestToSend:state});
}
setDTR = async (state) => {
await this.device.setSignals({dataTerminalReady:state});
}
connect = async ({baud=115200} = {}) => {
await this.device.open({baudRate: baud});
this.baudrate = baud;
}
disconnect = async () => {
if (this.reader !== null) {
this.reader.cancel();
this.reader.releaseLock();
}
await this.device.close();
}
}
export { Transport };

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1,14 +1,21 @@
const http = require("http");
const express = require("express");
const path = require("path");
const hostname = "127.0.0.1";
const port = 3000;
// Init App
const app = express();
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader("Content-Type", "text/plain");
res.end("Hello Worldyy bro");
// Static Files
app.use(express.static("public"));
app.use("/css", express.static(__dirname + "public/css "));
app.use("/js", express.static(__dirname + "public/js "));
app.use("/img", express.static(__dirname + "public/img "));
// Home Route
app.get("/", function (req, res) {
res.sendFile(__dirname + "/views/index.html");
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
// Start Server
app.listen(3000, function () {
console.log("Server started on port 3000...");
});

File diff suppressed because it is too large Load Diff

@ -4,12 +4,17 @@
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "./node_modules/.bin/nodemon npm index.js"
"dev": "nodemon npm index.js",
"start": "node index.js"
},
"author": "Selcuk Sari",
"license": "ISC",
"dependencies": {
"express": "^4.18.1",
"pug": "^3.0.2",
"xterm": "^4.18.0"
},
"devDependencies": {
"nodemon": "^2.0.18"
}
}

@ -0,0 +1,13 @@
// import { Terminal } from "xterm";
import { Terminal } from "/run/media/selcuk/Linux/repo/Anka_Anvil/Rev1/node/node_modules/xterm/lib/xterm.js";
const terminal = document.getElementById("terminal");
console.log("hi");
const term = Terminal({ cols: 120, rows: 40 });
// const term = new Terminal();
// term.open(terminalDiv);
// term.write("first succesfull hello world");
terminal.innerHTML = "Terminal should be here";

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Anka Anvil</title>
</head>
<body>
HEllo2
<div id="terminal"></div>
<script src="js/ss.js" type="module"></script>
</body>
</html>

@ -0,0 +1,21 @@
doctype html
html
head
title Anka Anvil
body
h1 #{title}
h2 asdasd
h2#terminal
h1= title
div= foo
div
label Bar
input(
type='text'
name='city'
placeholder='start typing...'
)
input(type='submit' id='submitbtn' value='Submit')
script.
document.addEventListener('keydown', event => {console.log("Bleep!")})
document.getElementById('submitbtn').addEventListener('click', () => doSomething())
Loading…
Cancel
Save