kappanhang/txseqbuf.go
Birk da Yooper 7656d4335b Added flag to set alternate controller address
Added flag to show CI-V packet contents to support debugging

At start-up show virtual soundcard info by both name & filesystem location
Updated to always present status lines at bottom of the terminal
Removed milliseconds from time shown on status lines
Reformatted status line showing packet activity to be easier to follow
Adjusted default status update frequency to 150ms to be easier to observe

Restored commented out code for working with single VFO

Added multiple functions to handle BCD <-> human readable values to improve easy of maintenance
Added function to prepare CI-V packets, abstracting this step so that each function no longer
  needs to create entire packet. This makes the code much easier to follow and maintaint.
  This will also greatly ease effort needed for extending radio features supported

Added/adjusted various comments

Updated some variable names to be less terse to facilitate maintenance
  eg "incTS" to "incTuningStep"

Some adjustments to improve readability/ease maintenance in favor of unnecessary optimizations
  EG - using formatted prints instead of prints using concatenations
       using strings.Repeat instead of loop to build space buffers
       abstracted control char strings to variables

Hooks for future functionality

Removed some commented out code blocks
   "Trust the repo, Luke!"
2024-02-24 20:53:49 -05:00

60 lines
1.6 KiB
Go

package main
import "time"
// This value is sent to the transceiver and - according to my observations - it will use
// this as it's RX buf length. Note that if it is set to larger than 500-600ms then audio TX
// won't work (small radio memory?) - HA2NON
const txSeqBufLength = 300 * time.Millisecond
type txSeqBufEntry struct {
seq seqNum
data []byte
addedAt time.Time
}
type txSeqBufStruct struct {
entries []txSeqBufEntry
}
func (s *txSeqBufStruct) add(seq seqNum, p []byte) {
s.entries = append(s.entries, txSeqBufEntry{
seq: seq,
data: p,
addedAt: time.Now(),
})
s.purgeOldEntries()
}
func (s *txSeqBufStruct) purgeOldEntries() {
// previous comment:
// We keep much more entries than the specified length of the TX seqbuf, so we can serve
// any requests coming from the server.
//
// NOTE: need to wade deeper through the entire code base and see if the following is a more useful comment, or we need a better "why" here:
//
// Prune the oldest item in the txSeqBuf if it's older than ten time the txSeqBuf length... so "about 1 second"
// this enables serving any requests from the server, even if older than the max... up to a point
for len(s.entries) > 0 && time.Since(s.entries[0].addedAt) > txSeqBufLength*10 {
s.entries = s.entries[1:]
}
}
func (s *txSeqBufStruct) get(seq seqNum) (d []byte) {
if len(s.entries) == 0 {
return nil
}
// Searching from backwards, as we expect most queries for latest entries.
for i := len(s.entries) - 1; i >= 0; i-- {
if s.entries[i].seq == seq {
d = make([]byte, len(s.entries[i].data))
copy(d, s.entries[i].data)
break
}
}
s.purgeOldEntries()
return d
}