AmbSignalMaper: Implement dbc2amb
authorPetr Nechaev <petr.nechaev@cogentembedded.com>
Thu, 5 Mar 2015 16:09:52 +0000 (19:09 +0300)
committerPetr Nechaev <petr.nechaev@cogentembedded.com>
Mon, 30 Mar 2015 11:25:19 +0000 (14:25 +0300)
Adds a "Direct Workflow" for generating CAN plugin from *.dbc file without
intermediate *.json file. dbc2amb selects signals from *.dbc file according to a pre-defined *.msg file which doesn't change when *.dbc file changes. This avoids repeating manual steps on *.json file.

May be useful at very early and late stages of vehicle software development, when there are many changes (cosmetic or other)  to *.dbc files.

TODO list:
* implement "mixing" of multiple *.dbc files into one plugin
* allow manual specification of message composition in *.msg file
* implement handling of SEND in addition to RECEIVE

tools/AmbSignalMapper/Makefile.PL
tools/AmbSignalMapper/README
tools/AmbSignalMapper/bin/dbc2amb [new file with mode: 0755]
tools/AmbSignalMapper/bin/json2amb
tools/AmbSignalMapper/lib/Intel/IviPoc/AmbPluginGenerator.pm
tools/AmbSignalMapper/lib/Intel/IviPoc/DbcGrammar
tools/AmbSignalMapper/lib/Intel/IviPoc/MsgGrammar [new file with mode: 0644]
tools/AmbSignalMapper/lib/Intel/IviPoc/templates/CMakeLists.txt
tools/AmbSignalMapper/lib/Intel/IviPoc/templates/ambtmpl.in.json [new file with mode: 0644]
tools/AmbSignalMapper/t/syntax.msg [new file with mode: 0644]

index bae450e..b2b5952 100644 (file)
@@ -33,7 +33,7 @@ WriteMakefile(
                'Digest::SHA1'=>0,
                #'Config::General'=>0,
        },
-       EXE_FILES => [ 'bin/dbc2json','bin/json2amb'],
+       EXE_FILES => [ 'bin/dbc2json','bin/json2amb', 'bin/dbc2amb' ],
        dist  => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
        clean => { FILES => 'AmbSignalMapper-*' },
 );
@@ -54,10 +54,11 @@ sub MY::postamble {
 # Compile the RecDescent grammar during make; 
 sub compile_DbcGrammar {
        push(@EXCLUSIONS,'blib/lib/Intel/IviPoc/DbcGrammar');
+       push(@EXCLUSIONS,'blib/lib/Intel/IviPoc/MsgGrammar');
        $MORE_MAKERULES .= <<'MakeGrammar';
 
 # Precompile the (Recursive Descent) DbcGrammar
-pure_all :: $(INST_LIBDIR)/Intel/IviPoc/DbcGrammar.pm
+pure_all :: $(INST_LIBDIR)/Intel/IviPoc/DbcGrammar.pm $(INST_LIBDIR)/Intel/IviPoc/MsgGrammar.pm
 
 $(INST_LIBDIR)/Intel/IviPoc/DbcGrammar.pm: lib/Intel/IviPoc/DbcGrammar
        $(PERLRUN) -MParse::RecDescent - lib/Intel/IviPoc/DbcGrammar Intel::IviPoc::DbcGrammar
@@ -66,6 +67,12 @@ $(INST_LIBDIR)/Intel/IviPoc/DbcGrammar.pm: lib/Intel/IviPoc/DbcGrammar
        $(CHMOD) $(PERM_RWX) bin/dbc2json
        $(CHMOD) $(PERM_RWX) bin/json2amb
 
+$(INST_LIBDIR)/Intel/IviPoc/MsgGrammar.pm: lib/Intel/IviPoc/MsgGrammar
+       $(PERLRUN) -MParse::RecDescent - lib/Intel/IviPoc/MsgGrammar Intel::IviPoc::MsgGrammar
+       $(NOECHO) $(MKPATH) $(INST_LIBDIR)/Intel/IviPoc
+       $(MV) -f MsgGrammar.pm blib/lib/Intel/IviPoc/MsgGrammar.pm
+       $(CHMOD) $(PERM_RWX) bin/dbc2amb
+
 MakeGrammar
 }
 
index 42907f5..af5de91 100644 (file)
@@ -1,8 +1,14 @@
 AmbSignalMapper
+===============
 
 ABSTRACT:
 
 The AmbSignalMapper tool serves basic utilities for AMB signal mapping process.
+Two workflows exist: a classic workflow with an intermediate file and a "direct"
+workflow with an *.msg file.
+
+Classic Workflow
+----------------
 It should take place in three steps:
 
 1. Vector CANdb++ conversion into intermediate file (First phase)
@@ -13,6 +19,27 @@ The First phase is achieved by software utolity called dbc2json.
 The second phase needs to be done by humans manually.
 The third phase is again covered by software utolity called json2amb. 
 
+Direct Workflow
+---------------
+This workflow is designed for generation of production code. It consists of three steps:
+1. Obtain a *.dbc file
+2. Prepare a special *.msg message definition file
+3. Generate AMB plugin by running
+       dbc2amb I<dbc file> I<msg file> I<outdir> I<plugin name>
+
+*.msg file contains message definitions marked by the keyword B<RECEIVE>. Messages can be
+selected by name "Message1" or by id with b<@> prefix "@141". An asterisk can be specified
+instead of the list of signals to select all signals. 
+
+       RECEIVE Message1 {
+               Signal1
+       }
+
+       RECEIVE Message2.Signal2;
+
+       RECEIVE @141.*;
+
+
 PREREQUISITES:
 
 Perl version 5.006 or higher.
@@ -56,6 +83,8 @@ perldoc command.
     
     perldoc json2amb   
 
+    perldoc dbc2amb
+
 LICENSE AND COPYRIGHT
 
 Copyright (C) 2014  Intel Corporation
diff --git a/tools/AmbSignalMapper/bin/dbc2amb b/tools/AmbSignalMapper/bin/dbc2amb
new file mode 100755 (executable)
index 0000000..acc5aad
--- /dev/null
@@ -0,0 +1,288 @@
+#!/usr/bin/perl -w
+
+#      Copyright (C) 2014  Intel Corporation
+#   Copyright (c) 2015  Cogent Embedded Inc.
+#   
+#      This library is free software; you can redistribute it and/or
+#      modify it under the terms of the GNU Lesser General Public
+#      License as published by the Free Software Foundation; either
+#      version 2.1 of the License, or (at your option) any later version.
+#
+#      This library is distributed in the hope that it will be useful,
+#      but WITHOUT ANY WARRANTY; without even the implied warranty of
+#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#      Lesser General Public License for more details.
+#
+#      You should have received a copy of the GNU Lesser General Public
+#      License along with this library; if not, write to the Free Software
+#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+use strict;
+use warnings;
+
+use warnings FATAL => 'all';
+
+use Intel::IviPoc::DbcGrammar;
+use Intel::IviPoc::MsgGrammar;
+use Intel::IviPoc::AmbCommon;
+use Intel::IviPoc::AmbPluginGenerator qw(processPlugin);
+use File::Basename;
+use File::Spec;
+use Cwd;
+use Data::Dumper;
+
+=head1 NAME
+
+dbc2amb - Vector CANdb++ to Automotive Message Broker plugin generator.
+
+=head1 SYNOPSIS
+
+B<dbc2amb> I<dbc file> I<msg file> [ I<outdir> [I<plugin name>] ] 
+
+=head1 DESCRIPTION
+
+Part of Automotive Message Broker Signal Mapper tool.
+
+B<dbc2amb> converts file in Vector CANdb++ format to Automotive Message Broker plugin.
+
+=head1 OPTIONS
+
+=over 4
+
+=item I<dbc file>
+
+Input I<dbc file> file in Vector CANdb++ (*.dbc) format.
+
+"-" (without quotes) can be specified instead of I<dbc file> to omit *.dbc file.
+
+=item I<msg file>
+
+Input I<msg file> file with message definitions.
+
+=item [ I<outdir> ]
+
+This parameter is optional. Target directory where the plugin is generated to.
+Otherwise current directory.
+
+=item [ I<plugin name> ]
+
+Machine- and user- readable name of the plugin. Plugin code will be exported to 
+B<I<outdir>>/BI<plugin name>_plugin> directory
+
+=back
+
+=head1 FILES
+
+=over 4
+
+=back
+
+=head1 REQUIRES
+
+Perl 5.006, Intel::IviPoc::DbcGrammar, Intel::IviPoc::MsgGrammar, Intel::IviPoc::AmbPluginGenerator, Intel::IviPoc::AmbCommon, File::Basename, File::Spec, Cwd
+
+=head1 SEE ALSO
+
+perl(1), amb2json(1), json2amb(1)
+
+=cut
+
+local $/;
+
+# get total arg passed to this script
+my $total = $#ARGV + 1;
+
+if ( $total < 2 or $total > 4) {
+    # get script name and print usage
+    my $scriptname = $0;
+    &printUsage($scriptname);
+    exit;
+    }
+
+# First parameter is input dbc filename
+my $dbc_inputfilename = $ARGV[0];
+my $dbc_text;
+if ($dbc_inputfilename eq '-') {
+       # use dummy *.dbc file if '-' is specified on command line
+       $dbc_text = "VERSION \"\" \n\n\nNS_ :  \n\n\nEMPTY  \nBS_:  \nBU_: \n ";
+}
+else {
+       $dbc_text = &readFileContent($dbc_inputfilename);
+}
+
+# Second parameter is input msg filename
+my $msg_inputfilename = $ARGV[1];
+my $msg_text = &readFileContent($msg_inputfilename);
+
+# Third optional parameter is output file
+my $targetDir = ();
+if ( $total <= 2 ) {
+       $targetDir = getcwd;
+} else {
+    $targetDir = Cwd::abs_path($ARGV[2]);
+}
+
+# Fourth optional parameter is plugin name
+my $pluginname;
+if ( $total <= 2 ) {
+       my ($infilename, $indirectories, $insuffix) = fileparse($dbc_inputfilename, qr/\.[^.]*/);
+       $pluginname = $infilename;
+} else {
+    $pluginname = $ARGV[3];
+}
+
+# We add one space to dbc file if there is something like  ""ReceiverId to get "" ReceiverId
+$dbc_text =~ s/"(.*)"(\w*)/"$1" $2/g;
+
+#Create parsers
+my $dbc_parser = new Intel::IviPoc::DbcGrammar;
+my $msg_parser = new Intel::IviPoc::MsgGrammar;
+
+# Print wait info for user
+&printWait($dbc_inputfilename, $msg_inputfilename, $targetDir);
+
+# Parse input files
+my $dbc_result;
+$dbc_result = $dbc_parser->DbcOutput($dbc_text);
+my $msg_result;
+$msg_result = $msg_parser->MsgOutput($msg_text);
+# print Dumper $msg_result;  #TODO: Remove debug print
+
+# Generate the plugin
+my $selected_signals = selectSignals($dbc_result, $msg_result, "CAN");
+$selected_signals->{'pluginName'} = $pluginname;
+#print Dumper $selected_signals; #TODO: remove this after debugging is complete
+my $hashingAllowed = 'D';
+
+processPlugin ( $hashingAllowed, $selected_signals, $targetDir );
+
+print "Plugin is generated in '$targetDir'.\n";
+
+# Finnish
+exit;
+
+
+=head2 selectSignals
+
+Select signals for implementing in an AMB plugin.
+
+=cut
+
+sub selectSignals {
+    my %dbc_root = %{$_[0]};
+    my %msg_root = %{$_[1]};
+       my $plugin_name = $_[2];
+
+       my @electronicControlUnits = ();
+       keys $msg_root{'receive'};
+       while( my($msg_id, $signals) = each $msg_root{'receive'}) {
+        
+
+               for my $ecu (@{$dbc_root{'electronicControlUnits'}}) {
+                       my %add_ecu = ();                       
+
+                       for my $message (@{$ecu->{'messages'}}) {
+                               if ((lc $msg_id eq lc $message->{'canName'}) or ($msg_id eq $message->{'canId'})) {
+                                       # selected valid message, add its common properties
+                                       my %msg_copy = %{$message};
+
+                                       if (!(exists $signals->{'*'})) {
+                                               delete $msg_copy{'signals'};
+
+                                               for my $signal (@{$message->{'signals'}}) {
+                                                       if (exists $signals->{$signal->{'canId'}}) {
+                                                               push(@{$msg_copy{'signals'}}, $signal);
+                                                       }
+                                               }
+                                       }
+
+                                       # add message only if not empty
+                                       if (exists $msg_copy{'signals'}) {
+                                               push(@{$add_ecu{'messages'}}, \%msg_copy);
+                                       }
+                               }
+                       }
+
+                       # add signals to the reference
+                       if (%add_ecu){
+                               push(@electronicControlUnits, \%add_ecu);
+                       }
+               }
+       }
+
+       my %jsonroot = ();
+    $jsonroot{'pluginName'} = "pluginName";
+    $jsonroot{'electronicControlUnits'} = \@electronicControlUnits;
+
+       return \%jsonroot;
+}
+
+=head2 printWait
+
+Prints out wait information
+
+=cut
+
+sub printWait {
+    print STDERR ("\n");
+    print STDERR ("Processing input dbc file:\n");
+    print STDERR ("    $_[0]\n");
+    print STDERR ("Processing input msg file:\n");
+    print STDERR ("    $_[1]\n");
+    print STDERR ("Generating output files is in:\n");
+    print STDERR ("    $_[2]\n");
+    print STDERR ("\n");
+    print STDERR ("This operation may take some while. Please wait...\n");
+}
+
+=head2 printUsage
+
+Prints out basic usage help
+
+=cut
+
+sub printUsage {
+    my $scriptname=$_[0];
+    print STDERR ("$scriptname\n");
+    print STDERR ("Usage: dbc2amb in_dbc_file in_msg_file [outdir [plugin_name]]\n");
+    print STDERR ("  in_dbc_file              Input dbc file. Specify '-' to skip.\n");
+    print STDERR ("  in_msg_file              Input msg file\n");
+    print STDERR ("  outdir                   Target plugin directory (optional) generated to,\n");
+    print STDERR ("                            otherwise current directory.\n");
+    print STDERR ("  plugin_name              Machine-readable name of the plugin\n");
+    print STDERR ("\n");
+}
+
+=head1 AUTHOR
+
+IntelIVIPoc, C<< <ivipoc at intel.com> >>
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+    perldoc dbc2amb
+
+=head1 ACKNOWLEDGEMENTS
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright (C) 2014  Intel Corporation
+
+Copyright (C) 2015  Cogent Embedded, Inc.
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+=cut
index 7e39e98..f2b4718 100755 (executable)
@@ -107,8 +107,17 @@ if ($total == 2) {
     $targetDir = Cwd::abs_path($ARGV[2]);
 }
 
+# Load the json
+my $json_text = &readFileContent( $ARGV[1] );
+
+my $json = JSON->new;
+$json = $json->utf8;
+
+my $dbcjson = $json->decode( $json_text );
+
+
 # Generate the plaugin
-processPlugin ( $hashingAllowed, $ARGV[1], $targetDir );
+processPlugin ( $hashingAllowed, $dbcjson, $targetDir );
 
 # Finnish
 exit;
index 4c60309..7524509 100644 (file)
@@ -84,16 +84,9 @@ my $hashingAllowed = 'E';       # Enabled by default
 
 sub processPlugin {
        $hashingAllowed = $_[0];
-       my $jsonfile = $_[1];
+       my $dbcjson = $_[1];
        my $targetDir = $_[2];
-
-       # Load the json
-       my $json_text = &readFileContent( $jsonfile );
-
-       my $json = JSON->new;
-       $json = $json->utf8;
-
-       my $dbcjson = $json->decode( $json_text );
+       
        if ($hashingAllowed eq 'E' ) {
                &encryptAmbPropertyNames( $dbcjson );
        }
@@ -113,6 +106,7 @@ sub processPlugin {
                                                 , "ambtmpl_plugin.cpp"
                                                 , "ambtmpl_cansignals.h"
                                                 , "ambtmpl_plugin.idl"
+                                                , "ambtmpl.in.json"
                                                 );
 
        my @pluginFiles = ( "CMakeLists.txt"
@@ -122,6 +116,7 @@ sub processPlugin {
                                          , lc ($pluginName) . "_plugin.cpp"
                                          , lc ($pluginName) . "_cansignals.h"
                                          , lc ($pluginName) . "_plugin.idl"
+                                         , lc ($pluginName) . ".in.json"
                                          );
 
        my @generationSubs = ( undef
@@ -131,6 +126,7 @@ sub processPlugin {
                                                 , \&generateCppImplTypes
                                                 , \&generateSignalsTypes
                                                 , \&generateIdlTypes
+                                                , undef
                                                 );
 
        my $templateFile = '';
@@ -483,7 +479,7 @@ sub generatePropertyClasses {
                $cppType = "$type";
        }
 
-        $typeBasedText .= "CANSIGNAL($ambPropertyName, $cppType, $signal->{'startBit'}, $signal->{'length'}, $byteOrdering, $signedness, $signal->{'factor'}, $signal->{'offset'}, static_cast<$cppType>($signal->{'minValue'}), static_cast<$cppType>($signal->{'maxValue'}), $convertFromFunction, $convertToFunction)\n";
+       $typeBasedText .= "CANSIGNAL($ambPropertyName, $cppType, $signal->{'startBit'}, $signal->{'length'}, $byteOrdering, $signedness, $signal->{'factor'}, $signal->{'offset'}, static_cast<$cppType>($signal->{'minValue'}), static_cast<$cppType>($signal->{'maxValue'}), $convertFromFunction, $convertToFunction)\n";
 
        $generatedText .= " */\n";
        my $shownPropertyName = $ambPropertyName;
index 80e6164..5e16d34 100644 (file)
@@ -1,4 +1,5 @@
 #Copyright (C) 2014  Intel Corporation
+#Copyright (c) 2015  Cogent Embedded Inc.
 #
 #This library is free software; you can redistribute it and/or
 #modify it under the terms of the GNU Lesser General Public
     my @ecuList = ();
     my %ecuMessages = ();
     my %ecuValues = ();
+    my %enumValues = ();
+    my %messageSenders = ();
+    my $fileComment = '';
+    my %ecuComments = ();
+    my %messageComments = ();
+    my %signalComments = ();
 }
 
 DbcOutput: Line(s?) eofile
@@ -75,32 +82,90 @@ Line: CommentPrefix /.*\n/
         # Not needed to output anything yet
     | 'VERSION' DoubleQuotedId
         # Not needed to output anything yet
+        # Version can be empty like this ""
     | 'NS_' ':' NSList(s?) ...'BS_'
+        # this tag holds a list of "new symbols" for the file
+        # Not needed to output anything
+    | 'BS_' ':'
+        # This tag holds definition of bit timings, obsolete
+        # Not need to output anything
+    | 'BU_' ':' <skip:'[ \t]*'> Identifier(s?)
         {
-            # We just read the list of NSs
-            @networks = @{$item[3]};
+           # This tag holds the list of ECUs in one line
+            @ecuList = @{$item[4]};
         }
-    | 'BS_' /.*\n/
-        # Not needed to output anything yet
-    | 'BU_' ':' EcuList(s?) ...'BO_'
-        {
-            @ecuList = @{$item[3]};
-        }
-    | 'BO_' Number Identifier ':' Identifier Identifier Signal(s?)
+    | 'BO_' Integer Identifier ':' Identifier Identifier Signal(s?)
         {
             my %msg = ();
             $msg{'canId'} = $item[2];
             $msg{'canName'} = $item[3];
             $msg{'canDlc'} = $item[5];
-            $msg{'canMessageId'} = $item[6];
+            $msg{'canEcuId'} = $item[6];
             $msg{'signals'} = $item[7];
 
             push ( @{$ecuMessages{$item[6]}}, \%msg );
         }
     | 'VAL_' Number Identifier ValuePair(s?) ';'
         {
+           # This tag holds enums defined for specific messages
             ${$ecuValues{$item[2]}->{$item[3]}} = $item[4];
         }
+    | 'VAL_TABLE_' Identifier ValuePair(s?) ';'
+        {
+           # This tag holds predefined enumerations
+            ${$enumValues{$item[2]}} = $item[3];
+        }
+    | 'BO_TX_BU_' Number ':' Receiver(s /,/) ';'
+       {
+           # This tag defines message senders
+           @{$messageSenders{$item[2]}} = $item[4];
+       }
+    | 'CM_' DoubleQuotedId ';'
+       {
+           # This tag is a comment for the whole file
+           $fileComment = $item[2];
+       }
+    | 'CM_' 'BU_' Identifier DoubleQuotedId ';'
+       {
+           # This tag is a comment for an ECU
+           ${$ecuComments{$item[3]}} = $item[4];
+       }
+    | 'CM_' 'BO_' Identifier DoubleQuotedId ';'
+       {
+           # This tag is a comment for a message
+           ${$messageComments{$item[3]}} = $item[4];
+       }
+    | 'CM_' 'SG_' Number Identifier DoubleQuotedId ';'
+       {
+           # This tag is a comment for a signal
+           ${$signalComments{$item[3]}->{$item[4]}} = $item[5];
+       }
+    | 'BA_' /.*;/
+           # This tag is an attribute definition
+           # Not needed to output anything yet
+    | 'BA_DEF_' /.*;/
+           # This tag is an attribute definition
+           # Not needed to output anything yet
+    | 'BA_DEF_DEF_' /.*;/
+           # This tag is an attribute definition
+           # Not needed to output anything yet
+    | 'BA_REL_' /.*;/
+           # This tag is an attribute definition
+           # Not needed to output anything yet
+    | 'BA_DEF_REL_' /.*;/
+           # This tag is an attribute definition
+           # Not needed to output anything yet
+    | 'BA_DEF_DEF_REL_' /.*;/
+           # This tag is an attribute definition
+           # Not needed to output anything yet
+    | 'BA_SGTYPE_' /.*;/
+           # This tag is an attribute definition
+           # Not needed to output anything yet
+    | 'BA_DEF_SGTYPE_' /.*;/
+           # This tag is an attribute definition
+           # Not needed to output anything yet
+    | 'SIG_GROUP_' Number Identifier Number ':' Identifier(s) ';'
+           # This tag is a signal group definition
     | <error: Invalid dbc format at $thisline!>
 
 Signal: 'SG_' Identifier ':' DataPlacement FactorOffset Range DoubleQuotedId Receiver(s /,/)
@@ -109,7 +174,7 @@ Signal: 'SG_' Identifier ':' DataPlacement FactorOffset Range DoubleQuotedId Rec
             $signal{'canId'} = $item[2];
 
             my %placement = %{$item[4]};
-            $signal{'startbit'} = $placement{'startbit'};
+            $signal{'startBit'} = $placement{'startbit'};
             $signal{'length'} = $placement{'length'};
             $signal{'byteOrdering'} = $placement{'byteOrdering'};
             $signal{'signedness'} = $placement{'signedness'};
@@ -133,11 +198,6 @@ Signal: 'SG_' Identifier ':' DataPlacement FactorOffset Range DoubleQuotedId Rec
             $return=\%signal;
         }
 
-EcuList: ...!'BO_' Identifier
-        {
-            $return = $item[2];
-        }
-
 NSList: ...!'BS_' Identifier
         {
             $return = $item[2];
@@ -209,10 +269,13 @@ Identifier: /[A-Za-z0-9_\-]+/
             $return = $item[1];
         }
 
-Number: /[-+]?[0-9]*/
+Number: Integer | RealNumber | Sign
+
+Integer: /[-+]?[0-9]*/
 RealNumber: /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/
 Sign: /^[-+]?/
 
 CommentPrefix: /^\/\//
 
 DoubleQuotation: "\""
+
diff --git a/tools/AmbSignalMapper/lib/Intel/IviPoc/MsgGrammar b/tools/AmbSignalMapper/lib/Intel/IviPoc/MsgGrammar
new file mode 100644 (file)
index 0000000..8ecadf2
--- /dev/null
@@ -0,0 +1,100 @@
+#Copyright (c) 2015  Cogent Embedded Inc.
+#
+#This library is free software; you can redistribute it and/or
+#modify it under the terms of the GNU Lesser General Public
+#License as published by the Free Software Foundation; either
+#version 2.1 of the License, or (at your option) any later version.
+#
+#This library is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#Lesser General Public License for more details.
+#
+#You should have received a copy of the GNU Lesser General Public
+#License along with this library; if not, write to the Free Software
+#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+{
+    my @receive = ();
+    my @send = ();
+}
+
+MsgOutput: Line(s?) eofile
+    {
+       my %rcv_msg = ();
+       my %send_msg = ();
+
+       for my $msg (@receive) {
+           my %m = %{$msg};
+
+           for my $signal (@{$m{'signals'}}) {
+                   $rcv_msg{$m{'id'}}->{$signal} += 1;
+            }
+       }
+
+       my %picked = ();
+       $picked{'receive'} = \%rcv_msg;
+       $picked{'send'} = \%send_msg;
+
+       return \%picked;
+    }
+
+eofile: /^\Z/
+
+Line: CommentPrefix /.*\n/
+        # Not needed to output anything yet
+    | 'RECEIVE' MessageSpec
+       {
+          # select the message for receiving
+          push(@receive, $item[2]);
+       }
+    | 'SEND' MessageSpec
+       {
+          # select the message for sending
+          push(@send, $item[2]);
+       }
+    | <error: Invalid msg format at $thisline!>        
+
+MessageSpec: MessageId '.' SignalId ';'
+       {
+          my %msg;
+          $msg{'id'} = $item[1];
+           @{$msg{'signals'}} = $item[3];
+          $return = \%msg;
+       }
+      | MessageId '{' SignalId(s? /,/) '}'
+       {
+          my %msg;
+          $msg{'id'} = $item[1];
+           $msg{'signals'} = $item[3];
+          $return = \%msg;
+       }
+
+MessageId: Identifier
+       {
+         # Message is selected by name
+         $return = $item[1];
+       }
+       | '@' Integer
+       {
+         # Message is selected by id
+         $return = $item[2];
+       }
+
+SignalId: Identifier|'*'
+
+Identifier: /[A-Za-z0-9_\-]+/
+        {
+            $return = $item[1];
+        }
+
+Number: Integer | RealNumber | Sign
+
+Integer: /[-+]?[0-9]*/
+RealNumber: /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/
+Sign: /^[-+]?/
+
+CommentPrefix: '#'
+
+DoubleQuotation: "\""
+
index 6d392ee..f5bfee9 100644 (file)
@@ -1,19 +1,27 @@
 cmake_minimum_required(VERSION 2.8)
 
-set( CMAKE_VERBOSE_MAKEFILE on )
+set(CMAKE_VERBOSE_MAKEFILE on )
+set(PLUGIN_SEGMENT_INSTALL_PATH "/etc/ambd/plugins.d")
+set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
+set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/${CMAKE_LIBRARY_ARCHITECTURE}" )
+set(PLUGIN_INSTALL_PATH "${LIB_INSTALL_DIR}/automotive-message-broker")
 
 # to install plugin into /usr instead of /usr/local
 set (CMAKE_INSTALL_PREFIX /usr)
 
-IF(CMAKE_BUILD_TYPE MATCHES DEBUG) 
+# check that CAN interface is specified and use vcan0 by default
+if(NOT DEFINED ${DEFAULT_CAN_INTERFACE})
+    set(DEFAULT_CAN_INTERFACE "vcan0")
+endif(NOT DEFINED ${DEFAULT_CAN_INTERFACE})
+
+if(CMAKE_BUILD_TYPE MATCHES DEBUG)
     message("debug mode") 
+else(CMAKE_BUILD_TYPE MATCHES DEBUG)
+    # default is RELEASE mode
+    message("release mode, no logger")
+    add_definitions(-D_LOGGER_NO_LOG)
 ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG)
  
-IF(CMAKE_BUILD_TYPE MATCHES RELEASE) 
-    message("release mode")
-    add_definitions(-D_LOGGER_NO_LOG)
-ENDIF(CMAKE_BUILD_TYPE MATCHES RELEASE)
-
 include(FindPkgConfig)
 
 find_package(Boost REQUIRED)
@@ -21,7 +29,7 @@ find_package(Boost REQUIRED)
 pkg_check_modules(glib REQUIRED glib-2.0)
 pkg_check_modules(json REQUIRED json)
 
-add_definitions(-std=gnu++0x -fPIC -fPIE)
+add_definitions(-std=gnu++0x)
 
 pkg_check_modules( amb REQUIRED automotive-message-broker )
 pkg_check_modules( amb-plugins-common REQUIRED amb-plugins-common )
@@ -31,6 +39,8 @@ include_directories(${include_dirs} ${amb-plugins-common_INCLUDE_DIRS} ${amb_INC
 set(ambtmpl_plugin_headers ambtmpl_plugin.h  ambtmpl_cansignals.h ambtmpl_cansignal.h)
 set(ambtmpl_plugin_sources ambtmpl_plugin.cpp ambtmpl_cansignal.cpp)
 
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ambtmpl.in.json ${CMAKE_CURRENT_BINARY_DIR}/ambtmpl @ONLY)
+
 if(ivipoc_tests)
 #########################################
 # ivipoc_tests START
@@ -63,6 +73,7 @@ add_library(ambtmpl_plugin MODULE ${ambtmpl_plugin_sources} ${ambtmpl_plugin_hea
 set_target_properties(ambtmpl_plugin PROPERTIES PREFIX "")
 target_link_libraries(ambtmpl_plugin ${link_libraries} ${libamb_LIBRARY} ${amb_LIBRARIES} ${amb-plugins-common_LIBRARIES})
 
-install(TARGETS ambtmpl_plugin LIBRARY DESTINATION lib/automotive-message-broker)
+install(TARGETS ambtmpl_plugin LIBRARY DESTINATION "lib/automotive-message-broker")
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ambtmpl DESTINATION ${PLUGIN_SEGMENT_INSTALL_PATH})
+
 
-############################################################################################################################################
diff --git a/tools/AmbSignalMapper/lib/Intel/IviPoc/templates/ambtmpl.in.json b/tools/AmbSignalMapper/lib/Intel/IviPoc/templates/ambtmpl.in.json
new file mode 100644 (file)
index 0000000..15cdea9
--- /dev/null
@@ -0,0 +1,7 @@
+{
+       "name" : "AmbTmpl",
+       "path" : "@PLUGIN_INSTALL_PATH@/ambtmpl_plugin.so",
+       "frequency" : "10",
+       "enabled" : true,
+       "interface" : "@DEFAULT_CAN_INTERFACE@"
+}
diff --git a/tools/AmbSignalMapper/t/syntax.msg b/tools/AmbSignalMapper/t/syntax.msg
new file mode 100644 (file)
index 0000000..391b217
--- /dev/null
@@ -0,0 +1,45 @@
+# Test file for Msg grammar
+#
+#Copyright (c) 2015  Cogent Embedded Inc.
+#
+#This library is free software; you can redistribute it and/or
+#modify it under the terms of the GNU Lesser General Public
+#License as published by the Free Software Foundation; either
+#version 2.1 of the License, or (at your option) any later version.
+#
+#This library is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#Lesser General Public License for more details.
+#
+#You should have received a copy of the GNU Lesser General Public
+#License along with this library; if not, write to the Free Software
+#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+# Pick one signal from message
+RECEIVE @1.Signal1;
+
+# Pick all signals from another message
+RECEIVE @2.*;
+
+RECEIVE Message1.Signal1;
+
+# pick multiple signals
+RECEIVE Message1 {
+       Signal1
+}
+
+RECEIVE @4 {
+       Signal1
+}
+
+RECEIVE @3 {
+       Signal1,
+       Signal2
+}
+
+RECEIVE @2 {
+       Signal1,
+       Signal2
+}
+