Run program after flashing
This commit is contained in:
parent
e6a72ba56a
commit
3010b29a26
@ -7,4 +7,4 @@ set -xe
|
|||||||
cd $LEGO/lmssrc/adk/lmsasm
|
cd $LEGO/lmssrc/adk/lmsasm
|
||||||
java -jar assembler.jar $F
|
java -jar assembler.jar $F
|
||||||
cd "$P"
|
cd "$P"
|
||||||
node -p 'require("fs").readFileSync("pxt.rbf").toString("hex")'
|
node -p 'require("fs").readFileSync("pxt.rbf").toString("hex").replace(/5858585858(58)+/, "XX")'
|
||||||
|
@ -8,8 +8,7 @@ eval("if (typeof process === 'object' && process + '' === '[object process]') px
|
|||||||
|
|
||||||
namespace pxt.editor {
|
namespace pxt.editor {
|
||||||
// this comes from aux/pxt.lms
|
// this comes from aux/pxt.lms
|
||||||
const rbfTemplate = "4c45474f5d0000006d000100000000001c0000000000000008000000821b028405018130813e805374617274696e672e2e2e00840060805858585858585858580044830383010640414082f5ff8405018130813e80427965210084000a";
|
const rbfTemplate = "4c45474f5d0000006d000100000000001c0000000000000008000000821b028405018130813e805374617274696e672e2e2e0084006080XX0044830383010640414082f5ff8405018130813e80427965210084000a";
|
||||||
|
|
||||||
|
|
||||||
function hf2Async() {
|
function hf2Async() {
|
||||||
return pxt.HF2.mkPacketIOAsync()
|
return pxt.HF2.mkPacketIOAsync()
|
||||||
@ -38,14 +37,19 @@ namespace pxt.editor {
|
|||||||
return initAsync()
|
return initAsync()
|
||||||
.then(w_ => {
|
.then(w_ => {
|
||||||
w = w_
|
w = w_
|
||||||
|
// run LS to make sure we can talk to device first
|
||||||
|
// otherwise flashing a file might lock it
|
||||||
|
return w.lsAsync("/")
|
||||||
|
}).then(() => {
|
||||||
let f = U.stringToUint8Array(atob(resp.outfiles[pxt.outputName()]))
|
let f = U.stringToUint8Array(atob(resp.outfiles[pxt.outputName()]))
|
||||||
return w.flashAsync(elfPath, f)
|
return w.flashAsync(elfPath, f)
|
||||||
})
|
}).then(() => {
|
||||||
.then(() => {
|
let rbfHex = rbfTemplate.replace("XX", U.toHex(U.stringToUint8Array(elfPath)))
|
||||||
let rbfHex = rbfTemplate.replace(/58585858(58)+/, U.toHex(U.stringToUint8Array(elfPath)))
|
|
||||||
let rbf = U.fromHex(rbfHex)
|
let rbf = U.fromHex(rbfHex)
|
||||||
HF2.write16(rbf, 4, rbf.length)
|
HF2.write16(rbf, 4, rbf.length)
|
||||||
return w.flashAsync(rbfPath, rbf)
|
return w.flashAsync(rbfPath, rbf)
|
||||||
|
}).then(() => {
|
||||||
|
return w.runAsync(rbfPath)
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
if (isCli)
|
if (isCli)
|
||||||
return w.disconnectAsync()
|
return w.disconnectAsync()
|
||||||
@ -61,4 +65,4 @@ namespace pxt.editor {
|
|||||||
};
|
};
|
||||||
return Promise.resolve<pxt.editor.ExtensionResult>(res);
|
return Promise.resolve<pxt.editor.ExtensionResult>(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@ namespace pxt.editor {
|
|||||||
size?: number;
|
size?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const runTemplate = "C00882010084XX0060640301606400"
|
||||||
|
|
||||||
export class Ev3Wrapper {
|
export class Ev3Wrapper {
|
||||||
msgs = new U.PromiseBuffer<Uint8Array>()
|
msgs = new U.PromiseBuffer<Uint8Array>()
|
||||||
private cmdSeq = U.randomUint32() & 0xffff;
|
private cmdSeq = U.randomUint32() & 0xffff;
|
||||||
@ -24,33 +26,52 @@ namespace pxt.editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private alloc(addSize: number, cmd: number, replyType = 1) {
|
private allocCore(addSize: number, replyType: number) {
|
||||||
let len = 6 + addSize
|
let len = 5 + addSize
|
||||||
let buf = new Uint8Array(len)
|
let buf = new Uint8Array(len)
|
||||||
HF2.write16(buf, 0, len - 2) // pktLen
|
HF2.write16(buf, 0, len - 2) // pktLen
|
||||||
HF2.write16(buf, 2, this.cmdSeq++) // msgCount
|
HF2.write16(buf, 2, this.cmdSeq++) // msgCount
|
||||||
buf[4] = replyType
|
buf[4] = replyType
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
|
private allocSystem(addSize: number, cmd: number, replyType = 1) {
|
||||||
|
let buf = this.allocCore(addSize + 1, replyType)
|
||||||
buf[5] = cmd
|
buf[5] = cmd
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runAsync(path: string) {
|
||||||
|
let codeHex = runTemplate.replace("XX", U.toHex(U.stringToUint8Array(path)))
|
||||||
|
let code = U.fromHex(codeHex)
|
||||||
|
let pkt = this.allocCore(2 + code.length, 0)
|
||||||
|
HF2.write16(pkt, 5, 0x0800)
|
||||||
|
U.memcpy(pkt, 7, code)
|
||||||
|
log(`run ${path}`)
|
||||||
|
return this.talkAsync(pkt)
|
||||||
|
.then(buf => {
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
talkAsync(buf: Uint8Array) {
|
talkAsync(buf: Uint8Array) {
|
||||||
return this.io.sendPacketAsync(buf)
|
return this.io.sendPacketAsync(buf)
|
||||||
.then(() => this.msgs.shiftAsync(1000))
|
.then(() => this.msgs.shiftAsync(1000))
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
if (resp[2] != buf[2] || resp[3] != buf[3])
|
if (resp[2] != buf[2] || resp[3] != buf[3])
|
||||||
U.userError("msg count de-sync")
|
U.userError("msg count de-sync")
|
||||||
if (resp[5] != buf[5])
|
if (buf[4] == 1) {
|
||||||
U.userError("cmd de-sync")
|
if (resp[5] != buf[5])
|
||||||
if (resp[6] != 0 && resp[6] != 8 /* EOF */)
|
U.userError("cmd de-sync")
|
||||||
U.userError("cmd error: " + resp[6])
|
if (resp[6] != 0 && resp[6] != 1 /* LS? */ && resp[6] != 8 /* EOF */)
|
||||||
|
U.userError("cmd error: " + resp[6])
|
||||||
|
}
|
||||||
return resp
|
return resp
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
flashAsync(path: string, file: Uint8Array) {
|
flashAsync(path: string, file: Uint8Array) {
|
||||||
log(`write ${file.length} to ${path}`)
|
log(`write ${file.length} to ${path}`)
|
||||||
let begin = this.alloc(4 + path.length + 1, 0x92)
|
let begin = this.allocSystem(4 + path.length + 1, 0x92)
|
||||||
HF2.write32(begin, 6, file.length) // fileSize
|
HF2.write32(begin, 6, file.length) // fileSize
|
||||||
U.memcpy(begin, 10, U.stringToUint8Array(path))
|
U.memcpy(begin, 10, U.stringToUint8Array(path))
|
||||||
|
|
||||||
@ -58,7 +79,7 @@ namespace pxt.editor {
|
|||||||
if (pos >= file.length) return Promise.resolve()
|
if (pos >= file.length) return Promise.resolve()
|
||||||
let size = file.length - pos
|
let size = file.length - pos
|
||||||
if (size > 1000) size = 1000
|
if (size > 1000) size = 1000
|
||||||
let upl = this.alloc(1 + size, 0x93, 0x1)
|
let upl = this.allocSystem(1 + size, 0x93, 0x1)
|
||||||
upl[6] = handle
|
upl[6] = handle
|
||||||
U.memcpy(upl, 6 + 1, file, pos, size)
|
U.memcpy(upl, 6 + 1, file, pos, size)
|
||||||
return this.talkAsync(upl)
|
return this.talkAsync(upl)
|
||||||
@ -74,7 +95,7 @@ namespace pxt.editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lsAsync(path: string): Promise<DirEntry[]> {
|
lsAsync(path: string): Promise<DirEntry[]> {
|
||||||
let lsReq = this.alloc(2 + path.length + 1, 0x99)
|
let lsReq = this.allocSystem(2 + path.length + 1, 0x99)
|
||||||
HF2.write16(lsReq, 6, 1024) // maxRead
|
HF2.write16(lsReq, 6, 1024) // maxRead
|
||||||
U.memcpy(lsReq, 8, U.stringToUint8Array(path))
|
U.memcpy(lsReq, 8, U.stringToUint8Array(path))
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
screen.clear()
|
screen.clear()
|
||||||
screen.setFont(ScreenFont.Large)
|
screen.setFont(ScreenFont.Large)
|
||||||
screen.drawText(10, 30, "Hello PXT!")
|
screen.drawText(10, 30, "Welcome PXT!")
|
||||||
|
|
||||||
screen.drawEllipse(40, 40, 20, 10, Draw.Fill)
|
screen.drawEllipse(40, 40, 20, 10, Draw.Fill)
|
||||||
output.setLights(LightsPattern.Orange)
|
output.setLights(LightsPattern.Orange)
|
||||||
|
Loading…
Reference in New Issue
Block a user