gpt4 book ai didi

android - android智能手机3.5mm音频口RS232串口信号输入(android开发)

转载 作者:行者123 更新时间:2023-11-30 03:19:40 24 4
gpt4 key购买 nike

您好,首先感谢您阅读我的问题!

我有一个设备,它给我的输出基本上只是一个 RS232 串行信号(1200 波特、8 个数据位、无奇偶校验位、一个停止位)。此输出通过 3.5 毫米音频插孔进入我的 Android 手机。

我想将每个数据位存储到一个变量中,显示或计算一些东西,当下一个位进来时,它应该覆盖变量。

在我将数据位放入变量中后,我确切地知道如何处理它,但我不知道如何进行基本输入/流/从音频插孔读取...

我找到了这个,但对我帮助不大:Android serial port via audio jack也许是这样的:Android: Need to record mic input

请帮帮我,谢谢!

编辑:关于我的信号的更多信息有效负载以 9 字节数据包的形式传输:

1: command byte as ASCII character ('I','A','S','L','R','C' or ' ')
2-6: time in ASCII chars (2:34:56)
7: checksum (64 + sum of time digits)
8: CR (carriage return, ASCII code 0x0D)
9: LF (line feed, ASCII code 0x0A)

Edit2:我还认为我必须将输入存储到缓冲区中,然后从缓冲区中读取信号...但是如何将音频插孔的串行输入写入缓冲区?

Edit3:也许这样的事情会奏效:

try
{
int N = AudioRecord.getMinBufferSize(8000,AudioFormat.CHANNEL_IN_MONO,AudioFormat.ENCODING_PCM_16BIT);
recorder = new AudioRecord(AudioSource.MIC, 1200, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, N*10);
track = new AudioTrack(AudioManager.STREAM_MUSIC, 1200,
AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, N*10, AudioTrack.MODE_STREAM);
recorder.startRecording();
track.play();
/*
* Loops until something outside of this thread stops it.
* Reads the data from the recorder and writes it to the audio track for playback.
*/
while(!stopped)
{
Log.i("Map", "Writing new data to buffer");
short[] buffer = buffers[ix++ % buffers.length];
N = recorder.read(buffer,0,buffer.length);
track.write(buffer, 0, buffer.length);
}
}
catch(Throwable x)
{
Log.w("Audio", "Error reading voice audio", x);
}
/*
* Frees the thread's resources after the loop completes so that it can be run again
*/
finally
{
recorder.stop();
recorder.release();
track.stop();
track.release();
}
}

最佳答案

虽然不是您问题的详细答案,但您当前的方法存在许多问题

  1. 您违反了 Nyquist sampling theory通过以线路速率对输入信号进行采样。您的系统带宽需要至少是比特率的两倍。

  2. 您目前似乎无法构建您的消息以指示消息在字节流中开始或结束。特别是,0x0a0x0d 都可能出现在消息正文的其他位置。您可能会考虑使用每个字节的 MSB 来信号帧,并且只在每个字节的剩余 7 位中编码有效负载)

  3. 您正在尝试在没有时钟恢复的情况下对信号进行采样。发送方发送时钟和接收方的采样时钟不同步——也就是说时钟边沿不对齐。它们可能会随着时间的推移而漂移。

此外,您需要注意信号电平 - RS232 可能在 12v 时发出信号。

这是一个已经很好解决的问题 - 我建议查看一些调制解调器标准。某种调制 - 例如 Phase Shift Keying通常与某种时钟恢复一起使用以处理上述问题 1 和 3。

关于android - android智能手机3.5mm音频口RS232串口信号输入(android开发),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19383890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com