This is Unofficial EPICS BASE Doxygen Site
osdTime.cpp File Reference
#include <sys/types.h>
#include <sys/socket.h>
#include <epicsStdio.h>
#include <rtems.h>
#include <errno.h>
#include <unistd.h>
#include <netinet/in.h>
#include <rtems/rtems_bsdnet_internal.h>
#include "epicsTime.h"
#include "osdTime.h"
#include "osiNTPTime.h"
#include "osiClockTime.h"
#include "generalTimeSup.h"
+ Include dependency graph for osdTime.cpp:

Go to the source code of this file.

Macros

#define __BSD_VISIBLE   1
 
#define EPICS_EXPOSE_LIBCOM_MONOTONIC_PRIVATE
 

Functions

int rtems_bsdnet_get_ntp (int, int(*)(), struct timespec *)
 
void osdTimeRegister (void)
 
int osdNTPGet (struct timespec *ts)
 
void osdNTPInit (void)
 
void osdNTPReport (void)
 
int osdTickGet (void)
 
int osdTickRateGet (void)
 
int epicsTime_gmtime (const time_t *pAnsiTime, struct tm *pTM)
 Break down a time_t into a struct tm in the UTC timezone. More...
 
int epicsTime_localtime (const time_t *clock, struct tm *result)
 Break down a time_t into a struct tm in the local timezone. More...
 

Variables

rtems_interval rtemsTicksPerSecond
 
double rtemsTicksPerSecond_double
 
double rtemsTicksPerTwoSeconds_double
 

Macro Definition Documentation

#define __BSD_VISIBLE   1

Definition at line 11 of file osdTime.cpp.

#define EPICS_EXPOSE_LIBCOM_MONOTONIC_PRIVATE

Definition at line 15 of file osdTime.cpp.

Function Documentation

int epicsTime_gmtime ( const time_t *  pAnsiTime,
struct tm *  pTM 
)

Break down a time_t into a struct tm in the UTC timezone.

Definition at line 120 of file osdTime.cpp.

121 {
122  struct tm * pRet = gmtime_r ( pAnsiTime, pTM );
123  if ( pRet ) {
124  return epicsTimeOK;
125  }
126  else {
127  return errno;
128  }
129 }
#define epicsTimeOK
Success.
Definition: epicsTime.h:339
int epicsTime_localtime ( const time_t *  clock,
struct tm *  result 
)

Break down a time_t into a struct tm in the local timezone.

Definition at line 131 of file osdTime.cpp.

132 {
133  struct tm * pRet = localtime_r ( clock, result );
134  if ( pRet ) {
135  return epicsTimeOK;
136  }
137  else {
138  return errno;
139  }
140 }
pvac::PutEvent result
Definition: clientSync.cpp:117
#define epicsTimeOK
Success.
Definition: epicsTime.h:339
int osdNTPGet ( struct timespec ts)

Definition at line 45 of file osdTime.cpp.

46 {
47  static unsigned bequiet;
48  ssize_t ret;
49 
50  if (ntpSocket < 0)
51  return -1;
52 
53  /* rtems_bsdnet_get_ntp() will send an NTP request, then
54  * call recvfrom() exactly once to process the expected reply.
55  * Any leftovers in the socket buffer (ie. duplicates of
56  * previous replies) will cause problems.
57  * So flush out the socket buffer first.
58  */
59  do {
60  char junk[16];
61 
62  ret = recvfrom(ntpSocket, junk, sizeof(junk), MSG_DONTWAIT, NULL, NULL);
63  if (ret == -1 && errno == EAGAIN) {
64  break;
65  }
66  else if (ret == -1) {
67  if (!bequiet) {
68  printf("osdNTPGet cleaner error: %s\n", strerror(errno));
69  bequiet = 1;
70  }
71  break;
72  }
73  else {
74  bequiet = 0;
75  }
76  } while (ret > 0);
77 
78  return rtems_bsdnet_get_ntp(ntpSocket, NULL, ts);
79 }
#define printf
Definition: epicsStdio.h:41
#define NULL
Definition: catime.c:38
int rtems_bsdnet_get_ntp(int, int(*)(), struct timespec *)
void osdNTPInit ( void  )

Definition at line 81 of file osdTime.cpp.

82 {
83  struct sockaddr_in myAddr;
84 
85  ntpSocket = socket (AF_INET, SOCK_DGRAM, 0);
86  if (ntpSocket < 0) {
87  printf("osdNTPInit() Can't create socket: %s\n", strerror (errno));
88  return;
89  }
90  memset (&myAddr, 0, sizeof myAddr);
91  myAddr.sin_family = AF_INET;
92  myAddr.sin_port = htons (0);
93  myAddr.sin_addr.s_addr = htonl (INADDR_ANY);
94  if (bind (ntpSocket, (struct sockaddr *)&myAddr, sizeof myAddr) < 0) {
95  printf("osdNTPInit() Can't bind socket: %s\n", strerror (errno));
96  close (ntpSocket);
97  ntpSocket = -1;
98  }
99 }
#define printf
Definition: epicsStdio.h:41
void osdNTPReport ( void  )

Definition at line 101 of file osdTime.cpp.

102 {
103 }
int osdTickGet ( void  )

Definition at line 105 of file osdTime.cpp.

106 {
107  rtems_interval t;
108  rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &t);
109  return t;
110 }
int osdTickRateGet ( void  )

Definition at line 112 of file osdTime.cpp.

113 {
114  return rtemsTicksPerSecond;
115 }
rtems_interval rtemsTicksPerSecond
Definition: osdTime.cpp:142
void osdTimeRegister ( void  )

Definition at line 36 of file osdTime.cpp.

37 {
38  /* Init NTP first so it can be used to sync ClockTime */
39  NTPTime_Init(100);
41 
43 }
void ClockTime_Init(int synchronize)
void osdMonotonicInit(void)
Definition: osdMonotonic.c:19
void NTPTime_Init(int priority)
Definition: osiNTPTime.c:121
#define CLOCKTIME_SYNC
Definition: osiClockTime.h:12
int rtems_bsdnet_get_ntp ( int  ,
int(*)()  ,
struct timespec  
)

Variable Documentation

rtems_interval rtemsTicksPerSecond

Definition at line 142 of file osdTime.cpp.

double rtemsTicksPerSecond_double

Definition at line 143 of file osdTime.cpp.

double rtemsTicksPerTwoSeconds_double

Definition at line 143 of file osdTime.cpp.