SOS Assertion Failure

I am running an Electron with version 1.0.1 and I am receiving an SOS (Assertion Failure) using hardware serial (serial4 and serial5) when a spike in the sensor occurs. Below is an example of what I am doing and it seems to occur when trying to read the serial output.

void ParticularSensor::readSensor() {
        char frame[32];
        frame[0] = b0; #defined in other part of code
        frame[1] = b1; #defined in other part of code
        frame[2] = b2; #defined in other part of code
        frame[3] = b3; #defined in other part of code

        char currentFrame;
        for(int i = 4; i < 32; i++) {
          if (serial == 4) {
            while (!Serial4.available()) { Particle.process(); }
            currentFrame = Serial4.read();
            frame[i] = currentFrame;
          } else if (serial == 5) {
            while (!Serial5.available()) { Particle.process(); }
            currentFrame = Serial5.read();
            frame[i] = currentFrame;
          }
        }

        int value = (int(frame[10])*256 + int(frame[11]));
        setRawDataValue(pm1, String(value));
        value = (int(frame[12])*256 + int(frame[13]));
        setRawDataValue(pm2, String(value));
        value = (int(frame[14])*256 + int(frame[15]));
        setRawDataValue(pm3, String(value));
}

My class has the following set function for a map of std::map<String, String> rawData;

void Sensor::setRawDataValue(String name, String value) {

    rawData[name] = value;
    
}

And I am calling this code using a vector of std::vector<Sensor*> sensorVector; and the code below after having the sensor initialized and inserted into the vector:

for (std::vector<Sensor*>::iterator it = sensorVector.begin(); it != sensorVector.end(); it++) {
  (*it)->readSensor();
}

This code works when the sensor is in ambient air, but when applied to substance to spike the sensor readings, from values of 0-5 to values over a 1000, it causes a SOS error. Why is this happening?

Note:
If I have this code in main with no classes, it will work without any errors, but I have this code is a separate .cpp file since I want to create class for each specific sensor that inherits from the sensor class.

With that limited insight into your code it’s hard to tell.

Potential causes may be

  • uninitialised/wrong object pointers.
    To find out and prevent SOS panic add a check whether the pointer points to a live object.
  • DIV/0 exceptions (especially with integer divisions rendering “unexpected” 0 results where you’d expect something between 0.0 and 1.0)
  • use of potentially uninitialised objects/functions in a global object constructors
  • …
1 Like