Browse Source

dummy login

develop
Robin Thoni 8 years ago
parent
commit
cad821e3aa
2 changed files with 29 additions and 0 deletions
  1. 4
    0
      src/config.h
  2. 25
    0
      src/main.cpp

+ 4
- 0
src/config.h View File

@@ -19,4 +19,8 @@
19 19
 #define PACKET_SELF_TEST 2
20 20
 #define PACKET_LOGIN 3
21 21
 
22
+#define LOGIN_OK 0
23
+#define LOGIN_FAILED 1
24
+#define LOGIN_ERROR 2
25
+
22 26
 #endif //DIGICODE_HOST_CONFIG_H

+ 25
- 0
src/main.cpp View File

@@ -1,5 +1,6 @@
1 1
 #include <iostream>
2 2
 #include<signal.h>
3
+#include <sstream>
3 4
 #include "DataAccess/ArduinoSerial.h"
4 5
 
5 6
 
@@ -16,6 +17,21 @@ std::string hexStr(std::string str)
16 17
     return s;
17 18
 }
18 19
 
20
+std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
21
+    std::stringstream ss(s);
22
+    std::string item;
23
+    while (std::getline(ss, item, delim)) {
24
+        elems.push_back(item);
25
+    }
26
+    return elems;
27
+}
28
+
29
+std::vector<std::string> split(const std::string &s, char delim) {
30
+    std::vector<std::string> elems;
31
+    split(s, delim, elems);
32
+    return elems;
33
+}
34
+
19 35
 int lastSignal = 0;
20 36
 
21 37
 void sig_handler(int signo)
@@ -49,6 +65,15 @@ int main()
49 65
             SERIAL_PACKET_TYPE_INT status = ERROR_NONE;
50 66
             arduinoSerial.write((const char*)&status, sizeof(status));
51 67
         }
68
+        if (data.getData().first == PACKET_LOGIN) {
69
+            std::vector<std::string> login = split(data.getData().second, '\n');
70
+            if (login.size() == 2) {
71
+                std::string uid = login[0];
72
+                std::string passwd = login[1];
73
+                SERIAL_PACKET_TYPE_INT status = (uid == "4242" ? LOGIN_OK : LOGIN_FAILED);
74
+                arduinoSerial.write((const char *) &status, sizeof(status));
75
+            }
76
+        }
52 77
     }
53 78
     return 0;
54 79
 

Loading…
Cancel
Save