private IEnumerator processDevices() { while (true) { scandata nextscan; while (CallbackQueue.ScanQueue.TryDequeue(out nextscan)) { updateView.postUpdate(new BleDevice(nextscan)); } statusreport nextStatus; while (CallbackQueue.StatusQueue.TryDequeue(out nextStatus)) { if (nextStatus.deviceState == (int)ConnectedDevice.state.interval_changing && !connectedDeviceMac.ContainsKey(nextStatus.deviceHandle)) { StringBuilder mac = new StringBuilder(); int bleDevice; EnfluxVRSuit.getDeviceStatus(nextStatus.deviceHandle, mac, out bleDevice); connectedDeviceMac.Add(nextStatus.deviceHandle, mac.ToString()); } if (connectedDeviceMac.ContainsKey(nextStatus.deviceHandle)) { updateView.postUpdate(new ConnectedDevice( nextStatus, connectedDeviceMac[nextStatus.deviceHandle])); } else { updateView.postUpdate(new ConnectedDevice(nextStatus)); } } yield return(null); } }
/** * parse friendly name to find COM port * pass COM port in to connect * */ public void attachPort(string friendlyName) { if (operatingState == ConnectionState.NONE || operatingState == ConnectionState.DETACHED) { System.Text.RegularExpressions.Regex toComPort = new System.Text.RegularExpressions.Regex(@".? \((COM\d+)\)$"); if (toComPort.IsMatch(friendlyName.ToString())) { StringBuilder comName = new StringBuilder() .Append(toComPort.Match(friendlyName.ToString()).Groups[1].Value); Debug.Log(comName); attachedPort = new AttachedPort(); if (EnfluxVRSuit.attachSelectedPort(comName, attachedPort) < 1) { operatingState = ConnectionState.ATTACHED; scanUpdater.StartScanning(); } else { Debug.Log("Error while trying to attach to port: " + comName); } } } else { Debug.Log("Unable to attach, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
public void disconnectEnflux() { if (operatingState == ConnectionState.CONNECTED) { StringBuilder returnBuffer = new StringBuilder(EnfluxVRSuit.MESSAGESIZE); if (EnfluxVRSuit.disconnect(connectedDevices.Count, returnBuffer) < 1) { Debug.Log("Devices disconnecting"); operatingState = ConnectionState.DISCONNECTED; //scanUpdater.StartScanning(); } else { Debug.Log(returnBuffer); } } if (operatingState == ConnectionState.DISCONNECTED) { // Already disconnected. } else { Debug.Log("Unable to disconnect, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
/* * INPUT: None * OUTPUT: None * * SUMMARY: Checks for correct operational state, then attempts * to detach from COM port * * ATTACH SUCCEED: update operational state, stop scanning for devices * ATTACH FAIL: state unchanged, prints error message to debug log * * RETURNS: NONE */ public void detachPort() { StringBuilder returnBuffer = new StringBuilder(EnfluxVRSuit.MESSAGESIZE); if (operatingState == ConnectionState.ATTACHED || operatingState == ConnectionState.DISCONNECTED || operatingState == ConnectionState.CONNECTED) { if (EnfluxVRSuit.detachPort(returnBuffer) < 1) { operatingState = ConnectionState.DETACHED; Debug.Log(returnBuffer); scanUpdater.StopScanning(); } else { Debug.Log(returnBuffer); } } else { Debug.Log("Unable to detach from port, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
//api expects input of all address to connect to, seperated by comma //example format: XX:XX:XX:XX:XX:XX,YY:YY:YY:YY:YY:YY public void connectEnflux(List <string> devices) { StringBuilder apiArg = new StringBuilder(); for (int device = 0; device < devices.Count; device++) { apiArg.Append(devices[device]); if (device < (devices.Count - 1)) { apiArg.Append(","); } } if (operatingState == ConnectionState.ATTACHED || operatingState == ConnectionState.DISCONNECTED) { StringBuilder returnBuffer = new StringBuilder(EnfluxVRSuit.MESSAGESIZE); if (EnfluxVRSuit.connect(apiArg, devices.Count, returnBuffer) < 1) { connectedDevices = devices; operatingState = ConnectionState.CONNECTED; Debug.Log("Devices connecting"); } else { Debug.Log(returnBuffer); } } else { Debug.Log("Unable to connect to devices, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
public void disableAnimate() { if (operatingState == ConnectionState.STREAMING) { StringBuilder returnBuffer = new StringBuilder(EnfluxVRSuit.MESSAGESIZE); //read and set mode streamWriter.WriteLine("stop"); streamWriter.Flush(); if (EnfluxVRSuit.stopRealTime(connectedDevices.Count, returnBuffer) < 1) { operatingState = ConnectionState.CONNECTED; clearStream(); //stop animation mode orientationAngles.setMode(0); serverState = ServerState.STARTED; } else { Debug.Log(returnBuffer); } } else { Debug.Log("Unable to stop stream, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
/* * INPUT: Friendly name of COM port where dongle is located * OUTPUT: None * * SUMMARY: Checks for correct operational state, * gets COMX location from input, and attempts to * attach to the port * * ATTACH SUCCEED: update operational state, start processing scan results * ATTACH FAIL: state unchanged, prints error message to debug log * * RETURNS: NONE */ public void attachPort(string friendlyName) { if (operatingState == ConnectionState.NONE || operatingState == ConnectionState.DETACHED) { StringBuilder comName = EnfluxUtils.parseFriendlyName(friendlyName); if (comName != null) { StringBuilder returnBuffer = new StringBuilder(EnfluxVRSuit.MESSAGESIZE); if (EnfluxVRSuit.attachSelectedPort(comName, returnBuffer) < 1) { operatingState = ConnectionState.ATTACHED; scanUpdater.StartScanning(); } else { Debug.Log(returnBuffer); } } } else { Debug.Log("Unable to attach, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
public void RefreshPorts() { StringBuilder returnBuffer = new StringBuilder(EnfluxVRSuit.MESSAGESIZE); EnfluxVRSuit.scanPortNames(returnBuffer); _ports.Clear(); if (returnBuffer != null) { _ports.Add(returnBuffer.ToString()); } }
void Start() { RefreshPorts(); // required so that when socket server launches, does not pause Unity Application.runInBackground = true; StartCoroutine(launchServer()); orientationAngles = GameObject.Find("[EnfluxVRHumanoid]") .GetComponent <EVRHumanoidLimbMap>(); scanUpdater = GameObject.Find("ScanResultsUpdater").GetComponent <ScanResultsUpdater>(); EnfluxVRSuit.registerResponseCallbacks(callbacks); operatingState = ConnectionState.NONE; }
public void calibrateDevices() { if (operatingState == ConnectionState.CONNECTED) { if (EnfluxVRSuit.performCalibration(connectedDevices.Count) < 1) { operatingState = ConnectionState.CALIBRATING; } else { Debug.Log("Problem running calibration"); } } else { Debug.Log("Unable to calibrate, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
public void finishCalibration() { if (operatingState == ConnectionState.CALIBRATING) { if (EnfluxVRSuit.finishCalibration(connectedDevices.Count) < 1) { operatingState = ConnectionState.CONNECTED; } else { Debug.Log("Problem occured during calibration"); } } else { Debug.Log("Unable to stop calibration, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
public void detachPort() { if (operatingState == ConnectionState.ATTACHED || operatingState == ConnectionState.DISCONNECTED) { if (EnfluxVRSuit.detachPort() < 1) { operatingState = ConnectionState.DETACHED; scanUpdater.StopScanning(); } else { Debug.Log("Error occured while detaching"); } } else { Debug.Log("Unable to detach from port, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
public void enableAnimate(bool record) { if (operatingState == ConnectionState.CONNECTED) { if (EnfluxVRSuit.streamRealTime(connectedDevices.Count, record) < 1) { operatingState = ConnectionState.STREAMING; StartCoroutine(readAngles()); } else { Debug.Log("Error, no devices to animate"); } } else { Debug.Log("Unable to stream, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
public void finishCalibration() { if (operatingState == ConnectionState.CALIBRATING) { StringBuilder returnBuffer = new StringBuilder(EnfluxVRSuit.MESSAGESIZE); if (EnfluxVRSuit.finishCalibration(connectedDevices.Count, returnBuffer) < 1) { operatingState = ConnectionState.CONNECTED; } else { Debug.Log(returnBuffer); } } else { Debug.Log("Unable to stop calibration, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
void OnApplicationQuit() { //Just in case some steps were skipped Debug.Log("Making sure things are closed down"); // Make sure sensors are disconnected, port is detached, // and client connection closed if (operatingState != ConnectionState.NONE || operatingState != ConnectionState.DETACHED || operatingState != ConnectionState.DISCONNECTED) { if (operatingState == ConnectionState.STREAMING) { disableAnimate(); } disconnectEnflux(); } if (operatingState != ConnectionState.NONE && operatingState != ConnectionState.DETACHED) { StringBuilder returnBuffer = new StringBuilder(EnfluxVRSuit.MESSAGESIZE); EnfluxVRSuit.detachPort(returnBuffer); } if (client != null) { client.Close(); } if (serverState != ServerState.CLOSED) { #if !NO_APPLICATION serverProcess.Kill(); #endif } EnfluxVRSuit.unregisterResponseCallbacks(); }
public void disconnectEnflux() { if (operatingState == ConnectionState.CONNECTED) { if (EnfluxVRSuit.disconnect(connectedDevices.Count) < 1) { Debug.Log("Devices disconnected"); client.Close(); operatingState = ConnectionState.DISCONNECTED; scanUpdater.StartScanning(); } else { Debug.Log("Problem disconnecting"); } } else { Debug.Log("Unable to disconnect, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
public void disableAnimate() { if (operatingState == ConnectionState.STREAMING) { if (EnfluxVRSuit.stopRealTime(connectedDevices.Count) < 1) { operatingState = ConnectionState.CONNECTED; clearStream(); //stop animation mode orientationAngles.setMode(0); serverState = ServerState.STARTED; } else { Debug.Log("Problem occured while stopping stream"); } } else { Debug.Log("Unable to stop stream, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
void OnApplicationQuit() { //Just in case some steps were skipped Debug.Log("Making sure things are closed down"); /** * Skips state check to be certain that port and background thread is * shutdown * */ if (operatingState != ConnectionState.NONE && operatingState != ConnectionState.DETACHED) { EnfluxVRSuit.detachPort(); } if (serverState != ServerState.CLOSED) { //todo: message from server confirming client disconnect //client.Close(); //todo: make this actually kill the process //currently just returns and error serverProcess.Kill(); } }
//api expects input of all address to connect to, seperated by comma //example format: XX:XX:XX:XX:XX:XX,YY:YY:YY:YY:YY:YY public void connectEnflux(List <string> devices) { StringBuilder apiArg = new StringBuilder(); for (int device = 0; device < devices.Count; device++) { apiArg.Append(devices[device]); if (device < (devices.Count - 1)) { apiArg.Append(","); } } Debug.Log(devices.Count); if (operatingState == ConnectionState.ATTACHED || operatingState == ConnectionState.DISCONNECTED) { if (EnfluxVRSuit.connect(apiArg, devices.Count) < 1) { connectedDevices = devices; operatingState = ConnectionState.CONNECTED; scanUpdater.StopScanning(); Debug.Log("Devices connected"); } else { Debug.Log("Problem connecting"); } } else { Debug.Log("Unable to connect to devices, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
public void enableAnimate(bool record) { if (operatingState == ConnectionState.CONNECTED) { StringBuilder returnBuffer = new StringBuilder(EnfluxVRSuit.MESSAGESIZE); if (EnfluxVRSuit.streamRealTime(connectedDevices.Count, record, returnBuffer) < 1) { operatingState = ConnectionState.STREAMING; StartCoroutine(readAngles()); } else { Debug.Log(returnBuffer); } } else { Debug.Log("Unable to stream, program is in wrong state " + Enum.GetName(typeof(ConnectionState), operatingState)); } }
void Awake() { //Get available COM ports availablePorts = new ComPorts(); EnfluxVRSuit.startScanPorts(availablePorts); }