Android - 编写用于发送 GPS 轨迹的 telnet 会话脚本
总之,
我熟悉通过模拟器连接时通过使用geo fix long lat Altitude
命令向模拟器伪造GPS信息的能力。
我想做的是让模拟在可能不同的计算机上运行,产生经纬度、经度和海拔高度,这些数据应该发送到 Android 设备,以假装模拟器认为它已收到 GPS 更新。
我看到了编写 telnet 会话脚本的各种解决方案;看起来最好的解决方案是,用伪代码表示:
while true:
if position update generated / received
open subprocess and call "echo 'geo fix lon lat altitude' | nc localhost 5554"
这似乎是一个大黑客,尽管它适用于 Mac(不适用于 Windows)。有更好的方法吗? (我无法提前生成轨迹并将其作为路线输入;Android 系统是实时模拟的一部分,但由于它在模拟器上运行,因此没有位置更新。另一个系统负责计算这些位置更新)。
编辑: 另一种方法,也许更干净,是使用 python 的 telnetlib 库。
import telnetlib
tn = telnetlib.Telnet("localhost",5554)
while True:
if position update generated / received
tn.write("geo fix longitude latitude altitude\r\n")
All,
I am familiar with the ability to fake GPS information to the emulator through the use of the geo fix long lat altitude
command when connected through the emulator.
What I'd like to do is have a simulation running on potentially a different computer produce lat, long, altitudes that should be sent over to the Android device to fake the emulator into thinking it has received a GPS update.
I see various solutions for scripting a telnet session; it seems like the best solution is, in pseudocode:
while true:
if position update generated / received
open subprocess and call "echo 'geo fix lon lat altitude' | nc localhost 5554"
This seems like a big hack, although it works on Mac (not on Windows). Is there a better way to do this? (I cannot generate the tracks ahead of time and feed them in as a route; the Android system is part of a real time simulation, but as it's running on an emulator there is no position updates. Another system is responsible for calculating these position updates).
edit:
Alternative method, perhaps more clean, is to use the telnetlib library of python.
import telnetlib
tn = telnetlib.Telnet("localhost",5554)
while True:
if position update generated / received
tn.write("geo fix longitude latitude altitude\r\n")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许这接近您正在寻找的
https://github.com/xperimental/fakegps
Maybe this is close to what you're looking for
https://github.com/xperimental/fakegps
Netcat(上例中的 nc)几乎可以编译任何内容,包括 Windows 和 Android 本身。
简而言之,这看起来不像是破解的解决方案,它看起来像是一个非常传统的 UNIX 脚本风格的解决方案,可以轻松地在任何现代平台上工作。
如果您不喜欢为每个修复打开一个新连接,您应该能够编写一个程序来生成标准输出的修复并将其通过管道传输到 netcat。
Netcat (the nc in the above example) compiles for just about anything, including windows and android itself.
In short, that doesn't look like a hack of a solution, it looks like a very traditional unix scripting style solution that could be easily made to work on any modern platform.
If you don't like opening a new connection for each fix, you should be able to just write a program that generates fixes to standard output and pipe it into netcat.