Skip to content

Commit

Permalink
Update module implementation
Browse files Browse the repository at this point in the history
Update module
  • Loading branch information
npentrel authored Nov 5, 2024
2 parents 6dbae82 + cbbe2db commit 7beab85
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 132 deletions.
41 changes: 2 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,11 @@ The following attributes are available for the `naomi:sync-at-time:timesyncsenso
}
```

To ensure the data manager starts up before the sensor, add this `service_config` to the component configuration on the **JSON** tab.

```json
"service_configs": [
{
"attributes": {
"capture_methods": []
},
"type": "data_manager"
}
]
```

The entire component configuration should resemble this:

```json
{
"attributes": {
"start": "14:10:00",
"end": "15:35:00",
"zone": "CET"
},
"depends_on": [],
"name": "timesensor",
"model": "naomi:sync-at-time:timesyncsensor",
"type": "sensor",
"namespace": "rdk",
"service_configs": [
{
"attributes": {
"capture_methods": []
},
"type": "data_manager"
}
]
}
```

To ensure the sensor starts before the data manager, add the sensor to the dependencies of the data manager.

### Configure data manager

On your machine's **Config** tab, switch to **JSON** mode and add a `selective_syncer_name` with the name for the sensor you configured:
On your machine's **Config** tab, switch to **JSON** mode and add a `selective_syncer_name` with the name for the sensor you configured to the data manager config. Also add the sensor to the `depends_on` field:

```json
{
Expand Down
171 changes: 83 additions & 88 deletions example.json
Original file line number Diff line number Diff line change
@@ -1,94 +1,89 @@
{
"components": [
{
"type": "camera",
"namespace": "rdk",
"attributes": {
"video_path": "FDF90FEB-59E5-4FCF-AABD-DA03C4E19BFB"
},
"depends_on": [],
"service_configs": [
{
"type": "data_manager",
"attributes": {
"capture_methods": [
{
"capture_frequency_hz": 0.2,
"method": "ReadImage",
"additional_params": {
"mime_type": "image/jpeg"
}
}
]
}
"services": [
{
"namespace": "rdk",
"depends_on": [
"timesensor"
],
"attributes": {
"additional_sync_paths": [],
"selective_syncer_name": "timesensor",
"sync_interval_mins": 0.2,
"capture_dir": "",
"tags": []
},
"name": "datamanager",
"type": "data_manager"
}
],
"agent_config": {
"subsystems": {
"viam-server": {
"disable_subsystem": false,
"release_channel": "stable",
"pin_version": "",
"pin_url": ""
},
"agent-provisioning": {
"pin_version": "",
"pin_url": "",
"disable_subsystem": false,
"release_channel": "stable"
},
"viam-agent": {
"release_channel": "stable",
"pin_version": "",
"pin_url": "",
"disable_subsystem": false
}
],
"name": "webcam",
"model": "webcam"
}
},
{
"attributes": {
"start": "14:10:00",
"end": "15:35:00",
"zone": "CET"
"modules": [
{
"version": "latest",
"type": "registry",
"name": "naomi_sync-at-time",
"module_id": "naomi:sync-at-time"
}
],
"components": [
{
"model": "webcam",
"type": "camera",
"namespace": "rdk",
"attributes": {
"video_path": "FDF90FEB-59E5-4FCF-AABD-DA03C4E19BFB"
},
"depends_on": [],
"service_configs": [
{
"attributes": {
"capture_methods": [
{
"additional_params": {
"mime_type": "image/jpeg"
},
"capture_frequency_hz": 0.2,
"method": "ReadImage"
}
]
},
"type": "data_manager"
}
],
"name": "webcam"
},
"depends_on": [],
"name": "timesensor",
"model": "naomi:sync-at-time:timesyncsensor",
"type": "sensor",
"namespace": "rdk",
"service_configs": [
{
"attributes": {
"capture_methods": []
},
"type": "data_manager"
{
"depends_on": [],
"name": "timesensor",
"model": "naomi:sync-at-time:timesyncsensor",
"type": "sensor",
"namespace": "rdk",
"attributes": {
"start": "18:29:00",
"end": "18:30:00",
"zone": "CET"
}
]
}
],
"services": [
{
"attributes": {
"selective_syncer_name": "timesensor",
"sync_interval_mins": 0.2,
"capture_dir": "",
"tags": [],
"additional_sync_paths": []
},
"name": "datamanager",
"type": "data_manager",
"namespace": "rdk"
}
],
"agent_config": {
"subsystems": {
"viam-server": {
"release_channel": "stable",
"pin_version": "",
"pin_url": "",
"disable_subsystem": false
},
"agent-provisioning": {
"release_channel": "stable",
"pin_version": "",
"pin_url": "",
"disable_subsystem": false
},
"viam-agent": {
"release_channel": "stable",
"pin_version": "",
"pin_url": "",
"disable_subsystem": false
}
}
},
"modules": [
{
"module_id": "naomi:sync-at-time",
"version": "0.0.1",
"type": "registry",
"name": "naomi_sync-at-time"
}
]
}
]
}
15 changes: 10 additions & 5 deletions timesyncsensor/timesyncsensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ func (s *timeSyncer) Readings(context.Context, map[string]interface{}) (map[stri
currentTime := time.Now()
var hStart, mStart, sStart, hEnd, mEnd, sEnd int
n, err := fmt.Sscanf(s.start, "%d:%d:%d", &hStart, &mStart, &sStart)

if err != nil || n != 3 {
s.logger.Error("Start time is not in the format HH:MM:SS.")
return datamanager.CreateShouldSyncReading(false), err
return nil, err
}
m, err := fmt.Sscanf(s.end, "%d:%d:%d", &hEnd, &mEnd, &sEnd)
if err != nil || m != 3 {
s.logger.Error("End time is not in the format HH:MM:SS.")
return datamanager.CreateShouldSyncReading(false), err
return nil, err
}

zone, err := time.LoadLocation(s.zone)
Expand All @@ -135,14 +136,18 @@ func (s *timeSyncer) Readings(context.Context, map[string]interface{}) (map[stri
endTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(),
hEnd, mEnd, sEnd, 0, zone)

readings := map[string]interface{}{"should_sync": false}
readings["time"] = currentTime
// If it is between the start and end time, sync.
if currentTime.After(startTime) && currentTime.Before(endTime) {
s.logger.Info("Syncing")
return datamanager.CreateShouldSyncReading(true), nil
s.logger.Debug("Syncing")
readings["should_sync"] = true
return readings, nil
}

// Otherwise, do not sync.
return datamanager.CreateShouldSyncReading(false), nil
s.logger.Debug("Not syncing. Current time not in sync window: " + currentTime)
return readings, nil
}

// Close closes the underlying generic.
Expand Down

0 comments on commit 7beab85

Please sign in to comment.