-
Notifications
You must be signed in to change notification settings - Fork 516
Split marshalling behavior into new FirmataMarshaller class #319
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
Your proposed changes make sense. I'm trying to think of how this would look as a stand-alone library (that firmata/arduino uses). Standalone lib would contain:
Also curious if FirmataMarshaller would make more sense as a FirmataBase class. I guess the issue there would be that some of the method signatures differ slightly (size_t vs byte). |
I will change FirmataDefines to FirmataConstants, because I think that matches the intent and doesn't necessarily need to describe the implementation. I wouldn't expect an Arduino user to use these new classes, unless they were intending to control a subsequent arduino or arduinos (an interesting scenario). I would mostly expect to see this on Raspberry Pis, CHIP, etc. I don't see it as a base class because it strictly translates calls from stubs into your protocol, which is the literal definition of marshalling. In this way the marshaller can be stateless (with the exception of a stream - which I should eliminate). If you are concerned about duplicated effort, v3.0.0 would allow you to shuffle certain methods (i.e. sendValueAsTwo7bitBytes) from FirmataClass into FirmataMarshaller that may be better suited to implementation only. That example specifically would allow you to make a more advanced packing algorithm without disrupting your users. FirmataClass has a unique role of orchestrating the parser and marshaller specifically designed for the Arduino, and I don't see any reason to change. Based on some of the comments and unused code, I see that you have already started to think about retaining state, in order to extend and improve the behavior of FirmataClass. That totally makes sense, and that scenario is enabled and encapsulated with this new architecture. Let me rev this real quick and we'll talk again. |
I made the file name change to I made Finally, in an attempt to remove all state from This caused me to battle with the compiler and ultimately lose. ;-P Then that thrust me into a giant philosophical debate (with myself) about why static callbacks aren't the way to move forward. As you know, the current callbacks in the parser are static, likely due to the fact Now that we are moving components (parser and marshaller) into cross platform libraries that will be executed on more powerful systems, it seems silly to force them to only have a single instance. For example, there is no reason a Raspberry Pi 3 shouldn't be able to send data to and receive data from two MKR1000s using WiFi simultaneously. In summary, leaving the |
*/ | ||
FirmataMarshaller::FirmataMarshaller() | ||
: | ||
FirmataStream(nullptr) |
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.
nullptr issue with Intel compiler
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.
Also used a few other places in this file.
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.
Doh! Sorry that's normally a good habit! :-P
fixing...
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.
fixed
I'll run some smoke tests tonight. |
@soundanalogous Sounds great! I'll check in periodically this evening to see if you hit any snags. |
Also, where is the best URL to direct users to for Windows Remote Arduino? I don't currently have a link to it in the README file. |
Thanks for thinking of that! Since I'm rev'ing the core as we speak, let's make that update later. |
*/ | ||
FirmataMarshaller::FirmataMarshaller() | ||
: | ||
FirmataStream((Stream *)NULL); |
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.
remove semicolon or this won't compile
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.
Other than this I'm not seeing any issues when running my test rig and complies without errors for all supported architectures.
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.
One moment please.
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.
@soundanalogous fixed
I think all is good here. @zfields anything else you wanted to add to this PR? |
@soundanalogous For now, I think it accomplishes what I set out to do. I would love to continue to contribute as much as you'll let me. I love the protocol and I believe with minimal tweaking it will allow me to achieve all the goals I have for my project for the foreseeable future. |
/* DEPRECATED as of Firmata v2.5.1. As of 2.5.1 there are separate version numbers for | ||
* the protocol version and the firmware version. | ||
*/ | ||
#define FIRMATA_MAJOR_VERSION 2 // same as FIRMATA_PROTOCOL_MAJOR_VERSION |
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.
These 3 deprecated defines need to be included in Firmata.h or older Firmata sketches will break.
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 meant to leave those in there. Let me see what I've done.
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 originally left them in there. I must have removed them by accident, I'll put them right back. I'm sorry.
5df1cbe
to
0af3a17
Compare
@soundanalogous The deprecated defines are restored, and it compiles and passes my tests |
Cool all looks good now. Merging... To replicate the compiler test sequence I go through, install the board packages for the following packages using the Arduino boards manager:
You may need to enter the following URLs into Arduino > Preferences... > Additional Boards Manager URLs to get some of the above packages to show up:
And also install the TeensyDuino library (It's typically 1 version of the Arduino IDE behind latest stable is for Arduino 1.6.11): http://www.pjrc.com/teensy/td_download.html Then try to compile StandardFirmata or StandardFirmataPlus for the following boards:
Also:
Now that I think of it, it's may be possible to script this process using arduino-builder. I'll try to look into that later this week or next weekend. |
This new class will provide cross platform marshalling of Firmata procedure calls. It can be updated independently of Firmata.h, which allows its functionality to be enhanced without breaking the existing API surface offered through Firmata.h.
This passes the Firmata test suite, as well as my independent verification using an UNO and Windows Remote Arduino.