Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
80 lines (73 loc) · 2.06 KB

File metadata and controls

80 lines (73 loc) · 2.06 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {
bufferEq,
delay,
DeviceScriptManagerCmd,
DeviceScriptManagerReg,
JDBus,
JDService,
OutPipe,
prettySize,
sha256,
SRV_DEVICE_SCRIPT_MANAGER,
toHex,
} from "jacdac-ts"
import { devsStartWithNetwork } from "./build"
import { error } from "./command"
import { readCompiled } from "./run"
import { BuildOptions } from "./sideprotocol"
export interface RunOptions {
tcp?: boolean
}
export async function deployScript(
fn: string,
options: RunOptions & BuildOptions
) {
const inst = await devsStartWithNetwork(options)
inst.deployHandler = code => {
if (code) error(`deploy error ${code}`)
process.exit(code)
}
const prog = await readCompiled(fn, options)
const r = inst.devsClientDeploy(prog.binary)
if (r) throw new Error("deploy error: " + r)
console.log(`remote-deployed ${fn}`)
}
export async function deployToService(
service: JDService,
bytecode: Uint8Array
) {
console.log(`deploy to ${service.device}`)
const sha = service.register(DeviceScriptManagerReg.ProgramSha256)
await sha.refresh()
if (sha.data?.length == 32) {
const exp = await sha256([bytecode])
if (bufferEq(exp, sha.data)) {
console.log(` sha256 match ${toHex(exp)}, skip`)
const running = service.register(DeviceScriptManagerReg.Running)
await running.sendSetBoolAsync(false)
await delay(10)
await running.sendSetBoolAsync(true)
return
}
}
await OutPipe.sendBytes(
service,
DeviceScriptManagerCmd.DeployBytecode,
bytecode,
p => {
// console.debug(` prog: ${(p * 100).toFixed(1)}%`)
}
)
console.log(` --> done, ${prettySize(bytecode.length)}`)
}
export async function deployToBus(bus: JDBus, bytecode: Uint8Array) {
let num = 0
for (const service of bus.services({
serviceClass: SRV_DEVICE_SCRIPT_MANAGER,
lost: false,
})) {
await deployToService(service, bytecode)
num++
}
return num
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.