From dd763963a037b579d4298a6fbb721f75bf4d3c73 Mon Sep 17 00:00:00 2001
From: galperti <cristian.galperti@epfl.ch>
Date: Mon, 27 Jun 2022 11:09:24 +0200
Subject: [PATCH] realtime signal fed to simulink

---
 .../algo_template_create_marte2_cfg.m         |  7 +++++--
 algos/template/marte2cfg/data_states.cfgsrc   | 19 +++++++++++--------
 algos/template/marte2cfg/rtapp-postsl.cfgsrc  |  6 +++++-
 algos/template/marte2cfg/rtapp-presl.cfgsrc   | 10 ++++++++++
 .../marte2cfg/rtapp-simulinkwrapper.cfgsrc    |  2 +-
 5 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/algos/template/marte2cfg/algo_template_create_marte2_cfg.m b/algos/template/marte2cfg/algo_template_create_marte2_cfg.m
index 3ce395f..a902b93 100644
--- a/algos/template/marte2cfg/algo_template_create_marte2_cfg.m
+++ b/algos/template/marte2cfg/algo_template_create_marte2_cfg.m
@@ -11,9 +11,11 @@
 % source MDSplus shotnumber
 mdssrcshot=-1;
 % destination MDSplus shotnumber (-1 stands for increment current by 1)
-mdsdstshot=1;
+mdsdstshot=2;
 % verbosity level
 verbosity=2;
+% MDS writer period
+mdsperiod=1;
 
 startpath=pwd;
 fcnpath=fileparts(mfilename('fullpath'));
@@ -80,7 +82,7 @@ diary off
 system('rm -rf mdswriter1.cfg');
 diary mdswriter1.cfg
 for i=1:numel(outsignals)
-    fprintf("%s = { NodeName =""template.outputs.%s"" Period = 1 AutomaticSegmentation = 0 MakeSegmentAfterNWrites = 2000 SamplePhase = 0 } \n", char(outsignals{i}{1}),char(outsignals{i}{5}));
+    fprintf("%s = { NodeName =""template.outputs.%s"" Period = MDSW0PERIOD AutomaticSegmentation = 0 MakeSegmentAfterNWrites = 2000 SamplePhase = 0 } \n", char(outsignals{i}{1}),char(outsignals{i}{5}));
 end
 diary off
 
@@ -104,4 +106,5 @@ system(sprintf('sed -i "s/>WAVEGEN0_ELEMS</%d/g" algo_template.cfg',wg0dim));
 system(sprintf('sed -i "s/MDSSRCSHOT/%d/g" algo_template.cfg',mdssrcshot));
 system(sprintf('sed -i "s/MDSDSTSHOT/%d/g" algo_template.cfg',mdsdstshot));
 system(sprintf('sed -i "s/VERBOSITY/%d/g" algo_template.cfg',verbosity));
+system(sprintf('sed -i "s/MDSW0PERIOD/%d/g" algo_template.cfg',mdsperiod));
 
diff --git a/algos/template/marte2cfg/data_states.cfgsrc b/algos/template/marte2cfg/data_states.cfgsrc
index 9e567da..e8cc19a 100644
--- a/algos/template/marte2cfg/data_states.cfgsrc
+++ b/algos/template/marte2cfg/data_states.cfgsrc
@@ -29,21 +29,23 @@
             NumberOfPreTriggers = 0 //Compulsory iff StoreOnTrigger = 1.  Number of cycles to store before the trigger.
             NumberOfPostTriggers = 0 //Compulsory iff StoreOnTrigger = 1.  Number of cycles to store after the trigger.
             Signals = {
-            /*
+           
+           /*
                 Trigger = { //Compulsory when StoreOnTrigger = 1. Must be set in index 0 of the Signals node. When the value of this signal is 1 data will be stored.
                     Type = uint8 //Type must be uint8
                 }
+            
                 Time = { //Compulsory when StoreOnTrigger = 1. Can be store in any index, but TimeSignal must be set = 1
                     Type = uint32 //Type must be uint32 or int32
                     TimeSignal = 1 //When set, this signal will be considered as the time source against which all signals will be stored.
-                    TimeSignalMultiplier = 1e-9 //Default = 1e-6. Multiplier to convert the time signal units into seconds,
+                    TimeSignalMultiplier = 1e-6 //Default = 1e-6. Multiplier to convert the time signal units into seconds,
                 }
             */
-            
-                Thread1_Cycletime       = { NodeName = "template.system.CH01" Period = 1 AutomaticSegmentation = 0 MakeSegmentAfterNWrites = 2000 SamplePhase = 0 }
-                GAMSimulink1_ReadTime   = { NodeName = "template.system.CH02" Period = 1 AutomaticSegmentation = 0 MakeSegmentAfterNWrites = 2000 SamplePhase = 0 }
-                GAMSimulink1_ExecTime   = { NodeName = "template.system.CH03" Period = 1 AutomaticSegmentation = 0 MakeSegmentAfterNWrites = 2000 SamplePhase = 0 }
-                GAMSimulink1_WriteTime  = { NodeName = "template.system.CH04" Period = 1 AutomaticSegmentation = 0 MakeSegmentAfterNWrites = 2000 SamplePhase = 0 }
+   
+                Thread1_Cycletime       = { NodeName = "template.system.CH01" Period = MDSW0PERIOD AutomaticSegmentation = 0 MakeSegmentAfterNWrites = 2000 SamplePhase = 0 }
+                GAMSimulink1_ReadTime   = { NodeName = "template.system.CH02" Period = MDSW0PERIOD AutomaticSegmentation = 0 MakeSegmentAfterNWrites = 2000 SamplePhase = 0 }
+                GAMSimulink1_ExecTime   = { NodeName = "template.system.CH03" Period = MDSW0PERIOD AutomaticSegmentation = 0 MakeSegmentAfterNWrites = 2000 SamplePhase = 0 }
+                GAMSimulink1_WriteTime  = { NodeName = "template.system.CH04" Period = MDSW0PERIOD AutomaticSegmentation = 0 MakeSegmentAfterNWrites = 2000 SamplePhase = 0 }
                 
                 >OUTPUTBUSMDSWRITER<
             }
@@ -82,7 +84,8 @@
                     Class = RealTimeThread 
                     CPUs = 0x4
                     Functions = {
-                      GAMTimer                         	      
+                      GAMTimer  
+                      TimeConversion
                       Constants
                       Wavegen0TimeBroker
                       Wavegen0DataBroker
diff --git a/algos/template/marte2cfg/rtapp-postsl.cfgsrc b/algos/template/marte2cfg/rtapp-postsl.cfgsrc
index 0a9a1f9..5d56601 100644
--- a/algos/template/marte2cfg/rtapp-postsl.cfgsrc
+++ b/algos/template/marte2cfg/rtapp-postsl.cfgsrc
@@ -1,6 +1,8 @@
 		+StorageBroker = {
 		 Class = IOGAM
-		 InputSignals = {            
+		 InputSignals = {  
+            //Trigger                     = { DataSource = DDB1 Type = uint8 }
+            //Time                        = { DataSource = DDB1 Type = uint32 }
             Thread1_CycleTime           = { DataSource = Timings Type = uint32 Alias = State1.Thread1_CycleTime }
             GAMSimulink1_ReadTime  		= { DataSource = Timings Type = uint32 } 
 	        GAMSimulink1_ExecTime  		= { DataSource = Timings Type = uint32 }  
@@ -8,6 +10,8 @@
 	        >OUTPUTBUSFLAT<
 		 }
 		 OutputSignals = {                        
+            //Trigger                     = { DataSource = MDSWriter_0 Type = uint8 }
+            //Time                        = { DataSource = MDSWriter_0 Type = uint32 }
             Thread1_Cycletime           = { DataSource = MDSWriter_0 Type = uint32 }
             GAMSimulink1_ReadTime  		= { DataSource = MDSWriter_0 Type = uint32 } 
 	        GAMSimulink1_ExecTime  		= { DataSource = MDSWriter_0 Type = uint32 }  
diff --git a/algos/template/marte2cfg/rtapp-presl.cfgsrc b/algos/template/marte2cfg/rtapp-presl.cfgsrc
index 7d0085f..81e324d 100644
--- a/algos/template/marte2cfg/rtapp-presl.cfgsrc
+++ b/algos/template/marte2cfg/rtapp-presl.cfgsrc
@@ -12,11 +12,21 @@ $TestApp = {
                 Counter = {                  DataSource = DDB1  Type = uint32 }                
                 Time    = {                	 DataSource = DDB1  Type = uint32 }            
             }
+        }
+        +TimeConversion = {
+            Class = ConversionGAM
+                InputSignals = {
+                    Time    = { DataSource = DDB1 Type = uint32 }
+                }
+                OutputSignals = {
+                    TimeSec = { DataSource = DDB1 Type = float32 Gain = 0.000001 }
+                }
         }
 	    +Constants = {
 	     Class = ConstantGAM
 	     OutputSignals = {
 				zero	= { DataSource = DDB1 Type = float32  NumberOfElements = 1  NumberOfDimensions=0 Default=0 }				
+                Trigger = { DataSource = DDB1 Type = uint8    NumberOfElements = 1  NumberOfDimensions=0 Default=1 }
 	     }
 	    }
         +Wavegen0TimeBroker = {
diff --git a/algos/template/marte2cfg/rtapp-simulinkwrapper.cfgsrc b/algos/template/marte2cfg/rtapp-simulinkwrapper.cfgsrc
index 7239fec..bda9fd5 100644
--- a/algos/template/marte2cfg/rtapp-simulinkwrapper.cfgsrc
+++ b/algos/template/marte2cfg/rtapp-simulinkwrapper.cfgsrc
@@ -10,7 +10,7 @@
             NonVirtualBusMode = "Structured" 
                                             
 			InputSignals = {		
-				realtime	= { DataSource = DDB1 Type = float32 NumberOfElements = 1 NumberOfDimensions=0 Alias = zero }
+				realtime	= { DataSource = DDB1 Type = float32 NumberOfElements = 1 NumberOfDimensions=0 Alias = TimeSec }
                 >INPUTBUSSTRUCT<
  			}
  			OutputSignals = { 
-- 
GitLab