414 Commits

Author SHA1 Message Date
Sem van der Hoeven
b2e1c90c16 Merge branch 'develop' 2020-11-02 10:38:07 +01:00
Sem van der Hoeven
86a8b2b789 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-11-02 10:37:48 +01:00
Sem van der Hoeven
aa2e16de89 fix 2020-11-02 10:37:40 +01:00
SemvdH
b112fc131e Merge pull request #11 from SemvdH/develop
[FIX] changes one line
2020-10-30 00:00:03 +01:00
shinichi
6725f2ff85 [FIX] changes one line 2020-10-29 23:59:15 +01:00
Sem van der Hoeven
89fe104418 test 2020-10-29 23:52:30 +01:00
SemvdH
2177f9bd19 Merge pull request #10 from SemvdH/develop
Develop
2020-10-29 23:50:48 +01:00
Sem van der Hoeven
28dc2c2f9c Merge branch 'unittest-setup' into develop 2020-10-29 23:49:19 +01:00
Sem van der Hoeven
cd1a95ae85 Merge branch 'unittest-setup' of https://github.com/SemvdH/Proftaak-RH-B4 into unittest-setup 2020-10-29 23:48:29 +01:00
Sem van der Hoeven
cad1a508e6 tests 2020-10-29 23:48:20 +01:00
Logophilist
06e1d1edee Last command tests 2020-10-29 23:47:18 +01:00
Logophilist
7c98aa6536 CommandTest Update 2020-10-29 23:40:11 +01:00
shinichi
d6cf5902da [ADD] update data in doctor applicatie 2020-10-29 23:32:47 +01:00
Sem van der Hoeven
c1ee84fd2e [ADD] added test methods for bools 2020-10-29 23:31:56 +01:00
Sem van der Hoeven
9f7a01170b Merge branch 'gethistoricdata' into develop 2020-10-29 22:58:51 +01:00
Sem van der Hoeven
6dd9bd4107 [ADD] finished writing historic data to documents 2020-10-29 22:57:50 +01:00
shinichi
4207eaefea [ADD] bike speed is set to 0 when session is not running 2020-10-29 22:57:10 +01:00
Logophilist
acc2fddf82 TerrainAdd, AddLayer, UpdateTerrain and renderTerrain tests done 2020-10-29 22:51:47 +01:00
Sem van der Hoeven
87b9ee65d0 [ADD] added writing contents to file 2020-10-29 22:51:14 +01:00
Logophilist
a333d6cd8d UnitTesting set up completed 2020-10-29 22:04:02 +01:00
Sem van der Hoeven
dffdae2cb4 [EDIT] tried adding lots of bike data 2020-10-29 21:01:45 +01:00
Sem van der Hoeven
baf89dac3f [ADD] added checking of all folders in username directory 2020-10-29 20:35:21 +01:00
Sem van der Hoeven
b98ac77261 [EDIT] some comments 2020-10-29 17:44:47 +01:00
shinichi
6d599cfcd2 wip gtg 2020-10-29 17:01:14 +01:00
Logophilist
c48e396e81 UnitTest Push 2020-10-28 12:01:20 +01:00
shinichi
da9d3184a1 token and volatile 2020-10-19 16:41:38 +02:00
fabjuuuh
2b6ea121c9 Merge remote-tracking branch 'origin/develop' into develop 2020-10-19 16:24:34 +02:00
fabjuuuh
478a2daab7 hi 2020-10-19 16:24:24 +02:00
shinichi
8b8dd901c7 Merge branch 'NextFocusOnEnter' into develop 2020-10-19 16:19:10 +02:00
fabjuuuh
aa5ea7a3e0 works kinda 2020-10-19 16:13:51 +02:00
shinichi
aeb5d59ce9 implemented nextfocuable 2020-10-19 15:32:14 +02:00
shinichi
ab1662f0fe Merge branch 'develop' into NextFocusOnEnter 2020-10-19 15:15:34 +02:00
shinichi
f07c3f9484 moving and fixing 2020-10-19 15:14:01 +02:00
fabjuuuh
2adfcc5bd7 fix 2020-10-19 15:13:27 +02:00
shinichi
3acdc942bc move files and copy code
from stackoverflow :P
2020-10-19 14:53:47 +02:00
shinichi
84cbcb4a6d send data to doctor 2020-10-19 14:35:51 +02:00
Logophilist
8385f09313 Bike animation added 2020-10-19 14:25:09 +02:00
fabjuuuh
3ea42b65ed Merge branch 'dataOnTabs' into develop 2020-10-19 14:11:59 +02:00
Sem van der Hoeven
55d3dd4eee actually fixed overflow exception 2020-10-19 14:09:03 +02:00
fabjuuuh
960327a3e3 Merge remote-tracking branch 'origin/develop' into dataOnTabs 2020-10-19 14:05:55 +02:00
fabjuuuh
083f27411e chart 2020-10-19 14:02:42 +02:00
shinichi
d9c8b7c6df Merge remote-tracking branch 'origin/develop' into develop 2020-10-19 14:02:07 +02:00
shinichi
de9716128c restyle tabheader 2020-10-19 14:02:03 +02:00
Sem van der Hoeven
f934dee2d0 made overflow return 255 instead of 0 2020-10-19 14:01:39 +02:00
Sem van der Hoeven
107d95b81a fixed overflowexception 2020-10-19 13:59:47 +02:00
Sem van der Hoeven
c50f898ec0 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-10-19 13:32:33 +02:00
Sem van der Hoeven
fb443a33d7 add send message 2020-10-19 13:32:26 +02:00
Sem van der Hoeven
8249632d00 add set resistance 2020-10-19 13:31:29 +02:00
shinichi
134bf235c3 multiple clients works 2020-10-19 13:24:38 +02:00
shinichi
bc738d0fa3 Merge remote-tracking branch 'origin/develop' into develop 2020-10-19 12:52:39 +02:00
shinichi
2ecc90ff2c doctor can now disconnect 2020-10-19 12:52:35 +02:00
Sem van der Hoeven
6a9e2b57ac Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-10-19 12:49:09 +02:00
Sem van der Hoeven
973ff20da4 small typo 2020-10-19 12:49:04 +02:00
shinichi
d98c32a508 Merge remote-tracking branch 'origin/develop' into develop 2020-10-19 12:24:09 +02:00
shinichi
dcf6c3c6d0 client can see if doctor connected 2020-10-19 12:23:52 +02:00
Sem van der Hoeven
689f7030e4 added displaying of last doctor message in vr scene 2020-10-19 12:20:26 +02:00
shinichi
4a238d9207 Auto stash before checking out "HEAD" 2020-10-19 12:07:00 +02:00
Sem van der Hoeven
31be096b94 added small comments 2020-10-19 11:57:42 +02:00
Sem van der Hoeven
7eb7b03d4f Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-10-19 11:55:34 +02:00
Sem van der Hoeven
17a17e3c6d added comments to dataparser 2020-10-19 11:55:20 +02:00
shinichi
163d2321cc username back added to tabs 2020-10-19 11:49:34 +02:00
shinichi
c9e913474c Merge remote-tracking branch 'origin/develop' into develop 2020-10-19 11:26:18 +02:00
shinichi
63b5c6ab73 removed unnecessary code 2020-10-19 11:26:09 +02:00
Sem van der Hoeven
6b355a0b72 added resistance editing from client to vr engine 2020-10-19 11:26:04 +02:00
fabjuuuh
9a46b17067 Merge remote-tracking branch 'origin/develop' into dataOnTabs 2020-10-19 11:20:28 +02:00
shinichi
b748bcf5c8 binded commands 2020-10-19 11:19:57 +02:00
fabjuuuh
62525f3a23 Merge remote-tracking branch 'origin/develop' into dataOnTabs 2020-10-19 11:14:57 +02:00
fabjuuuh
783c40d7d3 rip 2020-10-19 11:14:05 +02:00
shinichi
e9e3381960 icon works 2020-10-16 16:32:17 +02:00
shinichi
75ff7fe336 Merge remote-tracking branch 'origin/develop' into develop 2020-10-16 16:24:13 +02:00
shinichi
cc046d6611 wip 2020-10-16 16:24:07 +02:00
fabjuuuh
5751bbed81 Progress with structure to send data 2020-10-16 16:23:50 +02:00
Sem van der Hoeven
a76433803c Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-10-16 15:39:28 +02:00
Sem van der Hoeven
ae01646de6 added doctor icon 2020-10-16 15:39:17 +02:00
shinichi
e8a4901f09 fix 2020-10-16 15:15:09 +02:00
fabjuuuh
b868515ade Merge branch 'newDoctor' into develop 2020-10-16 15:06:52 +02:00
fabjuuuh
93eeea856f errors 2020-10-16 15:06:38 +02:00
fabjuuuh
0427fa89aa Merge remote-tracking branch 'origin/develop' into newDoctor 2020-10-16 15:04:16 +02:00
fabjuuuh
173dbf2745 update 2020-10-16 15:02:26 +02:00
shinichi
fd9b321292 doctor can see patients who logged on before 2020-10-16 15:02:19 +02:00
fabjuuuh
e3c580c8c2 Merge remote-tracking branch 'origin/develop' into newDoctor 2020-10-16 12:51:42 +02:00
shinichi
6fb9d0efaa Merge branch 'doctor-client-connecting' into develop 2020-10-16 12:49:18 +02:00
shinichi
540a640bc6 removed debuggers 2020-10-16 12:49:06 +02:00
fabjuuuh
aadbbc16a9 Workinng on communication 2020-10-16 12:48:14 +02:00
shinichi
777ed65707 Merge branch 'develop' into doctor-client-connecting 2020-10-16 12:19:04 +02:00
shinichi
44abffd7e7 closing windows works 2020-10-16 12:18:46 +02:00
shinichi
9ef51ddeca connecting to doctor after works 2020-10-16 12:18:03 +02:00
Sem van der Hoeven
2ebfea1a01 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-10-16 12:16:06 +02:00
Sem van der Hoeven
2f81f32a03 added checking for response from vr engine and automatic reconnect 2020-10-16 12:15:58 +02:00
fabjuuuh
b31fa293fb Commands 2020-10-16 11:42:32 +02:00
Sem van der Hoeven
014191b350 smol fix 2020-10-16 11:27:12 +02:00
shinichi
ac11f6c53b Merge remote-tracking branch 'origin/develop' into develop 2020-10-16 11:25:39 +02:00
shinichi
5bacfdc8ce added so only one doctor can login to server 2020-10-16 11:25:35 +02:00
Sem van der Hoeven
effdd887af Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-10-16 11:24:08 +02:00
Sem van der Hoeven
1c3e48f676 added ralfs message display on vr panel into engineconnection 2020-10-16 11:23:52 +02:00
shinichi
df37c9bd58 made doctor window fancy 2020-10-16 11:18:29 +02:00
shinichi
6ec09ec995 error catching 2020-10-16 10:51:45 +02:00
shinichi
813545c2da Merge branch 'ValueConverters' into develop 2020-10-16 10:41:52 +02:00
shinichi
29037f1774 status is now shown by image 2020-10-16 10:41:38 +02:00
shinichi
5280e70feb wip 2020-10-16 10:13:59 +02:00
shinichi
94be6fd22d Merge remote-tracking branch 'origin/develop' into develop 2020-10-14 16:28:41 +02:00
shinichi
dc2b2f06ae move styles to sharedproject and disposed client 2020-10-14 16:28:37 +02:00
Sem van der Hoeven
30c5d5a2a3 add message to server switch 2020-10-14 15:58:06 +02:00
shinichi
bbb0220c11 Merge branch 'window-restyle' into develop 2020-10-14 15:54:02 +02:00
shinichi
adf8435822 got rid of navigation ui 2020-10-14 15:53:52 +02:00
shinichi
ed19714338 Merge branch 'develop' into window-restyle 2020-10-14 15:30:00 +02:00
shinichi
c13cdf64b6 window works 2020-10-14 15:29:19 +02:00
Sem van der Hoeven
e226ab586e added message method to dataparser 2020-10-14 15:27:35 +02:00
fabjuuuh
6e534c318b Merge branch 'develop' into newDoctor 2020-10-14 15:21:03 +02:00
fabjuuuh
d8a3baeec1 Relaycommands 2020-10-14 15:19:43 +02:00
Sem van der Hoeven
ea4093ff75 added message to dataparser 2020-10-14 15:19:20 +02:00
Sem van der Hoeven
11ebc67c13 moved observableobject to util 2020-10-14 15:01:13 +02:00
Sem van der Hoeven
c5c74a3d7a moved dataparser to util 2020-10-14 14:59:00 +02:00
shinichi
756c646b93 before removing shadows 2020-10-14 14:55:58 +02:00
Sem van der Hoeven
037d7732f7 changed name from hasher to util 2020-10-14 14:55:31 +02:00
Sem van der Hoeven
91a20e0af7 set doctor of communication when doctor logs in 2020-10-14 14:49:53 +02:00
fabjuuuh
af5dca25f4 Remove Tabs when disconnect 2020-10-14 14:35:14 +02:00
shinichi
6bec8f1651 wip 2020-10-14 14:35:02 +02:00
fabjuuuh
3547207cad Merge branch 'develop' into newDoctor 2020-10-14 13:51:19 +02:00
Sem van der Hoeven
b519f33cb5 added new user when username not in file 2020-10-14 13:21:12 +02:00
Sem van der Hoeven
8263d51ca7 removed hashing username 2020-10-14 13:13:59 +02:00
fabjuuuh
ecb3be2916 Merge branch 'newDoctor' into develop 2020-10-14 13:07:20 +02:00
fabjuuuh
25176dbaeb Connections shit 2020-10-14 13:05:56 +02:00
Sem van der Hoeven
c9c0cf35a0 removed maincommand from placehouse sig 2020-10-14 13:05:55 +02:00
Sem van der Hoeven
568896c28d fully added the vr engine stuff to the client app 2020-10-14 12:21:53 +02:00
shinichi
56de6cfa24 wip 2020-10-14 12:05:28 +02:00
Sem van der Hoeven
22021dc821 removed vr engine retry button 2020-10-14 11:28:28 +02:00
Sem van der Hoeven
ea3afdeda1 added automatic reconnect to vr engine 2020-10-14 11:19:39 +02:00
shinichi
3822508b4c added empty resource files 2020-10-14 09:53:49 +02:00
shinichi
2e5dbeee14 added icon 2020-10-14 09:34:47 +02:00
shinichi
ee8333e6af try login failed popup to align
plz someone fix
2020-10-14 08:55:31 +02:00
shinichi
6ed069d0f3 Merge branch 'try-refactor-to-page' into develop 2020-10-14 08:43:11 +02:00
shinichi
fd4fcd0e51 Merge branch 'develop' into try-refactor-to-page 2020-10-14 08:42:53 +02:00
shinichi
073aa8c79a now pages
background image doesn't work so it is lime
2020-10-14 08:42:40 +02:00
fabjuuuh
301f6b447f Progress 2020-10-12 16:50:02 +02:00
fabjuuuh
df5e276eb3 Vastgelopen 2020-10-12 12:50:38 +02:00
Logophilist
87e199d1b5 Showing message on panel 2020-10-12 09:01:33 +02:00
shinichi
9761d189ec background image
i give up
2020-10-09 17:05:11 +02:00
Sem van der Hoeven
8ad861e18a conflicts 2020-10-09 16:59:31 +02:00
Sem van der Hoeven
f6e5152939 connect new gui to vr engine 2020-10-09 16:58:39 +02:00
shinichi
c8a812508f added folder for future use 2020-10-09 16:29:18 +02:00
shinichi
5fcf0d177b wip 2020-10-09 16:22:28 +02:00
shinichi
278a5adb5e change doctor password field to passwordbox 2020-10-09 16:03:49 +02:00
shinichi
528f515e0b Merge remote-tracking branch 'origin/develop' into develop 2020-10-09 15:37:30 +02:00
shinichi
b4088f5d30 edited focusable 2020-10-09 15:37:23 +02:00
Logophilist
34eed08234 Fixed grass texture, houses and time of day 2020-10-09 15:35:54 +02:00
shinichi
e410e9ec88 login failed popup shows 2020-10-09 15:07:27 +02:00
Sem van der Hoeven
25d0bda483 added new reference 2020-10-09 12:52:14 +02:00
Sem van der Hoeven
fafc96ad6a removed client 2020-10-09 12:50:46 +02:00
Sem van der Hoeven
bcdf8587c0 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-10-09 12:49:22 +02:00
Sem van der Hoeven
5cc008cd03 merged client and clientapp 2020-10-09 12:49:06 +02:00
Sem van der Hoeven
b642e17268 readded clientapp 2020-10-09 12:35:56 +02:00
Sem van der Hoeven
bcc479cf33 temp 2020-10-09 12:27:28 +02:00
shinichi
50a2ae9521 added popup not binded yet 2020-10-09 12:18:34 +02:00
Sem van der Hoeven
c87c190d14 fix dataparser import 2020-10-09 12:06:24 +02:00
Sem van der Hoeven
8e48fe7902 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-10-09 12:02:34 +02:00
Sem van der Hoeven
39b935ecbc o p t i m i z e 2020-10-09 12:02:23 +02:00
Sem van der Hoeven
68994fd3fe added BLEHANDLER tag to blehandler cw 2020-10-09 12:02:03 +02:00
Sem van der Hoeven
adf6073e42 added client project reference to server 2020-10-09 12:01:48 +02:00
Sem van der Hoeven
94d1c07c99 added client project reference to server 2020-10-09 12:01:34 +02:00
Sem van der Hoeven
2aa736b0a8 formatted speed to show km/h too 2020-10-09 12:01:23 +02:00
Sem van der Hoeven
b5ea137bad removed 20 second sleep 2020-10-09 12:00:51 +02:00
shinichi
dffeb39337 mainView is now binded 2020-10-09 11:40:52 +02:00
shinichi
2cb3fd5ec3 ble and simulation stop when window closes 2020-10-09 11:33:26 +02:00
shinichi
124eee5f12 implemented stop for BLEHandler and BikeSimulator 2020-10-09 11:16:51 +02:00
fabjuuuh
ab9180281e Merge branch 'dokter' into develop 2020-10-09 10:57:16 +02:00
fabjuuuh
a043cdc723 Merge branch 'develop' into dokter 2020-10-09 10:56:48 +02:00
shinichi
143f7e4d88 Merge branch 'move-Client-to-ClientApp' into develop 2020-10-07 21:21:19 +02:00
shinichi
e09f4f1325 changed names 2020-10-07 21:21:12 +02:00
shinichi
a23b268dc9 login working
uuuuggglyyyyyyyyyyyyyy :(
2020-10-07 19:45:20 +02:00
shinichi
7bf5bdb1ce delete 2020-10-07 18:34:04 +02:00
shinichi
46083b3912 copy 2020-10-07 17:56:21 +02:00
shinichi
187beaf6c1 Merge branch 'develop' into Client-GUI 2020-10-07 16:42:17 +02:00
Sem van der Hoeven
d6da6b18c4 added value update to panel and adjusted speed to match, only need to display speed with 1 decimal 2020-10-07 16:40:41 +02:00
shinichi
04b0051e72 Merge branch 'develop' into Client-GUI 2020-10-07 16:32:42 +02:00
shinichi
91bb0d65b7 added status 2020-10-07 16:31:44 +02:00
fabjuuuh
fc0e70403f Icon en livechart library 2020-10-07 16:16:52 +02:00
Sem van der Hoeven
847fa68acb fix for displaying things on vr scene 2020-10-07 16:06:16 +02:00
shinichi
d7dfe32cc3 wip 2020-10-07 15:49:57 +02:00
Sem van der Hoeven
651a44762b input test 2020-10-07 15:15:42 +02:00
shinichi
6159f3f57b added login logic and text 2020-10-07 15:14:39 +02:00
Sem van der Hoeven
046389f3b7 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-10-07 15:09:16 +02:00
Sem van der Hoeven
57aa9b6deb finished reconnecting on sim not started and then sending the commands 2020-10-07 15:08:45 +02:00
fabjuuuh
acbe3e9d55 Connect new tab 2020-10-07 14:56:04 +02:00
fabjuuuh
aea1b4fce4 connectie met server 2020-10-07 13:21:30 +02:00
shinichi
6e2b3a80b3 wip 2020-10-07 13:17:40 +02:00
Logophilist
26a784277a Panel now shows more data 2020-10-07 12:58:50 +02:00
Sem van der Hoeven
bff4718d3f added route to client vr scene 2020-10-07 12:51:09 +02:00
Sem van der Hoeven
499134fa9a Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-10-07 12:22:25 +02:00
Sem van der Hoeven
f5eb59694e added comments 2020-10-07 12:22:10 +02:00
shinichi
71ff5dfc81 Merge branch 'fix-getBPMgraphdata' into develop 2020-10-07 11:55:56 +02:00
shinichi
472c514275 removed debugging 2020-10-07 11:55:49 +02:00
shinichi
7c943f4f73 fix 2020-10-07 11:54:47 +02:00
Sem van der Hoeven
f31cdeb467 some writelines 2020-10-07 11:52:14 +02:00
Logophilist
05354b5ebe Merge remote-tracking branch 'origin/develop' into develop 2020-10-07 11:51:07 +02:00
Logophilist
f6c2b3c662 Panel fixed 2020-10-07 11:51:02 +02:00
Sem van der Hoeven
475159bbb2 fix conflicts 2020-10-07 11:24:19 +02:00
Sem van der Hoeven
c2b4b259a3 comment 2020-10-07 11:23:09 +02:00
fabjuuuh
a2937c0427 Merge branch 'wpf' into develop 2020-10-07 11:08:05 +02:00
fabjuuuh
02bd68d142 Merge branch 'develop' into wpf 2020-10-07 11:07:40 +02:00
Logophilist
699528bb83 Merge remote-tracking branch 'origin/develop' into develop 2020-10-05 20:21:08 +02:00
Logophilist
e4d192fb06 Commit alt code of VR engine 2020-10-05 20:20:57 +02:00
shinichi
5d14d53df5 wip 2020-10-02 16:29:11 +02:00
shinichi
09db19246e quick fix 2020-10-02 15:53:50 +02:00
shinichi
eb2738168b Merge remote-tracking branch 'origin/develop' into develop 2020-10-02 15:38:00 +02:00
shinichi
d85c5ff935 added function to get BPM graph data 2020-10-02 15:37:57 +02:00
Sem van der Hoeven
d420bdc2a4 merge conflicts 7: conflictnado 2020-10-02 11:49:48 +02:00
Sem van der Hoeven
cb2435bf53 weird fix 2020-10-02 11:48:03 +02:00
Sem van der Hoeven
ca2e61eb8e Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-10-02 11:44:30 +02:00
Sem van der Hoeven
32ef17365e pull 2020-10-02 11:44:26 +02:00
Sem van der Hoeven
fedf8c0e5b added client server login with hashed passwords and usernames 2020-10-02 11:43:07 +02:00
shinichi
505c4907d0 Merge branch 'set-resistance' into develop 2020-09-30 19:40:46 +02:00
shinichi
a5e679e6fb server now gets response when resistance is set 2020-09-30 19:40:37 +02:00
Sem van der Hoeven
3e5f6e46c4 progress on validation 2020-09-30 16:22:57 +02:00
shinichi
adea08cfb7 server can set resistance 2020-09-30 16:22:26 +02:00
wouter
c20a1b292e upgraded doktor stuff 2020-09-30 16:08:35 +02:00
shinichi
599b79ceee correctly implemented IHandler 2020-09-30 15:26:34 +02:00
shinichi
bd8994ad5b added start and stop session 2020-09-30 15:12:10 +02:00
Sem van der Hoeven
97f9d863aa fix 2020-09-30 15:10:47 +02:00
fabjuuuh
f777b583f5 progress 2020-09-30 14:37:40 +02:00
Sem van der Hoeven
d6b938668f added reconnecting to the vr server when no tunnel id is found 2020-09-30 14:33:15 +02:00
shinichi
45edbe5936 Merge branch 'binairy-writer' into develop 2020-09-30 14:25:29 +02:00
shinichi
a65c36b8d1 fix bug and more efficient code 2020-09-30 14:24:38 +02:00
shinichi
82f2d6b71c saving bike and bpm data in separate files 2020-09-30 14:17:26 +02:00
fabjuuuh
41e77ba16c hi 2020-09-30 13:12:18 +02:00
shinichi
6f1ab57fe4 saving in binairy format
took forever
2020-09-30 13:00:13 +02:00
Sem van der Hoeven
341723d1d1 added maincommand to engineconnection 2020-09-30 12:59:04 +02:00
Sem van der Hoeven
0cd3753b76 properly added engineconnection to client 2020-09-30 12:30:40 +02:00
Sem van der Hoeven
4388b39be5 only connects when username and password are entered 2020-09-30 12:27:31 +02:00
Sem van der Hoeven
0dc4bb6fad connected engine to client 2020-09-30 12:23:53 +02:00
Sem van der Hoeven
3ca3c1ad78 added engineconnection to client 2020-09-30 12:17:57 +02:00
Sem van der Hoeven
d06d621b13 added necessary methods and added method sig to cw of engineconnect 2020-09-30 12:13:59 +02:00
Sem van der Hoeven
7b05fcc898 added engineconnect as singleton 2020-09-30 12:01:53 +02:00
fabjuuuh
cc7f2d154c wpf 2020-09-30 11:52:38 +02:00
Sem van der Hoeven
c5b9a7ec09 made rh engine classes public 2020-09-30 11:44:00 +02:00
Sem van der Hoeven
3494f678e3 added doctor project 2020-09-30 10:15:30 +02:00
SemvdH
4af7b3bc44 Merge pull request #9 from SemvdH/develop
merge Develop into master
2020-09-25 16:51:28 +02:00
Sem van der Hoeven
9a80dc6260 Merge branch 'client' into develop 2020-09-25 16:49:53 +02:00
Sem van der Hoeven
4cabce69d5 Merge branch 'dashboard_VR' into develop 2020-09-25 16:49:19 +02:00
Logophilist
38886ca7c3 Bike follows route 2020-09-25 16:48:05 +02:00
shinichi
04e29402f7 Merge remote-tracking branch 'origin/client' into client 2020-09-25 16:38:45 +02:00
shinichi
78bb7f6a6c added possibility for multiple DataReceivers 2020-09-25 16:38:22 +02:00
fabjuuuh
99887a22ba Merge remote-tracking branch 'origin/client' into client 2020-09-25 16:38:22 +02:00
fabjuuuh
68a43fb930 Save Raw data 2020-09-25 16:38:16 +02:00
Sem van der Hoeven
dc4d3c852b removed internal 2020-09-25 15:56:47 +02:00
Sem van der Hoeven
13d99eb107 cleanup files 2020-09-25 15:56:26 +02:00
Sem van der Hoeven
aa5f58e752 cleaned program.cs 2020-09-25 15:54:41 +02:00
shinichi
a353d6839e added some flair 2020-09-25 15:50:20 +02:00
Sem van der Hoeven
b6e4842cf8 updated method to get id based on name 2020-09-25 15:48:47 +02:00
Sem van der Hoeven
1057c0caab added comments 2020-09-25 15:40:07 +02:00
shinichi
21203fd3ff login implemented 2020-09-25 15:33:39 +02:00
Sem van der Hoeven
8160e1c158 probably fixed the serials 2020-09-25 15:26:57 +02:00
shinichi
9c3b2c3f9b Auto stash before merge of "client" and "origin/client" 2020-09-25 15:00:43 +02:00
Sem van der Hoeven
d3a37d0238 progress on improving responses 2020-09-25 14:30:33 +02:00
Logophilist
bb30538f00 added features panel 2020-09-25 14:12:16 +02:00
Sem van der Hoeven
23846b14bc creating connection with new reading stuff works 2020-09-25 14:06:56 +02:00
fabjuuuh
6ef5bbfe12 More SaveData 2020-09-25 14:06:45 +02:00
fabjuuuh
cf9341a93e SaveData 2020-09-25 13:43:00 +02:00
Sem van der Hoeven
23f146afdd getting response from server through callback 2020-09-25 13:41:54 +02:00
Sem van der Hoeven
fac3987678 added delegate for reading server response 2020-09-25 13:26:48 +02:00
shinichi
d0071bd13c bug fix 2020-09-25 13:22:16 +02:00
fabjuuuh
97e6a528bb Merge remote-tracking branch 'origin/client' into client 2020-09-25 13:18:49 +02:00
fabjuuuh
80ee448acf Handledata 2020-09-25 13:18:41 +02:00
shinichi
8204f22fe7 better printing on client side 2020-09-25 13:18:19 +02:00
shinichi
22558e3289 print received data on client side 2020-09-25 13:11:14 +02:00
shinichi
360ec4175f OnRead for client updated 2020-09-25 13:04:39 +02:00
shinichi
506a074f36 Merge branch 'OnRead-rewrite' into client 2020-09-25 12:58:20 +02:00
shinichi
96f2e6e973 rewrote OnRead 2020-09-25 12:58:12 +02:00
shinichi
2139fcf2b2 removed clientId 2020-09-25 12:51:54 +02:00
shinichi
dded1a5b24 johan's code
senior meeting
2020-09-25 12:43:01 +02:00
shinichi
fb57a1779c comments and some small fixes 2020-09-23 15:37:37 +02:00
Logophilist
64773ffe1c Attempt 1 dashboard VR 2020-09-23 15:33:23 +02:00
shinichi
8c6cb443e3 deleted stuff 2020-09-23 15:22:45 +02:00
shinichi
81dcebb5e8 added client id to protocol 2020-09-23 15:11:13 +02:00
shinichi
c782301cf2 connection from bike/simulator to client to server 2020-09-23 15:05:09 +02:00
shinichi
d5eadbe529 forgot to stage 2020-09-23 14:32:07 +02:00
shinichi
d67c8448ad client and server connect 2020-09-23 14:31:37 +02:00
fabjuuuh
8e45c9a435 Merge remote-tracking branch 'origin/client' into client 2020-09-23 14:12:50 +02:00
fabjuuuh
cd5f23d3e4 Works i think 2020-09-23 14:12:35 +02:00
shinichi
5f7f1c8510 connected to bike? 2020-09-23 14:12:33 +02:00
shinichi
cdaac839b9 Merge remote-tracking branch 'origin/client' into client 2020-09-23 13:53:14 +02:00
shinichi
f899c90ff7 fix login message, implemented IDatareceiver, added Raw and json message 2020-09-23 13:53:00 +02:00
fabjuuuh
c62b0224e1 Merge remote-tracking branch 'origin/client' into client 2020-09-23 13:46:54 +02:00
shinichi
be9553cc51 fix login message, implemented IDatareceiver, added Rawa and jsom messag 2020-09-23 13:46:38 +02:00
fabjuuuh
40cbff209b Auto stash before merge of "client" and "origin/client" 2020-09-23 13:25:59 +02:00
shinichi
fd36e420d1 changed IDataConverter to IDataReceiver 2020-09-23 13:22:14 +02:00
shinichi
e315e1cf3f edited clients 2020-09-23 13:14:49 +02:00
shinichi
e0e910ac25 added newtonsoft to proftaakRH 2020-09-23 13:06:03 +02:00
Sem van der Hoeven
0bf41b5c07 fix projects not seeing message? 2020-09-23 12:31:55 +02:00
shinichi
de18ddc0f0 Merge branch 'server' into client 2020-09-23 12:12:42 +02:00
Sem van der Hoeven
a8d7e03331 added comment to enum 2020-09-23 12:11:36 +02:00
fabjuuuh
748f7eed46 Server 2020-09-23 12:11:32 +02:00
shinichi
674a10a779 Merge branch 'develop' into client 2020-09-23 12:01:16 +02:00
shinichi
797fb16465 client stuff 2020-09-23 12:00:40 +02:00
Sem van der Hoeven
60cf23d980 added identifier enum and made message use it 2020-09-23 11:58:36 +02:00
Sem van der Hoeven
31ef1beb82 added comments to message 2020-09-23 11:57:20 +02:00
Sem van der Hoeven
603703b3f6 rename program to message 2020-09-23 11:52:49 +02:00
Sem van der Hoeven
1a67e97f75 removed unused boolean warning 2020-09-23 11:51:22 +02:00
Sem van der Hoeven
28242ff052 added message class and added references to server and client projects 2020-09-23 11:50:25 +02:00
shinichi
a52f1ea7ed started client 2020-09-23 11:12:10 +02:00
fabjuuuh
dcae307754 Classes to server 2020-09-23 11:00:45 +02:00
Sem van der Hoeven
1041aa0391 added empty server and client projects 2020-09-23 10:43:03 +02:00
Sem van der Hoeven
b391583107 added other project to solution 2020-09-23 09:57:36 +02:00
SemvdH
3dc1709943 Merge pull request #8 from SemvdH/develop
Develop
2020-09-18 17:16:52 +02:00
Sem van der Hoeven
c63b51c22b fix? 2020-09-18 17:15:10 +02:00
Sem van der Hoeven
1ce519f661 wat 2020-09-18 17:14:16 +02:00
Sem van der Hoeven
7df8d98ed9 test 2020-09-18 17:08:19 +02:00
Sem van der Hoeven
fce99ff9ec Merge branch 'master' into develop 2020-09-18 17:00:17 +02:00
Sem van der Hoeven
a4bfac3de1 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-09-18 16:58:50 +02:00
SemvdH
5762989f93 Merge pull request #5 from SemvdH/temp
test
2020-09-18 16:58:41 +02:00
Sem van der Hoeven
fe977deb46 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-09-18 16:57:25 +02:00
Sem van der Hoeven
541538d50a test 2020-09-18 16:56:37 +02:00
shinichi
8f8490fe2a Merge remote-tracking branch 'origin/develop' into develop 2020-09-18 16:54:23 +02:00
shinichi
47cfe4efe6 nope 2020-09-18 16:54:21 +02:00
SemvdH
5cd4e61194 Merge pull request #4 from SemvdH/develop
merge Develop into master... again
2020-09-18 16:53:42 +02:00
Sem van der Hoeven
84a80df9ca Revert "removed unecessary folder"
This reverts commit 3f3a388ec1.
2020-09-18 16:52:33 +02:00
Sem van der Hoeven
3f3a388ec1 removed unecessary folder 2020-09-18 16:49:40 +02:00
Sem van der Hoeven
360767b6a5 added RH-Engine to solution 2020-09-18 16:49:02 +02:00
SemvdH
ddcc2171e0 Merge pull request #3 from SemvdH/revert-2-develop
Revert "merge Develop into master"
2020-09-18 16:45:00 +02:00
SemvdH
b6be86b811 Revert "merge Develop into master" 2020-09-18 16:44:47 +02:00
fdegroot1
109b982931 Merge pull request #2 from SemvdH/develop
merge Develop into master
2020-09-18 16:44:27 +02:00
Sem van der Hoeven
688509dc66 conflicts 5: The return 2020-09-18 16:42:02 +02:00
Sem van der Hoeven
02b180c246 clean and comment 2020-09-18 16:41:05 +02:00
shinichi
d912f2dd31 Merge remote-tracking branch 'origin/develop' into develop 2020-09-18 16:32:17 +02:00
shinichi
6d0439fab3 added follow route 2020-09-18 16:31:19 +02:00
Sem van der Hoeven
6b78cf12a2 conflicts 4: the reckoning 2020-09-18 16:30:24 +02:00
Sem van der Hoeven
9f675844ed road showing 2020-09-18 16:29:39 +02:00
fabjuuuh
92d95eb6a6 Made method for terrain no longer in createconnection 2020-09-18 16:29:26 +02:00
fabjuuuh
b2163b0459 Merge branch 'Terrain' into develop 2020-09-18 16:08:15 +02:00
Logophilist
c837af0392 attempt for road on route 2020-09-18 16:06:35 +02:00
fabjuuuh
de7f667dd0 Terrain 2020-09-18 16:01:39 +02:00
Sem van der Hoeven
7842baafb4 conflicts 3: revelations 2020-09-18 16:01:25 +02:00
Sem van der Hoeven
12b4b90bc5 create route method 2020-09-18 16:00:43 +02:00
shinichi
4a745ace75 added getUUIDFromResponse 2020-09-18 15:59:46 +02:00
shinichi
f1d543dafc Merge remote-tracking branch 'origin/develop' into develop 2020-09-18 15:57:13 +02:00
shinichi
c69c3193d4 added moveTo
not working
2020-09-18 15:56:34 +02:00
shinichi
17eb3b1845 added positions for models 2020-09-18 15:39:30 +02:00
Sem van der Hoeven
6eb2ac1a82 added route 2020-09-18 15:33:04 +02:00
Logophilist
36a0177270 routecommand attempt1 2020-09-18 14:54:13 +02:00
shinichi
a5a61a8a83 Merge remote-tracking branch 'origin/develop' into develop 2020-09-18 14:47:53 +02:00
shinichi
b7f3f3542f various changes 2020-09-18 14:47:33 +02:00
Sem van der Hoeven
f1066a365e comments on program.cs 2020-09-18 14:41:18 +02:00
Sem van der Hoeven
99b4e7f426 conflicts 2: the sequal 2020-09-18 14:26:24 +02:00
Sem van der Hoeven
3d72ed9694 conflicts yay 2020-09-18 14:25:21 +02:00
shinichi
037bb8a6cf Merge remote-tracking branch 'origin/develop' into develop 2020-09-18 14:25:04 +02:00
fabjuuuh
1e7d679fc2 Yeet 2020-09-18 14:24:55 +02:00
shinichi
0a2a0405bf Merge remote-tracking branch 'origin/develop' into develop 2020-09-18 14:23:46 +02:00
shinichi
6e09b87f60 added method overloading and custom models 2020-09-18 14:23:43 +02:00
Sem van der Hoeven
0d107a7170 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-09-18 14:21:35 +02:00
Sem van der Hoeven
1cda955254 pc stuff 2020-09-18 14:21:33 +02:00
DESKTOP-TV73FK0\woute
ef0b293373 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop
# Conflicts:
#	RH-Engine/Program.cs
2020-09-18 14:17:53 +02:00
DESKTOP-TV73FK0\woute
bc99bfd46b addlayer(not finished) 2020-09-18 14:16:41 +02:00
Sem van der Hoeven
8fd3322c63 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-09-18 12:53:17 +02:00
Sem van der Hoeven
c82f1e9537 comments 2020-09-18 12:53:14 +02:00
shinichi
178bbb030c Merge remote-tracking branch 'origin/develop' into develop 2020-09-18 12:51:17 +02:00
shinichi
bb70d80409 added bike 2020-09-18 12:50:53 +02:00
Sem van der Hoeven
e54cca454b added null message 2020-09-18 12:37:02 +02:00
DESKTOP-TV73FK0\woute
e98bf569f9 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop
# Conflicts:
#	RH-Engine/Program.cs
2020-09-18 12:32:06 +02:00
DESKTOP-TV73FK0\woute
a655646e80 idk 2020-09-18 12:30:57 +02:00
Sem van der Hoeven
0e2ee807e1 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-09-18 12:18:42 +02:00
Sem van der Hoeven
9ff2eb4e68 added standard name identifiers 2020-09-18 12:18:32 +02:00
shinichi
a8494bc4d2 added first iteration of adding a bike 2020-09-18 12:15:18 +02:00
Sem van der Hoeven
2b80dbad47 merge conflicts 2020-09-18 11:51:56 +02:00
Sem van der Hoeven
7c7b64094b add scene/get and progress on node/delete 2020-09-18 11:50:47 +02:00
fabjuuuh
e32d103e61 Node method 2020-09-18 11:41:44 +02:00
fabjuuuh
4782ecf53a Made methods for all the command still empty 2020-09-18 11:01:27 +02:00
fabjuuuh
a9036e6fc2 Terrrain command changed 2020-09-18 10:50:17 +02:00
Sem van der Hoeven
189fc18448 oneliner 2020-09-16 16:36:22 +02:00
Sem van der Hoeven
2e19b4af92 fiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix 2020-09-16 16:35:19 +02:00
Sem van der Hoeven
fe05f7e71d clean 2020-09-16 16:28:05 +02:00
Sem van der Hoeven
5f65eb32fd senior gesprek fixes 2020-09-16 16:04:21 +02:00
Sem van der Hoeven
c171f15316 vr message temp 2020-09-16 15:34:06 +02:00
Sem van der Hoeven
0264370b38 stuff 2020-09-16 15:30:49 +02:00
Sem van der Hoeven
39e4f655b1 change skybox 2020-09-16 15:21:07 +02:00
Sem van der Hoeven
87a370ee76 Merge remote-tracking branch 'origin/opdrachten' into skybox 2020-09-16 15:05:09 +02:00
Sem van der Hoeven
b9dc2b82a6 stuff 2020-09-16 15:05:07 +02:00
fabjuuuh
7b94cd77f9 Shit 2020-09-16 15:03:36 +02:00
Sem van der Hoeven
ac45f1b454 Merge branch 'develop' of https://github.com/SemvdH/Proftaak-RH-B4 into develop 2020-09-16 14:43:23 +02:00
Sem van der Hoeven
2adfce27b0 added vr message class 2020-09-16 14:43:19 +02:00
fabjuuuh
bdbda2b570 Merge remote-tracking branch 'origin/develop' into opdrachten 2020-09-16 14:29:11 +02:00
shinichi
5f18b3e772 working ish 2020-09-16 14:28:43 +02:00
shinichi
631342ba04 Merge remote-tracking branch 'origin/develop' into develop 2020-09-16 14:26:51 +02:00
shinichi
cb1ca0b671 fix? 2020-09-16 14:26:39 +02:00
shinichi
119f6384b6 tunnel created? 2020-09-16 14:18:56 +02:00
fabjuuuh
f292310775 JsonTextWriter 2020-09-16 14:18:39 +02:00
Sem van der Hoeven
60ae9a3716 finished getting all users method 2020-09-16 13:52:52 +02:00
Sem van der Hoeven
3307f57f36 added getting all users from response 2020-09-16 13:48:31 +02:00
shinichi
359484baa3 Merge branch 'plz-help-fix' into develop 2020-09-16 13:39:42 +02:00
shinichi
4854dcb759 fix re-added do while 2020-09-16 13:39:28 +02:00
shinichi
ae4fd1f093 wip
WHHHHYYYYYYY NOT WORK?!?!?
2020-09-16 13:10:59 +02:00
Sem van der Hoeven
ececffef3f fixed conflicts 2020-09-16 12:14:43 +02:00
Sem van der Hoeven
5699f8678e json parser stuff 2020-09-16 12:14:04 +02:00
shinichi
758fef325e added PC struct 2020-09-16 12:11:30 +02:00
Sem van der Hoeven
b0dc258455 removed offset for buffer 2020-09-16 11:47:37 +02:00
Sem van der Hoeven
d197d01971 oneliner for getting length 2020-09-16 11:44:28 +02:00
Sem van der Hoeven
86a5ddfbc4 thanks johan 2020-09-16 11:43:03 +02:00
Sem van der Hoeven
7edb0ceded fix courtesy of fabian 2020-09-16 10:31:24 +02:00
shinichi
b70da1148e added ReadPrefMessage 2020-09-16 10:23:35 +02:00
Sem van der Hoeven
934507dd36 stuff 2020-09-16 10:20:06 +02:00
shinichi
03dcd4c8b0 added method to get packetLength 2020-09-16 09:59:30 +02:00
Sem van der Hoeven
9dd292dafc added stuff for connecting to vr engine 2020-09-16 09:55:13 +02:00
Sem van der Hoeven
34a3e409ab added new project for the vr engine 2020-09-16 09:32:41 +02:00
SemvdH
6beb031907 Merge pull request #1 from SemvdH/develop
Merge develop into master
2020-09-11 15:34:55 +02:00
Sem van der Hoeven
72c369a578 merge simulation into develop 2020-09-11 15:34:21 +02:00
Logophilist
1c0958f33c Bike Simulator 0x19 (acc)Power update and cadence fix 2020-09-11 15:31:14 +02:00
Logophilist
dee370a4cb Worked on 0x19 simulator 2020-09-11 14:48:44 +02:00
Sem van der Hoeven
40f70a42d4 changed while true 2020-09-11 12:41:29 +02:00
shinichi
4ab46d94db Merge branch 'DataConverter' into develop 2020-09-11 12:39:43 +02:00
shinichi
e77372c913 added resistance changing 2020-09-11 12:39:06 +02:00
Sem van der Hoeven
a471854d71 added null check for sending resistance 2020-09-11 12:37:15 +02:00
shinichi
6e07f3b33a fixed instant power
who doesn't love bit flipping
2020-09-11 11:50:28 +02:00
Sem van der Hoeven
45096558fb added comments to dataconverter 2020-09-11 11:37:53 +02:00
Sem van der Hoeven
8dac69ebf9 added documentation comments to BLEHandler 2020-09-11 11:27:37 +02:00
Sem van der Hoeven
5c29a9c064 removed some comments 2020-09-11 11:17:00 +02:00
116 changed files with 8715 additions and 100 deletions

293
Client/Client.cs Normal file
View File

@@ -0,0 +1,293 @@
using System;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using ProftaakRH;
namespace Client
{
public class Client : IDataReceiver
{
private TcpClient client;
private NetworkStream stream;
private byte[] buffer = new byte[1024];
private bool connected;
private byte[] totalBuffer = new byte[1024];
private int totalBufferReceived = 0;
private EngineConnection engineConnection;
private bool sessionRunning = false;
private IHandler handler = null;
public Client() : this("localhost", 5555)
{
}
public Client(string adress, int port)
{
this.client = new TcpClient();
this.connected = false;
client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null);
}
/// <summary>
/// initializes the VR engine and sets the callbacks
/// </summary>
private void initEngine()
{
engineConnection = EngineConnection.INSTANCE;
engineConnection.OnNoTunnelId = retryEngineConnection;
engineConnection.OnSuccessFullConnection = engineConnected;
if (!engineConnection.Connected) engineConnection.Connect();
}
/// <summary>
/// retries to connect to the VR engine if no tunnel id was found
/// </summary>
private void retryEngineConnection()
{
Console.WriteLine("-- Could not connect to the VR engine. Please make sure you are running the simulation!");
Console.WriteLine("-- Press ENTER to retry connecting to the VR engine.");
Console.WriteLine("-- Press 'q' and then ENTER to not connect to the VR engine");
string input = Console.ReadLine();
if (input == string.Empty) engineConnection.CreateConnection();
else
{
Console.WriteLine("Skipping connecting to VR engine...");
engineConnection.Stop();
}
}
private void engineConnected()
{
Console.WriteLine("successfully connected to VR engine");
engineConnection.initScene();
if (engineConnection.Connected && sessionRunning && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
}
/// <summary>
/// callback method for when the TCP client is connected
/// </summary>
/// <param name="ar">the result of the async read</param>
private void OnConnect(IAsyncResult ar)
{
this.client.EndConnect(ar);
Console.WriteLine("TCP client Verbonden!");
this.stream = this.client.GetStream();
tryLogin();
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
}
/// <summary>
/// callback method for when there is a message read
/// </summary>
/// <param name="ar">the result of the async read</param>
private void OnRead(IAsyncResult ar)
{
int receivedBytes = this.stream.EndRead(ar);
if (totalBufferReceived + receivedBytes > 1024)
{
throw new OutOfMemoryException("buffer too small");
}
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, receivedBytes);
totalBufferReceived += receivedBytes;
int expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
while (totalBufferReceived >= expectedMessageLength)
{
//volledig packet binnen
byte[] messageBytes = new byte[expectedMessageLength];
Array.Copy(totalBuffer, 0, messageBytes, 0, expectedMessageLength);
byte[] payloadbytes = new byte[BitConverter.ToInt32(messageBytes, 0) - 5];
Array.Copy(messageBytes, 5, payloadbytes, 0, payloadbytes.Length);
string identifier;
bool isJson = DataParser.getJsonIdentifier(messageBytes, out identifier);
if (isJson)
{
switch (identifier)
{
case DataParser.LOGIN_RESPONSE:
string responseStatus = DataParser.getResponseStatus(payloadbytes);
if (responseStatus == "OK")
{
Console.WriteLine("Username and password correct!");
this.connected = true;
initEngine();
}
else
{
Console.WriteLine($"login failed \"{responseStatus}\"");
tryLogin();
}
break;
case DataParser.START_SESSION:
Console.WriteLine("Session started!");
this.sessionRunning = true;
if (engineConnection.Connected && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
sendMessage(DataParser.getStartSessionJson());
break;
case DataParser.STOP_SESSION:
Console.WriteLine("Stop session identifier");
this.sessionRunning = false;
sendMessage(DataParser.getStopSessionJson());
break;
case DataParser.SET_RESISTANCE:
Console.WriteLine("Set resistance identifier");
if (this.handler == null)
{
Console.WriteLine("handler is null");
sendMessage(DataParser.getSetResistanceResponseJson(false));
}
else
{
this.handler.setResistance(DataParser.getResistanceFromJson(payloadbytes));
sendMessage(DataParser.getSetResistanceResponseJson(true));
}
break;
default:
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
break;
}
}
else if (DataParser.isRawData(messageBytes))
{
Console.WriteLine($"Received data: {BitConverter.ToString(payloadbytes)}");
}
totalBufferReceived -= expectedMessageLength;
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
}
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
}
/// <summary>
/// starts sending a message to the server
/// </summary>
/// <param name="message">the message to send</param>
private void sendMessage(byte[] message)
{
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
/// <summary>
/// callback method for when a message is fully written to the server
/// </summary>
/// <param name="ar">the async result representing the asynchronous call</param>
private void OnWrite(IAsyncResult ar)
{
this.stream.EndWrite(ar);
}
#region interface
//maybe move this to other place
/// <summary>
/// bpm method for receiving the BPM value from the bluetooth bike or the simulation
/// </summary>
/// <param name="bytes">the message</param>
public void BPM(byte[] bytes)
{
if (!sessionRunning)
{
return;
}
if (bytes == null)
{
throw new ArgumentNullException("no bytes");
}
byte[] message = DataParser.GetRawDataMessage(bytes);
if (engineConnection.Connected && engineConnection.FollowingRoute)
{
engineConnection.BikeBPM = bytes[1];
}
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
/// <summary>
/// method for receiving the bike message from the bluetooth bike or the simulation
/// </summary>
/// <param name="bytes">the message</param>
public void Bike(byte[] bytes)
{
bool canSendToEngine = engineConnection.Connected && engineConnection.FollowingRoute;
if (!sessionRunning)
{
return;
}
if (bytes == null)
{
throw new ArgumentNullException("no bytes");
}
byte[] message = DataParser.GetRawDataMessage(bytes);
switch (bytes[0])
{
case 0x10:
if (canSendToEngine) engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
break;
case 0x19:
if (canSendToEngine) engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
break;
}
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
#endregion
/// <summary>
/// wether or not the client stream is connected
/// </summary>
/// <returns>true if it's connected, false if not</returns>
public bool IsConnected()
{
return this.connected;
}
/// <summary>
/// tries to log in to the server by asking for a username and password
/// </summary>
private void tryLogin()
{
//TODO File in lezen
Console.WriteLine("enter username");
string username = Console.ReadLine();
Console.WriteLine("enter password");
string password = Console.ReadLine();
string hashUser = Hashing.Hasher.HashString(username);
string hashPassword = Hashing.Hasher.HashString(password);
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(hashUser, hashPassword));
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
/// <summary>
/// sets the handler for the client, so either the bike simulator or the bluetooth bike handler
/// </summary>
/// <param name="handler"></param>
public void setHandler(IHandler handler)
{
this.handler = handler;
}
}
}

20
Client/Client.csproj Normal file
View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Message\Message.csproj" />
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
<ProjectReference Include="..\RH-Engine\RH-Engine.csproj" />
</ItemGroup>
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
</Project>

206
Client/DataParser.cs Normal file
View File

@@ -0,0 +1,206 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
namespace Client
{
public class DataParser
{
public const string LOGIN = "LOGIN";
public const string LOGIN_RESPONSE = "LOGIN RESPONSE";
public const string START_SESSION = "START SESSION";
public const string STOP_SESSION = "STOP SESSION";
public const string SET_RESISTANCE = "SET RESISTANCE";
/// <summary>
/// makes the json object with LOGIN identifier and username and password
/// </summary>
/// <param name="mUsername">username</param>
/// <param name="mPassword">password</param>
/// <returns>json object to ASCII to bytes</returns>
public static byte[] GetLoginJson(string mUsername, string mPassword)
{
dynamic json = new
{
identifier = LOGIN,
data = new
{
username = mUsername,
password = mPassword,
}
};
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
}
public static bool GetUsernamePassword(byte[] jsonbytes, out string username, out string password)
{
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(jsonbytes));
try
{
username = json.data.username;
password = json.data.password;
return true;
}
catch
{
username = null;
password = null;
return false;
}
}
private static byte[] getJsonMessage(string mIdentifier, dynamic data)
{
dynamic json = new
{
identifier = mIdentifier,
data
};
return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01);
}
private static byte[] getJsonMessage(string mIdentifier)
{
dynamic json = new
{
identifier = mIdentifier,
};
return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01);
}
public static byte[] getLoginResponse(string mStatus)
{
return getJsonMessage(LOGIN_RESPONSE, new { status = mStatus });
}
public static string getResponseStatus(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.status;
}
/// <summary>
/// get the identifier from json
/// </summary>
/// <param name="bytes">json in ASCII</param>
/// <param name="identifier">gets the identifier</param>
/// <returns>if it sucseeded</returns>
public static bool getJsonIdentifier(byte[] bytes, out string identifier)
{
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
byte messageId = bytes[4];
if (messageId == 0x01)
{
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(bytes.Skip(5).ToArray()));
identifier = json.identifier;
return true;
}
else
{
identifier = "";
return false;
}
}
/// <summary>
/// checks if the de message is raw data according to the protocol
/// </summary>
/// <param name="bytes">message</param>
/// <returns>if message contains raw data</returns>
public static bool isRawData(byte[] bytes)
{
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
return bytes[4] == 0x02;
}
/// <summary>
/// constructs a message with the payload, messageId and clientId
/// </summary>
/// <param name="payload"></param>
/// <param name="messageId"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
private static byte[] getMessage(byte[] payload, byte messageId)
{
byte[] res = new byte[payload.Length + 5];
Array.Copy(BitConverter.GetBytes(payload.Length + 5), 0, res, 0, 4);
res[4] = messageId;
Array.Copy(payload, 0, res, 5, payload.Length);
return res;
}
/// <summary>
/// constructs a message with the payload and clientId and assumes the payload is raw data
/// </summary>
/// <param name="payload"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
public static byte[] GetRawDataMessage(byte[] payload)
{
return getMessage(payload, 0x02);
}
/// <summary>
/// constructs a message with the payload and clientId and assumes the payload is json
/// </summary>
/// <param name="payload"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
public static byte[] getJsonMessage(byte[] payload)
{
return getMessage(payload, 0x01);
}
public static byte[] getStartSessionJson()
{
return getJsonMessage(START_SESSION);
}
public static byte[] getStopSessionJson()
{
return getJsonMessage(STOP_SESSION);
}
public static byte[] getSetResistanceJson(float mResistance)
{
dynamic data = new
{
resistance = mResistance
};
return getJsonMessage(SET_RESISTANCE, data);
}
public static byte[] getSetResistanceResponseJson(bool mWorked)
{
dynamic data = new
{
worked = mWorked
};
return getJsonMessage(SET_RESISTANCE, data);
}
public static float getResistanceFromJson(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.resistance;
}
public static bool getResistanceFromResponseJson(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked;
}
}
}

322
Client/EngineConnection.cs Normal file
View File

@@ -0,0 +1,322 @@
using System;
using System.Collections.Generic;
using System.Text;
using RH_Engine;
using System.Net.Sockets;
namespace Client
{
public delegate void HandleSerial(string message);
public delegate void HandleNoTunnelId();
public delegate void OnSuccessfullConnection();
public sealed class EngineConnection
{
private static EngineConnection instance = null;
private static readonly object padlock = new object();
private static System.Timers.Timer updateTimer;
public HandleNoTunnelId OnNoTunnelId;
public OnSuccessfullConnection OnSuccessFullConnection;
private static PC[] PCs = {
//new PC("DESKTOP-M2CIH87", "Fabian"),
//new PC("T470S", "Shinichi"),
//new PC("DESKTOP-DHS478C", "semme"),
new PC("HP-ZBOOK-SEM", "Sem")
//new PC("DESKTOP-TV73FKO", "Wouter"),
//new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
//new PC("NA", "Bart")
};
private static ServerResponseReader serverResponseReader;
private static string sessionId = string.Empty;
private static string tunnelId = string.Empty;
private static string cameraId = string.Empty;
private static string routeId = string.Empty;
private static string panelId = string.Empty;
private static string bikeId = string.Empty;
private static string headId = string.Empty;
public float BikeSpeed { get; set; }
public float BikePower { get; set; }
public float BikeBPM { get; set; }
public float BikeResistance { get; set; }
public bool FollowingRoute = false;
private static NetworkStream stream;
private static Dictionary<string, HandleSerial> serialResponses = new Dictionary<string, HandleSerial>();
private Command mainCommand;
public bool Connected = false;
EngineConnection()
{
BikeSpeed = 0;
BikePower = 0;
BikeBPM = 0;
BikeResistance = 50;
updateTimer = new System.Timers.Timer(1000);
updateTimer.Elapsed += UpdateTimer_Elapsed;
updateTimer.AutoReset = true;
updateTimer.Enabled = false;
}
private void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
UpdateInfoPanel();
}
/// <summary>
/// Singleton constructor
/// </summary>
public static EngineConnection INSTANCE
{
get
{
lock (padlock)
{
if (instance == null)
{
instance = new EngineConnection();
}
}
return instance;
}
}
/// <summary>
/// connects to the vr engine and initalizes the serverResponseReader
/// </summary>
public void Connect()
{
TcpClient client = new TcpClient("145.48.6.10", 6666);
stream = client.GetStream();
initReader();
CreateConnection();
}
/// <summary>
/// initializes and starts the reading of the responses from the vr server
/// </summary>
/// <param name="stream">the networkstream</param>
private void initReader()
{
serverResponseReader = new ServerResponseReader(stream);
serverResponseReader.callback = HandleResponse;
serverResponseReader.StartRead();
}
#region VR Message traffic
/// <summary>
/// connects to the server and creates the tunnel
/// </summary>
/// <param name="stream">the network stream to use</param>
public void CreateConnection()
{
WriteTextMessage( "{\r\n\"id\" : \"session/list\",\r\n\"serial\" : \"list\"\r\n}");
// wait until we have got a sessionId
while (sessionId == string.Empty) { }
string tunnelCreate = "{\"id\" : \"tunnel/create\", \"data\" : {\"session\" : \"" + sessionId + "\"}}";
WriteTextMessage(tunnelCreate);
}
/// <summary>
/// callback method that handles responses from the server
/// </summary>
/// <param name="message">the response message from the server</param>
public void HandleResponse(string message)
{
string id = JSONParser.GetID(message);
// because the first messages don't have a serial, we need to check on the id
if (id == "session/list")
{
sessionId = JSONParser.GetSessionID(message, PCs);
}
else if (id == "tunnel/create")
{
tunnelId = JSONParser.GetTunnelID(message);
Console.WriteLine("set tunnel id to " + tunnelId);
if (tunnelId == null)
{
Write("could not find a valid tunnel id!");
OnNoTunnelId?.Invoke();
Connected = false;
FollowingRoute = false;
return;
} else
{
Write("got tunnel id! " + tunnelId);
Connected = true;
OnSuccessFullConnection?.Invoke();
}
}
if (message.Contains("serial"))
{
//Console.WriteLine("GOT MESSAGE WITH SERIAL: " + message + "\n\n\n");
string serial = JSONParser.GetSerial(message);
//Console.WriteLine("Got serial " + serial);
if (serialResponses.ContainsKey(serial)) serialResponses[serial].Invoke(message);
}
}
public void initScene()
{
Write("initializing scene...");
mainCommand = new Command(tunnelId);
// reset the scene
WriteTextMessage(mainCommand.ResetScene());
//Get sceneinfo and set the id's
SendMessageAndOnResponse(mainCommand.GetSceneInfoCommand("sceneinfo"), "sceneinfo",
(message) =>
{
//Console.WriteLine("\r\n\r\n\r\nscene info" + message);
cameraId = JSONParser.GetIdSceneInfoChild(message, "Camera");
string headId = JSONParser.GetIdSceneInfoChild(message, "Head");
string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand");
string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand");
});
// add the route and set the route id
SendMessageAndOnResponse(mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
}
internal void StartRouteFollow()
{
Write("Starting route follow...");
FollowingRoute = true;
SendMessageAndOnResponse(mainCommand.AddBikeModel("bikeID"), "bikeID",
(message) =>
{
bikeId = JSONParser.GetResponseUuid(message);
SendMessageAndOnResponse(mainCommand.addPanel("panelAdd", bikeId), "panelAdd",
(message) =>
{
panelId = JSONParser.getPanelID(message);
WriteTextMessage(mainCommand.ColorPanel(panelId));
UpdateInfoPanel();
updateTimer.Enabled = true;
while (cameraId == string.Empty) { }
SetFollowSpeed(5.0f);
});
});
}
public void UpdateInfoPanel()
{
ShowPanel(BikeSpeed, (int)BikeBPM, (int)BikePower, (int)BikeResistance);
WriteTextMessage(mainCommand.RouteSpeed(BikeSpeed, bikeId));
WriteTextMessage(mainCommand.RouteSpeed(BikeSpeed, cameraId));
}
public void ShowPanel(double bikeSpeed, int bpm, int power, int resistance)
{
WriteTextMessage(mainCommand.ClearPanel(panelId));
SendMessageAndOnResponse(mainCommand.showBikespeed(panelId, "bikeSpeed", bikeSpeed), "bikeSpeed",
(message) =>
{
// TODO check if is drawn
});
SendMessageAndOnResponse(mainCommand.showHeartrate(panelId, "bpm", bpm), "bpm",
(message) =>
{
// TODO check if is drawn
});
SendMessageAndOnResponse(mainCommand.showPower(panelId, "power", power), "power",
(message) =>
{
// TODO check if is drawn
});
SendMessageAndOnResponse(mainCommand.showResistance(panelId, "resistance", resistance), "resistance",
(message) =>
{
// TODO check if is drawn
});
// Check if every text is drawn!
WriteTextMessage(mainCommand.SwapPanel(panelId));
}
private void SetFollowSpeed(float speed)
{
WriteTextMessage(mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 }));
WriteTextMessage(mainCommand.RouteFollow(routeId, cameraId, speed));
}
#endregion
#region message send/receive
/// <summary>
/// method that sends the speciefied message with the specified serial, and executes the given action upon receivind a reply from the server with this serial.
/// </summary>
/// <param name="stream">the networkstream to use</param>
/// <param name="message">the message to send</param>
/// <param name="serial">the serial to check for</param>
/// <param name="action">the code to be executed upon reveiving a reply from the server with the specified serial</param>
public void SendMessageAndOnResponse(string message, string serial, HandleSerial action)
{
if (serialResponses.ContainsKey(serial))
{
serialResponses[serial] = action;
} else
{
serialResponses.Add(serial, action);
}
WriteTextMessage(message);
}
/// <summary>
/// writes a message to the server
/// </summary>
/// <param name="stream">the network stream to use</param>
/// <param name="message">the message to send</param>
public void WriteTextMessage(string message)
{
byte[] msg = Encoding.ASCII.GetBytes(message);
byte[] res = new byte[msg.Length + 4];
Array.Copy(BitConverter.GetBytes(msg.Length), 0, res, 0, 4);
Array.Copy(msg, 0, res, 4, msg.Length);
stream.Write(res);
//Write("sent message " + message);
}
#endregion
public void Stop()
{
serverResponseReader.Stop();
}
public void Write(string msg)
{
Console.WriteLine( "[ENGINECONNECT] " + msg);
}
}
}

42
Client/Program.cs Normal file
View File

@@ -0,0 +1,42 @@
using System;
using Hardware;
using Hardware.Simulators;
using RH_Engine;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
namespace Client
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("// Connecting... //");
//connect fiets?
Client client = new Client();
while (!client.IsConnected())
{
}
BLEHandler bLEHandler = new BLEHandler(client);
bLEHandler.Connect();
client.setHandler(bLEHandler);
//BikeSimulator bikeSimulator = new BikeSimulator(client);
//bikeSimulator.StartSimulation();
//client.setHandler(bikeSimulator);
//while (true)
//{
//}
}
}
}

30
ClientApp/App.xaml Normal file
View File

@@ -0,0 +1,30 @@
<Application x:Class="ClientApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ClientApp"
xmlns:viewModels="clr-namespace:ClientApp.ViewModels"
xmlns:views="clr-namespace:ClientApp.Views"
StartupUri="Views/MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<DataTemplate DataType="{x:Type viewModels:MainViewModel}">
<views:MainView />
<!-- This is a Page -->
</DataTemplate>
<DataTemplate DataType="{x:Type viewModels:LoginViewModel}">
<views:LoginView />
<!-- This is a Page -->
</DataTemplate>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="WPFStuff/Styles/Fonts.xaml"/>
<ResourceDictionary Source="WPFStuff/Styles/Colors.xaml"/>
<ResourceDictionary Source="WPFStuff/Styles/Buttons.xaml"/>
<ResourceDictionary Source="WPFStuff/Styles/Texts.xaml"/>
<ResourceDictionary Source="WPFStuff/Styles/Windows.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

17
ClientApp/App.xaml.cs Normal file
View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace ClientApp
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

10
ClientApp/AssemblyInfo.cs Normal file
View File

@@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@@ -0,0 +1,66 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
<ApplicationIcon>Images\Logo\icon1.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<None Remove="Images\CoolBackground.jpg" />
<None Remove="Images\Icons\CheckMark.png" />
<None Remove="Images\Icons\CrossMark.png" />
<None Remove="Images\Logo\icon1.ico" />
<None Remove="Images\re15.jpg" />
<None Remove="Images\stone.png" />
</ItemGroup>
<ItemGroup>
<Content Include="Images\CoolBackground.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Images\Icons\CheckMark.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\Icons\CrossMark.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\Logo\icon1.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\re15.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Images\stone.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="AsyncAwaitBestPractices.MVVM" Version="4.3.0" />
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="PropertyChanged.Fody" Version="3.2.9" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
<ProjectReference Include="..\RH-Engine\RH-Engine.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
</Project>

View File

@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<PropertyChanged />
</Weavers>

74
ClientApp/FodyWeavers.xsd Normal file
View File

@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="TriggerDependentProperties" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the Dependent properties feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EnableIsChangedProperty" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the IsChanged property feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EventInvokerNames" type="xs:string">
<xs:annotation>
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEquality" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressWarnings" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings from this weaver.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressOnPropertyNameChangedWarning" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings about mismatched On_PropertyName_Changed methods.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
ClientApp/Images/re15.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
ClientApp/Images/stone.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -0,0 +1,212 @@
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace ClientApp.MagicCode
{
/// <summary>
/// Fixes the issue with Windows of Style <see cref="WindowStyle.None"/> covering the taskbar
/// </summary>
public class WindowResizer
{
#region Private Members
/// <summary>
/// The window to handle the resizing for
/// </summary>
private Window mWindow;
#endregion
#region Dll Imports
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetCursorPos(out POINT lpPoint);
[DllImport("user32.dll")]
static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr MonitorFromPoint(POINT pt, MonitorOptions dwFlags);
#endregion
#region Constructor
/// <summary>
/// Default constructor
/// </summary>
/// <param name="window">The window to monitor and correctly maximize</param>
/// <param name="adjustSize">The callback for the host to adjust the maximum available size if needed</param>
public WindowResizer(Window window)
{
mWindow = window;
// Listen out for source initialized to setup
mWindow.SourceInitialized += Window_SourceInitialized;
}
#endregion
#region Initialize
/// <summary>
/// Initialize and hook into the windows message pump
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_SourceInitialized(object sender, System.EventArgs e)
{
// Get the handle of this window
var handle = (new WindowInteropHelper(mWindow)).Handle;
var handleSource = HwndSource.FromHwnd(handle);
// If not found, end
if (handleSource == null)
return;
// Hook into it's Windows messages
handleSource.AddHook(WindowProc);
}
#endregion
#region Windows Proc
/// <summary>
/// Listens out for all windows messages for this window
/// </summary>
/// <param name="hwnd"></param>
/// <param name="msg"></param>
/// <param name="wParam"></param>
/// <param name="lParam"></param>
/// <param name="handled"></param>
/// <returns></returns>
private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
// Handle the GetMinMaxInfo of the Window
case 0x0024:/* WM_GETMINMAXINFO */
WmGetMinMaxInfo(hwnd, lParam);
handled = true;
break;
}
return (IntPtr)0;
}
#endregion
/// <summary>
/// Get the min/max window size for this window
/// Correctly accounting for the taskbar size and position
/// </summary>
/// <param name="hwnd"></param>
/// <param name="lParam"></param>
private void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
{
POINT lMousePosition;
GetCursorPos(out lMousePosition);
IntPtr lPrimaryScreen = MonitorFromPoint(new POINT(0, 0), MonitorOptions.MONITOR_DEFAULTTOPRIMARY);
MONITORINFO lPrimaryScreenInfo = new MONITORINFO();
if (GetMonitorInfo(lPrimaryScreen, lPrimaryScreenInfo) == false)
{
return;
}
IntPtr lCurrentScreen = MonitorFromPoint(lMousePosition, MonitorOptions.MONITOR_DEFAULTTONEAREST);
MINMAXINFO lMmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
if (lPrimaryScreen.Equals(lCurrentScreen) == true)
{
lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcWork.Left;
lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcWork.Top;
lMmi.ptMaxSize.X = lPrimaryScreenInfo.rcWork.Right - lPrimaryScreenInfo.rcWork.Left;
lMmi.ptMaxSize.Y = lPrimaryScreenInfo.rcWork.Bottom - lPrimaryScreenInfo.rcWork.Top;
}
else
{
lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcMonitor.Left;
lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcMonitor.Top;
lMmi.ptMaxSize.X = lPrimaryScreenInfo.rcMonitor.Right - lPrimaryScreenInfo.rcMonitor.Left;
lMmi.ptMaxSize.Y = lPrimaryScreenInfo.rcMonitor.Bottom - lPrimaryScreenInfo.rcMonitor.Top;
}
// Now we have the max size, allow the host to tweak as needed
Marshal.StructureToPtr(lMmi, lParam, true);
}
}
#region Dll Helper Structures
enum MonitorOptions : uint
{
MONITOR_DEFAULTTONULL = 0x00000000,
MONITOR_DEFAULTTOPRIMARY = 0x00000001,
MONITOR_DEFAULTTONEAREST = 0x00000002
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class MONITORINFO
{
public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
public Rectangle rcMonitor = new Rectangle();
public Rectangle rcWork = new Rectangle();
public int dwFlags = 0;
}
[StructLayout(LayoutKind.Sequential)]
public struct Rectangle
{
public int Left, Top, Right, Bottom;
public Rectangle(int left, int top, int right, int bottom)
{
this.Left = left;
this.Top = top;
this.Right = right;
this.Bottom = bottom;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct MINMAXINFO
{
public POINT ptReserved;
public POINT ptMaxSize;
public POINT ptMaxPosition;
public POINT ptMinTrackSize;
public POINT ptMaxTrackSize;
};
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
/// <summary>
/// x coordinate of point.
/// </summary>
public int X;
/// <summary>
/// y coordinate of point.
/// </summary>
public int Y;
/// <summary>
/// Construct a point of coordinates (x,y).
/// </summary>
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
}
#endregion
}

17
ClientApp/Models/Info.cs Normal file
View File

@@ -0,0 +1,17 @@
using ClientApp.Utils;
using System;
using System.Collections.Generic;
using System.Text;
using Util;
namespace ClientApp.Models
{
class Info : ObservableObject
{
public bool ConnectedToServer { get; set; }
public bool ConnectedToVREngine { get; set; }
public bool DoctorConnected { get; set; }
public bool CanConnectToVR { get; set; }
}
}

331
ClientApp/Utils/Client.cs Normal file
View File

@@ -0,0 +1,331 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using ClientApp.ViewModels;
using ProftaakRH;
using Util;
namespace ClientApp.Utils
{
public delegate void EngineCallback();
public class Client : IDataReceiver, IDisposable
{
public EngineCallback engineConnectFailed;
public EngineCallback engineConnectSuccess;
private TcpClient client;
private NetworkStream stream;
private byte[] buffer = new byte[1024];
private bool connected;
private byte[] totalBuffer = new byte[1024];
private int totalBufferReceived = 0;
public EngineConnection engineConnection;
private bool sessionRunning = true;
private IHandler handler = null;
private LoginViewModel LoginViewModel;
public Client() : this("localhost", 5555)
{
}
public Client(string adress, int port)
{
this.client = new TcpClient();
this.connected = false;
client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null);
}
/// <summary>
/// initializes the VR engine and sets the callbacks
/// </summary>
private void initEngine()
{
Debug.WriteLine("init engine");
engineConnection = EngineConnection.INSTANCE;
engineConnection.OnNoTunnelId = RetryEngineConnection;
engineConnection.OnSuccessFullConnection = engineConnected;
engineConnection.OnEngineDisconnect = RetryEngineConnection;
if (!engineConnection.Connected) engineConnection.Connect();
}
/// <summary>
/// retries to connect to the VR engine if no tunnel id was found
/// </summary>
public void RetryEngineConnection()
{
engineConnectFailed?.Invoke();
}
private void engineConnected()
{
Console.WriteLine("successfully connected to VR engine");
engineConnectSuccess?.Invoke();
engineConnection.initScene();
if (engineConnection.Connected && sessionRunning && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
}
/// <summary>
/// callback method for when the TCP client is connected
/// </summary>
/// <param name="ar">the result of the async read</param>
private void OnConnect(IAsyncResult ar)
{
this.client.EndConnect(ar);
Console.WriteLine("TCP client Verbonden!");
this.stream = this.client.GetStream();
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
}
/// <summary>
/// callback method for when there is a message read
/// </summary>
/// <param name="ar">the result of the async read</param>
private void OnRead(IAsyncResult ar)
{
Debug.WriteLine("got message in client app");
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead))
return;
int receivedBytes = this.stream.EndRead(ar);
if (totalBufferReceived + receivedBytes > 1024)
{
throw new OutOfMemoryException("buffer too small");
}
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, receivedBytes);
totalBufferReceived += receivedBytes;
int expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
while (totalBufferReceived >= expectedMessageLength)
{
//volledig packet binnen
byte[] messageBytes = new byte[expectedMessageLength];
Array.Copy(totalBuffer, 0, messageBytes, 0, expectedMessageLength);
byte[] payloadbytes = new byte[BitConverter.ToInt32(messageBytes, 0) - 5];
Array.Copy(messageBytes, 5, payloadbytes, 0, payloadbytes.Length);
string identifier;
bool isJson = DataParser.getJsonIdentifier(messageBytes, out identifier);
if (isJson)
{
switch (identifier)
{
case DataParser.LOGIN_RESPONSE:
string responseStatus = DataParser.getResponseStatus(payloadbytes);
if (responseStatus == "OK")
{
Debug.WriteLine("Username and password correct!");
this.LoginViewModel.setLoginStatus(true);
this.connected = true;
initEngine();
}
else
{
this.LoginViewModel.setLoginStatus(false);
Debug.WriteLine($"login failed \"{responseStatus}\"");
}
break;
case DataParser.START_SESSION:
Debug.WriteLine("Session started!");
this.sessionRunning = true;
if (engineConnection.Connected && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
Debug.WriteLine("start");
break;
case DataParser.STOP_SESSION:
Console.WriteLine("Stop session identifier");
this.sessionRunning = false;
stopBikeInSimulation();
Debug.WriteLine("stop");
break;
case DataParser.SET_RESISTANCE:
Debug.WriteLine("Set resistance identifier");
if (this.handler == null)
{
// send that the operation was not successful if the handler is null
Debug.WriteLine("handler is null");
sendMessage(DataParser.getSetResistanceResponseJson(false));
}
else
{
// set the resistance in the vr scene and send that it was successful
float resistance = DataParser.getResistanceFromJson(payloadbytes);
Debug.WriteLine("resistance set was " + resistance);
this.handler.setResistance(resistance);
engineConnection.BikeResistance = resistance;
sendMessage(DataParser.getSetResistanceResponseJson(true));
}
break;
case DataParser.MESSAGE:
Debug.WriteLine("client has received message from doctor");
engineConnection.DoctorMessage = DataParser.getChatMessageFromJson(payloadbytes);
break;
case DataParser.NEW_CONNECTION:
this.LoginViewModel.DoctorConnected(DataParser.getUsernameFromJson(payloadbytes));
break;
case DataParser.DISCONNECT:
this.LoginViewModel.DoctorDisconnected(DataParser.getUsernameFromJson(payloadbytes));
break;
default:
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
break;
}
}
else if (DataParser.isRawDataBikeServer(messageBytes))
{
Console.WriteLine($"Received data: {BitConverter.ToString(payloadbytes)}");
}
totalBufferReceived -= expectedMessageLength;
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
}
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
}
/// <summary>
/// starts sending a message to the server
/// </summary>
/// <param name="message">the message to send</param>
public void sendMessage(byte[] message)
{
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
/// <summary>
/// callback method for when a message is fully written to the server
/// </summary>
/// <param name="ar">the async result representing the asynchronous call</param>
private void OnWrite(IAsyncResult ar)
{
this.stream.EndWrite(ar);
}
#region interface
//maybe move this to other place
/// <summary>
/// bpm method for receiving the BPM value from the bluetooth bike or the simulation
/// </summary>
/// <param name="bytes">the message</param>
public void BPM(byte[] bytes)
{
if (!sessionRunning)
{
return;
}
if (bytes == null)
{
throw new ArgumentNullException("no bytes");
}
byte[] message = DataParser.GetRawBPMDataMessageServer(bytes);
if (engineConnection != null && engineConnection.Connected && engineConnection.FollowingRoute)
{
engineConnection.BikeBPM = bytes[1];
}
this.stream?.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
/// <summary>
/// method for receiving the bike message from the bluetooth bike or the simulation
/// </summary>
/// <param name="bytes">the message</param>
public void Bike(byte[] bytes)
{
if (!sessionRunning)
{
return;
}
if (bytes == null)
{
throw new ArgumentNullException("no bytes");
}
byte[] message = DataParser.GetRawBikeDataMessageServer(bytes);
bool canSendToEngine = engineConnection != null && engineConnection.Connected && engineConnection.FollowingRoute && this.sessionRunning;
switch (bytes[0])
{
case 0x10:
if (canSendToEngine) engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
else if (engineConnection != null) engineConnection.BikeSpeed = 0;
break;
case 0x19:
if (canSendToEngine) engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
else if (engineConnection != null) engineConnection.BikePower = 0;
break;
}
this.stream?.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
private void stopBikeInSimulation()
{
engineConnection.BikeSpeed = 0;
engineConnection.BikePower = 0;
}
#endregion
/// <summary>
/// wether or not the client stream is connected
/// </summary>
/// <returns>true if it's connected, false if not</returns>
public bool IsConnected()
{
return this.connected;
}
/// <summary>
/// tries to log in to the server by asking for a username and password
/// </summary>
public void tryLogin(string username, string password)
{
string hashPassword = Util.Hasher.HashString(password);
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(username, hashPassword));
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
/// <summary>
/// sets the handler for the client, so either the bike simulator or the bluetooth bike handler
/// </summary>
/// <param name="handler"></param>
public void SetHandler(IHandler handler)
{
this.handler = handler;
}
internal void SetLoginViewModel(LoginViewModel loginViewModel)
{
this.LoginViewModel = loginViewModel;
}
public void Dispose()
{
Debug.WriteLine("client dispose called");
sendMessage(DataParser.getDisconnectJson(LoginViewModel.Username));
this.stream.Dispose();
this.client.Dispose();
this.handler.stop();
this.engineConnection.Stop();
}
}
}

View File

@@ -0,0 +1,437 @@
using System;
using System.Collections.Generic;
using System.Text;
using RH_Engine;
using System.Net.Sockets;
using Newtonsoft.Json.Linq;
using System.Diagnostics;
using LibNoise.Primitive;
namespace ClientApp.Utils
{
public delegate void HandleSerial(string message);
public delegate void EngineDelegate();
public sealed class EngineConnection
{
private static EngineConnection instance = null;
private static readonly object padlock = new object();
private static System.Timers.Timer updateTimer;
private static System.Timers.Timer noVRResponseTimer;
public EngineDelegate OnNoTunnelId;
public EngineDelegate OnSuccessFullConnection;
public EngineDelegate OnEngineDisconnect;
private static PC[] PCs = {
//new PC("DESKTOP-M2CIH87", "Fabian"),
//new PC("T470S", "Shinichi"),
//new PC("DESKTOP-DHS478C", "semme"),
//new PC("HP-ZBOOK-SEM", "Sem")
//new PC("DESKTOP-TV73FKO", "Wouter"),
//new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
//new PC("NA", "Bart")
};
private static ServerResponseReader serverResponseReader;
private static string sessionId = string.Empty;
private static string tunnelId = string.Empty;
private static string cameraId = string.Empty;
private static string routeId = string.Empty;
private static string panelId = string.Empty;
private static string bikeId = string.Empty;
private static string headId = string.Empty;
private static string groundPlaneId = string.Empty;
private static string terrainId = string.Empty;
public string DoctorMessage { get; set; }
public float BikeSpeed { get; set; }
public float BikePower { get; set; }
public float BikeBPM { get; set; }
public float BikeResistance { get; set; }
public bool FollowingRoute = false;
private static NetworkStream stream;
private static Dictionary<string, HandleSerial> serialResponses = new Dictionary<string, HandleSerial>();
private Command mainCommand;
public bool Connected = false;
EngineConnection()
{
BikeSpeed = 0;
BikePower = 0;
BikeBPM = 0;
BikeResistance = 50;
DoctorMessage = "No message received yet";
updateTimer = new System.Timers.Timer(1000);
updateTimer.Elapsed += UpdateTimer_Elapsed;
updateTimer.AutoReset = true;
updateTimer.Enabled = false;
noVRResponseTimer = new System.Timers.Timer(15000);
noVRResponseTimer.Elapsed += noVRResponseTimeout;
noVRResponseTimer.AutoReset = false;
noVRResponseTimer.Enabled = false;
}
private void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
UpdateInfoPanel();
}
private void noVRResponseTimeout(object sender, System.Timers.ElapsedEventArgs e)
{
Write("VR RESPONSE TIMEOUT");
noVRResponseTimer.Stop();
sessionId = string.Empty;
tunnelId = string.Empty;
cameraId = string.Empty;
routeId = string.Empty;
panelId = string.Empty;
bikeId = string.Empty;
groundPlaneId = string.Empty;
terrainId = string.Empty;
OnEngineDisconnect?.Invoke();
}
/// <summary>
/// Singleton constructor
/// </summary>
public static EngineConnection INSTANCE
{
get
{
lock (padlock)
{
if (instance == null)
{
instance = new EngineConnection();
}
}
return instance;
}
}
/// <summary>
/// connects to the vr engine and initalizes the serverResponseReader
/// </summary>
public void Connect()
{
TcpClient client = new TcpClient("145.48.6.10", 6666);
stream = client.GetStream();
initReader();
CreateConnection();
}
/// <summary>
/// initializes and starts the reading of the responses from the vr server
/// </summary>
/// <param name="stream">the networkstream</param>
private void initReader()
{
serverResponseReader = new ServerResponseReader(stream);
serverResponseReader.callback = HandleResponse;
serverResponseReader.StartRead();
}
#region VR Message traffic
/// <summary>
/// connects to the server and creates the tunnel
/// </summary>
/// <param name="stream">the network stream to use</param>
public void CreateConnection()
{
WriteTextMessage("{\r\n\"id\" : \"session/list\",\r\n\"serial\" : \"list\"\r\n}");
// wait until we have got a sessionId
while (sessionId == string.Empty) { }
string tunnelCreate = "{\"id\" : \"tunnel/create\", \"data\" : {\"session\" : \"" + sessionId + "\"}}";
WriteTextMessage(tunnelCreate);
}
/// <summary>
/// callback method that handles responses from the server
/// </summary>
/// <param name="message">the response message from the server</param>
public void HandleResponse(string message)
{
string id = JSONParser.GetID(message);
// because the first messages don't have a serial, we need to check on the id
if (id == "session/list")
{
sessionId = JSONParser.GetSessionID(message, PCs);
}
else if (id == "tunnel/create")
{
tunnelId = JSONParser.GetTunnelID(message);
Console.WriteLine("set tunnel id to " + tunnelId);
if (tunnelId == null)
{
//Write("could not find a valid tunnel id!");
OnNoTunnelId?.Invoke();
Connected = false;
FollowingRoute = false;
return;
}
else
{
Write("got tunnel id! " + tunnelId);
Connected = true;
noVRResponseTimer.Enabled = true;
OnSuccessFullConnection?.Invoke();
}
}
if (message.Contains("serial"))
{
//Console.WriteLine("GOT MESSAGE WITH SERIAL: " + message + "\n\n\n");
string serial = JSONParser.GetSerial(message);
//Console.WriteLine("Got serial " + serial);
if (serialResponses.ContainsKey(serial)) serialResponses[serial].Invoke(message);
}
noVRResponseTimer.Stop();
noVRResponseTimer.Start();
}
public void initScene()
{
Write("initializing scene...");
mainCommand = new Command(tunnelId);
// reset the scene
WriteTextMessage(mainCommand.ResetScene());
//Get sceneinfo and set the id's
SendMessageAndOnResponse(mainCommand.GetSceneInfoCommand("sceneinfo"), "sceneinfo",
(message) =>
{
//Console.WriteLine("\r\n\r\n\r\nscene info" + message);
cameraId = JSONParser.GetIdSceneInfoChild(message, "Camera");
string headId = JSONParser.GetIdSceneInfoChild(message, "Head");
string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand");
string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand");
groundPlaneId = JSONParser.GetIdSceneInfoChild(message, "GroundPlane");
});
// add the route and set the route id
CreateTerrain();
SendMessageAndOnResponse(mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
}
internal void StartRouteFollow()
{
Write("Starting route follow...");
FollowingRoute = true;
SendMessageAndOnResponse(mainCommand.AddBikeModel("bikeID"), "bikeID",
(message) =>
{
bikeId = JSONParser.GetResponseUuid(message);
SendMessageAndOnResponse(mainCommand.addPanel("panelAdd", bikeId), "panelAdd",
(message) =>
{
panelId = JSONParser.getPanelID(message);
WriteTextMessage(mainCommand.ColorPanel(panelId));
UpdateInfoPanel();
updateTimer.Enabled = true;
while (cameraId == string.Empty) { }
SetFollowSpeed(5.0f);
WriteTextMessage(mainCommand.RoadCommand(routeId, "road"));
WriteTextMessage(mainCommand.ShowRoute("showRouteFalse", false));
});
});
setEnvironment();
}
private void setEnvironment()
{
Write("Setting environment");
WriteTextMessage(mainCommand.DeleteNode(groundPlaneId, "none"));
PlaceHouses();
WriteTextMessage(mainCommand.SkyboxCommand(DateTime.Now.Hour));
}
private void PlaceHouses()
{
PlaceHouse(2, new float[] { 10f, 1f, 30f }, 1);
PlaceHouse(1, new float[] { 42f, 1f, 22f }, new float[] { 0f, 90f, 0f }, 2);
PlaceHouse(11, new float[] { -20f, 1f, 0f }, new float[] { 0f, -35f, 0f }, 3);
PlaceHouse(7, new float[] { -15f, 1f, 50f }, new float[] { 0f, -50f, 0f }, 4);
PlaceHouse(24, new float[] { 40f, 1f, 40f }, new float[] { 0f, 75f, 0f }, 5);
PlaceHouse(22, new float[] { 34f, 1f, -20f }, 6);
PlaceHouse(14, new float[] { 0f, 1f, -20f }, new float[] { 0f, 210f, 0f }, 7);
}
private void PlaceHouse(int numberHousemodel, float[] position, int serialNumber)
{
PlaceHouse(numberHousemodel, position, new float[] { 0f, 0f, 0f }, serialNumber);
}
private void PlaceHouse(int numberHousemodel, float[] position, float[] rotation, int serialNumber)
{
string folderHouses = @"data\NetworkEngine\models\houses\set1\";
SendMessageAndOnResponse(mainCommand.AddModel("House1", "housePlacement" + serialNumber, folderHouses + "house" + numberHousemodel + ".obj", position, 4, rotation), "housePlacement" + serialNumber, (message) => Console.WriteLine(message));
}
public void UpdateInfoPanel()
{
ShowPanel(BikeSpeed, (int)BikeBPM, (int)BikePower, (int)BikeResistance);
WriteTextMessage(mainCommand.RouteSpeed(BikeSpeed, bikeId));
WriteTextMessage(mainCommand.RouteSpeed(BikeSpeed, cameraId));
}
public void ShowPanel(double bikeSpeed, int bpm, int power, int resistance)
{
WriteTextMessage(mainCommand.ClearPanel(panelId));
SendMessageAndOnResponse(mainCommand.showBikespeed(panelId, "bikeSpeed", bikeSpeed), "bikeSpeed",
(message) =>
{
// TODO check if is drawn
});
SendMessageAndOnResponse(mainCommand.showHeartrate(panelId, "bpm", bpm), "bpm",
(message) =>
{
// TODO check if is drawn
});
SendMessageAndOnResponse(mainCommand.showPower(panelId, "power", power), "power",
(message) =>
{
// TODO check if is drawn
});
SendMessageAndOnResponse(mainCommand.showResistance(panelId, "resistance", resistance), "resistance",
(message) =>
{
// TODO check if is drawn
});
SendMessageAndOnResponse(mainCommand.showMessage(panelId, "message", DoctorMessage), "message",
(message) =>
{
// TODO check if is drawn
});
// Check if every text is drawn!
WriteTextMessage(mainCommand.SwapPanel(panelId));
}
private void SetFollowSpeed(float speed)
{
Write("starting route follow");
WriteTextMessage(mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 }));
WriteTextMessage(mainCommand.RouteFollow(routeId, cameraId, speed));
}
public void CreateTerrain()
{
float x = 0f;
float[] height = new float[256 * 256];
ImprovedPerlin improvedPerlin = new ImprovedPerlin(0, LibNoise.NoiseQuality.Best);
for (int i = 0; i < 256 * 256; i++)
{
height[i] = improvedPerlin.GetValue(x / 10, x / 10, x * 100) / 3.5f + 1;
//if (height[i] > 1.1f)
//{
// height[i] = height[i] * 0.8f;
//}
//else if (height[i] < 0.9f)
//{
// height[i] = height[i] * 1.2f;
//}
x += 0.001f;
}
SendMessageAndOnResponse(mainCommand.TerrainAdd(new int[] { 256, 256 }, height, "terrain"), "terrain",
(message) =>
{
SendMessageAndOnResponse(mainCommand.renderTerrain("renderTerrain"), "renderTerrain",
(message) =>
{
terrainId = JSONParser.GetTerrainID(message);
string addLayerMsg = mainCommand.AddLayer(terrainId, "addLayer");
SendMessageAndOnResponse(addLayerMsg, "addLayer", (message) => Console.WriteLine(""));
});
});
}
#endregion
#region message send/receive
/// <summary>
/// method that sends the speciefied message with the specified serial, and executes the given action upon receivind a reply from the server with this serial.
/// </summary>
/// <param name="stream">the networkstream to use</param>
/// <param name="message">the message to send</param>
/// <param name="serial">the serial to check for</param>
/// <param name="action">the code to be executed upon reveiving a reply from the server with the specified serial</param>
public void SendMessageAndOnResponse(string message, string serial, HandleSerial action)
{
if (serialResponses.ContainsKey(serial))
{
serialResponses[serial] = action;
}
else
{
serialResponses.Add(serial, action);
}
WriteTextMessage(message);
}
/// <summary>
/// writes a message to the server
/// </summary>
/// <param name="stream">the network stream to use</param>
/// <param name="message">the message to send</param>
public void WriteTextMessage(string message)
{
byte[] msg = Encoding.ASCII.GetBytes(message);
byte[] res = new byte[msg.Length + 4];
Array.Copy(BitConverter.GetBytes(msg.Length), 0, res, 0, 4);
Array.Copy(msg, 0, res, 4, msg.Length);
stream.Write(res);
//Write("sent message " + message);
}
#endregion
public void Stop()
{
serverResponseReader.Stop();
}
public void Write(string msg)
{
Debug.WriteLine("[ENGINECONNECT] " + msg);
}
}
}

View File

@@ -0,0 +1,42 @@
using System;
using Hardware;
using Hardware.Simulators;
using RH_Engine;
using System.Security.Cryptography;
using System.Text;
namespace ClientApp.Utils
{
class Program
{
//static void Main(string[] args)
//{
// Console.WriteLine("// Connecting... //");
// //connect fiets?
// Client client = new Client();
// while (!client.IsConnected())
// {
// }
// //BLEHandler bLEHandler = new BLEHandler(client);
// //bLEHandler.Connect();
// //client.setHandler(bLEHandler);
// BikeSimulator bikeSimulator = new BikeSimulator(client);
// bikeSimulator.StartSimulation();
// client.setHandler(bikeSimulator);
// while (true)
// {
// }
//}
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Data;
using System.Windows.Media.Imaging;
namespace ClientApp.ValueConverters
{
//[ValueConversion(typeof(bool), typeof(BitmapImage))]
class BoolToMarkConverter : IValueConverter
{
public BitmapImage TrueImage { get; set; } = new BitmapImage(new Uri("pack://application:,,,/Images/Icons/CheckMark.png"));
public BitmapImage FalseImage { get; set; } = new BitmapImage(new Uri("pack://application:,,,/Images/Icons/CrossMark.png"));
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (!(value is bool))
{
return null;
}
bool b = (bool)value;
if (b)
{
return this.TrueImage;
}
else
{
return this.FalseImage;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;
using ClientApp.Utils;
using GalaSoft.MvvmLight.Command;
using Util;
namespace ClientApp.ViewModels
{
class LoginViewModel : ObservableObject
{
public string Username { get; set; }
public ICommand LoginCommand { get; set; }
public bool LoginStatus { get; set; } = false;
public bool InvertedLoginStatus { get; set; }
private MainWindowViewModel MainWindowViewModel;
public LoginViewModel(MainWindowViewModel mainWindowViewModel)
{
this.MainWindowViewModel = mainWindowViewModel;
LoginCommand = new RelayCommand<object>((parameter) =>
{
//TODO send username and password to server
this.MainWindowViewModel.client.tryLogin(Username, ((PasswordBox)parameter).Password);
});
}
internal void setLoginStatus(bool status)
{
this.MainWindowViewModel.InfoModel.ConnectedToServer = status;
this.InvertedLoginStatus = !status;
if (status)
{
this.MainWindowViewModel.SelectedViewModel = new MainViewModel(MainWindowViewModel);
}
}
internal void DoctorConnected(string name)
{
this.MainWindowViewModel.InfoModel.DoctorConnected = true;
}
internal void DoctorDisconnected(string name)
{
this.MainWindowViewModel.InfoModel.DoctorConnected = false;
}
}
}

View File

@@ -0,0 +1,46 @@
using ClientApp.Models;
using ClientApp.Utils;
using GalaSoft.MvvmLight.Command;
using System.Diagnostics;
using System.Windows.Input;
using Util;
namespace ClientApp.ViewModels
{
class MainViewModel : ObservableObject
{
public ICommand RetryServerCommand { get; set; }
public MainWindowViewModel MainWindowViewModel { get; set; }
private Client client;
public MainViewModel(MainWindowViewModel mainWindowViewModel)
{
this.MainWindowViewModel = mainWindowViewModel;
client = this.MainWindowViewModel.client;
client.engineConnectFailed = retryEngineConnection;
client.engineConnectSuccess = succesEngineConnection;
this.RetryServerCommand = new RelayCommand(() =>
{
//try connect server
this.MainWindowViewModel.InfoModel.ConnectedToServer = true;
});
}
private void retryEngineConnection()
{
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = false;
this.MainWindowViewModel.InfoModel.CanConnectToVR = true;
client.engineConnection.CreateConnection();
}
private void succesEngineConnection()
{
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = true;
this.MainWindowViewModel.InfoModel.CanConnectToVR = false;
}
}
}

View File

@@ -0,0 +1,137 @@
using ClientApp.MagicCode;
using ClientApp.Models;
using ClientApp.Utils;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Util;
using System.Windows;
using System.Windows.Input;
namespace ClientApp.ViewModels
{
class MainWindowViewModel : ObservableObject
{
#region private members
private Window mWindow;
private int mOuterMarginSize = 10;
private int mWindowRadius = 10;
#endregion
#region commands
public ICommand MinimizeCommand { get; set; }
public ICommand MaximizeCommand { get; set; }
public ICommand CloseCommand { get; set; }
public ICommand MenuCommand { get; set; }
#endregion
#region public properties
public Info InfoModel { get; set; }
public ObservableObject SelectedViewModel { get; set; }
public Client client { get; }
/// <summary>
/// size of the resize border around the window
/// </summary>
public double MinimumWidth { get; set; } = 250;
public double MinimumHeight { get; set; } = 250;
public int ResizeBorder { get; set; } = 6;
public Thickness ResizeBorderThickness { get { return new Thickness(ResizeBorder + OuterMarginSize); } }
public Thickness InnerContentPadding { get { return new Thickness(ResizeBorder); } }
public Thickness OuterMarginThickness { get { return new Thickness(OuterMarginSize); } }
public CornerRadius WindowCornerRadius { get { return new CornerRadius(WindowRadius); } }
public int OuterMarginSize
{
get
{
return mWindow.WindowState == WindowState.Maximized ? 0 : mOuterMarginSize;
}
set
{
mOuterMarginSize = value;
}
}
public int WindowRadius
{
get
{
return mWindow.WindowState == WindowState.Maximized ? 0 : mWindowRadius;
}
set
{
mWindowRadius = value;
}
}
public int TitleHeight { get; set; } = 42;
public GridLength TitleHeightGridLength { get { return new GridLength(TitleHeight + ResizeBorder); } }
#endregion
public MainWindowViewModel(Window window, Client client)
{
this.mWindow = window;
this.mWindow.StateChanged += (sender, e) =>
{
OnPropertyChanged(nameof(ResizeBorderThickness));
OnPropertyChanged(nameof(OuterMarginThickness));
OnPropertyChanged(nameof(WindowCornerRadius));
OnPropertyChanged(nameof(OuterMarginSize));
OnPropertyChanged(nameof(WindowRadius));
};
this.InfoModel = new Info();
this.client = client;
LoginViewModel loginViewModel = new LoginViewModel(this);
SelectedViewModel = loginViewModel;
this.client.SetLoginViewModel(loginViewModel);
this.MinimizeCommand = new RelayCommand(() => this.mWindow.WindowState = WindowState.Minimized);
this.MaximizeCommand = new RelayCommand(() => this.mWindow.WindowState ^= WindowState.Maximized);
this.CloseCommand = new RelayCommand(() => this.mWindow.Close());
this.MenuCommand = new RelayCommand(() => SystemCommands.ShowSystemMenu(this.mWindow, GetMousePosition()));
var resizer = new WindowResizer(this.mWindow);
this.mWindow.Closed += (sender, e) => this.client.Dispose();
}
#region helper
private Point GetMousePosition()
{
Debug.WriteLine("getmousePosition called");
var p = Mouse.GetPosition(this.mWindow);
return new Point(p.X + this.mWindow.Left, p.Y + this.mWindow.Top);
}
#endregion
}
}

View File

@@ -0,0 +1,25 @@
<Page x:Class="ClientApp.Views.LoginView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ClientApp.Views"
xmlns:viewModels="clr-namespace:ClientApp.ViewModels"
xmlns:Util="clr-namespace:Util.MagicCode"
mc:Ignorable="d"
ShowsNavigationUI="False"
d:DesignHeight="450" d:DesignWidth="800">
<DockPanel>
<DockPanel.Background>
<ImageBrush TileMode="Tile" ViewportUnits="Absolute" Viewport="0 0 64 64" ImageSource="\images\stone.png"/>
</DockPanel.Background>
<StackPanel VerticalAlignment="Center" Width="auto">
<Label Content="Username" HorizontalContentAlignment="Center" />
<TextBox x:Name="Username" Text="{Binding Username}" TextWrapping="Wrap" Width="120" Util:FocusAdvancement.AdvancesByEnterKey="True" />
<Label Content="Password" HorizontalContentAlignment="Center"/>
<PasswordBox x:Name="Password" Width="120" Util:FocusAdvancement.AdvancesByEnterKey="True"/>
<Button x:Name="Login" Content="Login" Command="{Binding LoginCommand}" CommandParameter="{Binding ElementName=Password}" Margin="0,20,0,0" Width="120"/>
<Label Content="Login failed" Foreground="Red" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Background="Transparent" IsEnabled="{Binding InvertedLoginStatus}"/>
</StackPanel>
</DockPanel>
</Page>

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ClientApp.Views
{
/// <summary>
/// Interaction logic for LoginView.xaml
/// </summary>
public partial class LoginView : Page
{
public LoginView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,40 @@
<Page x:Class="ClientApp.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ClientApp.Views"
xmlns:converter="clr-namespace:ClientApp.ValueConverters"
ShowsNavigationUI="False"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Page.Resources>
<converter:BoolToMarkConverter x:Key="BoolToMarkConverter"/>
</Page.Resources>
<DockPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal" Margin="20" HorizontalAlignment="Center">
<Label Content="Connected to server:" VerticalAlignment="Center"/>
<Image Source="{Binding Converter={StaticResource BoolToMarkConverter},Path=MainWindowViewModel.InfoModel.ConnectedToServer}" Stretch="Uniform" Width="20" Height="20"/>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal" Margin="20" HorizontalAlignment="Center">
<Label Content="Connected to VR-Engine:" VerticalAlignment="Center"/>
<Image Source="{Binding Converter={StaticResource BoolToMarkConverter},Path=MainWindowViewModel.InfoModel.ConnectedToVREngine}" Stretch="Uniform" Width="20" Height="20"/>
</StackPanel>
<StackPanel Grid.Column="2" Grid.Row="0" Orientation="Horizontal" Margin="20" HorizontalAlignment="Center">
<Label Content="Doctor connected:" VerticalAlignment="Center"/>
<Image Source="{Binding Converter={StaticResource BoolToMarkConverter},Path=MainWindowViewModel.InfoModel.DoctorConnected}" Stretch="Uniform" Width="20" Height="20"/>
</StackPanel>
</Grid>
</DockPanel>
</Page>

View File

@@ -0,0 +1,27 @@
using ClientApp.ViewModels;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ClientApp.Views
{
/// <summary>
/// Interaction logic for MainView.xaml
/// </summary>
public partial class MainView : Page
{
public MainView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,128 @@
<Window x:Class="ClientApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ClientApp"
xmlns:views="clr-namespace:ClientApp.Views"
xmlns:images="clrnamespace.Images"
mc:Ignorable="d"
WindowStyle="None"
AllowsTransparency="True"
x:Name="applicatonWindow"
WindowStartupLocation="CenterScreen"
MinHeight="{Binding MinimumHeight}"
MinWidth="{Binding MinimumWidth}"
Title="Whaazzzzuuuuuuuup">
<!--Icon="/Images/Logo/icon1_small.ico"-->
<!--Icon="pack://application:,,,/Images/Log/icon1_small.ico"-->
<Window.Resources>
<Style TargetType="{x:Type local:MainWindow}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Border Padding="{Binding OuterMarginThickness, FallbackValue=10}" >
<Grid>
<!-- opacity mask -->
<Border x:Name="Container"
Background="{StaticResource BackgroundLightBrush}"
CornerRadius="{Binding WindowCornerRadius, FallbackValue=10}"/>
<Border CornerRadius="{Binding WindowCornerRadius, FallbackValue=10}"
Background="{StaticResource BackgroundVeryLightBrush}">
<Border.Effect>
<DropShadowEffect ShadowDepth="0" Opacity="0.2"/>
</Border.Effect>
</Border>
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="{Binding ElementName=Container}"/>
</Grid.OpacityMask>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding TitleHeightGridLength, FallbackValue=42}"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Title bar -->
<Grid Grid.Column="0" Grid.Row="0" Panel.ZIndex="1" Background="{StaticResource BackgroundLightBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- icon -->
<Button Grid.Column="0" Style="{StaticResource SystemIconButton}" Command="{Binding MenuCommand}">
<Image Source="/Images/Logo/icon1.ico"/>
<!--<TextBlock Text="icon"/>-->
</Button>
<!-- Title -->
<Viewbox Grid.Column="1" Margin="0">
<TextBlock Style="{StaticResource HeaderText}" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title, FallbackValue=failed}"/>
</Viewbox>
<!-- Window buttons -->
<StackPanel Grid.Column="2" Orientation="Horizontal">
<Button Style="{StaticResource WindowControlButton}" Content="_" Command="{Binding MinimizeCommand}"/>
<Button Style="{StaticResource WindowControlButton}" Content="[]" Command="{Binding MaximizeCommand}"/>
<Button Style="{StaticResource WindowCloseButton}" Content="X" Command="{Binding CloseCommand}"/>
</StackPanel>
</Grid>
<!-- Page content -->
<Border Grid.Row="1" Grid.Column="0">
<ContentPresenter Content="{TemplateBinding Content}"/>
</Border>
<!-- shadow? -->
<Border Grid.Row="1" Height="6" BorderThickness="0 0.2 0 0" VerticalAlignment="Top">
<!--<Border.BorderBrush>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="{StaticResource BackgroundSemiLight}" Offset="0.0"/>
<GradientStop Color="{StaticResource BackgroundVeryLight}" Offset="1.0"/>
</LinearGradientBrush>
</Border.BorderBrush>-->
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="Transparent" Offset="1.0"/>
<GradientStop Color="#7000" Offset="0.0"/>
</LinearGradientBrush>
</Border.Background>
</Border>
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<WindowChrome.WindowChrome>
<WindowChrome
ResizeBorderThickness="{Binding ResizeBorderThickness}"
CaptionHeight="{Binding TitleHeight}"
CornerRadius="0"
GlassFrameThickness="0"/>
</WindowChrome.WindowChrome>
<Grid>
<Frame Content="{Binding SelectedViewModel}" Focusable="False" NavigationUIVisibility="Hidden"/>
<Label Content="gemaakt door: mensen" DockPanel.Dock="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontStyle="Italic" Foreground="Gray"/>
</Grid>
</Window>

View File

@@ -0,0 +1,57 @@
using ClientApp.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ClientApp.Utils;
using Hardware.Simulators;
using System.Threading;
using ProftaakRH;
namespace ClientApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private IHandler handler;
public MainWindow()
{
Client client = new Client();
InitializeComponent();
DataContext = new MainWindowViewModel(this, client);
//BLEHandler bLEHandler = new BLEHandler(client);
//bLEHandler.Connect();
//client.setHandler(bLEHandler);
BikeSimulator bikeSimulator = new BikeSimulator(client);
Thread newThread = new Thread(new ThreadStart(bikeSimulator.StartSimulation));
newThread.Start();
client.SetHandler(bikeSimulator);
handler = bikeSimulator;
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
handler.stop();
}
}
}

32
DoctorApp/App.xaml Normal file
View File

@@ -0,0 +1,32 @@
<Application x:Class="DoctorApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DoctorApp"
xmlns:viewModels="clr-namespace:DoctorApp.ViewModels"
xmlns:views="clr-namespace:DoctorApp.Views"
StartupUri="Views/MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<DataTemplate DataType="{x:Type viewModels:MainViewModel}">
<views:MainView />
<!-- This is a Page -->
</DataTemplate>
<DataTemplate DataType="{x:Type viewModels:LoginViewModel}">
<views:LoginView />
<!-- This is a Page -->
</DataTemplate>
<DataTemplate DataType="{x:Type viewModels:ClientInfoViewModel}">
<views:ClientInfoView/>
</DataTemplate>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="WPFStuff/Styles/Fonts.xaml"/>
<ResourceDictionary Source="WPFStuff/Styles/Colors.xaml"/>
<ResourceDictionary Source="WPFStuff/Styles/Buttons.xaml"/>
<ResourceDictionary Source="WPFStuff/Styles/Texts.xaml"/>
<ResourceDictionary Source="WPFStuff/Styles/Windows.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

17
DoctorApp/App.xaml.cs Normal file
View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace DoctorApp
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

10
DoctorApp/AssemblyInfo.cs Normal file
View File

@@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
<ApplicationIcon>doctor.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<None Remove="img\doctor.ico" />
<None Remove="img\patient.png" />
</ItemGroup>
<ItemGroup>
<Content Include="img\doctor.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="img\patient.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="AsyncAwaitBestPractices.MVVM" Version="4.3.0" />
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
<PackageReference Include="Prism.Wpf" Version="8.0.0.1909" />
<PackageReference Include="PropertyChanged.Fody" Version="3.2.9" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
</ItemGroup>
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
</Project>

View File

@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<PropertyChanged />
</Weavers>

74
DoctorApp/FodyWeavers.xsd Normal file
View File

@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="TriggerDependentProperties" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the Dependent properties feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EnableIsChangedProperty" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the IsChanged property feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EventInvokerNames" type="xs:string">
<xs:annotation>
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEquality" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressWarnings" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings from this weaver.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressOnPropertyNameChangedWarning" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings about mismatched On_PropertyName_Changed methods.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

127
DoctorApp/Models/Chart.cs Normal file
View File

@@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using LiveCharts;
using LiveCharts.Configurations;
using Util;
namespace DoctorApp.Models
{
class Chart : ObservableObject,INotifyPropertyChanged
{
private double _axisMax;
private double _axisMin;
private double _trend;
public event PropertyChangedEventHandler PropertyChanged;
public ChartValues<MeasureModel> ChartValues { get; set; }
public Func<double, string> DateTimeFormatter { get; set; }
public PatientInfo PatientInfo { get; set; }
public double AxisStep { get; set; }
public double AxisUnit { get; set; }
public double AxisMax
{
get { return _axisMax; }
set
{
_axisMax = value;
OnPropertyChanged("AxisMax");
}
}
public double AxisMin
{
get { return _axisMin; }
set
{
_axisMin = value;
OnPropertyChanged("AxisMin");
}
}
public bool IsReading { get; set; }
public Chart(PatientInfo patientInfo)
{
var mapper = Mappers.Xy<MeasureModel>()
.X(model => model.DateTime.Ticks)
.Y(model => model.Value);
Charting.For<MeasureModel>(mapper);
ChartValues = new ChartValues<MeasureModel>();
DateTimeFormatter = value => new DateTime((long)value).ToString("mm:ss");
AxisStep = TimeSpan.FromSeconds(1).Ticks;
AxisUnit = TimeSpan.TicksPerSecond;
SetAxisLimits(DateTime.Now);
IsReading = true;
ChartValues.Add(new MeasureModel
{
DateTime = DateTime.Now,
Value = 8
});
}
private void SetAxisLimits(DateTime now)
{
AxisMax = now.Ticks + TimeSpan.FromSeconds(1).Ticks; // lets force the axis to be 1 second ahead
AxisMin = now.Ticks - TimeSpan.FromSeconds(8).Ticks; // and 8 seconds behind
}
protected virtual void OnPropertyChanged(string propertyName = null)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void NewValue(double value)
{
var now = DateTime.Now;
_trend = value;
ChartValues.Add(new MeasureModel
{
DateTime = now,
Value = _trend
});
SetAxisLimits(now);
if (ChartValues.Count > 150) ChartValues.RemoveAt(0);
}
public void Clear()
{
Debug.WriteLine("clear");
ChartValues.Clear();
}
}
public class MeasureModel
{
public DateTime DateTime { get; set; }
public double Value { get; set; }
}
}

17
DoctorApp/Models/Info.cs Normal file
View File

@@ -0,0 +1,17 @@
using DoctorApp.Utils;
using System;
using System.Collections.Generic;
using System.Text;
using Util;
namespace DoctorApp.Models
{
class Info : ObservableObject
{
public bool ConnectedToServer { get; set; }
public bool ConnectedToVREngine { get; set; }
public bool DoctorConnected { get; set; }
public bool CanConnectToVR { get; set; }
}
}

View File

@@ -0,0 +1,25 @@
using System.Collections.ObjectModel;
using Util;
namespace DoctorApp.Models
{
class PatientInfo : ObservableObject
{
public ObservableCollection<string> ChatLog { get; set; }
public string Username { get; set; }
public string Status { get; set; }
public double Speed { get; set; }
public int BPM { get; set; }
public float Resistance { get; set; }
public int Acc_Power { get; set; }
public int Curr_Power { get; set; }
public int Distance { get; set; }
}
}

254
DoctorApp/Utils/Client.cs Normal file
View File

@@ -0,0 +1,254 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using DoctorApp.ViewModels;
using Microsoft.Win32;
using ProftaakRH;
using Util;
namespace DoctorApp.Utils
{
public delegate void EngineCallback();
public class Client
{
private TcpClient client;
private NetworkStream stream;
private byte[] buffer = new byte[1024];
private bool connected;
private byte[] totalBuffer = new byte[1024];
private int totalBufferReceived = 0;
private LoginViewModel LoginViewModel;
private MainViewModel MainViewModel;
private ClientInfoViewModel ClientInfoViewModel;
public Client() : this("localhost", 5555)
{
}
public Client(string adress, int port)
{
this.client = new TcpClient();
this.connected = false;
client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null);
}
/// <summary>
/// callback method for when the TCP client is connected
/// </summary>
/// <param name="ar">the result of the async read</param>
private void OnConnect(IAsyncResult ar)
{
this.client.EndConnect(ar);
Console.WriteLine("TCP client Verbonden!");
this.stream = this.client.GetStream();
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
}
/// <summary>
/// callback method for when there is a message read
/// </summary>
/// <param name="ar">the result of the async read</param>
private void OnRead(IAsyncResult ar)
{
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead))
return;
int receivedBytes = this.stream.EndRead(ar);
if (totalBufferReceived + receivedBytes > 1024)
{
throw new OutOfMemoryException("buffer too small");
}
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, receivedBytes);
totalBufferReceived += receivedBytes;
int expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
while (totalBufferReceived >= expectedMessageLength)
{
//volledig packet binnen
byte[] messageBytes = new byte[expectedMessageLength];
Array.Copy(totalBuffer, 0, messageBytes, 0, expectedMessageLength);
byte[] payloadbytes = new byte[BitConverter.ToInt32(messageBytes, 0) - 5];
Array.Copy(messageBytes, 5, payloadbytes, 0, payloadbytes.Length);
string identifier;
bool isJson = DataParser.getJsonIdentifier(messageBytes, out identifier);
if (isJson)
{
switch (identifier)
{
case DataParser.LOGIN_RESPONSE:
string responseStatus = DataParser.getResponseStatus(payloadbytes);
if (responseStatus == "OK")
{
Debug.WriteLine("Doctor Username and password correct!");
this.LoginViewModel.setLoginStatus(true);
this.connected = true;
}
else
{
this.LoginViewModel.setLoginStatus(false);
Debug.WriteLine($"login failed \"{responseStatus}\"");
}
break;
case DataParser.START_SESSION:
Console.WriteLine("Session started!");
break;
case DataParser.STOP_SESSION:
Console.WriteLine("Stop session identifier");
break;
case DataParser.SET_RESISTANCE:
Console.WriteLine("Set resistance identifier");
break;
case DataParser.NEW_CONNECTION:
this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromJson(payloadbytes));
break;
case DataParser.DISCONNECT:
this.MainViewModel.DisconnectedUser(DataParser.getUsernameFromJson(payloadbytes));
break;
default:
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
break;
}
}
else if (DataParser.isRawDataBikeDoctor(messageBytes))
{
MainViewModel.TransferDataToClientBike(payloadbytes);
}
else if (DataParser.isRawDataBPMDoctor(messageBytes))
{
MainViewModel.TransferDataToClientBPM(payloadbytes);
}
else if (DataParser.IsHistoricBikeData(messageBytes))
{
// todo change to name of patient
string name = MainViewModel.Tabs[0].PatientInfo.Username;
string result = "PATIENT INFO FOR " + name + "\n\n";
for (int i = 0; i < payloadbytes.Length; i += 8)
{
byte[] res = new byte[8];
Array.Copy(payloadbytes, i, res, 0, 8);
result += handleBikeHistory(res);
}
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/" + name + ".txt";
File.WriteAllText(path,result);
}
Array.Copy(totalBuffer, expectedMessageLength, totalBuffer, 0, (totalBufferReceived - expectedMessageLength)); //maybe unsafe idk
totalBufferReceived -= expectedMessageLength;
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
}
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.client.Connected)
return;
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
}
private string handleBikeHistory(byte[] bytes)
{
string res = string.Empty;
switch (bytes[0])
{
case 0x10:
res += "Time elapsed: " + bytes[2] / 4 + "s\n";
res += "Distance traveled: " + bytes[3] + "\n";
int input = bytes[4] | (bytes[5] << 8);
res += $"Speed {input * 0.01}m/s\n";
res += $"Heart rate: { Convert.ToString(bytes[6], 10)}";
break;
case 0x19:
res += $"RPM: {bytes[2]}\n";
int accumPower = bytes[3] | (bytes[4] << 8);
res += $"Accumulated power: {accumPower} watt\n";
int instantPower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
if (instantPower != 0xFFF)
{
res += $"Instant power: {instantPower} watt\n";
}
break;
}
return res + "\n";
}
/// <summary>
/// starts sending a message to the server
/// </summary>
/// <param name="message">the message to send</param>
public void sendMessage(byte[] message)
{
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
/// <summary>
/// callback method for when a message is fully written to the server
/// </summary>
/// <param name="ar">the async result representing the asynchronous call</param>
private void OnWrite(IAsyncResult ar)
{
this.stream.EndWrite(ar);
}
/// <summary>
/// wether or not the client stream is connected
/// </summary>
/// <returns>true if it's connected, false if not</returns>
public bool IsConnected()
{
return this.connected;
}
/// <summary>
/// tries to log in to the server by asking for a username and password
/// </summary>
public void tryLogin(string username, string password)
{
string hashPassword = Util.Hasher.HashString(password);
byte[] message = DataParser.getJsonMessage(DataParser.LoginAsDoctor(username, hashPassword));
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
internal void SetLoginViewModel(LoginViewModel loginViewModel)
{
this.LoginViewModel = loginViewModel;
}
internal void SetMainViewModel(MainViewModel mainViewModel)
{
this.MainViewModel = mainViewModel;
}
internal void SetClientInfoViewModel(ClientInfoViewModel clientInfoViewModel)
{
this.ClientInfoViewModel = clientInfoViewModel;
}
public void Dispose()
{
Debug.WriteLine("client dispose called");
sendMessage(DataParser.getDisconnectJson(LoginViewModel.Username));
this.stream.Dispose();
this.client.Dispose();
}
}
}

View File

@@ -0,0 +1,149 @@
using DoctorApp.Models;
using DoctorApp.Utils;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Windows.Controls;
using System.Windows.Input;
using Util;
namespace DoctorApp.ViewModels
{
class ClientInfoViewModel : ObservableObject
{
public PatientInfo PatientInfo { get; set; }
private string _mySelectedItem;
public string MySelectedItem
{
get { return _mySelectedItem; }
set
{
Chart.Clear();
_mySelectedItem = value;
}
}
public ICommand StartSession { get; set; }
public ICommand StopSession { get; set; }
public ICommand Chat { get; set; }
public ICommand ChatToAll { get; set; }
public ICommand ClientInfo { get; set; }
public ICommand SetResistance { get; set; }
public ICommand SaveHistoricData { get; set; }
public MainWindowViewModel MainWindowViewModel { get; set; }
private Client client;
public Chart Chart { get; set; }
public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel, string username)
{
MainWindowViewModel = mainWindowViewModel;
this.PatientInfo = new PatientInfo() { Username = username, Status = "Waiting to start" };
this.Chart = new Chart(this.PatientInfo);
PatientInfo.ChatLog = new ObservableCollection<string>();
client = mainWindowViewModel.client;
StartSession = new RelayCommand(() =>
{
client.sendMessage(DataParser.getStartSessionJson(PatientInfo.Username));
PatientInfo.Status = "Session started";
});
StopSession = new RelayCommand(() =>
{
client.sendMessage(DataParser.getStopSessionJson(PatientInfo.Username));
PatientInfo.Status = "Session stopped, waiting to start again.";
});
Chat = new RelayCommand<object>((parameter) =>
{
client.sendMessage(DataParser.getChatJson(PatientInfo.Username, ((TextBox)parameter).Text));
PatientInfo.ChatLog.Add(DateTime.Now + ": " + ((TextBox)parameter).Text);
});
//TODO RelayCommand ChatToAll
SetResistance = new RelayCommand<object>((parameter) =>
{
Debug.WriteLine("resistance");
//client.sendMessage(DataParser.getSetResistanceJson(PatientInfo.Username, float.Parse(((TextBox)parameter).Text)));
PatientInfo.Resistance = float.Parse(((TextBox)parameter).Text);
});
// request the historic data from the server
this.SaveHistoricData = new RelayCommand<object>((parameter) =>
{
this.client.sendMessage(DataParser.GetGetFileMessage(PatientInfo.Username));
// data is stored on the server
// send request to server that we want to get the current historic data from the patient
// server sends this back
// we parse it
});
}
public void BPMData(byte[] bytes)
{
//TODO
//Parsen van de data you fuck
PatientInfo.BPM = bytes[1];
if (bytes[0] == 0x00)
{
}
else
{
if (MySelectedItem == "BPM")
{
Chart.NewValue(PatientInfo.BPM);
}
}
}
public void BikeData(byte[] bytes)
{
//TODO
//Parsen van de data you fuck
switch (bytes[0])
{
case 0x10:
if (bytes[1] != 25)
{
throw new Exception();
}
PatientInfo.Distance = bytes[3];
PatientInfo.Speed = (bytes[4] | (bytes[5] << 8)) * 0.01;
if (MySelectedItem == "Speed")
{
Chart.NewValue(PatientInfo.Speed);
}
break;
case 0x19:
PatientInfo.Acc_Power = bytes[3] | (bytes[4] << 8);
PatientInfo.Curr_Power = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
break;
default:
Debug.WriteLine("rip");
break;
}
}
}
}

View File

@@ -0,0 +1,47 @@

using DoctorApp.Utils;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using System.Windows.Input;
using Util;
namespace DoctorApp.ViewModels
{
class LoginViewModel : ObservableObject
{
public string Username { get; set; }
public ICommand LoginCommand { get; set; }
public bool LoginStatus { get; set; }
public bool InvertedLoginStatus { get; set; }
private MainWindowViewModel mainWindowViewModel;
public LoginViewModel(MainWindowViewModel mainWindowViewModel)
{
this.mainWindowViewModel = mainWindowViewModel;
LoginCommand = new RelayCommand<object>((parameter) =>
{
//TODO send username and password to server
this.mainWindowViewModel.client.tryLogin(Username, ((PasswordBox)parameter).Password);
});
}
internal void setLoginStatus(bool status)
{
this.mainWindowViewModel.InfoModel.ConnectedToServer = status;
this.InvertedLoginStatus = !status;
if (status)
{
MainViewModel mainViewModel = new MainViewModel(mainWindowViewModel);
this.mainWindowViewModel.client.SetMainViewModel(mainViewModel);
this.mainWindowViewModel.SelectedViewModel = mainViewModel;
}
}
}
}

View File

@@ -0,0 +1,82 @@
using DoctorApp.Utils;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Windows.Controls;
using Util;
namespace DoctorApp.ViewModels
{
class MainViewModel : ObservableObject
{
public ObservableCollection<ClientInfoViewModel> Tabs { get; set; }
public int Selected { get; set; }
public MainWindowViewModel MainWindowViewModel { get; set; }
Client client;
public MainViewModel(MainWindowViewModel mainWindowViewModel)
{
this.MainWindowViewModel = mainWindowViewModel;
client = this.MainWindowViewModel.client;
Tabs = new ObservableCollection<ClientInfoViewModel>();
}
public void NewConnectedUser(string username)
{
Debug.WriteLine("new tab with name " + username);
App.Current.Dispatcher.Invoke((Action)delegate
{
Tabs.Add(new ClientInfoViewModel(MainWindowViewModel, username));
});
}
public void DisconnectedUser(string username)
{
App.Current.Dispatcher.Invoke((Action)delegate
{
foreach (ClientInfoViewModel item in Tabs)
{
if (item.PatientInfo.Username == username)
{
Tabs.Remove(item);
break;
}
}
});
}
public void TransferDataToClientBike(byte[] bytes)
{
string username = DataParser.getNameFromBytesBike(bytes);
foreach (ClientInfoViewModel item in Tabs)
{
if (item.PatientInfo.Username == username)
{
item.BikeData(DataParser.getDataWithoutName(bytes, 0, 8));
return;
}
}
Debug.WriteLine("[MainViewModel] did not find client (bike) username is " + username);
}
public void TransferDataToClientBPM(byte[] bytes)
{
string username = DataParser.getNameFromBytesBPM(bytes);
foreach (ClientInfoViewModel item in Tabs)
{
if (item.PatientInfo.Username == username)
{
item.BPMData(DataParser.getDataWithoutName(bytes, 0, 2));
return;
}
}
Debug.WriteLine("[MainViewModel] did not find client (bpm) username is " + username);
}
}
}

View File

@@ -0,0 +1,134 @@
using GalaSoft.MvvmLight.Command;
using System.Diagnostics;
using Util;
using System.Windows;
using System.Windows.Input;
using DoctorApp.Models;
using DoctorApp.Utils;
using Util.MagicCode;
namespace DoctorApp.ViewModels
{
class MainWindowViewModel : ObservableObject
{
#region private members
private Window mWindow;
private int mOuterMarginSize = 10;
private int mWindowRadius = 10;
#endregion
#region commands
public ICommand MinimizeCommand { get; set; }
public ICommand MaximizeCommand { get; set; }
public ICommand CloseCommand { get; set; }
public ICommand MenuCommand { get; set; }
#endregion
#region public properties
public Info InfoModel { get; set; }
public ObservableObject SelectedViewModel { get; set; }
public Client client { get; }
/// <summary>
/// size of the resize border around the window
/// </summary>
public double MinimumWidth { get; set; } = 250;
public double MinimumHeight { get; set; } = 250;
public int ResizeBorder { get; set; } = 6;
public Thickness ResizeBorderThickness { get { return new Thickness(ResizeBorder + OuterMarginSize); } }
public Thickness InnerContentPadding { get { return new Thickness(ResizeBorder); } }
public Thickness OuterMarginThickness { get { return new Thickness(OuterMarginSize); } }
public CornerRadius WindowCornerRadius { get { return new CornerRadius(WindowRadius); } }
public int OuterMarginSize
{
get
{
return mWindow.WindowState == WindowState.Maximized ? 0 : mOuterMarginSize;
}
set
{
mOuterMarginSize = value;
}
}
public int WindowRadius
{
get
{
return mWindow.WindowState == WindowState.Maximized ? 0 : mWindowRadius;
}
set
{
mWindowRadius = value;
}
}
public int TitleHeight { get; set; } = 42;
public GridLength TitleHeightGridLength { get { return new GridLength(TitleHeight + ResizeBorder); } }
#endregion
public MainWindowViewModel(Window window, Client client)
{
this.mWindow = window;
this.mWindow.StateChanged += (sender, e) =>
{
OnPropertyChanged(nameof(ResizeBorderThickness));
OnPropertyChanged(nameof(OuterMarginThickness));
OnPropertyChanged(nameof(WindowCornerRadius));
OnPropertyChanged(nameof(OuterMarginSize));
OnPropertyChanged(nameof(WindowRadius));
};
this.InfoModel = new Info();
this.client = client;
LoginViewModel loginViewModel = new LoginViewModel(this);
SelectedViewModel = loginViewModel;
this.client.SetLoginViewModel(loginViewModel);
this.MinimizeCommand = new RelayCommand(() => this.mWindow.WindowState = WindowState.Minimized);
this.MaximizeCommand = new RelayCommand(() => this.mWindow.WindowState ^= WindowState.Maximized);
this.CloseCommand = new RelayCommand(() => this.mWindow.Close());
this.MenuCommand = new RelayCommand(() => SystemCommands.ShowSystemMenu(this.mWindow, GetMousePosition()));
var resizer = new WindowResizer(this.mWindow);
this.mWindow.Closed += (sender, e) => this.client.Dispose();
}
#region helper
private Point GetMousePosition()
{
Debug.WriteLine("getmousePosition called");
var p = Mouse.GetPosition(this.mWindow);
return new Point(p.X + this.mWindow.Left, p.Y + this.mWindow.Top);
}
#endregion
}
}

View File

@@ -0,0 +1,93 @@
<UserControl x:Class="DoctorApp.Views.ClientInfoView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DoctorApp.Views"
mc:Ignorable="d"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Margin="15,5,15,15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="43*"/>
<RowDefinition Height="47*"/>
<RowDefinition Height="180*"/>
<RowDefinition Height="180*"/>
</Grid.RowDefinitions>
<Grid Grid.RowSpan="2" Margin="0,0,0,22">
<StackPanel Orientation="Horizontal" >
<StackPanel.Resources>
<Style TargetType="{x:Type Label}">
<Setter Property="Margin" Value="0,0,20,0"/>
</Style>
</StackPanel.Resources>
<Label Content="{Binding Path=PatientInfo.Username}"/>
<Label Content="{Binding Path=PatientInfo.Status}"/>
</StackPanel>
<Button Content="Save Historic Data" HorizontalAlignment="Right" VerticalAlignment="Center" Padding="5" Command="{Binding SaveHistoricData}"/>
</Grid>
<StackPanel Margin="0,10,0,0" Grid.Row="2">
<StackPanel.Resources>
<Style TargetType="{x:Type DockPanel}">
<Setter Property="Margin" Value="0,20,0,0"/>
</Style>
</StackPanel.Resources>
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
<Label Content="Resistance" Width="110" DockPanel.Dock="Right"/>
<Label Content="Current Speed" Width="110" DockPanel.Dock="Left"/>
<Label Content="Current BPM" Width="110" DockPanel.Dock="Top"/>
</DockPanel>
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
<TextBox Name="textBox_Resistance" Text="{Binding Path=PatientInfo.Resistance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
<TextBox Name="textBox_CurrentSpeed" Text="{Binding Path=PatientInfo.Speed, StringFormat=N2}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
<TextBox Name="textBox_CurrentBPM" Text="{Binding Path=PatientInfo.BPM}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
</DockPanel>
<DockPanel Height="26" LastChildFill="False">
<Label Content="Distance Covered" Width="110" DockPanel.Dock="Right"/>
<Label Content="Current Power" Width="110" DockPanel.Dock="Left"/>
<Label Content="Acc. Power" Width="110" DockPanel.Dock="Top"/>
</DockPanel>
<DockPanel Height="26" LastChildFill="False">
<TextBox Name="textBox_DistanceCovered" Text="{Binding Path=PatientInfo.Distance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
<TextBox Name="textBox_CurrentPower" Text="{Binding Path=PatientInfo.Curr_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
<TextBox Name="textBox_AccPower" Text="{Binding Path=PatientInfo.Acc_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
</DockPanel>
</StackPanel>
<ListBox Name="ChatBox" ItemsSource="{Binding PatientInfo.ChatLog}" Grid.Column="1" Margin="59,41,0,0" Grid.RowSpan="3"/>
<TextBox Name="textBox_Chat" Grid.Column="1" HorizontalAlignment="Left" Margin="59,10,0,0" Grid.Row="3" Text="" TextWrapping="Wrap" VerticalAlignment="Top" Width="235"/>
<Button x:Name="Send" Content="Send" Grid.Column="1" HorizontalAlignment="Left" Margin="59,33,0,0" Grid.Row="3" VerticalAlignment="Top" Command="{Binding Chat}" CommandParameter="{Binding ElementName=textBox_Chat}"/>
<Button Content="Start Session" Grid.Column="1" HorizontalAlignment="Left" Margin="69,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Command="{Binding StartSession}" CommandParameter=""/>
<Button Content="Stop Session" Grid.Column="1" HorizontalAlignment="Left" Margin="187,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Command="{Binding StopSession}" CommandParameter=""/>
<TextBox x:Name="textBox_SetResistance" Grid.Column="1" HorizontalAlignment="Left" Margin="69,128,0,0" Grid.Row="3" TextWrapping="Wrap" VerticalAlignment="Top" Width="97"/>
<Button Content="Set Resistance" Grid.Column="1" HorizontalAlignment="Left" Margin="187,128,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Height="18" Command="{Binding SetResistance}" CommandParameter="{Binding ElementName=textBox_SetResistance}"/>
<lvc:CartesianChart Grid.Row="3" AnimationsSpeed="0:0:0.5" Hoverable="False" DataTooltip="{x:Null}" Margin="0,33,0,-5">
<lvc:CartesianChart.Series>
<lvc:LineSeries Values="{Binding Chart.ChartValues}"
PointGeometry="{x:Null}"
LineSmoothness="1"
StrokeThickness="6"
Stroke="#F34336"
Fill="Transparent"/>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding Chart.DateTimeFormatter}"
MaxValue="{Binding Chart.AxisMax}"
MinValue="{Binding Chart.AxisMin}"
Unit="{Binding Chart.AxisUnit}">
<lvc:Axis.Separator>
<lvc:Separator Step="{Binding Chart.AxisStep}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190" SelectedItem="{Binding Path=MySelectedItem}">
<ComboBoxItem Content="Speed" IsSelected="True"></ComboBoxItem>
<ComboBoxItem Content="BPM"></ComboBoxItem>
</ComboBox>
</Grid>
</UserControl>

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DoctorApp.Views
{
/// <summary>
/// Interaction logic for ClientInfoView.xaml
/// </summary>
public partial class ClientInfoView : UserControl
{
public ClientInfoView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,25 @@
<UserControl x:Class="DoctorApp.Views.LoginView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DoctorApp.Views"
xmlns:viewModels="clr-namespace:DoctorApp.ViewModels"
xmlns:Util="clr-namespace:Util.MagicCode"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
>
<DockPanel>
<StackPanel VerticalAlignment="Center" Width="auto">
<Label Content="Username" HorizontalContentAlignment="Center" />
<TextBox x:Name="Username" Text="{Binding Username}" TextWrapping="Wrap" Width="120" Util:FocusAdvancement.AdvancesByEnterKey="True"/>
<Label Content="Password" HorizontalContentAlignment="Center"/>
<PasswordBox x:Name="Password" Width="120" Util:FocusAdvancement.AdvancesByEnterKey="True"/>
<Button x:Name="Login" Content="Login" Command="{Binding LoginCommand}" CommandParameter="{Binding ElementName=Password}" Margin="0,20,0,0" Width="120"/>
<Popup IsOpen="{Binding InvertedLoginStatus}" PopupAnimation = "Fade" HorizontalAlignment="Left">
<Label Content="Login failed" Foreground="Red" Background="#FFFF" />
</Popup>
</StackPanel>
</DockPanel>
</UserControl>

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DoctorApp.Views
{
/// <summary>
/// Interaction logic for LoginView.xaml
/// </summary>
public partial class LoginView : UserControl
{
public LoginView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,27 @@
<UserControl x:Class="DoctorApp.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DoctorApp.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<TabControl TabStripPlacement="Left" ItemsSource="{Binding Tabs}" SelectedItem="{Binding Selected}">
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="/img/patient.png" Width="25" Margin="0 0 5 0"/>
<TextBlock Text="{Binding PatientInfo.Username}" FontSize="20" MaxWidth="100" Width="100" TextTrimming="CharacterEllipsis"/>
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<ContentControl Content="{Binding}"/>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</Grid>
</UserControl>

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DoctorApp.Views
{
/// <summary>
/// Interaction logic for MainView.xaml
/// </summary>
public partial class MainView : UserControl
{
public MainView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,122 @@
<Window x:Class="DoctorApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DoctorApp"
mc:Ignorable="d"
Background="Transparent"
WindowStyle="None"
AllowsTransparency="True"
MinHeight="{Binding MinimumHeight}"
MinWidth="{Binding MinimumWidth}"
Title="MainWindow" Height="800" Width="1500">
<Window.Resources>
<Style TargetType="{x:Type local:MainWindow}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Border Padding="{Binding OuterMarginThickness, FallbackValue=10}" >
<Grid>
<!-- opacity mask -->
<Border x:Name="Container"
Background="{StaticResource BackgroundLightBrush}"
CornerRadius="{Binding WindowCornerRadius, FallbackValue=10}"/>
<Border CornerRadius="{Binding WindowCornerRadius, FallbackValue=10}"
Background="{StaticResource BackgroundVeryLightBrush}">
<Border.Effect>
<DropShadowEffect ShadowDepth="0" Opacity="0.2"/>
</Border.Effect>
</Border>
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="{Binding ElementName=Container}"/>
</Grid.OpacityMask>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding TitleHeightGridLength, FallbackValue=42}"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Title bar -->
<Grid Grid.Column="0" Grid.Row="0" Panel.ZIndex="1" Background="{StaticResource BackgroundLightBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- icon -->
<Button Grid.Column="0" Style="{StaticResource SystemIconButton}" Command="{Binding MenuCommand}">
<Image Source="/img/doctor.ico"/>
<!--<TextBlock Text="icon"/>-->
</Button>
<!-- Title -->
<Viewbox Grid.Column="1" Margin="0">
<TextBlock Style="{StaticResource HeaderText}" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title, FallbackValue=failed}"/>
</Viewbox>
<!-- Window buttons -->
<StackPanel Grid.Column="2" Orientation="Horizontal">
<Button Style="{StaticResource WindowControlButton}" Content="_" Command="{Binding MinimizeCommand}"/>
<Button Style="{StaticResource WindowControlButton}" Content="[]" Command="{Binding MaximizeCommand}"/>
<Button Style="{StaticResource WindowCloseButton}" Content="X" Command="{Binding CloseCommand}"/>
</StackPanel>
</Grid>
<!-- Page content -->
<Border Grid.Row="1" Grid.Column="0">
<ContentPresenter Content="{TemplateBinding Content}"/>
</Border>
<!-- shadow? -->
<Border Grid.Row="1" Height="6" BorderThickness="0 0.2 0 0" VerticalAlignment="Top">
<!--<Border.BorderBrush>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="{StaticResource BackgroundSemiLight}" Offset="0.0"/>
<GradientStop Color="{StaticResource BackgroundVeryLight}" Offset="1.0"/>
</LinearGradientBrush>
</Border.BorderBrush>-->
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="Transparent" Offset="1.0"/>
<GradientStop Color="#7000" Offset="0.0"/>
</LinearGradientBrush>
</Border.Background>
</Border>
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<WindowChrome.WindowChrome>
<WindowChrome
ResizeBorderThickness="{Binding ResizeBorderThickness}"
CaptionHeight="{Binding TitleHeight}"
CornerRadius="0"
GlassFrameThickness="0"/>
</WindowChrome.WindowChrome>
<Grid>
<Frame Content="{Binding SelectedViewModel}" Focusable="False" NavigationUIVisibility="Hidden"/>
<Label Content="gemaakt door: mensen" DockPanel.Dock="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontStyle="Italic" Foreground="Gray"/>
</Grid>
</Window>

View File

@@ -0,0 +1,32 @@
using DoctorApp.Utils;
using DoctorApp.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DoctorApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
Client client = new Client();
InitializeComponent();
DataContext = new MainWindowViewModel(this, client);
}
}
}

BIN
DoctorApp/doctor.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

BIN
DoctorApp/img/doctor.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

BIN
DoctorApp/img/patient.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

9
DokterApp/App.xaml Normal file
View File

@@ -0,0 +1,9 @@
<Application x:Class="DokterApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DokterApp"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

17
DokterApp/App.xaml.cs Normal file
View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace DokterApp
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

10
DokterApp/AssemblyInfo.cs Normal file
View File

@@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

196
DokterApp/Client.cs Normal file
View File

@@ -0,0 +1,196 @@
using System;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using ProftaakRH;
namespace DokterApp
{
public class Client : IDataReceiver
{
private TcpClient client;
private NetworkStream stream;
private byte[] buffer = new byte[1024];
private bool connected;
private byte[] totalBuffer = new byte[1024];
private int totalBufferReceived = 0;
private bool sessionRunning = false;
private IHandler handler = null;
private string username;
private string password;
private Del callback;
public Client(string adress, int port, string username, string password, Del callback)
{
this.callback = callback;
this.username = username;
this.password = password;
this.client = new TcpClient();
this.connected = false;
client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null);
}
private void OnConnect(IAsyncResult ar)
{
this.client.EndConnect(ar);
Console.WriteLine("TCP client Verbonden!");
this.stream = this.client.GetStream();
tryLogin();
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
}
private void OnRead(IAsyncResult ar)
{
int receivedBytes = this.stream.EndRead(ar);
if (totalBufferReceived + receivedBytes > 1024)
{
throw new OutOfMemoryException("buffer too small");
}
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, receivedBytes);
totalBufferReceived += receivedBytes;
int expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
while (totalBufferReceived >= expectedMessageLength)
{
//volledig packet binnen
byte[] messageBytes = new byte[expectedMessageLength];
Array.Copy(totalBuffer, 0, messageBytes, 0, expectedMessageLength);
byte[] payloadbytes = new byte[BitConverter.ToInt32(messageBytes, 0) - 5];
Array.Copy(messageBytes, 5, payloadbytes, 0, payloadbytes.Length);
string identifier;
bool isJson = DataParser.getJsonIdentifier(messageBytes, out identifier);
if (isJson)
{
switch (identifier)
{
case DataParser.LOGIN_RESPONSE:
string responseStatus = DataParser.getResponseStatus(payloadbytes);
if (responseStatus == "OK")
{
this.connected = true;
}
else
{
callback("yeet");
Console.WriteLine($"login failed \"{responseStatus}\"");
//tryLogin();
}
break;
case DataParser.START_SESSION:
this.sessionRunning = true;
sendMessage(DataParser.getStartSessionJson());
break;
case DataParser.STOP_SESSION:
this.sessionRunning = false;
sendMessage(DataParser.getStopSessionJson());
break;
case DataParser.SET_RESISTANCE:
if (this.handler == null)
{
Console.WriteLine("handler is null");
sendMessage(DataParser.getSetResistanceResponseJson(false));
}
else
{
this.handler.setResistance(DataParser.getResistanceFromJson(payloadbytes));
sendMessage(DataParser.getSetResistanceResponseJson(true));
}
break;
default:
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
break;
}
}
else if (DataParser.isRawData(messageBytes))
{
Console.WriteLine($"Received data: {BitConverter.ToString(payloadbytes)}");
}
totalBufferReceived -= expectedMessageLength;
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
}
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
}
private void sendMessage(byte[] message)
{
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
private void OnWrite(IAsyncResult ar)
{
this.stream.EndWrite(ar);
}
#region interface
//maybe move this to other place
public void BPM(byte[] bytes)
{
if (!sessionRunning)
{
return;
}
if (bytes == null)
{
throw new ArgumentNullException("no bytes");
}
byte[] message = DataParser.GetRawDataMessage(bytes);
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
public void Bike(byte[] bytes)
{
if (!sessionRunning)
{
return;
}
if (bytes == null)
{
throw new ArgumentNullException("no bytes");
}
byte[] message = DataParser.GetRawDataMessage(bytes);
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
#endregion
public bool IsConnected()
{
return this.connected;
}
private void tryLogin()
{
//TODO File in lezen
string hashUser = Hashing.Hasher.HashString(username);
string hashPassword = Hashing.Hasher.HashString(password);
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(hashUser, hashPassword));
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
public void setHandler(IHandler handler)
{
this.handler = handler;
}
}
}

206
DokterApp/DataParser.cs Normal file
View File

@@ -0,0 +1,206 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
namespace DokterApp
{
public class DataParser
{
public const string LOGIN = "LOGIN";
public const string LOGIN_RESPONSE = "LOGIN RESPONSE";
public const string START_SESSION = "START SESSION";
public const string STOP_SESSION = "STOP SESSION";
public const string SET_RESISTANCE = "SET RESISTANCE";
/// <summary>
/// makes the json object with LOGIN identifier and username and password
/// </summary>
/// <param name="mUsername">username</param>
/// <param name="mPassword">password</param>
/// <returns>json object to ASCII to bytes</returns>
public static byte[] GetLoginJson(string mUsername, string mPassword)
{
dynamic json = new
{
identifier = LOGIN,
data = new
{
username = mUsername,
password = mPassword,
}
};
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
}
public static bool GetUsernamePassword(byte[] jsonbytes, out string username, out string password)
{
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(jsonbytes));
try
{
username = json.data.username;
password = json.data.password;
return true;
}
catch
{
username = null;
password = null;
return false;
}
}
private static byte[] getJsonMessage(string mIdentifier, dynamic data)
{
dynamic json = new
{
identifier = mIdentifier,
data
};
return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01);
}
private static byte[] getJsonMessage(string mIdentifier)
{
dynamic json = new
{
identifier = mIdentifier,
};
return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01);
}
public static byte[] getLoginResponse(string mStatus)
{
return getJsonMessage(LOGIN_RESPONSE, new { status = mStatus });
}
public static string getResponseStatus(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.status;
}
/// <summary>
/// get the identifier from json
/// </summary>
/// <param name="bytes">json in ASCII</param>
/// <param name="identifier">gets the identifier</param>
/// <returns>if it sucseeded</returns>
public static bool getJsonIdentifier(byte[] bytes, out string identifier)
{
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
byte messageId = bytes[4];
if (messageId == 0x01)
{
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(bytes.Skip(5).ToArray()));
identifier = json.identifier;
return true;
}
else
{
identifier = "";
return false;
}
}
/// <summary>
/// checks if the de message is raw data according to the protocol
/// </summary>
/// <param name="bytes">message</param>
/// <returns>if message contains raw data</returns>
public static bool isRawData(byte[] bytes)
{
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
return bytes[4] == 0x02;
}
/// <summary>
/// constructs a message with the payload, messageId and clientId
/// </summary>
/// <param name="payload"></param>
/// <param name="messageId"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
private static byte[] getMessage(byte[] payload, byte messageId)
{
byte[] res = new byte[payload.Length + 5];
Array.Copy(BitConverter.GetBytes(payload.Length + 5), 0, res, 0, 4);
res[4] = messageId;
Array.Copy(payload, 0, res, 5, payload.Length);
return res;
}
/// <summary>
/// constructs a message with the payload and clientId and assumes the payload is raw data
/// </summary>
/// <param name="payload"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
public static byte[] GetRawDataMessage(byte[] payload)
{
return getMessage(payload, 0x02);
}
/// <summary>
/// constructs a message with the payload and clientId and assumes the payload is json
/// </summary>
/// <param name="payload"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
public static byte[] getJsonMessage(byte[] payload)
{
return getMessage(payload, 0x01);
}
public static byte[] getStartSessionJson()
{
return getJsonMessage(START_SESSION);
}
public static byte[] getStopSessionJson()
{
return getJsonMessage(STOP_SESSION);
}
public static byte[] getSetResistanceJson(float mResistance)
{
dynamic data = new
{
resistance = mResistance
};
return getJsonMessage(SET_RESISTANCE, data);
}
public static byte[] getSetResistanceResponseJson(bool mWorked)
{
dynamic data = new
{
worked = mWorked
};
return getJsonMessage(SET_RESISTANCE, data);
}
public static float getResistanceFromJson(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.resistance;
}
public static bool getResistanceFromResponseJson(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked;
}
}
}

View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
<ItemGroup>
<PackageReference Include="ChartControls" Version="1.3.3" />
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
</ItemGroup>
</Project>

28
DokterApp/ITab.cs Normal file
View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;
namespace DokterApp
{
public interface ITab
{
string Name { get; set; }
ICommand CloseCommand { get; }
event EventHandler CloseRequested;
}
public abstract class Tab : ITab
{
public string Name { get; set; }
public ICommand CloseCommand { get; }
public event EventHandler CloseRequested;
public Tab()
{
//CloseCommand =
}
}
}

29
DokterApp/MainWindow.xaml Normal file
View File

@@ -0,0 +1,29 @@
<Window x:Class="DokterApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DokterApp"
mc:Ignorable="d"
WindowState="Maximized"
Title="Dokter App" >
<Grid RenderTransformOrigin="0.499,0.49">
<Grid.RowDefinitions>
<RowDefinition Height="23*"/>
<RowDefinition Height="31*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Grid.ColumnSpan="2" Grid.RowSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" Orientation="Vertical">
<Label x:Name="Label" Content="Yo dokter login" Margin="0,0,0,20" HorizontalAlignment="Center"/>
<Label Content="Username" HorizontalContentAlignment="Center"/>
<TextBox x:Name="Username" TextWrapping="Wrap" Width="120"/>
<Label Content="Password" HorizontalContentAlignment="Center"/>
<PasswordBox x:Name="Password" Width="120"/>
<Button x:Name="Login" Content="Login" Margin="0,20,0,0" Click="Login_Click_1" />
</StackPanel>
</Grid>
</Window>

View File

@@ -0,0 +1,49 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DokterApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Del handler;
Client client;
public MainWindow()
{
InitializeComponent();
}
private void Login_Click_1(object sender, RoutedEventArgs e)
{
WindowTabs windowTabs = new WindowTabs();
handler = windowTabs.NewTab;
this.Label.Content = "Waiting";
this.client = new Client("localhost", 5555, this.Username.Text, this.Password.Password, handler);
while (!client.IsConnected())
{
}
windowTabs.Show();
this.Close();
}
}
public delegate void Del(string message);
}

View File

@@ -0,0 +1,67 @@
<UserControl x:Class="DokterApp.UserControlForTab"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DokterApp"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Margin="15,5,15,15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="43*"/>
<RowDefinition Height="47*"/>
<RowDefinition Height="180*"/>
<RowDefinition Height="180*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.RowSpan="2" Margin="0,0,0,22">
<StackPanel.Resources>
<Style TargetType="{x:Type Label}">
<Setter Property="Margin" Value="0,0,20,0"/>
</Style>
</StackPanel.Resources>
<Label Content="UserName" Name="Username_Label"/>
<Label Content="Status: " Name="Status_Label"/>
</StackPanel>
<StackPanel Margin="0,10,0,0" Grid.RowSpan="2" Grid.Row="1">
<StackPanel.Resources>
<Style TargetType="{x:Type DockPanel}">
<Setter Property="Margin" Value="0,20,0,0"/>
</Style>
</StackPanel.Resources>
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
<Label Content="Resistance" Width="110" DockPanel.Dock="Right"/>
<Label Content="Current Speed" Width="110" DockPanel.Dock="Left"/>
<Label Content="Current BPM" Width="110" DockPanel.Dock="Top"/>
</DockPanel>
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
<TextBox Name="textBox_Resistance" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
<TextBox Name="textBox_CurrentSpeed" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
<TextBox Name="textBox_CurrentBPM" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
</DockPanel>
<DockPanel Height="26" LastChildFill="False">
<Label Content="Distance Covered" Width="110" DockPanel.Dock="Right"/>
<Label Content="Current Power" Width="110" DockPanel.Dock="Left"/>
<Label Content="Acc. Power" Width="110" DockPanel.Dock="Top"/>
</DockPanel>
<DockPanel Height="26" LastChildFill="False">
<TextBox Name="textBox_DistanceCovered" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
<TextBox Name="textBox_CurrentPower" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
<TextBox Name="textBox_AccPower" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
</DockPanel>
</StackPanel>
<ListBox Name="ChatBox" Grid.Column="1" Margin="59,41,0,0" SelectionChanged="ListBox_SelectionChanged" Grid.RowSpan="3"/>
<TextBox Name="textBox_Chat" Grid.Column="1" HorizontalAlignment="Left" Margin="59,10,0,0" Grid.Row="3" Text="TextBox" TextWrapping="Wrap" VerticalAlignment="Top" Width="235"/>
<Button Content="Button" Grid.Column="1" HorizontalAlignment="Left" Margin="59,33,0,0" Grid.Row="3" VerticalAlignment="Top" Click="Button_Click"/>
<Button Content="Start Session" Grid.Column="1" HorizontalAlignment="Left" Margin="69,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Click="StartSession_Click"/>
<Button Content="Stop Session" Grid.Column="1" HorizontalAlignment="Left" Margin="187,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Click="StopSession_Click"/>
<TextBox x:Name="textBox_SetResistance" Grid.Column="1" HorizontalAlignment="Left" Margin="69,128,0,0" Grid.Row="3" TextWrapping="Wrap" VerticalAlignment="Top" Width="97"/>
<Button Content="Set Resistance" Grid.Column="1" HorizontalAlignment="Left" Margin="187,128,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Height="18" Click="SetResistance_Click"/>
<Canvas Grid.Row="3" Background="White" Margin="0,33,0,0"/>
<ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190"/>
<Button Content="Client Info" Grid.Column="1" HorizontalAlignment="Left" Margin="207,6,0,0" VerticalAlignment="Top" Height="26" Width="82" Click="ClientInfo_Click"/>
</Grid>
</UserControl>

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DokterApp
{
/// <summary>
/// Interaction logic for UserControlForTab.xaml
/// </summary>
public partial class UserControlForTab : UserControl
{
public UserControlForTab()
{
InitializeComponent();
Username_Label.Content = "Bob";
Status_Label.Content = "Status: Dead";
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
{
ChatBox.Items.Add(textBox_Chat.Text);
}
private void StartSession_Click(object sender, RoutedEventArgs e)
{
}
private void StopSession_Click(object sender, RoutedEventArgs e)
{
}
private void SetResistance_Click(object sender, RoutedEventArgs e)
{
}
private void ClientInfo_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("firstname:\tBob\n" +
"surname:\t\tde Bouwer");
}
}
}

14
DokterApp/UserTab.cs Normal file
View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace DokterApp
{
class UserTab : Tab
{
public UserTab()
{
Name = "Piet";
}
}
}

16
DokterApp/WindowTabs.xaml Normal file
View File

@@ -0,0 +1,16 @@
<Window x:Class="DokterApp.WindowTabs"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DokterApp"
mc:Ignorable="d"
WindowState="Maximized"
Title="WindowTabs" Height="450" Width="800">
<Grid>
<TabControl x:Name="tabControl" Loaded="tabControl_Load" TabStripPlacement="Left" Margin="0,23,0,0" />
<Button Content="Button" HorizontalAlignment="Left" Margin="578,125,0,0" VerticalAlignment="Top" Click="Button_Click"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace DokterApp
{
/// <summary>
/// Interaction logic for WindowTabs.xaml
/// </summary>
public partial class WindowTabs : Window
{
public TabControl tbControl;
public WindowTabs()
{
InitializeComponent();
}
private void tabControl_Load(object sender, RoutedEventArgs e)
{
this.tbControl = (sender as TabControl);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
NewTab("Test");
}
public void NewTab(string username)
{
Application.Current.Dispatcher.Invoke((Action)delegate {
// your code
TabItem newTabItem = new TabItem
{
Header = username,
Width = 110,
Height = 40
};
newTabItem.Content = new UserControlForTab();
this.tbControl.Items.Add(newTabItem);
});
}
}
}

BIN
DokterApp/favicon (1).ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

508
Hashing/DataParser.cs Normal file
View File

@@ -0,0 +1,508 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Printing.IndexedProperties;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Media.Animation;
namespace Util
{
public class DataParser
{
public const string LOGIN = "LOGIN";
public const string LOGIN_RESPONSE = "LOGIN RESPONSE";
public const string START_SESSION = "START SESSION";
public const string STOP_SESSION = "STOP SESSION";
public const string SET_RESISTANCE = "SET RESISTANCE";
public const string NEW_CONNECTION = "NEW CONNECTION";
public const string DISCONNECT = "DISCONNECT";
public const string LOGIN_DOCTOR = "LOGIN DOCTOR";
public const string MESSAGE = "MESSAGE";
public const string GET_FILE = "GET FILE";
/// <summary>
/// makes the json object with LOGIN identifier and username and password
/// </summary>
/// <param name="mUsername">username</param>
/// <param name="mPassword">password</param>
/// <returns>json object to ASCII to bytes</returns>
public static byte[] GetLoginJson(string mUsername, string mPassword)
{
dynamic json = new
{
identifier = LOGIN,
data = new
{
username = mUsername,
password = mPassword,
}
};
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
}
internal static string getNameFromBytesBike(byte[] bytes)
{
return getName(bytes, 8, bytes.Length - 8);
}
/// <summary>
/// converts the given string parameter into a message using our protocol.
/// </summary>
/// <param name="messageToSend">the message string to send</param>
/// <returns>a byte array using our protocol to send the message</returns>
public static byte[] GetMessageToSend(string messageToSend)
{
dynamic json = new
{
identifier = MESSAGE,
data = new
{
message = messageToSend
}
};
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
}
internal static string getNameFromBytesBPM(byte[] bytes)
{
return getName(bytes, 2, bytes.Length - 2);
}
private static string getName(byte[] bytes, int offset, int lenght)
{
byte[] nameArray = new byte[lenght];
Array.Copy(bytes, offset, nameArray, 0, lenght);
return Encoding.UTF8.GetString(nameArray);
}
/// <summary>
/// creates a message for when the doctor wants to log in.
/// </summary>
/// <param name="mUsername">the username of the doctor</param>
/// <param name="mPassword">the (hashed) password of the doctor</param>
/// <returns>a byte array using our protocol that contains the username and password of the doctor</returns>
public static byte[] LoginAsDoctor(string mUsername, string mPassword)
{
dynamic json = new
{
identifier = LOGIN_DOCTOR,
data = new
{
username = mUsername,
password = mPassword,
}
};
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
}
/// <summary>
/// gets the username and password from a given message array.
/// </summary>
/// <param name="jsonbytes">the array of bytes containing the message</param>
/// <param name="username">the username variable that the username will be put into</param>
/// <param name="password">the password variable that the password will be put into</param>
/// <returns><c>true</c> if the username and password were received correctly, <c>false</c> otherwise</returns>
public static bool GetUsernamePassword(byte[] jsonbytes, out string username, out string password)
{
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(jsonbytes));
try
{
username = json.data.username;
password = json.data.password;
return true;
}
catch
{
username = null;
password = null;
return false;
}
}
/// <summary>
/// gets message using our protocol of the given identifier and data.
/// </summary>
/// <param name="mIdentifier">the identifier string of the message</param>
/// <param name="data">the payload data of the message</param>
/// <returns>a byte array containing the json message with the given parameters, using our protocol.</returns>
private static byte[] getJsonMessage(string mIdentifier, dynamic data)
{
dynamic json = new
{
identifier = mIdentifier,
data
};
return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01);
}
/// <summary>
/// gets a message using our protocol with only the given identifier string.
/// </summary>
/// <param name="mIdentifier">the identifier to put into the message</param>
/// <returns>a byte array containing the json with only the identifier, using our protocol.</returns>
private static byte[] getJsonMessage(string mIdentifier)
{
dynamic json = new
{
identifier = mIdentifier,
};
return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01);
}
/// <summary>
/// gets the login response of the given status
/// </summary>
/// <param name="mStatus">the status of the response</param>
/// <returns>a byte array containing the response for the given status, using our protocol.</returns>
public static byte[] getLoginResponse(string mStatus)
{
return getJsonMessage(LOGIN_RESPONSE, new { status = mStatus });
}
/// <summary>
/// gets the status of the given json message
/// </summary>
/// <param name="json">the byte array containing a json message using our protocol</param>
/// <returns>the response of the message</returns>
public static string getResponseStatus(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.status;
}
/// <summary>
/// get the identifier from json
/// </summary>
/// <param name="bytes">json in ASCII</param>
/// <param name="identifier">gets the identifier</param>
/// <returns>if it sucseeded</returns>
public static bool getJsonIdentifier(byte[] bytes, out string identifier)
{
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
byte messageId = bytes[4];
if (messageId == 0x01)
{
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(bytes.Skip(5).ToArray()));
identifier = json.identifier;
return true;
}
else
{
identifier = "";
return false;
}
}
/// <summary>
/// checks if the de message is raw data according to the protocol
/// </summary>
/// <param name="bytes">message</param>
/// <returns>if message contains raw data</returns>
public static bool isRawDataBikeServer(byte[] bytes)
{
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
return bytes[4] == 0x02;
}
public static bool isRawDataBPMServer(byte[] bytes)
{
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
return bytes[4] == 0x03;
}
public static bool isRawDataBikeDoctor(byte[] bytes)
{
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
return bytes[4] == 0x04;
}
public static bool isRawDataBPMDoctor(byte[] bytes)
{
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
return bytes[4] == 0x05;
}
public static bool IsHistoricBikeData(byte[] bytes)
{
if (bytes.Length <= 5) throw new ArgumentException("bytes too short");
return bytes[4] == 0x06;
}
/// <summary>
/// constructs a message with the payload, messageId and clientId
/// </summary>
/// <param name="payload"></param>
/// <param name="messageId"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
private static byte[] getMessage(byte[] payload, byte messageId)
{
byte[] res = new byte[payload.Length + 5];
Array.Copy(BitConverter.GetBytes(payload.Length + 5), 0, res, 0, 4);
res[4] = messageId;
Array.Copy(payload, 0, res, 5, payload.Length);
return res;
}
/// <summary>
/// constructs a message with the payload and clientId and assumes the payload is raw data
/// </summary>
/// <param name="payload"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
public static byte[] GetRawBikeDataMessageServer(byte[] payload)
{
return getMessage(payload, 0x02);
}
public static byte[] GetRawBPMDataMessageServer(byte[] payload)
{
return getMessage(payload, 0x03);
}
public static byte[] GetRawBikeDataDoctor(byte[] payload, string username)
{
return GetRawDataDoctor(payload, username, 0x04);
}
public static byte[] GetRawBPMDataDoctor(byte[] payload, string username)
{
return GetRawDataDoctor(payload, username, 0x05);
}
private static byte[] GetRawDataDoctor(byte[] payload, string username, byte messageID)
{
byte[] nameArray = Encoding.ASCII.GetBytes(username);
byte[] total = new byte[nameArray.Length + payload.Length];
Array.Copy(payload, 0, total, 0, payload.Length);
Array.Copy(nameArray, 0, total, payload.Length, nameArray.Length);
return getMessage(total, messageID);
}
/// <summary>
/// constructs a message with the payload and clientId and assumes the payload is json
/// </summary>
/// <param name="payload"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
public static byte[] getJsonMessage(byte[] payload)
{
return getMessage(payload, 0x01);
}
/// <summary>
/// gets the message to start a session with the given user username
/// </summary>
/// <param name="user">the username of the user we want to start the session for</param>
/// <returns>a byte array containing the message to start the session of the given user, using our protocol.</returns>
public static byte[] getStartSessionJson(string user)
{
dynamic data = new
{
username = user
};
return getJsonMessage(START_SESSION, data);
}
/// <summary>
/// gets the message to stop a session with the given user username
/// </summary>
/// <param name="user">the username of the user we want to stop the session for</param>
/// <returns>a byte array containing the message to stop the session of the given user, using our protocol.</returns>
public static byte[] getStopSessionJson(string user)
{
dynamic data = new
{
username = user
};
return getJsonMessage(STOP_SESSION, data);
}
/// <summary>
/// gets the message to set the resistance of the given user with the given resistance.
/// </summary>
/// <param name="user">the username to set the resistance of.</param>
/// <param name="mResistance">the resistance value to set</param>
/// <returns>a byte array containing a json messsage to set the user's resistance, using our protocol.</returns>
public static byte[] getSetResistanceJson(string user, float mResistance)
{
dynamic data = new
{
username = user,
resistance = mResistance
};
return getJsonMessage(SET_RESISTANCE, data);
}
/// <summary>
/// gets the response message with the given value.
/// </summary>
/// <param name="mWorked">the boolean value to indicate if the operation we want to send a response for was successful or not.</param>
/// <returns>a byte array containing a json message with the response and the given value.</returns>
public static byte[] getSetResistanceResponseJson(bool mWorked)
{
dynamic data = new
{
worked = mWorked
};
return getJsonMessage(SET_RESISTANCE, data);
}
/// <summary>
/// gets the message to indicate a new connection for the given user.
/// </summary>
/// <param name="user">the username of the user to start a connection for.</param>
/// <returns>a byte array containing a json message to indicate a new connection for the given user, using our protocol.</returns>
public static byte[] getNewConnectionJson(string user)
{
if (user == null)
throw new ArgumentNullException("user null");
dynamic data = new
{
username = user
};
return getJsonMessage(NEW_CONNECTION, data);
}
/// <summary>
/// gets the message for when a user has been disconnected.
/// </summary>
/// <param name="user">the username of the user that has been disconnected</param>
/// <returns>a byte array containing a json message to indicate that the given user has disconnected, using our protocol.</returns>
public static byte[] getDisconnectJson(string user)
{
dynamic data = new
{
username = user
};
return getJsonMessage(DISCONNECT, data);
}
/// <summary>
/// gets the resistance from the given json message
/// </summary>
/// <param name="json">the json messag</param>
/// <returns>the resistance that was in the message</returns>
public static float getResistanceFromJson(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.resistance;
}
/// <summary>
/// gets the resistance response from the given json message
/// </summary>
/// <param name="json">the byte array containin the json message</param>
/// <returns>the response of the message, so wether it was successful or not.</returns>
public static bool getResistanceFromResponseJson(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked;
}
/// <summary>
/// gets the username from the given response message.
/// </summary>
/// <param name="json">the byte array containin the json message</param>
/// <returns>the username in the message.</returns>
public static string getUsernameFromResponseJson(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
}
/// <summary>
/// gets the chat message from the given json message.
/// </summary>
/// <param name="json">the byte array containin the json message</param>
/// <returns>the chat message in the json message</returns>
public static string getChatMessageFromJson(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.chat;
}
/// <summary>
/// gets the username from the given json message.
/// </summary>
/// <param name="json">the byte array containin the json message</param>
/// <returns>the username that is in the message</returns>
public static string getUsernameFromJson(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
}
/// <summary>
/// gets the byte array with the json message to send a message with the given parameters.
/// </summary>
/// <param name="user">the username of the user that wants to send the message</param>
/// <param name="message">the message the user wants to send</param>
/// <returns>a byte array containing a json message with the username and corresponding message, using our protocol.</returns>
public static byte[] getChatJson(string user, string message)
{
dynamic data = new
{
username = user,
chat = message
};
return getJsonMessage(MESSAGE, data);
}
public static byte[] getDataWithoutName(byte[] bytes, int offset, int length)
{
byte[] data = new byte[length];
Array.Copy(bytes, offset, data, 0, length);
return data;
}
public static byte[] GetGetFileMessage(string mUsername)
{
if (mUsername == null)
{
throw new ArgumentNullException("username null");
}
dynamic data = new
{
username = mUsername,
};
return getJsonMessage(GET_FILE, data);
}
public static string GetUsernameFromGetFileBytes(byte[] json)
{
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
}
public static string GetDateFromGetFileBytes(byte[] json)
{
return ((string)((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.dateTime);
}
public static byte[] GetFileMessage(byte[] file)
{
return getMessage(file, 0x06);
}
}
}

27
Hashing/Hasher.cs Normal file
View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
namespace Util
{
class Hasher
{
public static byte[] GetHash(string input)
{
using (HashAlgorithm algorithm = SHA256.Create())
{
return algorithm.ComputeHash(Encoding.UTF8.GetBytes(input));
}
}
public static string HashString(string input)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in GetHash(input)) {
sb.Append(b.ToString("X2"));
}
return sb.ToString();
}
}
}

40
Hashing/Hashing.projitems Normal file
View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>70277749-d423-4871-b692-2efc5a6ed932</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Hashing</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)DataParser.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Hasher.cs" />
<Compile Include="$(MSBuildThisFileDirectory)WPFStuff\MagicCode\FocusAdvancement.cs" />
<Compile Include="$(MSBuildThisFileDirectory)WPFStuff\MagicCode\WindowResizer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)WPFStuff\ObservableObject.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Buttons.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Colors.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Fonts.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Texts.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Windows.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,65 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ClientApp">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Colors.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type Button}" x:Key="Hoverless">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Button}" x:Key="SystemIconButton" BasedOn="{StaticResource Hoverless}" >
<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True"/>
<Setter Property="Padding" Value="4"/>
</Style>
<Style TargetType="{x:Type Button}" x:Key="WindowControlButton">
<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Foreground" Value="{StaticResource ForegroundMainBrush}"/>
<Setter Property="Padding" Value="6"/>
<Setter Property="LayoutTransform">
<Setter.Value>
<ScaleTransform ScaleX="2"/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource BackgroundSemiLightBrush}"/>
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type Button}" x:Key="WindowCloseButton" BasedOn="{StaticResource WindowControlButton}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,25 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ClientApp">
<Color x:Key="BackgroundLight">#efefef</Color>
<SolidColorBrush x:Key="BackgroundLightBrush" Color="{StaticResource BackgroundLight}"/>
<Color x:Key="BackgroundVeryLight">#fafafa</Color>
<SolidColorBrush x:Key="BackgroundVeryLightBrush" Color="{StaticResource BackgroundVeryLight}"/>
<Color x:Key="BackgroundSemiLight">#d7d7d7</Color>
<SolidColorBrush x:Key="BackgroundSemiLightBrush" Color="{StaticResource BackgroundSemiLight}"/>
<Color x:Key="ForegroundMain">#686868</Color>
<SolidColorBrush x:Key="ForegroundMainBrush" Color="{StaticResource ForegroundMain}"/>
<Color x:Key="ForegroundVeryDark">#000</Color>
<SolidColorBrush x:Key="ForegroundVeryDarkBrush" Color="{StaticResource ForegroundVeryDark}"/>
<Color x:Key="ForegroundWhite">#fff</Color>
<SolidColorBrush x:Key="ForegroundWhiteBrush" Color="{StaticResource ForegroundWhite}"/>
</ResourceDictionary>

View File

@@ -0,0 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ClientApp">
</ResourceDictionary>

11
Hashing/Styles/Texts.xaml Normal file
View File

@@ -0,0 +1,11 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ClientApp">
<Style TargetType="{x:Type TextBlock}" x:Key="HeaderText">
<Setter Property="Foreground" Value="{StaticResource ForegroundMainBrush}"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Margin" Value="0 4"/>
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ClientApp">
</ResourceDictionary>

13
Hashing/Util.shproj Normal file
View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>70277749-d423-4871-b692-2efc5a6ed932</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="Hashing.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,40 @@
using System;
using System.Windows;
using System.Windows.Input;
namespace Util.MagicCode
{
public static class FocusAdvancement
{
public static bool GetAdvancesByEnterKey(DependencyObject obj)
{
return (bool)obj.GetValue(AdvancesByEnterKeyProperty);
}
public static void SetAdvancesByEnterKey(DependencyObject obj, bool value)
{
obj.SetValue(AdvancesByEnterKeyProperty, value);
}
public static readonly DependencyProperty AdvancesByEnterKeyProperty =
DependencyProperty.RegisterAttached("AdvancesByEnterKey", typeof(bool), typeof(FocusAdvancement),
new UIPropertyMetadata(OnAdvancesByEnterKeyPropertyChanged));
static void OnAdvancesByEnterKeyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var element = d as UIElement;
if (element == null) return;
if ((bool)e.NewValue) element.KeyDown += Keydown;
else element.KeyDown -= Keydown;
}
static void Keydown(object sender, KeyEventArgs e)
{
if (!e.Key.Equals(Key.Enter)) return;
var element = sender as UIElement;
if (element != null) element.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
}
}

View File

@@ -0,0 +1,212 @@
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace Util.MagicCode
{
/// <summary>
/// Fixes the issue with Windows of Style <see cref="WindowStyle.None"/> covering the taskbar
/// </summary>
public class WindowResizer
{
#region Private Members
/// <summary>
/// The window to handle the resizing for
/// </summary>
private Window mWindow;
#endregion
#region Dll Imports
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetCursorPos(out POINT lpPoint);
[DllImport("user32.dll")]
static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr MonitorFromPoint(POINT pt, MonitorOptions dwFlags);
#endregion
#region Constructor
/// <summary>
/// Default constructor
/// </summary>
/// <param name="window">The window to monitor and correctly maximize</param>
/// <param name="adjustSize">The callback for the host to adjust the maximum available size if needed</param>
public WindowResizer(Window window)
{
mWindow = window;
// Listen out for source initialized to setup
mWindow.SourceInitialized += Window_SourceInitialized;
}
#endregion
#region Initialize
/// <summary>
/// Initialize and hook into the windows message pump
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_SourceInitialized(object sender, System.EventArgs e)
{
// Get the handle of this window
var handle = (new WindowInteropHelper(mWindow)).Handle;
var handleSource = HwndSource.FromHwnd(handle);
// If not found, end
if (handleSource == null)
return;
// Hook into it's Windows messages
handleSource.AddHook(WindowProc);
}
#endregion
#region Windows Proc
/// <summary>
/// Listens out for all windows messages for this window
/// </summary>
/// <param name="hwnd"></param>
/// <param name="msg"></param>
/// <param name="wParam"></param>
/// <param name="lParam"></param>
/// <param name="handled"></param>
/// <returns></returns>
private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
// Handle the GetMinMaxInfo of the Window
case 0x0024:/* WM_GETMINMAXINFO */
WmGetMinMaxInfo(hwnd, lParam);
handled = true;
break;
}
return (IntPtr)0;
}
#endregion
/// <summary>
/// Get the min/max window size for this window
/// Correctly accounting for the taskbar size and position
/// </summary>
/// <param name="hwnd"></param>
/// <param name="lParam"></param>
private void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
{
POINT lMousePosition;
GetCursorPos(out lMousePosition);
IntPtr lPrimaryScreen = MonitorFromPoint(new POINT(0, 0), MonitorOptions.MONITOR_DEFAULTTOPRIMARY);
MONITORINFO lPrimaryScreenInfo = new MONITORINFO();
if (GetMonitorInfo(lPrimaryScreen, lPrimaryScreenInfo) == false)
{
return;
}
IntPtr lCurrentScreen = MonitorFromPoint(lMousePosition, MonitorOptions.MONITOR_DEFAULTTONEAREST);
MINMAXINFO lMmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
if (lPrimaryScreen.Equals(lCurrentScreen) == true)
{
lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcWork.Left;
lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcWork.Top;
lMmi.ptMaxSize.X = lPrimaryScreenInfo.rcWork.Right - lPrimaryScreenInfo.rcWork.Left;
lMmi.ptMaxSize.Y = lPrimaryScreenInfo.rcWork.Bottom - lPrimaryScreenInfo.rcWork.Top;
}
else
{
lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcMonitor.Left;
lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcMonitor.Top;
lMmi.ptMaxSize.X = lPrimaryScreenInfo.rcMonitor.Right - lPrimaryScreenInfo.rcMonitor.Left;
lMmi.ptMaxSize.Y = lPrimaryScreenInfo.rcMonitor.Bottom - lPrimaryScreenInfo.rcMonitor.Top;
}
// Now we have the max size, allow the host to tweak as needed
Marshal.StructureToPtr(lMmi, lParam, true);
}
}
#region Dll Helper Structures
enum MonitorOptions : uint
{
MONITOR_DEFAULTTONULL = 0x00000000,
MONITOR_DEFAULTTOPRIMARY = 0x00000001,
MONITOR_DEFAULTTONEAREST = 0x00000002
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class MONITORINFO
{
public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
public Rectangle rcMonitor = new Rectangle();
public Rectangle rcWork = new Rectangle();
public int dwFlags = 0;
}
[StructLayout(LayoutKind.Sequential)]
public struct Rectangle
{
public int Left, Top, Right, Bottom;
public Rectangle(int left, int top, int right, int bottom)
{
this.Left = left;
this.Top = top;
this.Right = right;
this.Bottom = bottom;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct MINMAXINFO
{
public POINT ptReserved;
public POINT ptMaxSize;
public POINT ptMaxPosition;
public POINT ptMinTrackSize;
public POINT ptMaxTrackSize;
};
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
/// <summary>
/// x coordinate of point.
/// </summary>
public int X;
/// <summary>
/// y coordinate of point.
/// </summary>
public int Y;
/// <summary>
/// Construct a point of coordinates (x,y).
/// </summary>
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
}
#endregion
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace Util
{
public abstract class ObservableObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
public void OnPropertyChanged(string name)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
}

View File

@@ -0,0 +1,65 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ClientApp">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Colors.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type Button}" x:Key="Hoverless">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Button}" x:Key="SystemIconButton" BasedOn="{StaticResource Hoverless}" >
<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True"/>
<Setter Property="Padding" Value="4"/>
</Style>
<Style TargetType="{x:Type Button}" x:Key="WindowControlButton">
<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Foreground" Value="{StaticResource ForegroundMainBrush}"/>
<Setter Property="Padding" Value="6"/>
<Setter Property="LayoutTransform">
<Setter.Value>
<ScaleTransform ScaleX="2"/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource BackgroundSemiLightBrush}"/>
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type Button}" x:Key="WindowCloseButton" BasedOn="{StaticResource WindowControlButton}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,25 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ClientApp">
<Color x:Key="BackgroundLight">#efefef</Color>
<SolidColorBrush x:Key="BackgroundLightBrush" Color="{StaticResource BackgroundLight}"/>
<Color x:Key="BackgroundVeryLight">#fafafa</Color>
<SolidColorBrush x:Key="BackgroundVeryLightBrush" Color="{StaticResource BackgroundVeryLight}"/>
<Color x:Key="BackgroundSemiLight">#d7d7d7</Color>
<SolidColorBrush x:Key="BackgroundSemiLightBrush" Color="{StaticResource BackgroundSemiLight}"/>
<Color x:Key="ForegroundMain">#686868</Color>
<SolidColorBrush x:Key="ForegroundMainBrush" Color="{StaticResource ForegroundMain}"/>
<Color x:Key="ForegroundVeryDark">#000</Color>
<SolidColorBrush x:Key="ForegroundVeryDarkBrush" Color="{StaticResource ForegroundVeryDark}"/>
<Color x:Key="ForegroundWhite">#fff</Color>
<SolidColorBrush x:Key="ForegroundWhiteBrush" Color="{StaticResource ForegroundWhite}"/>
</ResourceDictionary>

View File

@@ -0,0 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ClientApp">
</ResourceDictionary>

View File

@@ -0,0 +1,11 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ClientApp">
<Style TargetType="{x:Type TextBlock}" x:Key="HeaderText">
<Setter Property="Foreground" Value="{StaticResource ForegroundMainBrush}"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Margin" Value="0 4"/>
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ClientApp">
</ResourceDictionary>

71
Message/Message.cs Normal file
View File

@@ -0,0 +1,71 @@
using Newtonsoft.Json;
using System;
namespace Message
{
/// <summary>
/// Message class to handle traffic between clients and server
/// </summary>
public class Message
{
public static void Main(string[] args)
{
}
/// <summary>
/// identifier for the message
/// </summary>
public Identifier Identifier
{
get;set;
}
/// <summary>
/// payload of the message, the actual text
/// </summary>
public string Payload
{
get;set;
}
/// <summary>
/// constructs a new message with the given parameters
/// </summary>
/// <param name="identifier">the identifier</param>
/// <param name="payload">the payload</param>
public Message(Identifier identifier, string payload)
{
this.Identifier = identifier;
this.Payload = payload;
}
/// <summary>
/// serializes this object to a JSON string
/// </summary>
/// <returns>a JSON representation of this object</returns>
public string Serialize()
{
return JsonConvert.SerializeObject(this);
}
/// <summary>
/// deserializes a JSON string into a new Message object
/// </summary>
/// <param name="json">the JSON string to deserialize</param>
/// <returns>a new <c>Message</c> object from the JSON string</returns>
public static Message Deserialize(string json)
{
return (Message)JsonConvert.DeserializeObject(json);
}
}
/// <summary>
/// Identifier enum for the Message objects
/// </summary>
public enum Identifier
{
LOGIN,
CHAT,
}
}

12
Message/Message.csproj Normal file
View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
</Project>

View File

@@ -4,42 +4,71 @@ using System.Text;
using Avans.TI.BLE;
using System.Threading;
using System.Security.Cryptography;
using ProftaakRH;
namespace Hardware
{
class BLEHandler
/// <summary>
/// <c>BLEHandler</c> class that handles connection and traffic to and from the bike
/// </summary>
public class BLEHandler : IHandler
{
IDataConverter dataConverter;
List<IDataReceiver> dataReceivers;
private BLE bleBike;
private BLE bleHeart;
public bool Running { get; set; }
public BLEHandler(IDataConverter dataConverter)
/// <summary>
/// Makes a new BLEHandler object
/// </summary>
/// <param name="dataReceiver">the dataconverter object</param>
public BLEHandler(IDataReceiver dataReceiver)
{
this.dataConverter = dataConverter;
bool running = false;
this.dataReceivers = new List<IDataReceiver> { dataReceiver };
}
public BLEHandler(List<IDataReceiver> dataReceivers)
{
this.dataReceivers = dataReceivers;
}
public void addDataReceiver(IDataReceiver dataReceiver)
{
this.dataReceivers.Add(dataReceiver);
}
/// <summary>
/// Checks for available devices to connect to, and if one is found, it connects to it
/// </summary>
public void Connect()
{
BLE bleBike = new BLE();
Thread.Sleep(1000); // We need some time to list available devices
// List available devices
List<String> bleBikeList = bleBike.ListDevices();
Console.WriteLine("Devices found: ");
Console.WriteLine("[BLEHANDLER] Devices found: ");
foreach (var name in bleBikeList)
{
Console.WriteLine(name);
if (name.Contains("Avans Bike"))
{
Console.WriteLine("connecting to {0}", name);
Console.WriteLine("[BLEHANDLER] connecting to {0}", name);
Connect(name);
break;
}
}
}
/// <summary>
/// Connects to the device with the given name
/// </summary>
/// <param name="deviceName">The name of the device to connect to</param>
public async void Connect(string deviceName)
{
int errorCode = 0;
@@ -95,23 +124,32 @@ namespace Hardware
Console.WriteLine("connected to BLE");
this.Running = true;
}
/// <summary>
/// Callback for when the subscription value of the ble bike has changed
/// </summary>
/// <param name="sender"> the sender object</param>
/// <param name="e">the value changed event</param>
private void BleBike_SubscriptionValueChanged(object sender, BLESubscriptionValueChangedEventArgs e)
{
//Console.WriteLine("Received from {0}: {1}", e.ServiceName,
// BitConverter.ToString(e.Data).Replace("-", " "));
//send to dataconverter
if (e.ServiceName == "6e40fec2-b5a3-f393-e0a9-e50e24dcca9e")
{
byte[] payload = new byte[8];
Array.Copy(e.Data, 4, payload, 0, 8);
this.dataConverter.Bike(payload);
foreach (IDataReceiver dataReceiver in this.dataReceivers)
{
dataReceiver.Bike(payload);
}
}
else if (e.ServiceName == "00002a37-0000-1000-8000-00805f9b34fb")
{
this.dataConverter.BPM(e.Data);
foreach (IDataReceiver dataReceiver in this.dataReceivers)
{
dataReceiver.BPM(e.Data);
}
}
else
{
@@ -120,6 +158,9 @@ namespace Hardware
}
/// <summary>
/// Disposes of the current BLE object, if it exists.
/// </summary>
private void disposeBLE()
{
this.bleBike?.Dispose();
@@ -127,8 +168,17 @@ namespace Hardware
this.Running = false;
}
/// <summary>
/// Method <c>setResistance</c> converts the input percentage to bytes and sends it to the bike.
/// </summary>
/// <param name="percentage">The precentage of resistance to set</param>
public void setResistance(float percentage)
{
if (!this.Running)
{
Console.WriteLine("BLE is not running");
return;
}
byte[] antMessage = new byte[13];
antMessage[0] = 0x4A;
antMessage[1] = 0x09;
@@ -140,7 +190,7 @@ namespace Hardware
antMessage[i] = 0xFF;
}
antMessage[11] = (byte)Math.Max(Math.Min(Math.Round(percentage / 0.5), 255), 0);
//antMessage[11] = 50; //hardcoded for testing
byte checksum = 0;
for (int i = 0; i < 12; i++)
@@ -151,7 +201,13 @@ namespace Hardware
antMessage[12] = checksum;//reminder that i am dumb :P
bleBike.WriteCharacteristic("6E40FEC3-B5A3-F393-E0A9-E50E24DCCA9E", antMessage);
bleBike.WriteCharacteristic("6e40fec3-b5a3-f393-e0a9-e50e24dcca9e", antMessage);
}
public void stop()
{
bleBike.SubscriptionValueChanged -= BleBike_SubscriptionValueChanged;
bleHeart.SubscriptionValueChanged -= BleBike_SubscriptionValueChanged;
}
}
}

View File

@@ -1,6 +1,8 @@
using LibNoise.Primitive;
using ProftaakRH;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
@@ -9,9 +11,9 @@ using System.Threading;
namespace Hardware.Simulators
{
class BikeSimulator : IHandler
public class BikeSimulator : IHandler
{
IDataConverter dataConverter;
List<IDataReceiver> dataReceivers;
private int elapsedTime = 0;
private int eventCounter = 0;
private double distanceTraveled = 0;
@@ -20,33 +22,56 @@ namespace Hardware.Simulators
private int BPM = 0;
private int cadence = 0;
private double resistance = 0;
private double power;
private double accPower;
byte[] array;
byte[] speedArray;
byte[] powerArray;
byte[] accPowerArray;
bool running = false;
public BikeSimulator(IDataConverter dataConverter)
public BikeSimulator(IDataReceiver dataReceiver)
{
this.dataConverter = dataConverter;
this.dataReceivers = new List<IDataReceiver> { dataReceiver };
}
public BikeSimulator(List<IDataReceiver> dataReceivers)
{
this.dataReceivers = dataReceivers;
}
public void addDataReceiver(IDataReceiver dataReceiver)
{
this.dataReceivers.Add(dataReceiver);
}
public void StartSimulation()
{
Console.WriteLine("simulating bike...");
//Example BLE Message
//4A-09-4E-05-19-16-00-FF-28-00-00-20-F0
this.running = true;
float x = 0.0f;
//Perlin for Random values
ImprovedPerlin improvedPerlin = new ImprovedPerlin(0,LibNoise.NoiseQuality.Best);
while (true)
ImprovedPerlin improvedPerlin = new ImprovedPerlin(0, LibNoise.NoiseQuality.Best);
while (this.running)
{
CalculateVariables(improvedPerlin.GetValue(x)+1);
CalculateVariables(improvedPerlin.GetValue(x) + 1);
//Simulate sending data
dataConverter.Bike(GenerateBike0x19());
dataConverter.Bike(GenerateBike0x10());
dataConverter.BPM(GenerateHeart());
foreach (IDataReceiver dataReceiver in this.dataReceivers)
{
dataReceiver.Bike(GenerateBike0x19());
dataReceiver.Bike(GenerateBike0x10());
dataReceiver.BPM(GenerateHeart());
}
Thread.Sleep(1000);
@@ -60,79 +85,70 @@ namespace Hardware.Simulators
//Generate an ANT message for page 0x19
private byte[] GenerateBike0x19()
{
byte[] bikeByte = { 0x19, Convert.ToByte(eventCounter%256), 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
byte statByte = (byte)(powerArray[1] >> 4);
byte[] bikeByte = { 0x19, Convert.ToByte(eventCounter % 256), Convert.ToByte(cadence % 254), accPowerArray[0], accPowerArray[1], powerArray[0], statByte, 0x20 };
return bikeByte;
}
//Generate an ANT message for page 0x10
private byte[] GenerateBike0x10()
{
byte[] bikeByte = { 0x10, Convert.ToByte(equipmentType), Convert.ToByte(elapsedTime*4%64), Convert.ToByte(distanceTraveled), array[0], array[1], Convert.ToByte(BPM), 0xFF };
return bikeByte;
try
{
byte[] bikeByte = { 0x10, check(equipmentType), check(elapsedTime * 4 % 64), check((int)Math.Round(distanceTraveled)), speedArray[0], speedArray[1], check(BPM), 0xFF };
return bikeByte;
}
catch (OverflowException e)
{
Debug.WriteLine(e);
byte[] res = { 0x10,0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0xFF};
return res;
}
}
private byte check(int value)
{
return value > 255 ? Convert.ToByte(255) : value < 0 ? Convert.ToByte(0) : Convert.ToByte(value);
}
//Generate an ANT message for BPM
private byte[] GenerateHeart()
{
byte[] hartByte = { 0x00, Convert.ToByte(BPM)};
byte[] hartByte = { 0x00, Convert.ToByte(BPM) };
return hartByte;
}
//Generate an ANT message for resistance
public byte[] GenerateResistance(float percentage)
{
byte[] antMessage = new byte[13];
antMessage[0] = 0x4A;
antMessage[1] = 0x09;
antMessage[2] = 0x4E;
antMessage[3] = 0x05;
antMessage[4] = 0x30;
for (int i = 5; i < 11; i++)
{
antMessage[i] = 0xFF;
}
antMessage[11] = (byte)Math.Max(Math.Min(Math.Round(percentage / 0.5), 255), 0);
//antMessage[11] = 50; //hardcoded for testing
byte checksum = 0;
for (int i = 0; i < 12; i++)
{
checksum ^= antMessage[i];
}
antMessage[12] = checksum;//reminder that i am dumb :P
return antMessage;
}
//Calculates the needed variables
//Input perlin value
private void CalculateVariables(float perlin)
{
this.speed = perlin * 5 / 0.01 ;
this.speed = perlin * 5 / 0.01;
short sped = (short)speed;
array = BitConverter.GetBytes(sped);
this.distanceTraveled = (distanceTraveled+(speed*0.01)) % 256;
this.BPM = (int) (perlin * 80);
this.cadence = (int)speed * 4;
speedArray = BitConverter.GetBytes(sped);
this.distanceTraveled = (distanceTraveled + (speed * 0.01)) % 256;
this.BPM = (int)(perlin * 80);
this.cadence = (int)speed / 6;
this.power = ((1 + resistance) * speed) / 14 % 4094;
this.accPower = (this.accPower + this.power) % 65536;
// TO DO power to power LSB & MSN
powerArray = BitConverter.GetBytes((short)this.power);
accPowerArray = BitConverter.GetBytes((short)accPower);
}
//Set resistance in simulated bike
public void setResistance(byte[] bytes)
public void setResistance(float percentage)
{
//TODO check if message is correct
if(bytes.Length == 13)
{
this.resistance = Convert.ToDouble(bytes[11])/2;
}
this.resistance = (byte)Math.Max(Math.Min(Math.Round(percentage / 0.5), 255), 0);
}
public void stop()
{
this.running = false;
}
}
//Interface for receiving a message on the simulated bike
interface IHandler
{
void setResistance(byte[] bytes);
}
}

View File

@@ -1,11 +1,19 @@
using System;
using ProftaakRH;
using System;
using System.Collections.Generic;
using System.Text;
namespace Hardware
{
class DataConverter : IDataConverter
/// <summary>
/// DataConverter class that handles all conversion of received data from the BLE bike.
/// </summary>
class DataConverter : IDataReceiver
{
/// <summary>
/// Receives, parses and displays any incoming data from the bike.
/// </summary>
/// <param name="bytes">the array of bytes that was received</param>
public void Bike(byte[] bytes)
{
if (bytes == null)
@@ -15,7 +23,7 @@ namespace Hardware
else
if (bytes.Length == 8)
{
switch (bytes[0])
{
case 0x10:
@@ -30,7 +38,7 @@ namespace Hardware
Console.WriteLine($"Speed is : {input * 0.01}m/s (Range 65.534m/4)");
if (bytes[6] != 0xFF)
{
Console.WriteLine("Heart rate byte: {0}", Convert.ToString(bytes[6],2));
Console.WriteLine("Heart rate byte: {0}", Convert.ToString(bytes[6], 2));
}
break;
case 0x19:
@@ -38,22 +46,23 @@ namespace Hardware
if (bytes[2] != 0xFF)
{
Console.WriteLine($"Instantaneous cadence: {bytes[2]} RPM (Range 0-254)");
}
int accumPower = bytes[3] | (bytes[4] << 8);
Console.WriteLine($"Accumulated power: {accumPower} watt (Rollover 65536)");
int instantPower = (bytes[5]) | (bytes[6]>>4)<<8;
int instantPower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
if (instantPower != 0xFFF)
Console.WriteLine($"Instant power: {instantPower} watt (Range 0-4094)");
Console.WriteLine($"Instant power: {instantPower} watt (Range 0-4094)");
int trainerStatus = bytes[6] & 0b00001111; // bit 4-7
int trainerStatus = bytes[6] & 0b11110000; // bit 4-7
int flags = bytes[7] >> 4;
int FEState = bytes[7] & 0b00001111;
break;
default:
@@ -68,6 +77,10 @@ namespace Hardware
Console.WriteLine();
}
/// <summary>
/// Gets and prints the BPM from the message received from the bike.
/// </summary>
/// <param name="bytes">The array with bytes that was received</param>
public void BPM(byte[] bytes)
{
if (bytes == null)
@@ -91,10 +104,4 @@ namespace Hardware
Console.WriteLine();
}
}
interface IDataConverter
{
void BPM(byte[] bytes);
void Bike(byte[] bytes);
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace ProftaakRH
{
public interface IDataReceiver
{
void BPM(byte[] bytes);
void Bike(byte[] bytes);
}
}

13
ProftaakRH/IHandler.cs Normal file
View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace ProftaakRH
{
public interface IHandler
{
void setResistance(float percentage);
void stop();
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
using Hardware;
@@ -7,16 +7,38 @@ using Hardware.Simulators;
namespace ProftaakRH
{
class Program
class Program
{
static void Main(string[] agrs)
{
IDataConverter dataConverter = new DataConverter();
BikeSimulator bikeSimulator = new BikeSimulator(dataConverter);
bikeSimulator.setResistance(bikeSimulator.GenerateResistance(1f));
IDataReceiver dataReceiver = new DataConverter();
BLEHandler bLEHandler = new BLEHandler(dataReceiver);
BikeSimulator bikeSimulator = new BikeSimulator(dataReceiver);
bikeSimulator.setResistance(1);
bikeSimulator.StartSimulation();
Console.ReadLine();
bool running = true;
while (running)
{
string input = Console.ReadLine();
input.ToLower();
input.Trim();
if (input == "quit")
{
running = false;
break;
}
try
{
int resistance = Int32.Parse(input);
bLEHandler.setResistance(resistance);
}
catch
{
//do nothing
}
}
}
}
}

View File

@@ -7,6 +7,7 @@
<ItemGroup>
<PackageReference Include="LibNoise" Version="0.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<Reference Include="BLELibrary">

View File

@@ -3,18 +3,64 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30413.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProftaakRH", "ProftaakRH.csproj", "{0F053CC5-D969-4970-9501-B3428EA3D777}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientApp", "..\ClientApp\ClientApp.csproj", "{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Util", "..\Hashing\Util.shproj", "{70277749-D423-4871-B692-2EFC5A6ED932}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProftaakRH", "ProftaakRH.csproj", "{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RH-Engine", "..\RH-Engine\RH-Engine.csproj", "{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "..\Server\Server.csproj", "{7D751284-17E8-434C-A7F6-2EB37572E7AE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DoctorApp", "..\DoctorApp\DoctorApp.csproj", "{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestRH", "..\UnitTestRH\UnitTestRH.csproj", "{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}"
ProjectSection(ProjectDependencies) = postProject
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B} = {BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}
{7D751284-17E8-434C-A7F6-2EB37572E7AE} = {7D751284-17E8-434C-A7F6-2EB37572E7AE}
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F} = {7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994} = {A232F2D5-AF98-4777-BF3A-FBDDFBC02994}
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3} = {C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}
EndProjectSection
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\Hashing\Hashing.projitems*{0b6ccc1d-5e76-420e-b54d-eb3e5ffea6cb}*SharedItemsImports = 5
..\Hashing\Hashing.projitems*{70277749-d423-4871-b692-2efc5a6ed932}*SharedItemsImports = 13
..\Hashing\Hashing.projitems*{7d751284-17e8-434c-a7f6-2eb37572e7ae}*SharedItemsImports = 5
..\Hashing\Hashing.projitems*{7ef854c1-73eb-4099-a7d7-057cceee6f8f}*SharedItemsImports = 5
..\Hashing\Hashing.projitems*{a232f2d5-af98-4777-bf3a-fbddfbc02994}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0F053CC5-D969-4970-9501-B3428EA3D777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F053CC5-D969-4970-9501-B3428EA3D777}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.Build.0 = Release|Any CPU
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}.Release|Any CPU.Build.0 = Release|Any CPU
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}.Release|Any CPU.Build.0 = Release|Any CPU
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}.Release|Any CPU.Build.0 = Release|Any CPU
{7D751284-17E8-434C-A7F6-2EB37572E7AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D751284-17E8-434C-A7F6-2EB37572E7AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D751284-17E8-434C-A7F6-2EB37572E7AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D751284-17E8-434C-A7F6-2EB37572E7AE}.Release|Any CPU.Build.0 = Release|Any CPU
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Release|Any CPU.Build.0 = Release|Any CPU
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Some files were not shown because too many files have changed in this diff Show More