Swift nsinputstream not giving me the correct data from Trimble

I've developed this for the android and simply used a bufferedreader and

br.readline()
and the code properly interpreted the data coming through.

I should be getting data that looks like this:

$GPRMC,191830.00,A,4159.87613,N,09338.29258,W,0.065,303.4,270815,0.8,E,D*21

what I am getting is data that looks like this:

(WK#

The code in viewDidLoad()


if accessoryList.count > 0 {

var accessory = accessoryList[0] as! EAAccessory

accessory.delegate = self

println(accessoryList[0].description)

session = EASession(accessory: accessoryList[0] as! EAAccessory, forProtocol: "com.trimble.mcs.gnss")

if session != nil {

inputStream = session.inputStream

/

inputStream.delegate = self

inputStream.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)

inputStream.open()

}

}


and the stream code


func stream(aStream: NSStream, handleEvent eventCode: NSStreamEvent) {

let inStream = aStream as? NSInputStream

switch (eventCode){

case NSStreamEvent.OpenCompleted:

NSLog("Stream opened")

break

case NSStreamEvent.HasBytesAvailable:

/

let bufferSize = 8

var buffer = [UInt8](count: bufferSize, repeatedValue: 0)

while(session.inputStream!.hasBytesAvailable) {

let result :Int = session.inputStream!.read(&buffer, maxLength: bufferSize)

if(result > 0){

var output = NSString(bytes: &buffer, length: bufferSize, encoding: NSUTF8StringEncoding)

if(output != nil) {

print(output!)

}

}

}

println("")

break

case NSStreamEvent.ErrorOccurred:

NSLog("ErrorOccurred")

break

case NSStreamEvent.EndEncountered:

NSLog("EndEncountered")

break

default:

NSLog("unknown.")

}

}


Is there something I'm missing? I'm getting data, it's just not in english. I know that the encoding is UTF8. Any help would be appreciated!

Answered by DTS Engineer in 60814022

I don't believe it's the MFi program.

If you’re using External Accessory framework then, yes, the accessory is MFi. An accessory must be MFi for the EA framework to talk to it.

It seems like your device has two interfaces:

  • an NMEA 0183 interface, which produces ASCII data — This is what you’re Android app is getting.

  • an EA stream, which produces binary data — This is what your iOS app is getting.

If you want to continue with the EA stream approach, you will either have to talk to the vendor to get a specification of the format of that stream or reverse engineer it for yourself.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

This actually is exactly what I'm working with https://en.wikipedia.org/wiki/NMEA_0183

Accepted Answer

I don't believe it's the MFi program.

If you’re using External Accessory framework then, yes, the accessory is MFi. An accessory must be MFi for the EA framework to talk to it.

It seems like your device has two interfaces:

  • an NMEA 0183 interface, which produces ASCII data — This is what you’re Android app is getting.

  • an EA stream, which produces binary data — This is what your iOS app is getting.

If you want to continue with the EA stream approach, you will either have to talk to the vendor to get a specification of the format of that stream or reverse engineer it for yourself.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

NMEA is sort of a raw format of GPS, and high-level devices can send data in various formats.

It is clear your device is not sending data in NMEA format when connected to iOS device.

You need to find out in what format your device is sending data to your iOS device.

Hmmm it looks like you guys are correct in saying it's binary format.


I found the codes on Trimble's site & it starts with the 02h

http://www.trimble.com/EC_ReceiverHelp/v4.15/en/GSOFmessages_GSOF.htm#RECEIVERSTATUSCODE


Thanks for all of the help. I didn't realize there were 2 types of transmissions different from what the android is recieving.

It looks like you are correct. There are 2 transmissions going on. This data is in binary while the androids data are simply nmea strings. The binary has much more data I'm interested in and Trimble's site seems to lay out the explanations for everything.

Swift nsinputstream not giving me the correct data from Trimble
 
 
Q