2015-08-30 20:01:41 +00:00
|
|
|
// Copyright (c) 2015 Joseph D Poirier
|
|
|
|
// Distributable under the terms of The New BSD License
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
2015-09-03 17:17:15 +00:00
|
|
|
// Package godump978 wraps libdump978, a 978MHz UAT demodulator.
|
2015-08-30 20:01:41 +00:00
|
|
|
|
2015-09-03 17:17:15 +00:00
|
|
|
package godump978
|
2015-08-30 20:01:41 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"unsafe"
|
2015-09-22 04:04:59 +00:00
|
|
|
"strconv"
|
2015-08-30 20:01:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <stdint.h>
|
2015-09-03 17:17:15 +00:00
|
|
|
#include "../dump978/dump978.h"
|
2015-08-30 20:01:41 +00:00
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
// OutChan is a buffered output channel for demodulated data.
|
|
|
|
var OutChan = make(chan string, 100)
|
|
|
|
|
|
|
|
//export dump978Cb
|
2015-09-22 01:03:32 +00:00
|
|
|
func dump978Cb(updown C.char, data *C.uint8_t, length C.int, rs_errors C.int, signal_strength C.int) {
|
2015-08-30 20:01:41 +00:00
|
|
|
// c buffer to go slice without copying
|
|
|
|
var buf []byte
|
|
|
|
|
|
|
|
b := (*reflect.SliceHeader)((unsafe.Pointer(&buf)))
|
|
|
|
b.Cap = int(length)
|
|
|
|
b.Len = int(length)
|
|
|
|
b.Data = uintptr(unsafe.Pointer(data))
|
|
|
|
|
|
|
|
// copy incoming to outgoing
|
|
|
|
outData := string(updown)
|
|
|
|
for i := 0; i < int(length); i++ {
|
|
|
|
outData += fmt.Sprintf("%02x", buf[i])
|
|
|
|
}
|
|
|
|
|
2015-09-22 04:04:59 +00:00
|
|
|
outData += ";rs=" + strconv.Itoa(int(rs_errors)) + ";ss=" + strconv.Itoa(int(signal_strength)) + ";"
|
|
|
|
|
2015-08-30 20:01:41 +00:00
|
|
|
OutChan <- outData
|
|
|
|
}
|