// 获取属性文件中所有的值,成功返回0,失败返回非0值 int getValues(void *handle, char ***values, int *valuescount) { int ret = 0, count = 0, index = 0; PROPS_HANDLE *ph = NULL; Properties *pCurrent = NULL; char **pValues = NULL; if (handle == NULL || values == NULL || valuescount == NULL) { ret = -1; printf("fun getValues error:%d from (handle == NULL || values == NULL || valuescount == NULL)\n",ret); return ret; } // 获取配置项数量 ret = getCount(handle, &count); if (ret != 0) { printf("fun getValues error:%d from getCount \n",ret); return ret; } // 申请内存空间,存放所有的value pValues = (char **)malloc(sizeof(char *) * count); if (pValues == NULL) { ret = -2; printf("fun getValues error:%d from malloc values\n",ret); return ret; } ph = (PROPS_HANDLE *)handle; pCurrent = ph->pHead->pNext; while (pCurrent != NULL) { pValues[index] = pCurrent->value; pCurrent = pCurrent->pNext; index++; } *values = pValues; *valuescount = count; return ret; }
bool MessageQueue::checkGlobalExCommandList2() { ExCommand *ex, *ex1; for (uint i = 0; i < getCount(); i++) { ex = getExCommandByIndex(i); if (ex->_messageKind != 1 && ex->_messageKind != 20 && ex->_messageKind != 5 && ex->_messageKind != 27) continue; for (Common::List<ExCommand *>::iterator it = g_fp->_exCommandList.begin(); it != g_fp->_exCommandList.end();) { ex1 = *it; if (ex1->_messageKind != 1 && ex1->_messageKind != 20 && ex1->_messageKind != 5 && ex1->_messageKind != 27) { it++; continue; } if (ex1->_keyCode != ex->_keyCode && ex1->_keyCode != -1 && ex->_keyCode != -1) { it++; continue; } MessageQueue *mq = g_fp->_globalMessageQueueList->getMessageQueueById(ex1->_parId); if (mq) { if (mq->getFlags() & 1) return false; delete mq; } it = g_fp->_exCommandList.erase(it); if (ex1->_excFlags & 2) { delete ex1; } } } return true; }
void Item::serializeItem(const OutputBinaryTreePtr& out) { out->startNode(OTBM_ITEM); out->addU16(getServerId()); out->addU8(ATTR_COUNT); out->addU8(getCount()); out->addU8(ATTR_CHARGES); out->addU16(getCountOrSubType()); Position dest = m_attribs.get<Position>(ATTR_TELE_DEST); if(dest.isValid()) { out->addU8(ATTR_TELE_DEST); out->addPos(dest); } if(isDepot()) { out->addU8(ATTR_DEPOT_ID); out->addU16(getDepotId()); } uint16 aid = m_attribs.get<uint16>(ATTR_ACTION_ID); uint16 uid = m_attribs.get<uint16>(ATTR_UNIQUE_ID); if(aid) { out->addU8(ATTR_ACTION_ID); out->addU16(aid); } if(uid) { out->addU8(ATTR_UNIQUE_ID); out->addU16(uid); } out->endNode(); if(!m_containerItems.empty()) { for(auto c : m_containerItems) c->serializeItem(out); } }
StringData* StringData::MakeEmpty() { void* vpEmpty = &s_theEmptyString; auto const sd = static_cast<StringData*>(vpEmpty); auto const data = reinterpret_cast<char*>(sd + 1); sd->m_data = data; sd->m_hdr.init(HeaderKind::String, 0); sd->m_lenAndHash = 0; // len=0, hash=0 data[0] = 0; assert(sd->m_len == 0); assert(sd->m_hash == 0); assert(sd->capacity() == 0); assert(sd->m_hdr.kind == HeaderKind::String); assert(sd->getCount() == 0); sd->setStatic(); assert(sd->isFlat()); assert(sd->isStatic()); assert(sd->checkSane()); return sd; }
bool isDictScalar(ExpressionPtr exp) { if (!exp) return true; assertx(exp->is(Expression::KindOfExpressionList)); auto list = static_pointer_cast<ExpressionList>(exp); assertx(list->getListKind() == ExpressionList::ListKindParam); for (int i = 0; i < list->getCount(); ++i) { auto& itemExp = (*list)[i]; if (!itemExp) continue; assertx(itemExp->is(Expression::KindOfArrayPairExpression)); auto pair = static_pointer_cast<ArrayPairExpression>(itemExp); auto name = pair->getName(); Variant val; if (!name || !name->getScalarValue(val)) return false; if (!val.isString() && !val.isInteger()) return false; if (pair->getValue() && !pair->getValue()->isScalar()) return false; } return true; }
/* ============================================================================= * adtree_getCount * -- queryVector must consist of queries sorted by id * ============================================================================= */ long adtree_getCount (adtree_t* adtreePtr, vector_t* queryVectorPtr) { adtree_node_t* rootNodePtr = adtreePtr->rootNodePtr; if (rootNodePtr == NULL) { return 0; } long lastQueryIndex = -1L; long numQuery = vector_getSize(queryVectorPtr); if (numQuery > 0) { query_t* lastQueryPtr = (query_t*)vector_at(queryVectorPtr, (numQuery - 1)); lastQueryIndex = lastQueryPtr->index; } return getCount(rootNodePtr, -1, 0, queryVectorPtr, lastQueryIndex, adtreePtr); }
void DataCon<anyType>::findVessel(std::string pID) { if (getCount()>0) { anyType *data; _dataList.find(pID); data=_dataList.getCurrent(); if (data!=NULL) { data->display(); } else { std::cout<<"data not found"<<std::endl; } } else { std::cout<<"no data inside"<<std::endl; } }
void driverGuy(int code) { int x = code%10; if (isJack) { isHalt = 1; return; } queue *front = new queue; queue *rear = front; rear->next = NULL; if (getCount(myTree->root) > (3 * x)) { listLNR(myTree->root->pRight, rear); } else { isRiverCrossed = 1; isSoulLand = 0; listLNRleaf(myTree->root->pLeft, rear); } while (front->next != NULL) { queue *del = front; if (front->next->key == 888) { isBlackBeard = 0; isAVL = 0; } delNode(front->next->key); front = front->next; delete del; } delete front; }
void DataCon<anyType>::addSSB(std::string pVesselName, unsigned int pSignature, unsigned int pLength, unsigned int pMaxRange, unsigned int pMaxSpeed, unsigned int pMaxDisp, unsigned int pCrew, unsigned int pVessType, unsigned int pMaxDive, unsigned int pMaxSpeedSubmerge, unsigned int pDispSubmerge, unsigned int pTotalSLBM) { std::cout<<"adding Submarine SSB"<<std::endl; SSB *data=new SSB(pVesselName, pSignature, pLength, pMaxRange, pMaxSpeed, pMaxDisp, pCrew, pVessType, pMaxDive, pMaxSpeedSubmerge, pDispSubmerge, pTotalSLBM); _dataList.addToList(data); _count++; std::cout<<"input succesful"<<std::endl; std::cout<<getCount()<<std::endl; }
price_t Stock ::getMarketValue(const Datetime& datetime, KQuery::KType ktype) const{ if (isNull()) { return 0.0; } if (!valid()) { if (datetime > lastDatetime()) { return 0.0; } } KQuery query = KQueryByDate(datetime, Null<Datetime>(), ktype); price_t price = 0.0; size_t out_start, out_end; KRecord k; if (getIndexRange(query, out_start, out_end)) { //找到的是>=datetime的记录 k = getKRecord(out_start, ktype); if (k.datetime == datetime) { price = k.closePrice; } else { if (out_start != 0) { k = getKRecord(out_start - 1, ktype); price = k.closePrice; } } } else { //没有找到,则取最后一条记录 size_t total = getCount(ktype); if (total > 0) { price = getKRecord(total - 1, ktype).closePrice; } } return price; }
Message* WbemExecClient::_doRequest(HTTPMessage * request) { // ATTN-RK-P2-20020416: We should probably clear out the queue first. PEGASUS_ASSERT(getCount() == 0); // Shouldn't be any messages in our queue _httpConnection->enqueue(request); Uint64 startMilliseconds = TimeValue::getCurrentTime().toMilliseconds(); Uint64 nowMilliseconds = startMilliseconds; Uint64 stopMilliseconds = nowMilliseconds + _timeoutMilliseconds; while (nowMilliseconds < stopMilliseconds) { // // Wait until the timeout expires or an event occurs: // _monitor->run(Uint32(stopMilliseconds - nowMilliseconds)); // // Check to see if incoming queue has a message // Message* response = dequeue(); if (response) { return response; } nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds(); } // // Throw timed out exception: // throw ConnectionTimeoutException(); }
std::vector<gcRefPtr<UserCore::Misc::UploadInfoThreadI>> DesuraJSBinding::getUploads() { std::vector<gcRefPtr<UserCore::Misc::UploadInfoThreadI>> ret; auto um = GetUploadMng(); if (!um) return ret; size_t count = um->getCount(); for (size_t x=0; x<count; x++) { auto item = um->getItem(x); if (item->isDeleted()) continue; ret.push_back(item); } return ret; }
bool comboUC::remove(controlUC* pControl) { int iIndex = getItemIndex(pControl); if (iIndex == -1) return false; if (!containerUC::removeAt(iIndex)) return false; for(int i = iIndex; i < getCount(); ++i) { controlUC* p = getItemAt(i); IListItemUC* pListItem = static_cast<IListItemUC*>(p->getInterface(L"IListItem")); if( pListItem != NULL ) { pListItem->setIndex(i); } } if( iIndex == m_iCurSel && m_iCurSel >= 0 ) { int iSel = m_iCurSel; m_iCurSel = -1; selectItem(findSelectable(iSel, false)); } else if( iIndex < m_iCurSel ) m_iCurSel -= 1; return true; }
/** \sa timeElement, timeElement.clockAlarm */ inline void Timer::NextTick () { _presentTime = (_presentTime + 1) & 0x7fff; // Add one tick to clock. if (0 == getCount ()) return; // No timers. // Check for expired timers. while (_presentTime == GET_TIMEOUT (0)) { // Update the timed out timers... one timer each time through while loop. static_cast<p_timeElement>(_timeOutList[0])->updateTimeOut (); // Execute the CallBack function. static_cast<p_timeElement>(_timeOutList[0])->clockAlarm (); // Sort the list. for (uint8_t i=1; i < _timeOutList.GetCount (); i++) if (normalizeTimeOut (GET_TIMEOUT (i-1)) > normalizeTimeOut (GET_TIMEOUT (i))) _timeOutList.Swap (i-1, i); else break; } }
ArrayData *ZendArray::dequeue(Variant &value) { if (getCount() > 1) { ZendArray *a = copyImpl(); a->dequeue(value); return a; } // To match PHP-like semantics, we invalidate all strong iterators // when an element is removed from the beginning of the array if (!m_strongIterators.empty()) { freeStrongIterators(); } if (m_pListHead) { value = m_pListHead->data; erase(findForErase(m_pListHead)); renumber(); } else { value = null; } // To match PHP-like semantics, the dequeue operation resets the array's // internal iterator m_pos = (ssize_t)m_pListHead; return NULL; }
void Ball::draw() { glNewList(data, GL_COMPILE); int green = getCount() * 20; if (green > 255) green = 255; glColor3ub(55, 100, green); gluSphere(qobj, radius, 20, 20); if (!vel.isNull()) { glColor3ub(0, 255, 0); glRotatef(vel.angleXY(), 0, 0, 1); glBegin(GL_LINES); glVertex3f(0, 0, pos.z); glVertex3f(1, 0, pos.z); glEnd(); glBegin(GL_POLYGON); glVertex3f(1, 0, pos.z); glVertex3f(0.9, -.1, pos.z); glVertex3f(0.9, .1, pos.z); glEnd(); } }
void ListView::insertItem(int count, const wchar_t** items) { if (hWnd_ != NULL && count > 0 && items != nullptr) { LVITEMW item; item.mask = LVIF_TEXT; item.state = 0; item.stateMask = 0; item.iItem = getCount(); item.iSubItem = 0; item.pszText = const_cast<wchar_t*>(items[0]); ListView_InsertItem(hWnd_, &item); for (int i = 1; i < count; ++i) { item.iSubItem = i; item.pszText = const_cast<wchar_t*>(items[i]); ListView_SetItem(hWnd_, &item); } } }
int PR2ArmIKSolver::CartToJntSearch(const KDL::JntArray& q_in, const KDL::Frame& p_in, KDL::JntArray &q_out, const double &timeout) { KDL::JntArray q_init = q_in; double initial_guess = q_init(free_angle_); ros::Time start_time = ros::Time::now(); double loop_time = 0; int count = 0; int num_positive_increments = (int)((pr2_arm_ik_.solver_info_.limits[free_angle_].max_position-initial_guess)/search_discretization_angle_); int num_negative_increments = (int)((initial_guess-pr2_arm_ik_.solver_info_.limits[free_angle_].min_position)/search_discretization_angle_); ROS_DEBUG("%f %f %f %d %d \n\n",initial_guess,pr2_arm_ik_.solver_info_.limits[free_angle_].max_position,pr2_arm_ik_.solver_info_.limits[free_angle_].min_position,num_positive_increments,num_negative_increments); while(loop_time < timeout) { if(CartToJnt(q_init,p_in,q_out) > 0) return 1; if(!getCount(count,num_positive_increments,-num_negative_increments)) return -1; q_init(free_angle_) = initial_guess + search_discretization_angle_ * count; ROS_DEBUG("%d, %f",count,q_init(free_angle_)); loop_time = (ros::Time::now()-start_time).toSec(); } if(loop_time >= timeout) { ROS_DEBUG("IK Timed out in %f seconds",timeout); return TIMED_OUT; } else { ROS_DEBUG("No IK solution was found"); return NO_IK_SOLUTION; } return NO_IK_SOLUTION; }
vector<vector<int>> combinationSum2(vector<int>& cand, int target) { if (cand.size() == 0) return vector<vector<int>>(); // 1) the 5 lines below are addition from CombinationSum.cpp. vector<int> candidates; unordered_map<int, int> count; for (auto c : cand) { if (++ count[c] == 1) candidates.push_back(c); } sort(candidates.begin(), candidates.end()); vector<vector<vector<int>>> ans(1 + target); for (int i = 1; i <= target; ++ i) { for (int j = 0; j < candidates.size(); ++ j) { if (i < candidates[j]) break; else if (i == candidates[j]) { vector<int> v(1, i); ans[i].push_back(v); break; } else { vector<vector<int>> & u = ans[i - candidates[j]]; for (int k = 0, len = u.size(); k < len; ++ k) { if (candidates[j] >= u[k].back() && getCount(u[k], candidates[j]) < count[candidates[j]]) { // 2) the getCount() above is addition from CombinationSum.cpp. ans[i].push_back(u[k]); ans[i].back().push_back(candidates[j]); } } } } } return ans[target]; }
DisplayControlDynamicCaps DomainDisplayControl_001::createDisplayControlDynamicCaps(UIntN domainIndex) { auto displaySet = getDisplayControlSet(getParticipantIndex(), domainIndex); // Get dynamic caps // The caps are stored in BIOS as brightness percentage. They must be converted // to indices before they can be used. UIntN lowerLimitIndex = getLowerLimitIndex(domainIndex, displaySet); UIntN upperLimitIndex = getUpperLimitIndex(domainIndex, displaySet); auto size = displaySet.getCount(); if (upperLimitIndex >= size) { throw dptf_exception("Upper Limit index is out of control set bounds."); } else if (upperLimitIndex > lowerLimitIndex || lowerLimitIndex >= size) { lowerLimitIndex = size - 1; getParticipantServices()->writeMessageWarning( ParticipantMessage(FLF, "Limit index mismatch, ignoring lower limit.")); } return DisplayControlDynamicCaps(upperLimitIndex, lowerLimitIndex); }
// create either a static or an uncounted string. // Diffrence between static and uncounted is in the lifetime // of the string. Static are alive for the lifetime of the process. // Uncounted are not ref counted but will be deleted at some point. ALWAYS_INLINE StringData* StringData::MakeShared(StringSlice sl, bool trueStatic) { if (UNLIKELY(sl.len > StringData::MaxSize)) { throw_string_too_large(sl.len); } auto const cc = CapCode::ceil(sl.len); auto const need = cc.decode() + kCapOverhead; auto const sd = static_cast<StringData*>( trueStatic ? low_malloc(need) : malloc(need) ); auto const data = reinterpret_cast<char*>(sd + 1); sd->m_data = data; sd->m_hdr.init(cc, HeaderKind::String, 0); sd->m_lenAndHash = sl.len; // hash=0 data[sl.len] = 0; auto const mcret = memcpy(data, sl.ptr, sl.len); auto const ret = reinterpret_cast<StringData*>(mcret) - 1; // Recalculating ret from mcret avoids a spill. assert(ret->m_hash == 0); assert(ret->getCount() == 0); if (trueStatic) { ret->setStatic(); } else { ret->setUncounted(); } assert(ret == sd); assert(ret->isFlat()); assert(trueStatic ? ret->isStatic() : ret->isUncounted()); assert(ret->checkSane()); return ret; }
ArrayData *VectorArray::pop(Variant &value) { if (UNLIKELY(!m_size)) { value.setNull(); return nullptr; } if (UNLIKELY(getCount() > 1)) { value = tvAsCVarRef(&m_elems[m_size - 1]); if (m_size == 1) { return StaticEmptyVectorArray::Get(); } VectorArray *a = NEW(VectorArray)(this, 0, m_size - 1); a->m_pos = (ssize_t)0; return a; } ssize_t pos = m_size - 1; value = tvAsCVarRef(&m_elems[pos]); tvAsVariant(&m_elems[pos]).~Variant(); assert(m_size && pos == m_size - 1L); m_size--; // To match PHP-like semantics, the pop operation resets the array's // internal iterator m_pos = m_size ? (ssize_t)0 : ArrayData::invalid_index; return nullptr; }
void FileInfoListView::addRange(FileInfo **filesInfo, size_t count) { int index = max(0, (getCount() - 1)); size_t i = 0; FileInfo *arr = *filesInfo; // Add folders first for (i = 0; i < count; i++) { FileInfo *fi = &arr[i]; if (fi->isDirectory()) { addItem(index++, fi); } // if directory } // for all files info // Add files for (i = 0; i < count; i++) { FileInfo *fi = &arr[i]; if (!fi->isDirectory()) { addItem(index++, fi); } // if not directory } // for all files info ListView::sort(); } // void
void Audio::fill(unsigned char *addr, int samples, Encoding encoding) { int frame = getFrame(encoding); int count = getCount(encoding); if(!frame || !count) return; while(samples >= count) { switch(encoding) { case mulawAudio: *addr = 0xff; break; case alawAudio: *addr = 0x55; break; default: memset(addr, 0, frame); break; } addr += frame; samples -= count; } }
void AntManager::step(int step) { if(!isInitialized) { while(foodGenerator != food_iterator()) { auto f = *foodGenerator; food[f->getPoint().y][f->getPoint().x] = f->getCount(); foodGenerator++; } isInitialized = true; } gui->BeginPaint(); for(int i = 0; i < height; ++i) for(int j = 0; j < width; ++j) gui->SetFood(antgui::ConcreteFood(antgui::Point(j, i), food[i][j])); for(int i = 0; i < height; ++i) for(int j = 0; j < width; ++j) for(auto &Ant : ants[i][j]) gui->SetAnt(*(Ant->getGui())); gui->EndPaint(); for(int i = 0; i < teamCount; ++i) { if(antCount[i] < maxAntCountPerTeam && step - antSpawn[i] > 10) { antCount[i]++; antSpawn[i] = step; ants[antRespawnPos[i].y][antRespawnPos[i].x].insert(std::shared_ptr<AntObject>(new AntObject(antRespawnPos[i], i))); } } for(int team = 0; team < teamCount; ++team) { for(int y = 0; y < height; ++y) { for(int x = 0; x < width; ++x) { auto safeIter = ants[y][x]; for(auto & AntPtr : safeIter) { if(AntPtr->getTeamId() == team && AntPtr->getFlag() == false && !AntPtr->isFrozen()) { std::cout << "Processing ant : team = " << team << std::endl; std::shared_ptr<antlogic::IAntLogic> logic = antlogic::IAntLogic::GetAntLogic(AntPtr->getTeamId()); antlogic::AntSensor sensor[3][3]; for(int dy = -1; dy <= 1; ++dy) { for(int dx = -1; dx <= 1; ++dx) { int cx = x + dx; int cy = y + dy; point pos(cx, cy); #define SENSOR sensor[dx+1][dy+1] if(!inrange(cx, cy)) SENSOR.isWall = true; else { if(food[cy][cx] > 0) SENSOR.isFood = true; auto it = std::find(antRespawnPos.begin(), antRespawnPos.end(), pos); if(it != antRespawnPos.end()) { if(it - antRespawnPos.begin() == team) SENSOR.isMyHill = true; else SENSOR.isEnemyHill = true; } std::set<std::shared_ptr<AntObject> > Ants = ants[cy][cx]; for(auto &Ant : Ants) { if(Ant->getTeamId() == AntPtr->getTeamId()) SENSOR.isFriend = true; else SENSOR.isEnemy = true; } SENSOR.smell = smell[cy][cx].first; SENSOR.smellIntensity = smell[cy][cx].second; } } } antlogic::AntAction res = logic->GetAction(*AntPtr->getLogic(), sensor); if(res.putSmell) { smell[y][x].first = res.smell; smell[y][x].second = 100; } //std::cout << "y=" << y << " x=" << x << " action = " << res.actionType << std::endl; //std::cout << "MEMORY : "; //for(int i = 0; i < antlogic::MAX_MEMORY; ++i) // std::cout << (int)AntPtr->getMemory()[i] << " "; //std::cout << std::endl; switch(res.actionType) { case antlogic::AntActionType::MOVE_UP: if(!AntObject::go(AntPtr, 0, -1)) std::cout << "MOVE_UP failed" << std::endl; break; case antlogic::AntActionType::MOVE_LEFT: if(!AntObject::go(AntPtr, -1, 0)) std::cout << "MOVE_LEFT failed" << std::endl; break; case antlogic::AntActionType::MOVE_DOWN: if(!AntObject::go(AntPtr, 0, 1)) std::cout << "MOVE_DOWN failed" << std::endl; break; case antlogic::AntActionType::MOVE_RIGHT: if(!AntObject::go(AntPtr, 1, 0)) std::cout << "MOVE_RIGHT failed" << std::endl; break; case antlogic::AntActionType::BITE_UP: if(!AntObject::bite(AntPtr, 0, -1)) std::cout << "BITE_UP failed" << std::endl; break; case antlogic::AntActionType::BITE_LEFT: if(!AntObject::bite(AntPtr, -1, 0)) std::cout << "BITE_LEFT failed" << std::endl; break; case antlogic::AntActionType::BITE_DOWN: if(!AntObject::bite(AntPtr, 0, 1)) std::cout << "BITE_DOWN failed" << std::endl; break; case antlogic::AntActionType::BITE_RIGHT: if(!AntObject::bite(AntPtr, 1, 0)) std::cout << "BITE_RIGHT failed" << std::endl; break; case antlogic::AntActionType::GET: if(food[y][x] > 0) { AntPtr->chFood() = true; food[y][x]--; } else { std::cout << "CHEATER. No food at this point" << std::endl; } break; case antlogic::AntActionType::PUT: if(AntPtr->chFood() == true) { food[y][x]++; AntPtr->chFood() = false; } else { std::cout << "CHEATER. Ant without food tried to place food" << std::endl; } break; } AntPtr->getFlag() = true; } } } } } std::cout << "done\n"; for(int i = 0; i < height; ++i) { for(int j = 0; j < width; ++j) { for(auto & AntPtr : ants[i][j]) { AntPtr->update(); } } } // scoreboard for (unsigned int t = 0; t < teamCount; t++) { gui->SetTeamScore(t, food[antRespawnPos[t].y][antRespawnPos[t].x]); } }
int main(void) { int i; int j; int data; int data2=0; char in = 0; i = 0x0000000004000500; int numBad = 1; int count; long long cpi; volatile void *wptr; short leds = 0; char capInit = 0; //mv1kC1(0x9800000040000000, 0x9800000000001000); //setInterrupts(); //__writeStringLoopback("Stack TLB entry setup.\n"); __writeString("Hello World! Have a BERI nice day!\n"); //debugTlb(); //cp0Regs(); // causeTrap(); // __writeString("Came back from trap and still alive :)\n"); // sysCtrlTest(); // data = rdtscl(5); //int coreid = getCoreID(); /* if (coreid == 0) { delay(); coreCount++; } else { coreCount++; } */ while(in != 'Q') { if (in != '\n') { //if (coreid == 0) { globalReset = 0; coreFlag = 0; __writeString("\n Number of Cores in Use : "); __writeHex(coreCount); __writeString("\n Menu:\n"); __writeString(" \"F\" for floating point co-processor test.\n"); __writeString(" \"L\" for load-linked and store-conditional test.\n"); __writeString(" \"A\" for arithmetic test result.\n"); __writeString(" \"B\" array bounds checking benchmark.\n"); __writeString(" \"D\" for multiply and divide test.\n"); __writeString(" \"C\" for Count register test.\n"); __writeString(" \"M\" for eternal memory test.\n"); //__writeString(" \"N\" for networking test.\n"); __writeString(" \"V\" for framebuffer test.\n"); __writeString(" \"K\" for Capability initialization.\n"); __writeString(" \"l\" to invert LEDs.\n"); __writeString(" \"T\" for touchscreen test.\n"); __writeString(" \"q\" for quicksort boundschecking test.\n"); __writeString(" \"d\" for domain crossing benchmark.\n"); __writeString(" \"G\" for compositor test.\n"); __writeString(" \"Q\" to quit.\n"); } } in = __readUARTChar(); __writeUARTChar(in); __writeString("\n"); //__writeHex(in); //__writeString("\n"); if (in == 'F') { __writeString("Floating Point co-processor test\n"); CoProFPTest(); } if (in == 'L') { __writeString("Load-linked and store-conditional test:\n"); data = 13; data = ll(&data); data = sc(&data, 14); //__writeHex(data); __writeString(" < load-linked and store-conditional result (0)\n"); data = testNset(&data, 14); //__writeHex(data); __writeString(" < test and set result (1)\n"); } if (in == 'A') { __writeString("Arithmetic test:\n"); data = 0; data = arithmaticTest(); __writeHex(data); __writeString(" < arithmetic test result (0)\n"); } if (in == 'T') { int * tX= (int *)0x9000000005000000; int * tY= (int *)0x9000000005000004; int * tDown= (int *)0x9000000005000008; __writeString("X:"); data = *tX; __writeHex(data); __writeString(" Y:"); data = *tY; __writeHex(data); __writeString(" Down:"); data = *tDown; __writeHex(data); __writeString("\n"); } if (in == 'G') { __writeString("Compositor test:\n"); } if (in == 'D') { numBad = 1; __writeString("Multiply and divide test.\n"); for (i = -10; i < 10; i++) { data = numBad * i; __writeHex(numBad); __writeString(" * "); __writeHex(i); __writeString(" = "); __writeHex(data); __writeString("\n"); if (i!=0) data2 = data / i; __writeHex(data); __writeString(" / "); __writeHex(i); __writeString(" = "); __writeHex(data2); __writeString("\n"); __writeString("\n"); if (data == 0) data = 1; numBad = data; } } if (in == 'M') { __writeString("Memory test:\n"); i = 0; while(1) { count = getCount(); //__writeString("count:"); //__writeHex(count); //__writeString("\n"); int idx = 0; for (j=0; j<0x4000; j++) { idx = i+j; ((volatile int *)DRAM_BASE)[idx] = DRAM_BASE + (idx<<2); } for (j=0; j<0x4000; j++) { idx = i+j; data = ((volatile int *)DRAM_BASE)[idx]; if (data != (int)(DRAM_BASE + (idx<<2))) { //__writeHex((int)(DRAM_BASE + (idx<<2))); //__writeString(" = "); //__writeHex(data); //__writeString("?\n"); numBad++; } } cpi = getCount() - count; //__writeString("newCount - count:"); //__writeHex(cpi); //__writeString("\n"); __writeHex((int)(DRAM_BASE + (idx<<2))); __writeString(" = "); __writeHex(data); __writeString("?\n"); if (numBad == 0) { __writeString("All good! \n"); } else { __writeHex(numBad); __writeString(" were bad :(\n"); numBad = 0; } cpi = (cpi*1000); //__writeString("diff*1000:"); //__writeHex(cpi); //__writeString("\n"); // 8 instructions in the first loop, 12 in the second. cpi = cpi/((8+12)*0x4000); __writeString("CPI of "); __writeDigit(cpi); __writeString("\n"); i+=0x4000; if (i > 0x07000000) i = 0; } } if (in == 'C') { __writeString("Count Register Test:\n"); for(i=0;i<10;i++) { data = ((volatile int *)MIPS_PHYS_TO_UNCACHED(CHERI_COUNT))[0]; __writeHex(data); __writeString(", "); } __writeString("\n"); } if (in == 'K') { if (capInit==0) { FBIncBase(0x9000000004000000); long length = FBGetLeng(); length = length - 800*600*2; FBDecLeng(length); capInit = 1; } __writeString("C4.base= ");__writeHex(FBGetBase());__writeString("\n"); __writeString("C4.length= ");__writeHex(FBGetLeng());__writeString("\n"); CapRegDump(); } if (in == 'V') { int color = 0x8888; int x = 50; int y = 50; int length = 75; int height = 50; long frameBuff = 0x9000000004000000; for (x=200; x<500; x+=100) { for (y=300; y<500; y+=75) { draw3DRect(color, x, y, length, height); } } for (i=0; i<(800*600/4); i++) { FBSDR(0x0C63F80007E0001F,i<<3); } int offset = y*800 + x; int addOff; int totOff; for (i=0; i<(800*600); i++) { ((volatile short*)frameBuff)[i] = i; } for (i=0; i<height; i++) { for (j=0; j<length; j++) { addOff = (800*i) + j; totOff = (offset+addOff); ((volatile short*)frameBuff)[totOff] = color; } } } if (in == 'l') { leds = ~leds; IO_WR(CHERI_LEDS,leds); } if (in == 'N') { wptr = (void *)CHERI_NET_RX; i = *(volatile int *)wptr; __writeString("After accessing CHERI_NET_RX, read:\n"); __writeDigit(i); i = 0xabcd; wptr = (void *)CHERI_NET_TX; __writeString("Before writing 123 to CHERI_NET_TX\n"); *((volatile int *)CHERI_NET_TX) = i; __writeString("After writing 123 to CHERI_NET_TX\n"); } if (in == 'B') { arrayBench(); } if (in == 'q') { doQuicksort(); } if (in == 'd') { armArray(); } // ADDED >> if (in == 'X') { int A[SORT_SIZE]; writeString("Branch Exercise:\n"); fillArray(A, SORT_SIZE/2, 1000); bubbleSort(A, SORT_SIZE/2); writeString("Finished Bubble Sort!\n"); for (i = 0; i<SORT_SIZE/2; i+= SORT_SIZE/2/32) { writeHex(i); writeString(" = "); writeHex(A[i]); writeString("\n"); } fillArray(A, SORT_SIZE, 1234); quickSort(A, 0, SORT_SIZE); writeString("Finished Quick Sort!\n"); for (i = 0; i<SORT_SIZE; i+= SORT_SIZE/32) { writeHex(i); writeString(" = "); writeHex(A[i]); writeString("\n"); } writeString("Searching for each element...\n"); for (j = 0; j<4; j++) { for (i = 0; i<SORT_SIZE; i++) { binarySearch(A, A[i], 0, SORT_SIZE); } } writeString("Searching Done.\n"); writeString("Starting Modular Eponentiation\n"); for (i = 0; i<SORT_SIZE/4; i++) { writeHex(modExp(i,0xAAAAAAAAAAAAAAAA)); writeString("\n"); } } // ADDED << //debugRegs(); } return 0; }
/** * @brief Dump the scan results to the log. */ void BLEScanResults::dump() { ESP_LOGD(LOG_TAG, ">> Dump scan results:"); for (int i=0; i<getCount(); i++) { ESP_LOGD(LOG_TAG, "- %s", getDevice(i).toString().c_str()); } } // dump
Audio::Level Audio::peak(Info &info, void *buffer, unsigned samples) { Level max = 0, value; unsigned long count; Sample *sp, mb; snd16_t *up, ub; unsigned char *sv = (unsigned char *)&mb, *s1, *s2; unsigned char *uv = (unsigned char *)&ub; if(!samples) samples = info.framecount; if(!samples) samples = getCount(info.encoding); switch(info.encoding) { case cdaStereo: case pcm16Stereo: samples *= 2; case pcm16Mono: case cdaMono: count = samples; if(info.format == snd && (info.order == __BYTE_ORDER || !info.order)) { count *= 2; up = (snd16_t *)buffer; while(samples--) { value = (Level)(*(up++) / 2); if(value > max) max = value; } return max; } if(info.format == snd) { count *= 2; s1 = (unsigned char *)buffer; s2 = s1 + 1; while(samples--) { uv[0] = *s2; uv[1] = *s1; s2 += 2; s1 += 2; ub /= 2; if((Level)ub > max) max = ub; } return max; } if(__BYTE_ORDER == info.order || !info.order) { sp = (Linear)buffer; while(samples--) { value = *(sp++); if(value < 0) value = -value; if(value > max) max = value; } return max; } s1 = (unsigned char *)buffer; s2 = s1 + 1; while(samples--) { sv[0] = *s2; sv[1] = *s1; s1 += 2; s2 += 2; if(mb < 0) mb = -mb; if(mb > max) max = mb; } return max; default: return -1; } }
Audio::Level Audio::impulse(Info &info, void *buffer, unsigned samples) { unsigned long sum = 0; unsigned long count; Sample *sp, mb; snd16_t *up, ub; unsigned char *sv = (unsigned char *)&mb, *s1, *s2; unsigned char *uv = (unsigned char *)&ub; if(!samples) samples = info.framecount; if(!samples) samples = getCount(info.encoding); if(!samples) return 0; switch(info.encoding) { case cdaStereo: case pcm16Stereo: samples *= 2; case pcm16Mono: case cdaMono: count = samples; if(info.format == snd && (info.order == __BYTE_ORDER || !info.order)) { count *= 2; up = (snd16_t *)buffer; while(samples--) sum += *(up++); return (Level)(sum / count); } if(info.format == snd) { count *= 2; s1 = (unsigned char *)buffer; s2 = s1 + 1; while(samples--) { uv[0] = *s2; uv[1] = *s1; s2 += 2; s1 += 2; sum += ub; } return (Level)(sum / count); } if(__BYTE_ORDER == info.order || !info.order) { sp = (Linear)buffer; while(samples--) { if(*sp < 0) sum -= *(sp++); else sum += *(sp++); } return (Level)(sum/count); } s1 = (unsigned char *)buffer; s2 = s1 + 1; while(samples--) { sv[0] = *s2; sv[1] = *s1; s1 += 2; s2 += 2; if(mb < 0) sum -= mb; else sum += mb; } return (Level)(sum / count); default: return -1; } }
bool end() const { return index_ >= length_ || getCount() == 0; }