services

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EarthRadius              = 6371000.0 // Earth radius in meters
	DefaultTxPower           = 14.0      // Default transmission power in dBm
	DefaultPathLossExponent  = 4.0       // Default path loss exponent
	DefaultReferenceDistance = 1.0       // Default reference distance in meters
)
View Source
const DefaultCacheTTL = time.Hour

DefaultCacheTTL is the default expiration time for all cache entries

Variables

View Source
var ErrCacheMiss = errors.New("cache miss")

ErrCacheMiss indicates that the requested key is not cached

Functions

func RegisterGlobal

func RegisterGlobal(parser devices.DeviceParser) error

RegisterGlobal registers a parser in the global registry

Types

type CircleIntersectionZone

type CircleIntersectionZone struct {
	CentroidX          float64
	CentroidY          float64
	Area               float64
	Valid              bool
	Confidence         float64      // 0-1 score based on intersection quality
	IntersectionPoints [][2]float64 // Actual intersection points for better centroid calculation
}

CircleIntersectionZone represents the intersection area between circles

type DeviceMappingCache

type DeviceMappingCache interface {
	Get(ctx context.Context, key string) (*models.DeviceMapping, error)
	Set(ctx context.Context, key string, mapping models.DeviceMapping) error
}

DeviceMappingCache defines the behaviour required for a cache backend

type DeviceProfileService

type DeviceProfileService struct {
	// contains filtered or unexported fields
}

DeviceProfileService handles device profile management

func NewDeviceProfileService

func NewDeviceProfileService() (*DeviceProfileService, error)

NewDeviceProfileService creates a new device profile service

func (*DeviceProfileService) Close added in v0.0.2

func (dps *DeviceProfileService) Close() error

Close closes the service and releases resources

func (*DeviceProfileService) GetAllDeviceModels added in v0.0.2

func (dps *DeviceProfileService) GetAllDeviceModels() []models.DeviceModel

GetAllDeviceModels returns all device models with manufacturer names resolved.

func (*DeviceProfileService) GetDeviceMapping

func (dps *DeviceProfileService) GetDeviceMapping(orgSlug, devEUI string) (*models.DeviceMapping, error)

func (*DeviceProfileService) GetManufacturerByID added in v0.0.2

func (dps *DeviceProfileService) GetManufacturerByID(manufacturerID string) (*models.Manufacturer, error)

GetManufacturerByID returns a manufacturer by ID

func (*DeviceProfileService) GetProfileByDeviceType added in v0.0.2

func (dps *DeviceProfileService) GetProfileByDeviceType(deviceType string) (*models.DeviceProfile, error)

GetProfileByDeviceType returns a device profile by device type

func (*DeviceProfileService) GetProfileByID added in v0.0.2

func (dps *DeviceProfileService) GetProfileByID(profileID string) (*models.DeviceProfile, error)

GetProfileByID returns a device profile by its UUID

func (*DeviceProfileService) ShouldSkipDevice

func (dps *DeviceProfileService) ShouldSkipDevice(orgSlug, devEUI string) (bool, error)

ShouldSkipDevice checks if a device should be skipped from processing.

type DeviceRegistryCache

type DeviceRegistryCache interface {
	// Existing DeviceMapping functionality for backward compatibility
	DeviceMappingCache

	// Org-aware Device Entry operations using interface{} to avoid circular imports
	GetDeviceEntry(ctx context.Context, org, deviceID string) (interface{}, error)
	SetDeviceEntry(ctx context.Context, org, deviceID string, device interface{}) error
	DeleteDeviceEntry(ctx context.Context, org, deviceID string) error

	// Fast org-specific identifier lookup
	GetDeviceByIdentifier(ctx context.Context, org, identifierType, key, value string) (string, error) // Returns deviceID
	SetIdentifierMapping(ctx context.Context, org, identifierType, key, value, deviceID string) error
	DeleteIdentifierMapping(ctx context.Context, org, identifierType, key, value string) error

	// Org-specific connection lookup
	GetDeviceByConnection(ctx context.Context, org, connectionType, value string) (string, error) // Returns deviceID
	SetConnectionMapping(ctx context.Context, org, connectionType, value, deviceID string) error
	DeleteConnectionMapping(ctx context.Context, org, connectionType, value string) error
}

DeviceRegistryCache interface - now enabled for Device Registry integration

func NewDeviceRegistryCacheFromEnv

func NewDeviceRegistryCacheFromEnv() DeviceRegistryCache

NewDeviceRegistryCacheFromEnv creates a Device Registry cache from environment variables

type LocationService

type LocationService struct{}

LocationService handles device location calculations

func NewLocationService

func NewLocationService() *LocationService

NewLocationService creates a new location service

func (*LocationService) CalculateDeviceLocation

func (ls *LocationService) CalculateDeviceLocation(payload map[string]interface{}) (*models.DeviceLocationData, error)

CalculateDeviceLocation calculates device location based on gateway data

func (*LocationService) CalculateDeviceLocationWithLNS added in v0.0.3

func (ls *LocationService) CalculateDeviceLocationWithLNS(payload map[string]interface{}, lnsType lns.LNSType) (*models.DeviceLocationData, error)

CalculateDeviceLocationWithLNS calculates device location using LNS-aware extraction

type LoggerConfig

type LoggerConfig struct {
	LogDir        string `mapstructure:"log_dir" env:"RAW_DATA_LOG_DIR"`
	EnableFileLog bool   `mapstructure:"enable_file_log" env:"RAW_DATA_ENABLE_FILE_LOG"`
	EnableJSONLog bool   `mapstructure:"enable_json_log" env:"RAW_DATA_ENABLE_JSON_LOG"`
	MaxFileSize   int64  `mapstructure:"max_file_size" env:"RAW_DATA_MAX_FILE_SIZE"`
}

LoggerConfig contains configuration for the logger service

type LoggerService

type LoggerService struct {
	// contains filtered or unexported fields
}

LoggerService handles raw data logging for training purposes

func NewLoggerService

func NewLoggerService(config LoggerConfig) (*LoggerService, error)

NewLoggerService creates a new logger service

func (*LoggerService) Close

func (ls *LoggerService) Close() error

Close closes the logger service and any open files

func (*LoggerService) LogRawData

func (ls *LoggerService) LogRawData(
	originalPayload map[string]interface{},
	decodedRawData interface{},
	processingInfo models.ProcessingInfo,
) error

LogRawData logs raw data for training purposes

type MessageProcessor

type MessageProcessor struct {
	// contains filtered or unexported fields
}

MessageProcessor handles enhanced message processing with Device Registry integration

func NewMessageProcessor

func NewMessageProcessor(registry *Registry) *MessageProcessor

NewMessageProcessor creates a new message processor

func (*MessageProcessor) CreateDeviceFromIdentifiers

func (mp *MessageProcessor) CreateDeviceFromIdentifiers(ctx context.Context, orgSlug string, identifiers []devices.DeviceIdentifier, payload map[string]interface{}) (*devices.DeviceEntry, error)

CreateDeviceFromIdentifiers creates a new device entry from identifiers

func (*MessageProcessor) DetermineDeviceType

func (mp *MessageProcessor) DetermineDeviceType(identifiers []devices.DeviceIdentifier, payload map[string]interface{}) devices.DeviceType

DetermineDeviceType determines device type from identifiers and payload

func (*MessageProcessor) GetParserForDevice

func (mp *MessageProcessor) GetParserForDevice(ctx context.Context, orgSlug string, device *devices.DeviceEntry) (devices.DeviceParser, error)

GetParserForDevice gets the appropriate parser for a device

func (*MessageProcessor) ProcessMessage

func (mp *MessageProcessor) ProcessMessage(ctx context.Context, orgSlug string, payload, locationPayload map[string]interface{}) (*ProcessingContext, error)

ProcessMessage processes an MQTT message using Device Registry

type PluginLoader

type PluginLoader struct {
	// contains filtered or unexported fields
}

PluginLoader handles dynamic loading of device parser plugins

func NewPluginLoader

func NewPluginLoader(pluginDir string, registry *Registry) *PluginLoader

NewPluginLoader creates a new plugin loader

func (*PluginLoader) LoadAll

func (pl *PluginLoader) LoadAll() error

LoadAll loads all plugins from the plugin directory

func (*PluginLoader) LoadPlugin

func (pl *PluginLoader) LoadPlugin(pluginPath string) error

LoadPlugin loads a single plugin file

func (*PluginLoader) LoadPluginFromPath

func (pl *PluginLoader) LoadPluginFromPath(pluginPath string) error

LoadPluginFromPath loads a plugin from an explicit path (outside plugin directory)

type ProcessingContext

type ProcessingContext struct {
	// Device identifiers
	Identifiers  []devices.DeviceIdentifier `json:"identifiers"`
	PrimaryID    string                     `json:"primary_id"`    // For Device Service API
	ProtocolType string                     `json:"protocol_type"` // "lorawan", "satellite", etc.

	// Device entries
	TechnicalDevice *devices.DeviceEntry  `json:"technical_device"` // From Device Registry (DEPRECATED)
	UnifiedDevice   *models.Device        `json:"unified_device"`   // New unified device model
	BusinessDevice  *models.DeviceMapping `json:"business_device"`  // Legacy - for backward compatibility

	// Processing state
	ShouldSkip   bool                 `json:"should_skip"`
	Organization string               `json:"organization"`
	Parser       devices.DeviceParser `json:"-"` // Selected parser
}

ProcessingContext combines all device information for message processing

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages all registered device parsers and device entries

func GetGlobalRegistry

func GetGlobalRegistry() *Registry

GetGlobalRegistry returns the global registry instance

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new device parser registry

func NewRegistryWithCache

func NewRegistryWithCache() *Registry

NewRegistryWithCache creates a new registry with Redis cache support

func (*Registry) DetectAndParse

func (r *Registry) DetectAndParse(ctx context.Context, payload *devices.RawPayload) (*devices.ParsedData, error)

DetectAndParse attempts to detect the device type and parse the payload It tries all registered parsers until one succeeds

func (*Registry) GetAllMetadata

func (r *Registry) GetAllMetadata() []devices.ParserMetadata

GetAllMetadata returns metadata for all registered parsers

func (*Registry) GetDevice

func (r *Registry) GetDevice(ctx context.Context, deviceID string) (*devices.DeviceEntry, error)

GetDevice retrieves a device by ID

func (*Registry) GetDeviceByConnections

func (r *Registry) GetDeviceByConnections(ctx context.Context, org string, connections []devices.DeviceConnection) (*devices.DeviceEntry, error)

GetDeviceByConnections implements connection lookup pattern

func (*Registry) GetDeviceByIdentifiers

func (r *Registry) GetDeviceByIdentifiers(ctx context.Context, org string, identifiers []devices.DeviceIdentifier) (*devices.DeviceEntry, error)

GetDeviceByIdentifiers implements multi-identifier lookup pattern

func (*Registry) GetParser

func (r *Registry) GetParser(deviceType devices.DeviceType) (devices.DeviceParser, error)

GetParser retrieves a parser by device type

func (*Registry) ListRegisteredParsers

func (r *Registry) ListRegisteredParsers() []devices.DeviceType

ListRegisteredParsers returns all registered device types

func (*Registry) ParseWithType

func (r *Registry) ParseWithType(ctx context.Context, payload *devices.RawPayload, deviceType devices.DeviceType) (*devices.ParsedData, error)

ParseWithType parses using a specific device type parser

func (*Registry) Register

func (r *Registry) Register(parser devices.DeviceParser) error

Register adds a device parser to the registry

func (*Registry) RegisterDevice

func (r *Registry) RegisterDevice(ctx context.Context, device *devices.DeviceEntry) error

RegisterDevice adds or updates a device entry in the registry

func (*Registry) Unregister

func (r *Registry) Unregister(deviceType devices.DeviceType)

Unregister removes a device parser from the registry

func (*Registry) UpdateDeviceLastSeen

func (r *Registry) UpdateDeviceLastSeen(ctx context.Context, deviceID string) error

UpdateDeviceLastSeen updates the last seen timestamp for a device

type TransformService

type TransformService struct {
	// contains filtered or unexported fields
}

TransformService handles data transformation

func NewTransformService

func NewTransformService(deviceProfileService *DeviceProfileService) *TransformService

NewTransformService creates a new transform service

func (*TransformService) TransformDeviceData

func (ts *TransformService) TransformDeviceData(deviceLocation *models.DeviceLocationData, gatewayCount int, originalPayload map[string]interface{}) (*models.TransformedDeviceData, error)

TransformDeviceData transforms device location data to the standardized output format

type UnifiedDeviceCache

type UnifiedDeviceCache interface {
	GetDevice(ctx context.Context, key string) (*models.Device, error)
	SetDevice(ctx context.Context, key string, device models.Device) error
}

UnifiedDeviceCache defines the cache interface for the unified Device model

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL