static boolean isPreviousToNode(Node * previous, Node * target) { Node *currentNode = target; Node *previousNode = NULL; Time targetTime = getNodeTime(target); //velvetLog("Testing if %li is previous to %li\n", getNodeID(previous), getNodeID(target)); while (true) { //velvetLog("CCC %li %f\n", getNodeID(currentNode), getNodeTime(currentNode)); if (currentNode == previous) return true; if (currentNode == previousNode) return false; if (getNodeID(currentNode) > nodeCount(graph) || getNodeID(currentNode) < -nodeCount(graph)) { velvetLog("Node ID??? %li %li\n", (long) getNodeID(currentNode), (long) getNodeID(previousNode)); } if (getNodeTime(currentNode) != targetTime) return false; previousNode = currentNode; currentNode = getNodePrevious(currentNode); } }
//*********************************************************************** void ICACHE_FLASH_ATTR easyMesh::handleTimeSync( meshConnectionType *conn, JsonObject& root ) { String timeStamp = root["msg"]; debugMsg( SYNC, "handleTimeSync(): with %d in timestamp=%s\n", conn->chipId, timeStamp.c_str()); conn->time.processTimeStamp( timeStamp ); //varifies timeStamp and updates it with a new one. debugMsg( SYNC, "handleTimeSync(): with %d out timestamp=%s\n", conn->chipId, timeStamp.c_str()); if ( conn->time.num < TIME_SYNC_CYCLES ) { staticThis->sendMessage( conn, _chipId, TIME_SYNC, timeStamp ); } uint8_t odd = conn->time.num % 2; if ( (conn->time.num + odd) >= TIME_SYNC_CYCLES ) { // timeSync completed if ( conn->time.adopt ) { conn->time.calcAdjustment( odd ); // flag all connections for re-timeSync SimpleList<meshConnectionType>::iterator connection = _connections.begin(); while ( connection != _connections.end() ) { if ( connection != conn ) { // exclude this connection connection->timeSyncStatus = NEEDED; } connection++; } } conn->lastTimeSync = getNodeTime(); conn->timeSyncStatus = COMPLETE; } }
// easyMesh Syncing functions //*********************************************************************** void ICACHE_FLASH_ATTR easyMesh::startNodeSync( meshConnectionType *conn ) { debugMsg( SYNC, "startNodeSync(): with %u\n", conn->chipId); String subs = subConnectionJson( conn ); sendMessage( conn, conn->chipId, NODE_SYNC_REQUEST, subs ); conn->nodeSyncRequest = getNodeTime(); conn->nodeSyncStatus = IN_PROGRESS; }
static void destroyPaths() { PassageMarker *marker; while (slowPath != NULL) { marker = slowPath; getNodeTime(getNode(marker)); getNodeTime(getTwinNode(getNode(marker))); slowPath = getNextInSequence(marker); destroyPassageMarker(marker); } while (fastPath != NULL) { marker = fastPath; getNodeTime(getNode(marker)); getNodeTime(getTwinNode(getNode(marker))); fastPath = getNextInSequence(marker); destroyPassageMarker(marker); } }
static void tourBusNode_local(Node * node) { Arc *arc; Node *destination; Time nodeTime = getNodeTime(node); //velvetLog("Node %li %f %i %p\n", getNodeID(node), // times[getNodeID(node) + nodeCount(graph)], simpleArcCount(node), // node); for (arc = getArc(node); arc != NULL; arc = getNextArc(arc)) { destination = getDestination(arc); // Node doesn't belong to the marked node area if (getNodeStatus(getDestination(arc)) != 1) continue; tourBusArc_local(node, arc, nodeTime); if (getNodeStatus(node) != 1) break; } }
static void comparePaths_local(Node * destination, Node * origin) { IDnum slowLength, fastLength; Node *fastNode, *slowNode; IDnum i; PassageMarkerI marker; //Measure lengths slowLength = fastLength = 0; fastNode = destination; slowNode = origin; //velvetLog("Looking into separate paths\n"); while (fastNode != slowNode) { //velvetLog("Fast node %li Slow node %li\n", getNodeID(fastNode), getNodeID(slowNode)); if (getNodeTime(fastNode) > getNodeTime(slowNode)) { fastLength++; fastNode = getNodePrevious(fastNode); } else if (getNodeTime(fastNode) < getNodeTime(slowNode)) { slowLength++; slowNode = getNodePrevious(slowNode); } else if (isPreviousToNode(slowNode, fastNode)) { while (fastNode != slowNode) { fastLength++; fastNode = getNodePrevious(fastNode); } } else if (isPreviousToNode(fastNode, slowNode)) { while (slowNode != fastNode) { slowLength++; slowNode = getNodePrevious(slowNode); } } else { fastLength++; fastNode = getNodePrevious(fastNode); slowLength++; slowNode = getNodePrevious(slowNode); } if (slowLength > MAXNODELENGTH || fastLength > MAXNODELENGTH) { //velvetLog("Paths too fragmented %li %li\n", slowLength, fastLength); return; } } if (fastLength == 0) return; //Backtracking to record actual paths fastPath = addUncertainPassageMarker(1, destination); setPassageMarkerStatus(fastPath, true); for (i = 0; i < fastLength; i++) { marker = addUncertainPassageMarker(1, getNodePrevious(getNode (fastPath))); setPassageMarkerStatus(marker, true); connectPassageMarkers(marker, fastPath, graph); fastPath = marker; } slowPath = addUncertainPassageMarker(2, destination); setPassageMarkerStatus(slowPath, true); marker = addUncertainPassageMarker(2, origin); setPassageMarkerStatus(marker, true); connectPassageMarkers(marker, slowPath, graph); slowPath = marker; for (i = 0; i < slowLength; i++) { marker = addUncertainPassageMarker(2, getNodePrevious(getNode (slowPath))); setPassageMarkerStatus(marker, true); connectPassageMarkers(marker, slowPath, graph); slowPath = marker; } //Extract sequences if (!extractSequence(fastPath, fastSequence) || !extractSequence(slowPath, slowSequence)) { //velvetLog("Paths too long\n"); destroyPaths(); return; } //Compare sequences if (compareSequences(fastSequence, slowSequence)) { //velvetLog("Correcting discrepancy\n"); cleanUpRedundancy_local(); return; } //velvetLog("\tFinished comparing paths, changes made\n"); destroyPaths(); }