}
type RMRParams struct {
- Mtype int
- Payload []byte
- PayloadLen int
- Meid *RMRMeid
- Xid string
- SubId int
- Src string
- Mbuf *C.rmr_mbuf_t
+ Mtype int
+ Payload []byte
+ PayloadLen int
+ Meid *RMRMeid
+ Xid string
+ SubId int
+ Src string
+ Mbuf *C.rmr_mbuf_t
}
func NewRMRClient() *RMRClient {
meidBuf := make([]byte, int(C.RMR_MAX_MEID))
if meidCstr := C.rmr_get_meid(rxBuffer, (*C.uchar)(unsafe.Pointer(&meidBuf[0]))); meidCstr != nil {
- params.Meid.PlmnID = strings.TrimRight(string(meidBuf[0:16]), "\000")
- params.Meid.EnbID = strings.TrimRight(string(meidBuf[16:32]), "\000")
+ params.Meid.RanName = strings.TrimRight(string(meidBuf), "\000")
}
xidBuf := make([]byte, int(C.RMR_MAX_XID))
if buf == nil {
Logger.Error("rmrClient: Allocating message buffer failed!")
}
-
return buf
}
+func (m *RMRClient) Free(mbuf *C.rmr_mbuf_t) {
+ if mbuf == nil {
+ Logger.Error("rmrClient: Can't free mbuffer, given nil pointer")
+ return
+ }
+ C.rmr_free_msg(mbuf)
+}
+
func (m *RMRClient) SendMsg(params *RMRParams) bool {
return m.Send(params, false)
}
buf.mtype = C.int(params.Mtype)
buf.sub_id = C.int(params.SubId)
buf.len = C.int(len(params.Payload))
+ if params.PayloadLen != 0 {
+ buf.len = C.int(params.PayloadLen)
+ }
datap := C.CBytes(params.Payload)
defer C.free(datap)
if params != nil {
if params.Meid != nil {
b := make([]byte, int(C.RMR_MAX_MEID))
- copy(b, []byte(params.Meid.PlmnID))
- copy(b[16:], []byte(params.Meid.EnbID))
+ copy(b, []byte(params.Meid.RanName))
C.rmr_bytes2meid(buf, (*C.uchar)(unsafe.Pointer(&b[0])), C.int(len(b)))
}
xidLen := len(params.Xid)
}
func (m *RMRClient) SendBuf(txBuffer *C.rmr_mbuf_t, isRts bool) bool {
+ defer C.rmr_free_msg(txBuffer)
+ var currBuffer *C.rmr_mbuf_t
+
for i := 0; i < 10; i++ {
txBuffer.state = 0
if isRts {
- txBuffer = C.rmr_rts_msg(m.context, txBuffer)
+ currBuffer = C.rmr_rts_msg(m.context, txBuffer)
} else {
- txBuffer = C.rmr_send_msg(m.context, txBuffer)
+ currBuffer = C.rmr_send_msg(m.context, txBuffer)
}
- if txBuffer == nil {
+ if currBuffer == nil {
break
- } else if txBuffer.state != C.RMR_OK {
- if txBuffer.state != C.RMR_ERR_RETRY {
+ } else if currBuffer.state != C.RMR_OK {
+ if currBuffer.state != C.RMR_ERR_RETRY {
time.Sleep(100 * time.Microsecond)
m.UpdateStatCounter("TransmitError")
}
- for j := 0; j < 100 && txBuffer.state == C.RMR_ERR_RETRY; j++ {
- txBuffer = C.rmr_send_msg(m.context, txBuffer)
+ for j := 0; j < 100 && currBuffer.state == C.RMR_ERR_RETRY; j++ {
+ currBuffer = C.rmr_send_msg(m.context, txBuffer)
}
}
- if txBuffer.state == C.RMR_OK {
+ if currBuffer.state == C.RMR_OK {
m.UpdateStatCounter("Transmitted")
return true
}