model

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReadPermission  = 0x0001 // Required to find or play media.
	WritePermission = 0x0002 // Required to update media.
	AdminPermission = 0x0004 // Required to create or delete media.
	SuperPermission = 0x0100 // Required to modify other's credentials.
)

Variables

View Source
var (
	ErrWrongNumParts = errors.New("wrong number of values for actuator")
	ErrSKeyParse     = errors.New("cannot parse site key for actuator")
)

Actuator errors.

View Source
var (
	ErrDeviceNotEnabled   = errors.New("device not enabled")
	ErrDeviceNotFound     = errors.New("device not found")
	ErrMissingDeviceKey   = errors.New("missing device key")
	ErrMalformedDeviceKey = errors.New("malformed device key")
	ErrInvalidDeviceKey   = errors.New("invalid device key")
	ErrInvalidMACAddress  = errors.New("invalid MAC address")
)
View Source
var (
	ErrInvalidMID          = errors.New("invalid MID")
	ErrIdenticalTimestamps = errors.New("too many identical timestamps")
	ErrInvalidRanges       = errors.New("cannot have both geohash and timestamp ranges")
	ErrInvalidKeyName      = errors.New("malformed MtsMedia key name")
	ErrMediaNotFound       = errors.New("media not found")
	ErrInvalidMtsPackets   = errors.New("clip contains invalid MTS packets")
	ErrNoMtsPackets        = errors.New("clip contains no MTS packets")
	ErrNoMediaPID          = errors.New("no media PID found")
)
View Source
var (
	ErrUnexpectedArgs      = errors.New("unexpected number of args")
	ErrArgParse            = errors.New("could not parse argument")
	ErrUnrecognisedFunc    = errors.New("unrecognised function key")
	ErrEvaluableExpression = &errEvaluableExpression{}
	ErrEvaluate            = &errEvaluate{}
)

Exported errors.

View Source
var ErrInvalidTime = errors.New("invalid time")

Functions

func ComputeVarSum

func ComputeVarSum(vars []Variable) int64

ComputeVarSum computes the var sum from a slice of variables. The var sum is a IEEE CRC checksum 32-bit signed integer of the name/value variable pairs concanentated with ampersands, i.e., var1=val1&var2=val2&var3=val3...

func CreateSite

func CreateSite(ctx context.Context, store datastore.Store, site *Site) error

CreateSite creates a site, or returns an error if a site with the given key exists.

func DeleteActuator

func DeleteActuator(ctx context.Context, store datastore.Store, aid string) error

DeleteActuator deletes and actuator from the datastore given its actuator ID.

func DeleteActuatorV2

func DeleteActuatorV2(ctx context.Context, store datastore.Store, mac int64, pin string) error

DeleteActuatorV2 deletes an actuator.

func DeleteCredential

func DeleteCredential(ctx context.Context, store datastore.Store, mid int64, name string) error

DeleteCredential deletes a single credential.

func DeleteCredentials

func DeleteCredentials(ctx context.Context, store datastore.Store, name string) error

DeleteCredentials deletes all credential for a given name.

func DeleteCron

func DeleteCron(ctx context.Context, store datastore.Store, skey int64, id string) error

DeleteCron deletes a cron.

func DeleteDevice

func DeleteDevice(ctx context.Context, store datastore.Store, mac int64) error

DeleteDevice deletes a device.

func DeleteMtsMedia

func DeleteMtsMedia(ctx context.Context, store datastore.Store, mid int64) error

DeleteMtsMedia deletes all MTS media for a given Media ID.

func DeleteScalars

func DeleteScalars(ctx context.Context, store datastore.Store, id int64) error

DeleteScalar deletes all scalars for a given ID.

func DeleteSensor

func DeleteSensor(ctx context.Context, store datastore.Store, sKey int64, sid string) error

DeleteSensor deletes a Sensor entity given the site key and sensor ID.

func DeleteSensorV2

func DeleteSensorV2(ctx context.Context, store datastore.Store, mac int64, pin string) error

DeleteSensorV2 deletes a sensor.

func DeleteSite

func DeleteSite(ctx context.Context, store datastore.Store, skey int64) error

DeleteSite deletes a site.

func DeleteText

func DeleteText(ctx context.Context, store datastore.Store, mid int64) error

DeleteText deletes all text for a given Media ID.

func DeleteUser

func DeleteUser(ctx context.Context, store datastore.Store, skey int64, email string) error

DeleteUser deletes a user.

func DeleteVariable

func DeleteVariable(ctx context.Context, store datastore.Store, skey int64, name string) error

DeleteVariable deletes a variable. Ignore colons in the scope.

func DeleteVariables

func DeleteVariables(ctx context.Context, store datastore.Store, skey int64, scope string) error

DeleteVariables deletes all variables for a given scope. Ignore colons in the scope.

func FromMID

func FromMID(mid int64) (string, string)

FromMID returns a MAC address and pin given a Media ID.

func FromSID

func FromSID(id int64) (string, string)

FromSID returns a MAC address and pin given a Scalar ID.

func GetMtsMediaKeys

func GetMtsMediaKeys(ctx context.Context, store datastore.Store, mid int64, gh []string, ts []int64) ([]*datastore.Key, error)

GetMtsMediaKeys retrieves MtsMedia keys for a given Media ID, optionally filtered by timestamp(s) and geohash(es).

func GetScalarKeys

func GetScalarKeys(ctx context.Context, store datastore.Store, id int64, ts []int64) ([]*datastore.Key, error)

GetScalarKeys is similiar to GetScalars, but returns the keys rather than the entities.

func GetSiteName

func GetSiteName(ctx context.Context, store datastore.Store, skey int64) (string, error)

GetSiteName is a helper function that returns the site name string given the site key.

func GetTextKeys

func GetTextKeys(ctx context.Context, store datastore.Store, mid int64, ts []int64) ([]*datastore.Key, error)

GetTextKeys retrieves text keys for a given Media ID, optionally filtered by timestamp(s).

func GetVarSum

func GetVarSum(ctx context.Context, store datastore.Store, skey int64, scope string) (int64, error)

GetVarSum gets the varsum for a given scope, and saves it as the system variable named "_varsum.<scope>". Note that the varsum is itself stored in the datastore not in memory, since it can be mutated any time by another datastore client. If the var sum is not found it is recomputed and saved.

func HasPermission

func HasPermission(ctx context.Context, store datastore.Store, mid int64, email string, perm int64) bool

HasPermission returns true if the user's email address or domain has the requested permission for the given MID. Note that the permission for a user (i.e., one associated with an email address) takes priority over the permission for a domain. This means that a particular user may have write or admin permission whereas other users in the domain are limited to read permissions. The single-character name "@" represents any domain, effectively granting public access.

func IsMacAddress

func IsMacAddress(mac string) bool

IsMacAddress returns true if mac is a valid IPv4 MAC address, optionally colon-separated, false otherwise. False is returned for "00:00:00:00:00:00".

func MacDecode

func MacDecode(enc int64) string

MacDecode decodes a network-endian int64 as a colon-separated MAC address string, e.g., 1 is decoded as "00:00:00:00:00:01". Zero is an invalid encoding and the empty string is returned instead of 00:00:00:00:00:00.

func MacEncode

func MacEncode(mac string) int64

MacEncode encodes a MAC address string, optionally colon-separated, as a network-endian int64, e.g., "00:00:00:00:00:01" and "000000000001" are both encoded as 1. Returns 0 for an invalid MAC address.

func PTSToSeconds

func PTSToSeconds(pts int64) float64

PTSToSeconds converts a duration in MPEG-TS Presentation Time Stamp (PTS) units to seconds.

func PutActuator

func PutActuator(ctx context.Context, store datastore.Store, act *Actuator) error

PutActuator puts an actuator in the datastore.

func PutActuatorV2

func PutActuatorV2(ctx context.Context, store datastore.Store, act *ActuatorV2) error

PutActuatorV2 creates/updates an actuator.

func PutCredential

func PutCredential(ctx context.Context, store datastore.Store, c *Credential) error

PutCredential creates or updates a Credential using MID.Name as the key.

func PutCron

func PutCron(ctx context.Context, store datastore.Store, c *Cron) error

PutCron creates or updates a cron.

func PutDevice

func PutDevice(ctx context.Context, store datastore.Store, dev *Device) error

PutDevice creates or updates a device.

func PutMedia

func PutMedia(ctx context.Context, store datastore.Store, m *Media) error

PutMedia creates or updates media.

func PutScalar

func PutScalar(ctx context.Context, store datastore.Store, s *Scalar) error

PutScalar writes a scalar.

func PutSensor

func PutSensor(ctx context.Context, store datastore.Store, s *Sensor) error

PutSensor puts a Sensor entity into the datastore.

func PutSensorV2

func PutSensorV2(ctx context.Context, store datastore.Store, s *SensorV2) error

PutSensorV2 creates/updates a sensor.

func PutSite

func PutSite(ctx context.Context, store datastore.Store, site *Site) error

PutSite creates or updates a site.

func PutUser

func PutUser(ctx context.Context, store datastore.Store, user *User) error

PutUser creates or updates a user.

func PutVariable

func PutVariable(ctx context.Context, store datastore.Store, skey int64, name, value string) error

PutVariable creates or updates a variable Strip any colons from the scope.

func RegisterEntities

func RegisterEntities()

RegisterEntities is a convenience function that registers all of the datastore entities in one go.

func SensorFormats

func SensorFormats() []string

SensorFormats returns a list of available formats for formatting sensor values.

func SensorFuncs

func SensorFuncs() []string

SensorFuncs returns a list of the funcs that can be selected for value transformation through Sensor entities.

func ToMID

func ToMID(mac, pin string) int64

ToMID returns a Media ID given a MAC address and a pin. It is formed from the 48-bit integer encoding of the mac (see MacEncode) followed by the 4-bit encoding of the pin.

func ToSID

func ToSID(mac, pin string) int64

ToSID produces a Scalar ID from a MAC address and pin. Unlike Media IDs, the pin is represented by 8 bits in order to accommodate 2-digit pin numbers.

func UpdateMtsMedia

func UpdateMtsMedia(ctx context.Context, store datastore.Store, m MtsMedia, pid uint16) error

UpdateMtsMedia deletes a MTS media and creates a new one in its place.

func WriteMtsMedia

func WriteMtsMedia(ctx context.Context, store datastore.Store, m *MtsMedia) error

WriteMtsMedia stores MTS (MPEG-TS) data (i.e, audio/video data), splitting it into 1MB chunks and/or at discontinuities. Note: this function currently will only write media from one elementary stream in the program.

func WriteText

func WriteText(ctx context.Context, store datastore.Store, t *Text) error

WriteText writes text to the datastore.

Types

type Actuator

type Actuator struct {
	SKey int64  `datastore:"Skey"` // Site key.
	AID  string `datastore:"Aid"`  // Actuator ID.
	Var  string // The variable whose value is applied to the pin.
	Pin  string // The device pin actuated represented as <DeviceID>.<Pin>.
}

Actuator represents an actuator datastore type to link a device output with a variable such that that variable value changes the physical device output value. NB: This type is deprecated. See ActuatorV2.

func GetActuatorByPin

func GetActuatorByPin(ctx context.Context, store datastore.Store, skey int64, did string, pin string) ([]Actuator, error)

GetActuatorByPin gets an actuator for device did and with pin. NB: Filter fields must be datastore field names!

func GetActuatorsBySite

func GetActuatorsBySite(ctx context.Context, store datastore.Store, sKey int64, devID string) ([]Actuator, error)

GetActuatorsBySite returns the actuators associated with a site optionally filtered by device. Provide "" for no filtering.

func (*Actuator) Copy

Copy is not currently implemented.

func (*Actuator) Decode

func (a *Actuator) Decode(b []byte) error

Decode deserializes an Actuator from tab-separated values.

func (*Actuator) Encode

func (a *Actuator) Encode() []byte

Encode serializes an Actuator into tab-separated values.

func (*Actuator) GetCache

func (a *Actuator) GetCache() datastore.Cache

GetCache returns nil, indicating no caching.

type ActuatorV2

type ActuatorV2 struct {
	Name string // Name of actuator (mutable).
	Mac  int64  // MAC address of associated device (immutable).
	Pin  string // Pin of associated device (immutable).
	Var  string // Relative name of device variable (mutable).
}

ActuatorV2 defines a version 2 actuator. An actuator sends the value of a variable to a device's output pin. The key is the MAC address concatenated with the pin. Version 2 actuators do not have a site key, but are linked to a site indirectly via their device. The variable name is relative to the device, not a full variable name.

func GetActuatorV2

func GetActuatorV2(ctx context.Context, store datastore.Store, mac int64, pin string) (*ActuatorV2, error)

GetActuatorV2 gets an actuator.

func GetActuatorsV2

func GetActuatorsV2(ctx context.Context, store datastore.Store, mac int64) ([]ActuatorV2, error)

GetActuatorsV2 gets all actuators for a device.

func (*ActuatorV2) Copy

func (a *ActuatorV2) Copy(dst datastore.Entity) (datastore.Entity, error)

Copy copies an actuator to dst, or returns a copy of the acuator when dst is nil.

func (*ActuatorV2) Decode

func (a *ActuatorV2) Decode(b []byte) error

Decode decodes an actuator from JSON.

func (*ActuatorV2) Encode

func (a *ActuatorV2) Encode() []byte

Encode encodes an actuator as JSON.

func (*ActuatorV2) GetCache

func (s *ActuatorV2) GetCache() datastore.Cache

GetCache returns the actuator cache.

type BinaryData

type BinaryData struct {
	Mac       int64
	Timestamp int64
	Fmt       string
	Data      []byte
	Pin       string
	Date      time.Time
}

BinaryData a cloud type for storing binary data.

func GetBinaryData

func GetBinaryData(ctx context.Context, store datastore.Store, mid int64, ts []int64) ([]BinaryData, error)

GetBinaryData retreives BinaryData entities for a given media ID, optionally filtered by timestamp(s). If ts is given with len(ts) == 1, then a single entity with the matching timestamp will be returned. If the ts is given with len(ts) == 2 then multiple entities corresponding to the range of ts[0] to ts[1] will be given.

type Credential

type Credential struct {
	MID     int64     // Media ID.
	Name    string    // User name, email address, group or domain.
	Perm    int64     // Permissions.
	Created time.Time // Date/time created.
}

Credential represents a user credential to access media. One credential exists for each media item for which a user, group or domain is permitted access. The same user/group/domain may have different credentials for different media, for example, have write access for one media item but only have read access for another.

func GetCredential

func GetCredential(ctx context.Context, store datastore.Store, mid int64, name string) (*Credential, error)

GetCredential returns a Credential for given a MID and name.

func GetCredentialsByMID

func GetCredentialsByMID(ctx context.Context, store datastore.Store, mid int64) ([]Credential, error)

GetCredentialsByMID returns all credentials for a given MID.

func GetCredentialsByName

func GetCredentialsByName(ctx context.Context, store datastore.Store, name string) ([]Credential, error)

GetCredentialsByName returns all credentials for a given name.

func (*Credential) Copy

Copy is not currently implemented.

func (*Credential) Decode

func (c *Credential) Decode(b []byte) error

Decode deserializes a Credential from tab-separated values.

func (*Credential) Encode

func (c *Credential) Encode() []byte

Encode serializes a Credential into tab-separated values.

func (*Credential) GetCache

func (c *Credential) GetCache() datastore.Cache

GetCache returns nil, indicating no caching.

func (*Credential) IsAdmin

func (c *Credential) IsAdmin() bool

IsAdmin returns true for a credential with admin permissions.

func (*Credential) IsReadable

func (c *Credential) IsReadable() bool

IsReadable returns true for a credential with read permissions.

func (*Credential) IsSuper

func (c *Credential) IsSuper() bool

IsSuper returns true for a credential with super permissions.

func (*Credential) IsWritable

func (c *Credential) IsWritable() bool

IsWritable returns true for a credential with write permissions.

type Cron

type Cron struct {
	Skey    int64     // Site key.
	ID      string    // Cron ID.
	Time    time.Time // Cron time.
	TOD     string    // Symbolic time of day, e.g., "Sunset", or repeating time "*30".
	Repeat  bool      // True if repeating time.
	Minutes int64     // Minutes since start of UTC day or repeat minutes.
	Action  string    // Action to be performed
	Var     string    // Action variable (if any).
	Data    string    `datastore:",noindex"` // Action data (if any).
	Enabled bool      // True if enabled, false otherwise.
}

Cron represents a cloud cron which perform actions at specified times (to the nearest minute).

func GetCron

func GetCron(ctx context.Context, store datastore.Store, skey int64, id string) (*Cron, error)

GetCron gets a cron.

func GetCronsBySite

func GetCronsBySite(ctx context.Context, store datastore.Store, skey int64) ([]Cron, error)

GetCronsBySite returns all the crons for a given site.

func (*Cron) Copy

func (c *Cron) Copy(datastore.Entity) (datastore.Entity, error)

Copy is not currently implemented.

func (*Cron) Decode

func (c *Cron) Decode(b []byte) error

Decode deserializes a Cron from tab-separated values.

func (*Cron) Encode

func (c *Cron) Encode() []byte

Encode serializes a Cron into tab-separated values.

func (*Cron) FormatTime

func (c *Cron) FormatTime(tz float64) string

FormatTime formats the cron time either as hh:mm or the time of day.

func (*Cron) GetCache

func (c *Cron) GetCache() datastore.Cache

GetCache returns nil, indicating no caching.

func (*Cron) ParseTime

func (c *Cron) ParseTime(s string, tz float64) error

ParseTime parses a string representing a 24-hour time, i.e., hh:mm or hhmm, or a symbolic time of day, e.g., Sunrise or Sunset, and sets the cron time properties accordingly.

type Device

type Device struct {
	Skey          int64     // Site key.
	Dkey          int64     // Device key.
	Mac           int64     // Encoded MAC address (immutable).
	Name          string    // Device name.
	Inputs        string    // Input pins.
	Outputs       string    // Output pins.
	Wifi          string    // Wifi credentials, if any.
	MonitorPeriod int64     // Monitor period (s).
	ActPeriod     int64     // Actuation period (s)
	Type          string    // Client type.
	Version       string    // Client version.
	Protocol      string    // Client protocol.
	Status        int64     // Status code.
	Latitude      float64   // Device latitude.
	Longitude     float64   // Device longtitude.
	Enabled       bool      // True if enabled, false otherwise.
	Updated       time.Time // Date/time last updated.
	// contains filtered or unexported fields
}

Device represents a cloud device. The encoded MAC address serves as the datastore ID key. See MacEncode.

func CheckDevice

func CheckDevice(ctx context.Context, store datastore.Store, mac string, dk string) (*Device, error)

CheckDevice returns a device if the supplied MAC address is valid, the device key (supplied as a string) is correct and the device is enabled, else an error.

func GetDevice

func GetDevice(ctx context.Context, store datastore.Store, mac int64) (*Device, error)

GetDevice returns a Device by its integer ID (which is the encoded MAC address).

func GetDevicesBySite

func GetDevicesBySite(ctx context.Context, store datastore.Store, skey int64) ([]Device, error)

GetDevicesBySite returns all the devices for a given site.

func (*Device) Copy

func (dev *Device) Copy(dst datastore.Entity) (datastore.Entity, error)

Copy copies a device to dst, or returns a copy of the device when dst is nil.

func (*Device) Decode

func (dev *Device) Decode(b []byte) error

Decode deserializes a Device from tab-separated values.

func (*Device) Encode

func (dev *Device) Encode() []byte

Encode serializes a Device into tab-separated values.

func (*Device) GetCache

func (dev *Device) GetCache() datastore.Cache

GetCache returns the device cache.

func (*Device) Hex

func (dev *Device) Hex() string

Return the MAC address as a hexadecimal string, i.e., essentially a MAC address without the colons.

func (*Device) InputList

func (dev *Device) InputList() []string

InputList returns device inputs as a list.

func (*Device) InputListWithID

func (dev *Device) InputListWithID() []string

Retain these for the sensor/actuator migration then remove.

func (*Device) MAC

func (dev *Device) MAC() string

Return the MAC address as a formated string, i.e., a wrapper for MacDecode(dev.Mac).

func (*Device) Other

func (dev *Device) Other(key string) string

Return other data which is not persistent.

func (*Device) OutputList

func (dev *Device) OutputList() []string

OutputList returns device outputs as a list.

func (*Device) OutputListWithID

func (dev *Device) OutputListWithID() []string

func (*Device) SetOther

func (dev *Device) SetOther(key, value string)

Set other data which is not persistent.

func (*Device) StatusText

func (dev *Device) StatusText() string

Return the device status as text.

type MTSFragment

type MTSFragment struct {
	Medias      []*MtsMedia // MtsMedias that make up fragment.
	Type        string      // MIME type of all this fragment's MtsMedias.
	Duration    int64       // Total duration of media that makes up the fragment in MTS frequency units.
	DurationSec int64       // Total duration of media that makes up the fragment in seconds.
	TSRange     [2]int64    // Contains the timestamp of the first MtsMedia and the timestamp directly after the the duration of the last MtsMedia.
	Continues   bool        // True if this fragment continues from the previous fragment, false if there a discontinuity.
}

MTSFragment is a series of continuous MtsMedia clips. MTSFragment does not have a limit on how many MtsMedias it can contain, whereas MtsMedia clips must be under 1MB.

func FragmentMTSMedia

func FragmentMTSMedia(in []MtsMedia, period, tolerance int64) (out []*MTSFragment)

FragmentMTSMedia returns a slice of MTSFragments from the given MtsMedia every period seconds or whenever there is a discontinutity. Tolerance, which is specified in MTS frequency units (90kHz), controls how strictly discontinuities are enforced and how strictly the period is adhered to.

type Media

type Media struct {
	MID         int64
	Description string
	Updated     time.Time
}

Media represents a unique media source. Each media has a unique Media ID (MID) which serves as the datastore key. The description is optional.

func GetMedia

func GetMedia(ctx context.Context, store datastore.Store, mid int64) (*Media, error)

GetMedia returns media by its Media ID.

func (*Media) Copy

Copy is not currently implemented.

func (*Media) Decode

func (m *Media) Decode(b []byte) error

Decode deserializes a Media from tab-separated values.

func (*Media) Encode

func (m *Media) Encode() []byte

Encode serializes a Media into tab-separated values.

func (*Media) GetCache

func (m *Media) GetCache() datastore.Cache

GetCache returns nil, indicating no caching.

type MtsMedia

type MtsMedia struct {
	MID       int64          // Media ID.
	Geohash   string         // Geohash, if any.
	Timestamp int64          // Timestamp (in seconds).
	PTS       int64          // Presentation timestamp (in MTS frequency units).
	Duration  int64          // Duration of clip (in MTS frequency units).
	Continues bool           // True if this clip continues from the previous one, false if there a discontinuity.
	Type      string         // MIME type.
	Metadata  string         // Other metadata, if any.
	Date      time.Time      // Date/time this record was created.
	Clip      []byte         `datastore:",noindex"` // Media data.
	Key       *datastore.Key `datastore:"__key__"`  // Not persistent but populated upon reading from the datastore.
	FramePTS  int64          `datastore:"-"`        // Frame period in PTS frequency units (not persistent).
}

MtsMedia represents a clip of continuous audio/video media data in MPEG-TS (MTS) format. Continues is true if the clip is continuous in time with respect to the previous one, false otherwise.

The Media ID (MID) can be any identifier that uniquely identifies the media source, but conventionally it is formed from the 48-bit MAC address followed by the 4-bit encoding of the pin of the source device. See ToMID.

NB: Since App Engine stores []byte as a blob, the clip cannot exceed 1MB in size. The "noindex" datastore attribute prevents the datastore from attempting to index the clip (and failing).

func GetMtsMedia

func GetMtsMedia(ctx context.Context, store datastore.Store, mid int64, gh []string, ts []int64) ([]MtsMedia, error)

GetMtsMedia retrieves MTS media data for a given Media ID, optionally filtered by timestamp(s) and geohash(es). One timestamp represents an instant in time whereas two represents a time range. Similarly one geohash represents a single location whereas two represents a neighborhood of locations. Results are ordered by geohash, then timestamp, and then creation time. It is invalid to specify ranges for both geohashes and timestamps, since the datastore prohibits inequality filters on different properties.

NB: FileStore queries are are limited to information encoded in the key, namely MID and Timestamp.

func GetMtsMediaByKey

func GetMtsMediaByKey(ctx context.Context, store datastore.Store, ky uint64) (*MtsMedia, error)

GetMtsMediaByKey retrieves a single MTS media entity by key ID.

func GetMtsMediaByKeys

func GetMtsMediaByKeys(ctx context.Context, store datastore.Store, ky []uint64) ([]MtsMedia, error)

GetMtsMediaByKeys returns multiple MTS media given a range of key IDs, skipping over missing keys and fractional times. An error is returned only if nothing is found at all. This function is O(N) with the number of keys and should not be used with large numbers of keys. Use GetMtsMedia instead.

func (*MtsMedia) Copy

Copy is not currently implemented.

func (*MtsMedia) Decode

func (m *MtsMedia) Decode(b []byte) error

Decode deserializes a MtsMedia.

func (*MtsMedia) Encode

func (m *MtsMedia) Encode() []byte

Encode serializes an MtsMedia entity as follows:

  • Octet(s) Value
  • 0-2 Reserved
  • 3 Continues
  • 4-11 MID (8 octets)
  • 12-23 Geohash (12 octets)
  • 24-31 Timestamp (8 octets)
  • 32-37 PTS (6 octets)
  • 38-43 Duration (6 octets)
  • 44-47 Type length (4 octets)
  • 48-51 Metadata length (4 octets)
  • 52-55 Clip length (4 octets)
  • >=56 Type, metadata, and clip data

func (*MtsMedia) GetCache

func (m *MtsMedia) GetCache() datastore.Cache

GetCache returns nil, indicating no caching.

func (*MtsMedia) KeyID

func (m *MtsMedia) KeyID() uint64

KeyID returns the MtsMedia key ID as an unsigned integer.

type Scalar

type Scalar struct {
	ID        int64
	Timestamp int64
	Value     float64
	Key       *datastore.Key `datastore:"__key__" json:"-"` // Not persistent but populated upon reading from the datastore.
}

Scalar represents scalar data, such as a single analog (A) or digital (D) value.

The ID can be any identifier that uniquely identifies the data source, but conventionally it is formed from the 48-bit MAC address followed by the 8-bit encoding of the pin of the source device. See ToSID.

func GetScalar

func GetScalar(ctx context.Context, store datastore.Store, id int64, ts int64) (*Scalar, error)

GetScalar gets a single scalar by ID and timestamp.

func GetScalars

func GetScalars(ctx context.Context, store datastore.Store, id int64, ts []int64) ([]Scalar, error)

GetScalars returns scalar data. When ts is a non-identical pair, it represents a time range. A value of -1 for the second value indicates no upper bound to the time range. When ts is a singleton or identical pair, it represents an exact time.

func (*Scalar) Copy

Copy is not currently implemented.

func (*Scalar) Decode

func (s *Scalar) Decode(b []byte) error

Decode deserializes a Scalar entity from tab-separated values.

func (*Scalar) Encode

func (s *Scalar) Encode() []byte

Encode serializes a Scalar entity into tab-separated values.

func (*Scalar) FormatValue

func (s *Scalar) FormatValue(prec int) string

FormatValue formats a scalar's value as a string to the specified precision.

func (*Scalar) GetCache

func (s *Scalar) GetCache() datastore.Cache

GetCache returns nil, indicating no caching.

func (*Scalar) KeyID

func (s *Scalar) KeyID() uint64

KeyID returns the scalar's key ID as an unsigned integer.

type Sensor

type Sensor struct {
	SKey     int64   `datastore:"skey"`
	SID      string  `datastore:"sid"`
	Pin      string  `datastore:"pin"`
	Quantity string  `datastore:"quantity"`
	Func     string  `datastore:"func"`
	Args     string  `datastore:"args"`
	Scale    float64 `datastore:"scale"`
	Offset   float64 `datastore:"offset"`
	Units    string  `datastore:"units"`
	Format   string  `datastore:"format"`
}

Sensor repsents a sensor datastore type. Sensors take raw measured values and transform them based on a few predefined functions, or by a custom function specified by a string expression. NB: This type is deprecated. See SensorV2.

func GetSensor

func GetSensor(ctx context.Context, store datastore.Store, sKey int64, sid string) (*Sensor, error)

GetSensor gets a Sensor from the datastore given the site key and sensor id.

func GetSensorByPin

func GetSensorByPin(ctx context.Context, store datastore.Store, sKey int64, did, pin string) (*Sensor, error)

GetSensorByPin gets a Sensor from the datastore given the site key and the pin for which the sensor is applied.

func GetSensorsBySite

func GetSensorsBySite(ctx context.Context, store datastore.Store, skey int64, devID string) ([]Sensor, error)

GetSensorsBySite returns sensors associated with a site optionally filter by device with the provided device ID.

func (*Sensor) Copy

Copy is not currently implemented.

func (*Sensor) Decode

func (s *Sensor) Decode(b []byte) error

Decode deserializes a Sensor from tab-separated values.

func (*Sensor) Encode

func (s *Sensor) Encode() []byte

Encode serializes a Sensor into tab-separated values.

func (*Sensor) GetCache

func (s *Sensor) GetCache() datastore.Cache

GetCache returns nil, indicating no caching.

func (*Sensor) Transform

func (s *Sensor) Transform(v float64) (float64, error)

Transform applies the transformation specified in s.Func to the passed value v.

type SensorV2

type SensorV2 struct {
	Name     string  // Name of sensor (mutable).
	Mac      int64   // MAC address of associated device (immutable).
	Pin      string  // Pin of associated device (immutable).
	Quantity string  // NMEA quantity code.
	Func     string  // Transformation function.
	Args     string  // Transformation args.
	Scale    float64 // Deprecated.
	Offset   float64 // Deprecated.
	Units    string  // Units of transformed value.
	Format   string  // Format of transformed value.
}

SensorV2 defines a version 2 sensor. A sensor formats the value obtained from a device input pin. The key is the MAC address concatenated with the pin. Version 2 sensors do not have a site key, but are linked to a site indirectly via their device.

func GetSensorV2

func GetSensorV2(ctx context.Context, store datastore.Store, mac int64, pin string) (*SensorV2, error)

GetSensorV2 gets a sensor.

func GetSensorsV2

func GetSensorsV2(ctx context.Context, store datastore.Store, mac int64) ([]SensorV2, error)

GetSensorsV2 gets all sensors for a device.

func (*SensorV2) Copy

func (s *SensorV2) Copy(dst datastore.Entity) (datastore.Entity, error)

Copy copies a sensor to dst, or returns a copy of the sensor when dst is nil.

func (*SensorV2) Decode

func (s *SensorV2) Decode(b []byte) error

Decode decodes a sensor from JSON.

func (*SensorV2) Encode

func (s *SensorV2) Encode() []byte

Encode encodes a sensor as JSON.

func (*SensorV2) GetCache

func (s *SensorV2) GetCache() datastore.Cache

GetCache returns the sensor cache.

func (*SensorV2) Transform

func (s *SensorV2) Transform(v float64) (float64, error)

Transform applies the transformation specified in s.Func to the passed value v.

type Site

type Site struct {
	Skey         int64
	Name         string
	OwnerEmail   string
	Latitude     float64
	Longitude    float64
	Timezone     float64
	NotifyPeriod int64
	Enabled      bool
	Confirmed    bool
	Premium      bool
	Public       bool
	Created      time.Time
}

Site represents a cloud site.

func GetAllSites

func GetAllSites(ctx context.Context, store datastore.Store) ([]Site, error)

GetAllSites returns all sites.

func GetPublicSites

func GetPublicSites(ctx context.Context, store datastore.Store) ([]Site, error)

GetPublicSites returns all public sites.

func GetSite

func GetSite(ctx context.Context, store datastore.Store, skey int64) (*Site, error)

GetSite returns a site by its site key.

func (*Site) Copy

func (site *Site) Copy(dst datastore.Entity) (datastore.Entity, error)

Copy copies a site to dst, or returns a copy of the site when dst is nil.

func (*Site) Decode

func (site *Site) Decode(b []byte) error

Decode deserializes a Site from JSON.

func (*Site) Encode

func (site *Site) Encode() []byte

Encode serializes a Site into JSON.

func (*Site) GetCache

func (site *Site) GetCache() datastore.Cache

GetCache returns the site cache.

type Text

type Text struct {
	MID       int64          // Media ID.
	Timestamp int64          // Timestamp (in seconds).
	Type      string         // Text type.
	Data      string         `datastore:",noindex"` // Text data.
	Date      time.Time      // Date/time last updated.
	Key       *datastore.Key `datastore:"__key__"` // Not persistent but populated upon reading from the datastore.
}

Text represents text data.

The Media ID (MID) can be any identifier that uniquely identifies the media source, but conventionally it is formed from the 48-bit MAC address followed by the 4-bit encoding of the pin of the source device. See ToMID.

func GetText

func GetText(ctx context.Context, store datastore.Store, mid int64, ts []int64) ([]Text, error)

GetText retrieves text for a given Media ID, optionally filtered by timestamp(s).

func (*Text) Copy

func (t *Text) Copy(datastore.Entity) (datastore.Entity, error)

Copy is not currently implemented.

func (*Text) Decode

func (t *Text) Decode(b []byte) error

Decode deserializes a Text entity from tab-separated values.

func (*Text) Encode

func (t *Text) Encode() []byte

Encode serializes a Text entity into tab-separated values.

func (*Text) GetCache

func (t *Text) GetCache() datastore.Cache

GetCache returns nil, indicating no caching.

func (*Text) KeyID

func (t *Text) KeyID() uint64

KeyID returns the Text key ID as an unsigned integer.

type User

type User struct {
	Skey    int64     // Site key.
	Email   string    // User email address.
	UserID  string    // Google account ID. Not currently used.
	Perm    int64     // User's site permissions.
	Created time.Time // Date/time created.
}

User represents a cloud user. One user exists for each site that a Google account is associated with. The same Google account may have different permissions for different sites, or none at all.

func GetUser

func GetUser(ctx context.Context, store datastore.Store, skey int64, email string) (*User, error)

GetUser returns a user by its key, which is the concatenated Skey.Email.

func GetUsers

func GetUsers(ctx context.Context, store datastore.Store, email string) ([]User, error)

GetUsers returns all users corresponding to a given email or domain, sorted by site key.

func GetUsersBySite

func GetUsersBySite(ctx context.Context, store datastore.Store, skey int64) ([]User, error)

GetUsersBySite returns all of the users for a given site.

func (*User) Copy

func (user *User) Copy(dst datastore.Entity) (datastore.Entity, error)

Copy copies a user to dst, or returns a copy of the user when dst is nil.

func (*User) Decode

func (user *User) Decode(b []byte) error

Decode deserializes a User from tab-separated values.

func (*User) Encode

func (user *User) Encode() []byte

Encode serializes a User into tab-separated values.

func (*User) GetCache

func (user *User) GetCache() datastore.Cache

GetCache returns the user cache.

func (*User) PermissionText

func (user *User) PermissionText() string

PermissionText returns text describing the user's permissions.

type Variable

type Variable struct {
	Skey    int64     // Site key.
	Scope   string    // Scope, if any.
	Name    string    // Variable name, which is any ID.
	Value   string    `datastore:",noindex"` // Variable value.
	Updated time.Time // Date/time last updated.
}

Variable represents a cloud variable, which stores abitrary string information. When the variable name includes a period, the portion to the left of the dot represents the scope. The scope is used to create namespaces, e.g., <MAC>.<var> represents a variable for a given device, whereas <var> represents a global variable for the entire site. Variables that start with an underscore, e.g., _<var>, are system variables which are typically hidden from users.

func GetVariable

func GetVariable(ctx context.Context, store datastore.Store, skey int64, name string) (*Variable, error)

GetVariable gets a variable. Ignore colons in the scope.

func GetVariablesBySite

func GetVariablesBySite(ctx context.Context, store datastore.Store, skey int64, scope string) ([]Variable, error)

GetVariablesBySite returns all the variables for a given site, optionally filtered by scope. Ignore colons in the scope.

func (*Variable) Basename

func (v *Variable) Basename() string

Basename returns the name of the variable without the scope.

func (*Variable) Copy

Copy is not currently implemented.

func (*Variable) Decode

func (v *Variable) Decode(b []byte) error

Decode deserializes a Variable from tab-separated values.

func (*Variable) Encode

func (v *Variable) Encode() []byte

Encode serializes a Variable into tab-separated values.

func (*Variable) GetCache

func (v *Variable) GetCache() datastore.Cache

GetCache returns nil, indicating no caching.

func (v *Variable) IsLink() bool

IsLink returns true if the variable is an HTTP or HTTPS URL.

func (*Variable) IsSystemVariable

func (v *Variable) IsSystemVariable() bool

IsSystemVariable returns true if the variable is a system variable, false otherwise.

Jump to

Keyboard shortcuts

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