Element::Element(string netlistLine, int &numNodes, vector<string> &variablesList) { stringstream sstream(netlistLine); char na[MAX_NAME], nb[MAX_NAME], nc[MAX_NAME], nd[MAX_NAME]; sstream >> name; type = getType(); sstream.str( string(netlistLine, name.size(), string::npos) ); if (type=='R' || type=='I' || type=='V') { sstream >> na >> nb >> value; cout << name << " " << na << " " << nb << " " << value << endl; a = getNodeNumber(na, numNodes, variablesList); b = getNodeNumber(nb, numNodes, variablesList); }
void Node::run() { //Time to wait for the network connection to be setup //May be reduced waitUntil(NOW()+5000*MILLISECONDS); //Detects the nodes ID nodeID = getNodeNumber(); PRINTF("This nodes ID: %i\n", nodeID); //Used to count the times a worker could not be detected short failcounter = 0; //Used for reading from the workerAlive topic long workerTopicID; //true when this node is the worker, false when the monitor //Each node starts as a monitor. bool worker = false; //Endless loop. Components should never stop working while(true) { PRINTF("Being monitor now!\n"); //Monitoring loop while(!worker) { //If there was no topic from the worker within the specified time... if(workerAlive.waitAndGet(workerTopicID,workerTimeOut) == -1) { //... then increase failcounter ++failcounter; //If we couldn't detect a worker multiple times we become a worker ourself if(failcounter > 2) worker = true; }else { //Worker topic found, resetting the counter failcounter = 0; } } //During role changes we flush the buffers flushBuffers(); PRINTF("Being the worker now!\n"); //Working loop while(worker) { //Publish worker topic //"I'm alive" workerAlive.publish(nodeID); //Work work(); //Handle all messages worker = wHandleMessages(); } //During role changes we flush the buffers flushBuffers(); } }
/**\brief * Print all memory to serial. Used for debug. */ void MergMemoryManagement::dumpMemory(){ /**\brief * Find the event variable position in memory */ #ifdef DEBUGDEF read(); byte a; Serial.println("MEMORY DUMP"); Serial.print("IDENT:"); a=EEPROM.read(MERG_MEMPOS); Serial.print(a,HEX); Serial.print("\nCAN_ID:"); Serial.print(can_ID,HEX); Serial.print("\nNN:"); Serial.print(getNodeNumber()); Serial.print("\nFlags:"); Serial.print(flags,HEX); Serial.print("\nNUM EVENTS:"); Serial.print(numEvents,HEX); Serial.print("\nNUM EVENTS VARS:"); Serial.print(MAX_VAR_PER_EVENT,HEX); Serial.print("\nNUM VARS:"); Serial.print(MAX_AVAIL_VARS,HEX); Serial.print("\nNODE VARS:"); for (int i=0;i<MAX_AVAIL_VARS;i++){ Serial.print(EEPROM.read(VARS_MEMPOS+i),HEX); Serial.print(" "); } Serial.print("\nDEVICE NUMBERS:"); for (int i=0;i<MAX_NUM_DEVICE_NUMBERS;i++){ Serial.print(EEPROM.read(DN_MEMPOS+i*NNDD_SIZE),HEX); Serial.print(EEPROM.read(DN_MEMPOS+i*NNDD_SIZE+1),HEX); Serial.print(" "); } Serial.println("\nEVENTS:"); int n=resolveEventPos(0); for (int i=0;i<MAX_NUM_EVENTS;i++){ for (int j=0;j<EVENT_SIZE;j++){ Serial.print(EEPROM.read(n),HEX); n++; Serial.print(" "); } Serial.print("VARS "); for (int j=0;j<MAX_VAR_PER_EVENT;j++){ Serial.print(EEPROM.read(n),HEX); n++; Serial.print(" "); } Serial.println(); } #endif // DEBUGDEF }