Documentation ¶
Index ¶
- Constants
- Variables
- func ComputeVarSum(vars []Variable) int64
- func CreateSite(ctx context.Context, store datastore.Store, site *Site) error
- func DeleteActuator(ctx context.Context, store datastore.Store, aid string) error
- func DeleteActuatorV2(ctx context.Context, store datastore.Store, mac int64, pin string) error
- func DeleteCredential(ctx context.Context, store datastore.Store, mid int64, name string) error
- func DeleteCredentials(ctx context.Context, store datastore.Store, name string) error
- func DeleteCron(ctx context.Context, store datastore.Store, skey int64, id string) error
- func DeleteDevice(ctx context.Context, store datastore.Store, mac int64) error
- func DeleteMtsMedia(ctx context.Context, store datastore.Store, mid int64) error
- func DeleteScalars(ctx context.Context, store datastore.Store, id int64) error
- func DeleteSensor(ctx context.Context, store datastore.Store, sKey int64, sid string) error
- func DeleteSensorV2(ctx context.Context, store datastore.Store, mac int64, pin string) error
- func DeleteSite(ctx context.Context, store datastore.Store, skey int64) error
- func DeleteText(ctx context.Context, store datastore.Store, mid int64) error
- func DeleteUser(ctx context.Context, store datastore.Store, skey int64, email string) error
- func DeleteVariable(ctx context.Context, store datastore.Store, skey int64, name string) error
- func DeleteVariables(ctx context.Context, store datastore.Store, skey int64, scope string) error
- func FromMID(mid int64) (string, string)
- func FromSID(id int64) (string, string)
- func GetMtsMediaKeys(ctx context.Context, store datastore.Store, mid int64, gh []string, ts []int64) ([]*datastore.Key, error)
- func GetScalarKeys(ctx context.Context, store datastore.Store, id int64, ts []int64) ([]*datastore.Key, error)
- func GetSiteName(ctx context.Context, store datastore.Store, skey int64) (string, error)
- func GetTextKeys(ctx context.Context, store datastore.Store, mid int64, ts []int64) ([]*datastore.Key, error)
- func GetVarSum(ctx context.Context, store datastore.Store, skey int64, scope string) (int64, error)
- func HasPermission(ctx context.Context, store datastore.Store, mid int64, email string, ...) bool
- func IsMacAddress(mac string) bool
- func MacDecode(enc int64) string
- func MacEncode(mac string) int64
- func PTSToSeconds(pts int64) float64
- func PutActuator(ctx context.Context, store datastore.Store, act *Actuator) error
- func PutActuatorV2(ctx context.Context, store datastore.Store, act *ActuatorV2) error
- func PutCredential(ctx context.Context, store datastore.Store, c *Credential) error
- func PutCron(ctx context.Context, store datastore.Store, c *Cron) error
- func PutDevice(ctx context.Context, store datastore.Store, dev *Device) error
- func PutMedia(ctx context.Context, store datastore.Store, m *Media) error
- func PutScalar(ctx context.Context, store datastore.Store, s *Scalar) error
- func PutSensor(ctx context.Context, store datastore.Store, s *Sensor) error
- func PutSensorV2(ctx context.Context, store datastore.Store, s *SensorV2) error
- func PutSite(ctx context.Context, store datastore.Store, site *Site) error
- func PutUser(ctx context.Context, store datastore.Store, user *User) error
- func PutVariable(ctx context.Context, store datastore.Store, skey int64, name, value string) error
- func RegisterEntities()
- func SensorFormats() []string
- func SensorFuncs() []string
- func ToMID(mac, pin string) int64
- func ToSID(mac, pin string) int64
- func UpdateMtsMedia(ctx context.Context, store datastore.Store, m MtsMedia, pid uint16) error
- func WriteMtsMedia(ctx context.Context, store datastore.Store, m *MtsMedia) error
- func WriteText(ctx context.Context, store datastore.Store, t *Text) error
- type Actuator
- type ActuatorV2
- type BinaryData
- type Credential
- func GetCredential(ctx context.Context, store datastore.Store, mid int64, name string) (*Credential, error)
- func GetCredentialsByMID(ctx context.Context, store datastore.Store, mid int64) ([]Credential, error)
- func GetCredentialsByName(ctx context.Context, store datastore.Store, name string) ([]Credential, error)
- func (c *Credential) Copy(datastore.Entity) (datastore.Entity, error)
- func (c *Credential) Decode(b []byte) error
- func (c *Credential) Encode() []byte
- func (c *Credential) GetCache() datastore.Cache
- func (c *Credential) IsAdmin() bool
- func (c *Credential) IsReadable() bool
- func (c *Credential) IsSuper() bool
- func (c *Credential) IsWritable() bool
- type Cron
- type Device
- func (dev *Device) Copy(dst datastore.Entity) (datastore.Entity, error)
- func (dev *Device) Decode(b []byte) error
- func (dev *Device) Encode() []byte
- func (dev *Device) GetCache() datastore.Cache
- func (dev *Device) Hex() string
- func (dev *Device) InputList() []string
- func (dev *Device) InputListWithID() []string
- func (dev *Device) MAC() string
- func (dev *Device) Other(key string) string
- func (dev *Device) OutputList() []string
- func (dev *Device) OutputListWithID() []string
- func (dev *Device) SetOther(key, value string)
- func (dev *Device) StatusText() string
- type MTSFragment
- type Media
- type MtsMedia
- func GetMtsMedia(ctx context.Context, store datastore.Store, mid int64, gh []string, ts []int64) ([]MtsMedia, error)
- func GetMtsMediaByKey(ctx context.Context, store datastore.Store, ky uint64) (*MtsMedia, error)
- func GetMtsMediaByKeys(ctx context.Context, store datastore.Store, ky []uint64) ([]MtsMedia, error)
- type Scalar
- type Sensor
- func GetSensor(ctx context.Context, store datastore.Store, sKey int64, sid string) (*Sensor, error)
- func GetSensorByPin(ctx context.Context, store datastore.Store, sKey int64, did, pin string) (*Sensor, error)
- func GetSensorsBySite(ctx context.Context, store datastore.Store, skey int64, devID string) ([]Sensor, error)
- type SensorV2
- type Site
- type Text
- type User
- type Variable
- func (v *Variable) Basename() string
- func (v *Variable) Copy(datastore.Entity) (datastore.Entity, error)
- func (v *Variable) Decode(b []byte) error
- func (v *Variable) Encode() []byte
- func (v *Variable) GetCache() datastore.Cache
- func (v *Variable) IsLink() bool
- func (v *Variable) IsSystemVariable() bool
Constants ¶
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 ¶
var ( ErrWrongNumParts = errors.New("wrong number of values for actuator") ErrSKeyParse = errors.New("cannot parse site key for actuator") )
Actuator errors.
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") )
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") )
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.
var ErrInvalidTime = errors.New("invalid time")
Functions ¶
func ComputeVarSum ¶
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 ¶
CreateSite creates a site, or returns an error if a site with the given key exists.
func DeleteActuator ¶
DeleteActuator deletes and actuator from the datastore given its actuator ID.
func DeleteActuatorV2 ¶
DeleteActuatorV2 deletes an actuator.
func DeleteCredential ¶
DeleteCredential deletes a single credential.
func DeleteCredentials ¶
DeleteCredentials deletes all credential for a given name.
func DeleteCron ¶
DeleteCron deletes a cron.
func DeleteDevice ¶
DeleteDevice deletes a device.
func DeleteMtsMedia ¶
DeleteMtsMedia deletes all MTS media for a given Media ID.
func DeleteScalars ¶
DeleteScalar deletes all scalars for a given ID.
func DeleteSensor ¶
DeleteSensor deletes a Sensor entity given the site key and sensor ID.
func DeleteSensorV2 ¶
DeleteSensorV2 deletes a sensor.
func DeleteSite ¶
DeleteSite deletes a site.
func DeleteText ¶
DeleteText deletes all text for a given Media ID.
func DeleteUser ¶
DeleteUser deletes a user.
func DeleteVariable ¶
DeleteVariable deletes a variable. Ignore colons in the scope.
func DeleteVariables ¶
DeleteVariables deletes all variables for a given scope. Ignore colons in the scope.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
PTSToSeconds converts a duration in MPEG-TS Presentation Time Stamp (PTS) units to seconds.
func PutActuator ¶
PutActuator puts an actuator in the datastore.
func PutActuatorV2 ¶
PutActuatorV2 creates/updates an actuator.
func PutCredential ¶
PutCredential creates or updates a Credential using MID.Name as the key.
func PutSensorV2 ¶
PutSensorV2 creates/updates a sensor.
func PutVariable ¶
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 ¶
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 ¶
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 ¶
UpdateMtsMedia deletes a MTS media and creates a new one in its place.
func WriteMtsMedia ¶
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.
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.
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 ¶
GetActuatorsV2 gets all actuators for a device.
func (*ActuatorV2) Copy ¶
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) 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 GetCronsBySite ¶
GetCronsBySite returns all the crons for a given site.
func (*Cron) FormatTime ¶
FormatTime formats the cron time either as hh:mm or the time of day.
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 GetDevicesBySite ¶
GetDevicesBySite returns all the devices for a given site.
func (*Device) Hex ¶
Return the MAC address as a hexadecimal string, i.e., essentially a MAC address without the colons.
func (*Device) InputListWithID ¶
Retain these for the sensor/actuator migration then remove.
func (*Device) MAC ¶
Return the MAC address as a formated string, i.e., a wrapper for MacDecode(dev.Mac).
func (*Device) OutputList ¶
OutputList returns device outputs as a list.
func (*Device) OutputListWithID ¶
func (*Device) StatusText ¶
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 ¶
Media represents a unique media source. Each media has a unique Media ID (MID) which serves as the datastore key. The description is optional.
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 ¶
GetMtsMediaByKey retrieves a single MTS media entity by key ID.
func GetMtsMediaByKeys ¶
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) Encode ¶
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
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 GetScalars ¶
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) FormatValue ¶
FormatValue formats a scalar's value as a string to the specified precision.
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 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.
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 ¶
GetSensorsV2 gets all sensors for a device.
func (*SensorV2) Copy ¶
Copy copies a sensor to dst, or returns a copy of the sensor when dst is nil.
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 ¶
GetAllSites returns all sites.
func GetPublicSites ¶
GetPublicSites returns all public sites.
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.
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 GetUsers ¶
GetUsers returns all users corresponding to a given email or domain, sorted by site key.
func GetUsersBySite ¶
GetUsersBySite returns all of the users for a given site.
func (*User) PermissionText ¶
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) IsSystemVariable ¶
IsSystemVariable returns true if the variable is a system variable, false otherwise.