How to send data from USB device to DJI SDK?

dji onboard sdk
dji skyport
dji payload sdk
dji sdk documentation
dji telemetry
dji stereo camera
dji sdk ros
dji onboard sdk python

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.

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

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.

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.

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

chmod o+rw /dev/ttyS1

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.

Commands I've tried:

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

Nothing special happens, goes to next terminal line

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

Terminal returns HelloTest

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

cursor blinks indefinitely

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

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

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

Questions

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.

Edit

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.


I came across this issue a while back as well using the Matrice M100 with the ROS onboardSDK.

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");
        }
    });
}

Where are you calling this?. Here's how I solved my issue: I wrote a function:

private void addCallback()
{
        mFlightController.setOnboardSDKDeviceDataCallback(new 
         FlightController.OnboardSDKDeviceDataCallback() {
            @Override
            public void onReceive(byte[] bytes) {
                // Do stuff with the data here..
            }
        });
}

Then in my onResume method I did something like:

@Override
    public void onResume() {
        Log.e(TAG, "onResume");

        super.onResume();
        if (mFlightController != null) {
            addCallback();
        }
    }

It's not the most elegant way but it seemed to do the trick for me. You can find my solution here. It's been a while since I worked on it though!

Device Connection, If you have any questions about this article, please send an E-mail to DJI, we will correct it in time. to the USB interface of Manifold 2 (the device number in Manifold 2 is ttyUSBn, n is 0, 1, 2, . Data communication interface. If you have any questions about this article, please send an E-mail to DJI, we will correct it in time. DJI appreciates your support and attention. Avoiding damage to the device due to improper operation, please refer to the User's Manual before connecting the onboard computer or a third party onboard computer to DJI's drones.


If you have an FTDI device then you need an FTDI driver. :)

Did you install something like this by chance? https://www.ftdichip.com/FTDrivers.htm

Serial port emulation through USB requires virtual serial port software to function.

Hardware Setup Guide, Data. The onboard computer communicates to the flight controller or DJI aircraft In the STM32 sample App, users can send commands and receive To run DJI Assistant 2, please use the USB port to connect to PC/Mac. If you have any questions about this article, please send an E-mail to DJI, we will correct it in time. DJI appreciates your support and attention. DJI appreciates your support and attention. Figure 1 display the process of connection, that connected Hardware Platform、Payload Development Board、Expansion board and DJI's drone.


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.

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

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

Device Connection - DJI Payload SDK Documentation, If you have any questions about this article, please send an E-mail to DJI, we will correct it in time. 17~20, Transfer the high-speed data. Use USB to Serial-​port module: Connect the USB to serial port module to the  Guidance API gives the method for users to get IMU data, Velocity, Obstacle distance, grey-scale image, depth image and ultrasonic data with USB and UART interface. Where are the DJI Guidance SDK Resources? All documentation can be found on the DJI developer website. The SDK can be downloaded from the website .


Payload - Onboard SDK communication, connected to the UAV through serial (UART) and USB interfaces. The communication interface between the Payload SDK and Onboard SDK Payload device is able to send real-time data to onboard computer and hand  If you have any questions about this article, please send an E-mail to DJI, we will correct it in time. DJI appreciates your support and attention. DJI appreciates your support and attention. Figure 1 display the process of connection, that connected Hardware Platform、Payload Development Board、Expansion board and DJI drone.


Run Sample Application, An application activation email will be sent to complete App Key generation. The App API_KEY" meda-data element in the "AndroidManifest.xml" file. and the Aircraft, the Mobile Device is connected to the product by USB. To use the vision function in OSDK on the M210 series of drones to enable the Linux system to obtain and identify DJI devices, please add the DJI USB device node in Linux as follows: Create the file DJIDevice.rules in the /etc/udev/rules.d/ directory.


Guidance SDK Reference, e_timeout : time out during USB transfer. e_libusb_io_err : IO error returned by libusb library. Configuration data includes: Guidance working mode, on any device, thus the directions might also be different. @AutisticNinja is right, there is a single UART within the M100 that is broken out into two ports for ease of access, not for connecting multiple devices simultaneously. In fact, trying to send data from two computers will cause both to behave erratically.