September 2019 Update

New! We're moving to the new forum!

ALL new Blog posts will be on the forum.

Please join us there.

This Blog will no longer be updated...

Saturday, August 10, 2019

Night Watchman

A mysterious bug popped up while I was fiddling with code early tonight, suddenly it was going haywire when loading the list of sensors for a Sensor Module.  I'm not sure the circumstances that kick off the error, but it had to do with me loading the sensor data in two parts because of a limitation of the MySql library (memory related)

I opted to first load a list of sensor Id's only, into an array of INT[maxNumberOfSensors]
then I would loop this array and load the first bunch of sensor configuration fields for a sensor, then another query to load the second group of fields for a sensor, and simply populate one struct with the results, leaving me with a complete sensor configuration record, and I then send it to the 2560 over the serial port, enclosed withing XML tags. 

I used the same database cursor for all three queries, figuring in each step, I was done with it, and didn't need the result sets any more, I had already grabbed what I needed.  This was new in my changes from the other night, as in the past, it was two completely separate calls to load the sensor config, and completely separate sql queries.

It was loading a complete list of sensorId into the array, but when it queried for a specific sensor, if simply failed to get any results, seems random...  The code made an assumption (ok, the programmer made an assumption) ((OK, IT WAS ME!!))  that it would find the record, afterall, it got the id in the first query...

When it failed to find the record, and my lack of error checking (honest, I'm usually pretty good about error checking) exposed another failure on my part... I knew it seemed too easy...
Between each call to populate the sensor configuration data structure, I SHOULD clear out any data that is already in therem because in this case, when it failed to load a record, it merrily went on it's way thinking the data already in the record was correct, and sent it to the 2560 again as another senor, but it was a duplicate...

The fix, simply add a call to the clearSensorConfig method, and create new cursors for each of the three queries.  

So far, we're batting 1000!

So here I sit, watching the screen, listening to Metallica blasting away full blast in my ear buds... Smoking joints, just chilling tonight...

I'll post an update later in the morning...

No comments:

Post a Comment

Any comments deemed off topic or offensive will be removed