| use strict; |
| use Cwd; |
| use lib "tools/perl"; |
| use Text::CSV; |
| use File::Path; |
| |
| #redirect STDERR to STDOUT |
| open(STDERR, ">&STDOUT"); |
| |
| printf "perl current dir : %s\n", getcwd(); |
| my $mspm_body_path = "$ARGV[2]/modem/mspm/src"; |
| |
| mkpath($mspm_body_path) if(! -e $mspm_body_path); |
| print "mspm gen source dir : $mspm_body_path\n"; |
| |
| my $mspm_gen_body = "$mspm_body_path/mspm_procedure_gen_table.c"; |
| open (MSPM_BODY, "> $mspm_gen_body") or die "open file fail : $mspm_gen_body\n"; |
| |
| my $csv = Text::CSV->new ( { binary => 1 } ) or die "Cannot use CSV: ".Text::CSV->error_diag(); |
| my @rows; |
| my $csv_file_name = sprintf("%s/protocol/as_multimode/asinterfaces/mspm_proc_gen_tbl/mspm_procedure_table.csv", getcwd()); |
| |
| print "CSV table file path : $csv_file_name\n"; |
| |
| if (! -f $csv_file_name) |
| { |
| printf "%s Not Exist\n", $csv_file_name; |
| exit |
| } |
| open(my $fh, "<:encoding(UTF-8)", $csv_file_name) or die "$csv_file_name : $!"; |
| while (my $row = $csv->getline($fh)) |
| { |
| push @rows, $row; |
| } |
| $csv->eof or $csv->error_diag(); |
| close $fh; |
| |
| my $max_row = scalar @rows; |
| my $max_col; |
| foreach (@rows) |
| { |
| my @first_row = @$_; |
| $max_col = scalar @first_row; |
| last; |
| } |
| |
| my @mspm_procedure_attr_index; |
| my $mspm_procedure_priority_index = 0; |
| my $mspm_procedure_category_type_index = 0; |
| my $mspm_procedure_extend_end_session_timer_value_index = 0; |
| my $mspm_procedure_on_start_stop_extend_end_session_timer_event_index = 0; |
| my $mspm_procedure_on_end_stop_extend_end_session_timer_event_index = 0; |
| my $mspm_procedure_source_module_index = 0; |
| my $mspm_icd_procedure_type_index = 0; |
| my @mspm_procedure_on_start_to_stop_timer_size_list; |
| my @mspm_procedure_on_start_to_stop_timer_list; |
| my @mspm_procedure_on_end_to_stop_timer_size_list; |
| my @mspm_procedure_on_end_to_stop_timer_list; |
| my @mspm_procedure_not_start_ext_timer_if_proc_exist_size_list; |
| my @mspm_procedure_not_start_ext_timer_if_proc_exist_list; |
| my @mspm_procedure_not_start_ext_timer_if_proc_not_exist_size_list; |
| my @mspm_procedure_not_start_ext_timer_if_proc_not_exist_list; |
| |
| #mspm_procedure_attribute_enum |
| for (my $col=0; $col < $max_col; $col++) |
| { |
| if (index(uc $rows[0][$col], "MSPM_PROC_ATTR_") == 0) |
| { |
| push @mspm_procedure_attr_index, $col; |
| } |
| if ((uc $rows[0][$col]) eq "PRIORITY") |
| { |
| $mspm_procedure_priority_index = $col; |
| } |
| if ((uc $rows[0][$col]) eq "CATEGORY") |
| { |
| $mspm_procedure_category_type_index = $col; |
| } |
| if ((uc $rows[0][$col]) eq "OWNER MODULE") |
| { |
| $mspm_procedure_source_module_index = $col; |
| } |
| if (index(uc $rows[0][$col], "MSPM_PROC_EXTEND_END_SESSION_TIMER_VALUE") == 0) |
| { |
| $mspm_procedure_extend_end_session_timer_value_index = $col; |
| } |
| if (index(uc $rows[0][$col], "MSPM_PROC_ON_START_TO_STOP_EXTEND_TIMER") == 0) |
| { |
| $mspm_procedure_on_start_stop_extend_end_session_timer_event_index = $col; |
| } |
| if (index(uc $rows[0][$col], "MSPM_PROC_ON_END_TO_STOP_EXTEND_TIMER") == 0) |
| { |
| $mspm_procedure_on_end_stop_extend_end_session_timer_event_index = $col; |
| } |
| if ((uc $rows[0][$col]) eq "ICD_PROCEDURE_TYPE") |
| { |
| $mspm_icd_procedure_type_index = $col; |
| } |
| } |
| |
| #mspm_procedure_enum |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| $mspm_procedure_on_start_to_stop_timer_size_list[$row-1] = 0; |
| $mspm_procedure_on_end_to_stop_timer_size_list[$row-1] = 0; |
| $mspm_procedure_not_start_ext_timer_if_proc_exist_size_list[$row-1] = 0; |
| $mspm_procedure_not_start_ext_timer_if_proc_not_exist_size_list[$row-1] = 0; |
| } |
| |
| #mspm_procedure_priority_table |
| print MSPM_BODY "#include \"mspm_public_api.h\"\n"; |
| print MSPM_BODY "#include \"mspm_fsm.h\"\n\n"; |
| print MSPM_BODY "kal_uint8 mspm_procedure_priority_table[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| printf MSPM_BODY " %2d, //%s\n", $rows[$row][$mspm_procedure_priority_index], $rows[$row][0]; |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #mspm_procedure_setting_table |
| print MSPM_BODY "kal_bool mspm_procedure_setting_table[MSPM_PROCEDURE_ENUM_NUM][MSPM_PROC_ATTR_MAX_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| print MSPM_BODY " //{"; |
| |
| print MSPM_BODY "MSPM_PROC_ATTR_AS_CONNECTION, "; |
| print MSPM_BODY "MSPM_PROC_ATTR_C2K_AS_CONNECTION, "; |
| foreach(@mspm_procedure_attr_index) |
| { |
| print MSPM_BODY "$rows[0][$_], "; |
| } |
| print MSPM_BODY "}\n"; |
| |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| print MSPM_BODY " {"; |
| if ((uc $rows[$row][$mspm_procedure_category_type_index]) eq "AS CONNECTION") |
| { |
| printf MSPM_BODY "%9s, ", "KAL_TRUE"; |
| } |
| else |
| { |
| printf MSPM_BODY "%9s, ", "KAL_FALSE"; |
| } |
| if ((uc $rows[$row][$mspm_procedure_category_type_index]) eq "C2K AS CONNECTION") |
| { |
| printf MSPM_BODY "%9s, ", "KAL_TRUE"; |
| } |
| else |
| { |
| printf MSPM_BODY "%9s, ", "KAL_FALSE"; |
| } |
| foreach(@mspm_procedure_attr_index) |
| { |
| if ((uc $rows[$row][$_]) eq "Y") |
| { |
| printf MSPM_BODY "%9s, ", "KAL_TRUE"; |
| } |
| else |
| { |
| printf MSPM_BODY "%9s, ", "KAL_FALSE"; |
| } |
| } |
| printf MSPM_BODY "}, //%s\n", $rows[$row][0]; |
| |
| my $mspm_on_start_string = (uc $rows[$row][$mspm_procedure_on_start_stop_extend_end_session_timer_event_index]); |
| while($mspm_on_start_string =~ /(\w+)/g) |
| { |
| my $mspm_on_start_proc = $1; |
| for (my $mspm_proc_index=1; $mspm_proc_index<$max_row-1; $mspm_proc_index++) |
| { |
| if ((uc $rows[$mspm_proc_index][0]) eq $mspm_on_start_proc) |
| { |
| $mspm_procedure_on_start_to_stop_timer_list[$mspm_proc_index-1][$mspm_procedure_on_start_to_stop_timer_size_list[$mspm_proc_index-1]] = $rows[$row][0]; |
| $mspm_procedure_on_start_to_stop_timer_size_list[$mspm_proc_index-1] += 1; |
| |
| $mspm_procedure_not_start_ext_timer_if_proc_exist_list[$row-1][$mspm_procedure_not_start_ext_timer_if_proc_exist_size_list[$row-1]] = $mspm_on_start_proc; |
| $mspm_procedure_not_start_ext_timer_if_proc_exist_size_list[$row-1] += 1; |
| } |
| } |
| } |
| |
| my $mspm_on_end_string = (uc $rows[$row][$mspm_procedure_on_end_stop_extend_end_session_timer_event_index]); |
| while($mspm_on_end_string =~ /(\w+)/g) |
| { |
| my $mspm_on_end_proc = $1; |
| for (my $mspm_proc_index=1; $mspm_proc_index<$max_row-1; $mspm_proc_index++) |
| { |
| if ((uc $rows[$mspm_proc_index][0]) eq $mspm_on_end_proc) |
| { |
| $mspm_procedure_on_end_to_stop_timer_list[$mspm_proc_index-1][$mspm_procedure_on_end_to_stop_timer_size_list[$mspm_proc_index-1]] = $rows[$row][0]; |
| $mspm_procedure_on_end_to_stop_timer_size_list[$mspm_proc_index-1] += 1; |
| |
| $mspm_procedure_not_start_ext_timer_if_proc_not_exist_list[$row-1][$mspm_procedure_not_start_ext_timer_if_proc_not_exist_size_list[$row-1]] = $mspm_on_end_proc; |
| $mspm_procedure_not_start_ext_timer_if_proc_not_exist_size_list[$row-1] += 1; |
| } |
| } |
| } |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #mspm_procedure_string_table |
| print MSPM_BODY "char* mspm_procedure_string_table[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| print MSPM_BODY " \"$rows[$row][0]\", \n"; |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #mspm_procedure_extend_end_session_timer_value_table |
| print MSPM_BODY "kal_uint32 mspm_procedure_extend_end_session_timer_value_table[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| printf MSPM_BODY " %5d, //%s\n", $rows[$row][$mspm_procedure_extend_end_session_timer_value_index], $rows[$row][0]; |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #mspm_procedure_on_start_to_stop_extend_timer_event_list_size_table |
| print MSPM_BODY "kal_uint8 mspm_procedure_on_start_to_stop_extend_timer_event_list_size_table[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| printf MSPM_BODY " %2d, //%s\n", $mspm_procedure_on_start_to_stop_timer_size_list[$row-1], $rows[$row][0]; |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #element of mspm_procedure_on_start_to_stop_extend_timer_event_list_table |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| if ($mspm_procedure_on_start_to_stop_timer_size_list[$row-1] > 0) |
| { |
| printf MSPM_BODY "static mspm_procedure_enum mspm_on_start_list_element_%s[] =\n", $rows[$row][0]; |
| print MSPM_BODY " {"; |
| for(my $j=0; $j<$mspm_procedure_on_start_to_stop_timer_size_list[$row-1]; $j++) |
| { |
| printf MSPM_BODY "%s, ", $mspm_procedure_on_start_to_stop_timer_list[$row-1][$j]; |
| } |
| print MSPM_BODY "};\n\n"; |
| } |
| } |
| |
| #mspm_procedure_on_start_to_stop_extend_timer_event_list_table |
| print MSPM_BODY "mspm_procedure_enum* mspm_procedure_on_start_to_stop_extend_timer_event_list_table[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for(my $i=0; $i<$max_row-2; $i++) |
| { |
| if ($mspm_procedure_on_start_to_stop_timer_size_list[$i] == 0) |
| { |
| printf MSPM_BODY " NULL, //%s\n", $rows[$i+1][0]; |
| } |
| else |
| { |
| printf MSPM_BODY " mspm_on_start_list_element_%s, //%s\n", $rows[$i+1][0], $rows[$i+1][0]; |
| } |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #mspm_procedure_on_end_to_stop_extend_timer_event_list_size_table |
| print MSPM_BODY "kal_uint8 mspm_procedure_on_end_to_stop_extend_timer_event_list_size_table[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| printf MSPM_BODY " %2d, //%s\n", $mspm_procedure_on_end_to_stop_timer_size_list[$row-1], $rows[$row][0]; |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #element of mspm_procedure_on_end_to_stop_extend_timer_event_list_table |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| if ($mspm_procedure_on_end_to_stop_timer_size_list[$row-1] > 0) |
| { |
| printf MSPM_BODY "static mspm_procedure_enum mspm_on_end_list_element_%s[] =\n", $rows[$row][0]; |
| print MSPM_BODY " {"; |
| for(my $j=0; $j<$mspm_procedure_on_end_to_stop_timer_size_list[$row-1]; $j++) |
| { |
| printf MSPM_BODY "%s, ", $mspm_procedure_on_end_to_stop_timer_list[$row-1][$j]; |
| } |
| print MSPM_BODY "};\n\n"; |
| } |
| } |
| |
| #mspm_procedure_on_end_to_stop_extend_timer_event_list_table |
| print MSPM_BODY "mspm_procedure_enum* mspm_procedure_on_end_to_stop_extend_timer_event_list_table[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for(my $i=0; $i<$max_row-2; $i++) |
| { |
| if ($mspm_procedure_on_end_to_stop_timer_size_list[$i] == 0) |
| { |
| printf MSPM_BODY " NULL, //%s\n", $rows[$i+1][0]; |
| } |
| else |
| { |
| printf MSPM_BODY " mspm_on_end_list_element_%s, //%s\n", $rows[$i+1][0], $rows[$i+1][0]; |
| } |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #mspm_procedure_not_start_extend_timer_if_proc_exist_list_size_table |
| print MSPM_BODY "kal_uint8 mspm_procedure_not_start_extend_timer_if_proc_exist_list_size_table[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| printf MSPM_BODY " %2d, //%s\n", $mspm_procedure_not_start_ext_timer_if_proc_exist_size_list[$row-1], $rows[$row][0]; |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #element of mspm_procedure_not_start_extend_timer_if_proc_exist_list_table |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| if ($mspm_procedure_not_start_ext_timer_if_proc_exist_size_list[$row-1] > 0) |
| { |
| printf MSPM_BODY "static mspm_procedure_enum mspm_not_start_ext_timer_if_proc_exist_element_%s[] =\n", $rows[$row][0]; |
| print MSPM_BODY " {"; |
| for(my $j=0; $j<$mspm_procedure_not_start_ext_timer_if_proc_exist_size_list[$row-1]; $j++) |
| { |
| printf MSPM_BODY "%s, ", $mspm_procedure_not_start_ext_timer_if_proc_exist_list[$row-1][$j]; |
| } |
| print MSPM_BODY "};\n\n"; |
| } |
| } |
| |
| #mspm_procedure_not_start_extend_timer_if_proc_exist_list_table |
| print MSPM_BODY "mspm_procedure_enum* mspm_procedure_not_start_extend_timer_if_proc_exist_list_table[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for(my $i=0; $i<$max_row-2; $i++) |
| { |
| if ($mspm_procedure_not_start_ext_timer_if_proc_exist_size_list[$i] == 0) |
| { |
| printf MSPM_BODY " NULL, //%s\n", $rows[$i+1][0]; |
| } |
| else |
| { |
| printf MSPM_BODY " mspm_not_start_ext_timer_if_proc_exist_element_%s, //%s\n", $rows[$i+1][0], $rows[$i+1][0]; |
| } |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #mspm_procedure_not_start_extend_timer_if_proc_not_exist_list_size_table |
| print MSPM_BODY "kal_uint8 mspm_procedure_not_start_extend_timer_if_proc_not_exist_list_size_table[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| printf MSPM_BODY " %2d, //%s\n", $mspm_procedure_not_start_ext_timer_if_proc_not_exist_size_list[$row-1], $rows[$row][0]; |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #element of mspm_procedure_not_start_extend_timer_if_proc_not_exist_list_table |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| if ($mspm_procedure_not_start_ext_timer_if_proc_not_exist_size_list[$row-1] > 0) |
| { |
| printf MSPM_BODY "static mspm_procedure_enum mspm_not_start_ext_timer_if_proc_not_exist_element_%s[] =\n", $rows[$row][0]; |
| print MSPM_BODY " {"; |
| for(my $j=0; $j<$mspm_procedure_not_start_ext_timer_if_proc_not_exist_size_list[$row-1]; $j++) |
| { |
| printf MSPM_BODY "%s, ", $mspm_procedure_not_start_ext_timer_if_proc_not_exist_list[$row-1][$j]; |
| } |
| print MSPM_BODY "};\n\n"; |
| } |
| } |
| |
| #mspm_procedure_not_start_extend_timer_if_proc_not_exist_list_table |
| print MSPM_BODY "mspm_procedure_enum* mspm_procedure_not_start_extend_timer_if_proc_not_exist_list_table[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for(my $i=0; $i<$max_row-2; $i++) |
| { |
| if ($mspm_procedure_not_start_ext_timer_if_proc_not_exist_size_list[$i] == 0) |
| { |
| printf MSPM_BODY " NULL, //%s\n", $rows[$i+1][0]; |
| } |
| else |
| { |
| printf MSPM_BODY " mspm_not_start_ext_timer_if_proc_not_exist_element_%s, //%s\n", $rows[$i+1][0], $rows[$i+1][0]; |
| } |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #mspm_source_module_list_table |
| print MSPM_BODY "kal_char* mspm_source_module_list_table[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| print MSPM_BODY " \"$rows[$row][$mspm_procedure_source_module_index]\", \n"; |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #mspm_procedure_type_table |
| print MSPM_BODY "mspm_procedure_type_enum mspm_procedure_type_table[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| if (index($rows[$row][$mspm_procedure_category_type_index], 'C2K') == -1) |
| { |
| printf MSPM_BODY " MSPM_PROCEDURE_TYPE_NON_C2K, //%s\n", $rows[$row][0]; |
| } |
| else |
| { |
| printf MSPM_BODY " MSPM_PROCEDURE_TYPE_C2K, //%s\n", $rows[$row][0]; |
| } |
| } |
| print MSPM_BODY "};\n\n"; |
| |
| #mspm_icd_procedure_type |
| print MSPM_BODY "#ifdef __ICD_LOGGING_SUPPORT__\n"; |
| print MSPM_BODY "mspm_icd_proc_enum mspm_icd_procedure_type[MSPM_PROCEDURE_ENUM_NUM] =\n"; |
| print MSPM_BODY "{\n"; |
| for (my $row = 1; $row < $max_row-1; $row++) |
| { |
| printf MSPM_BODY " %s, //%s\n", $rows[$row][$mspm_icd_procedure_type_index], $rows[$row][0]; |
| } |
| print MSPM_BODY "};\n"; |
| print MSPM_BODY "#endif /* __ICD_LOGGING_SUPPORT__ */\n\n"; |
| |
| #close file |
| close MSPM_BODY or warn "Error closing MSPM Body"; |
| close MSPM_CUSTOM or warn "Error closing MSPM Custom"; |
| |
| |
| |
| |
| |
| |
| |