如何将数据从 USB 设备发送到 DJI SDK? [英] How to send data from USB device to DJI SDK?

查看:46
本文介绍了如何将数据从 USB 设备发送到 DJI SDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这可能是一个有点基本的问题,但我在硬件方面没有太多经验.我正在使用 DJI Android 移动 SDK 与 M600 飞行控制器通信,并有一个 FTDI CU/TTY 设备,我正在尝试来回发送信息.

So this might be a bit basic of a question, but I don't have much experience on the hardware side of things. I am using DJI Android Mobile SDK to communicate with a M600 flight controller and have a FTDI CU/TTY device I am trying to send info back and forth.

这成功地将Hello World"发送到我的 USB 设备:

This successfully works to send "Hello World" to my USB device:

//sends data to onboard sdk device
final byte[] helloWorld = "HelloWorld".getBytes();
mFlightController.sendDataToOnboardSDKDevice(helloWorld, new CommonCallbacks.CompletionCallback() {
    @Override
    public void onResult(DJIError djiError) {
        if (djiError != null) {
            showToast(djiError.getDescription());
            WriteFileAppendAsync writeAppend = new WriteFileAppendAsync();
            writeAppend.execute(djiError.getDescription(), "sendOnboardErrorFile.txt");
        } else {
            showToast("Hopefully Hello World");
            WriteFileAppendAsync writeAppend = new WriteFileAppendAsync();
            writeAppend.execute(helloWorld.toString(), "sendOnboardSuccessFile.txt");
        }
    }
});

当我在终端中运行以下任一命令时,我可以看到这一点:

I can see this when I run either of the following in terminal:

screen /dev/cu.usbserial-BLAHBLAH 38400
screen /dev/tty.usbserial-BLAHBLAH 38400

每次我点击触发上述 DJI 代码的按钮时,都会出现一堆乱码/象形文字,然后弹出文本Hello World".

A bunch of gibberish/ hieroglyphics show up and then the text "Hello World" pops up every time I click a button that triggers the above DJI code.

现在,我想让这个工作的另一面,即使用以下内容从 USB 发送回 DJI sdk:

Now, I want to get the flips side of this working i.e. send something back from the USB to the DJI sdk using the following:

if (mFlightController.isOnboardSDKDeviceAvailable()) {
    showToast("Set Onboard SDk Callback");
    mFlightController.setOnboardSDKDeviceDataCallback(new FlightController.OnboardSDKDeviceDataCallback() {
        @Override
        public void onReceive(byte[] bytes) {
            WriteFileAppendAsync writeAppend = new WriteFileAppendAsync();
            writeAppend.execute(bytes.toString(), "onboardCallbackFile.txt");
        }
    });
}

问题是我似乎从来没有得到任何回应.

The trouble is I never seem to get anything in response.

根据 这个问题,我确定我对 USB 设备有读写权限:

As per this question, I made sure I have read write permission on the USB device:

chmod o+rw /dev/ttyS1

而且我试过各种echo和cat命令(不知道是读写哪个).他们要么说设备忙,要么说不是,他们似乎打开了一个通信端口(终端无限期闪烁),但没有任何内容发送到我的设备.

And I have tried all sorts of echo and cat commands (I don't know which one is read and write). They either say device is busy, or if not, they seem to open a port of communication (the terminal blinks indefinitely), but nothing sends to my device.

我尝试过的命令:

echo 'HelloTest' > /dev/cu.usbserial-BLAHBLAH

没有什么特别的事情发生,转到下一个终端行

Nothing special happens, goes to next terminal line

echo 'HelloTest' > /dev/tty.usbserial-BLAHBLAH

终端返回HelloTest

Terminal returns HelloTest

echo 'HelloTest' < /dev/tty.usbserial-BLAHBLAH

光标无限闪烁

echo 'HelloTest' < /dev/cu.usbserial-BLAHBLAH

终端返回HelloTest

Terminal returns HelloTest

cat < /dev/cu.usbserial-BLAHBLAH
cat -v < /dev/tty.usbserial-BLAHBLAH
cat -v > /dev/tty.usbserial-BLAHBLAH
cat -v > /dev/cu.usbserial-BLAHBLAH

没有这样的文件或目录(我想我需要为此运行 2 个终端?)

No such file or directory (I guess I need 2 terminals running for this?)

问题

这与波特率有关吗?我已经在 DJI Assistant 中进行了设置.TTY 和 CU 以及 Echo 和 Cat 有什么区别?我尝试了各种组合.我可以在 cu 和 tty 中使用 screen 命令.最后,什么是简单的 hello world 我可以发送回 sdk 以查看我实际上是从我的 USB 设备接收数据?我认为 echo 会成功,但我什么也没收到.

Does this have to do with Baud rate? I have set that up in DJI Assistant. What is the difference between TTY and CU and Echo and Cat? I have tried all sorts of combinations. I am able to use the screen command with both cu and tty. Finally, what is a simple hello world I can send back to the sdk to see that I am actually receiving data from my usb device? I would think echo would success, but I'm not receiving anything.

编辑

我几乎觉得我需要使用诸如 usb-serial-for-android 之类的东西;但是,我实际上并没有将 USB 设备连接到我的 android 设备.相反,我连接到 DJI RC 控制器,该控制器连接到 Lightbridge/M600,后者通过 API 端口与我的 USB 设备连接.

I almost feel like I need to use something like usb-serial-for-android; however, I'm not actually connecting the usb device to my android device. Instead, I am connecting to the DJI RC Controller, which connects to Lightbridge/ M600, which connects through the API port with my usb device.

推荐答案

我相信您需要了解 DJI OpenProtocol 才能完成这项工作.一堆胡言乱语"实际上是这里的问题.那些胡言乱语是 DJI 无人机用来正确中继通信的协议.

I believe you need to understand the DJI OpenProtocol to make this work. The "bunch of gibberish" is in fact the problem here. That gibberish is the protocol that DJI drones use to properly relay communications.

为了使用最新代码从Onboard"发送到Mobile",您需要将 0xFE CMD_Set Id 作为数据的标头:

In order to send from "Onboard" to "Mobile" with the latest code you need the 0xFE CMD_Set Id as a header to your data:

https://developer.dji.com/onboard-sdk/documentation/protocol-doc/open-protocol.html

因此,要么找出数据的正确格式,要么购买便宜的 PC 并安装 OSDK.

So, either, figure out the proper format to your data or buy a cheap PC and install the OSDK.

这篇关于如何将数据从 USB 设备发送到 DJI SDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆