简体   繁体   English

Android - 流媒体传感器数据不断?

[英]Android - streaming sensor data continuously?

I have the following code giving me some sensor data: 我有以下代码给我一些传感器数据:

private void computeOrientation() {
        if (SensorManager.getRotationMatrix(m_rotationMatrix, null, m_lastAccels, m_lastMagFields)) {
            SensorManager.getOrientation(m_rotationMatrix, m_orientation);

            /* 1 radian = 57.2957795 degrees */
            /*
             * [0] : yaw, rotation around z axis [1] : pitch, rotation around x
             * axis [2] : roll, rotation around y axis
             */
            float yaw = m_orientation[0] * 57.2957795f;
            float pitch = m_orientation[1] * 57.2957795f;
            float roll = m_orientation[2] * 57.2957795f;

            /* append returns an average of the last 10 values */
            m_lastYaw = m_filters[0].append(yaw);
            m_lastPitch = m_filters[1].append(pitch);
            m_lastRoll = m_filters[2].append(roll);

            yawText.setText("azi z: " + m_lastYaw);
            pitchText.setText("pitch x: " + m_lastPitch);
            rollText.setText("roll y: " + m_lastRoll);

                    //Now I want to send those 3 values over the network
                    //whenever they're calculated
}

This function will be invoked every few milliseconds I reckon, from onSensorChanged(SensorEvent event) . onSensorChanged(SensorEvent event) ,我将每隔几毫秒调用一次该函数。

I want to continually send/stream this data over internet network to a remote device, that will be using the data stream to calculate things in real time. 我想通过互联网网络不断地将这些数据发送/传输到远程设备,该设备将使用数据流实时计算数据。

How should I do this? 我该怎么做? Through sockets? 通过套接字? An AsyncTask? AsyncTask? Example source code for getting started would be much appreciated =) 入门的示例源代码将非常感激=)

This is a job for a Service to calculate the data in background. 这是服务在后台计算数据的工作。 Because no UI is necessary you can use a Thread insteed of an AsyncTask to get the sensor data. 因为不需要UI,所以可以使用AstryTask的线程来获取传感器数据。

There is more detail needed in general, but especially for the setup of the connection between your phone and the remote device. 通常需要更多细节,尤其是在手机和远程设备之间建立连接时。 If you use a LAN, sockets in combination with a ByteArrayriter on the Phone and a ByteArrayReader on the device should do the job. 如果您使用LAN,则套接字与电话上的ByteArrayriter和设备上的ByteArrayReader结合使用可以完成这项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM