-- -- Copyright 2014 Alessandro Gerlinger Romero -- -- This file is part of Hybrid fUML. -- -- Hybrid fUML is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- -- Hybrid fUML 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 General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with Hybrid fUML. If not, see . -- ------------------------------------------------------------------------------------------------------------------------------------------------------------ -- HELP FUNCTIONS - TRACING -- ONLY FOR TRACE PURPOSE -- IT IS NOT PART OF SEMANTICS -- FUNCTION for retrieve, filter and store the values of signal signalTrace :: [String] signalTrace = rctps++rctfvs++rctabs where -- locus l = function_fUML_locus -- clock data rc = function_Locus_reactionClock l rt = function_fUML_Clock_currentTimeInt rc -- signals rct = map (\v1v2cli-> (v1v2cli, function_fUML_signals v1v2cli)) $ expr2list $ dom function_fUML_signals -- with real value rcti = filter (\((v1,v2,cl,i),o) -> i == rt && card (function_Value_CompoundValue_featureValues o) > 0) rct rctf1 = map (\(v1v2cli,o) -> (v1v2cli,o,one $ function_Value_CompoundValue_featureValues(o))) rcti rctfv = map (\(v1v2cli,o,f) -> (v1v2cli,head $ function_FeatureValue_values(f))) rctf1 rctfvf = filter (\((v1,v2,cl,i),fv) -> fv /= FUML_Semantics_Classes_Kernel_ValueEmpty && function_Value_type(fv) == FUML_Semantics_Classes_Kernel_RealValue) rctfv rctfvs = map (\((v1,v2,cl,i),fv) -> show i ++ ",PRESENT," ++ function_Classifier_NamedElement_name(cl) ++ "," ++ show (function_Value_RealValue_value fv) ++ "," ++ show v1++ "," ++ show (function_fUML_oneClassifierType v1) ++ "," ++ show v2 ++ "," ++ show (function_fUML_oneClassifierType v2) ) rctfvf -- absent rctab = filter (\((v1,v2,cl,i),o) -> i == rt && function_fUML_oneClassifierType(function_fUML_signals(v1,v2,cl,i)) == function_Instance_Classifier_Signal_absentSignal) rct rctabs = map (\((v1,v2,cl,i),o) -> show i ++ ",ABSENT," ++ function_Classifier_NamedElement_name(cl) ++ ",," ++ show v1++ "," ++ show (function_fUML_oneClassifierType v1) ++ "," ++ show v2 ++ "," ++ show (function_fUML_oneClassifierType v2)) rctab -- pure signals present rctp = filter (\((v1,v2,cl,i),o) -> i == rt && notElem ((v1,v2,cl,i),o) rcti && notElem ((v1,v2,cl,i),o) rctab) rct rctps = map (\((v1,v2,cl,i),o) -> show i ++ ",PRESENT," ++ function_Classifier_NamedElement_name(cl) ++ ",," ++ show v1++ "," ++ show (function_fUML_oneClassifierType v1) ++ "," ++ show v2 ++ "," ++ show (function_fUML_oneClassifierType v2)) rctp -- FUNCTION for retrieve, filter and store values of continuous variables hybridTrace :: [String] hybridTrace = concat $ map (\o -> function_fUML_hybridTrace o) (expr2list function_fUML_activeObjects) -- FUNCTION for retrieve, filter and store the values of clocks clockTrace :: [String] clockTrace = (map (\c-> show (function_Clock_LogicalClock_definingEvent c) ++ "," ++ show (function_fUML_Clock_currentTimeInt c)) (expr2list $function_Locus_logicalClocks l )) ++ ["physicalClk,"++ show (function_Clock_currentTime (function_Locus_physicalClock l))] where l = function_fUML_locus -- to be used with trace from ASM -- using the following command -- fire1 (trace traceFG rule_fUML_mainHyb) -- -- as it is executed before the rule to get the current data use the following command -- fire1 (trace traceFG skip) traceFG :: IO () traceFG = do saveTraceFile (getFileName "hybrid") hybridTrace saveTraceFile (getFileName "signal") signalTrace saveTraceFile (getFileName "clock") clockTrace -- to be used with trace from ASM -- using the following commands -- fire1 rule_fUML_init2 -- traceFH -- traceFH :: IO () traceFH = do saveTraceFile (getFileName "hybrid") ["reactionClk,physicalClk,logicalClk,..."] saveTraceFile (getFileName "signal") ["reactionClk,status,classifier,realValue,sender,senderClassifier,receiver,receiverClassifier"] saveTraceFile (getFileName "clock") ["clock,currentTime"] getFileName :: String -> String getFileName s = "traces/"++ s ++ show(function_fUML_evaluationId)++".txt" -- opens a file an write in each line one item from array saveTraceFile :: String -> [String] -> IO() saveTraceFile n str = do start (do f<-(openFile n AppendMode) hPutStr f (unlines str) hClose f quit)