Skip to content
Snippets Groups Projects
Commit de1488bc authored by HoelShare's avatar HoelShare
Browse files
parents b8280176 f328038d
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment