-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.h
More file actions
655 lines (594 loc) · 19.3 KB
/
user.h
File metadata and controls
655 lines (594 loc) · 19.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
#ifndef USER_H_
#define USER_H_
#include "systemc.h"
#include "interface.h"
#include <string>
using namespace std;
/* Please check interface.h. There you will find all possbile values.*/
SC_MODULE(User) {
//output ports for smartphone inputs
sc_fifo_out<Activity> activity;
sc_out<bool> pt_pressed; //for powering_on, lock/unlock-screen, powering_off
sc_out<bool> ps_plugged; //power supply plugged in/off true/false
//input ports for monitoring the smartphone's status
sc_fifo_in<CmdPrompt> cmdprompt;
sc_fifo_in<Notification> notification;
sc_in<bool> powered_on;
sc_in<Display> display;
sc_in<Screen> screen;
sc_in<int> battery_level;
bool userChanged;
SC_CTOR(User) {
userChanged=false;
SC_THREAD(fst_seq);
}
void fst_seq()
{
//turn smartphone on:
turn_on();
bool isPowered = powered_on.read();
CmdPrompt currentPrompt = cmdprompt.read();
Display displayState = display.read();
Screen currentScreen = screen.read();
if (isPowered == false) {
print("Smartphone should be powered on by now. Thread will be closed...");
return;
}
if (displayState != Display::DISP_BRIGHT) {
print("Smartphone display should be shnining bright. Thread will be closed...");
}
if (currentPrompt != CmdPrompt::CMD_ENTER_PIN) {
print("Smartphone should be giving a PIN request. Thread will be closed...");
return;
}
if (currentScreen != Screen::SCR_PIN_REQUEST) {
print("Smartphone Screen doesn't show a PIN-request. Thread will be closed...");
return;
}
//enter wrong pin
print("Entering wrong PIN..");
activity.write(Activity::ACT_WRONG_PIN);
wait(1,SC_SEC);
Notification noti = notification.read();
currentScreen = screen.read();
if (noti != Notification::NOTI_WRONG_PIN) {
print("Smartphone doesn't state that the entered PIN was wrong. Thread will be closed...");
return;
}
if (currentScreen != Screen::SCR_PIN_REQUEST) {
print("Smartphone Screen doesn't show a PIN-request. Thread will be closed...");
return;
}
//enter correct pin
print("Entering correct PIN..");
activity.write(Activity::ACT_CORRECT_PIN);
wait(1,SC_SEC);
noti = notification.read();
currentScreen = screen.read();
if (noti != Notification::NOTI_CORRECT_PIN) {
print("Smartphone doesn't state that the entered PIN was correct. Thread will be closed...");
return;
}
if (currentScreen != Screen::SCR_HOME) {
print("Smartphone Screen doesn't show home screen. Thread will be closed...");
return;
}
//choose app
print("Choosing APP 3...");
activity.write(Activity::ACT_APP3);
wait(1,SC_SEC);
currentScreen = screen.read();
if (currentScreen != Screen::SCR_APP3) {
print("Smartphone Screen doesn't show APP 3. Thread will be closed...");
return;
}
//wait smartphone to be dimmed
print("Waiting for the Smartphone to be dimmed...");
activity.write(Activity::ACT_NOTHING);
wait(80,SC_SEC);
displayState = display.read();
if (displayState != Display::DISP_MEDIUM) {
print("Smartphone display should be dimmed by now. Thread will be closed...");
return;
}
//simple activity
print("Doing Something in current APP...");
activity.write(Activity::ACT_DEFAULT);
wait(1,SC_SEC);
displayState = display.read();
if (displayState != Display::DISP_BRIGHT) {
print("Smartphone display should be bright by now. Thread will be closed...");
return;
}
//press pt shortly
click_pt_button();
displayState = display.read();
currentScreen = screen.read();
if (displayState != Display::DISP_DARK) {
print("Smartphone display should be dark by now. Thread will be closed...");
return;
}
if (currentScreen != Screen::SCR_TURNED_OFF) {
print("Smartphone screen should be turned off by now. Thread will be closed...");
return;
}
//wait a moment
print("Just waiting and doing nothing...For 10 Seconds");
activity.write(Activity::ACT_NOTHING);
wait(10,SC_SEC);
//press pt shortly
click_pt_button();
displayState = display.read();
currentScreen = screen.read();
if (displayState != Display::DISP_BRIGHT) {
print("Smartphone display should be bright by now. Thread will be closed...");
return;
}
if (currentScreen != Screen::SCR_PIN_REQUEST) {
print("Smartphone screen should be showing a PIN request. Thread will be closed...");
return;
}
//enter correct pin
print("Entering correct PIN..");
activity.write(Activity::ACT_CORRECT_PIN);
wait(1,SC_SEC);
noti = notification.read();
currentScreen = screen.read();
if (noti != Notification::NOTI_CORRECT_PIN) {
print("Smartphone doesn't state that the entered PIN was correct. Thread will be closed...");
return;
}
if (currentScreen != Screen::SCR_APP3) {
print("Smartphone Screen doesn't show APP3. Thread will be closed...");
switch(currentScreen){
case Screen::SCR_HOME : print("home");break;
case Screen::SCR_PIN_REQUEST : print("pin");break;
case Screen::SCR_TURNED_OFF : print("off");break;
default: print("app");
}
return;
}
//press home_button,
print("Going back to home menu...");
activity.write(Activity::ACT_HOME);
wait(1,SC_SEC);
currentScreen = screen.read();
if (currentScreen != Screen::SCR_HOME) {
print("Smartphone Screen doesn't show home menu. Thread will be closed...");
return;
}
//let display timeout
print("Waiting for the Smartphone to be timed out...");
activity.write(Activity::ACT_NOTHING);
wait(101,SC_SEC);
displayState = display.read();
currentScreen = screen.read();
if (displayState != Display::DISP_DARK) {
print("Smartphone display should be dimmed by now. Thread will be closed...");
return;
}
if (currentScreen != SCR_TURNED_OFF) {
print("Smartphone Screen should be turned off by now. Thread will be closed...");
return;
}
//wait until battery is low (auto shutdown)
print("waiting for low battery auto shutdown");
int batt = battery_level.read();
while (batt > 10) {
wait(1,SC_SEC);
batt = battery_level.read();
}
int num_noti = notification.num_available();
bool infoLowBattery = false;
while (num_noti > 0 && !(infoLowBattery)) {
noti = notification.read();
if (noti == Notification::NOTI_LOW_BATTERY_LEVEL) {
infoLowBattery = true;
}
num_noti--;
}
if (infoLowBattery == false) {
print("Smartphone has not informed about Low Battery Level. Thread will be closed...");
return;
}
batt = battery_level.read();
isPowered = powered_on.read();
if (!(isPowered) && batt > 7) {
print("Smartphone's battery level is high enough. Smartphone shouldn't be powered off. Thread will be closed...");
}
if (isPowered) {
int battOld = 0;
while (isPowered || (batt != battOld)) {
wait(3,SC_SEC);
battOld = batt;
batt = battery_level.read();
isPowered = powered_on.read();
}
}
if (batt < 4) {
print("Smartphone's battery level is lower than allowed and shouldn't get that low. Thread will be closed...");
}
if (batt > 7) {
print("Smartphone's battery level is high enough. Smartphone shouldn't be powered off. Thread will be closed...");
}
isPowered = powered_on.read();
if (isPowered) {
print("Smartphone has low battery level and shouldn't be on now. Thread will be closed...");
return;
}
if (batt < 4) {
print("Smartphone's battery level is lower than allowed and shouldn't get that low. Thread will be closed...");
return;
}
//try to power up smartphone
print("Trying to power-up the smartphone...");
turn_on();
wait(1,SC_SEC);
isPowered = powered_on.read();
if (isPowered) {
print("Smartphone has low battery level and shouldn't be able to run. Thread will be closed...");
return;
}
//state: "Mist, Ladekabel vergessen! ;-)"
print("What a pitty. I must have forgotten my Smartphone's charging cable. END");
//add notification for 2nd user process here
scnd_seq();
}
void scnd_seq(){
userChanged=true;
cout<<endl;
print("***************************** User2 came **********************************");
cout<<endl;
wait(1,SC_SEC);
print("Trying to power-up the smartphone when battery level<10%...");
turn_on();
wait(1,SC_SEC);
bool isPowered = powered_on.read();
if (isPowered) {
print("Smartphone has low battery level and shouldn't be able to run. Thread will be closed...");
return;
}
//here charge the phone
ps_plugged.write(true);
wait(120,SC_SEC);//10%
print("Trying to power-up the smartphone when battery level=10%...");
turn_on();
wait(1,SC_SEC);
isPowered = powered_on.read();
if (isPowered) {
print("Smartphone has low battery level and shouldn't be able to run. Thread will be closed...");
return;
}
cout<<"battery level now:"<<battery_level.read()<<endl;
wait(60,SC_SEC);//13%
print("Trying to power-up the smartphone when battery level>10%...");
turn_on();
wait(1,SC_SEC);
isPowered = powered_on.read();
CmdPrompt currentPrompt = cmdprompt.read();
Display displayState = display.read();
Screen currentScreen = screen.read();
if (!isPowered) {
print("Smartphone should be powered on by now. Thread will be closed...");
cout<<battery_level.read()<<endl;
return;
}
cout<<"battery level now:"<<battery_level.read()<<endl;
click_pt_button();//close screen
print("Stop charging");
ps_plugged.write(false); //unplug
wait(180,SC_SEC);//10%
cout<<"battery level now:"<<battery_level.read()<<endl;
turn_off();
wait(3,SC_SEC);
print("Trying to power-up the smartphone when battery level=10%...");
turn_on();
isPowered = powered_on.read();
if (isPowered) {
print("Smartphone has low battery level and shouldn't be able to run. Thread will be closed...");
return;
}
ps_plugged.write(true);
print("Charge 200s to make it possible to open the phone");
wait(200,SC_SEC);//in 200s the battery level should be over 10%
print("Short press to see whether phone will be opened");
click_pt_button();
isPowered = powered_on.read();
if (isPowered) {
print("Smartphone was short pressed and shouldn't be able to run. Thread will be closed...");
return;
}
wait(1,SC_SEC);
turn_on();
isPowered = powered_on.read();
currentPrompt = cmdprompt.read();
displayState = display.read();
currentScreen = screen.read();
if (isPowered == false) {
print("Smartphone should be powered on by now. Thread will be closed...");
return;
}
if (displayState != Display::DISP_BRIGHT) {
print("Smartphone display should be shining bright. Thread will be closed...");
}
if (currentPrompt != CmdPrompt::CMD_ENTER_PIN) {
print("Smartphone should be giving a PIN request. Thread will be closed...");
return;
}
if (currentScreen != Screen::SCR_PIN_REQUEST) {
print("Smartphone Screen doesn't show a PIN-request. Thread will be closed...");
return;
}
//enter correct pin
print("Entering correct PIN...");
activity.write(Activity::ACT_CORRECT_PIN);
wait(1,SC_SEC);
Notification noti = notification.read();
currentScreen = screen.read();
print("Wait 1 min to see whether phone charge correctly when screen on");
activity.write(Activity::ACT_DEFAULT);
//remember the battery_level
int oldBattery1 = battery_level.read();
//watch, if the phone ist correctly charged with screen on
wait(60,SC_SEC);
int newBattery1 = battery_level.read();
int chargeScreenOn = newBattery1-oldBattery1;
if (chargeScreenOn != 1){
print("Smartphone is not correctly charged with screen on. Thread will be closed...");
cout<<chargeScreenOn<<endl;
return;
}
//watch, if the phone ist correctly charged with screen off
print("Closing the screen...");
wait(1,SC_SEC);
click_pt_button();//press pt shortly
displayState = display.read();
currentScreen = screen.read();
if (displayState != Display::DISP_DARK) {
print("Smartphone display should be dark by now. Thread will be closed...");
return;
}
if (currentScreen != Screen::SCR_TURNED_OFF) {
print("Smartphone screen should be turned off by now. Thread will be closed...");
return;
}
print("Wait 1 min to see whether phone charge correctly when screen off");
int oldBattery2 = battery_level.read();
wait(60,SC_SEC);
int newBattery2 = battery_level.read();
int chargeScreenOff = newBattery2-oldBattery2;
if (chargeScreenOff != 2){
print("Smartphone is not correctly charged with screen off. Thread will be closed...");
cout<<chargeScreenOff<<endl;
return;
}
//watch, if the phone ist correctly charged when turned off
//wait(1,SC_SEC);
print("Turning off the phone...");
int oldBattery3 = battery_level.read();
//Turn the smartphone off
turn_off();
print("Wait 1 min to see whether phone charge correctly when itself is turned off");
wait(60,SC_SEC);
turn_on();
isPowered = powered_on.read();
currentPrompt = cmdprompt.read();
displayState = display.read();
currentScreen = screen.read();
print("Entering correct PIN..");
activity.write(Activity::ACT_CORRECT_PIN);
wait(1,SC_SEC);
int newBattery3 = battery_level.read();
int chargeTurnOff = newBattery3-oldBattery3;
if (chargeTurnOff != 3){
print("Smartphone is not correctly charged when turned off. Thread will be closed...");
return;
}
//App wechsel
print("Choosing APP 1...");
activity.write(Activity::ACT_APP1);
wait(1,SC_SEC);
currentScreen = screen.read();
if (currentScreen != Screen::SCR_APP1) {
print("Smartphone Screen doesn't show APP 1. Thread will be closed...");
return;
}
//press home_button,
print("Going back to home menu...");
activity.write(Activity::ACT_HOME);
wait(1,SC_SEC);
currentScreen = screen.read();
if (currentScreen != Screen::SCR_HOME) {
print("Smartphone Screen doesn't show home menu. Thread will be closed...");
return;
}
print("Choosing APP 2...");
activity.write(Activity::ACT_APP2);
wait(1,SC_SEC);
currentScreen = screen.read();
if (currentScreen != Screen::SCR_APP2) {
print("Smartphone Screen doesn't show APP 2. Thread will be closed...");
return;
}
print("Going back to home menu...");
activity.write(Activity::ACT_HOME);
wait(1,SC_SEC);
currentScreen = screen.read();
if (currentScreen != Screen::SCR_HOME) {
print("Smartphone Screen doesn't show home menu. Thread will be closed...");
return;
}
print("Choosing APP 3...");
activity.write(Activity::ACT_APP3);
wait(1,SC_SEC);
currentScreen = screen.read();
if (currentScreen != Screen::SCR_APP3) {
print("Smartphone Screen doesn't show APP 3. Thread will be closed...");
return;
}
print("Going back to home menu...");
activity.write(Activity::ACT_HOME);
wait(1,SC_SEC);
currentScreen = screen.read();
if (currentScreen != Screen::SCR_HOME) {
print("Smartphone Screen doesn't show home menu. Thread will be closed...");
return;
}
print("Choosing APP 4...");
activity.write(Activity::ACT_APP4);
wait(1,SC_SEC);
currentScreen = screen.read();
if (currentScreen != Screen::SCR_APP4) {
print("Smartphone Screen doesn't show APP 4. Thread will be closed...");
return;
}
print("Going back to home menu...");
activity.write(Activity::ACT_HOME);
wait(1,SC_SEC);
currentScreen = screen.read();
if (currentScreen != Screen::SCR_HOME) {
print("Smartphone Screen doesn't show home menu. Thread will be closed...");
return;
}
print("Choosing APP 5...");
activity.write(Activity::ACT_APP5);
wait(1,SC_SEC);
currentScreen = screen.read();
if (currentScreen != Screen::SCR_APP5) {
print("Smartphone Screen doesn't show APP 5. Thread will be closed...");
return;
}
print("Going back to home menü...");
activity.write(Activity::ACT_HOME);
wait(1,SC_SEC);
currentScreen = screen.read();
if (currentScreen != Screen::SCR_HOME) {
print("Smartphone Screen doesn't show home menu. Thread will be closed...");
return;
}
//Ausschalten bei App-Nutzung
print("Choosing APP 5...");
activity.write(Activity::ACT_APP5);
wait(1,SC_SEC);
currentScreen = screen.read();
if (currentScreen != Screen::SCR_APP5) {
print("Smartphone Screen doesn't show APP 5. Thread will be closed...");
return;
}
print("Turning off when APP 5 opened...");
turn_off();
//after the turn off
wait(10,SC_SEC);
turn_on();
isPowered = powered_on.read();
currentPrompt = cmdprompt.read();
displayState = display.read();
currentScreen = screen.read();
print("Entering correct PIN..");
activity.write(Activity::ACT_CORRECT_PIN);
wait(1,SC_SEC);
noti = notification.read();
currentScreen = screen.read();
if (noti != Notification::NOTI_CORRECT_PIN) {
print("Smartphone doesn't state that the entered PIN was correct. Thread will be closed...");
return;
}
if (currentScreen != Screen::SCR_HOME) {
print("Smartphone Screen doesn't show home screen. Thread will be closed...");
return;
}
print("Turning off in Haupt Menü");
turn_off();//in Haupt Menü
//after the turn off
wait(10,SC_SEC);
print("Turning on again");
turn_on();
isPowered = powered_on.read();
currentPrompt = cmdprompt.read();
displayState = display.read();
currentScreen = screen.read();
print("Entering correct PIN..");
activity.write(Activity::ACT_CORRECT_PIN);
wait(1,SC_SEC);
noti = notification.read();
currentScreen = screen.read();
if (noti != Notification::NOTI_CORRECT_PIN) {
print("Smartphone doesn't state that the entered PIN was correct. Thread will be closed...");
return;
}
if (currentScreen != Screen::SCR_HOME) {
print("Smartphone Screen doesn't show home screen. Thread will be closed...");
return;
}
//press to close screen shortly before it closing automatically, to see whether screen will open again
activity.write(Activity::ACT_NOTHING);
wait(1,SC_SEC);
print("wait 100.5s");
activity.write(Activity::ACT_DEFAULT);
wait(99500,SC_MS);
//wait(500,SC_MS);
print("press to close screen shortly before it closing automatically");
click_pt_button();
displayState = display.read();
if (displayState != Display::DISP_DARK) {
print("Smartphone display should not be opened again. Thread will be closed...");
return;
}
wait(100,SC_SEC);
print("Turning off when Screen is dark");
turn_off();//in Haupt Menü
isPowered = powered_on.read();
if (isPowered) {
print("Smartphone should not be powered on by now. Thread will be closed...");
return;
}
cout<<endl;
print("########################### Test Succeeded! ###########################");
cout<<endl;
}
/*
//print given string on cout
void print(string s){
cout << "[" << sc_time_stamp() << " / " << sc_delta_count() << "](" << name() << "): " << s << endl;
}
*/
//print given string on cout
void print(string s){
cout << "[" << sc_time_stamp() << " / " << sc_delta_count() << "](" << (userChanged==false?"User1":"User2") << "): " << s << endl;
}
// Some possible actions
//Turn the Smartphone on.
void turn_on()
{
print("turn_on()");
pt_pressed.write(true);
//print("pt has been pressed and held..");
wait(3, SC_SEC);
pt_pressed.write(false);
//print("pt has been released");
wait(1,SC_SEC);
}
//Turn the smartphone off
void turn_off()
{
print("turn_off()");
pt_pressed.write(true);
//print("pt has been pressed");
wait(3, SC_SEC);
pt_pressed.write(false);
//print("pt has been released");
wait(1,SC_SEC);
}
//lock or unlock screen
void click_pt_button()
{
print("click_pt_button()");
pt_pressed.write(true);
//print("pt has been pressed");
wait(1, SC_SEC);
pt_pressed.write(false);
//print("pt has been released");
wait(1,SC_SEC);
}
};
#endif