Exemple #1
0
int sys_stime( int* tptr ) {
    if ( tptr == NULL ) {
        return -EINVAL;
    }

    set_system_time( ( time_t* )tptr );

    return 0;
}
// Apply Time Zone
// called on recovery start or when changing time zone in menu
// on recovery start, it will read and set t_zone.value, t_zone_offset.value and use_dst_time.value values
// when called from time zone menu, it will only write and apply t_zone.value
// system time is set when calling set_system_time()
static void apply_time_zone() {
        // called on recovery start, read values and apply time
        // read user config for t_zone.value in UTC hours offset
        char value[PROPERTY_VALUE_MAX];
        t_zone.value = 8;
        t_zone_offset.value = 0;
        use_dst_time.value = 0;
        set_system_time();
}
Exemple #3
0
void RTC1_COUNTER_STOP()
{
    rtc1_counter = NRF_RTC1->COUNTER;
    
    set_system_time( get_system_time() + rtc1_counter/8);
    NRF_RTC1->TASKS_CLEAR = 1;
    NVIC_DisableIRQ(RTC1_IRQn);

    NRF_RTC1->EVTENCLR = RTC_EVTEN_COMPARE0_Msk;
    NRF_RTC1->INTENCLR = RTC_INTENSET_COMPARE0_Msk;
    NRF_RTC1->TASKS_STOP = 1;
}
Exemple #4
0
time_t SNTP_ProcessPacket(uint8_t packet[], uint16_t length)
{
	if(length != sizeof(SNTP_Header_t))
		return 0;

	SNTP_Header_t* SNTP  = (SNTP_Header_t *)packet;

	if ((SNTP->VersionMode & 0x3F) != SNTP_VERSIONMODESERVER || (SNTP->VersionMode & 0xC0) == 0xC0 ||
	    (SNTP->TransmitTimestampSec == 0 && SNTP->TransmitTimestampSub == 0))
		return 0;

	TCNT1 = frac2timer(be32_to_cpu(SNTP->TransmitTimestampSub));
	time_t newTime = be32_to_cpu(SNTP->TransmitTimestampSec) - NTP_OFFSET;
	set_system_time(newTime);

	return newTime;
}
Exemple #5
0
int do_srvr_interface(UBUF *ubp, int first)
{
    int    htyp, hlen, clen, ilen, eflag, bflag, odr, nego_seq, end;
    long int tim;
    time_t time, stime = 0;
    BYTE   buf[MAX_NODE_PSIZE+1], *ip;
    BYTE  *fmw;

    QUEUE *q;
    PKBH  *pkbh;
    PKBUC *pkbuc;
    PKBUI *pkbui;

    SV_D20("do_srvr_interface(1)...\n");

    sigset(SIGINT, sig_int);
    sigset(SIGPIPE, sig_pipe);

    if (first) {
        if (srvr_write_nego_packet(ubp, gtway_start) < 0) { /* GTWAY_START */
            ubp_flush(ubp);
            return(-1);    
        }
    }

    for (nego_seq = eflag = bflag = 0; !eflag && nego_seq < 3; nego_seq++) {
        switch(nego_seq) {
            case 0:    
                if (srvr_write_nego_packet(ubp, req_to_rcv2) < 0) /* REQ_TO_RCV2 */
                    eflag++;
                break;

            case 1:
                if (!Srvr_gwtm_frq || (Srvr_conn_cnt % Srvr_gwtm_frq && !first))
                    continue;    // skip time request phase

                if (srvr_write_nego_packet(ubp, req_to_time) < 0){/* REQ_TO_TIME */
                    eflag++;
                    break;        // proc the response at out of switch
                }
                if (srvr_write_nego_packet(ubp, req_to_cntd) < 0) /* REQ_TO_CNTD */
                    eflag++;
                break;        // proc the response at out of switch

            case 2:
                if (Srvr_gwst_frq && (Srvr_conn_cnt % Srvr_gwst_frq) == 0) {
                    if (srvr_write_dta_of_gtwy(ubp) < 0) {
                        eflag++;
                        break;
                    }
                }

            for (odr = 1; !eflag && odr <= MAX_UORDER; odr++) { /* upwards */
                if (!(q = q_by_order(odr)))
                    continue;
                while(!eflag && (pkbh = q_delete(q))) {
                    if (!(q->flag & Q_IMAGE)) {
                        pkbuc = (PKBUC *)pkbh;

                        SV_D23("\n---> %.2x,%.2x,%.2x\n", pkbuc->b_type, pkbuc->h_mlen, pkbuc->h_mlen+SRVU_HEADLN_CMD);

                        if ((*srvr_ubp_write)(ubp, pkbuc->b_gwid, pkbuc->h_mlen + SRVU_HEADLN_CMD) > 0) {
                            q->tsend++;
                            q->tfail = 0;

                            SV_D12("gtwy-->srvr : %s[%.2x]\n", get_pdu_name(pkbuc->b_type), pkbuc->b_type);

                            Mfree(pkbuc);

                        }
                        else {
                            if (++(pkbuc->h_nretry) > q->maxrt) {
                                q->taway++;

                                L01("do_srvr_interface(9): send: CMDTA_PACKT(%.2x) away.\n", pkbuc->b_type);
                                SV_D01("do_srvr_interface(9): send: CMDTA_PACKT(%.2x) away.\n", pkbuc->b_type);
                                Mfree(pkbuc);
                            }
                            else {
                                q->tfail++;
                                q_insert_bak((PKBH *)pkbuc, q);

                                L01("do_srvr_interface(9): send: CMDTA_PACKT(%.2x) fail.\n", pkbuc->b_type);
                                SV_D01("do_srvr_interface(9): send: CMDTA_PACKT(%.2x) fail.\n", pkbuc->b_type);
                            }
                            eflag++;
                        }
                    }
                    else {
                        pkbui = (PKBUI *)pkbh;

                        SV_D23("\n---> %.2x,%.8x,%.8x\n", pkbui->b_type, pkbui->h_mlen, pkbui->h_mlen+SRVU_HEADLN_IMG);

                        if ((*srvr_ubp_write)(ubp, pkbui->b_gwid, pkbui->h_mlen + SRVU_HEADLN_IMG) > 0) {
                            q->tsend++;
                            q->tfail = 0;

                            SV_D12("gtwy-->srvr : %s[%.2x]\n", get_pdu_name(pkbui->b_type), pkbui->b_type);
                            Mfree(pkbui);

                            if (srvr_write_nego_packet(ubp, req_to_cntd) < 0)
                                eflag++;

                        }
                        else {
                            L03("do_srvr_interface(B): send: IMAGE_PACKT(%.2x):%.8x,%d: fail.\n", pkbui->b_type, pkbui->h_mlen-NDEU_HEADLN_IMG-2, pkbui->h_mlen-NDEU_HEADLN_IMG-2);
                            SV_D03("do_srvr_interface(B): send: IMAGE_PACKT(%.2x):%.8x,%d: fail.\n", pkbui->b_type, pkbui->h_mlen-NDEU_HEADLN_IMG-2, pkbui->h_mlen-NDEU_HEADLN_IMG-2);
                            if (++(pkbui->h_nretry) > q->maxrt) {
                                q->taway++;

                                L01("do_srvr_interface(B): send: CMDTA_PACKT(%.2x) away.\n", pkbui->b_type);
                                SV_D01("do_srvr_interface(B): send: CMDTA_PACKT(%.2x) away.\n", pkbui->b_type);
                                Mfree(pkbui);

                            }
                            else {
                                q->tfail++;
                                q_insert_bak((PKBH *)pkbui, q);

                                L01("do_srvr_interface(B_2): send: CMDTA_PACKT(%.2x) fail.\n", pkbui->b_type);
                                SV_D01("do_srvr_interface(B_2): send: CMDTA_PACKT(%.2x) fail.\n", pkbui->b_type);
                            }
                            eflag++;
                        }
                    }
                } // end while
            } // end for
        } // end switch

        for (end = 0; nego_seq < 2 && !end && !eflag; ) {
            if ((htyp = srvr_packet_head_peek(ubp, &hlen)) < 0) {
                eflag++;
                break; /* hlen :  ln(1)  --> sizeof binary body */
            }

            SV_D12("gtwy<--srvr : %s[%.2x]\n", get_pdu_name(htyp), htyp);

            if (htyp != DN_NORM_FMW && htyp != DN_GTWY_FMW) {
                if ((clen = srvr_dncmd_packet_read(ubp, buf, hlen, htyp)) <= 0) {
                    eflag++;
                    break; /* clen = id(1)+length(1)+address(2)+data(n)+escs */
                }
            }
            else {             // length == 4 byte
                fmw = (BYTE *)Malloc(MAX_FIRMW_SIZE);
                if ((clen = srvr_dnfmw_packet_read(ubp, fmw, hlen)) <= 0) {
                    Mfree(fmw);     /* clen = did(1)+data(n) = 1 + hlen */
                    eflag++;
                    break; 
                }
            }

            switch(htyp) {
                case DN_NORM_CMD:
                    srvr_enque_dncmd(htyp, hlen, clen, buf);
                    continue;    

                case DN_NORM_FMW:
                    srvr_enque_dnfmw(htyp, hlen, clen, fmw);
                    Mfree(fmw);
                    continue;

                case DN_GTWY_FMW:
                    if (srvr_enfuse_gtwy(htyp, hlen, clen, fmw) < 0)
                        eflag++;
                    else
                        bflag++;
                    Mfree(fmw);
                    continue;

                case SET_GW_TIME:
                    SV_D20("time = ");
                    SV_MDH(buf + SRVD_ADROFF_CMD, 4);
                    tim = get_bin_p2_n(buf + SRVD_ADROFF_CMD);
                    /* should be SRVD_DTAOFF_CMD */
                    SV_D21("fd Set OK...[%d]\n", tim);
                    set_system_time(tim);
                    continue;

                case REQ_GW_STAT:
                    if (srvr_write_dta_of_gtwy(ubp) < 0)
                    eflag++;
                    end++; 
                    break;

                case END_OF_SND2: 
                    end++; 
                    break;

                default : 
                    L01("do_srvr_interface(9) : recv: unknown type(%.2x)\n", htyp);
                    SV_D01("do_srvr_interface(9) : recv: unknown type(%.2x)\n", htyp);
                    end++; 
                    eflag++;
            } // end switch
        } // end for
    } // end for

        Srvr_conn_cnt++;
        SV_D01("Srvr_conn_cnt = %d\n", Srvr_conn_cnt);
    if (!eflag) {
    	srvr_write_nego_packet(ubp, end_of_snd3); /* END_OF_SND3 */
    	if (bflag){
            if(Cdma_uart_use) {
                cdma_disc_tcpip(ubp);            
                cdma_disc_circuit(ubp);
            }
            else {
                close(ubp->ufd);
                if(Cdsk_pppd_use) {
                    wakeup_pppd(PPPD_CTRL_PWROFF);
                }
            }
            sleep(3);
            SV_D00("do_srvr_interface(A) : Restart Egtwy..\n");
            srvr_reboot_gtwy();              /* no rturn */
        }
            
    }

    ubp_flush(ubp);

    if (!eflag)
        return(1);
    else
        return(-1);
}
static bool
timeout_test (void)
{
  bool status = true;
  SYNCH_QUEUE mq;
  MyTask task1;
  task1.create_reactor ();
  task1.start (1);
  TestHandler test_handler (task1.get_reactor (), mq);

  // The reactor of taks1 that uses a hrtimer will trigger a timeout in
  // 5 seconds which will enqueue a message block in the queue. At the
  // same moment we calculate a timeout for the dequeue operation for
  // 3 seconds in the future. Than we set the system time 4 seconds back.
  // The condition should timeout because the queue is empty and the trigger
  // only fires after the condition has timed out.
  // Next we start another dequeue for 3 seconds in the future which should
  // return before timing out because by then the trigger should have fired.
  // In case of using regular system time policy for message queue and
  // dequeue timeouts the first dequeue would not have timed out because
  // between calculating the timeout and starting the dequeue the system time
  // shifted back 4 sec causing the trigger to fire before the timeout elapsed.
  // In case timeshifting does not work because of priority problems or such
  // the test should succeed.

  if (!test_handler.trigger_in (ACE_Time_Value (5, 0)))
    ACE_ERROR_RETURN ((LM_ERROR,
                        "(%P|%t) Unable to schedule trigger.\n"),
                      false);

  if (!mq.is_empty ())
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("New queue is not empty!\n")));
      status = false;
    }
  else
    {
      ACE_Message_Block *b = 0;
      ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tv;
      tv = (tv.now () + ACE_Time_Value (3,0)); // Now (monotonic time) + 3 sec

      // shift back in time 4 sec
      set_system_time (ACE_OS::gettimeofday () - ACE_Time_Value (4, 0));

      if (mq.dequeue_head (b, &tv) != -1)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Dequeued before timeout elapsed!\n")));
          status = false;
        }
      else if (errno != EWOULDBLOCK)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%p\n"),
                      ACE_TEXT ("Dequeue timeout should be EWOULDBLOCK, got")));
          status = false;
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("First dequeue timed out: OK\n")));

          tv = (tv.now () + ACE_Time_Value (3,0)); // Now (monotonic time) + 3 sec
          if (mq.dequeue_head (b, &tv) != -1)
            {
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("Second dequeue succeeded: OK\n")));
              delete b;
            }
          else
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("Second dequeue timed out!\n")));
              status = false;
            }
        }

      // restore time
      set_system_time (ACE_OS::gettimeofday () + ACE_Time_Value (4, 0));
    }

  ACE_DEBUG((LM_INFO,
              "(%P|%t) Asking worker thread to finish.\n"));
  task1.stop ();

  ACE_Thread_Manager::instance ()->wait ();

  return status;
}
int run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("Monotonic_Manual_Event_Test"));

#if defined (ACE_HAS_THREADS)
  ACE_Manual_Event_T<ACE_Monotonic_Time_Policy> monotonic_event (0);
  ACE_Manual_Event systime_event (0);
  ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tm_mono;
  ACE_Time_Value tm_sys;

  parse_args (argc, argv);

  //FUZZ: disable check_for_lack_ACE_OS
  ACE_Time_Value wait (7, 0);   // Wait 7 sec
  //FUZZ: enable check_for_lack_ACE_OS

  if (use_monotonic)
    {
      evt = &monotonic_event;
      tm_mono = tm_mono.now () + wait;
      initial_timeout = &tm_mono;
    }
  else
    {
      evt = &systime_event;
      tm_sys = ACE_OS::gettimeofday () + wait;
      initial_timeout = &tm_sys;
    }

  // shift forward in time 3 sec; this will mess up timeouts if
  // monotonic timer is not used
  ACE_Time_Value tv_shift (3, 0);
  set_system_time (ACE_OS::gettimeofday () + tv_shift);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("spawning workers - initial timeout till %#T\n"), initial_timeout));

  if (ACE_Thread_Manager::instance ()->spawn_n
      (static_cast<size_t> (n_workers),
       ACE_THR_FUNC (worker),
       0,
       THR_NEW_LWP) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("spawn_n")),
                      1);

  // gives all workers chance to start
  ACE_OS::sleep (5);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("finished waiting for workers to start\n")));

  // restore time (workers will already have failed without monotonic timer)
  set_system_time (ACE_OS::gettimeofday () - tv_shift);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("sending pulse ()\n")));

  // Release the all workers.
  if (evt->pulse () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("pulse")),
                      1);

  // Wait 2 sec
  ACE_OS::sleep (2);

  //FUZZ: disable check_for_lack_ACE_OS
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("sending signal ()\n")));
  //FUZZ: enable check_for_lack_ACE_OS

  // Signal
  if (evt->signal () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("signal")),
                      1);

  ACE_Thread_Manager::instance ()->wait ();
#else
  ACE_UNUSED_ARG (argc);
  ACE_UNUSED_ARG (argv);
  ACE_ERROR ((LM_INFO,
              ACE_TEXT ("Threads not supported on this platform\n")));
#endif /* ACE_HAS_THREADS */
  ACE_END_TEST;
  return test_result;
}
Exemple #8
0
int
run_main (int , ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Monotonic_Task_Test"));

  int status = 0;

# if defined (ACE_HAS_THREADS)
  MyTask my_task;

  if (my_task.start () == 0)
    {
      // shift back in time 4 sec; this would mess up timeouts if
      // monotonic timer was not used
      ACE_Time_Value tv_shift (4, 0);
      set_system_time (ACE_OS::gettimeofday () - tv_shift);

      if (my_task.put_message () == 0)
        {
          // task should now have finished dequeueing and started waiting for stop signal
          // wait (2sec) on thread manager should timeout

                                                 // use the time policy aware gettimeofday()
                                                 // method of the task to get current time
          ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tv (my_task.gettimeofday ());
          tv += ACE_Time_Value (2, 0);

          // shift another 3 sec back in time; without monotonic timer support in
          // thread manager this would mess up the timed wait
          tv_shift += ACE_Time_Value (3, 0);
          set_system_time (ACE_OS::gettimeofday () - ACE_Time_Value (3,0));

          if (my_task.thr_mgr ()->wait (&tv) == 0)
            {
              ACE_ERROR ((LM_ERROR, ACE_TEXT ("Thread manager did not time out\n")));
              status = 1;
            }
          else
            {
              ACE_Time_Value_T<ACE_Monotonic_Time_Policy> tv_now (my_task.gettimeofday ());

              ACE_DEBUG ((LM_INFO, ACE_TEXT ("Thread manager timed out at %#T\n"), &tv_now));
            }
        }
      else
        status = 1;

      // ok, now stop task
      if (my_task.stop () != 0)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to stop task\n")));
          status = 1;
        }

      // restore time
      set_system_time (ACE_OS::gettimeofday () + tv_shift);
    }
  else
    status = 1;

# endif /* ACE_HAS_THREADS */

  ACE_END_TEST;
  return status;
}