modified: lib/obp60task/gen_set.pl

Bugfixes and some comments
This commit is contained in:
Tobias E 2024-11-20 19:39:16 +00:00
parent 960e80330f
commit 85ad03e0fa
1 changed files with 29 additions and 17 deletions

View File

@ -1,14 +1,11 @@
#!/bin/perl -w #!/bin/perl -w
#A tool to generate that part of config.json that deals with pages and Fields.
use List::Util qw( min max ); use List::Util qw( min max );
$NoOfPages=2;
@Defaults=qw(Voltage WindRose OneValue TwoValues ThreeValues FourValues FourValues2 Clock RollPitch Battery2);
@Numbers=qw(one two three four five six seven eight nine ten ); #List of all Pages and the number of parameters they expect.
%NoOfFields=qw( OneValue 1 %NoOfFieldsPerPage=qw(
TwoValues 2
ThreeValues 3
FourValues 4
FourValues2 4
WindRoseFlex 6
ApparentWind 0 ApparentWind 0
Autobahn 0 Autobahn 0
Battery2 0 Battery2 0
@ -16,18 +13,27 @@ $NoOfPages=2;
BME280 0 BME280 0
Clock 0 Clock 0
DST810 0 DST810 0
FourValues2 4
FourValues 4
Generator 0 Generator 0
KeelPosition 0 KeelPosition 0
OneValue 1
RollPitch 0 RollPitch 0
RudderPosition 0 RudderPosition 0
Solar 0 Solar 0
ThreeValues 3
TwoValues 2
Voltage 0 Voltage 0
White 0 White 0
WindRose 0 WindRose 0
WindRoseFlex 6
); );
#@Pages=qw(ApparentWind Autobahn Battery2 Battery BME280 Clock DST810 FourValues2 FourValues Generator KeelPosition OneValue RollPitch RudderPosition Solar ThreeValues TwoValues Voltage White WindRose WindRoseFlex); # No changes neede beyond this pint
@Pages=keys(%NoOfFields); $NoOfPages=10;
$MaxNoOFFIelds=max(values(%NoOfFields)); @Defaults=qw(Voltage WindRose OneValue TwoValues ThreeValues FourValues FourValues2 Clock RollPitch Battery2);
@Numbers=qw(one two three four five six seven eight nine ten);
@Pages=sort(keys(%NoOfFieldsPerPage));
$MaxNoOfFieldsPerPage=max(values(%NoOfFieldsPerPage));
for ($PageNo=1;$PageNo<=$NoOfPages;$PageNo++){ for ($PageNo=1;$PageNo<=$NoOfPages;$PageNo++){
@ -45,12 +51,18 @@ for ($PageNo=1;$PageNo<=$NoOfPages;$PageNo++){
if ($p < $#Pages){print ","} if ($p < $#Pages){print ","}
} }
print "]\n"; print "]\n";
print "\t",'"category": "OBP60 Page 1",',"\n"; print "\t",'"category": "OBP60 Page ',$PageNo,'",',"\n";
print "\t",'"capabilities": {',"\n"; print "\t",'"capabilities": {',"\n";
print "\t\t",'"obp60":"true"',"\n"; print "\t\t",'"obp60":"true"',"\n";
print "\t",'}',"\n"; print "\t",'}',"\n";
print "\t",'"condition":[';
for ($vp=$PageNo;$vp<=$NoOfPages;$vp++){
print '"{visiblePages":"',$vp,'"},';
}
#"visiblePages":"2"},{"visiblePages":"3"},{"visiblePages":"4"},{"visiblePages":"5"},{"visiblePages":"6"},{"visiblePages":"7"},{"visiblePages":"8"},{"visiblePages":"9"},{"visiblePages":"10"}
print "\b",']',"\n";
print '},',"\n"; print '},',"\n";
for ($FieldNo=1; $FieldNo<=$MaxNoOFFIelds;$FieldNo++){ for ($FieldNo=1; $FieldNo<=$MaxNoOfFieldsPerPage;$FieldNo++){
print "{\n"; print "{\n";
print "\t",'"name": "page',$PageNo,'value',$FieldNo,'",',"\n"; print "\t",'"name": "page',$PageNo,'value',$FieldNo,'",',"\n";
print "\t",'"label": "Field ',$FieldNo,'",',"\n"; print "\t",'"label": "Field ',$FieldNo,'",',"\n";
@ -63,13 +75,13 @@ for ($PageNo=1;$PageNo<=$NoOfPages;$PageNo++){
print "\t",'},',"\n"; print "\t",'},',"\n";
print "\t",'"condition":['; print "\t",'"condition":[';
foreach $page (@Pages) { foreach $page (@Pages) {
if($NoOfFields{$page}>=$FieldNo){ if($NoOfFieldsPerPage{$page}>=$FieldNo){
print '"page1type":"',$page,'"},'; print '{"page1type":"',$page,'"},';
} }
#{"page1type":"OneValue"},{"page1type":"TwoValues"},{"page1type":"ThreeValues"},{"page1type":"FourValues"},{"page1type":"FourValues2"},{"page1type":"WindRoseFlex"} #{"page1type":"OneValue"},{"page1type":"TwoValues"},{"page1type":"ThreeValues"},{"page1type":"FourValues"},{"page1type":"FourValues2"},{"page1type":"WindRoseFlex"}
} }
print "],\n"; print "\b],\n";
print '},',"\n"; print '},',"\n";
} }
} }