Skip to content
This repository was archived by the owner on Mar 8, 2021. It is now read-only.

Commit 2ec7e39

Browse files
committed
new version
1 parent 42487a6 commit 2ec7e39

File tree

8 files changed

+76
-349
lines changed

8 files changed

+76
-349
lines changed

del/new.js

-18
This file was deleted.

del/test.js

-25
This file was deleted.

del/test2.js

-95
This file was deleted.

index.js main.js

+48-77
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*
2-
Include das Express Modul
2+
Express Modul eingebunden (stellt für den Webserver statische Dateien bereit )
33
*/
44
var express = require("express")
55
, app = express();
66

77
/*
8-
Include das HTTP Modul
8+
HTTP Modul eingebunden (stellt Webserverdienste bereit, Zur deklaration eines Ports verwendet)
99
*/
1010
var server = require("http").createServer(app);
1111

1212
/*
13-
Include das Socket Modul
13+
Socket Modul eingebunden (ermöglicht Kommunikation zwischen Webinterface und main.js. Informationsübermittlung via Socket Event)
1414
*/
15-
var io = require("socket.io")(server);
15+
var io = require("socket.io")(server);
1616

1717
/*
18-
Include das MIP Modul
18+
MIP Modul eingebunden (SDK beinhaltet Funktionen und Definitionen zur Bluetoothansteuerung des MIP und seiner Bestandteile)
1919
*/
2020
var mip = require("wowweemip")
2121
, mipFinder = new mip.Finder()
@@ -24,37 +24,45 @@ var mip = require("wowweemip")
2424
/*
2525
Definitionen
2626
*/
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?
2929

30-
function Bot(bot)
30+
/*
31+
Object: Bot
32+
*/
33+
function Bot(bot) //Funktion zur Abfrage von verfügbaren MIPs
3134
{
3235
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
3739
this.connectErrorMsg = "";
3840
};
3941

42+
/*
43+
Funktion: Funktion zum erstellen eines Arrays, welches die Daten der gefundenen MIPs beinhaltet
44+
*/
4045
function getRobotlist()
4146
{
4247
var returnArray = new Array();
4348
for(var bot of Robots)
4449
{
4550
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
4853
returnArray.push(infoArray);
4954
};
5055
return JSON.stringify(returnArray);
5156
};
5257

58+
/*
59+
Funktion: Funktion zur Abfrage des Verbindungsstatus des MIP
60+
*/
5361
function getConnectStatus(bot)
5462
{
5563
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
5866
return JSON.stringify(returnArray);
5967
};
6068

@@ -70,27 +78,27 @@ server.listen(PORT);
7078
app.use(express.static(__dirname + '/web'));
7179

7280
/*
73-
Socket
81+
Socket (für die Kommunikation zwischen Webinterface und main.js)
7482
*/
7583
io.sockets.on('connection', function(socket) {
7684
// Socket um Farbe zu ändern
7785
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
7987
});
8088

81-
// Socket um Farbe zu ändern
89+
// Socket um Sound abzuspielen
8290
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
8492
});
8593

86-
// Socket Drive
94+
// Socket zum Fahren
8795
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
8997
});
9098

91-
// Socket Direction
99+
// Socket für Fahrrichtung
92100
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.
94102
});
95103

96104
// Socket mit vorhandenen Botnamen
@@ -102,40 +110,40 @@ io.sockets.on('connection', function(socket) {
102110
{
103111
if(DEBUG)
104112
{
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
106114
};
107115
if(bot.getBotId == id)
108116
{
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
111119
{
112120
if(DEBUG)
113121
{
114-
console.log("--> Connect failed: "+err);
115-
};
122+
console.log("--> Connect failed: "+err); //Konsole gibt aus: "--> Connect failed: " und Fehlercode
123+
};
116124
bot.connectErrorMsg = err;
117125
socket.emit('getConnectStatus', getConnectStatus(bot));
118126
return;
119127
};
120128

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!"
124132
console.log('----------------------------------------------------------------');
125133
};
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
128136

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
131139
{
132140
console.log(err);
133141
return;
134142
};
135143

136144
ConnectedBot.bot.convertMiPResponse(data, function(command, arr)
137145
{
138-
if(DEBUG)
146+
if(DEBUG) //Empfangen -> Gibt aus, was empfangen wurde
139147
{
140148
console.log("--> "+command+": "+arr);
141149
};
@@ -151,53 +159,14 @@ io.sockets.on('connection', function(socket) {
151159

152160
MiPRobot.prototype.readMipHardwareVersion.call(ConnectedBot.bot);
153161
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-
163162
socket.emit('getConnectStatus', getConnectStatus(bot));
164163
});
165164
};
166165
};
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-
197166
});
198167
});
199168

200-
169+
//gibt den folgenden Text in Konsole aus
201170
console.log('----------------------------------------------------------------');
202171
console.log('---> Studienprojekt MIP Control');
203172
console.log('----------------------------------------------------------------');
@@ -206,6 +175,8 @@ console.log('---> Entwickler: Lukas Gundermann');
206175
console.log('----------------------------------------------------------------');
207176
console.log('---> Server: http://localhost:'+PORT+'/');
208177
console.log('----------------------------------------------------------------');
178+
179+
//Funktion zum scannen nach verfügbaren Bluetoothverbindungen von MIPs
209180
mipFinder.scan(function(err, robots) {
210181
if (err != null)
211182
{

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "mip",
33
"version": "1.0.0",
44
"description": "",
5-
"main": "index.js",
5+
"main": "main.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},

0 commit comments

Comments
 (0)