|
|
@ -33,8 +33,10 @@ export interface Device { |
|
|
channels: Map<Types.ChannelNumber, Protobuf.Channel.Channel>; |
|
|
channels: Map<Types.ChannelNumber, Protobuf.Channel.Channel>; |
|
|
config: Protobuf.LocalOnly.LocalConfig; |
|
|
config: Protobuf.LocalOnly.LocalConfig; |
|
|
moduleConfig: Protobuf.LocalOnly.LocalModuleConfig; |
|
|
moduleConfig: Protobuf.LocalOnly.LocalModuleConfig; |
|
|
|
|
|
cannedMessagesConfig: Protobuf.CannedMessages.CannedMessageModuleConfig; |
|
|
workingConfig: Protobuf.Config.Config[]; |
|
|
workingConfig: Protobuf.Config.Config[]; |
|
|
workingModuleConfig: Protobuf.ModuleConfig.ModuleConfig[]; |
|
|
workingModuleConfig: Protobuf.ModuleConfig.ModuleConfig[]; |
|
|
|
|
|
workingCannedMessagesConfig: Protobuf.CannedMessages.CannedMessageModuleConfig[]; |
|
|
hardware: Protobuf.Mesh.MyNodeInfo; |
|
|
hardware: Protobuf.Mesh.MyNodeInfo; |
|
|
nodes: Map<number, Protobuf.Mesh.NodeInfo>; |
|
|
nodes: Map<number, Protobuf.Mesh.NodeInfo>; |
|
|
metadata: Map<number, Protobuf.Mesh.DeviceMetadata>; |
|
|
metadata: Map<number, Protobuf.Mesh.DeviceMetadata>; |
|
|
@ -69,9 +71,8 @@ export interface Device { |
|
|
setWorkingModuleConfig: (config: Protobuf.ModuleConfig.ModuleConfig) => void; |
|
|
setWorkingModuleConfig: (config: Protobuf.ModuleConfig.ModuleConfig) => void; |
|
|
setHardware: (hardware: Protobuf.Mesh.MyNodeInfo) => void; |
|
|
setHardware: (hardware: Protobuf.Mesh.MyNodeInfo) => void; |
|
|
// setMetrics: (metrics: Types.PacketMetadata<Protobuf.Telemetry>) => void;
|
|
|
// setMetrics: (metrics: Types.PacketMetadata<Protobuf.Telemetry>) => void;
|
|
|
setCannedMessages: ( |
|
|
setCannedMessages: (config: Protobuf.CannedMessages.CannedMessageModuleConfig) => void; |
|
|
message: Protobuf.CannedMessages.CannedMessageModuleConfig, |
|
|
setWorkingCannedMessages: (config: Protobuf.CannedMessages.CannedMessageModuleConfig) => void; |
|
|
) => void; |
|
|
|
|
|
setActivePage: (page: Page) => void; |
|
|
setActivePage: (page: Page) => void; |
|
|
setActiveNode: (node: number) => void; |
|
|
setActiveNode: (node: number) => void; |
|
|
setPendingSettingsChanges: (state: boolean) => void; |
|
|
setPendingSettingsChanges: (state: boolean) => void; |
|
|
@ -123,8 +124,10 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
channels: new Map(), |
|
|
channels: new Map(), |
|
|
config: new Protobuf.LocalOnly.LocalConfig(), |
|
|
config: new Protobuf.LocalOnly.LocalConfig(), |
|
|
moduleConfig: new Protobuf.LocalOnly.LocalModuleConfig(), |
|
|
moduleConfig: new Protobuf.LocalOnly.LocalModuleConfig(), |
|
|
|
|
|
cannedMessagesConfig: new Protobuf.CannedMessages.CannedMessageModuleConfig(), |
|
|
workingConfig: [], |
|
|
workingConfig: [], |
|
|
workingModuleConfig: [], |
|
|
workingModuleConfig: [], |
|
|
|
|
|
workingCannedMessagesConfig: [], |
|
|
hardware: new Protobuf.Mesh.MyNodeInfo(), |
|
|
hardware: new Protobuf.Mesh.MyNodeInfo(), |
|
|
nodes: new Map(), |
|
|
nodes: new Map(), |
|
|
metadata: new Map(), |
|
|
metadata: new Map(), |
|
|
@ -156,7 +159,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
if (device) { |
|
|
if (device) { |
|
|
device.status = status; |
|
|
device.status = status; |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
setConfig: (config: Protobuf.Config.Config) => { |
|
|
setConfig: (config: Protobuf.Config.Config) => { |
|
|
@ -199,7 +202,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
setModuleConfig: (config: Protobuf.ModuleConfig.ModuleConfig) => { |
|
|
setModuleConfig: (config: Protobuf.ModuleConfig.ModuleConfig) => { |
|
|
@ -268,7 +271,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
setWorkingConfig: (config: Protobuf.Config.Config) => { |
|
|
setWorkingConfig: (config: Protobuf.Config.Config) => { |
|
|
@ -279,18 +282,18 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
const workingConfigIndex = device?.workingConfig.findIndex( |
|
|
const workingConfigIndex = device?.workingConfig.findIndex( |
|
|
(wc) => wc.payloadVariant.case === config.payloadVariant.case, |
|
|
(wc) => wc.payloadVariant.case === config.payloadVariant.case |
|
|
); |
|
|
); |
|
|
if (workingConfigIndex !== -1) { |
|
|
if (workingConfigIndex !== -1) { |
|
|
device.workingConfig[workingConfigIndex] = config; |
|
|
device.workingConfig[workingConfigIndex] = config; |
|
|
} else { |
|
|
} else { |
|
|
device?.workingConfig.push(config); |
|
|
device?.workingConfig.push(config); |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
setWorkingModuleConfig: ( |
|
|
setWorkingModuleConfig: ( |
|
|
moduleConfig: Protobuf.ModuleConfig.ModuleConfig, |
|
|
moduleConfig: Protobuf.ModuleConfig.ModuleConfig |
|
|
) => { |
|
|
) => { |
|
|
set( |
|
|
set( |
|
|
produce<DeviceState>((draft) => { |
|
|
produce<DeviceState>((draft) => { |
|
|
@ -298,19 +301,35 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
if (!device) { |
|
|
if (!device) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
const workingModuleConfigIndex = |
|
|
const workingModuleConfigIndex = device?.workingModuleConfig.findIndex( |
|
|
device?.workingModuleConfig.findIndex( |
|
|
(wmc) => wmc.payloadVariant.case === |
|
|
(wmc) => |
|
|
moduleConfig.payloadVariant.case |
|
|
wmc.payloadVariant.case === |
|
|
); |
|
|
moduleConfig.payloadVariant.case, |
|
|
|
|
|
); |
|
|
|
|
|
if (workingModuleConfigIndex !== -1) { |
|
|
if (workingModuleConfigIndex !== -1) { |
|
|
device.workingModuleConfig[workingModuleConfigIndex] = |
|
|
device.workingModuleConfig[workingModuleConfigIndex] = |
|
|
moduleConfig; |
|
|
moduleConfig; |
|
|
} else { |
|
|
} else { |
|
|
device?.workingModuleConfig.push(moduleConfig); |
|
|
device?.workingModuleConfig.push(moduleConfig); |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
|
|
|
); |
|
|
|
|
|
}, |
|
|
|
|
|
setWorkingCannedMessages: ( |
|
|
|
|
|
cannedConfig: Protobuf.CannedMessages.CannedMessageModuleConfig |
|
|
|
|
|
) => { |
|
|
|
|
|
set( |
|
|
|
|
|
produce<DeviceState>((draft) => { |
|
|
|
|
|
const device = draft.devices.get(id); |
|
|
|
|
|
if (!device) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
if (device?.workingCannedMessagesConfig) { |
|
|
|
|
|
device?.workingCannedMessagesConfig.pop(); |
|
|
|
|
|
device?.workingCannedMessagesConfig.push(cannedConfig); |
|
|
|
|
|
} else { |
|
|
|
|
|
device?.workingCannedMessagesConfig.push(cannedConfig); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
setHardware: (hardware: Protobuf.Mesh.MyNodeInfo) => { |
|
|
setHardware: (hardware: Protobuf.Mesh.MyNodeInfo) => { |
|
|
@ -320,7 +339,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
if (device) { |
|
|
if (device) { |
|
|
device.hardware = hardware; |
|
|
device.hardware = hardware; |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
// setMetrics: (metrics: Types.PacketMetadata<Protobuf.Telemetry>) => {
|
|
|
// setMetrics: (metrics: Types.PacketMetadata<Protobuf.Telemetry>) => {
|
|
|
@ -374,7 +393,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
if (device) { |
|
|
if (device) { |
|
|
device.setCannedMessages(messages); |
|
|
device.setCannedMessages(messages); |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
setActivePage: (page) => { |
|
|
setActivePage: (page) => { |
|
|
@ -384,7 +403,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
if (device) { |
|
|
if (device) { |
|
|
device.activePage = page; |
|
|
device.activePage = page; |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
setPendingSettingsChanges: (state) => { |
|
|
setPendingSettingsChanges: (state) => { |
|
|
@ -394,7 +413,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
if (device) { |
|
|
if (device) { |
|
|
device.pendingSettingsChanges = state; |
|
|
device.pendingSettingsChanges = state; |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
addChannel: (channel: Protobuf.Channel.Channel) => { |
|
|
addChannel: (channel: Protobuf.Channel.Channel) => { |
|
|
@ -405,7 +424,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
device.channels.set(channel.index, channel); |
|
|
device.channels.set(channel.index, channel); |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
addWaypoint: (waypoint: Protobuf.Mesh.Waypoint) => { |
|
|
addWaypoint: (waypoint: Protobuf.Mesh.Waypoint) => { |
|
|
@ -414,7 +433,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
const device = draft.devices.get(id); |
|
|
const device = draft.devices.get(id); |
|
|
if (device) { |
|
|
if (device) { |
|
|
const waypointIndex = device.waypoints.findIndex( |
|
|
const waypointIndex = device.waypoints.findIndex( |
|
|
(wp) => wp.id === waypoint.id, |
|
|
(wp) => wp.id === waypoint.id |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if (waypointIndex !== -1) { |
|
|
if (waypointIndex !== -1) { |
|
|
@ -423,7 +442,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
device.waypoints.push(waypoint); |
|
|
device.waypoints.push(waypoint); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
addNodeInfo: (nodeInfo) => { |
|
|
addNodeInfo: (nodeInfo) => { |
|
|
@ -434,7 +453,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
device.nodes.set(nodeInfo.num, nodeInfo); |
|
|
device.nodes.set(nodeInfo.num, nodeInfo); |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
setActiveNode: (node) => { |
|
|
setActiveNode: (node) => { |
|
|
@ -444,7 +463,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
if (device) { |
|
|
if (device) { |
|
|
device.activeNode = node; |
|
|
device.activeNode = node; |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
addUser: (user) => { |
|
|
addUser: (user) => { |
|
|
@ -454,11 +473,10 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
if (!device) { |
|
|
if (!device) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
const currentNode = |
|
|
const currentNode = device.nodes.get(user.from) ?? new Protobuf.Mesh.NodeInfo(); |
|
|
device.nodes.get(user.from) ?? new Protobuf.Mesh.NodeInfo(); |
|
|
|
|
|
currentNode.user = user.data; |
|
|
currentNode.user = user.data; |
|
|
device.nodes.set(user.from, currentNode); |
|
|
device.nodes.set(user.from, currentNode); |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
addPosition: (position) => { |
|
|
addPosition: (position) => { |
|
|
@ -468,12 +486,11 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
if (!device) { |
|
|
if (!device) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
const currentNode = |
|
|
const currentNode = device.nodes.get(position.from) ?? |
|
|
device.nodes.get(position.from) ?? |
|
|
|
|
|
new Protobuf.Mesh.NodeInfo(); |
|
|
new Protobuf.Mesh.NodeInfo(); |
|
|
currentNode.position = position.data; |
|
|
currentNode.position = position.data; |
|
|
device.nodes.set(position.from, currentNode); |
|
|
device.nodes.set(position.from, currentNode); |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
addConnection: (connection) => { |
|
|
addConnection: (connection) => { |
|
|
@ -483,7 +500,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
if (device) { |
|
|
if (device) { |
|
|
device.connection = connection; |
|
|
device.connection = connection; |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
addMessage: (message) => { |
|
|
addMessage: (message) => { |
|
|
@ -494,12 +511,11 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
const messageGroup = device.messages[message.type]; |
|
|
const messageGroup = device.messages[message.type]; |
|
|
const messageIndex = |
|
|
const messageIndex = message.type === "direct" |
|
|
message.type === "direct" |
|
|
? message.from === device.hardware.myNodeNum |
|
|
? message.from === device.hardware.myNodeNum |
|
|
? message.to |
|
|
? message.to |
|
|
: message.from |
|
|
: message.from |
|
|
: message.channel; |
|
|
: message.channel; |
|
|
|
|
|
const messages = messageGroup.get(messageIndex); |
|
|
const messages = messageGroup.get(messageIndex); |
|
|
|
|
|
|
|
|
if (messages) { |
|
|
if (messages) { |
|
|
@ -508,7 +524,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
} else { |
|
|
} else { |
|
|
messageGroup.set(messageIndex, [message]); |
|
|
messageGroup.set(messageIndex, [message]); |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
@ -520,7 +536,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
device.metadata.set(from, metadata); |
|
|
device.metadata.set(from, metadata); |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
addTraceRoute: (traceroute) => { |
|
|
addTraceRoute: (traceroute) => { |
|
|
@ -540,7 +556,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
} else { |
|
|
} else { |
|
|
device.traceroutes.set(traceroute.from, [traceroute]); |
|
|
device.traceroutes.set(traceroute.from, [traceroute]); |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
removeNode: (nodeNum) => { |
|
|
removeNode: (nodeNum) => { |
|
|
@ -551,7 +567,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
device.nodes.delete(nodeNum); |
|
|
device.nodes.delete(nodeNum); |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
setMessageState: ( |
|
|
setMessageState: ( |
|
|
@ -560,7 +576,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
to: number, |
|
|
to: number, |
|
|
from: number, |
|
|
from: number, |
|
|
messageId: number, |
|
|
messageId: number, |
|
|
state: MessageState, |
|
|
state: MessageState |
|
|
) => { |
|
|
) => { |
|
|
set( |
|
|
set( |
|
|
produce<DeviceState>((draft) => { |
|
|
produce<DeviceState>((draft) => { |
|
|
@ -572,12 +588,11 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
} |
|
|
} |
|
|
const messageGroup = device.messages[type]; |
|
|
const messageGroup = device.messages[type]; |
|
|
|
|
|
|
|
|
const messageIndex = |
|
|
const messageIndex = type === "direct" |
|
|
type === "direct" |
|
|
? from === device.hardware.myNodeNum |
|
|
? from === device.hardware.myNodeNum |
|
|
? to |
|
|
? to |
|
|
: from |
|
|
: from |
|
|
: channelIndex; |
|
|
: channelIndex; |
|
|
|
|
|
const messages = messageGroup.get(messageIndex); |
|
|
const messages = messageGroup.get(messageIndex); |
|
|
|
|
|
|
|
|
if (!messages) { |
|
|
if (!messages) { |
|
|
@ -592,9 +607,9 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
msg.state = state; |
|
|
msg.state = state; |
|
|
} |
|
|
} |
|
|
return msg; |
|
|
return msg; |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
setDialogOpen: (dialog: DialogVariant, open: boolean) => { |
|
|
setDialogOpen: (dialog: DialogVariant, open: boolean) => { |
|
|
@ -605,7 +620,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
device.dialog[dialog] = open; |
|
|
device.dialog[dialog] = open; |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
processPacket(data: ProcessPacketParams) { |
|
|
processPacket(data: ProcessPacketParams) { |
|
|
@ -629,10 +644,10 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
num: data.from, |
|
|
num: data.from, |
|
|
lastHeard: data.time, |
|
|
lastHeard: data.time, |
|
|
snr: data.snr, |
|
|
snr: data.snr, |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
setMessageDraft: (message: string) => { |
|
|
setMessageDraft: (message: string) => { |
|
|
@ -642,7 +657,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({ |
|
|
if (device) { |
|
|
if (device) { |
|
|
device.messageDraft = message; |
|
|
device.messageDraft = message; |
|
|
} |
|
|
} |
|
|
}), |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|
|