Skip to content

Commit

Permalink
Showing 9 changed files with 112 additions and 948 deletions.
2 changes: 1 addition & 1 deletion core/socket.js
Original file line number Diff line number Diff line change
@@ -302,7 +302,7 @@ var Socket = class Socket{
else {
payload_string = payload_string_maybe
}
Socket.r_payload_grab_aux(robot_status, payload_string)
Socket.r_payload_grab_aux(robot_status, payload_string.toString()) //beware, sometimes payload_string is a buffer. This converts it to a string.
}

//called by both Socket.r_payload_grab AND DexterSim.process_next_instruction_r
147 changes: 70 additions & 77 deletions core/storage.js
Original file line number Diff line number Diff line change
@@ -227,47 +227,41 @@ module.exports.file_content = file_content //depricated
//callback passed err, and data.
//If error is non-null, its an error object or a string error message.
//if it is null, data is a string of the file content.
//but beware, sometimes data is a BUFFER not a string.
// data.toString() will convert a buffer to a string,
//and just returns the string if data happens to be a string
function read_file_async(path, encoding="utf8", callback){
let colon_pos = path.indexOf(":")
if(colon_pos == -1) {
path = make_full_path(path)
fs.readFile(path, encoding, callback)
}
else {
let dex_name_maybe = path.substring(0, colon_pos)
let dex = Dexter[dex_name_maybe]
if(dex){
let dex_file_path = path.substring(colon_pos + 1)
let the_callback = callback
let the_path = path
new Job({name: "dex_file_read",
do_list: [
dex.read_file(dex_file_path, "file_content"),
function(){
let cont = this.user_data.file_content
if(typeof(cont) == "string"){
the_callback(null, cont)
}
else {
let err = new Error("Error getting file content for: " + the_path + " with error number: " + cont, the_path)
the_callback(err, cont)
}
}
],
when_stopped: function(){ //this code OUGHT to be called but as of apr 2019, if we error due to dexter not connected, then Job,.finish is never called so we don't call this method. Handle it in Job.stop_for_reason
if(this.status_code == "errored"){
if(window.Editor) { //won't hit in node, bu won't error either
Editor.set_files_menu_to_path() //restore files menu to what it was before we tried to get the file off of dexter.
}
if(is_dexter_path(path)){
let dex_file_path = path.substring(colon_pos + 1)
let the_callback = callback
let the_path = path
new Job({name: "dex_file_read",
do_list: [
dex.read_file(dex_file_path, "file_content"),
function(){
let cont = this.user_data.file_content
if(typeof(cont) == "string"){
the_callback(null, cont)
}
else {
let err = new Error("Error getting file content for: " + the_path + " with error number: " + cont, the_path)
the_callback(err, cont)
}
}
],
when_stopped: function(){ //this code OUGHT to be called but as of apr 2019, if we error due to dexter not connected, then Job,.finish is never called so we don't call this method. Handle it in Job.stop_for_reason
if(this.status_code == "errored"){
if(window.Editor) { //won't hit in node, bu won't error either
Editor.set_files_menu_to_path() //restore files menu to what it was before we tried to get the file off of dexter.
}
}
}).start()
}
else {
path = make_full_path(path)
fs.readFile(path, callback)
}
}
}
}).start()
}
else {
path = make_full_path(path)
fs.readFile(path, callback)
}
}

module.exports.read_file_async = read_file_async
@@ -355,49 +349,33 @@ function write_file_async(path, content, encoding="utf8", callback){
if (content === undefined) {
content = Editor.get_javascript()
}
let colon_pos = path.indexOf(":")
if(colon_pos == -1) {
path = make_full_path(path)
if(!callback) {
let the_path = path
callback = function(err){
if(err){
dde_error("write_file_async passed: " + the_path +
"<br/>Got error: " + err.message)
}
else { out("saved: " + the_path, undefined, true) }
if(!callback) {
let the_path = path
callback = function(err){
if(err){
dde_error("write_file_async passed: " + the_path +
"<br/>Got error: " + err.message)
}
else { out("saved: " + the_path, undefined, true) }
}
fs.writeFile(path, content, encoding, callback)
}
else {
if(is_dexter_path(path)){
let colon_pos = path.indexOf(":") //will not return -1
let dex_name_maybe = path.substring(0, colon_pos)
let dex = Dexter[dex_name_maybe]
if(!callback) {
let the_path = path
callback = function(err){
if(err){
dde_error("write_file_async passed: " + the_path +
"<br/>Got error: " + err.message)
}
else { out("Saved: " + the_path, undefined, true) }
}
}
if(dex){
let dex_file_path = path.substring(colon_pos + 1)
let the_callback = callback
let the_path = path
new Job({name: "dex_file_read",
do_list: [
dex.write_file(dex_file_path, content),
callback //but never passes an error object. not good, but robot_status should contain an error, and error if there is one, else callback should be called with no error so it does what it should do when no error
]
}).start()
}
else {
path = make_full_path(path)
fs.writeFile(path, content, encoding, callback)
}
let dex = Dexter[dex_name_maybe] // will be a real robot
let dex_file_path = path.substring(colon_pos + 1)
let the_callback = callback
let the_path = path
new Job({name: "dex_file_read",
do_list: [
dex.write_file(dex_file_path, content),
callback //but never passes an error object. not good, but robot_status should contain an error, and error if there is one, else callback should be called with no error so it does what it should do when no error
]
}).start()
}
else {
path = make_full_path(path)
fs.writeFile(path, content, encoding, callback)
}
}

@@ -523,6 +501,21 @@ function is_root_path(path){
else { return false }
//return starts_with_one_of(path, ["/", "C:", "D:", "E:", "F:", "G:"]) //C: etc. is for Windows OS.
}
//returns true if its a path that isn't a top level, has a colon and the
//substring between the beginning of the path and the colon names a defined dexter.
//Beware that if the dexter is not defined YET, then this will return false.
function is_dexter_path(path){
if(is_root_path(path)) { return false }
else {
let colon_pos = path.indexOf(":")
if(colon_pos == -1) { return false }
else {
let dex_name_maybe = path.substring(0, colon_pos)
if(Dexter[dex_name_maybe]) { return true }
else { return false}
}
}
}

//______new load_files synchronous______
//verify all paths first before loading any of them because we want to error early.
25 changes: 20 additions & 5 deletions doc/ref_man.html
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@
</details>

<details id="read_file_doc_id" style="margin-left:40px;"><summary>read_file</summary>
<code>read_file</code> takes an argument of a file path,
<code>read_file</code> is a function that takes an argument of a file path,
and returns a string of the content of the file.<br/>
<i>Parameters:</i><br/>
<b>path</b> A string of a path to the file. Usually this will not start with a slash,
@@ -119,6 +119,11 @@
<p></p>
See <a href="#" onclick="open_doc(load_files_doc_id)">load_files</a>
for grabbing the file contents, then evaling it.
<p/></p>
See also Dexter instruction: <a href="#" onclick="open_doc('Dexter.read_file_doc_id')">Dexter.read_file</a>
<p></p>
<span style="color:red;">file_content</span> has been deprecated.
Please use <code>read_file</code> instead.
</details> <!-- end read_file -->

<details id="Editor.edit_file_doc_id" style="margin-left:40px;"><summary>Editor.edit_file</summary>
@@ -207,7 +212,10 @@
Makes the folder dde_apps/foo. Inside of it is placed
a folder named "bar", and inside of that is placed a folder "baz".
</details>
<details id="write_file_doc_id" style="margin-left:40px;"><summary>write_file</summary>

<details id="write_file_doc_id" style="margin-left:40px;"><summary>write_file</summary>
<code>write_file</code> is a function that takes an argument of a file path
and a new content string. It sets the content of that file.<br/>
Arguments:<br/>
<b>filepath</b> The location to save to. It will overwrite the current content.
Defaults to the file currently in the
@@ -219,7 +227,9 @@
<code>write_file("junk.js")</code> Gives foo.js the content now in the editor.
This is the <i>save_as</i> functionality.<br/>
<code>write_file("junk.js", "new content")</code> Replaces the existing content
of the given file with "new content".<br/>
of the given file with "new content".
<p></p>
See also Dexter instruction: <a href="#" onclick="open_doc('Dexter.write_file_doc_id')">Dexter.write_file</a>
</details>

<!-- removed for security reasons
@@ -5210,7 +5220,7 @@
could not be retrieved, but the Job itself does not error.
Subsequent instructions can test for the validity of the content with
<code title="unEVALable">typeof(this.user_data.{destination}) == "string")</code><br/>
Thus <i>read_file</i> can be used to test for the existence of the file,
Thus <i>Dexter.read_file</i> can be used to test for the existence of the file,
not just get its content.
<p></p>
<i>Example:</i>
@@ -5224,6 +5234,8 @@
else { out("can't find file: aa.dde") }
}
]})</code></pre>
See also <a href="#" onclick="open_doc(read_file_doc_id)">read_file</a>

</details>

<details id="Dexter.run_gcode_doc_id" class="doc_details"><summary>run_gcode</summary>
@@ -5337,7 +5349,8 @@
to wait for 2 seconds.
</details>
<details id="Dexter.write_file_doc_id" class="doc_details"><summary>write_file</summary>
Writes a file on Dexter's file system. The file is transmitted through
A Dexter instruction that Writes a file on Dexter's file system.
The file is transmitted through
DDE's socket interface to the Linux OS runnning on Dexter's processor
board.<br/>
<i>Parameters:</i><br/>
@@ -5352,6 +5365,8 @@
<i>Example:</i><br/>
<code>Dexter.write_file("/srv/samba/share/greeting.txt", "hello world")</code><br/>
This instruction requires an upgrade to Dexter's software available May, 2018.
<p></p>
See also <a href="#" onclick="open_doc('write_file_doc_id')">write_file</a>
</details>
</details> <!-- end dexter_instructions -->

14 changes: 13 additions & 1 deletion doc/release_notes.html
Original file line number Diff line number Diff line change
@@ -6,6 +6,18 @@
.doc_details summary { font-weight: 600; }
</style>

<details class="doc_details"><summary>v 3.3.3, May 2, 2019</summary>
Highlights: bug fixes.
<ul>
<li> Fixed bug: DXF.string_to_lines is now bound to txt.string_to_lines</li>

<li> improved documentation for read_file and write_file.</li>

<li> file menu open bug on WindowsOS fixed.</li>

</ul>
</details>

<details class="doc_details"><summary>v 3.3.2, May 2, 2019</summary>
Hightlights: File menu extensions. read_file & write_file names
now more consistent. Eval button functionality improved.
@@ -33,7 +45,7 @@
(lots of pnctuation chars added).
string_to_lines is not yet documented, but will be soon.</li>

<li> <code>file_content</code> deprecatred and replaced by <code>read_file</code>.<br/>
<li> <code>file_content</code> deprecated and replaced by <code>read_file</code>.<br/>
<code>file_content_async</code> deprecated and replace by <code>read_file_async</code><br/>
<code>Dexter.read_from_robot</code> deprecated and replaced by <code>Dexter.read_file</code>.<br/>
<code>Dexter.write_to_robot</code> deprecated and replaced by <code>Dexter.write_file</code>.
4 changes: 3 additions & 1 deletion editor.js
Original file line number Diff line number Diff line change
@@ -158,7 +158,8 @@ Editor.make_files_menu_path = function(folder, name) {
}


//returns an array of folder and file name. The folder always ends with slash or colon.
//returns an array of folder and file name.
// The returned folder always ends with slash or colon.
Editor.path_to_folder_and_name = function(path){
let file_name_start_index = path.lastIndexOf("/")
if(file_name_start_index == -1) { file_name_start_index = path.lastIndexOf(":") } //happens with dexter0:foo.js
@@ -647,6 +648,7 @@ Editor.edit_file = function(path){ //path could be "new buffer"
dde_error(err.message)
}
else {
content = content.toString() //because sometimes the content passed in is buffer, not a string. This handles both.
Editor.edit_file_aux(the_path, content)
}
})
3 changes: 3 additions & 0 deletions math/DXF.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
//James Wigglesworth
//Started: 2_10_2017
//Updated: 1_26_19
var txt = require("./txt.js") //doesn't work if its at the bottom so put it at top

var DXF = new function(){

@@ -1410,6 +1411,8 @@ this.dxf_to_instructions = function({
var Coor = require("./Coor.js")
var Vector = require("./Vector.js")
var Kin = require("./Kin.js")
//var txt = require("./txt.js") //doesn't work if its at the bottom, so put it at top


var {dde_error, warning, point_object_to_array, scale_point} = require("../core/utils.js")
var {read_file} = require("../core/storage.js")
2 changes: 1 addition & 1 deletion math/txt.js
Original file line number Diff line number Diff line change
@@ -3117,5 +3117,5 @@ var txt = new function(){
}

}
module.exports.txt = txt
module.exports = txt

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dexter_dev_env",
"productName": "dexter_dev_env",
"version": "3.3.2",
"version": "3.3.3",
"release_date": "May 2, 2019",
"description": "Dexter Development Environment",
"author": "Fry",
861 changes: 0 additions & 861 deletions three-revision-83.min.js

This file was deleted.

0 comments on commit 3afa4dc

Please sign in to comment.