// Author: NiuJiuRu
// Email: niujiuru@qq.com

package air530z

/*
#include "air530z.h"
*/
import "C"
import (
	"fmt"
	"unsafe"
)

// 打开与模块的通讯
func air530Z_ComInit() (int, error) {
	ret := int(C.Air530Z_ComInit())
	if ret != 0 {
		return ret, fmt.Errorf("an error occurred while calling the C.Air530Z_ComInit function(%d)", ret)
	}
	return 0, nil
}

// 关闭与模块的通讯
func air530Z_ComExit() error {
	ret := int(C.Air530Z_ComExit())
	if ret != 0 {
		return fmt.Errorf("an error occurred while calling the C.Air530Z_ComExit function(%d)", ret)
	}
	return nil
}

// 获取当前的2D位置
func air530Z_Get2DPosition() (lat string, lon string, err error) {
	var bufLat, bufLon [64]byte
	ret := int(C.Air530Z_GetPos2D((*C.char)(unsafe.Pointer(&bufLat[0])), (*C.char)(unsafe.Pointer(&bufLon[0]))))
	if ret == -1 {
		return "", "", fmt.Errorf("未定位, 请稍后")
	}
	return C.GoString((*C.char)(unsafe.Pointer(&bufLat[0]))), C.GoString((*C.char)(unsafe.Pointer(&bufLon[0]))), nil
}
