Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send Data OSDK to MSDK V4 for iOS #557

Open
Keita-Imaizumi opened this issue Aug 1, 2024 · 0 comments
Open

How to send Data OSDK to MSDK V4 for iOS #557

Keita-Imaizumi opened this issue Aug 1, 2024 · 0 comments

Comments

@Keita-Imaizumi
Copy link

I’m tring to develop communication app that send data from OSDK app to MSDK app with following setup.

My development setup:
Drone: Matrice 300RTK
Connecter: DJI OSDK expansion module
SDK: Onboard SDK 4.1.0, MSDK V4 for iOS

Tx(OSDK V4.1): vehicle->moc->sendDataToMSDK(https://developer.dji.com/onboard-api-reference/classDJI_1_1OSDK_1_1MobileDevice.html#details%EF%BC%89and)

OSDK App(Tx)

{ // Setup OSDK.
  LinuxSetup linuxEnvironment(argc, argv);
  Vehicle*   vehicle = linuxEnvironment.getVehicle();
  if (vehicle == nullptr) {
    std::cout << "Vehicle not initialized, exiting.\n";
    return -1;
  }
  DSTATUS("Start to listen bytes from MSDK, please input data through your"
          " MSDK App ......\n");
  setupMSDKParsing(vehicle, &linuxEnvironment);

  return 0;
}
void
setFromMSDKCallback(Vehicle* vehicle, LinuxSetup* linuxEnvironment)
{
  vehicle->mobileDevice->setFromMSDKCallback(parseFromMobileCallback,
                                             linuxEnvironment);
}

void
sendDataToMSDK(Vehicle* vehicle, uint8_t* data, uint8_t len)
{
  vehicle->mobileDevice->sendDataToMSDK(data, len);
}

// Function to be executed in the thread
void* sendDataThread(void* arg)
{
  Vehicle* vehicle = static_cast<Vehicle*>(arg);
  const char* testString = "Hello DJI!";
  uint8_t len = static_cast<uint8_t>(strlen(testString));

  while (keepLoopRunning)
  {
    sendDataToMSDK(vehicle, reinterpret_cast<uint8_t*>(const_cast<char*>(testString)), len);
    DSTATUS("Sending Data\n");
    sleep(1); // Wait for 1 second
  }

  return nullptr;
}


bool
setupMSDKParsing(Vehicle* vehicle, LinuxSetup* linuxEnvironment)
{
   // First, register the callback for parsing mobile data
  setFromMSDKCallback(vehicle, linuxEnvironment);

  // Setup a thread to send data to MSDK every second
  pthread_t sendThreadID;
  int ret = pthread_create(&sendThreadID, NULL, sendDataThread, (void*)vehicle);
  if (ret != 0)
  {
    DERROR("Failed to create thread for sending data!\n");
    return false;
  }

  // User input
  std::cout << "Listening to mobile commands. Press any key to exit.\n";
  char a;
  std::cin >> a;

  // Now that we're exiting, Let's shut off the sending thread
  keepLoopRunning = false;
  void* status;
  pthread_join(sendThreadID, &status);

  return true;
}

Rx(MSDK V4): OnboardSDKDevice Class(https://developer.dji.com/api-reference/ios-api/Components/FlightController/DJIFlightController.html#djiflightcontroller_onboardsdkdevice_inline)

MSDK App (Rx)

extension SomeClass: DJIOnboardSDKDelegate {
  func productConnected(_ product: DJIBaseProduct?) { 
        let fc = (DJISDKManager.product() as! DJIAircraft).flightController?// 追加
                if (fc != nil) {
                    print("\nfc not nil")
                    fc?.delegate = self
                }
         print(fc?.isOnboardSDKAvailable())
         let onboardSDKDevice = fc?.onboardSDKDevice
               
          onboardSDKDevice?.delegate = self
          self.onboardSDKDevice = onboardSDKDevice
    }
  func onboardSDKDevice(_ osdkDevice: DJIOnboardSDKDevice, didSendDataToMobile data: Data)
     {
      print("received data\(data)")
    }
}

I’d like get data on MSDK side using onboardSDKDevice(_ osdkDevice: DJIOnboardSDKDevice, didSendDataToMobile data: Data) but but MSDK App doesn’t receive any data despite the correct configuration for using didSendDataToMobile method as below.

From what I have seen in the logs, The OSDK App seems to be working correctly.

and I've used isOnboardSDKAvailable() to determine if the SDK has recognized the OSDK device but it's false.
I'd like to know why that method returns false and how to make OSDK available.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant