OpENer - Open Source EtherNet/IP(TM) I/O Target Stack  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
socket_timer.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (c) 2016, Rockwell Automation, Inc.
3  * All rights reserved.
4  *
5  ******************************************************************************/
6 
7 #include "socket_timer.h"
8 
9 #include "trace.h"
10 
12  const int socket) {
13  socket_timer->socket = socket;
14  OPENER_TRACE_INFO("Adds socket %d to socket timers\n", socket);
15 }
16 
18  const MilliSeconds actual_time) {
19  if (NULL != socket_timer) {
20  socket_timer->last_update = actual_time;
21  OPENER_TRACE_INFO("Sets time stamp for socket %d\n", socket_timer->socket);
22  }
23 }
24 
26  return socket_timer->last_update;
27 }
28 
30  socket_timer->socket = kEipInvalidSocket;
31  socket_timer->last_update = 0;
32 }
33 
34 void SocketTimerArrayInitialize(SocketTimer *const array_of_socket_timers,
35  const size_t array_length) {
36  for (size_t i = 0; i < array_length; ++i) {
37  SocketTimerClear(&array_of_socket_timers[i]);
38  }
39 }
40 
42  SocketTimer *const array_of_socket_timers,
43  const size_t array_length,
44  const int socket) {
45  for (size_t i = 0; i < array_length; ++i) {
46  if (socket == array_of_socket_timers[i].socket) {
47  return &array_of_socket_timers[i];
48  }
49  }
50  return NULL;
51 }
52 
54  SocketTimer *const array_of_socket_timers,
55  const size_t array_length) {
56  return SocketTimerArrayGetSocketTimer(array_of_socket_timers, array_length,
57  kEipInvalidSocket);
58 }
void SocketTimerArrayInitialize(SocketTimer *const array_of_socket_timers, const size_t array_length)
Initializes an array of Socket Timer entries.
Definition: socket_timer.c:34
Tracing infrastructure for OpENer.
MilliSeconds SocketTimerGetLastUpdate(SocketTimer *const socket_timer)
Gets time stamp of the last update.
Definition: socket_timer.c:25
Data structure to store last usage times for sockets.
Definition: socket_timer.h:15
void SocketTimerClear(SocketTimer *const socket_timer)
Clears a Socket Timer entry.
Definition: socket_timer.c:29
#define OPENER_TRACE_INFO(...)
Definition: trace.h:89
SocketTimer * SocketTimerArrayGetSocketTimer(SocketTimer *const array_of_socket_timers, const size_t array_length, const int socket)
Get the Socket Timer entry with the spezified socket value.
Definition: socket_timer.c:41
SocketTimer * SocketTimerArrayGetEmptySocketTimer(SocketTimer *const array_of_socket_timers, const size_t array_length)
Get an empty Socket Timer entry.
Definition: socket_timer.c:53
unsigned long MilliSeconds
Definition: typedefs.h:68
MilliSeconds last_update
Definition: socket_timer.h:17
void SocketTimerSetSocket(SocketTimer *const socket_timer, const int socket)
Sets socket of a Socket Timer.
Definition: socket_timer.c:11
void SocketTimerSetLastUpdate(SocketTimer *const socket_timer, const MilliSeconds actual_time)
Sets time stamp entry of the Socket Timer.
Definition: socket_timer.c:17