var network = require('./network');
var peripheral = require('./bluetooth-peripheral');
var usb = require('./usb-peripheral');
var S4 = require('./s4');

var main_ble = function() {
  var ble = new peripheral.BluetoothPeripheral();
  var listener = new network.MessageListener(ble.notify);
  listener.start();
};

var main_usb = function(test_mode) {
  var broadcaster = new network.MessageBroadcaster();
  broadcaster.start();
  var rower = new S4();

  if (test_mode) {
    rower.fakeRower(broadcaster.send);
  } else {
    // monitor USB attach and detach
    var peripheral = new usb.UsbPeripheral();
    peripheral.monitor_wr(rower.startRower(broadcaster.send), rower.stopRower(rower));

    rower.findPort().then(function() {
      rower.startRower(broadcaster.send)();
    }, function() {
      console.log('[Init] Awaiting WaterRower S4.2 to be connected to USB port');
    });
  }
};

var main = function() {
  var mode = process.argv[2];
  if (mode === '--test' || mode === '--usb') {
    main_usb(mode === '--test');
  } else if (mode === '--ble') {
    main_ble();
  } else {
    // TODO: unified mode without UDP
    console.log("Integrated mode not implemented yet: use --test, --ble or --usb command line flags");
  }
};

main();

@@ -1,40 +1,34 @@
 var 
-network = require('./network');%0A
+main_ble = function() %7B%0A  
 var 
@@ -79,101 +79,46 @@
 ');%0A
+  
 var 
-usb = require('./usb-peripheral');%0Avar S4 = require('./s4');%0A%0Avar main_ble = function() %7B
+network = require('./network');%0A
 %0A  v
@@ -279,24 +279,132 @@
 est_mode) %7B%0A
+  var network = require('./network');%0A  var usb = require('./usb-peripheral');%0A  var S4 = require('./s4');%0A%0A
   var broadc
@@ -930,24 +930,592 @@
 %7D);%0A  %7D%0A%7D;%0A%0A
+var main_full = function() %7B%0A  var peripheral = require('./bluetooth-peripheral');%0A  var S4 = require('./s4');%0A  var usb = require('./usb-peripheral');%0A%0A  var ble = new peripheral.BluetoothPeripheral();%0A  var rower = new S4();%0A  // monitor USB attach and detach%0A  var peripheral = new usb.UsbPeripheral();%0A  peripheral.monitor_wr(rower.startRower(ble.notify), rower.stopRower(rower));%0A%0A  rower.findPort().then(function() %7B%0A    rower.startRower(ble.notify)();%0A  %7D, function() %7B%0A    console.log('%5BInit%5D Awaiting WaterRower S4.2 to be connected to USB port');%0A  %7D);%0A%0A%7D;%0A%0A
 var main = f
@@ -1704,142 +1704,18 @@
     
-// TODO: unified mode without UDP%0A    console.log(%22Integrated mode not implemented yet: use --test, --ble or --usb command line flags%22
+main_full(
 );%0A 

Add integrated mode