int main( int argc, char **argv ) { int algo, arg, verbose; char *filename; /* Check arguments */ if( (argc < 3) || (argc > 4) ) { Help( argv[ 0 ] ); return 0; } arg = 1; /* Check for options */ verbose = 0; if( strcmp( argv[arg], "-v" ) == 0 ) { verbose = 1; ++ arg; } /* Get algo */ algo = 0; if( strcmp( argv[arg], "rle" ) == 0 ) algo = 1; if( strcmp( argv[arg], "huff" ) == 0 ) algo = 2; if( strcmp( argv[arg], "rice8" ) == 0 ) algo = 3; if( strcmp( argv[arg], "rice16" ) == 0 ) algo = 4; if( strcmp( argv[arg], "rice32" ) == 0 ) algo = 5; if( strcmp( argv[arg], "rice8s" ) == 0 ) algo = 6; if( strcmp( argv[arg], "rice16s" ) == 0 ) algo = 7; if( strcmp( argv[arg], "rice32s" ) == 0 ) algo = 8; if( strcmp( argv[arg], "lz" ) == 0 ) algo = 9; if( strcmp( argv[arg], "lz_f" ) == 0 ) algo = 10; if( strcmp( argv[arg], "sf" ) == 0 ) algo = 11; if( !algo ) { Help( argv[ 0 ] ); return 0; } ++ arg; /* Get file name */ filename = argv[arg]; /* Initialize timer */ InitTimer(); /* Test file */ TestFile( filename, algo, verbose ); return 0; }
/** * @function DeleteWorld * @brief * @date 2011-10-13 */ void GRIPFrame::DeleteWorld() { InitTimer("",0); timeVector.clear(); if(mWorld) { delete mWorld; mWorld = 0; selectedTreeNode = 0; treeView->DeleteAllItems(); } }
int main() { InitTimer(); InitComm(); PrintLn("hello, world!"); InitOLED(); TestOLED(); return 0; }
int main(void) //main body calls all other functions to initialize the proper values of the Transmission protocol, timer and ADC module, then starts them { InitialzeLCD(); //initializes LCD SetADCChannel(5); // sets ADC channel for temperature sensor InitADC(); // Initializes ADC and timer below to 1 second InitTimer(); startTimer(); startADC(); while(1) { // Main loop } }
void main(void) { (void)puts("\r\nIn test harness for timer.c \r\n"); InitTimer(); EnableInterrupts; StartTimer(1, 2000); while(1) { if(IsTimerExpired(1)) { (void)printf("Egg is Cooked!\r\n"); } } }
IoT_Error_t subscribeToShadowActionAcks(const char *pThingName, ShadowActions_t action, bool isSticky) { IoT_Error_t ret_val = NONE_ERROR; MQTTSubscribeParams subParams = MQTTSubscribeParamsDefault; bool clearBothEntriesFromList = true; int16_t indexAcceptedSubList = 0; int16_t indexRejectedSubList = 0; indexAcceptedSubList = getNextFreeIndexOfSubscriptionList(); indexRejectedSubList = getNextFreeIndexOfSubscriptionList(); if (indexAcceptedSubList >= 0 && indexRejectedSubList >= 0) { topicNameFromThingAndAction(SubscriptionList[indexAcceptedSubList].Topic, pThingName, action, SHADOW_ACCEPTED); subParams.mHandler = AckStatusCallback; subParams.qos = QOS_0; subParams.pTopic = SubscriptionList[indexAcceptedSubList].Topic; ret_val = pMqttClient->subscribe(&subParams); if (ret_val == NONE_ERROR) { SubscriptionList[indexAcceptedSubList].count = 1; SubscriptionList[indexAcceptedSubList].isSticky = isSticky; topicNameFromThingAndAction(SubscriptionList[indexRejectedSubList].Topic, pThingName, action, SHADOW_REJECTED); subParams.pTopic = SubscriptionList[indexRejectedSubList].Topic; ret_val = pMqttClient->subscribe(&subParams); if (ret_val == NONE_ERROR) { SubscriptionList[indexRejectedSubList].count = 1; SubscriptionList[indexRejectedSubList].isSticky = isSticky; clearBothEntriesFromList = false; // wait for SUBSCRIBE_SETTLING_TIME seconds to let the subscription take effect Timer subSettlingtimer; InitTimer(&subSettlingtimer); countdown(&subSettlingtimer, SUBSCRIBE_SETTLING_TIME); while(!expired(&subSettlingtimer)); } } } if (clearBothEntriesFromList) { if (indexAcceptedSubList >= 0) { SubscriptionList[indexAcceptedSubList].isFree = true; } else if (indexRejectedSubList >= 0) { SubscriptionList[indexRejectedSubList].isFree = true; } if (SubscriptionList[indexAcceptedSubList].count == 1) { ret_val = pMqttClient->unsubscribe(SubscriptionList[indexAcceptedSubList].Topic); } } return ret_val; }
int MQTTPublish(Client* c, const char* topicName, MQTTMessage* message) { int rc = FAILURE; Timer timer; MQTTString topic = MQTTString_initializer; topic.cstring = (char *)topicName; int len = 0; InitTimer(&timer); countdown_ms(&timer, c->command_timeout_ms); if (!c->isconnected) goto exit; if (message->qos == QOS1 || message->qos == QOS2) message->id = getNextPacketId(c); len = MQTTSerialize_publish(c->buf, c->buf_size, 0, message->qos, message->retained, message->id, topic, (unsigned char*)message->payload, message->payloadlen); if (len <= 0) goto exit; if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet goto exit; // there was a problem if (message->qos == QOS1) { if (waitfor(c, PUBACK, &timer) == PUBACK) { unsigned short mypacketid; unsigned char dup, type; if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) rc = FAILURE; } else rc = FAILURE; } else if (message->qos == QOS2) { if (waitfor(c, PUBCOMP, &timer) == PUBCOMP) { unsigned short mypacketid; unsigned char dup, type; if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) rc = FAILURE; } else rc = FAILURE; } exit: return rc; }
int TclServiceIdle(void) { IdleHandler *idlePtr; int oldGeneration; Tcl_Time blockTime; ThreadSpecificData *tsdPtr = InitTimer(); if (tsdPtr->idleList == NULL) { return 0; } oldGeneration = tsdPtr->idleGeneration; tsdPtr->idleGeneration++; /* * The code below is trickier than it may look, for the following reasons: * * 1. New handlers can get added to the list while the current one is * being processed. If new ones get added, we don't want to process * them during this pass through the list (want to check for other work * to do first). This is implemented using the generation number in the * handler: new handlers will have a different generation than any of * the ones currently on the list. * 2. The handler can call Tcl_DoOneEvent, so we have to remove the * handler from the list before calling it. Otherwise an infinite loop * could result. * 3. Tcl_CancelIdleCall can be called to remove an element from the list * while a handler is executing, so the list could change structure * during the call. */ for (idlePtr = tsdPtr->idleList; ((idlePtr != NULL) && ((oldGeneration - idlePtr->generation) >= 0)); idlePtr = tsdPtr->idleList) { tsdPtr->idleList = idlePtr->nextPtr; if (tsdPtr->idleList == NULL) { tsdPtr->lastIdlePtr = NULL; } idlePtr->proc(idlePtr->clientData); ckfree(idlePtr); } if (tsdPtr->idleList) { blockTime.sec = 0; blockTime.usec = 0; Tcl_SetMaxBlockTime(&blockTime); } return 1; }
/******************************************************************************* * PUBLIC FUNCTIONS * ******************************************************************************/ char IR_Init() { //dbprintf("\nInitializing the IR Sensor Module."); #ifdef USE_LEDS LED_Init(LED_BANK3 |LED_BANK1); LED_OffBank(LED_BANK3, 0xF); LED_OffBank(LED_BANK1, 0xF); #endif InitTimer(TIMER_IR, UPDATE_DELAY); return SUCCESS; }
int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate ) { if( !g_bTimerInitialized ) InitTimer(); int64_t ret = timeGetTime() * int64_t(1000); if( bAccurate ) { ret = FixupTimeIfLooped( ret ); ret = FixupTimeIfBackwards( ret ); } return ret; }
int MQTTConnect (Client *c, MQTTPacket_connectData *options) { Timer connect_timer; int rc = FAILURE; int len = 0; MQTTPacket_connectData default_options = MQTTPacket_connectData_initializer; InitTimer (&connect_timer); countdown_ms (&connect_timer, c->command_timeout_ms); if (c->isconnected) // don't send connect packet again if we are already connected goto exit; if (options == 0) options = &default_options; // set default options if none were supplied c->keepAliveInterval = options->keepAliveInterval; countdown (&c->ping_timer, c->keepAliveInterval); //-------------------------------------------------------------------- // Generate a MQTT "Connect" packet, and send it to the remote Broker //-------------------------------------------------------------------- len = MQTTSerialize_connect (c->buf, c->buf_size, options); if (len <= 0) goto exit; // supplied buffer is too small rc = sendPacket (c, len, &connect_timer); // send the connect packet if (rc != SUCCESS) goto exit; // there was a problem //-------------------------------------------------------------------- // Wait for and read in the MQTT "ConnAck" reply packet. //-------------------------------------------------------------------- // this will be a blocking call, wait for the connack if (waitfor(c, CONNACK, &connect_timer) == CONNACK) { unsigned char connack_rc = 255; char sessionPresent = 0; if (MQTTDeserialize_connack((unsigned char*) &sessionPresent, &connack_rc, c->readbuf, c->readbuf_size) == 1) rc = connack_rc; else rc = FAILURE; } else rc = FAILURE; exit: if (rc == SUCCESS) c->isconnected = 1; return rc; }
int MQTTSubscribe (Client *c, const char *topicFilter, enum QoS qos, messageHandler messageHandler) { int i; int rc = FAILURE; Timer timer; int len = 0; MQTTString topic = MQTTString_initializer; topic.cstring = (char*) topicFilter; InitTimer (&timer); countdown_ms (&timer, c->command_timeout_ms); // default is 1 second timeouts if ( ! c->isconnected) goto exit; len = MQTTSerialize_subscribe (c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic, (int*) &qos); if (len <= 0) goto exit; if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet goto exit; // there was a problem if (waitfor(c, SUBACK, &timer) == SUBACK) // wait for suback { int count = 0, grantedQoS = -1; unsigned short mypacketid; if (MQTTDeserialize_suback(&mypacketid, 1, &count, &grantedQoS, c->readbuf, c->readbuf_size) == 1) rc = grantedQoS; // will be 0, 1, 2 or 0x80 if (rc != 0x80) { for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) { if (c->messageHandlers[i].topicFilter == 0) { c->messageHandlers[i].topicFilter = topicFilter; c->messageHandlers[i].fp = messageHandler; rc = 0; // denote success break; } } } } else rc = FAILURE; // timed out - no SUBACK received exit: return rc; }
void main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; // Increase PMMCOREV level to 2 for proper radio operation SetVCore(2); ResetRadioCore(); InitButtonLeds(); InitTimer(); // Clean out the RX Buffer rxPosition = PACKET_LEN+2; while(rxPosition--) { RxBuffer[rxPosition] = 0; } InitRadio(); ReceiveOn(); while (1) { P1IE |= BIT7; // Enable button interrupt __bis_SR_register( LPM3_bits + GIE ); __no_operation(); if (buttonPressed) // Process a button press->transmit { ReceiveOff(); // Button means TX, stop RX receiving = 0; TransmitPacket(); buttonPressed = 0; // Re-enable button press } if(receiving) { ReceivePacket(); __no_operation(); } if(!transmitting) { ReceiveOn(); } } }
void main(void) { (void)printf("Start of E128 program\r\n"); InitPorts(); InitTimer(); InitMotors(); InitSide(); InitBeacons(); EnableInterrupts; StartMasterSM(); while(1) { // Repeat State Machine Forever (void)RunMasterSM(CheckEvents()); } }
int MQTTDisconnect(Client* c) { int rc = FAILURE; Timer timer; // we might wait for incomplete incoming publishes to complete int len = MQTTSerialize_disconnect(c->buf, c->buf_size); InitTimer(&timer); countdown_ms(&timer, c->command_timeout_ms); if (len > 0) rc = sendPacket(c, len, &timer); // send the disconnect packet c->isconnected = 0; return rc; }
/** * main program */ void main(void) { EnableInterrupts; // Interrupts aktivieren PTFDD = LED; InitTimer(); for(;;) { __RESET_WATCHDOG(); /* feeds the dog */ } /* please make sure that you never leave main */ }
int main(void) { int i; InitTimer(); InitUART(); LED_DDR |= LED_MASK; // The first handle opened for read goes to stdin, and the first handle // opened for write goes to stdout. fdevopen( UART0_PutCharStdio, UART0_GetCharStdio ); printf( "*****\n" ); printf( "***** Uart Test program\n" ); printf( "*****\n" ); while( 1 ) { LED_PORT ^= LED_MASK; printf( "." ); // Tick rate is 100/sec so waiting for 100 waits for 1 sec for ( i = 0; i < 100; i++ ) { WaitForTimer0Rollover(); if ( UART0_IsCharAvailable() ) { char ch = getchar(); printf( "Read: '%c'\n", ch ); if ( ch == ' ' ) { printf( "*** Press a key to continue\n" ); ch = getchar(); printf( "*** Continuing...\n" ); } } } } return 0; }
int keepalive(Client* c) { int rc = FAILURE; if (c->keepAliveInterval == 0) { return SUCCESS; } if (expired(&c->ping_timer)) { if (!c->ping_outstanding) { // there is not a ping outstanding - send one Timer timer; InitTimer(&timer); countdown_ms(&timer, 2000); //STM: modified the value from 1000 to 2000 int len = MQTTSerialize_pingreq(c->buf, c->buf_size); INFO("-->keepalive"); rc = sendPacket(c, len, &timer); // send the ping packet DeInitTimer(&timer); //STM: added this line if (len > 0 && rc == SUCCESS) { c->ping_outstanding = 1; // start a timer to wait for PINGRESP from server countdown(&c->ping_timer, c->keepAliveInterval / 2); } else { rc = FAILURE; } } else { // timer expired while waiting for a ping - decide we are disconnected MQTTDisconnect(c); if (c->disconnectHandler != NULL) { c->disconnectHandler(); } } } else { rc = SUCCESS; } return rc; }
static void Flash() { #if 0 // FIXME FILE *animf; TEvent e; VVF_DrawFrame = DrawFlash; animf = GetAnimFile("flash"); do {GetEvent(&e);} while (e.What != evNothing); DoneTimer(); PlayVVF(animf); InitTimer(); do {GetEvent(&e);} while (e.What != evNothing); fclose(animf); #endif }
int MQTTConnect(Client* c, MQTTPacket_connectData* options) { Timer connect_timer; int rc = FAILURE; MQTTPacket_connectData default_options = MQTTPacket_connectData_initializer; int len = 0; InitTimer(&connect_timer); countdown_ms(&connect_timer, c->command_timeout_ms); if (c->isconnected) // don't send connect packet again if we are already connected goto exit; if (options == 0) options = &default_options; // set default options if none were supplied c->keepAliveInterval = options->keepAliveInterval; countdown(&c->ping_timer, c->keepAliveInterval); if ((len = MQTTSerialize_connect(c->buf, c->buf_size, options)) <= 0) goto exit; if ((rc = sendPacket(c, len, &connect_timer)) != SUCCESS) // send the connect packet goto exit; // there was a problem // this will be a blocking call, wait for the connack if (waitfor(c, CONNACK, &connect_timer) == CONNACK) { unsigned char connack_rc = 255; char sessionPresent = 0; if (MQTTDeserialize_connack((unsigned char*)&sessionPresent, &connack_rc, c->readbuf, c->readbuf_size) == 1) rc = connack_rc; else rc = FAILURE; } else rc = FAILURE; exit: if (rc == SUCCESS) c->isconnected = 1; DeInitTimer(&connect_timer); //STM: added this line of code return rc; }
void MQTTClient(Client* c, Network* network, unsigned int command_timeout_ms, unsigned char* buf, size_t buf_size, unsigned char* readbuf, size_t readbuf_size) { int i; c->ipstack = network; for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) c->messageHandlers[i].topicFilter = 0; c->command_timeout_ms = command_timeout_ms; c->buf = buf; c->buf_size = buf_size; c->readbuf = readbuf; c->readbuf_size = readbuf_size; c->isconnected = 0; c->ping_outstanding = 0; c->defaultMessageHandler = NULL; InitTimer(&c->ping_timer); }
BOOL Chusky::OnInitDialog() { CDialogEx::OnInitDialog(); InitMarketDataList(); InitWaitOrderList(); InitDoneOrderList(); InitTrader(); InitTimer(); UpdateInsData(); UpdateMoney(); if (!needLine){ GetDlgItem(IDC_TREND_BUTTON)->EnableWindow(false); GetDlgItem(IDC_BUTTON)->EnableWindow(false); } return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE }
BYTE RestartTimer( TIMER_HANDLE handle, DWORD dwNewTime ){ if ( (handle > GET_VEC_NUM_MEMBERS(timer)) || (handle == TIMER_NULL) ){ return FALSE; } if ( tmInit == FALSE ){ InitTimer(); } if ( timer[handle].bTimer != handle ){ return FALSE; } timer[handle].dwTime = dwNewTime + dwTickCount; return TRUE; }
//Useful documentation //https://my.wpi.edu/bbcswebdav/pid-276133-dt-content-rid-1385566_1/courses/RBE3001-C14-MASTER/accelerometer_module_schematic%282%29.pdf //http://ww1.microchip.com/downloads/en/DeviceDoc/21298c.pdf //https://my.wpi.edu/bbcswebdav/pid-276133-dt-content-rid-1385573_1/courses/RBE3001-C14-MASTER/HitachiH48C3AxisAccelerometer.pdf void initAccelerometerWithTimer() { accel.newDataAvailable = 0; //Initialize SPI GenericSPIInit(); //Set SS to output DDRD |= (1 << ACCEL_SS); //set SS high PORTD |= (1 << ACCEL_SS); //Set timer to sample at 500 hz accel.timerMaxCount = ((float)F_CPU/((unsigned long)180*256))*((float)1/400); // = 1 for CTC = 180, prescale = 256, and frequency = 500 accel.timerCurrentCount = 0; InitTimer(0,CTC,180); //adjust the prescaler to F_CPU/256 TCCR0Bbits._CS02 = 1; TCCR0Bbits._CS01 = 0; TCCR0Bbits._CS00 = 0; }
int MQTTYield(Client* c, int timeout_ms) { int rc = SUCCESS; Timer timer; InitTimer(&timer); countdown_ms(&timer, timeout_ms); while (!expired(&timer)) { if (cycle(c, &timer) == FAILURE) { rc = FAILURE; break; } } return rc; }
void main(void) { noVoice(); InitTimer(50, 100); // �����жϳ�ʼ�� press_open_button = 1; press_close_button = 1; KBLS1 |= 0x03; KBLS0 |= 0x03; KBIF &= 0xfc; KBIE |= 0x03; EA = 1; Moto_EN = 1; //��ʼ�����ر���� transmit_wire = 1; voice_EN = 0; //����ʱ�������Źر� ADC_check_result = GetADCResult(6); //�ϵ�ʱ����ص������һ�� stolen_alarm_count = 0; //�屨�������� stolen_alarm_flag = 0; //�屨����־ transmiter_EN = 0; // turn off the transmitter receiver_EN = 0; // turn on the receiver transceiver_power_enable = 1; // �ϵ�ʱ����ģ���Դ�ر� Delay(3); TR0 = 1; while(1) { if(idle_EN == 1) { EKB = 1; idle_EN = 0; PCON |= 0x02; } // sEOS_Go_To_Sleep(); } }
Tcl_TimerToken TclCreateAbsoluteTimerHandler( Tcl_Time *timePtr, Tcl_TimerProc *proc, ClientData clientData) { register TimerHandler *timerHandlerPtr, *tPtr2, *prevPtr; ThreadSpecificData *tsdPtr; tsdPtr = InitTimer(); timerHandlerPtr = (TimerHandler *) ckalloc(sizeof(TimerHandler)); /* * Fill in fields for the event. */ memcpy((void *)&timerHandlerPtr->time, (void *)timePtr, sizeof(Tcl_Time)); timerHandlerPtr->proc = proc; timerHandlerPtr->clientData = clientData; tsdPtr->lastTimerId++; timerHandlerPtr->token = (Tcl_TimerToken) INT2PTR(tsdPtr->lastTimerId); /* * Add the event to the queue in the correct position * (ordered by event firing time). */ for (tPtr2 = tsdPtr->firstTimerHandlerPtr, prevPtr = NULL; tPtr2 != NULL; prevPtr = tPtr2, tPtr2 = tPtr2->nextPtr) { if (TCL_TIME_BEFORE(timerHandlerPtr->time, tPtr2->time)) { break; } } timerHandlerPtr->nextPtr = tPtr2; if (prevPtr == NULL) { tsdPtr->firstTimerHandlerPtr = timerHandlerPtr; } else { prevPtr->nextPtr = timerHandlerPtr; } TimerSetupProc(NULL, TCL_ALL_EVENTS); return timerHandlerPtr->token; }
BYTE IsTimerTimeOut( TIMER_HANDLE handle ){ if ( tmInit == FALSE ){ InitTimer(); } if ( (handle > GET_VEC_NUM_MEMBERS(timer)) || (handle == TIMER_NULL) ){ return FALSE; } if ( timer[handle].bTimer != handle ){ return FALSE; } if ( timer[handle].dwTime < dwTickCount ) return TRUE; return FALSE; }
void ReleaseTimer( TIMER_HANDLE * handle ){ if ( tmInit == FALSE ){ InitTimer(); } if ( (*handle > GET_VEC_NUM_MEMBERS(timer)) || (*handle == TIMER_NULL) ){ return; } if ( timer[*handle].bTimer != *handle ){ return; } memset( (char*)&timer[* handle], TIMER_NULL, sizeof( struct Timer ) ); *handle = TIMER_NULL; return; }
TIMER_HANDLE GetTimer( DWORD dwTime ){ BYTE i; if ( tmInit == FALSE ){ InitTimer(); } for ( i = 1; i < GET_VEC_NUM_MEMBERS(timer);i++ ){ if ( timer[i].bTimer == TIMER_NULL ){ timer[i].bTimer = i; timer[i].dwTime = dwTime + dwTickCount; return i; } } timer[0].bTimer = i; timer[0].dwTime = dwTime + dwTickCount; return 0; }