Browse Source

Fixes

pull/110/head
Malte Grimm 3 years ago
parent
commit
66466ac5d5
  1. 3
      src/components/PageComponents/Config/Bluetooth.tsx
  2. 3
      src/components/PageComponents/Config/Device.tsx
  3. 3
      src/components/PageComponents/Config/Display.tsx
  4. 3
      src/components/PageComponents/Config/LoRa.tsx
  5. 3
      src/components/PageComponents/Config/Network.tsx
  6. 3
      src/components/PageComponents/Config/Position.tsx
  7. 3
      src/components/PageComponents/Config/Power.tsx
  8. 78
      src/core/flashing/Flasher.ts
  9. 38
      src/core/stores/appStore.ts

3
src/components/PageComponents/Config/Bluetooth.tsx

@ -21,13 +21,14 @@ export const Bluetooth = (): JSX.Element => {
}, },
} : undefined; } : undefined;
const isPresetConfig = !("id" in config); const isPresetConfig = !("id" in config);
const { setWorkingConfig } = !isPresetConfig ? useDevice() : { setWorkingConfig: undefined };
const setConfig: (data: BluetoothValidation) => void = const setConfig: (data: BluetoothValidation) => void =
isPresetConfig ? (data) => { isPresetConfig ? (data) => {
config.config.bluetooth = new Protobuf.Config_BluetoothConfig(data); config.config.bluetooth = new Protobuf.Config_BluetoothConfig(data);
(config as ConfigPreset).saveConfigTree(); (config as ConfigPreset).saveConfigTree();
} }
: (data) => { : (data) => {
useDevice().setWorkingConfig!( setWorkingConfig!(
new Protobuf.Config({ new Protobuf.Config({
payloadVariant: { payloadVariant: {
case: "bluetooth", case: "bluetooth",

3
src/components/PageComponents/Config/Device.tsx

@ -21,13 +21,14 @@ export const Device = (): JSX.Element => {
}, },
} : undefined; } : undefined;
const isPresetConfig = !("id" in config); const isPresetConfig = !("id" in config);
const { setWorkingConfig } = !isPresetConfig ? useDevice() : { setWorkingConfig: undefined };
const setConfig: (data: DeviceValidation) => void = const setConfig: (data: DeviceValidation) => void =
isPresetConfig ? (data) => { isPresetConfig ? (data) => {
config.config.device = new Protobuf.Config_DeviceConfig(data); config.config.device = new Protobuf.Config_DeviceConfig(data);
(config as ConfigPreset).saveConfigTree(); (config as ConfigPreset).saveConfigTree();
} }
: (data) => { : (data) => {
useDevice().setWorkingConfig!( setWorkingConfig!(
new Protobuf.Config({ new Protobuf.Config({
payloadVariant: { payloadVariant: {
case: "device", case: "device",

3
src/components/PageComponents/Config/Display.tsx

@ -21,13 +21,14 @@ export const Display = (): JSX.Element => {
}, },
} : undefined; } : undefined;
const isPresetConfig = !("id" in config); const isPresetConfig = !("id" in config);
const { setWorkingConfig } = !isPresetConfig ? useDevice() : { setWorkingConfig: undefined };
const setConfig: (data: DisplayValidation) => void = const setConfig: (data: DisplayValidation) => void =
isPresetConfig ? (data) => { isPresetConfig ? (data) => {
config.config.display = new Protobuf.Config_DisplayConfig(data); config.config.display = new Protobuf.Config_DisplayConfig(data);
(config as ConfigPreset).saveConfigTree(); (config as ConfigPreset).saveConfigTree();
} }
: (data) => { : (data) => {
useDevice().setWorkingConfig!( setWorkingConfig!(
new Protobuf.Config({ new Protobuf.Config({
payloadVariant: { payloadVariant: {
case: "display", case: "display",

3
src/components/PageComponents/Config/LoRa.tsx

@ -21,13 +21,14 @@ export const LoRa = (): JSX.Element => {
}, },
} : undefined; } : undefined;
const isPresetConfig = !("id" in config); const isPresetConfig = !("id" in config);
const { setWorkingConfig } = !isPresetConfig ? useDevice() : { setWorkingConfig: undefined };
const setConfig: (data: LoRaValidation) => void = const setConfig: (data: LoRaValidation) => void =
isPresetConfig ? (data) => { isPresetConfig ? (data) => {
config.config.lora = new Protobuf.Config_LoRaConfig(data); config.config.lora = new Protobuf.Config_LoRaConfig(data);
(config as ConfigPreset).saveConfigTree(); (config as ConfigPreset).saveConfigTree();
} }
: (data) => { : (data) => {
useDevice().setWorkingConfig!( setWorkingConfig!(
new Protobuf.Config({ new Protobuf.Config({
payloadVariant: { payloadVariant: {
case: "lora", case: "lora",

3
src/components/PageComponents/Config/Network.tsx

@ -21,13 +21,14 @@ export const Network = (): JSX.Element => {
}, },
} : undefined; } : undefined;
const isPresetConfig = !("id" in config); const isPresetConfig = !("id" in config);
const { setWorkingConfig } = !isPresetConfig ? useDevice() : { setWorkingConfig: undefined };
const setConfig: (data: NetworkValidation) => void = const setConfig: (data: NetworkValidation) => void =
isPresetConfig ? (data) => { isPresetConfig ? (data) => {
config.config.network = new Protobuf.Config_NetworkConfig(data); config.config.network = new Protobuf.Config_NetworkConfig(data);
(config as ConfigPreset).saveConfigTree(); (config as ConfigPreset).saveConfigTree();
} }
: (data) => { : (data) => {
useDevice().setWorkingConfig!( setWorkingConfig!(
new Protobuf.Config({ new Protobuf.Config({
payloadVariant: { payloadVariant: {
case: "network", case: "network",

3
src/components/PageComponents/Config/Position.tsx

@ -21,13 +21,14 @@ export const Position = (): JSX.Element => {
}, },
} : undefined; } : undefined;
const isPresetConfig = !("id" in config); const isPresetConfig = !("id" in config);
const { setWorkingConfig } = !isPresetConfig ? useDevice() : { setWorkingConfig: undefined };
const setConfig: (data: PositionValidation) => void = const setConfig: (data: PositionValidation) => void =
isPresetConfig ? (data) => { isPresetConfig ? (data) => {
config.config.position = new Protobuf.Config_PositionConfig(data); config.config.position = new Protobuf.Config_PositionConfig(data);
(config as ConfigPreset).saveConfigTree(); (config as ConfigPreset).saveConfigTree();
} }
: (data) => { : (data) => {
useDevice().setWorkingConfig!( setWorkingConfig!(
new Protobuf.Config({ new Protobuf.Config({
payloadVariant: { payloadVariant: {
case: "position", case: "position",

3
src/components/PageComponents/Config/Power.tsx

@ -21,13 +21,14 @@ export const Power = (): JSX.Element => {
}, },
} : undefined; } : undefined;
const isPresetConfig = !("id" in config); const isPresetConfig = !("id" in config);
const { setWorkingConfig } = !isPresetConfig ? useDevice() : { setWorkingConfig: undefined };
const setConfig: (data: PowerValidation) => void = const setConfig: (data: PowerValidation) => void =
isPresetConfig ? (data) => { isPresetConfig ? (data) => {
config.config.power = new Protobuf.Config_PowerConfig(data); config.config.power = new Protobuf.Config_PowerConfig(data);
(config as ConfigPreset).saveConfigTree(); (config as ConfigPreset).saveConfigTree();
} }
: (data) => { : (data) => {
useDevice().setWorkingConfig!( setWorkingConfig!(
new Protobuf.Config({ new Protobuf.Config({
payloadVariant: { payloadVariant: {
case: "power", case: "power",

78
src/core/flashing/Flasher.ts

@ -193,7 +193,7 @@ export class FlashOperation {
public async flashAndConfigDevice() { public async flashAndConfigDevice() {
try { try {
await this.flash(); await this.flash();
// await this.setConfig(); await this.setConfig();
this.setState("done"); this.setState("done");
} }
catch(e) { catch(e) {
@ -207,8 +207,8 @@ export class FlashOperation {
const installedVersion = this.device.hardware.firmwareVersion; const installedVersion = this.device.hardware.firmwareVersion;
console.log(`Installed firmware verson: ${installedVersion}`); console.log(`Installed firmware verson: ${installedVersion}`);
const update = !fullFlash && this.device.nodes.get(this.device.hardware.myNodeNum) !== undefined ; const update = !fullFlash && this.device.nodes.get(this.device.hardware.myNodeNum) !== undefined ;
// if(update && installedVersion == firmwareToUse.tag) if(update && installedVersion == firmwareToUse.tag)
// return; return;
const port = await (this.device.connection! as ISerialConnection).disconnect(); const port = await (this.device.connection! as ISerialConnection).disconnect();
if(port === undefined) if(port === undefined)
@ -233,7 +233,7 @@ export class FlashOperation {
await loader.main_fn(); // TODO: This returns some interesting stuff, check it out await loader.main_fn(); // TODO: This returns some interesting stuff, check it out
if(sections.length > 1) { if(sections.length > 1) {
this.setState("erasing"); this.setState("erasing");
await loader.erase_flash(); // await loader.erase_flash();
} }
const totalLength = sections.reduce<number>((p, c) => p + c.data.byteLength, 0); const totalLength = sections.reduce<number>((p, c) => p + c.data.byteLength, 0);
let bytesFlashed = 0; let bytesFlashed = 0;
@ -251,25 +251,24 @@ export class FlashOperation {
return { data: content, address: s.offset }; return { data: content, address: s.offset };
})); }));
await loader.write_flash(files, "keep", undefined, undefined, false, true, (index, written, total) => { // await loader.write_flash(files, "keep", undefined, undefined, false, true, (index, written, total) => {
if(index != lastIndex) { // if(index != lastIndex) {
bytesFlashed += sections[lastIndex].data.byteLength; // bytesFlashed += sections[lastIndex].data.byteLength;
lastIndex = index; // lastIndex = index;
} // }
// I don't know what kind of weird size esploader computes but it doesn't match ours // // I don't know what kind of weird size esploader computes but it doesn't match ours
const bytesThisSegment = (written / total) * sections[index].data.byteLength; // const bytesThisSegment = (written / total) * sections[index].data.byteLength;
console.log(`FLASHING PROGRESS ${bytesFlashed + written} / ${totalLength} ... ${bytesFlashed} | ${written} | ${total} | ${index}`); // console.log(`FLASHING PROGRESS ${bytesFlashed + written} / ${totalLength} ... ${bytesFlashed} | ${written} | ${total} | ${index}`);
this.setState("flashing", (bytesFlashed + bytesThisSegment) / totalLength); // this.setState("flashing", (bytesFlashed + bytesThisSegment) / totalLength);
}); // });
} }
catch (e) { catch (e) {
throw e; throw e;
} }
finally { finally {
await this.loader?.flash_finish();
} }
debugger;
this.setState("config"); this.setState("config");
await port!.setSignals({requestToSend: true}); await port!.setSignals({requestToSend: true});
await new Promise(r => setTimeout(r, 100)); await new Promise(r => setTimeout(r, 100));
@ -281,31 +280,44 @@ export class FlashOperation {
baudRate: undefined, baudRate: undefined,
concurrentLogOutput: true concurrentLogOutput: true
}); });
await new Promise(r => setTimeout(r, 5000));
} }
private async setConfig() { private async setConfig() {
try {
this.setState("config"); this.setState("config");
const connection = (this.device.connection! as ISerialConnection); const connection = (this.device.connection! as ISerialConnection);
// await connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "device", value: this.config.device! } }));
const newConfig = new Protobuf.Config({
payloadVariant: {
case: "device",
value: this.config.device!
}
});
const promise = connection.setConfig(newConfig).then(() =>
connection.commitEditSettings().then(() => console.log("FLASHER: Config saved"))
).catch(e => console.error(e));
// We won't get an answer if serial output has been disabled in the new config await connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "position", value: this.config.position! } }));
if(this.config.device!.serialEnabled) // await connection.commitEditSettings().then(() => console.log("FLASHER: Config saved"));
await promise; await connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "power", value: this.config.power! } }));
await connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "network", value: this.config.network! } }));
await connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "display", value: this.config.display! } }));
await connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "lora", value: this.config.lora! } }));
await connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "bluetooth", value: this.config.bluetooth! } }));
await connection.commitEditSettings().then(() => console.log("FLASHER: Config saved"));
// await Promise.all([
// connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "device", value: this.config.device! } })),
// connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "position", value: this.config.position! } })),
// connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "power", value: this.config.power! } })),
// connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "network", value: this.config.network! } })),
// connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "display", value: this.config.display! } })),
// connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "lora", value: this.config.lora! } })),
// connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "bluetooth", value: this.config.bluetooth! } })),
// connection.setModuleConfig(new Protobuf.ModuleConfig({ payloadVariant: { case: "mqtt", value: this.! } })),
// connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "device", value: this.config.device! } })),
// connection.setConfig(new Protobuf.Config({ payloadVariant: { case: "device", value: this.config.device! } })),
// ]);
}
catch(e) {
this.setState("failed");
}
// We won't get an answer if serial output has been disabled in the new config
// if(this.config.device!.serialEnabled)
// await promise;
} }
public async cancel() { public async cancel() {

38
src/core/stores/appStore.ts

@ -173,12 +173,38 @@ export class ConfigPreset {
serialEnabled: true, serialEnabled: true,
nodeInfoBroadcastSecs: 10800 nodeInfoBroadcastSecs: 10800
}), }),
position: new Protobuf.Config_PositionConfig({ }), position: new Protobuf.Config_PositionConfig({
power: new Protobuf.Config_PowerConfig({ }), positionBroadcastSmartEnabled: true,
network: new Protobuf.Config_NetworkConfig({ }), gpsEnabled: true,
display: new Protobuf.Config_DisplayConfig({ }), rxGpio: 15,
lora: new Protobuf.Config_LoRaConfig({ }), txGpio: 13,
bluetooth: new Protobuf.Config_BluetoothConfig({ }), positionBroadcastSecs: 900,
gpsUpdateInterval: 120,
gpsAttemptTime: 900
}),
power: new Protobuf.Config_PowerConfig({
waitBluetoothSecs: 60,
meshSdsTimeoutSecs: 7200,
sdsSecs: 4294967295,
lsSecs: 300,
minWakeSecs: 10
}),
network: new Protobuf.Config_NetworkConfig({
ntpServer: "0.pool.ntp.org"
}),
display: new Protobuf.Config_DisplayConfig({
screenOnSecs: 600
}),
lora: new Protobuf.Config_LoRaConfig({
hopLimit: 3,
usePreset: true,
txEnabled: true,
txPower: 30
}),
bluetooth: new Protobuf.Config_BluetoothConfig({
enabled: true,
fixedPin: 123456
}),
}); });
} }

Loading…
Cancel
Save