Hi,
I am trying to send location information to a ble peripheral. Hence must convert the Float (Double) location and altitude to a ByteArray to pass the the requestWrite.
I have tried various stuff but keep getting exceptions....
function notifyLocationChange( lati, longi, elev ){ var ba = new[12]b; var latiArray = new[4]b; var longiArray = new[4]b; var elevArray = new[4]b; if( _characteristic != null ){ latiArray.addAll( ByteArray.encodeNumber(52.95, Lang.NUMBER_FORMAT_FLOAT, null )); longiArray.addAll( ByteArray.encodeNumber( 1.16, Lang.NUMBER_FORMAT_FLOAT, null )); elevArray.addAll( ByteArray.encodeNumber( 400.0, Lang.NUMBER_FORMAT_FLOAT, null )); //ba = ByteArray.encodeNumber(lati, Lang.NUMBER_FORMAT_FLOAT, null ); //ba.addAll( ByteArray.encodeNumber( longi, Lang.NUMBER_FORMAT_FLOAT, null )); //ba.addAll( ByteArray.encodeNumber( elev, Lang.NUMBER_FORMAT_FLOAT, null )); _characteristic.requestWrite( ba, {:writeType => Ble.WRITE_TYPE_DEFAULT} ); } }
and whatever I seem to try I get....
Error: Unhandled Exception Exception: UnexpectedTypeException: Expected ByteArray, given Object Stack: - notifyLocationChange() at C:\NordicSemi RF5_SDK_15.3.0_59ac345\examples\Incus_Performance\garmin\NovaThingy\source\EnvironmentProfileModel.mc:40 0x1000108c - onPosition() at C:\NordicSemi RF5_SDK_15.3.0_59ac345\examples\Incus_Performance\garmin\NovaThingy\source\PositionSampleView.mc:66 0x10000e87
Have tried various combinations?
I am also confused by Float; is this a base type of an object?
What is the difference between...
var x = new [12]b; and a ByteArray? Are they synonymous?
Regards,
Owain