Skip to content

Commit

Permalink
Merge pull request #272 from dcamarmas/lab
Browse files Browse the repository at this point in the history
Lab
  • Loading branch information
dcamarmas authored Feb 18, 2024
2 parents d60a3bc + 0cc9fb4 commit 46b07c5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 135 deletions.
109 changes: 5 additions & 104 deletions components/simulator/creator_uielto_target_flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@

flashing = false,
running = false,

display = "",
}
},

Expand Down Expand Up @@ -306,10 +304,7 @@

this_env = this;
gateway_remote_flash(this.flash_url + "/flash", farg).then( function(data) {
this_env.display += data;
this_env.flashing = false;
var monitor = document.getElementById('textarea_display');
monitor.scrollTop = monitor.scrollHeight;
show_notification(data, 'danger') ;
} ) ;

Expand All @@ -331,36 +326,14 @@

this_env = this;
gateway_remote_monitor(this.flash_url + "/monitor", farg).then( function(data) {
this_env.display += data;
this_env.running = false;
var monitor = document.getElementById('textarea_display');
monitor.scrollTop = monitor.scrollHeight;
//show_notification(data, 'danger') ;
} ) ;

//Google Analytics
creator_ga('simulator', 'simulator.monitor', 'simulator.monitor');
},

do_stop_flash( )
{
this.save();

this.flashing = false;

this_env = this;
gateway_remote_stop_flash(this.flash_url + "/stop").then( function(data) {
this_env.display += data;
this_env.flashing = false;
var monitor = document.getElementById('textarea_display');
monitor.scrollTop = monitor.scrollHeight;
show_notification(data, 'danger') ;
} ) ;

//Google Analytics
creator_ga('simulator', 'simulator.stop_flash', 'simulator.stop_flash');
},

//
//General
//
Expand All @@ -372,12 +345,7 @@
app._data.target_board = this._props.target_board;
app._data.target_port = this._props.target_port;
app._data.flash_url = this._props.flash_url;
},

clean( )
{
this.display = "";
},
}
},

template: ' <b-modal :id="id"' +
Expand Down Expand Up @@ -440,7 +408,6 @@
' </b-col>' +
' </b-row>' +
' </b-container>' +
' <br>' +
' ' +
' <b-container fluid align-h="center" class="mx-0 px-0" v-if="target_board !=\'\' && result">' +
' <b-row cols="1" align-h="center">' +
Expand All @@ -451,6 +418,7 @@
' </b-col>' +
' </b-row>' +
' </b-container>' +
' <br>' +
' ' +
' <b-container fluid align-h="center" class="mx-0 px-0" v-if="target_board !=\'\' && !enqueue">' +
' <b-row cols="1" align-h="center">' +
Expand Down Expand Up @@ -492,7 +460,7 @@
' </b-container>' +
' <br>' +
' ' +
' <b-tabs content-class="mt-3">' +
' <b-tabs content-class="mt-3" v-if="target_board !=\'\'">' +
' <b-tab title="Prerequisites">' +
' ' +
' <b-tabs content-class="mt-3">' +
Expand Down Expand Up @@ -811,47 +779,8 @@
' <b-spinner small v-if="running"></b-spinner>' +
' </b-button>' +
' </b-col>' +
/*' <b-col class="pt-2">' +
' <b-button class="btn btn-sm btn-block" variant="outline-danger" @click="do_stop_flash" :disabled="!flashing">' +
' <span><span class="fas fa-stop"></span> Stop</span>' +
' </b-button>' +
' </b-col>' +*/
' </b-row>' +
' </b-container>' +
/*' ' +
' <b-container fluid align-h="center" class="mx-0 px-0">' +
' <b-row cols="1" align-h="center">' +
' <b-col class="pt-2">' +
' <span>To stop the program execution press ctrl + ] in the terminal</span>' +
' </b-col>' +
' </b-row>' +
' </b-container>' +
' ' +
' <b-container fluid align-h="center" class="mx-0 px-0">' +
' <b-row cols="1" align-h="center">' +
' <b-col class="pt-2">' +
' <label for="range-6">Monitor:</label>' +
' <b-form-textarea id="textarea_display" ' +
' size="sm"' +
' v-model="display" ' +
' rows="8" ' +
' disabled ' +
' no-resize ' +
' title="Display">' +
' </b-form-textarea>' +
' </b-col>' +
' </b-row>' +
' </b-container>' +
' ' +
' <b-container fluid align-h="center" class="mx-0 px-0">' +
' <b-row cols="1" align-h="center">' +
' <b-col class="pt-2">' +
' <b-button class="btn btn-sm btn-block" variant="outline-secondary" @click="clean">' +
' <span><span class="fas fa-broom"></span> Clean</span>' +
' </b-button>' +
' </b-col>' +
' </b-row>' +
' </b-container>' +*/
' </b-tab>' +
' </b-tabs>' +
' ' +
Expand Down Expand Up @@ -1037,7 +966,7 @@
catch (err)
{
if (err.toString() == "TypeError: Failed to fetch") {
return "Please, execute 'python3 gateway.py' and connect your board first\n";
return "Gateway not available at the moment. Please, execute 'python3 gateway.py' and connect your board first\n";
}

return err.toString() + "\n";
Expand Down Expand Up @@ -1065,35 +994,7 @@
catch (err)
{
if (err.toString() == "TypeError: Failed to fetch") {
return "Please, execute 'python3 gateway.py' and connect your board first\n";
}

return err.toString() + "\n";
}
}

async function gateway_remote_stop_flash ( flash_url )
{
var fetch_args = {
method: 'POST',
headers: {
'Content-type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({})
} ;

try
{
var res = await fetch(flash_url, fetch_args) ;
var jres = await res.json();

return jres.status;
}
catch (err)
{
if (err.toString() == "TypeError: Failed to fetch") {
return "Please, execute 'python3 gateway.py' and connect your board first\n";
return "Gateway not available at the moment. Please, execute 'python3 gateway.py' and connect your board first\n";
}

return err.toString() + "\n";
Expand Down
14 changes: 1 addition & 13 deletions hw_lab/deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@
{
"target_board": "esp32c3",
"target_port": "/dev/ttyUSB0",
"target_url": "http://localhost:8080"
},
"target_2":
{
"target_board": "esp32c3",
"target_port": "/dev/ttyUSB0",
"target_url": "http://localhost:8080"
},
"target_3":
{
"target_board": "esp32c3",
"target_port": "/dev/ttyUSB0",
"target_url": "http://localhost:8080"
"target_url": "http://10.119.4.59:8080"
}
}
43 changes: 26 additions & 17 deletions hw_lab/hw_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,17 @@ def worker(item):
deployment[item]['status'] = 'busy'

# Sent to the target post
#url = deployment[item]['target_url']
#msg = {'target_port': ret['target_port'], 'target_board': ret['target_board'], 'assembly': ret['asm_code']}
#ret["status"] = requests.post(url, json = mgs)
url = deployment[item]['target_url'] + "/job"
msg = {'target_port': deployment[item]['target_port'], 'target_board': ret['target_board'], 'assembly': ret['asm_code']}

res = requests.post(url, json = msg)
jres = res.json()

###################
time.sleep(3)
ret["status"] = 'Completed'
###################
file = open("results/" + ret['request_id'] + ".txt", "w")
file.write(jres['status'])
file.close()

ret["status"] = 'Completed'

deployment[item]['status'] = 'free'
enqueue_request (queue_outgoing, ret)
Expand Down Expand Up @@ -176,7 +177,14 @@ def worker(item):
deployment_file.close()


# (3) Queue management
# (3)Create result directory
try:
os.mkdir('results')
except Exception as e:
pass


# (4) Queue management
queue_incoming['lock'] = threading.Lock()
queue_outgoing['lock'] = threading.Lock()

Expand All @@ -186,19 +194,19 @@ def worker(item):
t.start()


# (4) Setup flask and cors:
# (5) Setup flask and cors:
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'

# (4a) GET / -> send hw_lab.html
# (5a) GET / -> send hw_lab.html
@app.route("/", methods=["GET"])
@cross_origin()
def get_status():
ret = { 'incoming': queue_incoming, 'outgoing': queue_outgoing }
return json.dumps(ret)

# (4b) GET /targets -> send available targets
# (5b) GET /targets -> send available targets
@app.route("/target_boards", methods=["GET"])
@cross_origin()
def get_target_boards():
Expand All @@ -211,7 +219,7 @@ def get_target_boards():

return json.dumps(target_boards)

# (4c) POST /enqueue -> enqueue
# (5c) POST /enqueue -> enqueue
@app.route("/enqueue", methods=["POST"])
@cross_origin()
def post_enqueue():
Expand All @@ -232,7 +240,7 @@ def post_enqueue():

return jsonify(req_data)

# (4d) POST /delete -> delete
# (5d) POST /delete -> delete
@app.route("/delete", methods=["POST"])
@cross_origin()
def post_delete():
Expand All @@ -250,7 +258,7 @@ def post_delete():

return jsonify(req_data)

# (4e) POST /position -> position
# (5e) POST /position -> position
@app.route("/position", methods=["POST"])
@cross_origin()
def post_position():
Expand All @@ -268,7 +276,7 @@ def post_position():

return jsonify(req_data)

# (4f) POST /status -> status
# (5f) POST /status -> status
@app.route("/status", methods=["POST"])
@cross_origin()
def post_status():
Expand All @@ -291,12 +299,13 @@ def post_status():

return jsonify(req_data)

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

Expand Down
2 changes: 1 addition & 1 deletion js/min.creator_web.js

Large diffs are not rendered by default.

0 comments on commit 46b07c5

Please sign in to comment.