Exemplo n.º 1
0
int main(int argc, char *argv[]) {
	PKT_T pkg;
	struct sockaddr_in sa;
	socklen_t len = sizeof(sa);

	client_init(&client);

	while (1) {
		if (client.status != STATUS_WORKING)
			continue;
		recvfrom(client.sd, &pkg, sizeof(pkg), 0, (void *)&sa, &len);
		switch (FLAG_MASK(pkg.sync.req.flag)) {
			case FLAG_DATA_REQ:	//收到数据桢
				break;
			case FLAG_SYNC_ACK:	//中途收到同步ACK桢
				set_beacam_interval(pkg.sync.ack.interval, pkg.sync.ack.next_interval);
				break;
			default:
				fprintf(stderr, "work one times, now to sleep status\n");
				client.status = STATUS_SLEEP;
				break;
		}
	}

	close(client.sd);
	return 0;
}
Exemplo n.º 2
0
static void beacam_recv_fun(int unused) {
	PKT_T pkg;

	//如果已经处于工作状态,则直接返回
	if (client.status == STATUS_WORKING)
		return;
	//如果唤醒后5ms内收到广播桢,则回到工作状态,否则继续睡眠
	if (recv_tm(client.sd, &pkg, sizeof(pkg), 5) > 0 \
			&& FLAG_MASK(pkg.wakeup.flag) == FLAG_BCM_REQ) 
	{
		fprintf(stderr, "client resume to working status\n");
		client.status = STATUS_WORKING;
	} else {
		fprintf(stderr, "client return to sleep status\n");
		client.status = STATUS_SLEEP;
	}
}
Exemplo n.º 3
0
/*-------------------------------------------------------------------
    Procedure   :       Update a trigger var..and then checks to see if 
                        all the triggers associated with any condition that this
                        trigger is used in is complete if it is Set the events off...
    Input       :       TRIGGERVAR * TrigVar
                        int Op
                        int Val
    Output      :       nothing
-------------------------------------------------------------------*/
void ModifyTriggerVar( TRIGGERVAR * TrigVar , int Op , int Val )
{
    BOOL    Doit;
    int     i;
    TRIGGER * Trig;
    int     old_state;
    uint32  flags;
    int     count;

    old_state = TrigVar->State;
    switch( Op )
    {
    case TRIGGEROP_Set:
        TrigVar->State = Val;
        break;
    case TRIGGEROP_Reset:
        TrigVar->State = TrigVar->InitState;
        break;
    case TRIGGEROP_Inc:
        TrigVar->State += Val;
        break;
    case TRIGGEROP_Dec:
        TrigVar->State -= Val;
        break;
    case TRIGGEROP_Or:
        TrigVar->State |= Val;
        break;
    case TRIGGEROP_And:
        TrigVar->State &= Val;
        break;
    case TRIGGEROP_Xor:
        TrigVar->State ^= Val;
        break;
    case TRIGGEROP_Multiply:
        TrigVar->State *= Val;
        break;
    case TRIGGEROP_Divide:
        TrigVar->State /= Val;
        break;
    case TRIGGEROP_Random:
        TrigVar->State = (int) Random_Range( (uint16) Val );
        break;
    case TRIGGEROP_Setflag:
        TrigVar->State |= FLAG_MASK( Val );
        break;
    case TRIGGEROP_Clearflag:
        TrigVar->State &= ~FLAG_MASK( Val );
        break;
    }

    if( TrigVar->State == old_state ) return;

#ifdef DEBUG_TRIGGERS
    DebugPrintf( "modifytrigvar: var=%s(=%d) op=%d val=%d -> %d\n",
        TrigVar->Name, old_state, Op, Val, TrigVar->State );
#endif

    for( i = 0 ; i < TrigVar->NumOfTriggers ; i++ )
    {
        Trig = TrigVar->Triggers[i];
        Doit = FALSE;

        switch( Trig->Type )
        {
        case TRIGGERTYPE_Equal:
            if( TrigVar->State == Trig->ActiveState )
                Doit = TRUE;
            break;
        case TRIGGERTYPE_NotEqual:
            if( TrigVar->State != Trig->ActiveState )
                Doit = TRUE;
            break;
        case TRIGGERTYPE_Less:
            if( TrigVar->State < Trig->ActiveState )
                Doit = TRUE;
            break;
        case TRIGGERTYPE_Greater:
            if( TrigVar->State > Trig->ActiveState )
                Doit = TRUE;
            break;
        case TRIGGERTYPE_LessEqual:
            if( TrigVar->State <= Trig->ActiveState )
                Doit = TRUE;
            break;
        case TRIGGERTYPE_GreaterEqual:
            if( TrigVar->State >= Trig->ActiveState )
                Doit = TRUE;
            break;
        case TRIGGERTYPE_FlagCount:
            count = 0;
            for ( flags = TrigVar->State; flags; flags >>= 1 )
            {
                if ( flags & 1 )
                    count++;
            }
            if ( count == Trig->ActiveState )
                Doit = TRUE;
            break;
        case TRIGGERTYPE_FlagTest:
            if ( TrigVar->State & FLAG_MASK( Trig->ActiveState ) )
                Doit = TRUE;
            break;
        }

        if ( Doit )
        {
#ifdef DEBUG_TRIGGERS
            DebugPrintf( "modifytrigvar: trigger %d (type=%d, activestate=%d) activated (was %d)\n",
                Trig - Triggers, (int) Trig->Type, Trig->ActiveState, Trig->Active );
#endif
            if( !(_strnicmp( "secret" , &TrigVar->Name[0], 6 ) ) )
            {
                PlaySfx( SFX_Secret, 1.0F );
            }
        }

        Trig->Active = Doit;

        if( Trig->Active )
        {
            TestAllConditions( Trig );
        }
    }
}
	FLAG(IMAXBEL),
};

static const struct flags tc_oflags[] = {
	FLAG(OPOST),
	FLAG(ONLCR),
	FLAG(OXTABS),
	FLAG(ONOEOT),
	FLAG(OCRNL),
	FLAG(ONOCR),
	FLAG(ONLRET),
};

static const struct flags tc_cflags[] = {
	FLAG(CIGNORE),
	FLAG_MASK(CSIZE, CS5),
	FLAG_MASK(CSIZE, CS6),
	FLAG_MASK(CSIZE, CS7),
	FLAG_MASK(CSIZE, CS8),
	FLAG(CSTOPB),
	FLAG(CREAD),
	FLAG(PARENB),
	FLAG(PARODD),
	FLAG(HUPCL),
	FLAG(CLOCAL),
	FLAG(CRTSCTS),
	FLAG(CDTRCTS),
	FLAG(MDMBUF),
};

static const struct flags tc_lflags[] = {
Exemplo n.º 5
0
Arquivo: vm.c Projeto: Hooman3/minix
	FLAG(PROT_READ),
	FLAG(PROT_WRITE),
	FLAG(PROT_EXEC),
};

static const struct flags mmap_flags[] = {
	FLAG(MAP_SHARED),
	FLAG(MAP_PRIVATE),
	FLAG(MAP_FIXED),
	FLAG(MAP_RENAME),
	FLAG(MAP_NORESERVE),
	FLAG(MAP_INHERIT),
	FLAG(MAP_HASSEMAPHORE),
	FLAG(MAP_TRYFIXED),
	FLAG(MAP_WIRED),
	FLAG_MASK(MAP_ANON | MAP_STACK, MAP_FILE),
	FLAG(MAP_ANON),
	FLAG(MAP_STACK),
	FLAG(MAP_UNINITIALIZED),
	FLAG(MAP_PREALLOC),
	FLAG(MAP_CONTIG),
	FLAG(MAP_LOWER16M),
	FLAG(MAP_LOWER1M),
	FLAG(MAP_THIRDPARTY),
	/* TODO: interpret alignments for which there is no constant */
	FLAG_MASK(MAP_ALIGNMENT_MASK, MAP_ALIGNMENT_64KB),
	FLAG_MASK(MAP_ALIGNMENT_MASK, MAP_ALIGNMENT_16MB),
	FLAG_MASK(MAP_ALIGNMENT_MASK, MAP_ALIGNMENT_4GB),
	FLAG_MASK(MAP_ALIGNMENT_MASK, MAP_ALIGNMENT_1TB),
	FLAG_MASK(MAP_ALIGNMENT_MASK, MAP_ALIGNMENT_256TB),
	FLAG_MASK(MAP_ALIGNMENT_MASK, MAP_ALIGNMENT_64PB),