blob: a0f896f6f3b8142ff6afc07ca06cc22ccb9d51ac [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001use strict;
2use Cwd;
3use lib "tools/perl";
4use Spreadsheet::ParseExcel;
5
6my $curdir = getcwd();
7my $parser = Spreadsheet::ParseExcel->new();
8my $workbook = $parser->parse("$curdir/custom/protocol/common/ps/custom_lte_ca.xls");
9my $projdir = $ARGV[2];
10##my $logdir = $ARGV[3];
11
12$projdir =~ s/\.//g;
13
14## Redirect STDERR to STDOUT
15open(STDERR, ">&STDOUT");
16
17print "current project directory = $projdir\n";
18
19my $newdir = "$curdir$projdir/custom/modem";
20mkdir $newdir if(! -e $newdir);
21$newdir = "$newdir/eas_caband_tbl";
22mkdir $newdir if(! -e $newdir);
23##my $logfile = "$curdir$logdir/eas_gen_caband_tbl.log";
24##unlink($logfile) if (-e $logfile);
25##open(STDERR, ">$logfile");
26
27print "new file directory = $newdir\n";
28
29if (!defined $workbook)
30{
31 die $parser->error(), ".\n";
32}
33
34my $outputfile = "$newdir/eas_caband_tbl_v2.c";
35open (CABAND_TBL, "> $outputfile") || die "open file fail: eas_caband_tbl_v2.c";
36
37print CABAND_TBL "#include \"custom_eas_config.h\"\n\n";
38print CABAND_TBL "const eas_global_support_band_struct eas_ca_sel_tbl[] = {\n";
39print CABAND_TBL "/* { PLMN, {";
40for my $i (0 .. 255)
41{
42 my $j = ($i + 1) % 8;
43 printf CABAND_TBL "%10s", "B".($i+8)."~"."B".($i+1) if ($j == 1);
44 print CABAND_TBL "," if (($i + 1) != 256 && $j == 0);
45}
46print CABAND_TBL " }} */\n";
47
48my $worksheet1 = $workbook->worksheet('CASelectionBand1Band253');
49my $worksheet2 = $workbook->worksheet('CASelectionBand254Band256');
50
51## Get Excel table size
52my ( $row_min1, $row_max1 ) = $worksheet1->row_range();
53my ( $col_min1, $col_max1 ) = $worksheet1->col_range();
54
55my ( $row_min2, $row_max2 ) = $worksheet2->row_range();
56my ( $col_min2, $col_max2 ) = $worksheet2->col_range();
57
58## Only for debugging
59##print "\n";
60##print "Sheet 'CASelectionBand1Band253':\n";
61##print " row_min1 = $row_min1, row_max1 = $row_max1\n";
62##print " col_min1 = $col_min1, col_max1 = $col_max1\n";
63##print "\n";
64##print "Sheet 'CASelectionBand254Band256':\n";
65##print " row_min2 = $row_min2, row_max2 = $row_max2\n";
66##print " col_min2 = $col_min2, col_max2 = $col_max2\n";
67##print "\n";
68
69## Skip the title row
70$row_min1++;
71$row_min1++;
72
73for my $row1 ( $row_min1 .. $row_max1 )
74{
75 my $cell1 = $worksheet1->get_cell( $row1, $col_min1 );
76
77 if ($cell1->value() =~ /([-]+)(.*)/)
78 {
79 ## Level 1: Continents, World Wide or Test Network
80 if ($1 eq "-")
81 {
82 print CABAND_TBL " /* ".$2." */\n";
83 }
84 ## Level 2: Orientation or subregion of Contienent
85 elsif ($1 eq "--")
86 {
87 print CABAND_TBL " /** ".$2." **/\n";
88 }
89 ## Level 3: Countries, Nations
90 elsif ($1 eq "---")
91 {
92 print CABAND_TBL " /*** ".$2." ***/\n";
93
94 my $ltebandbitmask = "0x00";
95
96 my $cell1_2 = $worksheet1->get_cell( $row1, $col_min1+1 );
97 my @mcclist = split(',', $cell1_2->value());
98
99 for my $mcc (@mcclist)
100 {
101 my $cell1_3 = $worksheet1->get_cell( $row1, $col_min1+2 );
102 my @mnclist = split(',', $cell1_3->value());
103
104 for my $mnc (@mnclist)
105 {
106 if ($mcc eq "NULL") { $mcc = ""; }
107 if ($mnc eq "NULL") { $mnc = ""; }
108
109 print CABAND_TBL " {\"".$mcc.$mnc."\", {";
110
111 ## Starting from Band1, Band2, Band3, and so on
112 for my $col1 ($col_min1+3 .. $col_max1)
113 {
114 my $cell1_4 = $worksheet1->get_cell( $row1, $col1 );
115 if ($cell1_4->value() eq "YES")
116 {
117 $ltebandbitmask |= 1 << (($col1 - 3) % 8);
118 }
119
120 ## Conclude for each 8 bits
121 if ( ($col1 - 3 + 1) % 8 == 0 )
122 {
123 my $hex_string = sprintf("0x%02X", $ltebandbitmask);
124 printf CABAND_TBL "%10s", $hex_string;
125 print CABAND_TBL "," if (($col1 - 3 + 1) != 256);
126
127 ## Start over again
128 $ltebandbitmask = "0x00";
129 }
130 }
131
132 ## Continue on next worksheet (starting from Band254, ...
133 for my $col2 ($col_min2+3 .. $col_max2)
134 {
135 my $cell2_4 = $worksheet2->get_cell( $row1, $col2 );
136 if ($cell2_4->value() eq "YES")
137 {
138 $ltebandbitmask |= 1 << (((253+$col2) - 3) % 8);
139 }
140
141 ## Conclude for each 8 bits
142 if ( ((253+$col2) - 3 + 1) % 8 == 0 )
143 {
144 my $hex_string = sprintf("0x%02X", $ltebandbitmask);
145 printf CABAND_TBL "%10s", $hex_string;
146 print CABAND_TBL "," if (((253+$col2) - 3 + 1) != 256);
147
148 ## Start over again
149 $ltebandbitmask = "0x00";
150 }
151 }
152
153 print CABAND_TBL " }},\n";
154 }
155 }
156 }
157 ## Level 4: Operators
158 elsif ($1 eq "----")
159 {
160 print CABAND_TBL " /**** ".$2." ****/\n";
161
162 my $ltebandbitmask = "0x00";
163
164 my $cell1_2 = $worksheet1->get_cell( $row1, $col_min1+1 );
165 my @mcclist = split(',', $cell1_2->value());
166
167 for my $mcc (@mcclist)
168 {
169 my $cell1_3 = $worksheet1->get_cell( $row1, $col_min1+2 );
170 my @mnclist = split(',', $cell1_3->value());
171
172 for my $mnc (@mnclist)
173 {
174 if ($mcc eq "NULL") { $mcc = ""; }
175 if ($mnc eq "NULL") { $mnc = ""; }
176
177 print CABAND_TBL " {\"".$mcc.$mnc."\", {";
178
179 ## Starting from Band1, Band2, Band3, and so on
180 for my $col1 ($col_min1+3 .. $col_max1)
181 {
182 my $cell1_4 = $worksheet1->get_cell( $row1, $col1 );
183 if ($cell1_4->value() eq "YES")
184 {
185 $ltebandbitmask |= 1 << (($col1 - 3) % 8);
186 }
187
188 ## Conclude for each 8 bits
189 if ( ($col1 - 3 + 1) % 8 == 0 )
190 {
191 my $hex_string = sprintf("0x%02X", $ltebandbitmask);
192 printf CABAND_TBL "%10s", $hex_string;
193 print CABAND_TBL "," if (($col1 - 3 + 1) != 256);
194
195 ## Start over again
196 $ltebandbitmask = "0x00";
197 }
198 }
199
200 ## Continue on next worksheet (starting from Band254, ...
201 for my $col2 ($col_min2+3 .. $col_max2)
202 {
203 my $cell2_4 = $worksheet2->get_cell( $row1, $col2 );
204 if ($cell2_4->value() eq "YES")
205 {
206 $ltebandbitmask |= 1 << (((253+$col2) - 3) % 8);
207 }
208
209 ## Conclude for each 8 bits
210 if ( ((253+$col2) - 3 + 1) % 8 == 0 )
211 {
212 my $hex_string = sprintf("0x%02X", $ltebandbitmask);
213 printf CABAND_TBL "%10s", $hex_string;
214 print CABAND_TBL "," if (((253+$col2) - 3 + 1) != 256);
215
216 ## Start over again
217 $ltebandbitmask = "0x00";
218 }
219 }
220
221 print CABAND_TBL " }},\n";
222 }
223 }
224 }
225 }
226 elsif ($cell1->value() =~ /^\[UNIT_TEST/)
227 {
228 print CABAND_TBL "#ifdef UNIT_TEST\n";
229 }
230 elsif ($cell1->value() =~ /^\]UNIT_TEST/)
231 {
232 print CABAND_TBL "#endif /* UNIT_TEST */\n";
233 }
234}
235
236print CABAND_TBL "};\n\n";
237
238print CABAND_TBL "const kal_uint32 eas_ca_sel_num = sizeof(eas_ca_sel_tbl) / sizeof(eas_global_support_band_struct);\n";
239
240## Separation
241print CABAND_TBL "\n\n";
242
243print CABAND_TBL "const eas_global_support_band_struct eas_capsize_reduce_tbl[] = {\n";
244print CABAND_TBL "/* { PLMN, {";
245for my $i (0 .. 255)
246{
247 my $j = ($i + 1) % 8;
248 printf CABAND_TBL "%10s", "B".($i+8)."~"."B".($i+1) if ($j == 1);
249 print CABAND_TBL "," if (($i + 1) != 256 && $j == 0);
250}
251print CABAND_TBL " }} */\n";
252
253my $worksheet1 = $workbook->worksheet('CapabilitySizeBand1Band253');
254my $worksheet2 = $workbook->worksheet('CapabilitySizeBand254Band256');
255
256## Get Excel table size
257my ( $row_min1, $row_max1 ) = $worksheet1->row_range();
258my ( $col_min1, $col_max1 ) = $worksheet1->col_range();
259
260my ( $row_min2, $row_max2 ) = $worksheet2->row_range();
261my ( $col_min2, $col_max2 ) = $worksheet2->col_range();
262
263## Only for debugging
264##print "\n";
265##print "Sheet 'CapabilitySizeBand1Band253':\n";
266##print " row_min1 = $row_min1, row_max1 = $row_max1\n";
267##print " col_min1 = $col_min1, col_max1 = $col_max1\n";
268##print "\n";
269##print "Sheet 'CapabilitySizeBand254Band256':\n";
270##print " row_min2 = $row_min2, row_max2 = $row_max2\n";
271##print " col_min2 = $col_min2, col_max2 = $col_max2\n";
272##print "\n";
273
274## Skip the title row
275$row_min1++;
276$row_min1++;
277
278for my $row1 ( $row_min1 .. $row_max1 )
279{
280 my $cell1 = $worksheet1->get_cell( $row1, $col_min1 );
281
282 if ($cell1->value() =~ /([-]+)(.*)/)
283 {
284 ## Level 1: Continents, World Wide or Test Network
285 if ($1 eq "-")
286 {
287 print CABAND_TBL " /* ".$2." */\n";
288 }
289 ## Level 2: Orientation or subregion of Contienent
290 elsif ($1 eq "--")
291 {
292 print CABAND_TBL " /** ".$2." **/\n";
293 }
294 ## Level 3: Countries, Nations
295 elsif ($1 eq "---")
296 {
297 print CABAND_TBL " /*** ".$2." ***/\n";
298
299 my $ltebandbitmask = "0x00";
300
301 my $cell1_2 = $worksheet1->get_cell( $row1, $col_min1+1 );
302 my @mcclist = split(',', $cell1_2->value());
303
304 for my $mcc (@mcclist)
305 {
306 my $cell1_3 = $worksheet1->get_cell( $row1, $col_min1+2 );
307 my @mnclist = split(',', $cell1_3->value());
308
309 for my $mnc (@mnclist)
310 {
311 if ($mcc eq "NULL") { $mcc = ""; }
312 if ($mnc eq "NULL") { $mnc = ""; }
313
314 print CABAND_TBL " {\"".$mcc.$mnc."\", {";
315
316 ## Starting from Band1, Band2, Band3, and so on
317 for my $col1 ($col_min1+3 .. $col_max1)
318 {
319 my $cell1_4 = $worksheet1->get_cell( $row1, $col1 );
320 if ($cell1_4->value() eq "YES")
321 {
322 $ltebandbitmask |= 1 << (($col1 - 3) % 8);
323 }
324
325 ## Conclude for each 8 bits
326 if ( ($col1 - 3 + 1) % 8 == 0 )
327 {
328 my $hex_string = sprintf("0x%02X", $ltebandbitmask);
329 printf CABAND_TBL "%10s", $hex_string;
330 print CABAND_TBL "," if (($col1 - 3 + 1) != 256);
331
332 ## Start over again
333 $ltebandbitmask = "0x00";
334 }
335 }
336
337 ## Continue on next worksheet (starting from Band254, ...
338 for my $col2 ($col_min2+3 .. $col_max2)
339 {
340 my $cell2_4 = $worksheet2->get_cell( $row1, $col2 );
341 if ($cell2_4->value() eq "YES")
342 {
343 $ltebandbitmask |= 1 << (((253+$col2) - 3) % 8);
344 }
345
346 ## Conclude for each 8 bits
347 if ( ((253+$col2) - 3 + 1) % 8 == 0 )
348 {
349 my $hex_string = sprintf("0x%02X", $ltebandbitmask);
350 printf CABAND_TBL "%10s", $hex_string;
351 print CABAND_TBL "," if (((253+$col2) - 3 + 1) != 256);
352
353 ## Start over again
354 $ltebandbitmask = "0x00";
355 }
356 }
357
358 print CABAND_TBL " }},\n";
359 }
360 }
361 }
362 ## Level 4: Operators
363 elsif ($1 eq "----")
364 {
365 print CABAND_TBL " /**** ".$2." ****/\n";
366
367 my $ltebandbitmask = "0x00";
368
369 my $cell1_2 = $worksheet1->get_cell( $row1, $col_min1+1 );
370 my @mcclist = split(',', $cell1_2->value());
371
372 for my $mcc (@mcclist)
373 {
374 my $cell1_3 = $worksheet1->get_cell( $row1, $col_min1+2 );
375 my @mnclist = split(',', $cell1_3->value());
376
377 for my $mnc (@mnclist)
378 {
379 if ($mcc eq "NULL") { $mcc = ""; }
380 if ($mnc eq "NULL") { $mnc = ""; }
381
382 print CABAND_TBL " {\"".$mcc.$mnc."\", {";
383
384 ## Starting from Band1, Band2, Band3, and so on
385 for my $col1 ($col_min1+3 .. $col_max1)
386 {
387 my $cell1_4 = $worksheet1->get_cell( $row1, $col1 );
388 if ($cell1_4->value() eq "YES")
389 {
390 $ltebandbitmask |= 1 << (($col1 - 3) % 8);
391 }
392
393 ## Conclude for each 8 bits
394 if ( ($col1 - 3 + 1) % 8 == 0 )
395 {
396 my $hex_string = sprintf("0x%02X", $ltebandbitmask);
397 printf CABAND_TBL "%10s", $hex_string;
398 print CABAND_TBL "," if (($col1 - 3 + 1) != 256);
399
400 ## Start over again
401 $ltebandbitmask = "0x00";
402 }
403 }
404
405 ## Continue on next worksheet (starting from Band254, ...
406 for my $col2 ($col_min2+3 .. $col_max2)
407 {
408 my $cell2_4 = $worksheet2->get_cell( $row1, $col2 );
409 if ($cell2_4->value() eq "YES")
410 {
411 $ltebandbitmask |= 1 << (((253+$col2) - 3) % 8);
412 }
413
414 ## Conclude for each 8 bits
415 if ( ((253+$col2) - 3 + 1) % 8 == 0 )
416 {
417 my $hex_string = sprintf("0x%02X", $ltebandbitmask);
418 printf CABAND_TBL "%10s", $hex_string;
419 print CABAND_TBL "," if (((253+$col2) - 3 + 1) != 256);
420
421 ## Start over again
422 $ltebandbitmask = "0x00";
423 }
424 }
425
426 print CABAND_TBL " }},\n";
427 }
428 }
429 }
430 }
431 elsif ($cell1->value() =~ /^\[UNIT_TEST/)
432 {
433 print CABAND_TBL "#ifdef UNIT_TEST\n";
434 }
435 elsif ($cell1->value() =~ /^\]UNIT_TEST/)
436 {
437 print CABAND_TBL "#endif /* UNIT_TEST */\n";
438 }
439}
440
441print CABAND_TBL "};\n\n";
442
443print CABAND_TBL "const kal_uint32 eas_capsize_reduce_num = sizeof(eas_capsize_reduce_tbl) / sizeof(eas_global_support_band_struct);\n";
444
445## Separation
446print CABAND_TBL "\n\n";
447
448
449print CABAND_TBL "const eas_special_plmn_exclude_struct eas_special_plmn_exclude_tbl[] = {\n";
450print CABAND_TBL "/* { PLMN } */\n";
451
452my $worksheet = $workbook->worksheet('ExcludeForCAFilter');
453
454## Get Excel table size
455my ( $row_min, $row_max ) = $worksheet->row_range();
456my ( $col_min, $col_max ) = $worksheet->col_range();
457
458## Only for debugging
459##print "Sheet 'ExcludeForCAFilter':\n";
460##print " row_min = $row_min, row_max = $row_max\n";
461##print " col_min = $col_min, col_max = $col_max\n";
462
463## Skip the title row
464$row_min++;
465
466for my $row ( $row_min .. $row_max )
467{
468 my $cell = $worksheet->get_cell( $row, $col_min );
469
470 if ($cell->value() =~ /([-]+)(.*)/)
471 {
472 ## Level 1: Continents, World Wide or Test Network
473 if ($1 eq "-")
474 {
475 die "Level 1: Continents, World Wide - is not allowed in this sheet!";
476 }
477 ## Level 2: Orientation or subregion of Contienent
478 elsif ($1 eq "--")
479 {
480 die "Level 2: Orientation or subregion of Contienent - is not allowed in this sheet!";
481 }
482 ## Level 3: Countries, Nations
483 elsif ($1 eq "---")
484 {
485 die "Level 3: Countries, Nations - is not allowed in this sheet!";
486 }
487 ## Level 4: Operators
488 elsif ($1 eq "----")
489 {
490 print CABAND_TBL " /**** ".$2." ****/\n";
491
492 my $cell_2 = $worksheet->get_cell( $row, $col_min+1 );
493 my @mcclist = split(',', $cell_2->value());
494
495 for my $mcc (@mcclist)
496 {
497 my $cell_3 = $worksheet->get_cell( $row, $col_min+2 );
498 my @mnclist = split(',', $cell_3->value());
499
500 for my $mnc (@mnclist)
501 {
502 if ($mcc eq "NULL") { $mcc = ""; }
503 if ($mnc eq "NULL") { $mnc = ""; }
504
505 print CABAND_TBL " { \"".$mcc.$mnc."\" },\n";
506 }
507 }
508 }
509 }
510 elsif ($cell->value() =~ /^\[UNIT_TEST/)
511 {
512 print CABAND_TBL "#ifdef UNIT_TEST\n";
513 }
514 elsif ($cell->value() =~ /^\]UNIT_TEST/)
515 {
516 print CABAND_TBL "#endif /* UNIT_TEST */\n";
517 }
518}
519
520print CABAND_TBL "};\n\n";
521
522print CABAND_TBL "const kal_uint32 eas_special_plmn_exclude_num = sizeof(eas_special_plmn_exclude_tbl) / sizeof(eas_special_plmn_exclude_struct);\n";
523
524## Separation
525print CABAND_TBL "\n\n";
526
527
528
529print CABAND_TBL "#if !defined(MT6739)\n";
530print CABAND_TBL "const eas_global_ca_comb_struct eas_global_ca_comb_tbl[] = {\n";
531print CABAND_TBL "/* { PLMN,";
532printf CABAND_TBL "%30s", "Enable List";
533print CABAND_TBL ",";
534printf CABAND_TBL "%30s", "Disable List";
535print CABAND_TBL " } */\n";
536
537my $worksheet = $workbook->worksheet('EnableDisableCAComb');
538## Get Excel table size
539my ( $row_min, $row_max ) = $worksheet->row_range();
540my ( $col_min, $col_max ) = $worksheet->col_range();
541
542## Only for debugging
543##print "Sheet 'EnableDisableCAComb':\n";
544##print " row_min = $row_min, row_max = $row_max\n";
545##print " col_min = $col_min, col_max = $col_max\n";
546
547## Skip the title row
548$row_min++;
549
550for my $row ( $row_min .. $row_max )
551{
552 my $cell = $worksheet->get_cell( $row, $col_min );
553
554 if ($cell->value() =~ /([-]+)(.*)/)
555 {
556 ## Level 1: Continents, World Wide or Test Network
557 if ($1 eq "-")
558 {
559 print CABAND_TBL " /* ".$2." */\n";
560 }
561 ## Level 2: Orientation or subregion of Contienent
562 elsif ($1 eq "--")
563 {
564 print CABAND_TBL " /** ".$2." **/\n";
565 }
566 ## Level 3: Countries, Nations
567 elsif ($1 eq "---")
568 {
569 print CABAND_TBL " /*** ".$2." ***/\n";
570
571 my $cell = $worksheet->get_cell( $row, $col_min+1 );
572 my @mcclist = split(',', $cell->value());
573
574 for my $mcc (@mcclist)
575 {
576 my $cell = $worksheet->get_cell( $row, $col_min+2 );
577 my @mnclist = split(',', $cell->value());
578
579 for my $mnc (@mnclist)
580 {
581 if ($mcc eq "NULL") { $mcc = ""; }
582 if ($mnc eq "NULL") { $mnc = ""; }
583
584 print CABAND_TBL " {\"".$mcc.$mnc."\",";
585
586 ## Starting from Enable List, then Disable List
587 for my $col ($col_min+3 .. $col_max)
588 {
589 my $cell = $worksheet->get_cell( $row, $col );
590 if ($cell->value() eq "NULL")
591 {
592 printf CABAND_TBL "%30s", "\"\"";
593 }
594 else
595 {
596 my $ca_string = "\"".$cell->value()."\"";
597 printf CABAND_TBL "%30s", $ca_string;
598 }
599
600 print CABAND_TBL "," if ($col != $col_max);
601
602 print CABAND_TBL " },\n" if ($col == $col_max);
603 }
604 }
605 }
606 }
607 ## Level 4: Operators
608 elsif ($1 eq "----")
609 {
610 print CABAND_TBL " /**** ".$2." ****/\n";
611
612 my $cell = $worksheet->get_cell( $row, $col_min+1 );
613 my @mcclist = split(',', $cell->value());
614
615 for my $mcc (@mcclist)
616 {
617 my $cell = $worksheet->get_cell( $row, $col_min+2 );
618 my @mnclist = split(',', $cell->value());
619
620 for my $mnc (@mnclist)
621 {
622 if ($mcc eq "NULL") { $mcc = ""; }
623 if ($mnc eq "NULL") { $mnc = ""; }
624
625 print CABAND_TBL " {\"".$mcc.$mnc."\",";
626
627 ## Starting from Enable List, then Disable List
628 for my $col ($col_min+3 .. $col_max)
629 {
630 my $cell = $worksheet->get_cell( $row, $col );
631 if ($cell->value() eq "NULL")
632 {
633 printf CABAND_TBL "%30s", "\"\"";
634 }
635 else
636 {
637 my $ca_string = "\"".$cell->value()."\"";
638 printf CABAND_TBL "%30s", $ca_string;
639 }
640
641 print CABAND_TBL "," if ($col != $col_max);
642
643 print CABAND_TBL " },\n" if ($col == $col_max);
644 }
645 }
646 }
647 }
648 }
649 elsif ($cell->value() =~ /^\[UNIT_TEST/)
650 {
651 print CABAND_TBL "#ifdef UNIT_TEST\n";
652 }
653 elsif ($cell->value() =~ /^\]UNIT_TEST/)
654 {
655 print CABAND_TBL "#endif /* UNIT_TEST */\n";
656 }
657}
658
659print CABAND_TBL "};\n\n";
660
661print CABAND_TBL "const kal_uint32 eas_global_ca_comb_num = sizeof(eas_global_ca_comb_tbl) / sizeof(eas_global_ca_comb_struct);\n";
662print CABAND_TBL "#endif\n\n";
663
664## Success
665print "eas_caband_tbl_v2.c is generated successfully\n";