diff --git a/README.md b/README.md index 417fdbcb..5d803f11 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # backend -[![Build CoderBot backend](https://github.com/CoderBotOrg/backend/actions/workflows/build_backend.yml/badge.svg) +![Build CoderBot backend](https://github.com/CoderBotOrg/backend/actions/workflows/build_backend.yml/badge.svg) > CoderBot is a RaspberryPI-based programmable robot for educational purposes. Check the [project website](https://www.coderbot.org) for more information. > diff --git a/coderbot/api.py b/coderbot/api.py index 3cfc8432..88052aff 100644 --- a/coderbot/api.py +++ b/coderbot/api.py @@ -18,7 +18,7 @@ from audio import Audio from camera import Camera from cnn.cnn_manager import CNNManager -from coderbotTestUnit import run_test as runCoderbotTestUnit +from runtime_test import run_test from musicPackages import MusicPackageManager from program import Program, ProgramEngine @@ -262,21 +262,19 @@ def addMusicPackage(): """ Add a musical package an save the list of available packages on disk also add sounds and directory + zipName = request.args.get("zipname") """ - """zipName = request.args.get("zipname") - """ - file_to_upload = connexion.request.files['file_to_upload'] - print("adding " +str(file_to_upload)) - print("adding " + file_to_upload.filename) - file_to_upload.save(os.path.join('./updatePackages/', file_to_upload.filename)) - musicPkg = MusicPackageManager.get_instance() - response = musicPkg.addPackage(file_to_upload.filename) - if response == 1: - return 200 - elif response == 2: - return 400 - elif response == 3: - return 400 + try: + file_to_upload = connexion.request.files['file_to_upload'] + logging.info("adding " + file_to_upload.filename) + file_to_upload.save(os.path.join('/tmp/', file_to_upload.filename)) + music_pkg = MusicPackageManager.get_instance() + music_pkg.addPackage(file_to_upload.filename) + return "{}", 200 + except ValueError: + return "{}", 409 + except Exception: + return "{}", 400 def deleteMusicPackage(name): """ @@ -376,12 +374,7 @@ def resetDefaultPrograms(): ## Test def testCoderbot(body): - # taking first JSON key value (varargin) - if len(body.keys()) > 0: - tests_state = runCoderbotTestUnit(body[list(body.keys())[0]]) - return tests_state - else: - return 404 + return run_test(body.get("tests", [])) def listCNNModels(): cnn = CNNManager.get_instance() diff --git a/coderbot/musicPackages.py b/coderbot/musicPackages.py index 051b8738..e671b7e7 100644 --- a/coderbot/musicPackages.py +++ b/coderbot/musicPackages.py @@ -184,18 +184,16 @@ def addPackage(self, filename): if not self.verifyVersion(pkgname, version): if (version == self.packages[pkgname].getVersion()): logging.error("errore, il pacchetto " + pkgname + " ha versione identica a quello attualmente installato") - return 3 + raise ValueError() else: logging.info("errore, il pacchetto " + pkgname + " ha versione precendente a quello attualmente installato") - return 2 + raise ValueError() else: - - os.system('unzip -o ' + './updatePackages/' + filename + " -d ./updatePackages") - + os.system('unzip -o ' + '/tmp/' + filename + " -d /tmp") os.system('mkdir ' + pkgpath) - os.system('mv ./updatePackages/' + pkgname + "/" + 'audio.wav ' + pkgpath + '/') + os.system('mv /tmp/' + pkgname + "/" + 'audio.wav ' + pkgpath + '/') - with open('./updatePackages/' + pkgname + '/' + pkgname + '.json') as json_file: + with open('/tmp/' + pkgname + '/' + pkgname + '.json') as json_file: logging.info("adding " + pkgname + " package") data = json.load(json_file) for p in data['packages']: @@ -210,8 +208,7 @@ def addPackage(self, filename): self.updatePackages() - os.system('rm -rf ./updatePackages/' + pkgname) - return 1 + os.system('rm -rf /tmp/' + pkgname) def isPackageAvailable(self,namePackage): diff --git a/coderbot/coderbotTestUnit.py b/coderbot/runtime_test.py similarity index 86% rename from coderbot/coderbotTestUnit.py rename to coderbot/runtime_test.py index e397c14a..4a6260a5 100644 --- a/coderbot/coderbotTestUnit.py +++ b/coderbot/runtime_test.py @@ -11,6 +11,7 @@ If a test passes for correspondent component, a 1 is returned. If no test was executed on that component, 0 is preserved. """ +import logging from coderbot import CoderBot # Single components tests @@ -20,70 +21,70 @@ def __test_encoder(): try: c = CoderBot.get_instance() # moving both wheels at speed 100 clockwise - print("moving both wheels at speed 100 clockwise") + logging.info("moving both wheels at speed 100 clockwise") assert(c.speed() == 0) c.move(speed=100, elapse=2) assert(c.distance() != 0) assert (c.speed() == 0) # moving both wheels at speed 40 clockwise - print("moving both wheels at speed 40 clockwise") + logging.info("moving both wheels at speed 40 clockwise") assert(c.speed() == 0) c.move(speed=40, elapse=2) assert(c.distance() != 0) assert (c.speed() == 0) # moving both wheels at speed 100 counter-clockwise - print("moving both wheels at speed 100 counter-clockwise") + logging.info("moving both wheels at speed 100 counter-clockwise") assert(c.speed() == 0) c.move(speed=-100, elapse=2) assert(c.distance() != 0) assert (c.speed() == 0) # moving both wheels at speed 40 counter-clockwise - print("moving both wheels at speed 40 counter-clockwise") + logging.info("moving both wheels at speed 40 counter-clockwise") assert(c.speed() == 0) c.move(speed=-40, elapse=2) assert(c.distance() != 0) assert (c.speed() == 0) # moving forward - print("moving forward") + logging.info("moving forward") assert(c.speed() == 0) c.forward(speed=100, elapse=2) assert(c.distance() != 0) assert (c.speed() == 0) # moving backwards - print("moving backwards") + logging.info("moving backwards") assert(c.speed() == 0) c.backward(speed=100, elapse=2) assert(c.distance() != 0) assert (c.speed() == 0) # moving forward for 1 meter - print("moving forward for 1 meter") + logging.info("moving forward for 1 meter") assert(c.speed() == 0) c.forward(speed=100, distance=1000) assert(c.distance() != 0) assert (c.speed() == 0) # moving backwards for 1 meter - print("moving backwards for 1 meter") + logging.info("moving backwards for 1 meter") assert(c.speed() == 0) c.backward(speed=100, distance=1000) assert(c.distance() != 0) assert (c.speed() == 0) # turning left - print("turning left") + logging.info("turning left") assert(c.speed() == 0) c.left(speed=100, elapse=2) assert(c.distance() != 0) assert (c.speed() == 0) # turning right - print("turning right") + logging.info("turning right") assert(c.speed() == 0) c.right(speed=100, elapse=2) assert(c.distance() != 0) diff --git a/coderbot/v1.yml b/coderbot/v1.yml index 210ddf7b..a3c8872f 100644 --- a/coderbot/v1.yml +++ b/coderbot/v1.yml @@ -359,6 +359,23 @@ paths: description: "ok" tags: - Music extensions + post: + operationId: "api.addMusicPackage" + summary: "Add Music Package" + requestBody: + description: Add a Music Package + required: true + content: + application/x-www-form-urlencoded: + schema: + type: object + tags: + - System operations + responses: + 200: + description: "ok" + 400: + description: "upload failed" /music/packages/{name}: delete: operationId: "api.deleteMusicPackage" @@ -376,25 +393,7 @@ paths: description: "ok" 400: description: "not found" - - /system/update: - post: - operationId: "api.updateFromPackage" - summary: "Update CoderBot from package" - requestBody: - description: Update Activity - required: true - content: - application/x-www-form-urlencoded: - schema: - type: object - tags: - - System operations - responses: - 200: - description: "ok" - 400: - description: "upload failed" + /system/status: get: operationId: "api.get_status" @@ -404,6 +403,7 @@ paths: responses: 200: description: "Bot status" + /system/test: post: summary: Tests CoderBot components. @@ -411,15 +411,23 @@ paths: tags: - System operations requestBody: - description: Update Activity + description: Performs onboard tests required: true content: - application/x-www-form-urlencoded: + application/json: schema: type: object + properties: + tests: + type: array + items: + type: string responses: 200: description: Test ended. + 400: + description: Invalid input. + /system/info: get: operationId: "api.get_info" @@ -439,6 +447,7 @@ paths: responses: 200: description: "Successfully stopped the motors" + /control/move: post: summary: Moves the bot forward or backward. diff --git a/docker/stub/requirements.txt b/docker/stub/requirements.txt index 925819f3..81c1bc21 100644 --- a/docker/stub/requirements.txt +++ b/docker/stub/requirements.txt @@ -1,44 +1,26 @@ # API framework -connexion==2.14.1 -Flask==2.2.2 +connexion==2.14.2 +Flask==2.2.3 Flask-Cors==3.0.10 -itsdangerous==2.1.2 -jsonschema==4.15.0 -Markdown==3.4.1 -MarkupSafe==2.1.1 -pyyaml==6.0 -requests==2.28.1 -swagger-spec-validator==2.7.6 -tinydb==4.7.0 -urllib3==1.26.12 -Werkzeug==2.2.2 +tinydb==4.7.1 +Werkzeug==2.2.3 # Misc utils -setuptools==65.3.0 -certifi==2022.5.18.1 -absl-py==1.2.0 -chardet==3.0.4 -click==8.1.3 -clickclick==20.10.2 -gast==0.5.3 -idna==3.3 -pybind11==2.10.0 -inflection==0.5.1 +setuptools==67.4.0 event-channel==0.4.3 -pytz==2022.2.1 + +# IO extensions +spidev==3.5 # Audio sox==1.4.1 # Computer Vision grpcio==1.48.1 -numpy==1.23.2 -Pillow==9.2.0 -protobuf==4.21.8 +numpy==1.24.2 +Pillow==9.4.0 +protobuf==4.22.0 opencv-contrib-python==4.5.5.62 -tflite-runtime==2.10.0 +tflite-runtime==2.11.0 pytesseract==0.3.10 pyzbar==0.1.9 - -#I/O -spidev==3.5 diff --git a/requirements.txt b/requirements.txt index d149f5c4..35aad39d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,31 +1,13 @@ # API framework -connexion==2.14.1 -Flask==2.2.2 +connexion==2.14.2 +Flask==2.2.3 Flask-Cors==3.0.10 -itsdangerous==2.1.2 -jsonschema==4.15.0 -Markdown==3.4.1 -MarkupSafe==2.1.1 -pyyaml==6.0 -requests==2.28.1 -swagger-spec-validator==2.7.6 -tinydb==4.7.0 -urllib3==1.26.12 -Werkzeug==2.2.2 +tinydb==4.7.1 +Werkzeug==2.2.3 # Misc utils -setuptools==65.3.0 -certifi==2022.5.18.1 -absl-py==1.2.0 -chardet==3.0.4 -click==8.1.3 -clickclick==20.10.2 -gast==0.5.3 -idna==3.3 -pybind11==2.10.0 -inflection==0.5.1 +setuptools==67.4.0 event-channel==0.4.3 -pytz==2022.2.1 # IO extensions pigpio==1.78 @@ -39,11 +21,11 @@ pyalsaaudio==0.9.2 # Computer Vision grpcio==1.48.1 -numpy==1.23.2 -Pillow==9.2.0 -protobuf==4.21.8 +numpy==1.24.2 +Pillow==9.4.0 +protobuf==4.22.0 opencv-contrib-python==4.5.5.62 -tflite-runtime==2.10.0 +tflite-runtime==2.11.0 pytesseract==0.3.10 picamera==1.13 pyzbar==0.1.9 diff --git a/test/music/snake/audio.wav b/test/music/snake/audio.wav new file mode 100644 index 00000000..39775e14 Binary files /dev/null and b/test/music/snake/audio.wav differ diff --git a/test/music/snake/snake.json b/test/music/snake/snake.json new file mode 100644 index 00000000..476eebe6 --- /dev/null +++ b/test/music/snake/snake.json @@ -0,0 +1,25 @@ +{ + "packages": { + "snake": { + "category": "animal", + "name_IT": "serpente", + "name_EN": "snake", + "version": "0.1", + "date": "2020-06-01", + "interface": { + "base": { + "available": "TRUE", + "icon": "snake.png" + }, + "intermediate": { + "available": "TRUE", + "icon": "snake.png" + }, + "advanced": { + "available": "TRUE", + "icon": "snake.png" + } + } + } + } +} \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy