Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork155
Remove global clients#1014
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…OME and HOME directories
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
codecov-commenter commentedMar 31, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@## main #1014 +/- ##==========================================+ Coverage 20.24% 20.81% +0.57%========================================== Files 42 42 Lines 3241 3291 +50 ==========================================+ Hits 656 685 +29- Misses 2498 2515 +17- Partials 87 91 +4
Flags with carried forward coverage won't be shown.Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…serial, and update files
…ating logAction method
dido18 commentedApr 3, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Tested on linux with MKR 1010
|
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
hub.go Outdated
p.OnClose=func(port*serport) { | ||
hub.serialPortList.MarkPortAsClosed(p.portName) | ||
hub.serialPortList.List() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think you can remove theOnClose
callback and move those two lines of code in thespClose
method below after callingp.Close()
. AFAIK this struct is the only one closing ports, so moving the code there should cover all the cases. The following should be the updatedspClose
function:
func (hub*hub)spClose(portnamestring) {ifmyport,ok:=hub.serialHub.FindPortByName(portname);ok {hub.broadcastSys<- []byte("Closing serial port "+portname)myport.Close()hub.serialPortList.MarkPortAsClosed(myport.portName)hub.serialPortList.List()}else {hub.spErr("We could not find the serial port "+portname+" that you were trying to close.")}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
uhm I think it is also called here
arduino-create-agent/serialport.go
Line 171 inb717430
p.Close() |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
…o hub.go for better organization
Tested again like#1014 (comment) |
Test: It can download a tool.
This hte was logs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would try to reduce callbacks if possible. They are usually difficult to follow.
hub.go Outdated
onRegister:=func(port*serport) { | ||
broadcastSys<- []byte("{\"Cmd\":\"Open\",\"Desc\":\"Got register/open on port.\",\"Port\":\""+port.portConf.Name+"\",\"Baud\":"+strconv.Itoa(port.portConf.Baud)+",\"BufferType\":\""+port.BufferType+"\"}") | ||
} | ||
onUnregister:=func(port*serport) { | ||
broadcastSys<- []byte("{\"Cmd\":\"Close\",\"Desc\":\"Got unregister/close on port.\",\"Port\":\""+port.portConf.Name+"\",\"Baud\":"+strconv.Itoa(port.portConf.Baud)+"}") | ||
} | ||
serialHubub:=newSerialHub(onRegister,onUnregister) | ||
onList:=func(data []byte) { | ||
broadcastSys<-data | ||
} | ||
onErr:=func(errstring) { | ||
broadcastSys<- []byte("{\"Error\":\""+err+"\"}") | ||
} | ||
serialPortList:=newSerialPortList(tools,onList,onErr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would simplify both of this two with theChanWriter
onRegister:=func(port*serport) { | |
broadcastSys<- []byte("{\"Cmd\":\"Open\",\"Desc\":\"Got register/open on port.\",\"Port\":\""+port.portConf.Name+"\",\"Baud\":"+strconv.Itoa(port.portConf.Baud)+",\"BufferType\":\""+port.BufferType+"\"}") | |
} | |
onUnregister:=func(port*serport) { | |
broadcastSys<- []byte("{\"Cmd\":\"Close\",\"Desc\":\"Got unregister/close on port.\",\"Port\":\""+port.portConf.Name+"\",\"Baud\":"+strconv.Itoa(port.portConf.Baud)+"}") | |
} | |
serialHubub:=newSerialHub(onRegister,onUnregister) | |
onList:=func(data []byte) { | |
broadcastSys<-data | |
} | |
onErr:=func(errstring) { | |
broadcastSys<- []byte("{\"Error\":\""+err+"\"}") | |
} | |
serialPortList:=newSerialPortList(tools,onList,onErr) | |
serialHubub:=newSerialHub(ChanWriter{Ch:broadcastSys}) | |
serialPortList:=newSerialPortList(tools,ChanWriter{Ch:broadcastSys}) |
OnListfunc([]byte)`json:"-"` | ||
OnErrfunc(string)`json:"-"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
OnListfunc([]byte)`json:"-"` | |
OnErrfunc(string)`json:"-"` | |
writerio.Writer`json:"-"` |
serial.go Outdated
sh.mu.Lock() | ||
//log.Print("Registering a port: ", p.portConf.Name) | ||
h.broadcastSys<- []byte("{\"Cmd\":\"Open\",\"Desc\":\"Got register/open on port.\",\"Port\":\""+port.portConf.Name+"\",\"Baud\":"+strconv.Itoa(port.portConf.Baud)+",\"BufferType\":\""+port.BufferType+"\"}") | ||
sh.onRegister(port) |
lucarin91Apr 18, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
sh.onRegister(port) | |
fmt.Fprintf(sh.writer,`{"Cmd":"Open","Desc":"Got register/open onport.","Port":%q,"Baud":%d,"BufferType":%q}`,port.portConf.Name ,port.portConf.Baud,port.BufferType) |
sh.mu.Lock() | ||
//log.Print("Unregistering a port: ", p.portConf.Name) | ||
h.broadcastSys<- []byte("{\"Cmd\":\"Close\",\"Desc\":\"Got unregister/close on port.\",\"Port\":\""+port.portConf.Name+"\",\"Baud\":"+strconv.Itoa(port.portConf.Baud)+"}") | ||
sh.onUnregister(port) |
lucarin91Apr 18, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
sh.onUnregister(port) | |
fmt.Fprintf(sh.writer,`{"Cmd":"Close","Desc":"Got unregister/close onport.","Port":%q,"Baud":%d}`,port.portConf.Name,port.portConf.Baud) |
OnList:onList, | ||
OnErr:onErr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
OnList:onList, | |
OnErr:onErr, | |
writer:io.Writer, |
//log.Println(err) | ||
h.broadcastSys<- []byte("Error creating json on port list "+ | ||
err.Error()) | ||
sp.OnErr("Error creating json on port list "+err.Error()) |
lucarin91Apr 18, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
sp.OnErr("Error creating json on port list"+err.Error()) | |
fmt.Fprintf(sp.writer,"Error creating json on port list%s",err.Error()) |
sp.OnErr("Error creating json on port list "+err.Error()) | ||
}else { | ||
h.broadcastSys<-ls | ||
sp.OnList(ls) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
sp.OnList(ls) | |
sp.Write(ls) |
I added some comments but I don't want to block the PR
cmaglie commentedApr 24, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I've merged#1032 here. |
Uh oh!
There was an error while loading.Please reload this page.
Please check if the PR fulfills these requirements
before creating one)
The purpose of this PR is to improve the maintainability, testability, and clarity of the codebase by removing global variables and explicitly passing dependencies as arguments to functions or methods. Global variables can lead to tightly coupled code, making it harder to understand, test, and maintain.
remove global variables, they are now created in the main function and passed explicitly to the components or functions that need them.
move the
go hub.serialPortList.Run()
from themaingo
into thehub.run()
because the hub is in charge of connecting serial events to websocket clients.No.