Added received time and APRS API
Some checks failed
Test and build / Test and lint (push) Failing after 35s
Test and build / Build collector (push) Failing after 34s
Test and build / Build receiver (push) Failing after 35s

This commit is contained in:
2026-03-05 16:11:24 +01:00
parent 13afa08e8a
commit 7a8d7b0275
3 changed files with 86 additions and 72 deletions

View File

@@ -2,7 +2,6 @@ package schema
import (
"context"
"database/sql"
"os"
"strings"
"time"
@@ -21,8 +20,8 @@ type APRSStation struct {
Symbol string `xorm:"varchar(2)" json:"symbol"`
FirstHeardAt time.Time `xorm:"timestamp not null"`
LastHeardAt time.Time `xorm:"timestamp not null"`
LastLatitude sql.NullFloat64
LastLongitude sql.NullFloat64
LastLatitude *float64 `xorm:"numeric(10,8)" json:"latitude,omitempty"`
LastLongitude *float64 `xorm:"numeric(11,8)" json:"longitude,omitempty"`
}
func GetAPRSStation(ctx context.Context, call string) (*APRSStation, error) {
@@ -46,20 +45,20 @@ func (station APRSStation) GetPackets(ctx context.Context) ([]*APRSPacket, error
}
type APRSPacket struct {
ID int64 `xorm:"pk autoincr" json:"id"`
RadioID int64 `xorm:"index" json:"radio_id"`
Radio Radio `json:"radio"`
StationID int64 `json:"-"`
Station *APRSStation `xorm:"-" json:"station"`
Source string `xorm:"varchar(10) not null" json:"src"`
Destination string `xorm:"varchar(10) not null" json:"dst"`
Path string `xorm:"varchar(88) not null default ''" json:"path"`
Comment string `xorm:"varchar(250)" json:"comment"`
Latitude sql.NullFloat64 `json:"latitude,omitempty"`
Longitude sql.NullFloat64 `json:"longitude,omitempty"`
Symbol string `xorm:"varchar(2)" json:"symbol"`
Raw string `json:"raw"`
ReceivedAt time.Time `json:"received_at"`
ID int64 `xorm:"pk autoincr" json:"id"`
RadioID int64 `xorm:"index" json:"radio_id"`
Radio *Radio `xorm:"-" json:"radio"`
StationID int64 `json:"-"`
Source string `xorm:"varchar(10) not null" json:"src"`
Destination string `xorm:"varchar(10) not null" json:"dst"`
Path string `xorm:"varchar(88) not null default ''" json:"path"`
Comment string `xorm:"varchar(250)" json:"comment"`
Latitude *float64 `xorm:"numeric(10,8)" json:"latitude,omitempty"`
Longitude *float64 `xorm:"numeric(11,8)" json:"longitude,omitempty"`
Symbol string `xorm:"varchar(2)" json:"symbol"`
Raw string `json:"raw"`
ReceivedAt time.Time `json:"received_at"`
//Station *APRSStation `xorm:"-" json:"station"`
}
func GetAPRSPackets(ctx context.Context, limit int) ([]*APRSPacket, error) {

View File

@@ -3,6 +3,7 @@ package schema
import (
"context"
"database/sql"
"fmt"
"time"
"github.com/sirupsen/logrus"
@@ -89,7 +90,11 @@ func Open(driver, config string) error {
names.LintGonicMapper[name] = true
}
xormEngine.SetMapper(names.GonicMapper{})
xormEngine.SetLogger(xormLogger{})
logger := &xormLogger{}
//logger.SetLevel(log.LOG_DEBUG)
xormEngine.SetLogger(logger)
xormEngine.ShowSQL(true)
for _, model := range registeredModels {
Logger.Debugf("schema: sync schema %T", model)
@@ -136,10 +141,32 @@ func NULLTime(t time.Time) *time.Time {
return &t
}
type xormLogger struct{}
type xormLogger struct {
showSQL bool
}
func (l xormLogger) BeforeSQL(ctx log.LogContext) {
var sessionPart string
v := ctx.Ctx.Value(log.SessionIDKey)
if key, ok := v.(string); ok {
sessionPart = fmt.Sprintf(" [%s]", key)
}
Logger.Debugf("[SQL (before)]%s %s %v", sessionPart, ctx.SQL, ctx.Args)
}
func (l xormLogger) AfterSQL(ctx log.LogContext) {
var sessionPart string
v := ctx.Ctx.Value(log.SessionIDKey)
if key, ok := v.(string); ok {
sessionPart = fmt.Sprintf(" [%s]", key)
}
if ctx.ExecuteTime > 0 {
Logger.Infof("[SQL (after)]%s %s %v - %v", sessionPart, ctx.SQL, ctx.Args, ctx.ExecuteTime)
} else {
Logger.Infof("[SQL (after)]%s %s %v", sessionPart, ctx.SQL, ctx.Args)
}
} // only invoked when IsShowSQL is true
func (l xormLogger) BeforeSQL(context log.LogContext) {} // only invoked when IsShowSQL is true
func (l xormLogger) AfterSQL(context log.LogContext) {} // only invoked when IsShowSQL is true
func (l xormLogger) Debug(args ...any) { Logger.Debug(append([]any{"engine: "}, args...)...) }
func (l xormLogger) Debugf(format string, args ...any) { Logger.Debugf("engine: "+format, args...) }
func (l xormLogger) Error(args ...any) { Logger.Error(append([]any{"engine: "}, args...)...) }
@@ -181,12 +208,14 @@ func (l xormLogger) SetLevel(level log.LogLevel) {
}
}
func (l xormLogger) ShowSQL(show ...bool) {
_ = show
func (l *xormLogger) ShowSQL(show ...bool) {
if len(show) > 0 {
l.showSQL = show[0]
}
}
func (l xormLogger) IsShowSQL() bool {
return false
return l.showSQL
}
var _ log.ContextLogger = (*xormLogger)(nil)