internal WearableProxyProvider() { _sensorStatus = new Dictionary <SensorId, bool?>(); _gestureStatus = new Dictionary <GestureId, bool?>(); ResetDeviceStatus(); _networkTimeout = 1.0f; _server = new TcpClient(); _protocol = new WearableProxyClientProtocol(); _protocol.ConnectionStatus += OnConnectionStatus; _protocol.DeviceList += OnDeviceList; _protocol.KeepAlive += OnKeepAlive; _protocol.SensorStatus += OnSensorStatus; _protocol.GestureStatus += OnGestureStatus; _protocol.NewSensorFrame += OnNewSensorFrame; _protocol.SensorUpdateIntervalValue += OnUpdateIntervalValue; _protocol.PingQuery += OnPingQuery; _portNumber = 0; _hostname = string.Empty; _receiveIndex = 0; _receiveBuffer = new byte[WearableProxyProtocolBase.SuggestedServerToClientBufferSize]; _transmitIndex = 0; _transmitBuffer = new byte[WearableProxyProtocolBase.SuggestedClientToServerBufferSize]; _issuedWarningLastPacket = false; }
internal override void StopSearchingForDevices() { _transmitIndex = 0; WearableProxyClientProtocol.EncodeStopDeviceSearch(_transmitBuffer, ref _transmitIndex); SendTransmitBuffer(); _searchingForDevices = false; }
internal override void SearchForDevices(Action <Device[]> onDevicesUpdated) { _transmitIndex = 0; WearableProxyClientProtocol.EncodeInitiateDeviceSearch(_transmitBuffer, ref _transmitIndex); SendTransmitBuffer(); _searchingForDevices = true; _onDevicesUpdatedCallback = onDevicesUpdated; }
internal override void ConnectToDevice(Device device, Action onSuccess, Action onFailure) { _transmitIndex = 0; WearableProxyClientProtocol.EncodeConnectToDevice(_transmitBuffer, ref _transmitIndex, device.uid); SendTransmitBuffer(); _connectingToDevice = true; _deviceConnectSuccessCallback = onSuccess; _deviceConnectFailureCallback = onFailure; }
internal override void SetDeviceConfiguration(WearableDeviceConfig config) { _transmitIndex = 0; WearableProxyClientProtocol.EncodeSetNewConfig(_transmitBuffer, ref _transmitIndex, config); SendTransmitBuffer(); // Since failed attempts, retries, etc are handled on the <i>server</i> side, all configuration attempts // should be considered a success as long as the packet was sent out. _sendConfigSuccessNextFrame = true; }
internal override void DisconnectFromDevice() { _transmitIndex = 0; WearableProxyClientProtocol.EncodeDisconnectFromDevice(_transmitBuffer, ref _transmitIndex); SendTransmitBuffer(); if (_connectedDevice != null) { // We can immediately disconnect the client without waiting for a response. OnDeviceDisconnected(_connectedDevice.Value); _connectedDevice = null; ResetDeviceStatus(); } }
internal override void DisconnectFromDevice() { _transmitIndex = 0; WearableProxyClientProtocol.EncodeDisconnectFromDevice(_transmitBuffer, ref _transmitIndex); SendTransmitBuffer(); if (_connectedDevice != null) { // We can immediately disconnect the client without waiting for a response. OnConnectionStatusChanged(ConnectionStatus.Disconnected, _connectedDevice); _connectedDevice = null; ResetDeviceStatus(); _sendConfigSuccessNextFrame = false; } }
internal override RotationSensorSource GetRotationSource() { // If we've never received data, there's not much we can do but warn the user, request the data, and return defaults if (_rotationSource == null) { Debug.LogWarning(WearableConstants.ProxyProviderNoDataWarning); _transmitIndex = 0; WearableProxyClientProtocol.EncodeQueryRotationSource(_transmitBuffer, ref _transmitIndex); SendTransmitBuffer(); return(WearableConstants.DefaultRotationSource); } else { return(_rotationSource.Value); } }
internal override bool GetGestureEnabled(GestureId gestureId) { // If we've never received data, there's not much we can do but warn the user, request the data, and return defaults if (_gestureStatus[gestureId] == null) { Debug.LogWarning(WearableConstants.ProxyProviderNoDataWarning); _transmitIndex = 0; WearableProxyClientProtocol.EncodeQueryGestureStatus(_transmitBuffer, ref _transmitIndex); SendTransmitBuffer(); return(false); } else { return(_gestureStatus[gestureId].Value); } }
internal override SensorUpdateInterval GetSensorUpdateInterval() { // If we've never received data, there's not much we can do but warn the user, request the data, and return defaults if (_sensorUpdateInterval == null) { Debug.LogWarning(WearableConstants.ProxyProviderNoDataWarning); _transmitIndex = 0; WearableProxyClientProtocol.EncodeQueryUpdateInterval(_transmitBuffer, ref _transmitIndex); SendTransmitBuffer(); return(WearableConstants.DefaultUpdateInterval); } else { return(_sensorUpdateInterval.Value); } }
internal override void SearchForDevices( AppIntentProfile appIntentProfile, Action <Device[]> onDevicesUpdated, bool autoReconnect, float autoReconnectTimeout) { base.SearchForDevices(appIntentProfile, onDevicesUpdated, autoReconnect, autoReconnectTimeout); if (autoReconnect) { throw new NotImplementedException(); } _transmitIndex = 0; WearableProxyClientProtocol.EncodeInitiateDeviceSearch(_transmitBuffer, ref _transmitIndex); SendTransmitBuffer(); _searchingForDevices = true; }
internal override void DisconnectFromDevice() { _transmitIndex = 0; WearableProxyClientProtocol.EncodeDisconnectFromDevice(_transmitBuffer, ref _transmitIndex); SendTransmitBuffer(); for (var i = 0; i < WearableConstants.GestureIds.Length; i++) { if (WearableConstants.GestureIds[i] == GestureId.None) { continue; } _gestureStatus[WearableConstants.GestureIds[i]] = false; } if (_connectedDevice != null) { // We can immediately disconnect the client without waiting for a response. OnDeviceDisconnected(_connectedDevice.Value); _connectedDevice = null; ResetDeviceStatus(); } }
internal override void DisableGesture(GestureId gestureId) { _transmitIndex = 0; WearableProxyClientProtocol.EncodeGestureControl(_transmitBuffer, ref _transmitIndex, gestureId, false); SendTransmitBuffer(); }
internal override void StopSensor(SensorId sensorId) { _transmitIndex = 0; WearableProxyClientProtocol.EncodeSensorControl(_transmitBuffer, ref _transmitIndex, sensorId, false); SendTransmitBuffer(); }
internal override void SetRotationSource(RotationSensorSource source) { _transmitIndex = 0; WearableProxyClientProtocol.EncodeSetRotationSource(_transmitBuffer, ref _transmitIndex, source); SendTransmitBuffer(); }
internal override void SetSensorUpdateInterval(SensorUpdateInterval updateInterval) { _transmitIndex = 0; WearableProxyClientProtocol.EncodeSetUpdateInterval(_transmitBuffer, ref _transmitIndex, updateInterval); SendTransmitBuffer(); }
protected override void RequestDeviceConfigurationInternal() { _transmitIndex = 0; WearableProxyClientProtocol.EncodeQueryConfig(_transmitBuffer, ref _transmitIndex); SendTransmitBuffer(); }