Hi,
I'm trying to interpret code coming in from a 7600 GSM module when a call is received. I am getting the char array 'R', 'I', 'N', 'G' into my 32 byte array, I'm confirming this by mirroring out the content of the array on the console just before I compare it, but when I try and use strcmp to compare it to the string "RING" it never gets a match. Can anyone shed some light on what I'm doing wrong please?
SoftwareSerial myserial(7, 8); //Define virtual serial port name as myseria,Rx is port 7, Tx is port 8
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
const byte numGChars = 32;
char receivedGChars[numChars]; // an array to store the received data
boolean newData = false;
boolean newGData = false;
const String AlexPhone = ####;
const String LizPhone = ####;
int gesture = -1;
const int powerPin = 12;
const int ledPin = 13;
void setup() {
Serial.begin(57600);
myserial.begin(57600); //Initialize virtual serial port
while (!Serial)
turnGsmOn();
Serial.write("Starting");
}
void loop() {
recvWithEndMarker(); // Bluetooth input
showNewData();
recvGWithEndMarker(); // GSM input
showGNewData();
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
// if (Serial.available() > 0) {
while (Serial.available() > 0) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
} else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void recvGWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char grc;
// if (Serial.available() > 0) {
while (myserial.available() > 0 ) {
grc = myserial.read();
if (grc != endMarker) {
receivedGChars[ndx] = grc;
ndx++;
if (ndx >= numGChars) {
ndx = numGChars - 1;
}
} else {
receivedGChars[ndx] = '\0'; // terminate the string
ndx = 0;
newGData = true;
}
}
}
// Message from bluetooth link
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
// Checks input begins with a #
if (receivedChars[0] == 35) {
if (receivedChars[1] == 67) {
send_SMS("***********", "######");
}
if (receivedChars[1] == 66) {
send_SMS("***********", "######");
}
} else {
myserial.println(receivedChars); //if myserial received data, output it via Serial.
}
newData = false;
}
}
// Message from modem
void showGNewData() {
if (newGData == true) {
Serial.println(receivedGChars);
// The compare below never works......but if I compare just the
// first char in the array to 'R' it does, so I know I'm getting
// something through.
if (strcmp(receivedGChars, "RING") == 0) {
Serial.println("ATA");
myserial.println("ATA");
}
newGData = false;
}
}