mirror of
https://github.com/dpup/meshstream.git
synced 2026-08-12 11:42:53 +02:00
Another checkpoint moving to proto defined packets
This commit is contained in:
+23
-23
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/dpup/prefab/logging"
|
||||
|
||||
pb "meshstream/proto/generated/meshtastic"
|
||||
pb "meshstream/generated/meshtastic"
|
||||
)
|
||||
|
||||
// MessageLogger logs messages using the provided logger
|
||||
@@ -44,23 +44,23 @@ func NewMessageLogger(broker *Broker, briefMode bool, logger logging.Logger) (*M
|
||||
func (ml *MessageLogger) getBriefSummary(packet *Packet) string {
|
||||
var summary string
|
||||
|
||||
if packet.DecodedPacket.DecodeError != nil {
|
||||
return fmt.Sprintf("Error decoding packet: %v", packet.DecodedPacket.DecodeError)
|
||||
if packet.Data.DecodeError != "" {
|
||||
return fmt.Sprintf("Error decoding packet: %v", packet.Data.DecodeError)
|
||||
}
|
||||
|
||||
// Create a basic summary based on the port type
|
||||
switch packet.PortNum {
|
||||
switch packet.Data.PortNum {
|
||||
case pb.PortNum_TEXT_MESSAGE_APP:
|
||||
// For text messages, include the text content
|
||||
if text, ok := packet.Payload.(string); ok {
|
||||
summary = fmt.Sprintf("Text message: %s", text)
|
||||
if packet.Data.GetTextMessage() != "" {
|
||||
summary = fmt.Sprintf("Text message: %s", packet.Data.GetTextMessage())
|
||||
} else {
|
||||
summary = "Text message (invalid format)"
|
||||
}
|
||||
|
||||
case pb.PortNum_POSITION_APP:
|
||||
// For position messages, include a compact location summary
|
||||
if pos, ok := packet.Payload.(*pb.Position); ok {
|
||||
if pos := packet.Data.GetPosition(); pos != nil {
|
||||
lat := float64(pos.GetLatitudeI()) / 10000000.0
|
||||
lon := float64(pos.GetLongitudeI()) / 10000000.0
|
||||
summary = fmt.Sprintf("Position: %.5f, %.5f", lat, lon)
|
||||
@@ -70,7 +70,7 @@ func (ml *MessageLogger) getBriefSummary(packet *Packet) string {
|
||||
|
||||
case pb.PortNum_TELEMETRY_APP:
|
||||
// For telemetry, give a short summary of what's included
|
||||
if telemetry, ok := packet.Payload.(*pb.Telemetry); ok {
|
||||
if telemetry := packet.Data.GetTelemetry(); telemetry != nil {
|
||||
parts := []string{}
|
||||
if telemetry.GetEnvironmentMetrics() != nil {
|
||||
parts = append(parts, "environment")
|
||||
@@ -88,7 +88,7 @@ func (ml *MessageLogger) getBriefSummary(packet *Packet) string {
|
||||
|
||||
default:
|
||||
// For other types, just mention the port type
|
||||
summary = fmt.Sprintf("Message type: %s", packet.PortNum.String())
|
||||
summary = fmt.Sprintf("Message type: %s", packet.Data.PortNum.String())
|
||||
}
|
||||
|
||||
return summary
|
||||
@@ -100,30 +100,30 @@ func (ml *MessageLogger) logMessage(packet *Packet) {
|
||||
briefSummary := ml.getBriefSummary(packet)
|
||||
|
||||
// Build the message prefix with type and GatewayID info for brief mode
|
||||
typePrefix := fmt.Sprintf("[%s]", packet.PortNum.String())
|
||||
if packet.GatewayID != "" {
|
||||
briefSummary = fmt.Sprintf("%s Gateway:%s %s", typePrefix, packet.GatewayID, briefSummary)
|
||||
typePrefix := fmt.Sprintf("[%s]", packet.Data.PortNum.String())
|
||||
if packet.Data.GatewayId != "" {
|
||||
briefSummary = fmt.Sprintf("%s Gateway:%s %s", typePrefix, packet.Data.GatewayId, briefSummary)
|
||||
} else {
|
||||
briefSummary = fmt.Sprintf("%s %s", typePrefix, briefSummary)
|
||||
}
|
||||
|
||||
if ml.briefMode {
|
||||
fields := []interface{}{
|
||||
"portNum", packet.PortNum.String(),
|
||||
"from", packet.From,
|
||||
"to", packet.To,
|
||||
"gateway", packet.GatewayID,
|
||||
"channel", packet.TopicInfo.Channel,
|
||||
"region", packet.TopicInfo.RegionPath,
|
||||
"hopLimit", packet.HopLimit,
|
||||
"id", packet.ID,
|
||||
"portNum", packet.Data.PortNum.String(),
|
||||
"from", packet.Data.From,
|
||||
"to", packet.Data.To,
|
||||
"gateway", packet.Data.GatewayId,
|
||||
"channel", packet.Info.Channel,
|
||||
"region", packet.Info.RegionPath,
|
||||
"hopLimit", packet.Data.HopLimit,
|
||||
"id", packet.Data.Id,
|
||||
}
|
||||
if packet.DecodedPacket.DecodeError != nil {
|
||||
fields = append(fields, "error", packet.DecodedPacket.DecodeError.Error())
|
||||
if packet.Data.DecodeError != "" {
|
||||
fields = append(fields, "error", packet.Data.DecodeError)
|
||||
}
|
||||
ml.logger.Infow(briefSummary, fields...)
|
||||
} else {
|
||||
ml.logger.Infow(briefSummary, "packet", packet)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user