void m2_time_task(void) { timeInc(); showTimeMode.updateDisp(); // check timer if (setTimerMode.state.on == 0) { portWrite(PORTB, LO, RELE_1_PIN); // off } else { Time time = timeGet(); if(timeLE(setTimerMode.state.timeOn, setTimerMode.state.timeOff)) { if (timeGE(time, setTimerMode.state.timeOn) && timeLE(time, setTimerMode.state.timeOff) ) { portWrite(PORTB, HI, RELE_1_PIN); } else { portWrite(PORTB, LO, RELE_1_PIN); } } else { if (timeLE(time, setTimerMode.state.timeOff) || timeGE(time, setTimerMode.state.timeOn) ) { portWrite(PORTB, HI, RELE_1_PIN); } else { portWrite(PORTB, LO, RELE_1_PIN); } } } }
/*============================================================================= * TEMPO */ bool tempoC::operator()() { unsigned long t = timeGet(); if(t - LastTime < Interval) return false; LastTime = t; return true; }
static DDS_boolean PP_seq_handler ( unsigned int nof_cycles ) { DDS_SampleInfoSeq infoList = { 0, 0, NULL, FALSE }; int amount; DDS_boolean result = FALSE; DDS_ReturnCode_t dds_result; /* printf "PING: PING_seq arrived\n"); */ preTakeTime = timeGet (); dds_result = pingpong_PP_seq_msgDataReader_take ( PP_seq_reader, &PP_seq_dataList, &infoList, 1, DDS_ANY_SAMPLE_STATE, DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE); postTakeTime = timeGet (); amount = PP_seq_dataList._length; if (amount != 0) { if (amount > 1) { printf ("PING: Ignore excess messages : %d msg received\n", amount); } PP_seq_dataList._buffer[0].count++; if (PP_seq_dataList._buffer[0].count < nof_cycles) { preWriteTime = timeGet (); dds_result = pingpong_PP_seq_msgDataWriter_write (PP_seq_writer, &PP_seq_dataList._buffer[0], DDS_HANDLE_NIL); postWriteTime = timeGet (); add_stats (&write_access, 1E6 * timeToReal (timeSub (postWriteTime, preWriteTime))); } else { result = TRUE; } add_stats (&read_access, 1E6 * timeToReal (timeSub (postTakeTime, preTakeTime))); add_stats (&roundtrip, 1E6 * timeToReal (timeSub (postTakeTime, roundTripTime))); roundTripTime = preWriteTime; dds_result = pingpong_PP_seq_msgDataReader_return_loan (PP_seq_reader, &PP_seq_dataList, &infoList); } else { printf ("PING: PING_seq triggered, but no data available\n"); } return result; }
/*============================================================================= * UNIT */ void city_displayUnit(cityC* city, int id) { float angle = (timeGet()/100 + id*200)%360; glDisable(GL_BLEND); glTranslated(0, -.5, -.5); glScaled(.7, .7, .5); glRotated(angle, 0, 1, 0); duType(city->Race->GetUtype(id), city->Owner->Color); }
virtual bool cmd(byte cmd) { LOGA("ST: cmd=%d", cmd); if (cmd == 3) { // up // go to edit dataHolder.put(timeGet()); } if (cmd == 4) { // right if (++ m >= 4) m = 1; // circle: hh:mm | mm:ss | day updateDisp(); } return true; }
void updateDisp() { Time time = timeGet(); switch (m) { case 1: { dprintd2(disp, time.h, time.m); if (time.s % 2 == 0) disp[1] |= DIG_DOT_MASK; } break; case 2: { dprintd2(disp, time.m, time.s); if (time.s % 2 == 0) disp[1] |= DIG_DOT_MASK; } break; case 3: dprintdint(disp, time.d); break; default: { // show "Err" SET_DISP(disp, DIG_EMPTY_MASK, DIG_E_MASK, DIG_R_MASK, DIG_R_MASK); } } }
void aiC::Execute(bool serverHasUpdatedGameState) { switch(aiStatus) { // just started, need to connect with server case 0: if(netConnected()) aiStatus++; else if(timeGet() - aiLastCommand > 2000) { pf("ai %s, trying to connect:\n", Name); cmd("name AI-%s", Name); cmd("join localhost"); aiLastCommand = timeGet(); } break; // waiting for other players to join case 1: if(game && game->Turn > 0) aiStatus++; else //if(playercount() > 1) if(timeGet() - aiLastCommand > 2000) { cmd("ready"); aiLastCommand = timeGet(); } break; // choose picks case 2: if(self->Status == BRAIN_ACTIVE) aiStatus++; else if(timeGet() - aiLastCommand > 2000) { Pick(); aiLastCommand = timeGet(); } // play case 3: if(serverHasUpdatedGameState) Think(); break; } }
int main ( int argc, char *argv[] ) { DDS_ConditionSeq *conditionList; DDS_WaitSet w; DDS_Condition exp_condition; pong_handler *active_handler; DDS_DomainParticipantQos *dpQos; DDS_TopicQos *tQos; DDS_PublisherQos *pQos; DDS_DataWriterQos *dwQos; DDS_SubscriberQos *sQos; DDS_DataReaderQos *drQos; time_t clock = time (NULL); DDS_Duration_t wait_timeout = {3,0}; DDS_ReturnCode_t result; DDS_boolean finish_flag = FALSE; DDS_boolean timeout_flag = FALSE; DDS_boolean terminate = FALSE; int imax = 1; int i; unsigned int block; init_clock(); /* * init timing statistics */ init_stats (&roundtrip, "round_trip"); init_stats (&write_access, "write_access"); init_stats (&read_access, "read_access"); /* * Evaluate cmdline arguments */ if (argc != 1) { if (argc != 6) { printf ("Invalid.....\n Usage: %s [blocks blocksize topic_id WRITE_PARTITION READ_PARTITION]\n", argv[0]); exit (1); } nof_blocks = atoi (argv[1]); nof_cycles = atoi (argv[2]); topic_id = argv[3][0]; write_partition = argv[4]; read_partition = argv[5]; } /* * Create WaitSet */ w = DDS_WaitSet__alloc (); /* * Initialize Qos variables */ dpQos = DDS_DomainParticipantQos__alloc(); tQos = DDS_TopicQos__alloc(); pQos = DDS_PublisherQos__alloc(); dwQos = DDS_DataWriterQos__alloc(); sQos = DDS_SubscriberQos__alloc(); drQos = DDS_DataReaderQos__alloc(); /* * Initialize condition list */ conditionList = NULL; /* * Create participant */ dpf = DDS_DomainParticipantFactory_get_instance (); dp = DDS_DomainParticipantFactory_create_participant (dpf, myDomain, DDS_PARTICIPANT_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); if (dp == DDS_HANDLE_NIL) { printf ("%s PING: ERROR - Splice Daemon not running", argv[0]); exit (1); } /* * Create PING publisher */ DDS_DomainParticipant_get_default_publisher_qos (dp, pQos); pQos->partition.name._length = 1; pQos->partition.name._maximum = 1; pQos->partition.name._buffer = DDS_StringSeq_allocbuf (1); pQos->partition.name._buffer[0] = DDS_string_alloc (strlen(write_partition) + 1); strcpy (pQos->partition.name._buffer[0], write_partition); p = DDS_DomainParticipant_create_publisher (dp, pQos, NULL, DDS_STATUS_MASK_NONE); DDS_free (pQos); /* * Create PONG subscriber */ DDS_DomainParticipant_get_default_subscriber_qos (dp, sQos); sQos->partition.name._length = 1; sQos->partition.name._maximum = 1; sQos->partition.name._buffer = DDS_StringSeq_allocbuf (1); sQos->partition.name._buffer[0] = DDS_string_alloc (strlen(read_partition) + 1); strcpy (sQos->partition.name._buffer[0], read_partition); s = DDS_DomainParticipant_create_subscriber (dp, sQos, NULL, DDS_STATUS_MASK_NONE); DDS_free (sQos); /* * PP_min_msg */ /* Create Topic */ PP_min_dt = pingpong_PP_min_msgTypeSupport__alloc (); pingpong_PP_min_msgTypeSupport_register_type (PP_min_dt, dp, "pingpong::PP_min_msg"); PP_min_topic = DDS_DomainParticipant_create_topic (dp, "PP_min_topic", "pingpong::PP_min_msg", DDS_TOPIC_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datawriter */ PP_min_writer = DDS_Publisher_create_datawriter (p, PP_min_topic, DDS_DATAWRITER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datareader */ PP_min_reader = DDS_Subscriber_create_datareader (s, PP_min_topic, DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Add datareader statuscondition to waitset */ PP_min_sc = DDS_DataReader_get_statuscondition (PP_min_reader); DDS_StatusCondition_set_enabled_statuses (PP_min_sc, DDS_DATA_AVAILABLE_STATUS); result = DDS_WaitSet_attach_condition (w, PP_min_sc); /* * PP_seq_msg */ /* Create Topic */ PP_seq_dt = pingpong_PP_seq_msgTypeSupport__alloc (); pingpong_PP_seq_msgTypeSupport_register_type (PP_seq_dt, dp, "pingpong::PP_seq_msg"); PP_seq_topic = DDS_DomainParticipant_create_topic (dp, "PP_seq_topic", "pingpong::PP_seq_msg", DDS_TOPIC_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datawriter */ PP_seq_writer = DDS_Publisher_create_datawriter (p, PP_seq_topic, DDS_DATAWRITER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datareader */ PP_seq_reader = DDS_Subscriber_create_datareader (s, PP_seq_topic, DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Add datareader statuscondition to waitset */ PP_seq_sc = DDS_DataReader_get_statuscondition (PP_seq_reader); DDS_StatusCondition_set_enabled_statuses (PP_seq_sc, DDS_DATA_AVAILABLE_STATUS); result = DDS_WaitSet_attach_condition (w, PP_seq_sc); /* * PP_string_msg */ /* Create Topic */ PP_string_dt = pingpong_PP_string_msgTypeSupport__alloc (); pingpong_PP_string_msgTypeSupport_register_type (PP_string_dt, dp, "pingpong::PP_string_msg"); PP_string_topic = DDS_DomainParticipant_create_topic (dp, "PP_string_topic", "pingpong::PP_string_msg", DDS_TOPIC_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datawriter */ PP_string_writer = DDS_Publisher_create_datawriter (p, PP_string_topic, DDS_DATAWRITER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datareader */ PP_string_reader = DDS_Subscriber_create_datareader (s, PP_string_topic, DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Add datareader statuscondition to waitset */ PP_string_sc = DDS_DataReader_get_statuscondition (PP_string_reader); DDS_StatusCondition_set_enabled_statuses (PP_string_sc, DDS_DATA_AVAILABLE_STATUS); result = DDS_WaitSet_attach_condition (w, PP_string_sc); /* * PP_fixed_msg */ /* Create Topic */ PP_fixed_dt = pingpong_PP_fixed_msgTypeSupport__alloc (); pingpong_PP_fixed_msgTypeSupport_register_type (PP_fixed_dt, dp, "pingpong::PP_fixed_msg"); PP_fixed_topic = DDS_DomainParticipant_create_topic (dp, "PP_fixed_topic", "pingpong::PP_fixed_msg", DDS_TOPIC_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datawriter */ PP_fixed_writer = DDS_Publisher_create_datawriter (p, PP_fixed_topic, DDS_DATAWRITER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datareader */ PP_fixed_reader = DDS_Subscriber_create_datareader (s, PP_fixed_topic, DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Add datareader statuscondition to waitset */ PP_fixed_sc = DDS_DataReader_get_statuscondition (PP_fixed_reader); DDS_StatusCondition_set_enabled_statuses (PP_fixed_sc, DDS_DATA_AVAILABLE_STATUS); result = DDS_WaitSet_attach_condition (w, PP_fixed_sc); /* * PP_array_msg */ /* Create Topic */ PP_array_dt = pingpong_PP_array_msgTypeSupport__alloc (); pingpong_PP_array_msgTypeSupport_register_type (PP_array_dt, dp, "pingpong::PP_array_msg"); PP_array_topic = DDS_DomainParticipant_create_topic (dp, "PP_array_topic", "pingpong::PP_array_msg", DDS_TOPIC_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datawriter */ PP_array_writer = DDS_Publisher_create_datawriter (p, PP_array_topic, DDS_DATAWRITER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datareader */ PP_array_reader = DDS_Subscriber_create_datareader (s, PP_array_topic, DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Add datareader statuscondition to waitset */ PP_array_sc = DDS_DataReader_get_statuscondition (PP_array_reader); DDS_StatusCondition_set_enabled_statuses (PP_array_sc, DDS_DATA_AVAILABLE_STATUS); result = DDS_WaitSet_attach_condition (w, PP_array_sc); /* * PP_quit_msg */ /* Create Topic */ PP_quit_dt = pingpong_PP_quit_msgTypeSupport__alloc (); pingpong_PP_quit_msgTypeSupport_register_type (PP_quit_dt, dp, "pingpong::PP_quit_msg"); PP_quit_topic = DDS_DomainParticipant_create_topic (dp, "PP_quit_topic", "pingpong::PP_quit_msg", DDS_TOPIC_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datawriter */ PP_quit_writer = DDS_Publisher_create_datawriter (p, PP_quit_topic, DDS_DATAWRITER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); for (block = 0; block < nof_blocks ; block++) { while (!finish_flag) { /* * Send Initial message */ timeout_flag = FALSE; switch(topic_id) { case 'm': { /* printf ("PING: sending initial ping_min\n"); */ pingpong_PP_min_msg *PPdata = pingpong_PP_min_msg__alloc (); exp_condition = PP_min_sc; active_handler = &PP_min_handler; PPdata->count = 0; PPdata->block = block; preWriteTime = timeGet (); result = pingpong_PP_min_msgDataWriter_write (PP_min_writer, PPdata, DDS_HANDLE_NIL); postWriteTime = timeGet (); DDS_free (PPdata); } break; case 'q': { /* printf ("PING: sending initial ping_seq\n"); */ pingpong_PP_seq_msg *PPdata = pingpong_PP_seq_msg__alloc (); exp_condition = PP_seq_sc; active_handler = &PP_seq_handler; PPdata->count = 0; PPdata->block = block; preWriteTime = timeGet (); result = pingpong_PP_seq_msgDataWriter_write (PP_seq_writer, PPdata, DDS_HANDLE_NIL); postWriteTime = timeGet (); DDS_free (PPdata); } break; case 's': { /* printf ("PING: sending initial ping_string\n"); */ pingpong_PP_string_msg *PPdata = pingpong_PP_string_msg__alloc (); exp_condition = PP_string_sc; active_handler = &PP_string_handler; PPdata->count = 0; PPdata->block = block; PPdata->a_string = DDS_string_alloc (8); strcpy (PPdata->a_string, "a_string"); preWriteTime = timeGet (); result = pingpong_PP_string_msgDataWriter_write (PP_string_writer, PPdata, DDS_HANDLE_NIL); postWriteTime = timeGet (); DDS_free (PPdata); } break; case 'f': { /* printf ("PING: sending initial ping_fixed\n"); */ pingpong_PP_fixed_msg *PPdata = pingpong_PP_fixed_msg__alloc (); exp_condition = PP_fixed_sc; active_handler = &PP_fixed_handler; PPdata->count = 0; PPdata->block = block; PPdata->a_bstring = DDS_string_alloc (9); strcpy (PPdata->a_bstring, "a_bstring"); preWriteTime = timeGet (); result = pingpong_PP_fixed_msgDataWriter_write (PP_fixed_writer, PPdata, DDS_HANDLE_NIL); postWriteTime = timeGet (); DDS_free (PPdata); } break; case 'a': { /* printf ("PING: sending initial ping_array\n"); */ pingpong_PP_array_msg *PPdata = pingpong_PP_array_msg__alloc (); exp_condition = PP_array_sc; active_handler = &PP_array_handler; PPdata->count = 0; PPdata->block = block; preWriteTime = timeGet (); result = pingpong_PP_array_msgDataWriter_write (PP_array_writer, PPdata, DDS_HANDLE_NIL); postWriteTime = timeGet (); DDS_free (PPdata); } break; case 't': { /* printf ("PING: sending initial ping_quit\n"); */ pingpong_PP_quit_msg *PPdata = pingpong_PP_quit_msg__alloc(); PPdata->quit = TRUE; terminate = TRUE; finish_flag = TRUE; preWriteTime = timeGet (); result = pingpong_PP_quit_msgDataWriter_write (PP_quit_writer, PPdata, DDS_HANDLE_NIL); postWriteTime = timeGet (); DDS_free (PPdata); } break; default: printf("Invalid topic-id\n"); exit(1); } if (!terminate) { roundTripTime = preWriteTime; add_stats (&write_access, 1E6 * timeToReal (timeSub (postWriteTime, preWriteTime))); /* * Wait for response, calculate timing, and send another data if not ready */ while (!(timeout_flag || finish_flag)) { conditionList = DDS_ConditionSeq__alloc(); result = DDS_WaitSet_wait (w, conditionList, &wait_timeout); if (conditionList) { imax = conditionList->_length; if (imax != 0) { for (i = 0; i < imax; i++) { if (conditionList->_buffer[i] == exp_condition) { finish_flag = active_handler (nof_cycles); } else { printf ("PING: unexpected condition triggered: %x\n", (unsigned int)conditionList->_buffer[i]); } } } else { printf ("PING: TIMEOUT - message lost\n"); timeout_flag = TRUE; } DDS_free(conditionList); } else { printf ("PING: TIMEOUT - message lost\n"); timeout_flag = TRUE; } } } } if (!terminate) { finish_flag = FALSE; if (block == 0) { printf ("# PING PONG measurements (in us) \n"); printf ("# Executed at: %s", ctime(&clock)); printf ("# Roundtrip time [us] Write-access time [us] Read-access time [us]\n"); printf ("# Block Count mean min max Count mean min max Count mean min max\n"); } printf ("%6d %10d %6.0f %6.0f %6.0f %10d %6.0f %6.0f %6.0f %10d %6.0f %6.0f %6.0f\n", block, roundtrip.count, roundtrip.average, roundtrip.min, roundtrip.max, write_access.count, write_access.average, write_access.min, write_access.max, read_access.count, read_access.average, read_access.min, read_access.max); fflush (NULL); init_stats (&write_access, "write_access"); init_stats (&read_access, "read_access"); init_stats (&roundtrip, "round_trip"); } } result = DDS_Subscriber_delete_datareader (s, PP_min_reader); result = DDS_Publisher_delete_datawriter (p, PP_min_writer); result = DDS_Subscriber_delete_datareader (s, PP_seq_reader); result = DDS_Publisher_delete_datawriter (p, PP_seq_writer); result = DDS_Subscriber_delete_datareader (s, PP_string_reader); result = DDS_Publisher_delete_datawriter (p, PP_string_writer); result = DDS_Subscriber_delete_datareader (s, PP_fixed_reader); result = DDS_Publisher_delete_datawriter (p, PP_fixed_writer); result = DDS_Subscriber_delete_datareader (s, PP_array_reader); result = DDS_Publisher_delete_datawriter (p, PP_array_writer); result = DDS_Publisher_delete_datawriter (p, PP_quit_writer); result = DDS_DomainParticipant_delete_subscriber (dp, s); result = DDS_DomainParticipant_delete_publisher (dp, p); result = DDS_DomainParticipant_delete_topic (dp, PP_min_topic); result = DDS_DomainParticipant_delete_topic (dp, PP_seq_topic); result = DDS_DomainParticipant_delete_topic (dp, PP_string_topic); result = DDS_DomainParticipant_delete_topic (dp, PP_fixed_topic); result = DDS_DomainParticipant_delete_topic (dp, PP_array_topic); result = DDS_DomainParticipant_delete_topic (dp, PP_quit_topic); result = DDS_DomainParticipantFactory_delete_participant (dpf, dp); DDS_free (w); DDS_free (PP_min_dt); DDS_free (PP_seq_dt); DDS_free (PP_string_dt); DDS_free (PP_fixed_dt); DDS_free (PP_array_dt); DDS_free (PP_quit_dt); DDS_free (dpQos); DDS_free (tQos); DDS_free (dwQos); DDS_free (drQos); return 0; }
/********************************************************************************************************** ** Function name: date ** Descriptions: display now month calendar with color, like this: ** ----------------------------- ** SUN MON TUE WED THU FRI SAT ** ----------------------------- ** 1 2 ** 3 4 5 6 7 8 9 ** 10 11 12 13 14 15 16 ** 17 18 19 20 21 22 23 ** 24 25 26 27 28 29 30 ** 31 ** ----------------------------- ** input parameters: NONE ** output parameters: NONE ** Returned value: OK: Always ** Created by: WangDongfang ** Created Date: 2010-07-02 **--------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: **--------------------------------------------------------------------------------------------------------- **********************************************************************************************************/ STATUS C_date (int argc, char **argv) { int iFirstWeekday; int iDays; int i; int set_val; NONGLI_DATE nong_date; TIME_SOCKET tsTimeSet; TIME_SOCKET tsTimeNow; tsTimeSet = timeGet(); /* * set time if need */ if (argc >= 2) { sscanf (argv[1], "%d", (unsigned int *)&set_val); if (set_val != 0) { tsTimeSet.iYear = set_val; } } if (argc >= 3) { sscanf (argv[2], "%d", (unsigned int *)&set_val); if (set_val != 0) { tsTimeSet.iMon = set_val; } } if (argc >= 4) { sscanf (argv[3], "%d", (unsigned int *)&set_val); if (set_val != 0) { tsTimeSet.iDay = set_val; } } if (argc >= 5) { sscanf (argv[4], "%d", (unsigned int *)&tsTimeSet.iHour); } if (argc >= 6) { sscanf (argv[5], "%d", (unsigned int *)&tsTimeSet.iMin); } if (argc >= 7) { sscanf (argv[6], "%d", (unsigned int *)&tsTimeSet.iSec); } if (argc >= 2) { timeSet (tsTimeSet); } /* * get now time */ tsTimeNow = timeGet(); iFirstWeekday = (7 - (tsTimeNow.iDay - 1) % 7 + tsTimeNow.iWday) % 7; iDays = monthDays(tsTimeNow.iYear, tsTimeNow.iMon); MODE_BEGIN_STRING_DATE printf("Date : %d-%02d-%02d\n" "Today : %s\n", tsTimeNow.iYear, tsTimeNow.iMon, tsTimeNow.iDay, __GpcWeeks[tsTimeNow.iWday]); MODE_BEGIN_FRAME printf("-----------------------------\n"); for (i = 0; i < 7; i++) { /* SUN MON TUE ... SAT */ printf(" %s", __GpcWeeksShort[i]); } printf("\n"); printf("-----------------------------\n"); for (i = 0; i < iFirstWeekday; i++) { /* The Blanks before 1# */ printf(" "); } for (i = 1; i <= iDays; i++) { /* The days 1# ... 31# */ if (iFirstWeekday == 6 || iFirstWeekday == 0) { MODE_BEGIN_WEEKEND } else { MODE_BEGIN_WEEKDAY } if (i == tsTimeNow.iDay) { printf(" "); MODE_BEGIN_TODDAY printf("%2d", i); MODE_END_TODDAY } else {
void timerC::Stop() { Eta += timeGet() - TStart; }
void timerC::Start() { TStart = timeGet(); }
int OSPL_MAIN (int argc, char ** argv) #endif { DDS_ConditionSeq *conditionList; DDS_WaitSet w; DDS_DomainParticipantQos *dpQos; DDS_TopicQos *tQos; DDS_PublisherQos *pQos; DDS_DataWriterQos *dwQos; DDS_SubscriberQos *sQos; DDS_DataReaderQos *drQos; DDS_Condition exp_condition = NULL; pong_handler *active_handler = NULL; DDS_Duration_t wait_timeout = {3,0}; DDS_boolean finish_flag = FALSE; DDS_boolean timeout_flag = FALSE; DDS_boolean terminate = FALSE; DDS_ReturnCode_t result; int imax = 1; int i; unsigned int block; printf ("Starting ping example\n"); fflush(stdout); /* * init timing statistics */ init_stats (&roundtrip, "round_trip"); init_stats (&write_access, "write_access"); init_stats (&read_access, "read_access"); /* * Evaluate cmdline arguments */ #ifdef INTEGRITY nof_blocks = 100; nof_cycles = 100; #if defined (PING1) topic_id = 'm'; #elif defined (PING2) topic_id = 'q'; #elif defined (PING3) topic_id = 's'; #elif defined (PING4) topic_id = 'f'; #elif defined (PING5) topic_id = 'b'; #elif defined (PING6) nof_blocks = 1; nof_cycles = 10; topic_id = 't'; #endif write_partition = "PongRead"; read_partition = "PongWrite"; #else if (argc != 1) { if (argc != 6) { printf ("Invalid.....\n Usage: %s [blocks blocksize topic_id WRITE_PARTITION READ_PARTITION]\n", argv[0]); exit (1); } nof_blocks = atoi (argv[1]); nof_cycles = atoi (argv[2]); topic_id = argv[3][0]; write_partition = argv[4]; read_partition = argv[5]; } #endif #ifdef _WIN32 init_clock(); #endif /* * Create WaitSet */ w = DDS_WaitSet__alloc (); /* * Initialize Qos variables */ dpQos = DDS_DomainParticipantQos__alloc(); tQos = DDS_TopicQos__alloc(); pQos = DDS_PublisherQos__alloc(); dwQos = DDS_DataWriterQos__alloc(); sQos = DDS_SubscriberQos__alloc(); drQos = DDS_DataReaderQos__alloc(); /* * Initialize condition list */ conditionList = NULL; /* * Create participant */ dpf = DDS_DomainParticipantFactory_get_instance (); dp = DDS_DomainParticipantFactory_create_participant (dpf, myDomain, DDS_PARTICIPANT_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); if (dp == DDS_HANDLE_NIL) { printf ("%s PING: ERROR - Splice Daemon not running", argv[0]); exit (1); } /* * Create PING publisher */ DDS_DomainParticipant_get_default_publisher_qos (dp, pQos); pQos->partition.name._length = 1; pQos->partition.name._maximum = 1; pQos->partition.name._buffer = DDS_StringSeq_allocbuf (1); pQos->partition.name._buffer[0] = DDS_string_dup (write_partition); p = DDS_DomainParticipant_create_publisher (dp, pQos, NULL, DDS_STATUS_MASK_NONE); DDS_free (pQos); /* * Create PONG subscriber */ DDS_DomainParticipant_get_default_subscriber_qos (dp, sQos); sQos->partition.name._length = 1; sQos->partition.name._maximum = 1; sQos->partition.name._buffer = DDS_StringSeq_allocbuf (1); sQos->partition.name._buffer[0] = DDS_string_dup (read_partition); s = DDS_DomainParticipant_create_subscriber (dp, sQos, NULL, DDS_STATUS_MASK_NONE); DDS_free (sQos); /* * PP_min_msg */ /* Create Topic */ PP_min_dt = pingpong_PP_min_msgTypeSupport__alloc (); pingpong_PP_min_msgTypeSupport_register_type (PP_min_dt, dp, "pingpong::PP_min_msg"); PP_min_topic = DDS_DomainParticipant_create_topic (dp, "PP_min_topic", "pingpong::PP_min_msg", DDS_TOPIC_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); DDS_Publisher_get_default_datawriter_qos(p, dwQos); dwQos->reliability.kind = DDS_BEST_EFFORT_RELIABILITY_QOS; dwQos->history.kind = DDS_KEEP_ALL_HISTORY_QOS; /* Create datawriter */ PP_min_writer = DDS_Publisher_create_datawriter (p, PP_min_topic, dwQos, NULL, DDS_STATUS_MASK_NONE); /* Create datareader */ PP_min_reader = DDS_Subscriber_create_datareader (s, PP_min_topic, DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Add datareader statuscondition to waitset */ PP_min_sc = DDS_DataReader_get_statuscondition (PP_min_reader); DDS_StatusCondition_set_enabled_statuses (PP_min_sc, DDS_DATA_AVAILABLE_STATUS); DDS_WaitSet_attach_condition (w, PP_min_sc); /* * PP_seq_msg */ /* Create Topic */ PP_seq_dt = pingpong_PP_seq_msgTypeSupport__alloc (); pingpong_PP_seq_msgTypeSupport_register_type (PP_seq_dt, dp, "pingpong::PP_seq_msg"); PP_seq_topic = DDS_DomainParticipant_create_topic (dp, "PP_seq_topic", "pingpong::PP_seq_msg", DDS_TOPIC_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datawriter */ PP_seq_writer = DDS_Publisher_create_datawriter (p, PP_seq_topic, dwQos, NULL, DDS_STATUS_MASK_NONE); /* Create datareader */ PP_seq_reader = DDS_Subscriber_create_datareader (s, PP_seq_topic, DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Add datareader statuscondition to waitset */ PP_seq_sc = DDS_DataReader_get_statuscondition (PP_seq_reader); DDS_StatusCondition_set_enabled_statuses (PP_seq_sc, DDS_DATA_AVAILABLE_STATUS); DDS_WaitSet_attach_condition (w, PP_seq_sc); /* * PP_string_msg */ /* Create Topic */ PP_string_dt = pingpong_PP_string_msgTypeSupport__alloc (); pingpong_PP_string_msgTypeSupport_register_type (PP_string_dt, dp, "pingpong::PP_string_msg"); PP_string_topic = DDS_DomainParticipant_create_topic (dp, "PP_string_topic", "pingpong::PP_string_msg", DDS_TOPIC_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datawriter */ PP_string_writer = DDS_Publisher_create_datawriter (p, PP_string_topic, dwQos, NULL, DDS_STATUS_MASK_NONE); /* Create datareader */ PP_string_reader = DDS_Subscriber_create_datareader (s, PP_string_topic, DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Add datareader statuscondition to waitset */ PP_string_sc = DDS_DataReader_get_statuscondition (PP_string_reader); DDS_StatusCondition_set_enabled_statuses (PP_string_sc, DDS_DATA_AVAILABLE_STATUS); DDS_WaitSet_attach_condition (w, PP_string_sc); /* * PP_fixed_msg */ /* Create Topic */ PP_fixed_dt = pingpong_PP_fixed_msgTypeSupport__alloc (); pingpong_PP_fixed_msgTypeSupport_register_type (PP_fixed_dt, dp, "pingpong::PP_fixed_msg"); PP_fixed_topic = DDS_DomainParticipant_create_topic (dp, "PP_fixed_topic", "pingpong::PP_fixed_msg", DDS_TOPIC_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datawriter */ PP_fixed_writer = DDS_Publisher_create_datawriter (p, PP_fixed_topic, dwQos, NULL, DDS_STATUS_MASK_NONE); /* Create datareader */ PP_fixed_reader = DDS_Subscriber_create_datareader (s, PP_fixed_topic, DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Add datareader statuscondition to waitset */ PP_fixed_sc = DDS_DataReader_get_statuscondition (PP_fixed_reader); DDS_StatusCondition_set_enabled_statuses (PP_fixed_sc, DDS_DATA_AVAILABLE_STATUS); DDS_WaitSet_attach_condition (w, PP_fixed_sc); /* * PP_array_msg */ /* Create Topic */ PP_array_dt = pingpong_PP_array_msgTypeSupport__alloc (); pingpong_PP_array_msgTypeSupport_register_type (PP_array_dt, dp, "pingpong::PP_array_msg"); PP_array_topic = DDS_DomainParticipant_create_topic (dp, "PP_array_topic", "pingpong::PP_array_msg", DDS_TOPIC_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datawriter */ PP_array_writer = DDS_Publisher_create_datawriter (p, PP_array_topic, dwQos, NULL, DDS_STATUS_MASK_NONE); /* Create datareader */ PP_array_reader = DDS_Subscriber_create_datareader (s, PP_array_topic, DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Add datareader statuscondition to waitset */ PP_array_sc = DDS_DataReader_get_statuscondition (PP_array_reader); DDS_StatusCondition_set_enabled_statuses (PP_array_sc, DDS_DATA_AVAILABLE_STATUS); DDS_WaitSet_attach_condition (w, PP_array_sc); /* * PP_bseq_msg */ /* Create Topic */ PP_bseq_dt = pingpong_PP_bseq_msgTypeSupport__alloc (); pingpong_PP_bseq_msgTypeSupport_register_type (PP_bseq_dt, dp, "pingpong::PP_bseq_msg"); PP_bseq_topic = DDS_DomainParticipant_create_topic (dp, "PP_bseq_topic", "pingpong::PP_bseq_msg", DDS_TOPIC_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datawriter */ PP_bseq_writer = DDS_Publisher_create_datawriter (p, PP_bseq_topic, dwQos, NULL, DDS_STATUS_MASK_NONE); /* Create datareader */ PP_bseq_reader = DDS_Subscriber_create_datareader (s, PP_bseq_topic, DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Add datareader statuscondition to waitset */ PP_bseq_sc = DDS_DataReader_get_statuscondition (PP_bseq_reader); DDS_StatusCondition_set_enabled_statuses (PP_bseq_sc, DDS_DATA_AVAILABLE_STATUS); DDS_WaitSet_attach_condition (w, PP_bseq_sc); /* * PP_quit_msg */ /* Create Topic */ PP_quit_dt = pingpong_PP_quit_msgTypeSupport__alloc (); pingpong_PP_quit_msgTypeSupport_register_type (PP_quit_dt, dp, "pingpong::PP_quit_msg"); PP_quit_topic = DDS_DomainParticipant_create_topic (dp, "PP_quit_topic", "pingpong::PP_quit_msg", DDS_TOPIC_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE); /* Create datawriter */ PP_quit_writer = DDS_Publisher_create_datawriter (p, PP_quit_topic, dwQos, NULL, DDS_STATUS_MASK_NONE); /* Fr: workarround for ticket dds1712 */ conditionList = DDS_ConditionSeq__alloc(); assert(conditionList); DDS_WaitSet_wait (w, conditionList, &wait_timeout); DDS_free(conditionList); for (block = 0; block < nof_blocks && !terminate ; block++) { while (!finish_flag) { /* * Send Initial message */ timeout_flag = FALSE; switch(topic_id) { case 'm': { /* printf ("PING: sending initial ping_min\n"); */ pingpong_PP_min_msg *PPdata = pingpong_PP_min_msg__alloc (); exp_condition = PP_min_sc; active_handler = &PP_min_handler; PPdata->count = 0; PPdata->block = block; preWriteTime = timeGet (); pingpong_PP_min_msgDataWriter_write (PP_min_writer, PPdata, DDS_HANDLE_NIL); postWriteTime = timeGet (); DDS_free (PPdata); } break; case 'q': { /* printf ("PING: sending initial ping_seq\n"); */ pingpong_PP_seq_msg *PPdata = pingpong_PP_seq_msg__alloc (); exp_condition = PP_seq_sc; active_handler = &PP_seq_handler; PPdata->count = 0; PPdata->block = block; { int i = 0; PPdata->payload._buffer = pingpong_seq_char_allocbuf(SEQ_PAYLOAD_SIZE); PPdata->payload._length = SEQ_PAYLOAD_SIZE; PPdata->payload._maximum = SEQ_PAYLOAD_SIZE; for (i=0; i<SEQ_PAYLOAD_SIZE; i++) { PPdata->payload._buffer[i] = (char)i; } } preWriteTime = timeGet (); pingpong_PP_seq_msgDataWriter_write (PP_seq_writer, PPdata, DDS_HANDLE_NIL); postWriteTime = timeGet (); DDS_free (PPdata); } break; case 's': { /* printf ("PING: sending initial ping_string\n"); */ pingpong_PP_string_msg *PPdata = pingpong_PP_string_msg__alloc (); exp_condition = PP_string_sc; active_handler = &PP_string_handler; PPdata->count = 0; PPdata->block = block; PPdata->a_string = DDS_string_dup ("a_string"); preWriteTime = timeGet (); pingpong_PP_string_msgDataWriter_write (PP_string_writer, PPdata, DDS_HANDLE_NIL); postWriteTime = timeGet (); DDS_free (PPdata); } break; case 'f': { /* printf ("PING: sending initial ping_fixed\n"); */ pingpong_PP_fixed_msg *PPdata = pingpong_PP_fixed_msg__alloc (); exp_condition = PP_fixed_sc; active_handler = &PP_fixed_handler; PPdata->count = 0; PPdata->block = block; PPdata->a_bstring = DDS_string_dup ("a_bstring"); preWriteTime = timeGet (); pingpong_PP_fixed_msgDataWriter_write (PP_fixed_writer, PPdata, DDS_HANDLE_NIL); postWriteTime = timeGet (); DDS_free (PPdata); } break; case 'a': { /* printf ("PING: sending initial ping_array\n"); */ pingpong_PP_array_msg *PPdata = pingpong_PP_array_msg__alloc (); exp_condition = PP_array_sc; active_handler = &PP_array_handler; PPdata->count = 0; PPdata->block = block; preWriteTime = timeGet (); pingpong_PP_array_msgDataWriter_write (PP_array_writer, PPdata, DDS_HANDLE_NIL); postWriteTime = timeGet (); DDS_free (PPdata); } break; case 'b': { /* printf ("PING: sending initial ping_bseq_msg\n"); */ pingpong_PP_bseq_msg *PPdata = pingpong_PP_bseq_msg__alloc (); exp_condition = PP_bseq_sc; active_handler = &PP_bseq_handler; PPdata->count = 0; PPdata->block = block; preWriteTime = timeGet (); pingpong_PP_bseq_msgDataWriter_write (PP_bseq_writer, PPdata, DDS_HANDLE_NIL); postWriteTime = timeGet (); DDS_free (PPdata); } break; case 't': { /* printf ("PING: sending initial ping_quit\n"); */ pingpong_PP_quit_msg *PPdata = pingpong_PP_quit_msg__alloc(); PPdata->quit = TRUE; terminate = TRUE; finish_flag = TRUE; sleep(1); preWriteTime = timeGet (); pingpong_PP_quit_msgDataWriter_write (PP_quit_writer, PPdata, DDS_HANDLE_NIL); postWriteTime = timeGet (); sleep(1); DDS_free (PPdata); } break; default: printf("Invalid topic-id\n"); exit(1); } if (!terminate) { roundTripTime = preWriteTime; add_stats (&write_access, 1E6 * timeToReal (timeSub (postWriteTime, preWriteTime))); /* * Wait for response, calculate timing, and send another data if not ready */ while (!(timeout_flag || finish_flag)) { conditionList = DDS_ConditionSeq__alloc(); result = DDS_WaitSet_wait (w, conditionList, &wait_timeout); if(result == DDS_RETCODE_OK || result == DDS_RETCODE_NO_DATA || result == DDS_RETCODE_TIMEOUT) { if (conditionList) { imax = conditionList->_length; if (imax != 0) { for (i = 0; i < imax; i++) { if (conditionList->_buffer[i] == exp_condition) { finish_flag = active_handler (nof_cycles); } else { printf ("PING: unexpected condition triggered: %lx\n", (unsigned long)conditionList->_buffer[i]); } } } else { printf ("PING: TIMEOUT - message lost\n"); timeout_flag = TRUE; } DDS_free(conditionList); } else { printf ("PING: TIMEOUT - message lost\n"); timeout_flag = TRUE; } } else { printf ("PING: Waitset wait failed (code %d), terminating.\n", result); finish_flag = TRUE; terminate = TRUE; } } } } if (!terminate) { finish_flag = FALSE; if (block == 0) { printf ("# PING PONG measurements (in us) \n"); printf ("# Roundtrip time [us] Write-access time [us] Read-access time [us]\n"); printf ("# Block Count mean min max Count mean min max Count mean min max\n"); } printf ("%6d %10d %6.0f %6.0f %6.0f %10d %6.0f %6.0f %6.0f %10d %6.0f %6.0f %6.0f\n", block, roundtrip.count, roundtrip.average, roundtrip.min, roundtrip.max, write_access.count, write_access.average, write_access.min, write_access.max, read_access.count, read_access.average, read_access.min, read_access.max); fflush (stdout); init_stats (&write_access, "write_access"); init_stats (&read_access, "read_access"); init_stats (&roundtrip, "round_trip"); } } DDS_Subscriber_delete_datareader (s, PP_min_reader); DDS_Publisher_delete_datawriter (p, PP_min_writer); DDS_Subscriber_delete_datareader (s, PP_seq_reader); DDS_Publisher_delete_datawriter (p, PP_seq_writer); DDS_Subscriber_delete_datareader (s, PP_string_reader); DDS_Publisher_delete_datawriter (p, PP_string_writer); DDS_Subscriber_delete_datareader (s, PP_fixed_reader); DDS_Publisher_delete_datawriter (p, PP_fixed_writer); DDS_Subscriber_delete_datareader (s, PP_array_reader); DDS_Publisher_delete_datawriter (p, PP_array_writer); DDS_Subscriber_delete_datareader (s, PP_bseq_reader); DDS_Publisher_delete_datawriter (p, PP_bseq_writer); DDS_Publisher_delete_datawriter (p, PP_quit_writer); DDS_DomainParticipant_delete_subscriber (dp, s); DDS_DomainParticipant_delete_publisher (dp, p); DDS_DomainParticipant_delete_topic (dp, PP_min_topic); DDS_DomainParticipant_delete_topic (dp, PP_seq_topic); DDS_DomainParticipant_delete_topic (dp, PP_string_topic); DDS_DomainParticipant_delete_topic (dp, PP_fixed_topic); DDS_DomainParticipant_delete_topic (dp, PP_array_topic); DDS_DomainParticipant_delete_topic (dp, PP_bseq_topic); DDS_DomainParticipant_delete_topic (dp, PP_quit_topic); DDS_DomainParticipantFactory_delete_participant (dpf, dp); DDS_free (w); DDS_free (PP_min_dt); DDS_free (PP_seq_dt); DDS_free (PP_string_dt); DDS_free (PP_fixed_dt); DDS_free (PP_array_dt); DDS_free (PP_bseq_dt); DDS_free (PP_quit_dt); DDS_free (dpQos); DDS_free (tQos); DDS_free (dwQos); DDS_free (drQos); printf ("Completed ping example\n"); fflush(stdout); return 0; }
void performCommandPLC() { UINT8 ui8NameStrDL[15]; UINT32 pos; UINT32 err = SUCCESS; UINT32 ui32dstDirPos; switch(ucHMI_addr) { case PLC_TIME: stime.tm_sec = uiHMIWord[PLC_TIME+5]; stime.tm_min = uiHMIWord[PLC_TIME+4]; stime.tm_hour = uiHMIWord[PLC_TIME+3]; stime.tm_mday = uiHMIWord[PLC_TIME+2]; stime.tm_mon = uiHMIWord[PLC_TIME+1]; stime.tm_year = uiHMIWord[PLC_TIME]-1900; timeSet(&stime); #if C_LEVI_DEBUG printf("time=%d/%d/%d %d:%d:%d ",uiHMIWord[PLC_TIME],uiHMIWord[PLC_TIME+1],uiHMIWord[PLC_TIME+2],uiHMIWord[PLC_TIME+3],uiHMIWord[PLC_TIME+4],uiHMIWord[PLC_TIME+5]); #endif if((uiHMIWord[PLC_TIME]!=2000)||(uiHMIWord[PLC_TIME+1]!=01)) ui8TimeFlag = 1; timeGet(&ptime); sio_psprintf(ui8NameStrDL, "%02d%02d%02dDC.CSV", (UINT32)(ptime->tm_year-100)%100, ptime->tm_mon,ptime->tm_mday); xdcfCurRootDirSet(ui8TermModule); //mp3_GetFileList(); pos = myFindFile(ui8NameStrDL); myGetSingleDayDL(pos, &ui32SuccessNum); break; case PLC_PARA_BUF: memcpy((UINT8 *)&curDevice, (UINT8 *)&uiHMIWord[PLC_PARA_BUF], C_PLC_PARA_NUM*sizeof(UINT16)); #if C_LEVI_DEBUG printf("device=%d, class=%d ",uiHMIWord[PLC_MODULE_NO],uiHMIWord[PLC_MODULE_NO+1]); #endif getModuleName(ui16CurModule, ui8TermModule); writePara(); //readPara(); break; case PLC_MODULE_NO: #if C_LEVI_DEBUG printf("device=%d, class=%d ",uiHMIWord[PLC_MODULE_NO],uiHMIWord[PLC_MODULE_NO+1]); #endif ui16CurModule = uiHMIWord[PLC_MODULE_NO]; ui16CurClass = uiHMIWord[PLC_MODULE_NO+1]; getModuleName(ui16CurModule, ui8TermModule); readPara(); writePara(); readParadelaytime(); writeParadelaytime(); break; case TESTSTEP0: test_step0=(~uiHMIWord[TESTSTEP0])&0xffff; test_step1=(~uiHMIWord[TESTSTEP1])&0xff; test_mode=(uiHMIWord[TestMode]&0x01); printf("test_step0=%d, test_step1=%d, test_mode=%d ",test_step0,test_step1,test_mode); break; case delay_time: memcpy((UINT8 *)&delay,(UINT8 *)&uiHMIWord[delay_time],C_delay_NUM*sizeof(UINT16)); //memcpy((UINT8 *)&uiHMIWord[delay_time], (UINT8 *)&delay, C_delay_NUM*sizeof(UINT16)); getModuleName(ui16CurModule, ui8TermModule); writeParadelaytime(); //readParadelaytime(); break; case PLC_BAKCMD: gpioConfig(GPIO_CARD_DET, 0); gpioSet(GPIO_CARD_DET, 1); if(gpioGet(GPIO_CARD_DET)==0) { err = xdcfActiveDevIdSet(DRIVE_SD); xdcfInit(imageDirNameStr, imageFileNameStr, 0); dirInit(); if(err==SUCCESS) { xdcfChange2Root(); vfsMkdir(ui8TermModule); xdcfCurRootDirSet(ui8TermModule); xdcfCurDirPosGet(&ui32dstDirPos); myXdcfDelFile(); xdcfActiveDevIdSet(DRIVE_NAND); xdcfCurRootDirSet(ui8TermModule); xdcfChange2Root(); vfsChdir(ui8TermModule); err |= myXdcfCopyDisk(ui32dstDirPos); if(uiHMIWord[PLC_BAKCMD]) { myXdcfDelFile(); } if(err==SUCCESS) uiHMIWord[PLC_BAKINFO] = 2; else uiHMIWord[PLC_BAKINFO] = 4; // ¶ÁSD¿¨´íÎó } else { uiHMIWord[PLC_BAKINFO] = 4; // ¶ÁSD¿¨´íÎó } } else { uiHMIWord[PLC_BAKINFO] = 3; // ûÓÐSD¿¨ } #if C_FILE_DEBUG printf("backup end "); #endif break; default: break; } }