Skip to content

Commit

Permalink
iot2050-conf-webui: Add support for sm1223 dc di16 dq16 rly
Browse files Browse the repository at this point in the history
Signed-off-by: Nian Gao <[email protected]>
Signed-off-by: Baocheng Su <[email protected]>
Signed-off-by: Li Hua Qian <[email protected]>
  • Loading branch information
huaqianli committed Jul 29, 2024
1 parent d3c0428 commit d62f0d0
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import ConfigGroupLabel from '@/components/ConfigEntry/ConfigGroupLabel';
import Paper from '@mui/material/Paper';
import FormGroup from '@mui/material/FormGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
Expand All @@ -16,7 +19,7 @@ import { range } from 'lodash';

const yamlUIMapping = [
{
keys: [/di\.ch0_3_delay_time/, /di\.ch4_7_delay_time/],
keys: [/di\.ch0_3_delay_time/, /di\.ch4_7_delay_time/, /di\.ch8_11_delay_time/, /di\.ch12_15_delay_time/],
rules: [
{
scenario: 'all',
Expand Down Expand Up @@ -45,7 +48,7 @@ const yamlUIMapping = [
]
},
{
keys: [/dq\.ch[0-7]\.substitute/],
keys: [/dq\.ch([0-9]|1[0-5])\.substitute/],
rules: [
{
scenario: 'all',
Expand All @@ -70,80 +73,109 @@ const inputFiltersSelection = [
uiString.TIME_9
];

export const SM1223ConfDefault = {
mlfb: '6ES7223-1QH32-0XB0',
di: {
ch0_3_delay_time: {
label: uiString.LABEL_DI_INPUT_FILTER_TIME_CH0_3,
export function SM1223ConfDefault (mlfb) {
const ret = {
mlfb,
di: {
ch0_3_delay_time: {
label: uiString.LABEL_DI_INPUT_FILTER_TIME_CH0_3,
selection: inputFiltersSelection,
value: uiString.TIME_3
},
ch4_7_delay_time: {
label: uiString.LABEL_DI_INPUT_FILTER_TIME_CH4_7,
selection: inputFiltersSelection,
value: uiString.TIME_3
}
},
dq: {
behavior_with_OD: {
label: uiString.LABEL_DQ_LOST_CONNECTION,
selection: [
uiString.DISCONN_2,
uiString.DISCONN_3
],
value: uiString.DISCONN_2
}
}
};

let chTotal = 8;
if (mlfb === '6ES7223-1PL32-0XB0') {
ret.di.ch8_11_delay_time = {
label: uiString.LABEL_DI_INPUT_FILTER_TIME_CH8_11,
selection: inputFiltersSelection,
value: uiString.TIME_3
},
ch4_7_delay_time: {
label: uiString.LABEL_DI_INPUT_FILTER_TIME_CH4_7,
};
ret.di.ch12_15_delay_time = {
label: uiString.LABEL_DI_INPUT_FILTER_TIME_CH12_15,
selection: inputFiltersSelection,
value: uiString.TIME_3
}
},
dq: {
behavior_with_OD: {
label: uiString.LABEL_DQ_LOST_CONNECTION,
selection: [
uiString.DISCONN_2,
uiString.DISCONN_3
],
value: uiString.DISCONN_2
},
ch0: { substitute: true },
ch1: { substitute: true },
ch2: { substitute: true },
ch3: { substitute: true },
ch4: { substitute: true },
ch5: { substitute: true },
ch6: { substitute: true },
ch7: { substitute: true }
};
chTotal = 16;
}

for (let i = 0; i < chTotal; i++) {
const chX = 'ch' + i;
ret.dq[chX] = { substitute: true };
};

return ret;
};

export function convertToUIFormat (config) {
const ret = JSON.parse(JSON.stringify(SM1223ConfDefault));
const ret = JSON.parse(JSON.stringify(SM1223ConfDefault(config.mlfb)));
ret.di.ch0_3_delay_time.value = converter.yamlToUi('di.ch0_3_delay_time', config.di.ch0_3_delay_time);
ret.di.ch4_7_delay_time.value = converter.yamlToUi('di.ch4_7_delay_time', config.di.ch4_7_delay_time);
ret.dq.behavior_with_OD.value = converter.yamlToUi('dq.behavior_with_OD', config.dq.behavior_with_OD);
ret.dq.ch0.substitute = converter.yamlToUi('dq.ch0.substitute', config.dq.ch0.substitute);
ret.dq.ch1.substitute = converter.yamlToUi('dq.ch1.substitute', config.dq.ch1.substitute);
ret.dq.ch2.substitute = converter.yamlToUi('dq.ch2.substitute', config.dq.ch2.substitute);
ret.dq.ch3.substitute = converter.yamlToUi('dq.ch3.substitute', config.dq.ch3.substitute);
ret.dq.ch4.substitute = converter.yamlToUi('dq.ch4.substitute', config.dq.ch4.substitute);
ret.dq.ch5.substitute = converter.yamlToUi('dq.ch5.substitute', config.dq.ch5.substitute);
ret.dq.ch6.substitute = converter.yamlToUi('dq.ch6.substitute', config.dq.ch6.substitute);
ret.dq.ch7.substitute = converter.yamlToUi('dq.ch7.substitute', config.dq.ch7.substitute);

let chTotal = 8;
if (config.mlfb === '6ES7223-1PL32-0XB0') {
ret.di.ch8_11_delay_time.value = converter.yamlToUi('di.ch8_11_delay_time', config.di.ch8_11_delay_time);
ret.di.ch12_15_delay_time.value = converter.yamlToUi('di.ch12_15_delay_time', config.di.ch12_15_delay_time);
chTotal = 16;
}

for (let i = 0; i < chTotal; i++) {
let chX = 'ch' + i;
ret.dq[chX].substitute = converter.yamlToUi(`dq.${chX}.substitute`, config.dq[chX].substitute);
}

return ret;
};

export function convertToDeviceFormat (config) {
const ret = {
description: uiString.DESC_MOD,
description: 'TBD',
mlfb: config.mlfb,
di: {
ch0_3_delay_time: converter.uiToYaml('di.ch0_3_delay_time', config.di.ch0_3_delay_time.value),
ch4_7_delay_time: converter.uiToYaml('di.ch4_7_delay_time', config.di.ch4_7_delay_time.value)
},
dq: {
behavior_with_OD: converter.uiToYaml('dq.behavior_with_OD', config.dq.behavior_with_OD.value),
ch0: { substitute: converter.uiToYaml('dq.ch0.substitute', config.dq.ch0.substitute) },
ch1: { substitute: converter.uiToYaml('dq.ch1.substitute', config.dq.ch1.substitute) },
ch2: { substitute: converter.uiToYaml('dq.ch2.substitute', config.dq.ch2.substitute) },
ch3: { substitute: converter.uiToYaml('dq.ch3.substitute', config.dq.ch3.substitute) },
ch4: { substitute: converter.uiToYaml('dq.ch4.substitute', config.dq.ch4.substitute) },
ch5: { substitute: converter.uiToYaml('dq.ch5.substitute', config.dq.ch5.substitute) },
ch6: { substitute: converter.uiToYaml('dq.ch6.substitute', config.dq.ch6.substitute) },
ch7: { substitute: converter.uiToYaml('dq.ch7.substitute', config.dq.ch7.substitute) }
behavior_with_OD: converter.uiToYaml('dq.behavior_with_OD', config.dq.behavior_with_OD.value)
}
};

const chTotal = config.mlfb === '6ES7223-1QH32-0XB0' ? 8 : 16;

if (chTotal === 8) {
ret.description = uiString.DESC_MOD_AC_DI8_DQ8RLY;
} else {
ret.description = uiString.DESC_MOD_DC_DI16_DQ16RLY;
ret.di['ch8_11_delay_time'] = converter.uiToYaml('di.ch8_11_delay_time', config.di.ch8_11_delay_time.value);
ret.di['ch12_15_delay_time'] = converter.uiToYaml('di.ch12_15_delay_time', config.di.ch12_15_delay_time.value);
}

for (let i = 0; i < chTotal; i++) {
let chX = 'ch' + i;
ret.dq[chX] = { substitute: converter.uiToYaml(`dq.${chX}.substitute`, config.dq[chX].substitute) };
}

return ret;
};

export default function SM1223Conf ({ slotNum, configData, updateConfig }) {
export default function SM1223Conf ({ slotNum, configData, updateConfig, chTotal }) {
const onChangeBehaviorWithOD = (event, value) => {
const newConf = configData;
newConf.dq.behavior_with_OD.value = value;
Expand All @@ -168,56 +200,89 @@ export default function SM1223Conf ({ slotNum, configData, updateConfig }) {
spacing={2}
>
<ModuleInfo
description={uiString.DESC_MOD}
artNumber="6ES7 223-1QH32-0XB0"
description={chTotal === 8 ? uiString.DESC_MOD_AC_DI8_DQ8RLY : uiString.DESC_MOD_DC_DI16_DQ16RLY}
artNumber={configData.mlfb === '6ES7223-1QH32-0XB0' ? "6ES7 223-1QH32-0XB0" : "6ES7 223-1PL32-0XB0"}
fwVersion="NA"
/>

<SelectionConfig
id="input-filter-time-ch0-3"
data={configData.di.ch0_3_delay_time}
updateConfig={updateSlotConfig}
/>
<Paper elevation={3}>
<FormControl sx={{ m: 2 }} component="fieldset" variant="standard">
<ConfigGroupLabel label='Digital Inputs' />
<FormGroup>
<Stack
direction="column"
justifyContent="flex-start"
alignItems="stretch"
spacing={2}
>

<SelectionConfig
id="input-filter-time-ch4-7"
data={configData.di.ch4_7_delay_time}
updateConfig={updateSlotConfig}
/>
<SelectionConfig
id="input-filter-time-ch0-3"
data={configData.di.ch0_3_delay_time}
updateConfig={updateSlotConfig}
/>

<FormControl>
<FormLabel id="do-discon-config-label">{configData.dq.behavior_with_OD.label}</FormLabel>
<RadioGroup
aria-labelledby="do-discon-config-label"
value={configData.dq.behavior_with_OD.value}
name="do-discon-config-group"
onChange={onChangeBehaviorWithOD}
>
{configData.dq.behavior_with_OD.selection.map((option) => (
<FormControlLabel value={option} control={<Radio />} label={option} key={option}/>
))}

<Box sx={{
display: configData.dq.behavior_with_OD.value === uiString.DISCONN_3 ? 'flex' : 'none',
flexDirection: 'column',
ml: 3
}}
>
{range(0, 8).map((index) => (
<FormControlLabel key={index}
label={'Channel ' + index}
control={<Checkbox
checked={configData.dq['ch' + index].substitute}
onChange={onChangeChSubstitute}
id={'checkbox-ch-' + index}
name={'ch' + index}
/>}
<SelectionConfig
id="input-filter-time-ch4-7"
data={configData.di.ch4_7_delay_time}
updateConfig={updateSlotConfig}
/>
))
}
</Box>
</RadioGroup>
</FormControl>

{chTotal === 16 && (<>
<SelectionConfig
id="input-filter-time-ch8-11"
data={configData.di.ch8_11_delay_time}
updateConfig={updateSlotConfig}
/>
<SelectionConfig
id="input-filter-time-ch12-15"
data={configData.di.ch12_15_delay_time}
updateConfig={updateSlotConfig}
/>
</>
)}
</Stack>
</FormGroup>
</FormControl>
</Paper>

<Paper elevation={3}>
<FormControl sx={{ m: 2 }} component="fieldset" variant="standard">
<ConfigGroupLabel label='Digital Outputs' />
<FormLabel id="do-discon-config-label">{configData.dq.behavior_with_OD.label}</FormLabel>
<RadioGroup
aria-labelledby="do-discon-config-label"
value={configData.dq.behavior_with_OD.value}
name="do-discon-config-group"
onChange={onChangeBehaviorWithOD}
>
{configData.dq.behavior_with_OD.selection.map((option) => (
<FormControlLabel value={option} control={<Radio />} label={option} key={option}/>
))}

<Box sx={{
display: configData.dq.behavior_with_OD.value === uiString.DISCONN_3 ? 'flex' : 'none',
flexDirection: 'column',
ml: 3
}}
>
{range(0, chTotal).map((index) => (
<FormControlLabel key={index}
label={'Channel ' + index}
control={<Checkbox
checked={configData.dq['ch' + index].substitute}
onChange={onChangeChSubstitute}
id={'checkbox-ch-' + index}
name={'ch' + index}
/>}
/>
))
}
</Box>
</RadioGroup>
</FormControl>
</Paper>

</Stack>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable camelcase */
/* eslint-disable react/prop-types */
import * as React from 'react';
import SM1223Conf from './SM1223Conf';
import uiString from '@/lib/uiString/SM1223.json';

export default function SM1223_AC_DI8_DQ8RLY_Conf ({ slotNum, configData, updateConfig }) {
return (
<SM1223Conf
slotNum={slotNum}
configData={configData}
updateConfig={updateConfig}
chTotal={8}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable camelcase */
/* eslint-disable react/prop-types */
import * as React from 'react';
import SM1223Conf from './SM1223Conf';

export default function SM1223_DC_DI16_DQ16RLY_Conf ({ slotNum, configData, updateConfig }) {
return (
<SM1223Conf
slotNum={slotNum}
configData={configData}
updateConfig={updateConfig}
chTotal={16}
/>
);
}
Loading

0 comments on commit d62f0d0

Please sign in to comment.