Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
akru committed Jan 8, 2016
2 parents 9ce252a + 47da6cd commit 1f29186
Show file tree
Hide file tree
Showing 64 changed files with 2,901 additions and 41 deletions.
34 changes: 34 additions & 0 deletions Ethereum smart contracts/example/motherbase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
contract motherbase {
address creator;
int256 public homebaseLongitude;
int256 public homebaseLatitude;
mapping (address => bool) droneActiveOf;
address public airwayAdminAddr;


modifier creatorCheck { if (msg.sender == creator) _ }

/* Functions */
function motherbase(int256 _homebaseLongitude,
int256 _homebaseLatitude,
address _airwayAdminAddr) {
creator = msg.sender;
homebaseLatitude = _homebaseLatitude;
homebaseLongitude = _homebaseLongitude;
airwayAdminAddr = _airwayAdminAddr;
}

function setDrone(address _droneAddr) creatorCheck returns(bool result) {
droneActiveOf[_droneAddr] = true;
result true;
}

function inactiveDrone(address _droneAddr) creatorCheck returns(bool result) {
droneActiveOf[_droneAddr] = false;
result true;
}




}
9 changes: 6 additions & 3 deletions ROS/aira_ros_bridge/lib/aira_bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ var ROSMSG = require('./rosmsg');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));

var ros = new ROSLIB.Ros({url : 'ws://localhost:9090'});
ros.on('connection', function() {console.log('Connected to websocket server.')});
var ros;

/*** Functions ***/
function topicOn(accessor, contract_abi, fun) {
Expand All @@ -32,7 +31,11 @@ function topicOn(accessor, contract_abi, fun) {
}
}

function bridge(contract_address) {
function bridge(contract_address, port) {
/* Init ROS connection instance */
ros = new ROSLIB.Ros({url : 'ws://localhost:'+port});
ros.on('connection', function() {console.log('Connected to websocket server.')});

/* Load publishers */
var ros_contract = web3.eth.contract(ABI.ros_compatible).at(contract_address);

Expand Down
51 changes: 51 additions & 0 deletions ROS/aira_ros_bridge/lib/msg/dron_common_msgs/RouteRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Init libs
var ROSLIB = require('roslib');
var Helpers = require('../helpers');
var SatFix = require('../dron_common_msgs/SatFix');
// Solidity message definition
var bytecode = '606060405260405161016f38038061016f83398101604052805160805191019060605182516000805482825581805290927f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563918201929190608001821560bc579160200282015b8281111560bc5782518254600160a060020a03191617825560209290920191600191909101906066565b505080600160006101000a81548163ffffffff021916908302179055505050608c806100e36000396000f35b5060909291505b8082111560df578054600160a060020a031916815560010160c3565b509056606060405260e060020a6000350463af640d0f81146024578063b8a24252146032575b005b608260015463ffffffff1681565b60826004356000805482908110156002575080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563015473ffffffffffffffffffffffffffffffffffffffff1681565b6060908152602090f3';
var abi = [{"constant":true,"inputs":[],"name":"id","outputs":[{"name":"","type":"uint32"}],"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"checkpoints","outputs":[{"name":"","type":"address"}],"type":"function"},{"inputs":[{"name":"_checkpoints","type":"address[]"},{"name":"_id","type":"uint32"}],"type":"constructor"}];
// JSON message converter
function eth2json(address, web3) {
var msg = Helpers.getContract(abi, address, web3);
var route = [];
var ix = 0;
while (msg.checkpoints(ix) != "0x")
route.push(SatFix.eth2json(msg.checkpoints(ix++), web3));
return {
// Message fields START
id: parseInt(msg.id()),
checkpoints: route
// Message fields END
}
}
function mkArray(arr, obj, web3, fn) {
var count = 0;
arr.forEach(function(e, i, a) {
obj.ros2eth(e, web3, function(err, r) {
arr[i] = r;
++count;
});
});
while (count != arr.length);
return arr;
}
// Setup exports
module.exports = {
/*
* This message converter should be autogenerated from
* ROS message definition language.
* TODO: converter implementation.
*/
abi: abi,
eth2json: eth2json,
eth2ros: function(msg, web3) {return new ROSLIB.Message(eth2json(msg, web3))},
ros2eth: function(msg, web3, fun) {
var id = msg.id;

mkArray(msg.checkpoints, SatFix, web3, function(checkpoints) {
var args = [id, checkpoints];
Helpers.newContract(abi, bytecode, web3, args, fun);
});
}
}
62 changes: 62 additions & 0 deletions ROS/aira_ros_bridge/lib/msg/dron_common_msgs/RouteResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Init libs
var ROSLIB = require('roslib');
var Helpers = require('../helpers');
var SatFix = require('../dron_common_msgs/SatFix');
// Solidity message definition
var bytecode = '606060405260405161019038038061019083398101604052805160805160a051919290910160a05160008054610100850264ffffffff001960ff1990921687179190911617815582516001805482825592819052927fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf69283019290608001821560c2579160200282015b8281111560c25782518254600160a060020a03191617825560209290920191908401906089565b505050505060a8806100e86000396000f35b5060b09291505b8082111560e4578054600160a060020a0319168155830160c9565b509056606060405260e060020a6000350463af640d0f8114602e578063b980c78f146042578063c1991219146093575b005b609e60005463ffffffff6101009091041681565b609e600435600180548290811015600257506000527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6015473ffffffffffffffffffffffffffffffffffffffff1681565b609e60005460ff1681565b6060908152602090f3';
var abi = [{"constant":true,"inputs":[],"name":"id","outputs":[{"name":"","type":"uint32"}],"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"route","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":true,"inputs":[],"name":"valid","outputs":[{"name":"","type":"bool"}],"type":"function"},{"inputs":[{"name":"_valid","type":"bool"},{"name":"_id","type":"uint32"},{"name":"_route","type":"address[]"}],"type":"constructor"}];
// JSON message converter
function eth2json(address, web3) {
var msg = Helpers.getContract(abi, address, web3);
var route = [];
var val = true;
var ix = 0;
while (msg.route(ix) != "0x")
route.push(SatFix.eth2json(msg.route(ix++), web3));
if (msg.valid() == "False")
val = false; // TODO: check
return {
// Message fields START
valid: val,
id: parseInt(msg.id()),
route: route
// Message fields END
}
}
function mkArray(arr, obj, web3, fn) {
var count = 0;
arr.forEach(function(e, i, a) {
console.log("Make new message: " + i);
obj.ros2eth(e, web3, function(err, r) {
arr[i] = r;
++count;
console.log("Message created: " + i);
});
});
setTimeout(function cb() {
if (count == arr.length)
fn(arr);
else
setTimeout(cb, 1000);
}, 1000);
}
// Setup exports
module.exports = {
/*
* This message converter should be autogenerated from
* ROS message definition language.
* TODO: converter implementation.
*/
abi: abi,
eth2json: eth2json,
eth2ros: function(msg, web3) {return new ROSLIB.Message(eth2json(msg, web3))},
ros2eth: function(msg, web3, fun) {
var valid = msg.valid;
var id = msg.id;

mkArray(msg.route, SatFix, web3, function(route) {
var args = [valid, id, route];
Helpers.newContract(abi, bytecode, web3, args, fun);
});
}
}
35 changes: 35 additions & 0 deletions ROS/aira_ros_bridge/lib/msg/dron_common_msgs/SatFix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Init libs
var ROSLIB = require('roslib');
var Helpers = require('../helpers');
// Solidity message definition
var bytecode = '6060604052604051606080608683395060c06040525160805160a05160009283556001919091556002556050908190603690396000f3606060405260e060020a60003504634fd7d76a8114602e578063589af69c146036578063d906896a14603e575b005b604660005481565b604660015481565b604660025481565b6060908152602090f3';
var abi = [{"constant":true,"inputs":[],"name":"latitude","outputs":[{"name":"","type":"int256"}],"type":"function"},{"constant":true,"inputs":[],"name":"longitude","outputs":[{"name":"","type":"int256"}],"type":"function"},{"constant":true,"inputs":[],"name":"altitude","outputs":[{"name":"","type":"int256"}],"type":"function"},{"inputs":[{"name":"_latitude","type":"int256"},{"name":"_longitude","type":"int256"},{"name":"_altitude","type":"int256"}],"type":"constructor"}];
// JSON message converter
function eth2json(address, web3) {
var msg = Helpers.getContract(abi, address, web3);
return {
// Message fields START
latitude: parseInt(msg.latitude()) / 1000000.0,
longitude: parseInt(msg.longitude()) / 1000000.0,
altitude: parseInt(msg.altitude()) / 1000000.0
// Message fields END
};
}
// Setup exports
module.exports = {
/*
* This message converter should be autogenerated from
* ROS message definition language.
* TODO: converter implementation.
*/
abi: abi,
eth2json: eth2json,
eth2ros: function(address, web3) {return new ROSLIB.Message(eth2json(address, web3))},
ros2eth: function(msg, web3, fun) {
var latitude = msg.latitude * 1000000;
var longitude = msg.longitude * 1000000;
var altitude = msg.altitude * 1000000;
var args = [latitude, longitude, altitude];
Helpers.newContract(abi, bytecode, web3, args, fun);
}
}
8 changes: 7 additions & 1 deletion ROS/aira_ros_bridge/lib/msg/std_msgs/Int64.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ var Helpers = require('../helpers');
// Solidity data
var bytecode = '60606040526040516020806085833950608060405251600080547801000000000000000000000000000000000000000000000000808402046001604060020a03199091161790555060328060536000396000f3606060405260e060020a600035046373d4a13a8114601a575b005b602560005460070b81565b60070b6060908152602090f3';
var abi = [{"constant":true,"inputs":[],"name":"data","outputs":[{"name":"","type":"int64"}],"type":"function"},{"inputs":[{"name":"_data","type":"int64"}],"type":"constructor"}];
// JSON serialization
function eth2json(address, web3) {
var msg = Helpers.getContract(abi, address, web3);
return {data: parseInt(msg.data())}
}
// Setup exports
module.exports = {
/*
Expand All @@ -12,7 +17,8 @@ module.exports = {
* TODO: converter implementation.
*/
abi: abi,
eth2ros: function(msg) {return new ROSLIB.Message({data: parseInt(msg.data())})},
eth2json: eth2json,
eth2ros: function(msg, web3) {return new ROSLIB.Message(eth2json(msg, web3))},
ros2eth: function(msg, web3, fun) {
//
var msg_data = msg.data;
Expand Down
8 changes: 7 additions & 1 deletion ROS/aira_ros_bridge/lib/msg/std_msgs/String.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ var Helpers = require('../helpers');
// Solidity data
var bytecode = '60606040526040516101d53803806101d5833981016040528051018060006000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10608d57805160ff19168380011785555b50607c9291505b8082111560ba57838155600101606b565b505050610117806100be6000396000f35b828001600101855582156064579182015b828111156064578251826000505591602001919060010190609e565b509056606060405260e060020a600035046373d4a13a811461001b575b005b6100766000805460806020601f6002600019610100600187161502019094169390930492830181900402810160405260608281529291908282801561010f5780601f106100e45761010080835404028352916020019161010f565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156100d65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b820191906000526020600020905b8154815290600101906020018083116100f257829003601f168201915b50505050508156';
var abi = [{"constant":true,"inputs":[],"name":"data","outputs":[{"name":"","type":"string"}],"type":"function"},{"inputs":[{"name":"_data","type":"string"}],"type":"constructor"}];
function eth2json(address, web3) {
var msg = Helpers.getContract(abi, address, web3);
return {data: msg.data()}
}

// Setup exports
module.exports = {
/*
Expand All @@ -12,7 +17,8 @@ module.exports = {
* TODO: converter implementation.
*/
abi: abi,
eth2ros: function(msg) {return new ROSLIB.Message({data: msg.data()})},
eth2json: eth2json,
eth2ros: function(msg, web3) {return new ROSLIB.Message(eth2json(msg, web3))},
ros2eth: function(msg, web3, fun) {
var args = [msg.data];
Helpers.newContract(abi, bytecode, web3, args, fun);
Expand Down
29 changes: 29 additions & 0 deletions ROS/aira_ros_bridge/lib/msg/std_msgs/UInt32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Init libs
var ROSLIB = require('roslib');
var Helpers = require('../helpers');
// Solidity data
var bytecode = '606060405260405160208060638339506080604052516000805463ffffffff1916821790555060328060316000396000f3606060405260e060020a600035046373d4a13a8114601a575b005b602860005463ffffffff1681565b6060908152602090f3';
var abi = [{"constant":true,"inputs":[],"name":"data","outputs":[{"name":"","type":"uint32"}],"type":"function"},{"inputs":[{"name":"_data","type":"uint32"}],"type":"constructor"}];
// JSON serialization
function eth2json(address, web3) {
var msg = Helpers.getContract(abi, address, web3);
return {data: parseInt(msg.data())}
}
// Setup exports
module.exports = {
/*
* This message converter should be autogenerated from
* ROS message definition language.
* TODO: converter implementation.
*/
abi: abi,
eth2json: eth2json,
eth2ros: function(msg, web3) {return new ROSLIB.Message(eth2json(msg, web3))},
ros2eth: function(msg, web3, fun) {
//
var msg_data = msg.data;
var args = [msg_data];
//
Helpers.newContract(abi, bytecode, web3, args, fun);
}
}
4 changes: 2 additions & 2 deletions ROS/aira_ros_bridge/start.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (process.argv.length < 3)
console.log("Usage: " + process.argv[0] + " " + process.argv[1] + " ADDRESS");
console.log("Usage: " + process.argv[0] + " " + process.argv[1] + " CONTRACT_ADDRESS BRIDGE_PORT");
else
require('./lib/aira_bridge')(process.argv[2])
require('./lib/aira_bridge')(process.argv[2], process.argv[3])
Loading

0 comments on commit 1f29186

Please sign in to comment.