forked from ArduPilot/companion
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37c9649
commit 384c5d2
Showing
6 changed files
with
280 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
var socket = io(); | ||
var uploader = new SocketIOFileClient(socket); | ||
var form = document.getElementById('form'); | ||
|
||
uploader.on('ready', function() { | ||
console.log('SocketIOFile ready to go!'); | ||
}); | ||
uploader.on('loadstart', function() { | ||
console.log('Loading file to browser before sending...'); | ||
}); | ||
uploader.on('progress', function(progress) { | ||
console.log('Loaded ' + progress.loaded + ' / ' + progress.total); | ||
}); | ||
uploader.on('start', function(fileInfo) { | ||
console.log('Start uploading', fileInfo); | ||
}); | ||
uploader.on('stream', function(fileInfo) { | ||
console.log('Streaming... sent ' + fileInfo.sent + ' bytes.'); | ||
}); | ||
uploader.on('complete', function(fileInfo) { | ||
console.log('Upload Complete', fileInfo); | ||
}); | ||
uploader.on('error', function(err) { | ||
console.log('Error!', err); | ||
}); | ||
uploader.on('abort', function(fileInfo) { | ||
console.log('Aborted: ', fileInfo); | ||
}); | ||
|
||
form.onsubmit = function(ev) { | ||
ev.preventDefault(); | ||
|
||
// Send File Element to upload | ||
var fileEl = document.getElementById('file'); | ||
// var uploadIds = uploader.upload(fileEl); | ||
|
||
// Or just pass file objects directly | ||
var uploadIds = uploader.upload(fileEl.files); | ||
}; | ||
|
||
function updateNew() { | ||
console.log("Update button pressed"); | ||
}; | ||
|
||
socket.on('terminal output', function(data) { | ||
var terminalEl = document.getElementById("terminal-output"); | ||
var html = terminalEl.innerHTML + data; | ||
var autoscroll = terminalEl.scrollHeight - terminalEl.scrollTop | ||
=== terminalEl.clientHeight; | ||
terminalEl.innerHTML = html.replace(/\n.*?\r/g, "\n"); | ||
if (autoscroll) { | ||
terminalEl.scrollTop = terminalEl.scrollHeight; | ||
} | ||
}); | ||
|
||
socket.on('terminal-output', function(data) { | ||
var terminalEl = document.getElementById("terminal-output"); | ||
var html = terminalEl.innerHTML + data; | ||
var autoscroll = terminalEl.scrollHeight - terminalEl.scrollTop | ||
=== terminalEl.clientHeight; | ||
//terminalEl.innerHTML = html; | ||
terminalEl.innerHTML = html.replace(/\n.*?\r/g, "\n"); | ||
if (autoscroll) { | ||
terminalEl.scrollTop = terminalEl.scrollHeight; | ||
} | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Companion Recovery Server</title> | ||
<link rel="stylesheet" type="text/css" href="styles.css"> | ||
</head> | ||
<body> | ||
<h1>Companion Recovery Server</h1> | ||
<hr> | ||
<div id="First"> | ||
Select an appropriate ".lrz" file to update Companion | ||
</div><hr> | ||
<div> | ||
<form id="form"> | ||
<input type="file" id="file"/> | ||
<input id= "submit-button" type="submit" class="button" value= "Upload" /> | ||
</form> | ||
<div id="update-div"> | ||
<button id="update-button" onclick='updateNew()'> Update </button> | ||
</div> | ||
<div id="textarea1"> | ||
<textarea rows="30" cols="90" id="terminal-output" class="dynamic-parent-width" readonly></textarea> | ||
</div> | ||
</div> | ||
|
||
<script src="socket.io.js"></script> | ||
<script src="socket.io-file-client.js"></script> | ||
<script src="app.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<!-- CSS file for Companion Recovery Server --> | ||
|
||
html, body { | ||
height: 100%; | ||
} | ||
|
||
html { | ||
padding-top: 85px; | ||
padding-bottom: 90px; | ||
display: table; | ||
margin: auto; | ||
} | ||
|
||
body { | ||
border: medium solid grey; | ||
margin-top: 100px; | ||
margin-left: 600px; | ||
margin-right: 600px; | ||
margin-bottom: 100px; | ||
border-radius: 10px; | ||
display: table-cell; | ||
vertical-align: middle; | ||
} | ||
|
||
h1 { | ||
font-family: verdana; | ||
font-size: 1.5em; | ||
text-align: center; | ||
padding: 20px; | ||
padding-top: 30px; | ||
} | ||
|
||
hr { | ||
text-align: center; | ||
width: 80%; | ||
} | ||
|
||
#First { | ||
font-size: 14pt; | ||
font-family: verdana; | ||
color: #2699d0; | ||
padding: 10px; | ||
text-align: center; | ||
} | ||
|
||
form { | ||
padding: 20px; | ||
text-align: center; | ||
padding-bottom: 10px; | ||
} | ||
|
||
textarea { | ||
|
||
font-family: verdana; | ||
resize: vertical; | ||
border-radius: 10px; | ||
} | ||
|
||
#textarea1 { | ||
margin-left: 30px; | ||
margin-right: 30px; | ||
padding-bottom: 30px; | ||
} | ||
|
||
#submit-button { | ||
border-radius: 5px; | ||
background-color: #2699d0; | ||
border: thin solid #2699d0; | ||
color: #ffffff; | ||
width: 80px; | ||
height: 30px; | ||
} | ||
|
||
#update-button { | ||
border-radius: 5px; | ||
background-color: #bbbbbb; | ||
border: thin solid #bbbbbb; | ||
color: #000000; | ||
width: 80px; | ||
height: 30px; | ||
} | ||
|
||
#update-div { | ||
padding-bottom: 20px; | ||
text-align: center; | ||
} | ||
|
||
|
||
<!-- Styles that are divs start with a # sign --> | ||
<!-- Styles that are classes start with a . --> | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
const express = require('express'); | ||
const app = express(); | ||
const SocketIOFile = require('socket.io-file'); | ||
|
||
var server = app.listen(3000, function() { | ||
console.log("Server running successfully on Port:3000"); | ||
}); | ||
var io = require('socket.io')(server); | ||
|
||
app.get('/', (req, res, next) => { | ||
return res.sendFile(__dirname + '/recovery-client/index.html'); | ||
}); | ||
|
||
app.get('/app.js', (req, res, next) => { | ||
return res.sendFile(__dirname + '/recovery-client/app.js'); | ||
}); | ||
|
||
app.get('/socket.io.js', (req, res, next) => { | ||
return res.sendFile(__dirname + '/node_modules/socket.io-client/dist/socket.io.js'); | ||
}); | ||
|
||
app.get('/socket.io-file-client.js', (req, res, next) => { | ||
return res.sendFile(__dirname + '/node_modules/socket.io-file-client/socket.io-file-client.js'); | ||
}); | ||
|
||
app.get('/styles.css', (req,res,next) => { | ||
return res.sendFile(__dirname + '/recovery-client/styles.css'); // redirect CSS bootstrap | ||
}); | ||
|
||
|
||
io.on('connection', function(socket) { | ||
console.log('Socket connected.'); | ||
|
||
var count = 0; | ||
var uploader = new SocketIOFile(socket, { | ||
// uploadDir: { // multiple directories | ||
// music: 'data/music', | ||
// document: 'data/document' | ||
// }, | ||
uploadDir: '/mnt/Imagefile', // simple directory | ||
// accepts: ['application/octet-stream'], // chrome and some of browsers checking mp3 as 'audio/mp3', not 'audio/mpeg' | ||
// maxFileSize: 4294967296, // 4 GB. default is undefined(no limit) | ||
chunkSize: 26214400, // default is 10240(1KB) 94371840 52428800 | ||
transmissionDelay: 0, // delay of each transmission, higher value saves more cpu resources, lower upload speed. default is 0(no delay) | ||
overwrite: false, // overwrite file if exists, default is true. | ||
/*rename: function(filename) { | ||
var split = filename.split('.'); // split filename by .(extension) | ||
var fname = split[0]; // filename without extension | ||
var ext = split[1]; | ||
return `${fname}_${count++}.${ext}`; | ||
}*/ | ||
}); | ||
uploader.on('start', (fileInfo) => { | ||
console.log('Start uploading'); | ||
console.log(fileInfo); | ||
socket.emit('terminal output', "\n" + "Start Uploading" + "\n" + "\n"); | ||
socket.emit('terminal output', JSON.stringify(fileInfo, null, 2) + '\n' + '\n'); | ||
}); | ||
uploader.on('stream', (fileInfo) => { | ||
console.log(`${fileInfo.wrote} / ${fileInfo.size} byte(s)`); | ||
socket.emit('terminal-output', '\r' + "Progress --> " + Math.round(fileInfo.wrote / fileInfo.size * 100) + " %"); | ||
}); | ||
uploader.on('complete', (fileInfo) => { | ||
console.log('Upload Complete.'); | ||
console.log(fileInfo); | ||
socket.emit('terminal output', "\n" + "\n" + "Upload Complete" + "\n"); | ||
socket.emit('terminal output', '\n' + JSON.stringify(fileInfo, null, 2) + '\n'); | ||
}); | ||
uploader.on('error', (err) => { | ||
console.log('Error!', err); | ||
socket.emit('terminal output', "\n" + err + "\n"); | ||
}); | ||
uploader.on('abort', (fileInfo) => { | ||
console.log('Aborted: ', fileInfo); | ||
socket.emit('terminal output', "\n" + JSON.stringify(fileInfo, null, 2) + "\n"); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
cd /home/pi/companion/br-webui | ||
node recovery-server.js |