Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying the destination path #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 15 additions & 5 deletions webrepl.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<div class="file-box">
<strong>Send a file</strong>
<input type="file" id="put-file-select" />
<strong>Destination path</strong>
<input type="text" name="set_filepath" id="put_filepath" value="." size="13" />
<div id="put-file-list"></div>
<input type="button" value="Send to device" id="put-file-button" onclick="put_file(); return false;" />
</div>
Expand Down Expand Up @@ -85,6 +87,7 @@
var connected = false;
var binary_state = 0;
var put_file_name = null;
var put_file_path = null;
var put_file_data = null;
var get_file_name = null;
var get_file_data = null;
Expand Down Expand Up @@ -273,20 +276,27 @@

function put_file() {
var dest_fname = put_file_name;
var dest_fpath = document.getElementById('put_filepath').value;
var dest_fsize = put_file_data.length;
var dest_full_fname = dest_fpath + '/' + dest_fname;

// WEBREPL_FILE = "<2sBBQLH64s"
var rec = new Uint8Array(2 + 1 + 1 + 8 + 4 + 2 + 64);
rec[0] = 'W'.charCodeAt(0);
rec[1] = 'A'.charCodeAt(0);
rec[2] = 1; // put
rec[3] = 0;
rec[4] = 0; rec[5] = 0; rec[6] = 0; rec[7] = 0; rec[8] = 0; rec[9] = 0; rec[10] = 0; rec[11] = 0;
rec[12] = dest_fsize & 0xff; rec[13] = (dest_fsize >> 8) & 0xff; rec[14] = (dest_fsize >> 16) & 0xff; rec[15] = (dest_fsize >> 24) & 0xff;
rec[16] = dest_fname.length & 0xff; rec[17] = (dest_fname.length >> 8) & 0xff;
rec[4] = 0; rec[5] = 0; rec[6] = 0; rec[7] = 0; rec[8] = 0; rec[9] = 0;
rec[10] = 0; rec[11] = 0;
rec[12] = dest_fsize & 0xff;
rec[13] = (dest_fsize >> 8) & 0xff;
rec[14] = (dest_fsize >> 16) & 0xff;
rec[15] = (dest_fsize >> 24) & 0xff;
rec[16] = dest_full_fname.length & 0xff;
rec[17] = (dest_full_fname.length >> 8) & 0xff;
for (var i = 0; i < 64; ++i) {
if (i < dest_fname.length) {
rec[18 + i] = dest_fname.charCodeAt(i);
if (i < dest_full_fname.length) {
rec[18 + i] = dest_full_fname.charCodeAt(i);
} else {
rec[18 + i] = 0;
}
Expand Down