Browse Source

dummy login

develop
Robin Thoni 8 years ago
parent
commit
aa48159b17
2 changed files with 32 additions and 13 deletions
  1. 8
    3
      config.h
  2. 24
    10
      main.ino

+ 8
- 3
config.h View File

16
 #define SELF_TEST_ERROR_LABEL "Error: "
16
 #define SELF_TEST_ERROR_LABEL "Error: "
17
 #define UID_LABEL "UID:"
17
 #define UID_LABEL "UID:"
18
 #define PWD_LABEL "PWD:"
18
 #define PWD_LABEL "PWD:"
19
-#define LOGIN_IN_PROGRESS "Login..."
20
-#define LOGIN_FAILED "Login failed"
21
-#define LOGIN_SUCCESS "Access granted"
19
+#define LOGIN_IN_PROGRESS_LABEL "Login..."
20
+#define LOGIN_FAILED_LABEL "Login failed"
21
+#define LOGIN_SUCCESS_LABEL "Access granted"
22
 
22
 
23
 #define UID_MAX_LEN 12
23
 #define UID_MAX_LEN 12
24
 #define PWD_MAX_LEN 12
24
 #define PWD_MAX_LEN 12
26
 #define MAX_IDLE_TIME 20
26
 #define MAX_IDLE_TIME 20
27
 
27
 
28
 #define LOGIN_FAILED_TIME 2
28
 #define LOGIN_FAILED_TIME 2
29
+#define MAX_LOGIN_TIME 5
29
 
30
 
30
 #define SELF_TEST_INTERVAL 60
31
 #define SELF_TEST_INTERVAL 60
31
 #define SELF_TEST_ERROR_INTERVAL 2
32
 #define SELF_TEST_ERROR_INTERVAL 2
44
 #define PACKET_SELF_TEST 2
45
 #define PACKET_SELF_TEST 2
45
 #define PACKET_LOGIN 3
46
 #define PACKET_LOGIN 3
46
 
47
 
48
+#define LOGIN_OK 0
49
+#define LOGIN_FAILED 1
50
+#define LOGIN_ERROR 2
51
+
47
 #define DEBUG
52
 #define DEBUG
48
 
53
 
49
 
54
 

+ 24
- 10
main.ino View File

150
         }
150
         }
151
     }
151
     }
152
     else if (status == LoginInProgress) {
152
     else if (status == LoginInProgress) {
153
-        lcd.print(LOGIN_IN_PROGRESS);
153
+        lcd.print(LOGIN_IN_PROGRESS_LABEL);
154
     }
154
     }
155
     else if (status == LoginFailed) {
155
     else if (status == LoginFailed) {
156
-        lcd.print(LOGIN_FAILED);
156
+        lcd.print(LOGIN_FAILED_LABEL);
157
     }
157
     }
158
     else if (status == LoginSuccess) {
158
     else if (status == LoginSuccess) {
159
-        lcd.print(LOGIN_SUCCESS);
159
+        lcd.print(LOGIN_SUCCESS_LABEL);
160
     }
160
     }
161
 }
161
 }
162
 
162
 
173
     status = LoginInProgress;
173
     status = LoginInProgress;
174
     updateLcd();
174
     updateLcd();
175
 
175
 
176
-    delay(LOGIN_FAILED_TIME * 1000);
177
-
178
     hostCommunication.login(uid, password);
176
     hostCommunication.login(uid, password);
179
 
177
 
180
-    status = LoginSuccess;
181
-    updateLcd();
182
-
183
-    delay(LOGIN_FAILED_TIME * 1000);
178
+    HostCommunicationResult res = hostCommunication.read(MAX_LOGIN_TIME * 1000);
184
 
179
 
185
-    askUidPassword();
180
+    if (!res.isSuccess || res.length != sizeof(SERIAL_PACKET_TYPE_INT)) {
181
+        selfTest();
182
+        return;
183
+    }
184
+    else {
185
+        int loginRes = *(SERIAL_PACKET_TYPE_INT*)res.data;
186
+        if (loginRes == LOGIN_OK) {
187
+            status = LoginSuccess;
188
+        }
189
+        else if (loginRes == LOGIN_FAILED) {
190
+            status = LoginFailed;
191
+        }
192
+        else {
193
+            selfTest();
194
+            return;
195
+        }
196
+        updateLcd();
197
+        delay(LOGIN_FAILED_TIME * 1000);
198
+        askUidPassword();
199
+    }
186
 }
200
 }
187
 
201
 
188
 void selfTest()
202
 void selfTest()

Loading…
Cancel
Save