Skip to content

Commit 18234c3

Browse files
authored
Merge pull request #13 from jaculus-org/feat/lib
Implement libs (Project, Package, Registry)
2 parents 80b3b10 + c830442 commit 18234c3

67 files changed

Lines changed: 4888 additions & 899 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
"@eslint/js": "^9.38.0",
2121
"@jaculus/link": "workspace:*",
2222
"@jaculus/project": "workspace:*",
23+
"jaculus-tools": "workspace:*",
24+
"@jaculus/common": "workspace:*",
25+
"@obsidize/tar-browserify": "^6.3.2",
2326
"@types/chai": "^4.3.20",
2427
"@types/mocha": "^10.0.10",
2528
"@types/node": "^24.0.7",
29+
"@types/pako": "^2.0.4",
2630
"@zenfs/core": "^1.11.4",
2731
"chai": "^5.1.2",
2832
"chai-bytes": "^0.1.2",
@@ -31,6 +35,7 @@
3135
"husky": "^9.1.7",
3236
"jiti": "^2.5.1",
3337
"mocha": "^11.7.2",
38+
"pako": "^2.1.0",
3439
"prettier": "^3.6.2",
3540
"queue-fifo": "^0.2.5",
3641
"tsx": "^4.20.6",

packages/common/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
"author": {
1010
"name": "Petr Kubica (cubicap)"
1111
},
12+
"contributors": [
13+
{
14+
"name": "Jakub Andrýsek (JakubAndrysek)",
15+
"url": "https://kubaandrysek.cz/"
16+
}
17+
],
1218
"license": "GPL-3.0-only",
1319
"type": "module",
1420
"exports": {

packages/common/src/buffer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export function concatUint8Arrays(chunks: Uint8Array[]): Uint8Array {
2+
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
3+
const result = new Uint8Array(totalLength);
4+
let offset = 0;
5+
for (const chunk of chunks) {
6+
result.set(chunk, offset);
7+
offset += chunk.length;
8+
}
9+
return result;
10+
}

packages/common/src/bundle.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface ProjectBundle {
2+
dirs: Set<string>;
3+
files: Record<string, Uint8Array>;
4+
}

packages/common/src/index.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
type LogMethod = (message?: string) => void;
2-
3-
export interface Logger {
4-
error: LogMethod;
5-
warn: LogMethod;
6-
info: LogMethod;
7-
verbose: LogMethod;
8-
debug: LogMethod;
9-
silly: LogMethod;
10-
}
1+
export { Logger } from "./logger.js";
2+
export { RequestFunction, getRequestJson, JaculusRequestError } from "./request.js";
3+
export { concatUint8Arrays } from "./buffer.js";
4+
export { type ProjectBundle } from "./bundle.js";

packages/common/src/logger.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type LogMethod = (message?: string) => void;
2+
3+
export interface Logger {
4+
error: LogMethod;
5+
warn: LogMethod;
6+
info: LogMethod;
7+
verbose: LogMethod;
8+
debug: LogMethod;
9+
silly: LogMethod;
10+
}

packages/common/src/request.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export type RequestFunction = (baseUri: string, libFile: string) => Promise<Uint8Array>;
2+
3+
export async function getRequestJson(
4+
getRequest: RequestFunction,
5+
baseUri: string,
6+
libFile: string
7+
): Promise<any> {
8+
return getRequest(baseUri, libFile).then((data) => {
9+
const text = new TextDecoder().decode(data);
10+
return JSON.parse(text);
11+
});
12+
}
13+
14+
export class JaculusRequestError extends Error {
15+
constructor(message: string) {
16+
super(message);
17+
this.name = "JaculusRequestError";
18+
}
19+
}

packages/device/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
"author": {
1010
"name": "Petr Kubica (cubicap)"
1111
},
12+
"contributors": [
13+
{
14+
"name": "Jakub Andrýsek (JakubAndrysek)",
15+
"url": "https://kubaandrysek.cz/"
16+
}
17+
],
1218
"license": "GPL-3.0-only",
1319
"type": "module",
1420
"main": "./dist/device.js",

packages/device/src/controller.ts

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,32 @@ export const ControllerCommandStrings: Record<ControllerCommand, string> = {
3838
[ControllerCommand.CONFIG_ERASE]: "CONFIG_ERASE",
3939
};
4040

41+
enum WifiKvNs {
42+
Ssids = "wifi_net",
43+
Main = "wifi_cfg",
44+
}
45+
46+
enum WifiKeys {
47+
Mode = "mode",
48+
StaMode = "sta_mode",
49+
StaSpecific = "sta_ssid",
50+
StaApFallback = "sta_ap_fallback",
51+
ApSsid = "ap_ssid",
52+
ApPass = "ap_pass",
53+
CurrentIp = "current_ip",
54+
}
55+
56+
export enum WifiMode {
57+
DISABLED = 0,
58+
STATION = 1,
59+
AP = 2,
60+
}
61+
62+
export enum WifiStaMode {
63+
BEST_SIGNAL = 0,
64+
SPECIFIC_SSID = 1,
65+
}
66+
4167
enum KeyValueDataType {
4268
INT64 = 0,
4369
FLOAT32 = 1,
@@ -82,8 +108,8 @@ export class Controller {
82108
return false;
83109
}
84110

85-
public start(path: string): Promise<void> {
86-
this._logger?.verbose("Starting program: " + path);
111+
public start(entryPoint: string = ""): Promise<void> {
112+
this._logger?.verbose("Starting program: " + (entryPoint ? entryPoint : ""));
87113
return new TimeoutPromise(
88114
TIMEOUT_MS,
89115
(resolve, reject) => {
@@ -98,7 +124,7 @@ export class Controller {
98124

99125
const packet = this._out.buildPacket();
100126
packet.put(ControllerCommand.START);
101-
for (const c of path) {
127+
for (const c of entryPoint) {
102128
packet.put(c.charCodeAt(0));
103129
}
104130
packet.send();
@@ -449,4 +475,67 @@ export class Controller {
449475
}
450476
);
451477
}
478+
479+
// WiFi Configuration Methods
480+
public async addWifiNetwork(ssid: string, password: string): Promise<void> {
481+
this._logger?.verbose(`Adding WiFi network: ${ssid}`);
482+
return this.configSetString(WifiKvNs.Ssids, ssid.substring(0, 15), password);
483+
}
484+
485+
public async removeWifiNetwork(ssid: string): Promise<void> {
486+
this._logger?.verbose(`Removing WiFi network: ${ssid}`);
487+
return this.configErase(WifiKvNs.Ssids, ssid);
488+
}
489+
490+
public getWifiMode(): Promise<WifiMode> {
491+
return this.configGetInt(WifiKvNs.Main, WifiKeys.Mode) as Promise<WifiMode>;
492+
}
493+
494+
public setWifiMode(mode: WifiMode): Promise<void> {
495+
return this.configSetInt(WifiKvNs.Main, WifiKeys.Mode, mode);
496+
}
497+
498+
public getWifiStaMode(): Promise<WifiStaMode> {
499+
return this.configGetInt(WifiKvNs.Main, WifiKeys.StaMode) as Promise<WifiStaMode>;
500+
}
501+
502+
public setWifiStaMode(mode: WifiStaMode): Promise<void> {
503+
return this.configSetInt(WifiKvNs.Main, WifiKeys.StaMode, mode);
504+
}
505+
506+
public getWifiStaSpecific(): Promise<string> {
507+
return this.configGetString(WifiKvNs.Main, WifiKeys.StaSpecific);
508+
}
509+
510+
public setWifiStaSpecific(ssid: string): Promise<void> {
511+
return this.configSetString(WifiKvNs.Main, WifiKeys.StaSpecific, ssid);
512+
}
513+
514+
public getWifiStaApFallback(): Promise<number> {
515+
return this.configGetInt(WifiKvNs.Main, WifiKeys.StaApFallback);
516+
}
517+
518+
public setWifiStaApFallback(enabled: boolean): Promise<void> {
519+
return this.configSetInt(WifiKvNs.Main, WifiKeys.StaApFallback, enabled ? 1 : 0);
520+
}
521+
522+
public getWifiApSsid(): Promise<string> {
523+
return this.configGetString(WifiKvNs.Main, WifiKeys.ApSsid);
524+
}
525+
526+
public setWifiApSsid(ssid: string): Promise<void> {
527+
return this.configSetString(WifiKvNs.Main, WifiKeys.ApSsid, ssid);
528+
}
529+
530+
public getWifiApPassword(): Promise<string> {
531+
return this.configGetString(WifiKvNs.Main, WifiKeys.ApPass);
532+
}
533+
534+
public setWifiApPassword(password: string): Promise<void> {
535+
return this.configSetString(WifiKvNs.Main, WifiKeys.ApPass, password);
536+
}
537+
538+
public getCurrentWifiIp(): Promise<string> {
539+
return this.configGetString(WifiKvNs.Main, WifiKeys.CurrentIp);
540+
}
452541
}

packages/device/src/device.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import {
99
} from "@jaculus/link/muxCommunicator";
1010
import { CobsEncoder } from "@jaculus/link/encoders/cobs";
1111
import { Uploader } from "./uploader.js";
12-
import { Controller } from "./controller.js";
12+
import { Controller, WifiMode, WifiStaMode } from "./controller.js";
1313

14-
export { Uploader, Controller };
14+
export { Uploader, type UploaderProgress, type UploaderProgressCallback } from "./uploader.js";
15+
export { type ProjectBundle } from "@jaculus/common";
16+
export { Controller, WifiMode, WifiStaMode };
1517

1618
export class JacDevice {
1719
private _mux: Mux;

0 commit comments

Comments
 (0)