From 98b3829796b5cec573bc8e0876fb82785c2b5f6e Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Wed, 15 Jul 2015 16:52:09 +0200 Subject: [PATCH 1/3] Fix duplication issues --- serial.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/serial.go b/serial.go index 3773e572f..4f45421e7 100755 --- a/serial.go +++ b/serial.go @@ -472,22 +472,24 @@ func spListDual(network bool) { // happen on windows in a fallback scenario where an // open port can't be identified because it is locked, // so just solve that by manually inserting - for port := range sh.ports { + if network { + for port := range sh.ports { - isFound := false - for _, item := range list { - if strings.ToLower(port.portConf.Name) == strings.ToLower(item.Name) { - isFound = true + isFound := false + for _, item := range list { + if strings.ToLower(port.portConf.Name) == strings.ToLower(item.Name) { + isFound = true + } } - } - if !isFound { - // artificially push to front of port list - log.Println(fmt.Sprintf("Did not find an open port in the serial port list. We are going to artificially push it onto the list. port:%v", port.portConf.Name)) - var ossp OsSerialPort - ossp.Name = port.portConf.Name - ossp.FriendlyName = port.portConf.Name - list = append([]OsSerialPort{ossp}, list...) + if !isFound { + // artificially push to front of port list + log.Println(fmt.Sprintf("Did not find an open port in the serial port list. We are going to artificially push it onto the list. port:%v", port.portConf.Name)) + var ossp OsSerialPort + ossp.Name = port.portConf.Name + ossp.FriendlyName = port.portConf.Name + list = append([]OsSerialPort{ossp}, list...) + } } } From 5c1c638ed4dcce745370fbb461bb67c186700264 Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Tue, 21 Jul 2015 16:06:02 +0200 Subject: [PATCH 2/3] Remove fallback completely --- serial.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/serial.go b/serial.go index 4f45421e7..6fb94fd4f 100755 --- a/serial.go +++ b/serial.go @@ -472,26 +472,26 @@ func spListDual(network bool) { // happen on windows in a fallback scenario where an // open port can't be identified because it is locked, // so just solve that by manually inserting - if network { - for port := range sh.ports { - - isFound := false - for _, item := range list { - if strings.ToLower(port.portConf.Name) == strings.ToLower(item.Name) { - isFound = true - } - } - - if !isFound { - // artificially push to front of port list - log.Println(fmt.Sprintf("Did not find an open port in the serial port list. We are going to artificially push it onto the list. port:%v", port.portConf.Name)) - var ossp OsSerialPort - ossp.Name = port.portConf.Name - ossp.FriendlyName = port.portConf.Name - list = append([]OsSerialPort{ossp}, list...) - } - } - } + // if network { + // for port := range sh.ports { + + // isFound := false + // for _, item := range list { + // if strings.ToLower(port.portConf.Name) == strings.ToLower(item.Name) { + // isFound = true + // } + // } + + // if !isFound { + // // artificially push to front of port list + // log.Println(fmt.Sprintf("Did not find an open port in the serial port list. We are going to artificially push it onto the list. port:%v", port.portConf.Name)) + // var ossp OsSerialPort + // ossp.Name = port.portConf.Name + // ossp.FriendlyName = port.portConf.Name + // list = append([]OsSerialPort{ossp}, list...) + // } + // } + // } // we have a full clean list of ports now. iterate thru them // to append the open/close state, baud rates, etc to make From dbd146d6941815501769dd4cdb3a81cd8f359def Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Thu, 23 Jul 2015 16:11:26 +0200 Subject: [PATCH 3/3] Use a faster implementation to avoid crashes when reading a lot of data --- main.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 6b1019ee4..411a07a98 100755 --- a/main.go +++ b/main.go @@ -301,14 +301,18 @@ const homeTemplateHtml = ` var socket; var msg = $("#msg"); - var log = $("#log"); + var log = document.getElementById('log'); + var messages = []; function appendLog(msg) { - var d = log[0] - var doScroll = d.scrollTop == d.scrollHeight - d.clientHeight; - msg.appendTo(log) + messages.push(msg); + if (messages.length > 100) { + messages.shift(); + } + var doScroll = log.scrollTop == log.scrollHeight - log.clientHeight; + log.innerHTML = messages.join("
"); if (doScroll) { - d.scrollTop = d.scrollHeight - d.clientHeight; + log.scrollTop = log.scrollHeight - log.clientHeight; } } @@ -334,7 +338,7 @@ const homeTemplateHtml = ` appendLog($("
Connection closed.
")) }); socket.on("message", function(evt) { - appendLog($("
").text(evt)) + appendLog(evt); }); } else { appendLog($("
Your browser does not support WebSockets.
"))