1
1
/*
2
- Include das Express Modul
2
+ Express Modul eingebunden (stellt für den Webserver statische Dateien bereit )
3
3
*/
4
4
var express = require ( "express" )
5
5
, app = express ( ) ;
6
6
7
7
/*
8
- Include das HTTP Modul
8
+ HTTP Modul eingebunden (stellt Webserverdienste bereit, Zur deklaration eines Ports verwendet)
9
9
*/
10
10
var server = require ( "http" ) . createServer ( app ) ;
11
11
12
12
/*
13
- Include das Socket Modul
13
+ Socket Modul eingebunden (ermöglicht Kommunikation zwischen Webinterface und main.js. Informationsübermittlung via Socket Event)
14
14
*/
15
- var io = require ( "socket.io" ) ( server ) ;
15
+ var io = require ( "socket.io" ) ( server ) ;
16
16
17
17
/*
18
- Include das MIP Modul
18
+ MIP Modul eingebunden (SDK beinhaltet Funktionen und Definitionen zur Bluetoothansteuerung des MIP und seiner Bestandteile)
19
19
*/
20
20
var mip = require ( "wowweemip" )
21
21
, mipFinder = new mip . Finder ( )
@@ -24,37 +24,45 @@ var mip = require("wowweemip")
24
24
/*
25
25
Definitionen
26
26
*/
27
- const PORT = 5000 ;
28
- const DEBUG = true ;
27
+ const PORT = 5000 ; //Der Port wurde als 5000 definiert, kann jedoch geändert werden
28
+ const DEBUG = true ; //Sollen Zusaetzliche Informationen in der Shellconsole angezeigt werden?
29
29
30
- function Bot ( bot )
30
+ /*
31
+ Object: Bot
32
+ */
33
+ function Bot ( bot ) //Funktion zur Abfrage von verfügbaren MIPs
31
34
{
32
35
this . bot = bot ;
33
-
34
- this . getBotId = bot . _peripheral . id ;
35
- this . getBotName = bot . name ;
36
- this . isConnected = false ;
36
+ this . getBotId = bot . _peripheral . id ; //Ließt MIP Identitätsnummer aus
37
+ this . getBotName = bot . name ; //Ließt MIP Name aus
38
+ this . isConnected = false ; //Setzt Verbindung auf false, MIP nicht verbunden
37
39
this . connectErrorMsg = "" ;
38
40
} ;
39
41
42
+ /*
43
+ Funktion: Funktion zum erstellen eines Arrays, welches die Daten der gefundenen MIPs beinhaltet
44
+ */
40
45
function getRobotlist ( )
41
46
{
42
47
var returnArray = new Array ( ) ;
43
48
for ( var bot of Robots )
44
49
{
45
50
infoArray = { } ;
46
- infoArray [ 'id' ] = bot . getBotId ;
47
- infoArray [ 'name' ] = bot . getBotName ;
51
+ infoArray [ 'id' ] = bot . getBotId ; //MIP ID
52
+ infoArray [ 'name' ] = bot . getBotName ; //MIP Name
48
53
returnArray . push ( infoArray ) ;
49
54
} ;
50
55
return JSON . stringify ( returnArray ) ;
51
56
} ;
52
57
58
+ /*
59
+ Funktion: Funktion zur Abfrage des Verbindungsstatus des MIP
60
+ */
53
61
function getConnectStatus ( bot )
54
62
{
55
63
var returnArray = { } ;
56
- returnArray [ 'success' ] = bot . isConnected ;
57
- returnArray [ 'msg' ] = bot . connectErrorMsg ;
64
+ returnArray [ 'success' ] = bot . isConnected ; //gibt 'success' aus, wenn MIP erfolgreich verbunden
65
+ returnArray [ 'msg' ] = bot . connectErrorMsg ; //gibt 'msg' (Fehlermeldung) aus wenn Verbindung fehlgeschlagen
58
66
return JSON . stringify ( returnArray ) ;
59
67
} ;
60
68
@@ -70,27 +78,27 @@ server.listen(PORT);
70
78
app . use ( express . static ( __dirname + '/web' ) ) ;
71
79
72
80
/*
73
- Socket
81
+ Socket (für die Kommunikation zwischen Webinterface und main.js)
74
82
*/
75
83
io . sockets . on ( 'connection' , function ( socket ) {
76
84
// Socket um Farbe zu ändern
77
85
socket . on ( 'setLed' , function ( r , g , b ) {
78
- MiPRobot . prototype . setMipChestLedWithColor . call ( ConnectedBot . bot , r , g , b , 0x00 ) ;
86
+ MiPRobot . prototype . setMipChestLedWithColor . call ( ConnectedBot . bot , r , g , b , 0x00 ) ; //setzt LED standardgemäß auf aus. Farbeinstellung erfolgt über Webinterface
79
87
} ) ;
80
88
81
- // Socket um Farbe zu ändern
89
+ // Socket um Sound abzuspielen
82
90
socket . on ( 'playSound' , function ( soundNumber ) {
83
- MiPRobot . prototype . playMipSound . call ( ConnectedBot . bot , soundNumber , 0 ) ;
91
+ MiPRobot . prototype . playMipSound . call ( ConnectedBot . bot , soundNumber , 0 ) ; //Ruft je nach Wahl den entsprechenden Sound auf
84
92
} ) ;
85
93
86
- // Socket Drive
94
+ // Socket zum Fahren
87
95
socket . on ( 'drive' , function ( cm ) {
88
- MiPRobot . prototype . driveDistanceByCm . call ( ConnectedBot . bot , cm , 0 ) ;
96
+ MiPRobot . prototype . driveDistanceByCm . call ( ConnectedBot . bot , cm , 0 ) ; //Fahrdistanz standardgemäß auf 0. Je nach Wahl wird die gewünschte Distanz übergeben und ausgeführt
89
97
} ) ;
90
98
91
- // Socket Direction
99
+ // Socket für Fahrrichtung
92
100
socket . on ( 'direction' , function ( degree ) {
93
- MiPRobot . prototype . driveDistanceByCm . call ( ConnectedBot . bot , 10 , degree ) ;
101
+ MiPRobot . prototype . driveDistanceByCm . call ( ConnectedBot . bot , 3 , degree ) ; //Fahrtrischtung in Grad. Auch über Webinterface einstellbar.
94
102
} ) ;
95
103
96
104
// Socket mit vorhandenen Botnamen
@@ -102,40 +110,40 @@ io.sockets.on('connection', function(socket) {
102
110
{
103
111
if ( DEBUG )
104
112
{
105
- console . log ( "--> Try to connect to: " + bot . getBotId ) ;
113
+ console . log ( "--> Try to connect to: " + bot . getBotId ) ; //schreibt ins Log, mit welchem MIP sich derzeit versucht wird zu verbinden
106
114
} ;
107
115
if ( bot . getBotId == id )
108
116
{
109
- mipFinder . connect ( bot . bot , function ( err ) {
110
- if ( err != null )
117
+ mipFinder . connect ( bot . bot , function ( err ) {
118
+ if ( err != null ) //Tritt ein Verbindungsfehler auf, wird folgende Anweisung aufgerufen
111
119
{
112
120
if ( DEBUG )
113
121
{
114
- console . log ( "--> Connect failed: " + err ) ;
115
- } ;
122
+ console . log ( "--> Connect failed: " + err ) ; //Konsole gibt aus: "--> Connect failed: " und Fehlercode
123
+ } ;
116
124
bot . connectErrorMsg = err ;
117
125
socket . emit ( 'getConnectStatus' , getConnectStatus ( bot ) ) ;
118
126
return ;
119
127
} ;
120
128
121
- if ( DEBUG )
122
- {
123
- console . log ( "--> Connect was successful!" ) ;
129
+ if ( DEBUG ) //War die Verbindung erfolgreich, wird folgende If Anweisung aufgerufen
130
+ {
131
+ console . log ( "--> Connect was successful!" ) ; //Konsolenlogeintrag "--> Connect was successful!"
124
132
console . log ( '----------------------------------------------------------------' ) ;
125
133
} ;
126
- bot . isConnected = true ;
127
- ConnectedBot = bot ;
134
+ bot . isConnected = true ; //Setzt Verbindungsstatus auf true (Verbunden)
135
+ ConnectedBot = bot ; //übergibt verbundenen Bot an Variable bot
128
136
129
- ConnectedBot . bot . enableBTReceiveDataNotification ( true , function ( err , data ) {
130
- if ( err )
137
+ ConnectedBot . bot . enableBTReceiveDataNotification ( true , function ( err , data ) { //Prüft ob gesendete Daten empfangen wurden
138
+ if ( err ) //Nicht empfangen -> Fehler
131
139
{
132
140
console . log ( err ) ;
133
141
return ;
134
142
} ;
135
143
136
144
ConnectedBot . bot . convertMiPResponse ( data , function ( command , arr )
137
145
{
138
- if ( DEBUG )
146
+ if ( DEBUG ) //Empfangen -> Gibt aus, was empfangen wurde
139
147
{
140
148
console . log ( "--> " + command + ": " + arr ) ;
141
149
} ;
@@ -151,53 +159,14 @@ io.sockets.on('connection', function(socket) {
151
159
152
160
MiPRobot . prototype . readMipHardwareVersion . call ( ConnectedBot . bot ) ;
153
161
MiPRobot . prototype . readMipFirmwareVersion . call ( ConnectedBot . bot ) ;
154
- //ConnectedBot.bot.readMipVolumeLevel;
155
- /*ConnectedBot.bot.readMipStatus(function(data)
156
- {
157
- console.log(data);
158
- });*/
159
- /*console.log(ConnectedBot.bot.(100, 0, function(err) {
160
- console.log("moving toward");
161
- }));*/
162
-
163
162
socket . emit ( 'getConnectStatus' , getConnectStatus ( bot ) ) ;
164
163
} ) ;
165
164
} ;
166
165
} ;
167
- /*var selectedRobot, mipFinder = new mip.Finder();
168
-
169
- for(var bot of Robots)
170
- {
171
- if(bot.Name == data)
172
- {
173
- selectedRobot = bot
174
- };
175
- };*/
176
- /*mipFinder.scan(function(err, robots) {
177
- console.log("GALL");
178
- if (err != null)
179
- {
180
- console.log(err);
181
- return;
182
- };
183
-
184
- for (var i in robots)
185
- {
186
- console.log(robots[i].name+" vs "+data);
187
- if(robots[i].name == data)
188
- {
189
- console.log(robots[i].name);
190
- mipFinder.connect(robots[i], function(err) {
191
- console.log(data);
192
- });
193
- };
194
- };
195
- });*/
196
-
197
166
} ) ;
198
167
} ) ;
199
168
200
-
169
+ //gibt den folgenden Text in Konsole aus
201
170
console . log ( '----------------------------------------------------------------' ) ;
202
171
console . log ( '---> Studienprojekt MIP Control' ) ;
203
172
console . log ( '----------------------------------------------------------------' ) ;
@@ -206,6 +175,8 @@ console.log('---> Entwickler: Lukas Gundermann');
206
175
console . log ( '----------------------------------------------------------------' ) ;
207
176
console . log ( '---> Server: http://localhost:' + PORT + '/' ) ;
208
177
console . log ( '----------------------------------------------------------------' ) ;
178
+
179
+ //Funktion zum scannen nach verfügbaren Bluetoothverbindungen von MIPs
209
180
mipFinder . scan ( function ( err , robots ) {
210
181
if ( err != null )
211
182
{
0 commit comments