Browse Source

wip

pull/536/head
Dan Ditomaso 1 year ago
parent
commit
8fffde0165
  1. 5
      deno.json
  2. 892
      deno.lock
  3. 5
      package.json
  4. 9
      src/components/Form/FormSelect.tsx
  5. 23
      src/components/PageComponents/Config/Network.tsx
  6. 10
      src/core/utils/ip.ts
  7. 5
      src/validation/config/network.ts

5
deno.json

@ -1,5 +1,10 @@
{
"imports": {
"@meshtastic/core": "jsr:@meshtastic/core@^2.6.2",
"@meshtastic/js": "jsr:@meshtastic/js@^2.3.4",
"@meshtastic/transport-http": "jsr:@meshtastic/transport-http@^0.2.1",
"@meshtastic/transport-web-bluetooth": "jsr:@meshtastic/transport-web-bluetooth@^0.1.1",
"@meshtastic/transport-web-serial": "jsr:@meshtastic/transport-web-serial@^0.2.1",
"@app/": "./src/",
"@pages/": "./src/pages/",
"@components/": "./src/components/",

892
deno.lock

File diff suppressed because it is too large

5
package.json

@ -35,10 +35,6 @@
"homepage": "https://meshtastic.org",
"dependencies": {
"@bufbuild/protobuf": "^2.2.3",
"@meshtastic/core": "npm:@jsr/[email protected]",
"@meshtastic/js": "npm:@jsr/[email protected]",
"@meshtastic/transport-http": "npm:@jsr/meshtastic__transport-http",
"@meshtastic/transport-web-serial": "npm:@jsr/meshtastic__transport-web-serial",
"@noble/curves": "^1.8.1",
"@radix-ui/react-accordion": "^1.2.3",
"@radix-ui/react-checkbox": "^1.1.4",
@ -74,6 +70,7 @@
"react-qrcode-logo": "^3.0.0",
"rfc4648": "^1.5.4",
"vite-plugin-node-polyfills": "^0.23.0",
"zod": "^3.24.2",
"zustand": "5.0.3"
},
"devDependencies": {

9
src/components/Form/FormSelect.tsx

@ -10,13 +10,14 @@ import {
SelectValue,
} from "@components/UI/Select.tsx";
import { useController, type FieldValues } from "react-hook-form";
import { computeHeadingLevel } from "@core/utils/test.tsx";
export interface SelectFieldProps<T> extends BaseFormBuilderProps<T> {
type: "select";
selectChange?: (e: string, name: string) => void;
validate?: (newValue: string) => Promise<boolean>;
defaultValue?: string;
properties: BaseFormBuilderProps<T>["properties"] & {
defaultValue?: T;
enumValue: {
[s: string]: string | number;
};
@ -38,11 +39,15 @@ export function SelectInput<T extends FieldValues>({
disabled,
field,
}: GenericFormElementProps<T, SelectFieldProps<T>>) {
// Get default value and set it
const defaultValue = field.properties.defaultValue ?? field.defaultValue;
const {
field: { value, onChange, ...rest },
} = useController({
name: field.name,
control,
defaultValue: defaultValue ? defaultValue.toString() : undefined,
});
const { enumValue, formatEnumName, ...remainingProperties } = field.properties;
@ -70,12 +75,12 @@ export function SelectInput<T extends FieldValues>({
onChange(Number.parseInt(newValue));
};
return (
<Select
onValueChange={handleValueChange}
disabled={disabled}
value={value?.toString()}
defaultValue={defaultValue?.toString()}
{...remainingProperties}
{...rest}
>

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

@ -1,4 +1,4 @@
import type { NetworkValidation } from "@app/validation/config/network.tsx";
import type { NetworkValidation } from "@app/validation/config/network.ts";
import { create } from "@bufbuild/protobuf";
import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.ts";
@ -12,6 +12,9 @@ export const Network = () => {
const { config, setWorkingConfig } = useDevice();
const onSubmit = (data: NetworkValidation) => {
console.log("Network data", data);
setWorkingConfig(
create(Protobuf.Config.ConfigSchema, {
payloadVariant: {
@ -21,7 +24,7 @@ export const Network = () => {
ipv4Config: create(
Protobuf.Config.Config_NetworkConfig_IpV4ConfigSchema,
{
ip: convertIpAddressToInt(data.ipv4Config.ip) ?? 0,
ip: convertIpAddressToInt(data?.ipv4Config?.ip) ?? 0,
gateway: convertIpAddressToInt(data.ipv4Config.gateway) ?? 0,
subnet: convertIpAddressToInt(data.ipv4Config.subnet) ?? 0,
dns: convertIpAddressToInt(data.ipv4Config.dns) ?? 0,
@ -165,6 +168,22 @@ export const Network = () => {
},
],
},
{
label: "UDP Config",
description: "UDP over Mesh configuration",
fields: [
{
type: "select",
name: "enabledProtocols",
label: "Mesh via UDP enabled",
properties: {
enumValue:
Protobuf.Config.Config_NetworkConfig_ProtocolFlags,
formatEnumName: true,
}
},
],
},
{
label: "NTP Config",
description: "NTP configuration",

10
src/core/utils/ip.ts

@ -1,10 +1,12 @@
export function convertIntToIpAddress(int: number): string {
return `${int & 0xff}.${(int >> 8) & 0xff}.${(int >> 16) & 0xff}.${
(int >> 24) & 0xff
}`;
return `${int & 0xff}.${(int >> 8) & 0xff}.${(int >> 16) & 0xff}.${(int >> 24) & 0xff
}`;
}
export function convertIpAddressToInt(ip: string): number | null {
export function convertIpAddressToInt(ip: string): number | undefined {
if (!ip) {
return undefined;
}
return (
ip
.split(".")

5
src/validation/config/network.ts

@ -11,7 +11,7 @@ import {
export class NetworkValidation
implements
Omit<Protobuf.Config.Config_NetworkConfig, keyof Message | "ipv4Config"> {
Omit<Protobuf.Config.Config_NetworkConfig, keyof Message | "ipv4Config"> {
@IsBoolean()
wifiEnabled: boolean;
@ -34,6 +34,9 @@ export class NetworkValidation
ipv4Config: NetworkValidationIpV4Config;
@IsEnum(Protobuf.Config.Config_NetworkConfig_EnabledProtocols)
enabledProtocols: Protobuf.Config.Config_NetworkConfig_ProtocolFlags;
@IsString()
rsyslogServer: string;
}

Loading…
Cancel
Save