Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab #274

Merged
merged 3 commits into from
Feb 19, 2024
Merged

Lab #274

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
161 changes: 64 additions & 97 deletions components/simulator/creator_uielto_target_flash.js

Large diffs are not rendered by default.

22 changes: 0 additions & 22 deletions dockers/hw_lab/container_start.sh

This file was deleted.

4 changes: 2 additions & 2 deletions dockers/hw_lab/Dockerfile → dockers/remote_lab/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ RUN git clone https://github.com/creatorsim/creator.git && \
cd creator && \
npm install terser jshint colors yargs readline-sync

RUN ln -s /creator/hw_lab/deployment.json deployment.json
RUN ln -s /creator/remote_lab/deployment.json deployment.json


#Run web service
COPY start_hw_lab.sh .
COPY start_remote_lab.sh .
CMD ["/usr/bin/sleep","infinity"]
22 changes: 22 additions & 0 deletions dockers/remote_lab/container_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash


#
# Main
#

docker pull creatorsim/creator_remote_lab

if [[ -n $(docker container ls -q --filter name=creator_remote_lab) ]]; then
docker container stop $(docker container ls -q --filter name=creator_remote_lab)
fi

docker container rm creator_remote_lab

if [ $# -ne 0 ]; then
docker build -t creatorsim/creator_remote_lab .
fi

docker run --init -it -p 5000:5000 --name creator_remote_lab creatorsim/creator_remote_lab /bin/bash

echo " Done."
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

#Run gateway
export PYTHONPATH=/usr/local/lib/python3.10/dist-packages:${PYTHONPATH}
cd /creator/hw_lab/
python3 hw_lab.py deployment.json
cd /creator/remote_lab/
python3 remote_lab.py deployment.json
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@

<!-- Flash -->
<flash id="flash"
:remote_lab="remote_lab"
:lab_url="lab_url"
:result_email="result_email"
:target_board="target_board"
:target_port="target_port"
:flash_url="flash_url">
Expand Down
2 changes: 1 addition & 1 deletion js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ try
//Flash
//

remote_lab: "",
lab_url: "",
result_email: "",
target_ports: { Win: 'rfc2217://host.docker.internal:4000?ign_set_control', Mac: '/dev/cu.usbserial-210', Linux: '/dev/ttyUSB0' }, //TODO: include into flash component - modal info
target_board: "", //TODO: include into flash component - modal info
target_port: "", //TODO: include into flash component - modal info
Expand Down
2 changes: 1 addition & 1 deletion js/min.creator_web.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions mk_dockers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ docker container rm creatorsim/creator_gateway
docker buildx build --no-cache --platform linux/amd64,linux/arm64,linux/arm/v7 -t creatorsim/creator_gateway .
cd ..

#Build hw_lab docker
cd hw_lab
docker container stop $(docker container ls -q --filter name=creatorsim/creator_hw_lab)
docker container rm creatorsim/creator_hw_lab
#docker build --no-cache -t creatorsim/creator_hw_lab .
docker buildx build --no-cache --platform linux/amd64,linux/arm64,linux/arm/v7 -t creatorsim/creator_hw_lab .
#Build remote_lab docker
cd remote_lab
docker container stop $(docker container ls -q --filter name=creatorsim/creator_remote_lab)
docker container rm creatorsim/creator_remote_lab
#docker build --no-cache -t creatorsim/creator_remote_lab .
docker buildx build --no-cache --platform linux/amd64,linux/arm64,linux/arm/v7 -t creatorsim/creator_remote_lab .
cd ..

#Build command line docker
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"colors": "^1.4.0",
"jshint": "^2.13.6",
"readline-sync": "^1.4.10",
"terser": "^5.27.1",
"terser": "^5.27.2",
"yargs": "^17.7.2"
}
}
File renamed without changes.
File renamed without changes.
51 changes: 36 additions & 15 deletions hw_lab/hw_lab.py → remote_lab/remote_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

from flask import Flask, request, jsonify, send_file, Response
from flask_cors import CORS, cross_origin
import subprocess, os, signal, sys, json, threading, time, requests
from getpass import getpass
from email.message import EmailMessage
import subprocess, os, signal, sys, json, threading, time, requests, smtplib



Expand Down Expand Up @@ -136,9 +138,33 @@ def worker(item):
file.write(jres['status'])
file.close()

ret["status"] = 'Completed'
# Sent email with the results
receivers = ret['result_email']

email = EmailMessage()
email["From"] = sender
email["To"] = receivers
email["Subject"] = "[CREATOR] Remote device results"
message = "Remote device ID=" + ret['request_id'] + " has been successfully completed, the execution results are attached. \n\nSincerely,\nCREATOR Team\n\nhttps://creatorsim.github.io/"
email.set_content(message, subtype="plain")

with open("results/" + ret['request_id'] + ".txt", "rb") as f:
email.add_attachment(
f.read(),
filename="remote_device_" + ret['request_id'] + ".txt",
maintype="text",
subtype="txt"
)

smtpObj = smtplib.SMTP_SSL('smtp.gmail.com', 465)
smtpObj.login(sender, password)
smtpObj.sendmail(sender, receivers, email.as_string())
smtpObj.quit()


ret["status"] = 'Completed'
deployment[item]['status'] = 'free'

enqueue_request (queue_outgoing, ret)


Expand All @@ -152,7 +178,7 @@ def worker(item):

# (1) Check params
if len(sys.argv) < 2:
print("Use: python3 hw_lab.py <deployment_file> [port]");
print("Use: python3 remote_lab.py <deployment_file> [port]");
exit(-1)

port = 5000
Expand All @@ -161,6 +187,10 @@ def worker(item):


# (2) Get Deployment configuration
print("Enter E-mail:")
sender = input()
password = getpass()

try:
deployment_file = open(sys.argv[1], 'r')
except Exception as e:
Expand Down Expand Up @@ -199,7 +229,7 @@ def worker(item):
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'

# (5a) GET / -> send hw_lab.html
# (5a) GET / -> send remote_lab.html
@app.route("/", methods=["GET"])
@cross_origin()
def get_status():
Expand Down Expand Up @@ -228,10 +258,11 @@ def post_enqueue():
try:
req_data = request.get_json()
target_board = req_data['target_board']
result_email = req_data['result_email']
asm_code = req_data['assembly']
req_data['status'] = ''

new_request = { "request_id": str(request_id), "target_board": target_board, "asm_code": asm_code }
new_request = { "request_id": str(request_id), "result_email": result_email, "target_board": target_board, "asm_code": asm_code }
req_data['status'] = enqueue_request (queue_incoming, new_request)
request_id = request_id + 1

Expand Down Expand Up @@ -299,16 +330,6 @@ def post_status():

return jsonify(req_data)

# (5g) GET /result -> send execution result
@app.route("/result", methods=["GET"])
@cross_origin()
def get_result():
try:
req_id = request.args.get('req_id')
return send_file("results/" + req_id + ".txt", as_attachment=True)
except Exception as e:
return str(e)



# Run
Expand Down