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

add support for connect over raw tcp socket #425

Merged
merged 3 commits into from Feb 8, 2017

Conversation

cs8425
Copy link
Contributor

@cs8425 cs8425 commented Feb 7, 2017

use esp8266 as wifi-to-serial transparent bridge.
test with esp-link v2.2.3
I had disabled debug log, not test with debug log on.
(web setting page >> Debug log >> off, see: jeelabs/esp-link#83 )

usage:

select Manual Selection
type tcp://esp-ip:port (esp-link default: tcp://192.168.4.1:2323)
and click connect

Copy link
Member

@mikeller mikeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cs8425. I like your pull request, I think it's a valuable addition. Unfortunately I cannot test it at the moment, as I don't have an unused esp8266 (some are in the mail).

I have made some suggestions for fixes / improvements. Can you please amend them?

js/serial.js Outdated
@@ -1,6 +1,9 @@
'use strict';

var serial = {
connectionType: 'serial', // 'serial' or 'tcp'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for maintainability, can you please add new stuff to the bottom of the list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after failed, before transmitting?
or after outputBuffer, before connect?
Sorry for my bad English.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where it is now is good. Having new stuff at the beginning is confusing. And don't worry about English, it isn't my first language either, and the same goes for many contributors here.

js/serial.js Outdated
@@ -12,10 +15,76 @@ var serial = {
transmitting: false,
outputBuffer: [],

LOGHEAD: 'SERIAL: ',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a constant, so it should be logHead.

js/serial.js Outdated
connect: function (path, options, callback) {
var self = this;
self.openRequested = true;

var testUrl = path.match(/tcp:\/\/(.*):(.*)/)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be more specific here: /^http:\/\/([A-Za-z0-9\.-]+)\:(\d+)$/. This will also ensure that the port number is numeric.

js/serial.js Outdated
var testUrl = path.match(/tcp:\/\/(.*):(.*)/)
if (testUrl) {
self.connectionIP = testUrl[1];
self.connectionPort = testUrl[2] || self.connectionPort;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testUrl[2] will always be defined. If you want it to default to the predefined port, make the port number optional in the regex: /^http:\/\/([A-Za-z0-9\.-]+)(?:\:(\d+))?$.

js/serial.js Outdated
self.openRequested = false;
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double linebreak.

js/serial.js Outdated
connect: function (path, options, callback) {
var self = this;
self.openRequested = true;

var testUrl = path.match(/tcp:\/\/(.*):(.*)/)
if (testUrl) {
self.connectionIP = testUrl[1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd stick the two clauses of this if statement into connectTcp and connectSerial respectively to increase readability.

js/serial.js Outdated
console.log('setNoDelay', noDelayResult)
if(noDelayResult != 0) {
self.openRequested = false;
console.log(self.LOGHEAD + 'Failed to setNoDelay');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a case where the app requires additional permissions? If so, we should log it to the application's log with GUI.log(chrome.i18n.getMessage('<messageName>')). (Messages are in messaages.json.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app only requires 1 more permissions,
already in manifest.json.
setNoDelay is to disable Nagle's Algorithm,
which cause a little delay between data input and real send out.
Maybe change it as an option?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No that's all good then. There are cases where apps need to be given special permissions in chrome (i.e. outside of the app), but if this isn't one of them then just logging it to the console is fine.

@cs8425
Copy link
Contributor Author

cs8425 commented Feb 8, 2017

fixes and add a little error handle.

known issue:
in CLI page, idle too long got ERR_SOCKET_NOT_CONNECTED, FC will stuck in CLI mode.
Reboot FC or re-connect manually by something like nc to exit CLI mod.

@mikeller
Copy link
Member

mikeller commented Feb 8, 2017

I am not worried about the CLI issue. There is a similar one when using a serial connection: If disconnecting the cable while in CLI with a battery connected, it's not possible to reconnect before power cycling.

@mikeller mikeller merged commit 06c46d3 into betaflight:master Feb 8, 2017
@mikeller
Copy link
Member

mikeller commented Feb 8, 2017

Thank you very much for your contribution, @cs8425.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants