+void FunctionalBlock::createInputPattern() throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::createInputPattern())";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ \r
+ lengthIP = -1;\r
+ foreach(AbstractInterface* iface, getControlInputs()) { \r
+ ConnectedInterface* connIface = AI_TO_CON(iface);\r
+ QList<char>* out = connIface->getConnectedFrom()->getOutputPattern();\r
+ if (out->size() == 0) {\r
+ clearInputPattern();\r
+ throw(Exception(NO_IFACE_IP));\r
+ }\r
+ if (lengthIP == -1) {\r
+ lengthIP = out->size();\r
+ }\r
+ else {\r
+ if (out->size() < lengthIP) lengthIP = out->size();\r
+ }\r
+ \r
+ QList<char>* in = new QList<char>(*out);\r
+ foreach(char c, *in) {\r
+ cout << (int)c;\r
+ }\r
+ cout << endl; \r
+ inputPattern.insert(connIface,in); \r
+ }\r
+ // search the last valid group in IP,\r
+ while(! isValidDataGroup(inputPattern,lengthIP-1)) {\r
+ //removeDataGroup(inputPattern,lengthIP-1);\r
+ lengthIP -= 1;\r
+ }\r
+}\r
+\r
+void FunctionalBlock::createAdmittance(int nbExec) throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::createAdmittance()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif \r
+ // firstly, copy CP in AP\r
+ QMapIterator<AbstractInterface*,QList<char>* > iterC(consumptionPattern);\r
+ while (iterC.hasNext()) {\r
+ iterC.next();\r
+ QList<char>* pattern = new QList<char>(*(iterC.value()));\r
+ admittance.insert(iterC.key(), pattern); \r
+ }\r
+ lengthAP = lengthCP;\r
+ int clock = 0; \r
+ cout << "trigger 1 at c.c. 0" << endl;\r
+ for(int i=1;i<nbExec;i++) {\r
+ // searching for the clock cycle for which a new exec starts\r
+ int nbGroup = 0;\r
+ while ((clock < lengthAP) && (nbGroup < delta)) {\r
+ if (isValidDataGroup(admittance,clock)) nbGroup+=1;\r
+ clock += 1;\r
+ }\r
+ while ((clock < lengthAP) && (! isValidDataGroup(admittance,clock))) clock+=1;\r
+ cout << "trigger " << (i+1) << " at c.c. " << clock << endl;\r
+ int sc = clock;\r
+ // combine CP with AP at sc\r
+ for(int j=0;j<lengthCP;j++) {\r
+ // first case : column of CP must be placed beyond AP's end.\r
+ if (sc == lengthAP) {\r
+ cout << i << "," << j << " append in AP at " << sc << endl;\r
+ appendToPattern(consumptionPattern,j,admittance,1);\r
+ lengthAP += 1;\r
+ sc += 1; \r
+ }\r
+ // second case : CP and AP can be combined directly (i.e. no X | 1 to do)\r
+ else if (canCombinePatterns(consumptionPattern,j,admittance,sc)) {\r
+ cout << i << "," << j << " combine at " << sc << endl;\r
+ combinePatterns(consumptionPattern,j,admittance,sc);\r
+ sc += 1;\r
+ }\r
+ // third case : CP has an X column\r
+ else if (isOnlyXDataGroup(consumptionPattern,j)) {\r
+ cout << i << "," << j << " shift rigth AP to combine at " << sc << endl;\r
+ shiftRightPattern(admittance,sc);\r
+ lengthAP += 1;\r
+ if (! canCombinePatterns(consumptionPattern,j,admittance,sc)) {\r
+ cerr << "Abnormal case when combining AP and CP" << endl;\r
+ }\r
+ combinePatterns(consumptionPattern,j,admittance,sc); \r
+ sc += 1;\r
+ }\r
+ // fourth case : AP has an X column\r
+ else if (isOnlyXDataGroup(admittance,sc)) {\r
+ cout << i << "," << j << " jump c.c. for CP at " << sc << endl; \r
+ sc += 1;\r
+ j -= 1;\r
+ }\r
+ else {\r
+ throw(INVALID_DELTA_CP); \r
+ }\r
+ }\r
+ }\r
+ // turn all X into 0\r
+ QMapIterator<AbstractInterface*,QList<char>* > iterA(admittance);\r
+ while (iterA.hasNext()) {\r
+ iterA.next();\r
+ QList<char>* pattern = iterA.value();\r
+ for(int i=0;i<pattern->size();i++) {\r
+ if (pattern->at(i) == -1) pattern->replace(i,0);\r
+ cout << (int)(pattern->at(i));\r
+ }\r
+ cout << endl;\r
+ } \r
+}\r
+\r
+void FunctionalBlock::checkInputPatternCompatibility() throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::checkInputPatternCompatibility()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ \r
+ // firstly, create input pattern\r
+ try {\r
+ createInputPattern();\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ int nbExec = createTriggers();\r
+ cout << qPrintable(name) << " will exec. " << nbExec << " times." << endl;\r
+ \r
+ try {\r
+ createAdmittance(nbExec);\r
+ }\r
+ catch(Exception e) {\r
+ cout << "cannot create admittance" << endl;\r
+ throw(e);\r
+ }\r
+ \r
+ int clock = 0; // index in IP \r
+ int i = 0; // index in AP \r
+ while ((clock < lengthIP) && (i < lengthAP)) {\r
+ \r
+ // if AP is a valid group, search for the next valid group in IP\r
+ if (isValidDataGroup(admittance,i)) {\r
+ while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;\r
+ if (clock == lengthIP) {\r
+ cerr << "Abnormal case: end of IP has been reached without finding a valid group" << endl;\r
+ throw(Exception(IP_END_NULLCOL)); \r
+ }\r
+ } \r
+ /* at that point 2 cases of compat : IP(clock) and AP(i) are equal valid group, or\r
+ are both null columns\r
+ */\r
+ if (! samePatterns(inputPattern,clock,admittance,i)) {\r
+ cout << "AP(" << i << ") and IP(" << clock << ") are not equal" << endl;\r
+ throw(Exception(IP_AP_NOTCOMPAT)); // IP and AP not compatible\r
+ }\r
+ clock++;\r
+ i++;\r
+ }\r
+ if (clock < lengthIP) {\r
+ throw(Exception(AP_TOO_SHORT));\r
+ cerr << "Abnormal case: AP is to short" << endl; \r
+ } \r
+}\r
+\r
+void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) {\r