Skip to content

Commit 852ab98

Browse files
committed
Properly send EOT for MMDVM? Other cleanup.
1 parent e11afe0 commit 852ab98

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

cmd/m17-gateway/packaging/debian/postinst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ systemctl enable m17-gateway.service
6666
echo
6767
echo "M17 Gateway installed successfully!"
6868
echo "Configuration file: /etc/m17-gateway.ini"
69-
echo "View logs with: journalctl -u m17-gateway"
69+
echo "View logs with: journalctl -u m17-gateway -o cat -f"
7070
echo "Start with: sudo systemctl start m17-gateway"
7171
echo "Check status with: systemctl status m17-gateway"

codec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const (
1212
SymbolsPerSyncword = 8 //symbols per syncword
1313
SymbolsPerPayload = 184 //symbols per payload in a frame
1414
SymbolsPerFrame = 192 //symbols per whole 40 ms frame, 40ms * 4800 = 192
15+
BytesPerFrame = SymbolsPerFrame * BitsPerSymbol / 8
1516
BitsPerSymbol = 2
1617
BitsPerPayload = SymbolsPerPayload * BitsPerSymbol
1718
)

mmdvm_modem.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ type MMDVMModem struct {
131131
// protected by mutex
132132
exit bool
133133
lastStatusCheck time.Time
134+
lastTXData time.Time
134135
space int
135136
// end protected by mutex
136137

@@ -183,7 +184,8 @@ func NewMMDVMModem(
183184
}
184185

185186
m := &MMDVMModem{
186-
sendCmds: make(chan []byte, 20),
187+
sendCmds: make(chan []byte, 100), // 4 seconds
188+
lastTXData: time.Now(),
187189
config: MMDVMConfig{
188190
duplex: duplex,
189191
rxInvert: rxInvert,
@@ -363,7 +365,7 @@ func (m *MMDVMModem) modemReceive() {
363365
func (m *MMDVMModem) modemSend() {
364366
log.Printf("[DEBUG] modemSend starting")
365367
for !m.isExit() {
366-
if m.getSpace() > 1 /*|| m.protocolVersion == 1*/ {
368+
if m.getSpace() > 1 {
367369
_, err := m.port.Write(<-m.sendCmds)
368370
if err != nil {
369371
log.Printf("[WARN] modemSend: Error writing to modem: %v", err)
@@ -1007,14 +1009,30 @@ func (m *MMDVMModem) writeBits(typ byte, bits []Bit) {
10071009
cmd = append(cmd, buf...)
10081010
m.sendToModem(cmd)
10091011
}
1012+
10101013
func (m *MMDVMModem) writeEOT() {
10111014
// log.Printf("[DEBUG] writeEOT")
1012-
cmd := []byte{mmdvmFrameStart, 3, mmdvmM17EOT}
1015+
var buf []byte
1016+
for i := 0; i < BytesPerFrame/len(EOTMarkerBytes); i++ {
1017+
buf = append(buf, EOTMarkerBytes...)
1018+
}
1019+
cmd := []byte{mmdvmFrameStart, byte(4 + len(buf)), mmdvmM17EOT, 0}
1020+
cmd = append(cmd, buf...)
10131021
m.sendToModem(cmd)
10141022
}
10151023

10161024
func (m *MMDVMModem) sendToModem(cmd []byte) {
1017-
m.sendCmds <- cmd
1025+
select {
1026+
case m.sendCmds <- cmd:
1027+
// okay
1028+
since := time.Since(m.lastTXData)
1029+
if since > 100*time.Millisecond {
1030+
log.Printf("[DEBUG] Last TX data sent %v ago", since.Round(time.Millisecond))
1031+
}
1032+
m.lastTXData = time.Now()
1033+
default:
1034+
fmt.Println("[DEBUG] sendToModem message send failed")
1035+
}
10181036
}
10191037

10201038
func (m *MMDVMModem) getSpace() int {

0 commit comments

Comments
 (0)