Documentation
¶
Index ¶
Constants ¶
const ( ReadCoilsFunc = "ReadCoils" // 0x01 ReadDiscreteInputsFunc = "ReadDiscreteInputs" // 0x02 ReadHoldingRegistersFunc = "ReadHoldingRegisters" // 0x03 ReadInputRegistersFunc = "ReadInputRegisters" // 0x04 ByteOrderABCD = "ABCD" // Big-endian (standard network order) ByteOrderDCBA = "DCBA" // Little-endian (x86, ARM in little-endian mode) ByteOrderCDAB = "CDAB" // Middle-endian (PDP-style) ByteOrderBADC = "BADC" // Byte-swapped (less common, but used in some contexts) )
const ( BoolType = "bool" Int16Type = "int16" Int32Type = "int32" Uint16Type = "uint16" Uint32Type = "uint32" Float32Type = "float32" StringType = "string" )
Variables ¶
var ( ErrInvalidWriteValue = errors.New("invalid write value") ErrValueOutOfRange = errors.New("value out of range for type") )
Sentinel errors for write-request validation failures that the HTTP layer maps to 400 Bad Request, as opposed to operational failures (rate limiter, connection, device I/O) which stay 500.
var ClientOrderFields = map[string]string{
"id": "id",
"name": "LOWER(name)",
}
ClientOrderFields maps API-facing order keys to SQL column expressions for the modbus clients table.
Functions ¶
This section is empty.
Types ¶
type ClientRepository ¶
type ClientRepository interface {
// Save persists multiple Modbus clients.
// Clients are saved using a transaction.
// If one client fails, then none will be saved.
// Successful operation is indicated by non-nil error response.
Save(ctx context.Context, dls ...Client) ([]Client, error)
// RetrieveByThing retrieves clients related to
// a certain thing identified by a given ID.
RetrieveByThing(ctx context.Context, thingID string, pm PageMetadata) (ClientsPage, error)
// RetrieveByGroup retrieves Modbus clients related to
// a certain group identified by a given ID.
RetrieveByGroup(ctx context.Context, groupID string, pm PageMetadata) (ClientsPage, error)
// RetrieveByID retrieves a client having the provided ID.
RetrieveByID(ctx context.Context, id string) (Client, error)
// RetrieveAll retrieves all clients.
RetrieveAll(ctx context.Context) ([]Client, error)
// Update performs an update to the existing client.
// A non-nil error is returned to indicate operation failure.
Update(ctx context.Context, w Client) error
// Remove removes Modbus clients having the provided IDs.
Remove(ctx context.Context, ids ...string) error
// RemoveByThing removes Modbus clients related to
// a certain thing identified by a given thing ID.
RemoveByThing(ctx context.Context, thingID string) error
// RemoveByGroup removes Modbus clients related to
// a certain group identified by a given group ID.
RemoveByGroup(ctx context.Context, groupID string) error
}
type ClientsPage ¶
type ClientsPage struct {
PageMetadata
Clients []Client
}
type PageMetadata ¶ added in v0.39.0
type PageMetadata struct {
Total uint64 `json:"total,omitempty"`
Offset uint64 `json:"offset,omitempty"`
Limit uint64 `json:"limit,omitempty"`
Order string `json:"order,omitempty"`
Dir string `json:"dir,omitempty"`
Name string `json:"name,omitempty"`
IPAddress string `json:"ip_address,omitempty"`
Port string `json:"port,omitempty"`
SlaveID int64 `json:"slave_id,omitempty"`
Frequency string `json:"frequency,omitempty"`
}
PageMetadata contains page metadata that helps navigation.
type Publisher ¶ added in v0.42.0
type Publisher interface {
messaging.MessageDispatcher
}
Publisher specifies the minimal publishing capability the modbus service needs.
type ReadRequest ¶ added in v0.44.0
type ReadRequest struct {
IPAddress string
Port string
SlaveID uint8
FunctionCode string
DataFields []DataField
}
ReadRequest describes an ad hoc Modbus read against a device with no persisted client: connection info plus the fields to decode. Authorized by user token alone.
type Service ¶
type Service interface {
// CreateClients creates clients for certain thing identified by the thing ID.
CreateClients(ctx context.Context, token, thingID string, Clients ...Client) ([]Client, error)
// CreateClient creates a single client for the thing identified by the thing ID,
// with data fields parsed from an uploaded file.
CreateClient(ctx context.Context, token, thingID string, client Client) (Client, error)
// ListClientsByThing retrieves data about a subset of clients
// related to a certain thing.
ListClientsByThing(ctx context.Context, token, thingID string, pm PageMetadata) (ClientsPage, error)
// ListClientsByGroup retrieves data about a subset of clients
// related to a certain group.
ListClientsByGroup(ctx context.Context, token, groupID string, pm PageMetadata) (ClientsPage, error)
// ViewClient retrieves data about a client identified with the provided ID.
ViewClient(ctx context.Context, token, id string) (Client, error)
// ReadRegisters performs an immediate Modbus read against the given connection and
// decodes the requested data fields. No client is created or looked up; the token
// is only checked for validity, not against any specific resource.
ReadRegisters(ctx context.Context, token string, req ReadRequest) (map[string]any, error)
// WriteRegister performs an immediate Modbus write against the given connection.
// No client is created or looked up; the token is only checked for validity, not
// against any specific resource.
WriteRegister(ctx context.Context, token string, req WriteRequest) error
// UpdateClient updates client identified by the provided ID.
UpdateClient(ctx context.Context, token string, client Client) error
// RemoveClients removes clients identified with the provided IDs.
RemoveClients(ctx context.Context, token string, id ...string) error
// RemoveClientsByThing removes clients related to the specified thing,
// identified by the provided thing ID.
RemoveClientsByThing(ctx context.Context, thingID string) error
// RemoveClientsByGroup removes clients related to the specified group,
// identified by the provided group ID.
RemoveClientsByGroup(ctx context.Context, groupID string) error
// RescheduleTasks reschedules all tasks for things related to the specified profile ID.
RescheduleTasks(ctx context.Context, profileID string, config *domain.ProfileConfig) error
// LoadAndScheduleTasks loads schedulers and starts them to execute requests based on client configuration.
LoadAndScheduleTasks(ctx context.Context) error
}
Service specifies an API that must be fulfilled by the domain service implementation, and all of its decorators (e.g. logging & metrics). All methods that accept a token parameter use it to identify and authorize the user performing the operation.
func New ¶
func New(auth domain.AuthClient, things domain.ThingsClient, pub Publisher, clients ClientRepository, idp uuid.IDProvider, logger logger.Logger) Service
type WriteRequest ¶ added in v0.44.0
type WriteRequest struct {
IPAddress string
Port string
SlaveID uint8
Address uint16
Type string
ByteOrder string
Scale float64
Value any
}
WriteRequest describes an ad hoc Modbus write against a device with no persisted client. The write function code is derived from Type, not from any FunctionCode. Authorized by user token alone.