Hi,
I have been developing a arduino library called Mote which is performing a function similar to a Remote Terminal Unit used in SCADA.
I have many methods calling other methods within the class, and some variables are class variables so I dont have to pass variables as arguments to internal functions.
My problem is that certain methods have gibberish in the global class variables while others are fine. The way I tested this is with print statement for debugging.
The global class variables are defined as public in the Mote.h as:
char* topic;
char* payload;
int payloadLength;
Then the sketch hands data to the library through the method call:
mote.execute(topic,payload,payloadLength);
The method for execute is:
void Mote::execute(char* topic, char* payload, int payloadLength){
this->topic = topic;
this->payload = payload;
this->payloadLength = payloadLength;
Serial.print("Mote::execute: topic = ");
Serial.println(this->topic);
Serial.print("Mote::execute: payload = ");
Serial.println(this->payload);
bool validMsg = AL_decode();
//Serial.print("Mote::execute: validMsg: ");
Serial.println(validMsg);
if(validMsg){
if(String(protocol.objType)=="$L"){
Controller_latch(conversions.charA2int(protocol.index), String(protocol.value));
}else if(String(protocol.objType)=="$P"){
Controller_pulse(conversions.charA2int(protocol.index), String(protocol.value));
}
}
//reset the protocol variables
resetProtocol();
//reset the global topic and payload variables
resetTopicAndPayload();
}
Here the variables to the execute method are stored into global class variables. I did some debug prints here to check:
Mote::execute: topic = 1/11/$L/101
Mote::execute: payload = 1
Mote::AL_decode: topic =
Mote::AL_decode: payload = 1
Mote::decode: srcNode= 0
Mote::decode: destNode: 0
Mote::decode: objType:
Mote::decode: index:
Mote::decode: value: 1
0
Then execute calls AL_decode() which has the first few lines of code below:
bool Mote::AL_decode(){
//Decode topic and payload into system variable protocol struct c/o src,dest,objType, index, value - old rxFromNetwork
///topic = "1/11/$P/151";
//payload = "1000";
Serial.print("Mote::AL_decode: topic = ");
Serial.println(this->topic);
Serial.print("Mote::AL_decode: payload = ");
Serial.println(this->payload);
So somehow based on the print debugs the AL_decode() get garbage data as the global class variables, specifically for "topic".
Why is this so? Am I out of RAM?
I am running this on an Arduino Uno with the sketch size of 9324 bytes.
Please any help would be appreciated.
Thanks in advance
Jason