Skip to content

Conversation

@jjblum
Copy link

@jjblum jjblum commented Feb 10, 2017

Pull request to be completed simultaneously with platypusllc/server/feature/runtime_sensor_selection, commit 69b0f756, pull request

The firmware now establishes the objects in the platypus::sensors[ ] array at runtime. The array starts with dummy objects and serial handlers. The phone server application sends a JSON that specifies which sensor objects should populate the array. The firmware parses this JSON command and instantiates the appropriate sensor objects, clearing any memory that might have been used by old sensor objects.

jjblum added 8 commits January 5, 2017 16:06
Had to add default constructor for Sensor.
Also had to make Sensor.name() not purely virtual to allow for static class variables.
…ged in.

Can't free the static dummy sensor memory, so fixed that.
Had to increase the ES2 on/off interval to get serial from it.
Works most of the time, but it is possible to start sending gibberish messages that cause the phone to crash.
This seems to occur when you leave a sensor plugged in after it was working and then tell the firmware it is dummy/none.
The sensor (or another sensor) may then start sending gibberish very very quickly to the phone, causing it to crash.
For example, this occurred when S1 started as DO and S3 started as ES2, and then S1 is set to dummy.
This caused S3 to send ridiculous messages much faster than it should.
The JSON parsing in the phone is protected by try/catch that works when gibberish is sent that normal rates,
  but reading.type.toString() will cause an uncaught null pointer exception if it is sent at extreme rates.
The previous commit caused gibberish to appear on other sensor channels when a
real sensor was set to dummy, e.g.

DO, dummy, ES2 --> dummy, dummy, ES2

could cause the ES2 channel to produce gibberish extremely quickly,
overwhelming the phone and crashing it.

The serial handlers were stored in a separate global array.
Setting the sensor to a dummy did not change what was already set up as a callback reference,
and this probably caused the undefined behavior.

Now, when a sensor is set back to a dummy, its corresponding serial handler is as well.
@jjblum
Copy link
Author

jjblum commented Feb 24, 2017

Do I also need to reset the pin settings for the channel when I set it back to a dummy? That is not included in this pull request.

@jjblum
Copy link
Author

jjblum commented Mar 2, 2017

There is an issue. sensors[0] needs to be left as a ServoSensor. Otherwise the airboat will not turn the fan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants