Skip to content

Commit

Permalink
Micropython - File upload: Transfer as a list of bytes(numbers)
Browse files Browse the repository at this point in the history
  • Loading branch information
oddstr13 committed Apr 28, 2017
1 parent 8a7471f commit 80893ea
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ESPlorer/src/ESPlorer/pyFiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ public boolean Put(String ft, String[] s) {
boolean success = true;
sendBuf = new ArrayList<String>();

sendBuf.add("f=open('" + escape(ft) + "','w')");
sendBuf.add("f=open('" + escape(ft) + "','wb')");
for (String subs : s) {
sendBuf.add("f.write('" + escape(subs) + "\\n')");
sendBuf.add("f.write(bytes(" + lineToByteList(subs) + "))");
}
sendBuf.add("f.close()");
sendBuf.add("del f");

return success;
}
Expand Down Expand Up @@ -63,6 +64,21 @@ public String GetParent() {
public boolean isExist() {
return false;
}

public String lineToByteList(String str) {
StringBuilder buf = new StringBuilder((str.length() * 4)+5);
buf.append('[');

for(byte b : str.getBytes()) {
buf.append(String.valueOf(b));
buf.append(',');
}

buf.append("10"); // \n - newline
buf.append(']');

return buf.toString();
}

public String escape(String str) {
char ch;
Expand Down

0 comments on commit 80893ea

Please sign in to comment.