-
Notifications
You must be signed in to change notification settings - Fork 96
Add packet transfer protocol #188
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
Conversation
Looks good so far! I think given EventEmitter isn't on browser it might be worth adding I guess the input data handler would ideally be its own function rather than buried inside Right now we don't remove XON/XOFF chars from the input stream, but I think we'd probably want to do that now (as we need to be able to remove the packet ACK/NAK anyway) - and to reliably receive binary data I think we need to ignore XON/XOFF when in the middle of receiving a binary packet. |
Yeah missing the events stuff was catching me out, and by first stab at writing the packet parsing I did using The ACK/NACK does that come right after the write, so there's no control chars or anything as a preamble? Just that window of within a second after a write expect a 6 or 21 char? Another thing I wasn't sure on after reading more about the protocol (and I've not dug too much into the C code yet), with something like a |
Yeah, it's a pain not being able to rely on certain things being built in (
Correct, yes.
There's just a limitiation of response size (it's just one packet). Not ideal, but it's simple. One thing to note is the response is produced by |
This is looking really good so far - is the 'eval' you added working at the moment? |
I've been having mixed results 😄 I was going to have a chat to you about it for a bit of a direction steer lest I wander down a wrong path. I'll push my latest code, but so far I've been testing with: esp.init(() => {
Espruino.Config.set("SERIAL_FLOW_CONTROL", false)
Espruino.Core.Serial.open("COM17", (status) => {
if (status === undefined) throw new Error("Failed to connect")
Espruino.Core.Utils.executeExpressionV2('process.env', (data) => {
console.log("process.env", data)
Espruino.Core.Utils.downloadFileV2('FW.js', true, (data) => {
console.log("FW.js", data)
})
})
})
}) and I'm getting back the EVAL response okay, the download works okay if I disable flow control, but it's still not quite there as I'm not properly collecting the 0 length packet to close out the frame. I'm also not sure how to best handle concurrency and how that goes at the Espruino end, I've seen there's code that does queuing of transmit stuff, and then some of the evals was matching the request to responses maybe? Not sure how that works here, I know most things should be synchronous but wasn't sure the best way to enforce that in the code so that if a sent another EVAL while one was still ongoing, how that would maybe queue and still tie up the expected responses etc. I feel like a lot of these problems are already solved in some way in the code so I didn't want to just make Edit: |
Thanks - this is looking good!
I imagine flow control will be 'eating' the XON/XOFF - what I'd do is what we do in uart.js - handle the packets in the same code that handles ack/nack (ideally also xon/xoff but uart.js doesn't do that yet) and then emit a 'packet' event. Then you can ignore xon/xoff when in the middle of a packet (Espruino doesn't escape them as ideally it shouldn't be emitting XOFF during a packet as we're not sending stuff to it). The other benefit is the IDE could listen for packets later on (I'd planned on having the ability to maybe send debug info via packets on a separate channel) I'll have a play with this now and let you know how I get on.
Well, it's not handled super well at the moment, but I think with the code you have you're okish. Perhaps what we could do is make the callback you supply to We'd probably have to tweak the old 'eval' too but that would have suffered issues too |
I just made some changes at master...rikkuness-packetsend (aea870e) if that looks ok to you? I think file receive now works ok (with the zero packet) and it works alongside flow control. Looking at this, one thing that I can't help thinking is that the It's not perfect, but there's a lot to be said for using the exact same code in the IDE and EspruinoWebTools (I could even copy it into the |
Thanks for taking a look over it! Yeah sounds good to me, you're definitely much more familiar with the codebase so happy to take your lead on it 😄 I was a bit worried that some of what I had was diverging and I was duplicating anyway, makes sense to roll some of the WebTools stuff over here. I guess once this has those elements this almost becomes the goto package and supersedes WebTools to some degree? May be a bit more of a sledgehammer to crack a nut in some cases but it'd be nice to have that lower maintainability |
Thanks! I've just pushed some changes to https://github.com/espruino/EspruinoWebTools I'll see how well it works (it's now used for the Bangle.js App Loader) and will have a go at getting it into EspruinoTools
Yes, there's definitely an argument that the App Loader should be using it (as it uses the espruinotools package anyway). UART.js/Puck.js libs started off as just a super-simple way to get access from the PC, and there seem to be a bunch of places that use them as-is - so I think they probably still have their place, but anything that's actually writing JS code to an Espruino device should probably end up using EspruinoTools I guess. The one thing it'll be missing is the menus for selecting which connection method to use (as they're currently in the IDE) |
Ok, I've just pushed some more changes to master...rikkuness-packetsend. I've tested with:
How does this work for you? So now we're using the same Connection class as UART.js, which feels like it tidies things up a little - it's not great but as far as I can tell the CLI and IDE still works which is good! |
Hey, thanks for getting this over the line, sorry I wasn't around to test, day job has been hectic. I'll have more of a play now everything is merged up and see how I get on 🙏🏻 |
Will keep this open as a WIP and add to it as I work things out to make sure I don't end up too far down a wrong path.
Fixes #187