Skip to content

Commit

Permalink
remote config
Browse files Browse the repository at this point in the history
  • Loading branch information
hanappe committed Apr 20, 2024
1 parent b18e781 commit baf6444
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/romi/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def power_down(self):
help='The file for the fake camera')
args = parser.parse_args()

#camera = Camera(args.topic, args.topic)
camera = FakeCamera(args.topic, args.topic, args.file)
camera = Camera(args.topic, args.topic)
#camera = FakeCamera(args.topic, args.topic, args.file)
for i in range(10):
image = camera.grab()
if image != None:
Expand Down
52 changes: 52 additions & 0 deletions python/romi/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import websocket
from PIL import Image
from io import BytesIO
from rcom.rcom_client import RcomClient
import argparse
import json

class Config(RcomClient):

def __init__(self, topic = 'config', id = 'config'):
super().__init__(topic, id)

def has_section(self, name):
params = {'name': name}
result = self.execute('has-section', params)
return result['answer']

def get_section(self, name):
params = {'name': name}
return self.execute('get-section', params)

def set_section(self, name, value):
params = {'name': name, 'value': value}
return self.execute('set-section', params)

def get(self):
return self.execute('get')


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--topic', type=str, nargs='?', default="config",
help='The regsitry topic')
args = parser.parse_args()

config = Config(args.topic, args.topic)

print(json.dumps(config.get(), indent=4))
print("------------------------------------")
print(config.has_section('camera'))
print("------------------------------------")
print(json.dumps(config.get_section('camera'), indent=4))
print("------------------------------------")
try:
config.set_section('non-existant', 4)
except Exception as e:
print(f"Error: {e}")
print("------------------------------------")
try:
config.set_section('test', 4)
except Exception as e:
print(f"Error: {e}")

0 comments on commit baf6444

Please sign in to comment.