Skip to content

Commit 57138e2

Browse files
committed
add conditionExt generation
1 parent 4df8bbe commit 57138e2

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

utils/src/csv2tsp.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,9 @@ const messageTrans: Trans<MessageLine> = (location, wholeLine, header, additions
617617
let circuit = line[1];
618618
const model = line[2];
619619
let field = line[4];
620+
const zz = hex(fromHex(line[5])[0] as number) || '';
620621
let value = line[6]||'';
622+
let noNs = '';
621623
if (circuit==='scan') {
622624
if (!model) {
623625
// refers to Ebus.Id.Id
@@ -628,24 +630,30 @@ const messageTrans: Trans<MessageLine> = (location, wholeLine, header, additions
628630
}
629631
}
630632
const fname = field||(value&&normalize?'value':'');
631-
additions.conditions.set(name, [[pascalCase(circuit),pascalCase(model),fname].filter(p=>p).join('.'), value]);
633+
additions.conditions.set(name, [[pascalCase(circuit),pascalCase(model),fname].filter(p=>p).join('.'), value, zz, noNs]);
632634
return;
633635
}
634636
// conditional
635637
const loadInclude = dirsStr[0]==='!' && line[1] && path.basename(line[1], path.extname(line[1]));
636638
conditions.forEach(cond => {
637639
// SW<1,SW>1,SW=1,SW<=1,SW>=1
638640
let [,name, values] = cond.match(/^([^=<>]*)(.*)$/)||[,cond];
639-
const [field, value] = additions.conditions.get(name)||additions.conditions.get(cond)||[];
641+
const [field, value, zz, noNs] = additions.conditions.get(name)||additions.conditions.get(cond)||[];
640642
if (value && !values) {
641643
values = value;
642644
}
643-
conds.push(`@condition(${field}${values?`, ${values.split(';').map(v=>'"'+v+'"').join(',')}`:''})`);
645+
if (zz) {
646+
conds.push(`@conditionExt(${field}, ${zz}${values?`, ${values.split(';').map(v=>'"'+v+'"').join(',')}`:''})`);
647+
} else {
648+
conds.push(`@condition(${field}${values?`, ${values.split(';').map(v=>'"'+v+'"').join(',')}`:''})`);
649+
}
644650
let nsAdd;
645651
if (value) {
646652
nsAdd = name;
653+
} else if (noNs) {
654+
nsAdd = '';
647655
} else {
648-
nsAdd = values||'';
656+
nsAdd = (zz?'_'+zz.substring(2)+(values?'_':''):'')+(values||'');
649657
if (loadInclude && nsAdd.startsWith("='") && field.includes('.Id.')) {
650658
nsAdd = '_'+loadInclude.split('.').reverse()[0]; // reduce multiple product ids with filename instead
651659
}

0 commit comments

Comments
 (0)