本文整理汇总了C++中scan函数的典型用法代码示例。如果您正苦于以下问题:C++ scan函数的具体用法?C++ scan怎么用?C++ scan使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了scan函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_for
void do_for (void)
/***** do_for
do a for command in a UDF.
for i=value to value step value; .... ; end
*****/
{ int h,signum;
char name[16],*jump;
header *hd,*init,*end,*step;
double vend,vstep;
struct { header hd; double value; } rv;
if (!udfon)
{ output("For only allowed in functions!\n"); error=57; return;
}
rv.hd.type=s_real; *rv.hd.name=0;
rv.hd.size=sizeof(header)+sizeof(double); rv.value=0.0;
scan_space(); scan_name(name); if (error) return;
kill_local(name);
newram=endlocal;
hd=new_reference(&rv.hd,name); if (error) return;
endlocal=newram=(char *)hd+hd->size;
scan_space(); if (*next!='=')
{ output("Syntax error in for.\n"); error=71; goto end;
}
next++; init=scan(); if (error) goto end;
init=getvalue(init); if (error) goto end;
if (init->type!=s_real)
{ output("Startvalue must be real!\n"); error=72; goto end;
}
rv.value=*realof(init);
scan_space(); if (strncmp(next,"to",2))
{ output("Endvalue missing in for!\n"); error=73; goto end;
}
next+=2;
end=scan(); if (error) goto end;
end=getvalue(end); if (error) goto end;
if (end->type!=s_real)
{ output("Endvalue must be real!\n"); error=73; goto end;
}
vend=*realof(end);
scan_space();
if (!strncmp(next,"step",4))
{ next+=4;
step=scan(); if (error) goto end;
step=getvalue(step); if (error) goto end;
if (step->type!=s_real)
{ output("Stepvalue must be real!\n"); error=73; goto end;
}
vstep=*realof(step);
}
else vstep=1.0;
signum=(vstep>=0)?1:-1;
vend=vend+signum*epsilon;
if (signum>0 && rv.value>vend) { scan_end(); goto end; }
else if (signum<0 && rv.value<vend) { scan_end(); goto end; }
newram=endlocal;
scan_space(); if (*next==';' || *next==',') next++;
jump=next;
while (!error)
{ if (*next==1)
{ output("End missing!\n");
error=401; goto end;
}
h=command();
if (udfon!=1 || h==c_return) break;
if (h==c_break) { scan_end(); break; }
if (h==c_end)
{ rv.value+=vstep;
if (signum>0 && rv.value>vend) break;
else if (signum<0 && rv.value<vend) break;
else next=jump;
if (test_key()==escape)
{ output("User interrupted!\n");
error=1; break;
}
}
}
end : kill_local(name);
}
示例2: debugme
void debugme(void) {
proutn("Reset levels? ");
if (ja() != 0) {
if (energy < inenrg) energy = inenrg;
shield = inshld;
torps = intorps;
lsupres = inlsr;
}
proutn("Reset damage? ");
if (ja() != 0) {
int i;
for (i=0; i <= ndevice; i++) if (damage[i] > 0.0) damage[i] = 0.0;
stdamtim = 1e30;
}
proutn("Toggle idebug? ");
if (ja() != 0) {
idebug = !idebug;
if (idebug) prout("Debug output ON");
else prout("Debug output OFF");
}
proutn("Cause selective damage? ");
if (ja() != 0) {
int i, key;
for (i=1; i <= ndevice; i++) {
proutn("Kill ");
proutn(device[i]);
proutn("? ");
chew();
key = scan();
if (key == IHALPHA && isit("y")) {
damage[i] = 10.0;
if (i == DRADIO) stdamtim = d.date;
}
}
}
proutn("Examine/change events? ");
if (ja() != 0) {
int i;
for (i = 1; i < NEVENTS; i++) {
int key;
if (future[i] == 1e30) continue;
switch (i) {
case FSNOVA: proutn("Supernova "); break;
case FTBEAM: proutn("T Beam "); break;
case FSNAP: proutn("Snapshot "); break;
case FBATTAK: proutn("Base Attack "); break;
case FCDBAS: proutn("Base Destroy "); break;
case FSCMOVE: proutn("SC Move "); break;
case FSCDBAS: proutn("SC Base Destroy "); break;
}
cramf(future[i]-d.date, 8, 2);
chew();
proutn(" ?");
key = scan();
if (key == IHREAL) {
future[i] = d.date + aaitem;
}
}
chew();
}
}
示例3: scan
lexer::~lexer() {
if (state != eof) {
scan('\0');
}
}
示例4: def_program
static void
def_program(definition *defp)
{
token tok;
version_list *vlist;
version_list **vtailp;
proc_list *plist;
proc_list **ptailp;
defp->def_kind = DEF_PROGRAM;
scan(TOK_IDENT, &tok);
defp->def_name = tok.str;
scan(TOK_LBRACE, &tok);
vtailp = &defp->def.pr.versions;
scan(TOK_VERSION, &tok);
do {
scan(TOK_IDENT, &tok);
vlist = ALLOC(version_list);
vlist->vers_name = tok.str;
scan(TOK_LBRACE, &tok);
ptailp = &vlist->procs;
do {
plist = ALLOC(proc_list);
plist->next = NULL;
get_type(&plist->res_prefix, &plist->res_type, DEF_PROGRAM);
if (streq(plist->res_type, "opaque")) {
error("illegal result type");
}
scan(TOK_IDENT, &tok);
plist->proc_name = tok.str;
scan(TOK_LPAREN, &tok);
get_type(&plist->arg_prefix, &plist->arg_type, DEF_PROGRAM);
if (streq(plist->arg_type, "opaque")) {
error("illegal argument type");
}
scan(TOK_RPAREN, &tok);
scan(TOK_EQUAL, &tok);
scan_num(&tok);
scan(TOK_SEMICOLON, &tok);
plist->proc_num = tok.str;
*ptailp = plist;
ptailp = &plist->next;
peek(&tok);
} while (tok.kind != TOK_RBRACE);
*vtailp = vlist;
vtailp = &vlist->next;
scan(TOK_RBRACE, &tok);
scan(TOK_EQUAL, &tok);
scan_num(&tok);
vlist->vers_num = tok.str;
scan(TOK_SEMICOLON, &tok);
scan2(TOK_VERSION, TOK_RBRACE, &tok);
} while (tok.kind == TOK_VERSION);
scan(TOK_EQUAL, &tok);
scan_num(&tok);
defp->def.pr.prog_num = tok.str;
*vtailp = NULL;
}
示例5: helpme
static void helpme(void) {
int i, j;
char cmdbuf[32];
char linebuf[132];
FILE *fp;
/* Give help on commands */
int key;
key = scan();
while (TRUE) {
if (key == IHEOL) {
proutn("Help on what command?");
key = scan();
}
if (key == IHEOL) return;
for (i = 0; i < NUMCOMMANDS; i++) {
if (strcmp(commands[i], citem)==0) break;
}
if (i != NUMCOMMANDS) break;
skip(1);
prout("Valid commands:");
listCommands(FALSE);
key = IHEOL;
chew();
skip(1);
}
if (i == 23) {
strcpy(cmdbuf, " ABBREV");
}
else {
strcpy(cmdbuf, " Mnemonic: ");
j = 0;
while ((cmdbuf[j+13] = toupper(commands[i][j])) != 0) j++;
}
fp = fopen("sst.doc", "r");
if (fp == NULL) {
prout("Spock- \"Captain, that information is missing from the");
prout(" computer. You need to find SST.DOC and put it in the");
prout(" current directory.\"");
return;
}
i = strlen(cmdbuf);
do {
if (fgets(linebuf, 132, fp) == NULL) {
prout("Spock- \"Captain, there is no information on that command.\"");
fclose(fp);
return;
}
} while (strncmp(linebuf, cmdbuf, i) != 0);
skip(1);
prout("Spock- \"Captain, I've found the following information:\"");
skip(1);
do {
if (linebuf[0]!=12) { // ignore page break lines
linebuf[strlen(linebuf)-1] = '\0'; // No \n at end
prout(linebuf);
}
fgets(linebuf,132,fp);
} while (strstr(linebuf, "******")==NULL);
fclose(fp);
}
示例6: exec
static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
{
int dev_func;
mode_config_proto_t* proto = &con->mode->proto;
int action, period, continuous, t;
action = 0;
period = 1000;
continuous = FALSE;
for (t = token_pos; p->tokens[t]; t++) {
switch (p->tokens[t]) {
case T_SHOW:
t += show(con, p);
break;
case T_TYPEA:
proto->dev_function = NFC_TYPEA;
break;
case T_VICINITY:
proto->dev_function = NFC_VICINITY;
break;
case T_PERIOD:
t += 2;
memcpy(&period, p->buf + p->tokens[t], sizeof(int));
break;
case T_CONTINUOUS:
continuous = TRUE;
break;
case T_SCAN:
case T_SNIFF:
case T_SNIFF_DBG:
case T_EMUL_MIFARE:
case T_EMUL_ISO14443A:
action = p->tokens[t];
break;
}
}
if (action == T_SCAN) {
dev_func = proto->dev_function;
if( (dev_func == NFC_TYPEA) || (dev_func == NFC_VICINITY) ) {
if (continuous) {
cprintf(con, "Scanning %s ",
proto->dev_function == NFC_TYPEA ? "MIFARE" : "Vicinity");
cprintf(con, "with %dms period. Press user button to stop.\r\n", period);
while (!USER_BUTTON) {
scan(con);
chThdSleepMilliseconds(period);
}
} else {
scan(con);
}
} else {
cprintf(con, "Please select MIFARE or Vicinity mode first.\r\n");
return 0;
}
} else if (action == T_SNIFF) {
hydranfc_sniff_14443A(con);
} else if (action == T_SNIFF_DBG) {
hydranfc_sniff_14443A_dbg(con);
} else if (action == T_EMUL_MIFARE) {
hydranfc_emul_mifare(con);
} else if (action == T_EMUL_ISO14443A)
hydranfc_emul_iso14443a(con);
return t - token_pos;
}
示例7: eval
//.........这里部分代码省略.........
v = exeval(ex, expr->data.call.procedure->value->data.procedure.body, env);
for (n = 0, a = expr->data.call.procedure->value->data.procedure.args; a && n < elementsof(save); a = a->data.operand.right)
a->data.operand.left->data.variable.symbol->value->data.constant.value = save[n++];
return v;
case FUNCTION:
n = 0;
args[n++].string = (char*)env;
for (x = expr->data.operand.right; x && n < elementsof(args); x = x->data.operand.right)
args[n++] = eval(ex, x->data.operand.left, env);
return (*ex->disc->getf)(ex, expr->data.operand.left, expr->data.operand.left->data.variable.symbol, expr->data.operand.left->data.variable.reference, args+1, EX_CALL, ex->disc);
case ID:
if (expr->data.variable.index)
i = eval(ex, expr->data.variable.index, env);
else
i.integer = EX_SCALAR;
return (*ex->disc->getf)(ex, expr, expr->data.variable.symbol, expr->data.variable.reference, env, (int)i.integer, ex->disc);
case INC:
n = 1;
goto add;
case PRINTF:
v.integer = print(ex, expr, env, NiL);
return v;
case QUERY:
print(ex, expr, env, sfstderr);
v.integer = !astquery(2, "");
return v;
case RETURN:
ex->loopret = eval(ex, x, env);
ex->loopcount = 32767;
ex->loopop = expr->op;
return ex->loopret;
case SCANF:
case SSCANF:
v.integer = scan(ex, expr, env, NiL);
return v;
case SPRINTF:
print(ex, expr, env, ex->tmp);
v.string = exstash(ex->tmp, ex->ve);
return v;
case '=':
v = eval(ex, expr->data.operand.right, env);
if (expr->subop != '=')
{
r = v;
if (x->op == DYNAMIC)
v = getdyn(ex, x, env, &assoc);
else
{
if (x->data.variable.index)
v = eval(ex, x->data.variable.index, env);
else
v.integer = EX_SCALAR;
v = (*ex->disc->getf)(ex, x, x->data.variable.symbol, x->data.variable.reference, env, (int)v.integer, ex->disc);
}
switch (x->type)
{
case FLOATING:
switch (expr->subop)
{
case '+':
v.floating += r.floating;
break;
case '-':
v.floating -= r.floating;
break;
case '*':
示例8: main
void main(void)
{
char local_map[9][9]; /* Buffer to hold the local map */
int x_pos, /* Current X and Y coordinates of robot */
y_pos;
int go_dir; /* current direction (index to angle[]) */
int scan_angle=0; /* Current scanning angle */
int range; /* range returned from the scan routine */
int try;
/* Configure robot - all normal settings in this case
* This *MUST* be the first special function called by the robot */
configure(2,2,2,2,2,0);
randomize();
go_dir=random(8); /* Select initial direction */
/* Note - this is an *INFINITE* loop - the PCROBOTS executive program
kills the robot off when necessary*/
while(1)
{
/* Get the current position */
getxy(&x_pos,&y_pos);
/* Get a map of the local area */
get_local_map((char *)local_map);
/* Quick and easy way of dealing with the robot being near an outside wall */
if (x_pos<20)
go_dir=(random(3)-1)%8;
if (x_pos>=980)
go_dir=random(3)+3;
if (y_pos<20)
go_dir=random(3)+1;
if (y_pos>=980)
go_dir=random(3)+5;
try=0;
/* Look for a square which hasn't got a wall in it (ignore traps in this
* simple program) */
while (local_map[angle[go_dir].y][angle[go_dir].x] == ARENA_WALL)
{
go_dir=random(8);
/* Failsafe check to avoid the program getting trapped here */
if (try++ > 10)
break;
}
/* Move in the new direction */
movement(50,angle[go_dir].angle);
/* Check if target found, shoot at it if so, otherwise go to next angle */
if (scan(scan_angle,5,&range)>=0)
{
if(!shells_left()) buy_shells(1);
shoot(scan_angle,range);
}
else
scan_angle=(scan_angle+5)%360;
}
}
示例10: KLOP_GetAdapterList
std::list<ADAPTER_INFO>
KLOP_GetAdapterList()
{
std::list<ADAPTER_INFO> RetList;
ADAPTER_INFO AI;
HKEY hKey = NULL;
FILETIME ftLastWriteTime; // last write time
CHAR achKey[MAX_PATH];
wchar_t wchKey[MAX_PATH];
ULONG KeyLength;
int i;
DWORD retCode;
if ( KLOP_isWinNT() )
{
/*
if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, NT_ADAPTERS_KEY, &hKey ) )
{
for (i = 0, retCode = ERROR_SUCCESS; retCode == ERROR_SUCCESS; i++ )
{
KeyLength = MAX_PATH;
retCode = RegEnumKeyExW(hKey, i, wchKey, &KeyLength, NULL, NULL, NULL, &ftLastWriteTime );
if ( ERROR_SUCCESS == retCode )
{
memset ( &AI , 0, sizeof ( AI ) );
wcscpy ( (wchar_t*)AI.AdapterBuffer, L"\\Device\\");
wcscat ( (wchar_t*)AI.AdapterBuffer, wchKey );
AI.AdapterNameSize = ( wcslen ( (wchar_t*)AI.AdapterBuffer ) + 1 ) << 1;
AI.LocalIp = 0;
RetList.push_back( AI );
}
}
}
else
*/
{
// Winnt4.0
if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards", &hKey ) )
{
for ( i = 0, retCode = ERROR_SUCCESS; retCode == ERROR_SUCCESS; i++ )
{
HKEY hSubKey = NULL;
KeyLength = MAX_PATH;
retCode = RegEnumKeyExW(hKey, i, wchKey, &KeyLength, NULL, NULL, NULL, &ftLastWriteTime );
if ( retCode == ERROR_SUCCESS )
{
retCode = RegOpenKeyW(hKey, wchKey, &hSubKey );
}
if ( retCode == ERROR_SUCCESS )
{
KeyLength = MAX_PATH;
DWORD type = REG_SZ;
if ( ERROR_SUCCESS == RegQueryValueExW(
hSubKey,
L"ServiceName",
NULL,
&type,
(LPBYTE)wchKey,
(ULONG*)&KeyLength ) )
{
memset ( &AI , 0, sizeof ( AI ) );
wcscpy ( (wchar_t*)AI.AdapterBuffer, L"\\Device\\");
wcscat ( (wchar_t*)AI.AdapterBuffer, wchKey );
AI.AdapterNameSize = ( wcslen ( (wchar_t*)AI.AdapterBuffer ) + 1 ) << 1;
AI.LocalIp = 0;
// Если открывается и не Hidden, тогда добавляем для проверки.
if ( scan( (wchar_t*)wchKey ) && !IsHidden(hSubKey) )
RetList.push_back( AI );
}
}
if ( hSubKey )
RegCloseKey( hSubKey );
}
}
}
}
else
{
if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, W9X_ADAPTER_KEY, &hKey ) )
{
for (i = 0, retCode = ERROR_SUCCESS; retCode == ERROR_SUCCESS; i++ )
{
KeyLength = MAX_PATH;
retCode = RegEnumKeyExA(hKey, i, achKey, &KeyLength, NULL, NULL, NULL, &ftLastWriteTime);
if ( ERROR_SUCCESS == retCode )
{
memset ( &AI , 0, sizeof ( AI ) );
strcpy ( AI.AdapterBuffer, achKey );
AI.AdapterNameSize = strlen ( achKey ) + 1;
AI.LocalIp = 0;
//.........这里部分代码省略.........
示例11: scan
/**
* Performs a garbage collection of the immix space.
*/
void ImmixGC::collect(GCData& data) {
Object* tmp;
gc_.clear_lines();
int via_handles_ = 0;
int via_roots = 0;
for(Roots::Iterator i(data.roots()); i.more(); i.advance()) {
tmp = i->get();
if(tmp->reference_p()) saw_object(tmp);
via_roots++;
}
if(data.threads()) {
for(std::list<ManagedThread*>::iterator i = data.threads()->begin();
i != data.threads()->end();
++i) {
scan(*i, false);
}
}
for(capi::Handles::Iterator i(*data.handles()); i.more(); i.advance()) {
if(i->in_use_p() && !i->weak_p()) {
saw_object(i->object());
via_handles_++;
}
}
for(capi::Handles::Iterator i(*data.cached_handles()); i.more(); i.advance()) {
if(i->in_use_p() && !i->weak_p()) {
saw_object(i->object());
via_handles_++;
}
}
std::list<capi::Handle**>* gh = data.global_handle_locations();
if(gh) {
for(std::list<capi::Handle**>::iterator i = gh->begin();
i != gh->end();
++i) {
capi::Handle** loc = *i;
if(capi::Handle* hdl = *loc) {
if(!REFERENCE_P(hdl)) continue;
if(hdl->valid_p()) {
Object* obj = hdl->object();
if(obj && obj->reference_p()) {
saw_object(obj);
via_handles_++;
}
} else {
std::cerr << "Detected bad handle checking global capi handles\n";
}
}
}
}
#ifdef ENABLE_LLVM
if(LLVMState* ls = data.llvm_state()) ls->gc_scan(this);
#endif
gc_.process_mark_stack(allocator_);
// We've now finished marking the entire object graph.
check_finalize();
// Finalize can cause more things to continue to live, so we must
// check the mark_stack again.
while(gc_.process_mark_stack(allocator_)) {
check_finalize();
}
// Sweep up the garbage
gc_.sweep_blocks();
// This resets the allocator state to sync it up with the BlockAllocator
// properly.
allocator_.get_new_block();
// Clear unreachable objects from the various remember sets
int cleared = 0;
unsigned int mark = object_memory_->mark();
cleared = object_memory_->unremember_objects(mark);
for(std::list<gc::WriteBarrier*>::iterator wbi = object_memory_->aux_barriers().begin();
wbi != object_memory_->aux_barriers().end();
++wbi) {
gc::WriteBarrier* wb = *wbi;
cleared += wb->unremember_objects(mark);
}
// Now, calculate how much space we're still using.
immix::Chunks& chunks = gc_.block_allocator().chunks();
immix::AllBlockIterator iter(chunks);
int live_bytes = 0;
//.........这里部分代码省略.........
示例12: switch
//.........这里部分代码省略.........
pedal();
break;
case 47:
rbmode();
break;
case 48:
rdadc();
break;
case 49:
rdsbyte();
break;
case 50:
rdstat();
break;
case 51:
relock();
break;
case 52:
reset();
break;
case 53:
rt();
break;
case 54:
runaway();
break;
case 55:
saveset();
break;
case 56:
savepos();
break;
case 57:
scan();
break;
case 58:
scanr();
break;
case 59:
scanv();
break;
case 60:
secure();
break;
case 61:
sethome();
break;
case 62:
setlow();
break;
case 63:
setup();
break;
case 64:
si();
break;
case 65:
speed();
break;
case 66:
spin();
break;
case 67:
status();
break;
case 68:
示例13: ofGetElapsedTimef
void FaceScanner::update()
{
m_grabber.update();
if(m_grabber.isFrameNew())
{
if (m_shouldTrack)
{
m_tracker.update(toCv(m_grabber));
//----If we've found a face, we store its intrinsics and begin our scanning procedure
if (m_tracker.getFound() && //Have we found a face?
ofGetElapsedTimef() > 2.0f && //Has it been at least 2 seconds?
m_tracker.getImageFeature(ofxFaceTracker::FACE_OUTLINE).getArea() > MIN_FACE_AREA) //If we've found a face, is it reasonably large?
{
ofLogNotice("Face Scanner") << "Found a face.";
//----The FBOs are cleared IFF the last sequence drawn was the particle system (denoted by the boolean m_shouldClearAmbient)
if (!m_shouldClearAmbient) m_inkRenderer->clear();
m_inkRenderer->setDrawMode(InkRenderer::FOLLOWERS);
convertColor(m_grabber, m_thresh, CV_RGB2GRAY);
m_faceOutline = m_tracker.getImageFeature(ofxFaceTracker::FACE_OUTLINE);
m_faceCenter = m_faceOutline.getCentroid2D();
m_faceArea = m_faceOutline.getArea(); //This is a hack: something is wrong with the sign of the value returned by getArea()
m_faceBoundingBox = m_faceOutline.getBoundingBox();
m_shouldTrack = false;
m_drawFrameStart = ofGetElapsedTimef(); //When did this scan start?
scan(200, 10); //Start at a threshold value of 200, and decrement by 5 for each iteration
}
else
{
//----If we don't see a face and it's been m_ambientTimeout seconds, enter ambient mode
if ((ofGetElapsedTimef() - m_ambientFrameStart) >= m_ambientTimeout) {
//----We only want to do these operations once, otherwise the FBOs will clear every frame, and the particle system will never be drawn
if (m_shouldClearAmbient)
{
ofLogNotice("Face Scanner") << "Entering ambient mode.";
//----We tell the InkRenderer to draw particles after clearing the FBOs and resetting the "draw counter"
m_inkRenderer->setDrawMode(InkRenderer::PARTICLES);
m_inkRenderer->clear();
m_shouldClearAmbient = false;
}
}
}
}
else if ((ofGetElapsedTimef() - m_drawFrameStart) >= m_drawTimeout)
{
//----If we shouldn't be tracking, that means we've already found a face, so begin the countdown
ofLogNotice("Face Scanner") << "Starting a new scan.";
//----After this point, we might not see another face, so we record the current time and ready the InkRenderer for a particle simulation
m_ambientFrameStart = ofGetElapsedTimef();
m_shouldClearAmbient = true;
ofSaveScreen("screenshots/image_" + ofGetTimestampString() + ".png");
reset();
}
}
}
示例14: switch
// loop function, can be factorized (for later)
uint8_t symaxProtocol::run( rx_values_t *rx_value )
{
uint8_t returnValue = UNKNOWN;
switch(mState)
{
case BOUND:
{
unsigned long newTime = millis();
returnValue = BOUND_NO_VALUES;
if( !mWireless->rxFlag() )
{
// Signal lost
if((newTime - mLastSignalTime) > 4000)
{
reset();
mLastSignalTime = newTime;
}
}
else
{
bool incrementChannel = false;
mWireless->resetRxFlag();
while ( !mWireless->rxEmpty() )
{
mWireless->readPayload(mFrame, PSIZE);
if( checksum(mFrame) == mFrame[PSIZE-1] )
{
// a valid frame has been received
incrementChannel = true;
// Discard bind frame
if( mFrame[5] != 0xAA && mFrame[6] != 0xAA )
{
// Extract values
returnValue = BOUND_NEW_VALUES;
rx_value->throttle = mFrame[0];
rx_value->yaw = mFrame[2];
if (rx_value->yaw < 0)
rx_value->yaw = 128 - rx_value->yaw;
rx_value->pitch = mFrame[1];
if (rx_value->pitch < 0)
rx_value->pitch = 128 - rx_value->pitch;
rx_value->roll = mFrame[3];
if (rx_value->roll < 0)
rx_value->roll = 128 - rx_value->roll;
rx_value->trim_yaw = mFrame[6] & 0x3F;
if (rx_value->trim_yaw >= 32)
rx_value->trim_yaw = 32 - rx_value->trim_yaw;
rx_value->trim_pitch = mFrame[5] & 0x3F;
if (rx_value->trim_pitch >= 32)
rx_value->trim_pitch = 32 - rx_value->trim_pitch;
rx_value->trim_roll = mFrame[7] & 0x3F;
if (rx_value->trim_roll >= 32)
rx_value->trim_roll = 32 - rx_value->trim_roll;
rx_value->video = mFrame[4] & 0x80;
rx_value->picture = mFrame[4] & 0x40;
rx_value->highspeed = mFrame[5] & 0x80;
rx_value->flip = mFrame[6] & 0x40;
mLastSignalTime = newTime;
}
}
}
if(incrementChannel)
{
mRfChNum++;
if( mRfChNum >= FSIZE)
mRfChNum = 0;
mWireless->switchFreq(mRFChanBufs[mRfChNum]);
}
}
}
break;
// Initial state
case NO_BIND:
{
returnValue = NOT_BOUND;
unsigned long newTime = millis();
if( !mWireless->rxFlag() )
{
scan();
}
else
{
mWireless->resetRxFlag();
bool bFrameOk = false;
while ( !mWireless->rxEmpty() )
{
//.........这里部分代码省略.........
示例15: reduce_by_key
clsparseStatus
reduce_by_key(
int keys_first,
int keys_last,
int values_first,
cl_mem keys_input,
cl_mem values_input,
cl_mem keys_output,
cl_mem values_output,
int *count,
clsparseControl control
)
{
cl_int l_Error;
/**********************************************************************************
* Compile Options
*********************************************************************************/
const int kernel0_WgSize = WAVESIZE*KERNEL02WAVES;
const int kernel1_WgSize = WAVESIZE*KERNEL1WAVES;
const int kernel2_WgSize = WAVESIZE*KERNEL02WAVES;
//const std::string params = std::string() +
// " -DKERNEL0WORKGROUPSIZE=" + std::to_string(kernel0_WgSize)
// + " -DKERNEL1WORKGROUPSIZE=" + std::to_string(kernel1_WgSize)
// + " -DKERNEL2WORKGROUPSIZE=" + std::to_string(kernel2_WgSize);
const std::string params;
cl::Context context = control->getContext();
std::vector<cl::Device> dev = context.getInfo<CL_CONTEXT_DEVICES>();
int computeUnits = dev[0].getInfo< CL_DEVICE_MAX_COMPUTE_UNITS >( );
int wgPerComputeUnit = dev[0].getInfo< CL_DEVICE_MAX_WORK_GROUP_SIZE >( );
int resultCnt = computeUnits * wgPerComputeUnit;
cl_uint numElements = keys_last - keys_first + 1;
size_t sizeInputBuff = numElements;
int modWgSize = (sizeInputBuff & (kernel0_WgSize-1));
if( modWgSize )
{
sizeInputBuff &= ~modWgSize;
sizeInputBuff += kernel0_WgSize;
}
cl_uint numWorkGroupsK0 = static_cast< cl_uint >( sizeInputBuff / kernel0_WgSize );
size_t sizeScanBuff = numWorkGroupsK0;
modWgSize = (sizeScanBuff & (kernel0_WgSize-1));
if( modWgSize )
{
sizeScanBuff &= ~modWgSize;
sizeScanBuff += kernel0_WgSize;
}
cl_mem tempArrayVec = clCreateBuffer(context(),CL_MEM_READ_WRITE, (numElements)*sizeof(int), NULL, NULL );
/**********************************************************************************
* Kernel 0
*********************************************************************************/
cl::Kernel kernel0 = KernelCache::get(control->queue,"reduce_by_key", "OffsetCalculation", params);
KernelWrap kWrapper0(kernel0);
kWrapper0 << keys_input << tempArrayVec
<< numElements;
cl::NDRange local0(kernel0_WgSize);
cl::NDRange global0(sizeInputBuff);
cl_int status = kWrapper0.run(control, global0, local0);
if (status != CL_SUCCESS)
{
return clsparseInvalidKernelExecution;
}
int init = 0;
scan(0,
numElements - 1,
tempArrayVec,
tempArrayVec,
0,
0,
control
);
int pattern = 0;
cl_mem keySumArray = clCreateBuffer(context(),CL_MEM_READ_WRITE, (sizeScanBuff)*sizeof(int), NULL, NULL );
cl_mem preSumArray = clCreateBuffer(context(),CL_MEM_READ_WRITE, (sizeScanBuff)*sizeof(int), NULL, NULL );
cl_mem postSumArray = clCreateBuffer(context(),CL_MEM_READ_WRITE,(sizeScanBuff)*sizeof(int), NULL, NULL );
clEnqueueFillBuffer(control->queue(), keySumArray, &pattern, sizeof(int), 0,
(sizeScanBuff)*sizeof(int), 0, NULL, NULL);
clEnqueueFillBuffer(control->queue(), preSumArray, &pattern, sizeof(int), 0,
(sizeScanBuff)*sizeof(int), 0, NULL, NULL);
clEnqueueFillBuffer(control->queue(), postSumArray, &pattern, sizeof(int), 0,
(sizeScanBuff)*sizeof(int), 0, NULL, NULL);
//.........这里部分代码省略.........