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

SDK crashes after sending data to companion computer on Matrice 300 #518

Open
makk25 opened this issue May 23, 2022 · 2 comments
Open

SDK crashes after sending data to companion computer on Matrice 300 #518

makk25 opened this issue May 23, 2022 · 2 comments

Comments

@makk25
Copy link

makk25 commented May 23, 2022

Dear DJI Team,

I try to send Data from my iOS application to a companion computer on a Matrice 300 RTK. For this I’m using the DJI mobile SDK (4.16) and the DJI onboard SDK (4.1.0).

Receiving Data from the companion computer does not cause any problems. But if I try to send data, the application crashes after sending. This means, that the data are received on the companion computer, but afterward the iOS application throws a “bad access exception”. It seems that this erros occurs in the DJI mobile SDK so I’m not able to get useful information to solve the problem.

Bildschirmfoto 2022-05-23 um 10 41 50

private var voxelRepository: VoxelRepository?
    
func connectToOnboardSDK(){
     self.voxelRepository = VoxelRepository() { (data)  in
         print(data)
     }
}
 
 func startConnection(){
     var startVoxelTransmissionSettings = Voxel_LidarSettings()
     let serializedSettings = VoxelSerializer.serializeSettings(lidarSettings: startVoxelTransmissionSettings)

     self.voxelRepository?.sendData(data: serializedSettings ?? Data())
 }
import Foundation
import DJISDK

class VoxelRepository: NSObject {
   
    private let EOM = "^"
    
    private var onboardSDKDevice: DJIOnboardSDKDevice?
    
    private var responseData = Data()
    
    private var completion: (Voxel_LidarData)->Void
    
    init(completion: @escaping (Voxel_LidarData)->Void){
        self.completion = completion
        
        super.init()
        
        initOnboardSDK()
    }
    
    private func initOnboardSDK(){
        
        let product = DJISDKManager.product()
        let aircraft = product as? DJIAircraft
        let flightController = aircraft!.flightController
        let onboardSDKDevice = flightController!.onboardSDKDevice
        guard flightController!.isOnboardSDKAvailable() == true else {
            return
        }
        
        onboardSDKDevice!.delegate = self
        self.onboardSDKDevice = onboardSDKDevice
    }
        
    func sendData(data: Data) {
        let size = data.count
        var bytesSent = 0
        let packageSize = 100
        while bytesSent < size {
            let bytesToSend = min(packageSize, size-bytesSent)
            let dataPart = data.subdata(in: bytesSent..<bytesSent+bytesToSend)
            print("sending data with length \(bytesToSend)")
            
            onboardSDKDevice!.sendDataFromMobile(toOnboard: dataPart) { error in
                print("completion with \(error.debugDescription)")
              }
    
            bytesSent += bytesToSend
        }
        
        print("done sending bytes")
        sendEOM()
    }
    
    private func sendEOM() {
        let eomMessage = EOM.data(using: .utf8) ?? Data()
        onboardSDKDevice!.sendDataFromMobile(toOnboard: eomMessage, withCompletion: nil)
        print("eom sent")
    }
}

extension VoxelRepository: DJIOnboardSDKDeviceDelegate {
    func onboardSDKDeviceDidDeactivate(_ osdkDevice: DJIOnboardSDKDevice) {
        
    }
    
    func onboardSDKDevice(_ osdkDevice: DJIOnboardSDKDevice, didActivateWithOnboardSDKVersion osdkVersion: String) {
        
    }

    func onboardSDKDevice(_ osdkDevice: DJIOnboardSDKDevice, didSendDataToMobile data: Data) {
        print("did receive data")
        if let stringRep = String(data: data, encoding: .utf8), stringRep == EOM {
            // Response Data contains whole message, parse and reset for next message
            let lidarData = VoxelSerializer.deserializeLidarHit(data: responseData)
            
            // signal to somewhere that lidar data has been received
            print("received lidar data with nr of hits: \(lidarData?.hits.count)")
            responseData = Data()
          
            self.completion(lidarData ?? Voxel_LidarData())
            return
        }
        
        print("appending data")
        responseData.append(data)
    }
}

Am I missing something, or could there be a problem with the DJI mobile SDK?

Best Regards

Versions / Products
DJI mobile SDK 4.16
DJI onboard SDK 4.1.0
Matrice 300 RTK
iPad Air 4
iOS 15.4.1
Xcode 13.3.1

@DJI-William
Copy link

For M300, you should use a MOP function. We ntroduce a new mechanism to communicate between MSDK and OSDK. Please have a look the DJIPipeline.

@makk25
Copy link
Author

makk25 commented May 25, 2022

Okay, thanks for the quick reply. I will try this and get back to you.

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

2 participants