KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
srp.h
Go to the documentation of this file.
1 /*
2  * srp.h
3  *
4  * Created on: 22 mrt. 2013
5  * Author: vincentb
6  */
7 
8 #ifndef SRP_H_
9 #define SRP_H_
10 
11 /**
12  * @file
13  *
14  * @ingroup network
15  *
16  * SRP or Simple Retransmission Protocol is a protocol which retransmits packets if they have not
17  * been confirmed within a predefined time. When a packet is lost, i.e. it has not been confirmed
18  * within a certain time, after multiple sends, it will notify the sender that the packet did not
19  * make it.
20  *
21  * SRP is an asynchronous protocol, multiple packets may be in processing, being send but not
22  * confirmed. when replying the acknowledge of the sender may be in the receiving packets.
23  */
24 
25 #include <stdint.h>
26 #include <stdbool.h>
27 #include "net/net.h"
28 
29 // configuration parameters -- you may change these, but be careful.
30 #define SRP_MAX_SIZE 1028 //!< Maximum size of one SRP message.
31 #define SRP_TX_QUEUE_SIZE ( SRP_MAX_SIZE * 3 ) //!< Transmit queue buffer size.
32 #define SRP_TX_MAX_QUEUE 32 //!< Allow up to 32 items on the TX queue
33 #define SRP_RESEND_TIMEOUT 200 //!< Resend time-out in ms
34 #define SRP_RESEND_MAX 6 //!< Max number of resends
35 #define SRP_RX_MAX_CACHE 48 //!< Max receive confirms
36 
37 // fixed protocol defines, don't change!
38 #define SRP_FLG_MSG BIT(0) //!< Contains message
39 #define SRP_FLG_DONTACK BIT(1) //!< No ack required
40 #define SRP_FLG_ACK_SHIFT 4 //!< Shift for the number of acks
41 #define SRP_FLG_ACK_MASK 0x30 //!< Mask for the number of acks
42 
43 //! maximum size of the payload of a SRP message.
44 #define SRP_MAX_PAYLOAD ( SRP_MAX_SIZE - sizeof(SrpHeader) )
45 
46 #define SRP_MAX_ACKS 2 //!< Maximum number of acknowledges.
47 
48 
49 /**
50  * Header used by SRP protocol.
51  */
52 typedef struct
53 {
54  uint8_t flags;
55  uint8_t msgId;
56  uint8_t ackId[SRP_MAX_ACKS];
57 } SrpHeader;
58 
59 
60 /**
61  * Outputs SRP status information.
62  */
63 void srpDumpStatus();
64 
65 /**
66  * Transmit UDP packet. Invoked by SRP when its done formatting a packet.
67  *
68  * This is a callback and must be implemented by the protocol stack.
69  *
70  * @param txAddr The addresss to send to.
71  * @param udpPayload The payload to transmit.
72  * @param len The length of the payload.
73  */
74 void _srpUdpTx(SockAddr * txAddr, uint8_t * udpPayload, int len);
75 
76 /**
77  * Process a received SRP packet. Invoked by SRP when a SRP packet has been received.
78  *
79  * This is a callback and must be implemented by the protocol stack.
80  *
81  * @note Implementors should take care not to do too much in this call. Executing long running
82  * processes will stall SRP processing. Complecated tasks should be executed outside of
83  * this function.
84  *
85  * @param rxAddr The address of the sender.
86  * @param message The message to parse.
87  * @param len The length of the message.
88  */
89 void _srpRx(SockAddr * rxAddr, uint8_t * message, int len);
90 
91 
92 /**
93  * Stub, invoked when an SRP message is lost.
94  *
95  * @param addr The socket address
96  * @param msgId The message ID
97  */
98 void _srpLost(SockAddr * addr, uint8_t msgId);
99 
100 /**
101  * Initializes the SRP protocol engine.
102  */
103 void srpInit();
104 
105 
106 /**
107  * Invoked by UDP stack for receiving a SRP packet.
108  *
109  * @param rxAddr The sender address.
110  * @param udpPayload The data in the udp packet.
111  * @param len The lenght of the payload.
112  */
113 void srpUdpRx(SockAddr * rxAddr, uint8_t * udpPayload, int len);
114 
115 /**
116  * Invoked by application for sending an SRP packet.
117  *
118  * @note SRP packets may be no longer than SRP_MAX_PAYLOAD.
119  *
120  * @param txIpAddr The ip address to send to.
121  * @param message The message to send.
122  * @param len The length of the message.
123  */
124 bool srpTx(SockAddr * txAddr, uint8_t * message, int len);
125 
126 /**
127  * Should be called periodically to process any pending requests.
128  */
129 void srpProcess();
130 
131 
132 
133 #endif /* SRP_H_ */
bool srpTx(SockAddr *txAddr, uint8_t *message, int len)
Invoked by application for sending an SRP packet.
Definition: srp.c:586
void _srpUdpTx(SockAddr *txAddr, uint8_t *udpPayload, int len)
Transmit UDP packet.
Definition: network.c:393
void _srpLost(SockAddr *addr, uint8_t msgId)
Stub, invoked when an SRP message is lost.
Definition: network.c:657
void srpDumpStatus()
Outputs SRP status information.
Definition: srp.c:153
void srpProcess()
Should be called periodically to process any pending requests.
Definition: srp.c:636
void srpUdpRx(SockAddr *rxAddr, uint8_t *udpPayload, int len)
Invoked by UDP stack for receiving a SRP packet.
Definition: srp.c:408
Header used by SRP protocol.
Definition: srp.h:52
Combination of IP address and port.
Definition: net.h:31
#define SRP_MAX_ACKS
Maximum number of acknowledges.
Definition: srp.h:46
void _srpRx(SockAddr *rxAddr, uint8_t *message, int len)
Process a received SRP packet.
Definition: network.c:605
void srpInit()
Initializes the SRP protocol engine.
Definition: srp.c:648