/*! */ void SpectralDistribution::normalize() noexcept { ZISC_ASSERT(!isAllZero(), "The intensities are all zero."); const Float k = zisc::invert(compensatedSum()); for (uint i = 0; i < size(); ++i) { const Float v = k * get(i); set(i, v); } }
QImage* setMaskMap(IplImage* ocvImage, IplImage* mask) { int height = ocvImage->height; int width = ocvImage->width; QImage *retImage = new QImage( width, height, QImage::Format_RGB32 ); int R, G, B; for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { CvScalar color1 = cvGet2D(ocvImage, y, x); CvScalar color2 = cvGet2D(mask, y, x); if(ocvImage->nChannels == 3) { R = 0.6 * color1.val[2] + 0.4 * color2.val[2]; G = 0.6 * color1.val[1] + 0.4 * color2.val[1]; B = 0.6 * color1.val[0] + 0.4 * color2.val[0]; } if(x > 0 && x < width-1 && y > 0 && y < height-1 && (color2.val[2] != 0 || color2.val[1] != 0 || color2.val[0] != 0)) { CvScalar color3 = cvGet2D(mask, y, x-1); CvScalar color4 = cvGet2D(mask, y, x+1); CvScalar color5 = cvGet2D(mask, y-1, x); CvScalar color6 = cvGet2D(mask, y+1, x); if(isAllZero(color3) || isAllZero(color4) || isAllZero(color5) || isAllZero(color6)) { R = 255; G = 255; B = 0; } } retImage->setPixel(x, y, qRgb(R, G, B)); } } return retImage; }
int WaitUntilMoveEnd(RobotArm *robot){ int checkTerm = 10; int presVel[NUM_XEL]; int fingerLoad[NUM_FINGER]; int goalPos[NUM_XEL], presPos[NUM_XEL]; while(1){ _sleep(33); robot->GetPresVelocity(presVel); robot->GetGoalPosition(goalPos); robot->GetPresPosition(presPos); int maxSub = compareMaxSubPos(goalPos, presPos); //robot->GetFingerLoad(fingerLoad); if(isAllZero(presVel) == 1 || maxSub < 10) return 1; } return 1; }
void updateBondCounters(HSP *sp, SFLAdaptor *bond) { char procFileName[256]; snprintf(procFileName, 256, "/proc/net/bonding/%s", bond->deviceName); FILE *procFile = fopen(procFileName, "r"); if(procFile) { // limit the number of chars we will read from each line // (there can be more than this - fgets will chop for us) #define MAX_PROC_LINE_CHARS 240 char line[MAX_PROC_LINE_CHARS]; SFLAdaptor *currentSlave = NULL; HSPAdaptorNIO *slave_nio = NULL; HSPAdaptorNIO *bond_nio = (HSPAdaptorNIO *)bond->userData; HSPAdaptorNIO *aggregator_slave_nio = NULL; bond_nio->lacp.attachedAggID = bond->ifIndex; uint32_t aggID = 0; // make sure we don't hold on to stale data - may need // to pick up actorSystemID from a slave port. memset(bond_nio->lacp.actorSystemID, 0, 6); memset(bond_nio->lacp.partnerSystemID, 0, 6); int readingMaster = YES; // bond master data comes first int gotActorID = NO; while(fgets(line, MAX_PROC_LINE_CHARS, procFile)) { char buf_var[MAX_PROC_LINE_CHARS]; char buf_val[MAX_PROC_LINE_CHARS]; // buf_var is up to first ':', buf_val is the rest if(sscanf(line, "%[^:]:%[^\n]", buf_var, buf_val) == 2) { char *tok_var = trimWhitespace(buf_var); char *tok_val = trimWhitespace(buf_val); if(readingMaster) { if(my_strequal(tok_var, "MII Status")) { if(my_strequal(tok_val, "up")) { bond_nio->lacp.portState.v.actorAdmin = 2; // dot3adAggPortActorAdminState bond_nio->lacp.portState.v.actorOper = 2; bond_nio->lacp.portState.v.partnerAdmin = 2; bond_nio->lacp.portState.v.partnerOper = 2; } else { bond_nio->lacp.portState.all = 0; } } if(my_strequal(tok_var, "System Identification")) { if(debug) { myLog(LOG_INFO, "updateBondCounters: %s system identification %s", bond->deviceName, tok_val); } char sys_mac[MAX_PROC_LINE_CHARS]; uint64_t code; if(sscanf(tok_val, "%"SCNu64" %s", &code, sys_mac) == 2) { if(hexToBinary((u_char *)sys_mac,bond_nio->lacp.actorSystemID, 6) != 6) { myLog(LOG_ERR, "updateBondCounters: system mac read error: %s", sys_mac); } else if(!isAllZero(bond_nio->lacp.actorSystemID, 6)) { gotActorID = YES; } } } if(my_strequal(tok_var, "Partner Mac Address")) { if(debug) { myLog(LOG_INFO, "updateBondCounters: %s partner mac is %s", bond->deviceName, tok_val); } if(hexToBinary((u_char *)tok_val,bond_nio->lacp.partnerSystemID, 6) != 6) { myLog(LOG_ERR, "updateBondCounters: partner mac read error: %s", tok_val); } } if(my_strequal(tok_var, "Aggregator ID")) { aggID = strtol(tok_val, NULL, 0); if(debug) { myLog(LOG_INFO, "updateBondCounters: %s aggID %u", bond->deviceName, aggID); } } } // initially the data is for the bond, but subsequently // we get info about each slave. So we started with // (readingMaster=YES,currentSlave=NULL), and now we // detect transitions to slave data: if(my_strequal(tok_var, "Slave Interface")) { readingMaster = NO; currentSlave = adaptorListGet(sp->adaptorList, trimWhitespace(tok_val)); slave_nio = currentSlave ? (HSPAdaptorNIO *)currentSlave->userData : NULL; if(debug) { myLog(LOG_INFO, "updateBondCounters: bond %s slave %s %s", bond->deviceName, tok_val, currentSlave ? "found" : "not found"); } if(slave_nio) { // initialize from bond slave_nio->lacp.attachedAggID = bond->ifIndex; memcpy(slave_nio->lacp.partnerSystemID, bond_nio->lacp.partnerSystemID, 6); memcpy(slave_nio->lacp.actorSystemID, bond_nio->lacp.actorSystemID, 6); // make sure the parent is going to export separate // counters if the slave is going to (because it was // marked as a switchPort): if(slave_nio->switchPort) { bond_nio->switchPort = YES; } // and vice-versa if(bond_nio->switchPort) { slave_nio->switchPort = YES; } } } if(readingMaster == NO && slave_nio) { if(my_strequal(tok_var, "MII Status")) { if(my_strequal(tok_val, "up")) { slave_nio->lacp.portState.v.actorAdmin = 2; // dot3adAggPortActorAdminState slave_nio->lacp.portState.v.actorOper = 2; slave_nio->lacp.portState.v.partnerAdmin = 2; slave_nio->lacp.portState.v.partnerOper = 2; } else { slave_nio->lacp.portState.all = 0; } } if(my_strequal(tok_var, "Permanent HW addr")) { if(!gotActorID) { // Still looking for our actorSystemID, so capture this here in case we // decide below that it is the one we want. Note that this mac may not be the // same as the mac associated with this port that we read back in readInterfaces.c. if(hexToBinary((u_char *)tok_val,slave_nio->lacp.actorSystemID, 6) != 6) { myLog(LOG_ERR, "updateBondCounters: permanent HW addr read error: %s", tok_val); } } } if(my_strequal(tok_var, "Aggregator ID")) { uint32_t slave_aggID = strtol(tok_val, NULL, 0); if(slave_aggID == aggID) { // remember that is the slave port that has the same aggregator ID as the bond aggregator_slave_nio = slave_nio; } } } } } if(aggregator_slave_nio && !gotActorID) { // go back and fill in the actorSystemID on all the slave ports shareActorIDFromSlave(sp, bond_nio, aggregator_slave_nio); } fclose(procFile); } }