Explorar o código

Parse and validate message

Robert Marshall %!s(int64=5) %!d(string=hai) anos
pai
achega
589067ab08
Modificáronse 1 ficheiros con 10 adicións e 1 borrados
  1. 10 1
      Receiver/src/main.cpp

+ 10 - 1
Receiver/src/main.cpp

@@ -4,6 +4,14 @@
 RH_ASK _driver;
 unsigned int _output = 12;
 
+bool validateMessage(char* message){
+	return strncmp("LED On: ", message, 8) == 0; //returns 0 on match
+}
+
+bool parseMessage(char* message){
+	return validateMessage(message) && message[8] == '1';
+}
+
 void setup(){
 	pinMode(_output, OUTPUT);
 	Serial.begin(9600);
@@ -20,6 +28,7 @@ void loop(){
 		Serial.print("Message: ");
 		Serial.println((char *)buf);
 
-		digitalWrite(_output, buf[8] == '1');
+		Serial.println(validateMessage((char *)buf));
+		Serial.println(parseMessage((char *)buf));
 	}
 }