-
Notifications
You must be signed in to change notification settings - Fork 517
replace error strings with error codes #80
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
|
Adding an error message to the Firmata protocol is a good idea. For now, the proposed message format only supports 1 data byte, thus offering codes ranging from 0 - 127. E.g, bigger error codes could make it easier to 'classify' error codes, by reserving on or more bits for that purpose. |
|
I agree. I'll update the proposal and pull request. Bigger thing I still need to get consensus on here is moving error messages from Strings (as they are currently represented... taking up a lot of SRAM) to numeric codes. It will be a backwards incompatible update for anyone who was relying on the error string messages. |
|
I would like to share one more thought: reserve error codes 0 to 127 for the Firmata protocol itself. Doing so you keep the possibility to implement standardized Firmata error codes later on. |
|
Error msg might need a bit of context (e.g. Feature on Pin didn't succeed - this requires information about pinmode and pin). So I'd suggest: |
|
I prefer to keep the error message simple and basic and avoid to tie it up to specific scenarios (like pinmode). The bytecodes of my example regarding a pinmode error would simply look like this: When there is a need for communicating more data (i.e. pin number and mode), it is better to append it after the initial error code: |
|
In ConfigurableFirmata you'd have two cases. The error either comes from the Firmata base or from one of the configured features which are (with the exceptions of FirmataExt and FirmataScheduler) associated with a pinmode (which is not nessesary a mode the arduino allows to set nativly, but mere a numer that identifies the feature configured for this pin). Thats why I don't think the pinmode is optional. If it were all error-messages coming from a feature would contain two error codes: First the code that tells its 'not core Firmata', then the one that is specific for this feature. The only way to overcome this would be some kind of 'error-code-registry' for custom-features which I'd like to avoid.
|
|
What about: Error type is similar to what Norbert is talking about regarding pin modes. So you could have feature-specific errors. I2C for example (where most of the current string error messages are). I also need to add errors for memory usage since we have dynamic allocation so that's another broad category. However memory errors are also feature related (Servo, Stepper and OneWire feature classes all allocate memory dynamically via malloc). |
|
isn't this basically the same as my proposal without the mandatory pin (indeed I intended the pin to be optional)? Or would you rather put the pinmode into byte 3 if ERROR_TYPE says 'pinmode-specific-error'? I don't have a strong oppinion here - it just should be short in terms of memory required to send the message, but not too short to not restrict introduction of future pinmodes (aka 'features' in configurable). |
|
I have been thinking about the error type byte and I am still not convinced it would make sense to make it part of the error message. It would require a well thought out taxonomy of error types, describing the meaning of all supported error types precisely. It is easier to reserve the first 127 (or 1000 or whatever) codes for the Firmata protocol and leave it up to the user to design error codes of their own. The reserved error codes pretty much tell you what type of error you are dealing with. Error code examples:
etc. |
|
How would you classify errors from 1-Wire, I2C, Servo, Shift or any other (not yet developed) feature? By using a byte for error_type/pinmode/feature the developer of a new feature has to care about getting a pinmode assigned and is free to choose his errorcodes as he likes without getting in conflict with other features. As a user (not developer) of custom-features you wouldn't want to go to the sourcecode and care about uniqueness of error-codes. |
|
I agree with Norbert that we need some level of classification. For example there are currently 4 i2c errors defined in StandardFirmata: "I2C Read Error: Too many bytes received" Each error message is currently sent as a Firmata String message. Having a pin or error type of I2C for example would make it easier to keep error codes organized. If we shift to a numeric (rather than String) error message implementation, it will be the responsibility of the Firmata client implementation to present any errors to the user in a meaningful way based on the numberic codes received from the board. So the first i2c error message above could be represented like this using numeric codes: This feature / pin specific features are organized and IMO would be much easier to keep organized on the client side. If at some point in the future you need a new I2C error type, you give it the next value in the enumeration. Contrast that with a single list of numeric error codes that are sequential. You could have feature specific error codes scattered throughout list. |
|
OK, when we decide to introduce an error type (or class), it would be necessary to dictate a fixed set of well defined error types, wouldn't it? I mean, when you leave it up to implementers of the protocol to design error types themselves, client code can not rely on the meaning of the error type it receives, thus rendering this code useless. E.g., error types could be (only to draw the picture):
What's your opinion on this? |
|
Feature level types are already defined as pin modes (this is what Norbert has been referring to): When a new feature is added, a new pin mode is added and thus a new error type (and each error type can have multiple type specific error codes) can be added. If there is no SPI support now there can be no SPI errors until a SPI feature is added for example. Pin types would need to be reserved up to a value of 0x127. There should also be a section of numbers reserved for user application error types. |
This update frees 122 bytes of RAM. I have replace the old string error messages in StandardFirmata with single byte error codes (0 - 127). A user can add custom error codes to any Firmata sketch. The client library should provide a message for each error code (or otherwise handle the error as necessary).
This update may impact any client library that handles the old string error messages sent by StandardFirmata (if this is actually the case with any client library - I suspect it is rare). However, given that this pull request is for Firmata 2.4.0 and the RAM savings and overall more explicit nature of the new error_code I think this update justifies the backwards incompatible change.