Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions note/dfu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2025 Blues Inc. All rights reserved.
// Use of this source code is governed by licenses granted by the
// copyright holder including that found in the LICENSE file.

// Package note dfu.go contains DFU-related structures generated/parsed by the notecard
package note

// DFUState is the state of the DFU in progress
type DFUState struct {
Type string `json:"type,omitempty"`
File string `json:"file,omitempty"`
Length uint32 `json:"length,omitempty"`
CRC32 uint32 `json:"crc32,omitempty"`
MD5 string `json:"md5,omitempty"`
Phase string `json:"mode,omitempty"`
Status string `json:"status,omitempty"`
BeganSecs uint32 `json:"began,omitempty"`
RetryCount uint32 `json:"retry,omitempty"`
ConsecutiveErrors uint32 `json:"errors,omitempty"`
BinaryRetries uint32 `json:"binretry,omitempty"`
DFUStartCount uint32 `json:"dfu_started,omitempty"`
DFUCompletedCount uint32 `json:"dfu_completed,omitempty"`
ODFUStartedCount uint32 `json:"odfu_started,omitempty"`
ODFUTarget string `json:"odfu_target,omitempty"`
ReadFromService uint32 `json:"read,omitempty"`
UpdatedSecs uint32 `json:"updated,omitempty"`
DownloadComplete bool `json:"dl_complete,omitempty"`
DisabledReason string `json:"disabled,omitempty"`
MinNotecardVersion string `json:"min_card_version,omitempty"`

// This will always point to the current running version
Version string `json:"version,omitempty"`
}

// DFUEnv is the data structure passed to Notehub when DFU info changes
type DFUEnv struct {
Card *DFUState `json:"card,omitempty"`
User *DFUState `json:"user,omitempty"`
Modem *DFUState `json:"modem,omitempty"`
Star *DFUState `json:"star,omitempty"`
}

type DfuPhase string

const (
DfuPhaseUnknown DfuPhase = ""
DfuPhaseIdle DfuPhase = "idle"
DfuPhaseError DfuPhase = "error"
DfuPhaseDownloading DfuPhase = "downloading"
DfuPhaseSideloading DfuPhase = "sideloading"
DfuPhaseReady DfuPhase = "ready"
DfuPhaseReadyRetry DfuPhase = "ready-retry"
DfuPhaseUpdating DfuPhase = "updating"
DfuPhaseCompleted DfuPhase = "completed"
)
12 changes: 12 additions & 0 deletions note/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import (
// ErrTimeout (golint)
const ErrTimeout = "{timeout}"

// ErrInternalTimeout of a notehub-to-notehub transaction (golint)
const ErrInternalTimeout = "{internal-timeout}"

// ErrRouteTimeout of a notehub-to-customer-service transaction (golint)
const ErrRouteTimeout = "{route-timeout}"

// ErrClosed (golint)
const ErrClosed = "{closed}"

Expand Down Expand Up @@ -115,6 +121,9 @@ const ErrDeviceNotFound = "{device-noexist}"
// ErrDeviceNotSpecified (golint)
const ErrDeviceNotSpecified = "{device-none}"

// ErrDeviceId (golint)
const ErrDeviceId = "{device-id-invalid}"

// ErrDeviceDisabled (golint)
const ErrDeviceDisabled = "{device-disabled}"

Expand Down Expand Up @@ -142,6 +151,9 @@ const ErrFleetNotFound = "{fleet-noexist}"
// ErrCardIo (golint)
const ErrCardIo = "{io}"

// ErrCardHeartbeat (golint)
const ErrCardHeartbeat = "{heartbeat}"

// ErrAccessDenied (golint)
const ErrAccessDenied = "{access-denied}"

Expand Down
96 changes: 72 additions & 24 deletions note/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const EventSessionEnd = "session.end"
// EventGeolocation (golint)
const EventGeolocation = "device.geolocation"

// EventSocket (golint)
const EventSocket = "web.socket"

// EventWebhook (golint)
const EventWebhook = "webhook"

Expand All @@ -65,23 +68,28 @@ type Event struct {
Payload []byte `json:"payload,omitempty"`
Details *map[string]interface{} `json:"details,omitempty"`
// Metadata
SessionUID string `json:"session,omitempty"`
SessionBegan int64 `json:"session_began,omitempty"`
TLS bool `json:"tls,omitempty"`
Transport string `json:"transport,omitempty"`
Continuous bool `json:"continuous,omitempty"`
BestID string `json:"best_id,omitempty"`
DeviceUID string `json:"device,omitempty"`
DeviceSN string `json:"sn,omitempty"`
ProductUID string `json:"product,omitempty"`
AppUID string `json:"app,omitempty"`
Received float64 `json:"received,omitempty"`
Req string `json:"req,omitempty"`
Error string `json:"err,omitempty"`
Updates int32 `json:"updates,omitempty"`
Deleted bool `json:"deleted,omitempty"`
Sent bool `json:"queued,omitempty"`
Bulk bool `json:"bulk,omitempty"`
SessionUID string `json:"session,omitempty"`
SessionBegan int64 `json:"session_began,omitempty"`
TLS bool `json:"tls,omitempty"`
Transport string `json:"transport,omitempty"`
Continuous bool `json:"continuous,omitempty"`
BestID string `json:"best_id,omitempty"`
DeviceUID string `json:"device,omitempty"`
DeviceSN string `json:"sn,omitempty"`
ProductUID string `json:"product,omitempty"`
AppUID string `json:"app,omitempty"`
Received float64 `json:"received,omitempty"`
Req string `json:"req,omitempty"`
Error string `json:"err,omitempty"`
Updates int32 `json:"updates,omitempty"`
Deleted bool `json:"deleted,omitempty"`
Sent bool `json:"queued,omitempty"`
Bulk bool `json:"bulk,omitempty"`
BulkReceived float64 `json:"batch_received,omitempty"`
BulkNumber uint32 `json:"batch_number,omitempty"`
BulkTotal uint32 `json:"batch_total,omitempty"`
FirmwareHost string `json:"firmware_host,omitempty"`
FirmwareNotecard string `json:"firmware_notecard,omitempty"`
// This field is ONLY used when we remove the payload for storage reasons, to show the app how large it was
MissingPayloadLength int64 `json:"payload_length,omitempty"`
// Location
Expand Down Expand Up @@ -179,13 +187,53 @@ const (

// RouteLogEntry is the log entry used by notification processing
type RouteLogEntry struct {
EventSerial int64 `json:"event,omitempty"`
RouteSerial int64 `json:"route,omitempty"`
Date time.Time `json:"date,omitempty"`
Attn bool `json:"attn,omitempty"`
Status string `json:"status,omitempty"`
Text string `json:"text,omitempty"`
URL string `json:"url,omitempty"`
EventSerial int64 `json:"event,omitempty"`
RouteSerial int64 `json:"route,omitempty"`
Date time.Time `json:"date,omitempty"`
Attn bool `json:"attn,omitempty"`
Status string `json:"status,omitempty"`
Text string `json:"text,omitempty"`
URL string `json:"url,omitempty"`
Source RoutingSource `json:"source,omitempty"`

// Time in milliseconds that the route took to process
// We're making a simplifying assumption that the route will always
// take at least 1ms. So 0 means we didn't record the duration.
Duration int64 `json:"duration,omitempty"`
}

type RoutingSource uint8

const (
RoutingSourceUnknown RoutingSource = iota
RoutingSourceNormal
RoutingSourceProxy
RoutingSourceRetry
RoutingSourceManual
RoutingSourceDirect
RoutingSourceTest
)

// String returns a string representation of the routing source
func (s RoutingSource) String() string {
switch s {
case RoutingSourceUnknown:
return "" // display nothing if no entry/default
case RoutingSourceNormal:
return "Normal Routing"
case RoutingSourceProxy:
return "Web Proxy Request"
case RoutingSourceRetry:
return "Auto-Retry"
case RoutingSourceManual:
return "Manual Reroute"
case RoutingSourceDirect:
return "Direct Routing" //only used for test events, should never show in route logs
case RoutingSourceTest:
return "Test" // only used for tests
default:
return "invalid"
}
}

// GetAggregateEventStatus returns the status of the event given all
Expand Down
6 changes: 6 additions & 0 deletions note/notefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ const HealthHostNotefile = "_health_host.qo"
// GeolocationNotefile is the hard-wired notefile that the notehub uses when performing a geolocation
const GeolocationNotefile = "_geolocate.qo"

// SocketNotefile is the hard-wired notefile that the notehub uses when doing websocket I/O
const SocketNotefile = "_socket.qo"

// WebNotefile is the hard-wired notefile that the notehub uses when performing web requests
const WebNotefile = "_web.qo"

// WatchdogNotefile is the hard-wired notefile that the notehub uses when adding watchdog messages
const WatchdogNotefile = "_watchdog.qo"

// SyncPriorityLowest (golint)
const SyncPriorityLowest = -3

Expand Down
25 changes: 17 additions & 8 deletions note/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ type DeviceSession struct {
PowerPrimary bool `json:"power_primary,omitempty"`
// Mojo power usage
PowerMahUsed float64 `json:"power_mah,omitempty"`
// Information about failed connections PRIOR to this one
PenaltySecs uint32 `json:"penalty_secs,omitempty"`
FailedConnects uint32 `json:"failed_connects,omitempty"`
// Socket-relate
SocketAlias string `json:"socket_alias,omitempty"`
SocketConnectError string `json:"socket_connect_error,omitempty"`
SocketBytesSent int64 `json:"socket_bytes_sent,omitempty"`
SocketBytesRcvd int64 `json:"socket_bytes_rcvd,omitempty"`
}

func (s *DeviceSession) This() *DeviceUsage {
Expand All @@ -115,20 +123,21 @@ func (s *DeviceSession) Period() *DeviceUsage {
return s.PeriodPtr
}

// TowerLocation is the cell tower location structure generated by the tower utility
// TowerLocation is a location structure generated by a lookup
type TowerLocation struct {
When int64 `json:"time,omitempty"` // time when this location was ascertained
Name string `json:"n,omitempty"` // name of the location
CountryCode string `json:"c,omitempty"` // country code
Lat float64 `json:"lat,omitempty"` // latitude
Lon float64 `json:"lon,omitempty"` // longitude
TimeZone string `json:"zone,omitempty"` // timezone name
Source string `json:"source,omitempty"` // source of this location
When int64 `json:"time,omitempty"` // time when this location was ascertained
Name string `json:"n,omitempty"` // name of the location
CountryCode string `json:"c,omitempty"` // country code
Lat float64 `json:"lat,omitempty"` // latitude
Lon float64 `json:"lon,omitempty"` // longitude
TimeZone string `json:"zone,omitempty"` // timezone name
MCC int `json:"mcc,omitempty"`
MNC int `json:"mnc,omitempty"`
LAC int `json:"lac,omitempty"`
CID int `json:"cid,omitempty"`
OLC string `json:"l,omitempty"` // open location code
TimeZoneID int `json:"z,omitempty"` // timezone id (see tz.go)
Count int64 `json:"count,omitempty"` // number of times this location was recently used
Deprecated int64 `json:"count,omitempty"` // (no longer used or supported)
Towers int `json:"towers,omitempty"` // number of triangulation points
}
74 changes: 0 additions & 74 deletions notecard-driver-windows7.inf

This file was deleted.

8 changes: 4 additions & 4 deletions notecard/cobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
)

func TestCob(t *testing.T) {
rand.Seed(time.Now().UnixNano())
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
min := 100
max := 1000
len := rand.Intn(max-min+1) + min
len := rng.Intn(max-min+1) + min
buf := make([]byte, len)
xor := byte(rand.Int())
xor := byte(rng.Int())

_, err := rand.Read(buf)
_, err := rng.Read(buf)
require.NoError(t, err)

encoded, err := CobsEncode(buf, xor)
Expand Down
Loading