2015-08-14 15:53:08 +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.
|
|
|
|
|
|
|
|
// Package dump978 wraps libdump978, a 978MHz UAT demodulator.
|
|
|
|
|
|
|
|
package dump978
|
|
|
|
|
|
|
|
import (
|
2015-08-21 08:49:18 +00:00
|
|
|
"fmt"
|
2015-08-14 15:53:08 +00:00
|
|
|
"reflect"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "dump978/dump978.h"
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
2015-08-21 08:49:18 +00:00
|
|
|
// OutChan is a buffered output channel for demodulated data.
|
|
|
|
var OutChan = make(chan string, 100)
|
2015-08-14 15:53:08 +00:00
|
|
|
|
2015-08-19 06:32:11 +00:00
|
|
|
//export dump978Cb
|
|
|
|
func dump978Cb(updown C.char, data *C.uint8_t, length C.int) {
|
2015-08-14 15:53:08 +00:00
|
|
|
// c buffer to go slice without copying
|
|
|
|
var buf []byte
|
2015-08-21 08:49:18 +00:00
|
|
|
|
|
|
|
b := (*reflect.SliceHeader)((unsafe.Pointer(&buf)))
|
2015-08-14 15:53:08 +00:00
|
|
|
b.Cap = int(length)
|
|
|
|
b.Len = int(length)
|
|
|
|
b.Data = uintptr(unsafe.Pointer(data))
|
|
|
|
|
|
|
|
// copy incoming to outgoing
|
2015-08-21 08:49:18 +00:00
|
|
|
outData := string(updown)
|
|
|
|
for i := 0; i < int(length); i++ {
|
|
|
|
outData += fmt.Sprintf("%02x", buf[i])
|
|
|
|
}
|
|
|
|
|
2015-08-14 15:53:08 +00:00
|
|
|
OutChan <- outData
|
|
|
|
}
|