Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
cfry committed Jun 27, 2019
1 parent 490488a commit 3962018
Show file tree
Hide file tree
Showing 42 changed files with 2,056 additions and 964 deletions.
9 changes: 6 additions & 3 deletions core/dextersim.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ DexterSim = class DexterSim{
//so just leave that as it is--apr 2019
if (this.sim_actual === true){
let rob = this.robot
if((rs_copy[Dexter.INSTRUCTION_TYPE] == "r") &&
(typeof(payload_string_maybe) == "number") &&
(payload_string_maybe > 0)){
rs_copy[Dexter.ERROR_CODE] = payload_string_maybe
}
setTimeout(function(){
Socket.on_receive(rs_copy, rob.name, payload_string_maybe)
}, 1)
Expand Down Expand Up @@ -422,13 +427,11 @@ DexterSim = class DexterSim{
let whole_content
try { whole_content = read_file(source) }//errors if path in "source" doesn't exist
catch(err){
return 1 //return the error code
return 2 //return the error code
}
let start_index = hunk_index * Instruction.Dexter.read_file.payload_max_chars
let end_index = start_index + Instruction.Dexter.read_file.payload_max_chars
let payload_string = whole_content.substring(start_index, end_index) //ok if end_index is > whole_cotnent.length, it just gets how much it can, no error
//out("some content from " + source + " hunk: " + hunk_index + " payload: " + payload_string)
//Socket.r_payload_grab_aux(instruction_array, payload_string)
return payload_string
}
//Dexter.write_file
Expand Down
6 changes: 6 additions & 0 deletions core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ var Coor = require("../math/Coor.js")
var Kin = require("../math/Kin.js")
var Vector = require("../math/Vector.js")
var Job = require("./job.js")

var {Robot, Brain, Dexter, Human, Serial} = require("./robot.js")
var {Control} = require("./instruction_control.js")
var {IO} = require("./instruction_io.js")

var {out} = require("./out.js")
var calibrate_build_tables = require("../low_level_dexter/calibrate_build_tables.js")
var DXF = require("../math/DXF.js")
Expand All @@ -119,6 +123,8 @@ global.Dexter = Dexter
global.make_ins = Dexter.make_ins
global.out = out
global.Robot = Robot
global.Control = Control
global.IO = IO
global.Job = Job
global.Vector = Vector
global.Kin = Kin
Expand Down
128 changes: 64 additions & 64 deletions core/instruction.js

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions core/instruction_control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var {Robot} = require('./robot.js')

class Control{}

Control.break = Robot.break
Control.go_to = Robot.go_to
Control.loop = Robot.loop
Control.label = Robot.label
Control.suspend = Robot.suspend
Control.unsuspend = Robot.unsuspend
Control.sync_point = Robot.sync_point
Control.wait_until = Robot.wait_until

Control.include_job = Robot.include_job
Control.send_to_job = Robot.send_to_job
Control.sent_from_job = Robot.sent_from_job
Control.start_job = Robot.start_job
Control.stop_job = Robot.stop_job

Control.debugger = Robot.debugger
Control.error = Robot.error
Control.if_any_errors = Robot.if_any_errors

module.exports.Control = Control
19 changes: 12 additions & 7 deletions core/instruction_dexter.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ Instruction.Dexter.read_file = class read_file extends Instruction.Dexter{
if(!this.robot) { this.set_instruction_robot_from_job(job_instance) }
if (this.first_do_item_call) {
const sim_actual = Robot.get_simulate_actual(this.robot.simulate)
//have to check for dexter_file_systems or else the 2nd time I rn the job, it will
//have to check for dexter_file_systems or else the 2nd time I run the job, it will
//have a double length path with 2 dexter_file_systems parts
if (!this.source.startsWith("/") && (sim_actual === true) && !this.source.startsWith("dexter_file_systems")) {
this.fuller_source = "dexter_file_systems/" + this.robot.name + "/" + this.source
Expand All @@ -703,23 +703,23 @@ Instruction.Dexter.read_file = class read_file extends Instruction.Dexter{
//the below can never happen
//if (this.is_done) {
// this.processing_r_instruction = false
// return Robot.break()
// return Control.break()
//}
let read_file_instance = this
let robot = this.robot //closed over
job_instance.insert_single_instruction(Robot.loop(true, function(content_hunk_index){
job_instance.insert_single_instruction(Control.loop(true, function(content_hunk_index){
let job_instance = this
if (read_file_instance.is_done) {
//init this inst just in case it gets used again
read_file_instance.is_done = false
read_file_instance.first_do_item_call = true
read_file_instance.processing_r_instruction = false
return Robot.break()
return Control.break()
}
else {
read_file_instance.processing_r_instruction = true
return [make_ins("r", content_hunk_index, read_file_instance.fuller_source, robot),
Robot.wait_until(function(){
Control.wait_until(function(){
return !read_file_instance.processing_r_instruction
})
]
Expand All @@ -744,6 +744,7 @@ Instruction.Dexter.read_file = class read_file extends Instruction.Dexter{
}

//called from socket.js
//payload_string_maybe is a string or an error code (an int > 0)
static got_content_hunk(job_id, ins_id, payload_string_maybe){
let job_instance = Job.job_id_to_job_instance(job_id)
if (job_instance == null){
Expand All @@ -764,9 +765,13 @@ Instruction.Dexter.read_file = class read_file extends Instruction.Dexter{
}
}

//used by Dexter.write_file too
//used by Dexter.write_file to prepare path for passing it to make_ins("W" ...)
//because the path used for write_file defaults to "srv/samba/share/dde_apps",
//whereas the path for make_ins("W" ...) defaults to srv/samba/share
//see Dexter.srv_samba_share_default_to_absolute_path to do the opposite
static add_default_file_prefix_maybe(path){
if(path.startsWith("/")) { return path }
if (path.startsWith("/")) { return path }
else if (path.startsWith("#")) { return path }
else if (path.startsWith("./")) { return "dde_apps/" + path.substring(2) }
else if (path.startsWith("../")) { return path.substring(3) } //will go to dexrun's default foler, ie /srv/samba/share/
else { return "dde_apps/" + path }
Expand Down
16 changes: 16 additions & 0 deletions core/instruction_io.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var {Robot} = require('./robot.js')

class IO{}

IO.get_page = Robot.get_page
IO.grab_robot_status = Robot.grab_robot_status
IO.out = Robot.out
IO.show_picture = Robot.show_picture
IO.show_video = Robot.show_video
IO.take_picture = Robot.take_picture
//read_file and write_file are Dexter-specific instructions only,
//so they are under Dexter.read_file and Dexter.write_file

module.exports.IO = IO


8 changes: 4 additions & 4 deletions core/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ class Job{
inter_do_item_dur: 0.005, //we don't need to have fast communication with Dexter. Minimize traffic
do_list:[
Dexter.write_file("job/run/" + dde_monitor_job_instance.name + ".dde", job_src),
Robot.loop(true,
Control.loop(true,
function(){
if(this.user_data.dexter_log !== undefined) { //got a dexter log meaning the monitored job is over.
return Robot.break()
return Control.break()
}
else if ((this.user_data.stop_job_running_on_dexter) &&
(!this.user_data.already_handled_stop_job)) { //set by clicking the job button
Expand Down Expand Up @@ -1658,7 +1658,7 @@ Job.prototype.handle_start_object = function(cur_do_item){
}
}
else if(cur_do_item.dur) {
this.insert_single_instruction(Robot.wait_until(cur_do_item.dur))
this.insert_single_instruction(Control.wait_until(cur_do_item.dur))
}
if (!start_args) { cur_do_item.start.apply(the_inst_this) }
else if (Array.isArray(start_args)) { cur_do_item.start.apply(the_inst_this, start_args) }
Expand Down Expand Up @@ -2261,7 +2261,7 @@ Job.prototype.increment_added_items_count_for_parent_instruction_of = function(i
(type_of(par_loc_index) == "number") &&
(par_loc_index < this.program_counter)) { //backwards goto in same job
let loop_inst_maybe = this.do_list[par_loc_index]
if(loop_inst_maybe instanceof Robot.loop){ //shoot, we can't make the inserted instruction a sub_object of a loop's go_to
if(loop_inst_maybe instanceof Control.loop){ //shoot, we can't make the inserted instruction a sub_object of a loop's go_to
//so we've got to climb up the tree and increment the next instr that has a positive added_items_count
//but that aic must "contain" the instr_id of the added instruction
for(let maybe_par_id = par_loc_index - 1; maybe_par_id >= 0; maybe_par_id--){
Expand Down
1 change: 1 addition & 0 deletions core/out.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function out_eval_result(text, color="#000000", src){
src = replace_substrings(src, "'", "&apos;")
src_formatted = " <code title='" + src + "'>&nbsp;" + src_formatted + src_formatted_suffix + "&nbsp;</code>"
}
//if (src_formatted == "") { console.log("_____out_eval_result passed src: " + src + " with empty string for src_formatted and text: " + text)}
text = "<fieldset><legend><i>Result of evaling </i>" + src_formatted + "</legend>" + text + "</fieldset>"
append_to_output(text)
}
Expand Down
40 changes: 28 additions & 12 deletions core/robot.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ var Robot = class Robot {
}

//Control Instructions
static break(){ //stop a Robot.loop
static break(){ //stop a Control.loop
return new Instruction.break()
}
static debugger(){ //stop a Robot.loop
static debugger(){ //stop a Control.loop
return new Instruction.debugger()
}
static error(reason){ //declare that an error happened. This will cause the job to stop.
Expand Down Expand Up @@ -231,7 +231,7 @@ var Robot = class Robot {
//default to undefined.
static get_page(url_or_options, response_variable_name="http_response"){
if(url_or_options === undefined){
dde_error("Robot.get_page called with no <b>url_or_options</b> argument<br/>" +
dde_error("Control.get_page called with no <b>url_or_options</b> argument<br/>" +
"which is typically the string of a url.")
}
return new Instruction.Get_page(url_or_options, response_variable_name)
Expand Down Expand Up @@ -1071,16 +1071,16 @@ Dexter = class Dexter extends Robot {
}
else if ((this_robot.simulate === false) || (this_robot.simulate === "both")){
this_job.stop_for_reason("errored", "The job: " + this_job.name + " is using robot: " + this_robot.name +
"<br/>\nbut could not connect with a Dexter robot at: " +
"<br/>but could not connect with a Dexter robot at: " +
this_robot.ip_address + " port: " + this_robot.port +
"<br/>\nYou can change this robot to <code>simulate=true</code> and run it.")
"<br/>You can change this robot to <code>simulate=true</code> and run it.")
}
else if (this_robot.simulate === null){
if ((sim_actual === false) || (sim_actual === "both")){
this_job.stop_for_reason("errored", "The job: " + this_job.name + " is using robot: " + this_robot.name +
'<br/>\nwith the Jobs menu "Simulate?" item being: ' + sim_actual +
"<br/>\nbut could not connect with Dexter." +
"<br/>\nYou can use the simulator by switching the menu item to 'true'. ")
'<br/>with the Jobs menu "Simulate?" item being: ' + sim_actual +
"<br/>but could not connect with Dexter." +
"<br/>You can use the simulator by switching the menu item to 'true'. ")
out("Could not connect to Dexter.", "red")
}
else {
Expand Down Expand Up @@ -1965,8 +1965,9 @@ Dexter.write_file = function(file_name=null, content=""){
return instrs
}

//depricated. Note reversed args from Dexter.write_file
//depricated. Note reversed args from Dexter.write_file and default path adjustment
Dexter.write_to_robot = function(content="", file_name=null){
file_name = Dexter.srv_samba_share_default_to_absolute_path(file_name)
return Dexter.write_file(file_name, content)
}

Expand Down Expand Up @@ -2009,12 +2010,27 @@ new Job({name: "my_job",
do_list: [out(Dexter.write_file(data, "/srv/samba/share/test.txt"))]})
*/

Dexter.read_file = function (source, destination){
Dexter.read_file = function(source, destination="read_file_content"){
return new Instruction.Dexter.read_file(source, destination)
}
Dexter.read_from_robot = Dexter.read_file //depricated
//examples pf path input:
// ./foo.txt => /srv/samba/share/foo.txt
// ../foo.txt => /srv/samba/foo.txt
// foo.txt => /srv/samba/share/foo.txt
Dexter.srv_samba_share_default_to_absolute_path = function(path){
if (path.startsWith("/")) { return path }
else if (path.startsWith("#")) { return path }
else if (path.startsWith("./")) { return "/srv/samba/share/" + path.substring(2) }
else if (path.startsWith("../")) { return "/srv/samba/" + path.substring(3) }
else { return "/srv/samba/share/" + path }
}

Dexter.read_from_robot = function (source, destination="read_file_content"){ //depricated. simlar to read_file but differs in that srv_sama_share is the default folder
source = Dexter.srv_samba_share_default_to_absolute_path(source)
return Dexter.read_file(source, destination)
}

Dexter.prototype.read_file = function (source, destination){
Dexter.prototype.read_file = function (source, destination="read_file_content"){
return new Instruction.Dexter.read_file(source, destination, this)
}

Expand Down
Loading

0 comments on commit 3962018

Please sign in to comment.