diff --git a/GPN_BadgeLasertag.ino b/GPN_BadgeLasertag.ino index 55787ea149d024d45bec50a6329d1bae7c8b8575..1cabf39b4f5d6bd01607db1521439d0f009c8ed0 100644 --- a/GPN_BadgeLasertag.ino +++ b/GPN_BadgeLasertag.ino @@ -81,19 +81,36 @@ void hostGame() { #endif } +bool isNumber(char number){ + return number >= 0x30 && number <= 0x39; +} + bool isValidIp(String ip){ unsigned short pos0 = ip.indexOf('.'); - unsigned short pos1 = ip.indexOf('.', pos0); - unsigned short pos2 = ip.indexOf('.', pos1); - unsigned short pos3 = ip.indexOf('.', pos2); + unsigned short pos1 = ip.indexOf('.', pos0+1); + unsigned short pos2 = ip.indexOf('.', pos1+1); + + String tuple0 = ip.substring(0, pos0); + String tuple1 = ip.substring(pos0 + 1, pos1); + String tuple2 = ip.substring(pos1 + 1, pos2); + String tuple3 = ip.substring(pos2 + 1, ip.length() - 1); - String part0 = ip.substring(0, pos0); - String part1 = ip.substring(pos0, pos1); - String part2 = ip.substring(pos1, pos2); - String part3 = ip.substring(pos2, ip.length()); + bool isValid = true; - Serial.printf("Zerhackstuekelte IP: %s:%s:%s:%s", part0.c_str(), part1.c_str(), part2.c_str(), part3.c_str()); + for (int i = 0; i < tuple0.length(); i++){ + Serial.printf("tuple0: %d -> %c\n", i, tuple0[i]); + isValid &= isNumber(tuple0[i]); + } + for (int i = 0; i < tuple1.length(); i++){ + Serial.printf("tuple1: %d -> %c\n", i, tuple1[i]); + } + for (int i = 0; i < tuple2.length(); i++){ + Serial.printf("tuple2: %d -> %c\n", i, tuple2[i]); + } + for (int i = 0; i < tuple3.length(); i++){ + Serial.printf("tuple3: %d -> %c\n", i, tuple3[i]); + } } @@ -106,9 +123,9 @@ String recv_ir() { bool dataVerified = false; uint8_t checksumRec = 0; - bool done = false; + //bool done = false; - while (!dataCompleted && !done) { + while (!dataCompleted) { int on_time = 0; decode_results results; // Somewhere to store the results if (irrecv.decode(&results)) { @@ -116,18 +133,19 @@ String recv_ir() { Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWBUF"); return "a12\n7.0\n.0.\n1b"; } - char *buf = reinterpret_cast<char *>(&results.value); if (millis() - on_time > 500) { pixels.setPixelColor(1, pixels.Color(0, 0, 0)); pixels.show(); } - + uint8_t checksum = 'X'; if (stringCompleted) { uint8_t checksum = buf[1]; dataCompleted = true; + Serial.printf("checksum?? %c;%c\n", checksumRec << 8 | 222, checksum); + if (checksum == checksumRec) { dataVerified = true; pixels.setPixelColor(1, pixels.Color(0, 100, 0)); @@ -142,7 +160,8 @@ String recv_ir() { Serial.printf("->:\n\t0: %c\n\t1: %c\n\t2: %c\n\t3: %c\n", buf[0], buf[1], buf[2], buf[3]); if (buf[0] == '\n' || buf[1] == '\n' || buf[2] == '\n' || buf[3] == '\n') { stringCompleted = true; - done = isValidIp(received.substring(1, received.length() - 2)); + Serial.printf("string complete %s\n", received.c_str()); +//done = true; //isValidIp(received.substring(1, received.length() - 2)); } } irrecv.resume(); // Prepare for the next value