Browse Source

Fixes

pull/110/head
Malte Grimm 3 years ago
parent
commit
66466ac5d5
  1. 3
      src/components/PageComponents/Config/Bluetooth.tsx
  2. 5
      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. 80
      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;
const isPresetConfig = !("id" in config);
const { setWorkingConfig } = !isPresetConfig ? useDevice() : { setWorkingConfig: undefined };
const setConfig: (data: BluetoothValidation) => void =
isPresetConfig ? (data) => {
config.config.bluetooth = new Protobuf.Config_BluetoothConfig(data);
(config as ConfigPreset).saveConfigTree();
}
: (data) => {
useDevice().setWorkingConfig!(
setWorkingConfig!(
new Protobuf.Config({
payloadVariant: {
case: "bluetooth",

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

@ -11,7 +11,7 @@ import {
import { Protobuf } from '@meshtastic/meshtasticjs';
export const Device = (): JSX.Element => {
const config = useConfig();
const config = useConfig();
const enableSwitch: EnableSwitchData | undefined = config.overrideValues ? {
getEnabled(name) {
return config.overrideValues![name] ?? false;
@ -21,13 +21,14 @@ export const Device = (): JSX.Element => {
},
} : undefined;
const isPresetConfig = !("id" in config);
const { setWorkingConfig } = !isPresetConfig ? useDevice() : { setWorkingConfig: undefined };
const setConfig: (data: DeviceValidation) => void =
isPresetConfig ? (data) => {
config.config.device = new Protobuf.Config_DeviceConfig(data);
(config as ConfigPreset).saveConfigTree();
}
: (data) => {
useDevice().setWorkingConfig!(
setWorkingConfig!(
new Protobuf.Config({
payloadVariant: {
case: "device",

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

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

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

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

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

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

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

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

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

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

80
src/core/flashing/Flasher.ts

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

38
src/core/stores/appStore.ts

@ -173,12 +173,38 @@ export class ConfigPreset {
serialEnabled: true,
nodeInfoBroadcastSecs: 10800
}),
position: new Protobuf.Config_PositionConfig({ }),
power: new Protobuf.Config_PowerConfig({ }),
network: new Protobuf.Config_NetworkConfig({ }),
display: new Protobuf.Config_DisplayConfig({ }),
lora: new Protobuf.Config_LoRaConfig({ }),
bluetooth: new Protobuf.Config_BluetoothConfig({ }),
position: new Protobuf.Config_PositionConfig({
positionBroadcastSmartEnabled: true,
gpsEnabled: true,
rxGpio: 15,
txGpio: 13,
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