mangOH green: golang and positioning

Hi,

I am trying to access the positioning service from a Go app and I’m stuck on starting the positioning service. Generally, how do you use Legato services from 3rd party apps (in my case a Go app)?

I am using bundles to package the app or just copy the binary to the mangOH green to see whether it works at all.

When I run the app I get le_posCtrl_ConnectService() not called for current thread. I’m assuming that I need to start the positioning service somehow and that this is achieved through the bindings section in the .adef file.

$ cat Makefile
CC=/opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/gcc
build: clean
	CC=$(CC) GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 go build

scp: build
	scp gps root@192.168.2.2:

instapp: build
	mkapp -v -t wp750x gps.adef
	instapp gps.wp750x.update 192.168.2.2

ifgen:
	ifgen  --gen-interface --gen-client --gen-local $(LEGATO_ROOT)/interfaces/positioning/le_pos.api
	ifgen  --gen-interface --gen-client --gen-local $(LEGATO_ROOT)/interfaces/positioning/le_posCtrl.api

clean:
	rm -f *.o
	rm -f gps
$ cat gps.adef
sandboxed: false

version: 1.0.0

bundles:
{
	file:
	{
		[x] gps /bin/gps
	}
}

processes:
{
    run:
    {
        ( gps )
    }
}
$ cat /go/src/gps/main.go

package main

/*
#cgo CFLAGS: -I/legato/framework/c/inc
#cgo LDFLAGS: -L/legato/build/wp750x/framework/lib -llegato

#include <stdio.h>
#include "legato.h"
#include "le_pos_interface.h"
#include "le_posCtrl_interface.h"
*/
import "C"

import "log"
import "time"

func main() {
	log.Print("Starting gps")

	// this never returns
	// log.Print("Calling le_posCtrl_ConnectService()")
	// C.le_posCtrl_ConnectService()

	log.Print("Calling le_posCtrl_Requst()")
	ref := C.le_posCtrl_Request()
	if ref == nil {
		log.Fatal("Cannot activate positioning service")
	}
	defer C.le_posCtrl_Release(ref)

	var lat, lon, acc C.int
	for {
		log.Println("Calling le_pos_Get2DLocation")
		res2 := C.le_pos_Get2DLocation(&lat, &lon, &acc)
		log.Printf("le_pos_Get2DLocation: res: %d lat: %d lon: %d acc: %d\n", res2, lat, lon, acc)
		time.Sleep(500*time.Millisecond)
	}
}

Running make and copying the file to 192.168.2.2 and running it returns

Jun  9 22:30:00 swi-mdm9x15 user.emerg Legato: *EMR* | _UNKNOWN_[8337]/framework T=main | LE_FILENAME GetCurrentSessionRef() 320 | le_posCtrl_ConnectService() not called for current thread

Adding a call to le_posCtrl_ConnectService() at the start never returns.

I’ve then tried adding generic bindings to the gps.adef file but with no success.

...
bindings:
{
    *.le_posCtrl -> positioningService.le_posCtrl
    *.le_pos -> positioningService.le_pos
}

mkapp -v -t wp750x gps.adef returns

/go/src/gps/gps.adef:27:6: error: No such client-side pre-built interface 'le_posCtrl'.

I’m probably missing something obvious or this isn’t possible. Any help is greatly appreciated.

Update 1: I am using Legato 16.10.3 on a mangOH green with a WP750x

Have you tried asking on the Legato forum?

Actually - no :slight_smile: I’m somewhat new to this environment. I’ll try thx.