-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/web app organization #216
base: develop
Are you sure you want to change the base?
Changes from all commits
a424482
a38726f
4f7f30c
a5e0cb0
e29187c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var Poseidon = require('../app.js'); | ||
|
||
var power = Poseidon.HardwareFactory.createPowerManager(); | ||
|
||
setTimeout(function() { | ||
power.exit(); | ||
process.exit(); | ||
}, 10000); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var Config = require('./config.json'); | ||
var Ports = require('./Sockets/Ports.json'); | ||
var Sockets = require('./Sockets'); | ||
var Peripherals = require('./CppInterface/PeripheralsProcess.js'); | ||
var HardwareFactory = require('./CppInterface/Factory.js'); | ||
var Vision = require('./VisionInterface'); | ||
|
||
var server = Sockets.createSocket(Ports.DispatcherPort); | ||
var logServer = Sockets.createSocket(Ports.LoggerPort); | ||
var hardwareFactory = new HardwareFactory(server, logServer); | ||
var visionFactory = new Vision.Factory(); | ||
|
||
if(Config.appStartMode === "auto") { | ||
Peripherals.initialize(); | ||
} | ||
else { | ||
console.log("Entering manual mode: run './Periphers --dispatcherPort="+ | ||
Ports.DispatcherPort+" --loggerPort="+Ports.LoggerPort+"'"); | ||
} | ||
|
||
module.exports = { | ||
HardwareFactory: hardwareFactory, | ||
VisionFactory: visionFactory | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"appStartMode":"manual" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
appStartMode: | ||
manual - The js app is started seperately from the c++ app. (The user must | ||
manualy start the c++ app after starting the js app.) | ||
auto - The js app starts concurrently with the c++ app as if they were | ||
one. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
var fileSystem = require('fs'); | ||
var path = require("path"); | ||
var Poseidon = require('../Brain/app.js'); | ||
|
||
var WebLogger = require('./WebLogger'); | ||
var FileLogger = require('./FileLogger'); | ||
|
||
var fileLogger = new FileLogger("./test.log"); | ||
var webLogger = new WebLogger(fileLogger); | ||
|
||
var thrustController = Poseidon.HardwareFactory.createThrustController(); | ||
var powerManager = Poseidon.HardwareFactory.createPowerManager(); | ||
var imuSensor = Poseidon.HardwareFactory.createImuSensor(); | ||
var headLights = Poseidon.HardwareFactory.createHeadlights(); | ||
|
||
function DMSG(x) { | ||
console.log(x); | ||
} | ||
|
||
module.exports = { | ||
pullWebLog: function() { | ||
return webLogger.pull(); | ||
}, | ||
|
||
move: function(value) { | ||
DMSG("Moving: " + value); | ||
thrustController.move(value); | ||
}, | ||
dive: function(value) { | ||
DMSG("Diving: " + value); | ||
thrustController.dive(value); | ||
}, | ||
secondaryDive: function(value) { | ||
DMSG("Diving2: " + value); | ||
thrustController.secondaryDive(value); | ||
}, | ||
yaw: function(value) { | ||
DMSG("Yawing: " + value); | ||
thrustController.yaw(value); | ||
}, | ||
pitch: function(value) { | ||
DMSG("Pitching: " + value); | ||
thrustController.pitch(value); | ||
}, | ||
roll: function(value) { | ||
DMSG("Rolling: " + value); | ||
thrustController.roll(value); | ||
}, | ||
goDirection: function(move, dive, dive2) { | ||
DMSG("Go Direction: " + move + ", " + dive2 + ", " + dive); | ||
thrustController.goDirection(move, dive2, dive); | ||
}, | ||
rotate: function(yaw, pitch, roll) { | ||
DMSG("Rotate: " + yaw + ", " + pitch + ", " + roll); | ||
thrustController.rotate(yaw, pitch, roll); | ||
}, | ||
killThrust: function() { | ||
DMSG("Kill Thrusters"); | ||
thrustController.kill(); | ||
}, | ||
|
||
turnOnImu: function() { | ||
powerManager.turnOnImu(); | ||
}, | ||
turnOffImu: function() { | ||
powerManager.turnOffImu(); | ||
}, | ||
getAcceleration: function() { | ||
imuSensor.getAcceleration().done(function(accel) { | ||
webLogger.info("Acceleration: " + JSON.stringify(accel)); | ||
}); | ||
}, | ||
getAngularAcceleration: function() { | ||
imuSensor.getAngularAcceleration().done(function(accel) { | ||
webLogger.info("Angular Acceleration: " + JSON.stringify(accel)); | ||
}); | ||
}, | ||
getHeading: function() { | ||
imuSensor.getHeading().done(function(heading) { | ||
webLogger.info("Heading: " + JSON.stringify(heading)); | ||
}); | ||
}, | ||
getInternalTemperature: function() { | ||
imuSensor.getInternalTemperature().done(function(temperature) { | ||
webLogger.info("Internal Temperature: " + JSON.stringify(temperature)); | ||
}); | ||
}, | ||
getExternalTemperature: function() { | ||
imuSensor.getExternalTemperature().done(function(temperature) { | ||
webLogger.info("External Temperature: " + JSON.stringify(temperature)); | ||
}); | ||
}, | ||
getInternalPressure: function() { | ||
imuSensor.getInternalPressure().done(function(pressure) { | ||
webLogger.info("Internal Pressure: " + JSON.stringify(pressure)); | ||
}); | ||
}, | ||
getExternalPressure: function() { | ||
imuSensor.getExternalPressure().done(function(pressure) { | ||
webLogger.info("External Pressure: " + JSON.stringify(pressure)); | ||
}); | ||
}, | ||
|
||
exit: function() { | ||
powerManager.exit(); | ||
process.exit(); | ||
}, | ||
|
||
turnOnEscs: function() { | ||
DMSG("Turn On Escs"); | ||
powerManager.turnOnEscs(); | ||
}, | ||
turnOffEscs: function() { | ||
DMSG("Turn Off Escs"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a logger. Use it. Also, this type of psuedo-macro looking naming does not feel appropriate for JavaScript. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was temporary (DMSG) - I forgot to delete it. |
||
powerManager.turnOffEscs(); | ||
}, | ||
|
||
toggleLights: function() { | ||
DMSG("Toggle Lights"); | ||
headLights.toggleLights(); | ||
}, | ||
|
||
runScript: function(index) { | ||
fileSystem.readdir("./TestScripts", function (err, fileNames) { | ||
if(fileNames[index]) { | ||
var filePath = path.resolve("TestScripts", fileNames[index]); | ||
if(require.cache[filePath]) delete require.cache[filePath]; | ||
var script = require(filePath); | ||
script.execute(thrustController, imuSensor, webLogger, headLights, powerManager); | ||
return ('ran ' + fileNames[index]); | ||
} | ||
else { | ||
return ('script not found'); | ||
} | ||
}) | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is breaking encapsulation. These sockets should have been left inside the Factory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to disagree. App.js (while improperly named) is a form of "builder" design pattern. (The builder design pattern is one of the 23 discussed by the Gang of Four.)
A builder will take advantage of factories to create more complex objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I will admit that this builder module does need to be better organized.