implemented the epansion line stuff

made adjustments to to the grain cable by adding i2c as an option as long as you set and expander line,
also ajusted DeviceAvailability so that an i2c address will not be claimed if the component has an expansion line set, updated the device wizard to removed pin options if the i2c port was selected and vice versa for pins since we now have a components that supports both types, updated the components setting to set the default address type based on the restriction passed in that is set by the wizard, and fall back to what is was before if one is not passed in
This commit is contained in:
csawatzky 2025-07-11 13:56:17 -06:00
parent 54a826bc2d
commit 3325c9d75b
11 changed files with 113 additions and 36 deletions

4
package-lock.json generated
View file

@ -42,7 +42,7 @@
"mui-tel-input": "^7.0.0", "mui-tel-input": "^7.0.0",
"notistack": "^3.0.1", "notistack": "^3.0.1",
"openweathermap-ts": "^1.2.10", "openweathermap-ts": "^1.2.10",
"protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#staging", "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#cable_expander",
"query-string": "^9.2.1", "query-string": "^9.2.1",
"react": "^18.3.1", "react": "^18.3.1",
"react-beautiful-dnd": "^13.1.1", "react-beautiful-dnd": "^13.1.1",
@ -10889,7 +10889,7 @@
}, },
"node_modules/protobuf-ts": { "node_modules/protobuf-ts": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#4523ffef42032eb4a923bd50d4cfcccbb1397dbd", "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#eff6e4e51be080fdee9503d74ee66a0504436545",
"dependencies": { "dependencies": {
"protobufjs": "^6.8.8" "protobufjs": "^6.8.8"
} }

View file

@ -54,7 +54,7 @@
"mui-tel-input": "^7.0.0", "mui-tel-input": "^7.0.0",
"notistack": "^3.0.1", "notistack": "^3.0.1",
"openweathermap-ts": "^1.2.10", "openweathermap-ts": "^1.2.10",
"protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#staging", "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#cable_expander",
"query-string": "^9.2.1", "query-string": "^9.2.1",
"react": "^18.3.1", "react": "^18.3.1",
"react-beautiful-dnd": "^13.1.1", "react-beautiful-dnd": "^13.1.1",

View file

@ -169,6 +169,7 @@ export default function ComponentSettings(props: Props) {
const [removeDialogOpen, setRemoveDialogOpen] = useState(false); const [removeDialogOpen, setRemoveDialogOpen] = useState(false);
const [formComponent, setFormComponent] = useState<Component>(new Component()); const [formComponent, setFormComponent] = useState<Component>(new Component());
const [cableID, setCableID] = useState(0); const [cableID, setCableID] = useState(0);
const [expansionLine, setExpansionLine] = useState(0);
const [overlayIndex, setOverlayIndex] = useState(0); const [overlayIndex, setOverlayIndex] = useState(0);
const [overlayColourDialog, setOverlayCoulourDialog] = useState(false); const [overlayColourDialog, setOverlayCoulourDialog] = useState(false);
const [tabVal, setTabVal] = useState(0); const [tabVal, setTabVal] = useState(0);
@ -222,6 +223,9 @@ export default function ComponentSettings(props: Props) {
const isFormValid = () => { const isFormValid = () => {
//let { component } = form; //let { component } = form;
let type = or(formComponent.settings.type, ""); let type = or(formComponent.settings.type, "");
if(supportsExpansion() && expansionLine === 0){
return false
}
return isComponentTypeValid(type) && isAddressValid(formComponent); return isComponentTypeValid(type) && isAddressValid(formComponent);
}; };
@ -238,7 +242,6 @@ export default function ComponentSettings(props: Props) {
componentType: quack.ComponentType componentType: quack.ComponentType
): number[] => { ): number[] => {
let positions = availablePositions.get(addressType); let positions = availablePositions.get(addressType);
console.log(positions)
if (!positions) return []; if (!positions) return [];
switch (addressType) { switch (addressType) {
case quack.AddressType.ADDRESS_TYPE_I2C: case quack.AddressType.ADDRESS_TYPE_I2C:
@ -306,6 +309,7 @@ export default function ComponentSettings(props: Props) {
const component = formComponent; const component = formComponent;
//component.settings.calibrationCoefficient = Number(form.coefficient); //component.settings.calibrationCoefficient = Number(form.coefficient);
if (cableID > 0) component.settings.addressType = cableID + 8; if (cableID > 0) component.settings.addressType = cableID + 8;
component.settings.expansionLine = expansionLine
componentAPI componentAPI
.add(device.id(), component.settings, as) .add(device.id(), component.settings, as)
.then((_response: any) => { .then((_response: any) => {
@ -372,10 +376,10 @@ export default function ComponentSettings(props: Props) {
let ext = extension(type, subtype); let ext = extension(type, subtype);
formComponent.settings.type = type; formComponent.settings.type = type;
formComponent.settings.subtype = subtype; formComponent.settings.subtype = subtype;
formComponent.settings.addressType = getAddressTypes( formComponent.settings.addressType = or(addressTypeRestriction, getAddressTypes(
formComponent.settings.type, formComponent.settings.type,
formComponent.settings.subtype formComponent.settings.subtype
)[0]; )[0]);
formComponent.settings.address = or( formComponent.settings.address = or(
getAvailablePositions(formComponent.settings.addressType, formComponent.settings.type)[0], getAvailablePositions(formComponent.settings.addressType, formComponent.settings.type)[0],
Component.create().settings.address Component.create().settings.address
@ -398,11 +402,19 @@ export default function ComponentSettings(props: Props) {
}; };
const handlePositionChanged = (event: any) => { const handlePositionChanged = (event: any) => {
setCableID(0)
setExpansionLine(0)
let f = cloneDeep(formComponent); let f = cloneDeep(formComponent);
f.settings.address = event.target.value //split the string
.toString() let split: string[] = event.target.value.toString().split(":")
.split(":") // pop the addres off of the end of the array
.pop(); f.settings.address = parseInt(split.pop() ?? "0")
// pop the address type out of the array next
f.settings.addressType = parseInt(split.pop() ?? "0")
// f.settings.address = event.target.value
// .toString()
// .split(":")
// .pop();
setFormComponent(f); setFormComponent(f);
}; };
@ -413,7 +425,6 @@ export default function ComponentSettings(props: Props) {
for (let i = 0; i < addressTypes.length; i++) { for (let i = 0; i < addressTypes.length; i++) {
let addressType = addressTypes[i]; let addressType = addressTypes[i];
let availablePositions = getAvailablePositions(addressType, type); let availablePositions = getAvailablePositions(addressType, type);
console.log(availablePositions)
availableMenuItemPositions.push( availableMenuItemPositions.push(
<MenuItem key={addressType} divider disabled> <MenuItem key={addressType} divider disabled>
@ -490,6 +501,21 @@ export default function ComponentSettings(props: Props) {
); );
}; };
const isCableComponent = () => {
return (formComponent.settings.type === quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE ||
formComponent.settings.type ===
quack.ComponentType.COMPONENT_TYPE_DRAGER_GAS_DONGLE ||
formComponent.settings.type === quack.ComponentType.COMPONENT_TYPE_PRESSURE_CABLE ||
(formComponent.settings.type === quack.ComponentType.COMPONENT_TYPE_CAPACITOR_CABLE &&
formComponent.subType() ===
quack.CapacitorCableSubtype.CAPACITOR_CABLE_SUBTYPE_FROG))
}
const supportsExpansion = () => {
return (formComponent.settings.type === quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE &&
formComponent.settings.addressType === quack.AddressType.ADDRESS_TYPE_I2C)
}
const addForm = () => { const addForm = () => {
return ( return (
<DialogContent> <DialogContent>
@ -543,14 +569,8 @@ export default function ComponentSettings(props: Props) {
formComponent.settings.subtype formComponent.settings.subtype
)} )}
</TextField> </TextField>
{(formComponent.settings.type === quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE || {supportsExpansion() && setExpLine()}
formComponent.settings.type === {(isCableComponent() && !supportsExpansion())&& setComponentAddrType()}
quack.ComponentType.COMPONENT_TYPE_DRAGER_GAS_DONGLE ||
formComponent.settings.type === quack.ComponentType.COMPONENT_TYPE_PRESSURE_CABLE ||
(formComponent.settings.type === quack.ComponentType.COMPONENT_TYPE_CAPACITOR_CABLE &&
formComponent.subType() ===
quack.CapacitorCableSubtype.CAPACITOR_CABLE_SUBTYPE_FROG)) &&
setComponentAddrType()}
</React.Fragment> </React.Fragment>
) : activeStep === 1 ? ( ) : activeStep === 1 ? (
<ComponentForm <ComponentForm
@ -582,6 +602,28 @@ export default function ComponentSettings(props: Props) {
</DialogContent> </DialogContent>
); );
}; };
const setExpLine = () => {
return (
<TextField
label="Expansion Line"
type="number"
margin="normal"
error={expansionLine < 1 || expansionLine > 12}
fullWidth
variant="outlined"
value={expansionLine}
helperText="Enter line the cable is connected to on your expander"
onChange={e => {
let number = parseInt(e.target.value);
if (number < 0 || isNaN(number)) number = 0;
if (number > 12) number = 12;
setExpansionLine(number);
}}
/>
);
};
const setComponentAddrType = () => { const setComponentAddrType = () => {
return ( return (
<TextField <TextField

View file

@ -198,16 +198,23 @@ export default function DeviceWizard(props: Props) {
/** /**
* function that restricts the pin availabilty in the availability map to the pin of the port that was selected * function that restricts the pin availabilty in the availability map to the pin of the port that was selected
* does nothing for I2C ports as the restrictions for that are handled by the component type
* @param port port that was selected * @param port port that was selected
* @param availability availability map of the device * @param availability availability map of the device
* @returns modified availability map * @returns modified availability map
*/ */
const adjustAvailablePositions = (port: PortInformation, availability: DeviceAvailabilityMap) => { const adjustAvailablePositions = (port: PortInformation, availability: DeviceAvailabilityMap) => {
let currentAvailability = availability; let currentAvailability = availability;
console.log(port)
switch (port.addressType) { switch (port.addressType) {
case quack.AddressType.ADDRESS_TYPE_CONFIGURABLE_PIN_ARRAY: case quack.AddressType.ADDRESS_TYPE_CONFIGURABLE_PIN_ARRAY:
currentAvailability.set(port.addressType, [{ address: port.address, label: port.label }]); currentAvailability.set(port.addressType, [{ address: port.address, label: port.label }]);
//since we now have a component type that can be pins or i2c need to remove i2c options if they selected a pin port
currentAvailability.set(quack.AddressType.ADDRESS_TYPE_I2C, new Map());
break;
case quack.AddressType.ADDRESS_TYPE_I2C:
//since we now have a component type that can be pins or i2c need to remove pin options if they selected the i2c port
currentAvailability.set(quack.AddressType.ADDRESS_TYPE_CONFIGURABLE_PIN_ARRAY, []);
break;
} }
return currentAvailability; return currentAvailability;
}; };

View file

@ -67,18 +67,25 @@ export class Component {
return quack.ComponentID.fromObject({ return quack.ComponentID.fromObject({
type: this.settings.type, type: this.settings.type,
addressType: this.settings.addressType, addressType: this.settings.addressType,
address: this.settings.address address: this.settings.address,
expansionLine: this.settings.expansionLine,
muxLine: this.settings.muxLine
}); });
} }
public locationString(): string { public locationString(): string {
return ( let compositeLocation = or(this.settings.type, 0).toString() +
or(this.settings.type, 0).toString() +
"-" + "-" +
or(this.settings.addressType, 0).toString() + or(this.settings.addressType, 0).toString() +
"-" + "-" +
or(this.settings.address, 0).toString() or(this.settings.address, 0).toString()
); if(this.settings.expansionLine){
compositeLocation = compositeLocation + "-" + this.settings.expansionLine
}
if(this.settings.muxLine){
compositeLocation = compositeLocation + ":" + this.settings.muxLine
}
return compositeLocation;
} }
public type(): quack.ComponentType { public type(): quack.ComponentType {

View file

@ -16,7 +16,8 @@ export const I2C: AddressTypeExtension = {
[quack.ComponentType.COMPONENT_TYPE_CAPACITANCE, 0x4f], [quack.ComponentType.COMPONENT_TYPE_CAPACITANCE, 0x4f],
[quack.ComponentType.COMPONENT_TYPE_CAPACITOR_CABLE, 0x4f], [quack.ComponentType.COMPONENT_TYPE_CAPACITOR_CABLE, 0x4f],
[quack.ComponentType.COMPONENT_TYPE_SEN5X, 0x68], [quack.ComponentType.COMPONENT_TYPE_SEN5X, 0x68],
[quack.ComponentType.COMPONENT_TYPE_AIRFLOW, 0x29] [quack.ComponentType.COMPONENT_TYPE_AIRFLOW, 0x29],
[quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE, 0x70]
]); ]);
const offset = offsets.get(componentType); const offset = offsets.get(componentType);

View file

@ -16,6 +16,7 @@ export const GetBinShapeDescribers = (): BinShapeDescriber[] => {
]; ];
}; };
// DEPRECATED -- the bon now knows its components from the relative object table
export const HasGrainCable = (bin?: pond.BinSettings): boolean => { export const HasGrainCable = (bin?: pond.BinSettings): boolean => {
if (bin && bin.deviceComponents) { if (bin && bin.deviceComponents) {
bin.deviceComponents.forEach(dc => { bin.deviceComponents.forEach(dc => {

View file

@ -23,7 +23,9 @@ export function getComponentIDString(component?: Component): string {
? componentIDToString({ ? componentIDToString({
type: component.settings.type, type: component.settings.type,
addressType: component.settings.addressType, addressType: component.settings.addressType,
address: component.settings.address address: component.settings.address,
expansionLine: component.settings.expansionLine,
muxLine: component.settings.muxLine
}) })
: "0-0-0"; : "0-0-0";
} }
@ -40,13 +42,18 @@ export function componentIDToString(componentID?: quack.IComponentID | null): st
if (!componentID) { if (!componentID) {
return "0-0-0"; return "0-0-0";
} }
return ( let compositeLocation = or(componentID.type, 0).toString() +
or(componentID.type, 0).toString() +
"-" + "-" +
or(componentID.addressType, 0).toString() + or(componentID.addressType, 0).toString() +
"-" + "-" +
or(componentID.address, 0).toString() or(componentID.address, 0).toString()
); if(componentID.expansionLine){
compositeLocation = compositeLocation + "-" + componentID.expansionLine
}
if(componentID.muxLine){
compositeLocation = compositeLocation + ":" + componentID.muxLine
}
return compositeLocation;
} }
export function stringToComponentId(componentIDString: string): quack.ComponentID { export function stringToComponentId(componentIDString: string): quack.ComponentID {

View file

@ -176,7 +176,7 @@ export function GrainCable(subtype: number = 0): ComponentTypeExtension {
isSource: true, isSource: true,
isArray: true, isArray: true,
isCalibratable: false, isCalibratable: false,
addressTypes: [quack.AddressType.ADDRESS_TYPE_CONFIGURABLE_PIN_ARRAY], addressTypes: [quack.AddressType.ADDRESS_TYPE_CONFIGURABLE_PIN_ARRAY, quack.AddressType.ADDRESS_TYPE_I2C],
interactionResultTypes: [], interactionResultTypes: [],
states: [], states: [],
measurements: [ measurements: [

View file

@ -11,6 +11,11 @@ export type DevicePositions = number[] | ComponentAvailabilityMap | Configurable
export type DeviceAvailabilityMap = Map<quack.AddressType, DevicePositions>; export type DeviceAvailabilityMap = Map<quack.AddressType, DevicePositions>;
export type OffsetAvailabilityMap = Map<quack.AddressType, number[][]>; export type OffsetAvailabilityMap = Map<quack.AddressType, number[][]>;
//component types that can be connected to an expander in the I2C port
const ExpansionComponentTypes: quack.ComponentType[] = [
quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE
]
const DefaultPinArray: ConfigurablePin[] = [ const DefaultPinArray: ConfigurablePin[] = [
{ address: 1, label: "1" }, { address: 1, label: "1" },
{ address: 2, label: "2" }, { address: 2, label: "2" },
@ -60,7 +65,8 @@ const DefaultAvailability: DeviceAvailabilityMap = new Map<quack.AddressType, De
[quack.ComponentType.COMPONENT_TYPE_CAPACITANCE, [0x50]], [quack.ComponentType.COMPONENT_TYPE_CAPACITANCE, [0x50]],
[quack.ComponentType.COMPONENT_TYPE_CAPACITOR_CABLE, [0x50]], [quack.ComponentType.COMPONENT_TYPE_CAPACITOR_CABLE, [0x50]],
[quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]], [quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]],
[quack.ComponentType.COMPONENT_TYPE_AIRFLOW, [0x2a]] [quack.ComponentType.COMPONENT_TYPE_AIRFLOW, [0x2a]],
[quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE, [0x71]] // the address cables will use when they are plugged into the expander with V2 device only
]) ])
], ],
[quack.AddressType.ADDRESS_TYPE_DAC, [0, 1]], [quack.AddressType.ADDRESS_TYPE_DAC, [0, 1]],
@ -103,7 +109,8 @@ export class DeviceAvailability {
ClaimAddress( ClaimAddress(
addressType: quack.AddressType, addressType: quack.AddressType,
componentType: quack.ComponentType, componentType: quack.ComponentType,
address: number address: number,
expansionLine?: number
) { ) {
let offset = addressType - 8; let offset = addressType - 8;
if (offset > 0) addressType = addressType - (7 + offset); if (offset > 0) addressType = addressType - (7 + offset);
@ -127,6 +134,9 @@ export class DeviceAvailability {
break; break;
case quack.AddressType.ADDRESS_TYPE_I2C: case quack.AddressType.ADDRESS_TYPE_I2C:
case quack.AddressType.ADDRESS_TYPE_SPI: case quack.AddressType.ADDRESS_TYPE_SPI:
if(expansionLine){
break;
}
let addressTypePositions = cloneDeep( let addressTypePositions = cloneDeep(
this.availability.get(addressType) as ComponentAvailabilityMap this.availability.get(addressType) as ComponentAvailabilityMap
); );
@ -171,7 +181,8 @@ export function FindAvailablePositions(
available.ClaimAddress( available.ClaimAddress(
component.settings.addressType, component.settings.addressType,
component.settings.type, component.settings.type,
or(component.settings.address, 0) or(component.settings.address, 0),
component.settings.expansionLine
); );
} }
}); });

View file

@ -246,7 +246,7 @@ export const BindaptV2MonitorAvailability: DeviceAvailabilityMap = new Map<
[ [
quack.AddressType.ADDRESS_TYPE_I2C, quack.AddressType.ADDRESS_TYPE_I2C,
new Map<quack.ComponentType, number[]>([ new Map<quack.ComponentType, number[]>([
//[quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]], [quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]],
[quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]], [quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]],
// [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated? // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated?
[quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]], [quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]],
@ -278,12 +278,13 @@ export const BindaptV2AutomateAvailability: DeviceAvailabilityMap = new Map<
[ [
quack.AddressType.ADDRESS_TYPE_I2C, quack.AddressType.ADDRESS_TYPE_I2C,
new Map<quack.ComponentType, number[]>([ new Map<quack.ComponentType, number[]>([
//[quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]], [quack.ComponentType.COMPONENT_TYPE_PRESSURE, [0x18]],
[quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]], [quack.ComponentType.COMPONENT_TYPE_DHT, [0x40]],
// [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated? // [quack.ComponentType.COMPONENT_TYPE_VAPOUR_PRESSURE_DEFICIT, [0x40]], //component type deprecated?
[quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]], [quack.ComponentType.COMPONENT_TYPE_LIDAR, [0x62]],
[quack.ComponentType.COMPONENT_TYPE_CO2, [0x61]], [quack.ComponentType.COMPONENT_TYPE_CO2, [0x61]],
[quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]] [quack.ComponentType.COMPONENT_TYPE_SEN5X, [0x69]],
[quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE, [0x71]]
]) ])
], ],
[quack.AddressType.ADDRESS_TYPE_POWER, [0]], [quack.AddressType.ADDRESS_TYPE_POWER, [0]],