versadac  1
versadac - Scalable Recorder Firmware
clclient.h
1 /*---------------------------------------------------------------------------*/
2 /* Copyright (C) 2006 Woodhead Software & Electonics. All rights reserved. */
3 /*---------------------------------------------------------------------------*/
4 /* This program is protected by international copyright. */
5 /* */
6 /* The use of this software including but not limited to its Source Code */
7 /* is subject to restrictions as agreed in the license agreement between */
8 /* you and Woodhead. */
9 /* Copying or distribution is not allowed unless expressly permitted */
10 /* according to your license agreement with Woodhead. */
11 /*---------------------------------------------------------------------------*/
12 /* */
13 /* Project : STACK PROFINET Controller */
14 /* Component : RPC Interface */
15 /* $Workfile:: clclient.h $*/
16 /* $Revision:: 2 $*/
17 /* $Date:: 9/22/09 6:01p $*/
18 /* */
19 /*---------------------------------------------------------------------------*/
20 /* */
21 /* D e s c r i p t i o n : */
22 /* RPC Client State Machine */
23 /* */
24 /*---------------------------------------------------------------------------*/
25 #ifndef __RPC_CLCLIENT_H__
26  #define __RPC_CLCLIENT_H__
27 
28 #include "os_pck.h"
29 
30 extern APP_WORD gwClientInUsed;
31 
32 /*---------------------------------------------------------------------------*/
33 /* TIMER MANAGMENT */
34 /*---------------------------------------------------------------------------*/
35 /*Think to update NB_CLIENT_TIMER*/
36 #define ID_TIMEOUT_FRAG 0
37 #define ID_TIMEOUT_WAIT 1
38 #define ID_TIMEOUT_PING 2
39 #define ID_TIMEOUT_ACK 3
40 #define ID_TIMEOUT_CANCEL 4
41 #define ID_TIMEOUT_BROADCAST 5
42 
43 #define NB_CLIENT_TIMER 6
44 APP_WORD rpc_tmFrag (APP_LPVOID lpData, APP_WORD wDummy);
45 APP_WORD rpc_tmWait (APP_LPVOID lpData, APP_WORD wDummy);
46 APP_WORD rpc_tmPing (APP_LPVOID lpData, APP_WORD wDummy);
47 APP_WORD rpc_tmAck (APP_LPVOID lpData, APP_WORD wDummy);
48 APP_WORD rpc_tmCancel (APP_LPVOID lpData, APP_WORD wDummy);
49 APP_WORD rpc_tmBroadcast(APP_LPVOID lpData, APP_WORD wDummy);
50 
51 
52 /*---------------------------------------------------------------------------*/
53 /* VARIABLE */
54 /*---------------------------------------------------------------------------*/
55 
56 /*----------------------------------------------------------*/
57 /* Field removed from RT because in RPCCall Struct */
58 /* ST_CLR_RPC_UUID uuidObjId; OBJ_ID */
59 /* ST_CLR_RPC_UUID uuidIfId; IF_ID */
60 /* APP_DWORD dwIfVersion; IF_VERSION */
61 /* APP_DWORD dwSeqNum; SEQ_NUM */
62 /* APP_LPBYTE pbyInParam; IN_PARAMS */
63 /* APP_WORD wOpNum; OP_NUM */
64 /*----------------------------------------------------------*/
65 
66 typedef struct _CL_CLIENT_MACHINE_RT
67 {
68  APP_DWORD dwRequestCount; /* 4 - 0 *//*REQUEST_COUNT */
69  APP_DWORD dwCancelID; /* 4 - 4 *//*CANCEL_ID */
70  APP_DWORD dwRcvCancelID; /* 4 - 8 *//*RCV_CANCEL_ID */
71  APP_DWORD dwExceptionStatus; /* 4 - 12 *//*EXCEPTION_STATUS */
72 
73  APP_LPBYTE pbyInFrag; /* 4 - 16 *//*IN_FRAG */
74  APP_LPBYTE pbyBody; /* 4 - 20 *//*BODY (PDU) */
75  APP_WORD wInLen; /* 2 - 24 *//* */
76  APP_WORD wOutSerialNum; /* 2 - 26 *//*OUT_SERIAL_NUM */
77  APP_WORD wContOutFragNum; /* 2 - 28 *//*CONT_OUT_FRAG_NUM */
78  APP_WORD wPingCount; /* 2 - 30 *//*PING_COUNT */
79  APP_WORD wFragAck; /* 2 - 32 *//* */
80 
81 }PACK_ALIGNEMENT(ST_CL_CLIENT_MACHINE_RT); /* 34 */
82 
83 typedef struct _CL_CLIENT_MACHINE_PDU
84 {
85  APP_DWORD dwSeqNum; /* 4 - 0 *//*SEQ_NUM */
86  APP_DWORD dwBootTime; /* 4 - 4 *//*BOOT_TIME */
87  APP_DWORD dwFaultStatus; /* 4 - 8 *//*FAULT_STATUS */
88  APP_DWORD dwRejectStatus; /* 4 - 12 *//*REJECT_STATUS */
89  APP_DWORD dwCancelID; /* 4 - 16 *//*CANCEL_ID */
90  APP_LPBYTE pbyBody; /* 4 - 20 *//*BODY */
91 
92  ST_CLR_RPC_UUID uuidActivity; /*16 - 24 *//*ACTIVITY_ID */
93 
94  APP_WORD wFragNum; /* 2 - 40 *//*FRAG_NUM */
95  APP_WORD wVersionNum; /* 2 - 42 *//*VERSION_NUM */
96  APP_WORD wSerialNum; /* 2 - 44 *//*SERIAL_NUM */
97  APP_WORD wLen; /* 2 - 46 *//* */
98  APP_BOOL bLittleEndian; /* 2 - 48 *//* */
99  APP_BYTE byRequestType; /* 1 - 50 *//*REQUEST_TYPE */
100 #ifdef PADDING
101  APP_BYTE Padding_1; /* 1 - 51 */
102 #endif
103 }PACK_ALIGNEMENT(ST_CL_CLIENT_MACHINE_PDU);/* 52*/
104 
105 /*------------------------------------------------------------*/
106 /* Field removed from SND because in RPCCall Struct */
107 /* ST_CLR_RPC_UUID uuidActivity; ACTIVITY */
108 /* ST_CLR_RPC_UUID uuidObjId; OBJ_ID */
109 /* ST_CLR_RPC_UUID uuidIfId; IF_ID */
110 /* APP_DWORD dwIfVersion; IF_VERSION */
111 /* APP_DWORD dwSeqNum; SEQ_NUM */
112 /* APP_DWORD dwBootTime; BOOT_TIME */
113 /* APP_WORD wOpNum; OP_NUM */
114 /*------------------------------------------------------------*/
115 
117 {
118  APP_LPBYTE pbyInParam; /*4 - 0*//*IN_PARAMS */
119  APP_WORD wFragNum; /*2 - 4*//*FRAG_NUM */
120  APP_WORD wSerialNum; /*2 - 6*//*SERIAL_NUM */
121  APP_BYTE byRequestType; /*1 - 8*//*REQUEST_TYPE */
122 #ifdef PADDING
123  APP_BYTE padding__1; /*1 - 9*//* */
124  APP_BYTE padding__2; /*1 - 10*//* */
125  APP_BYTE padding__3; /*1 - 11*//* */
126 #endif
127  ST_OS_SOCKADDR_IN stSendSockAddr; /*16-12*/
128 }PACK_ALIGNEMENT(ST_CL_CLIENT_MACHINE_SND); /*28*/
129 
130 /*---------------------------------------------------------------------------*/
131 /* CONDITION */
132 /*---------------------------------------------------------------------------*/
133 
135 {
136 /*Condition*/
137 APP_DWORD bBroadcast; /* 4 - 0 */ /*COND_BROADCAST Statechart internal flag: broadcast call semantic.*/
138 APP_DWORD bBurst; /* 4 - 4 */ /*COND_BURST Run time internal flag set if no fack is expected before sending next fragment.This flag is used by RPC run-time implementations to optimise the frequency of fragmented outbound packets.*/
139 APP_DWORD bIdempotent; /* 4 - 8 */ /*COND_IDEMPOTENT Statechart internal flag: idempotent call.*/
140 APP_DWORD bLastInFrag; /* 4 - 12 */ /*COND_LAST_IN_FRAG Statechart internal flag: last in fragment or non-frag in packet ready to send.*/
141 APP_DWORD bMaybe; /* 4 - 16 */ /*COND_MAYBE Statechart internal flag: maybe call.*/
142 APP_DWORD bRequestActive; /* 4 - 20 */ /*COND_REQUEST_ACTIVE Statechart internal flag: send request has started.*/
143 APP_DWORD bResponseActive; /* 4 - 24 */ /*COND_RESPONSE_ACTIVE Statechart internal flag: indicates availability of response data.*/
144 APP_DWORD bRtPendingCancel; /* 4 - 28 */ /*COND_RT_PENDING_CANCEL Statechart internal: cancel pending state at server's provider.*/
145 APP_DWORD bSndFrag; /* 4 - 32 */ /*COND_SND_FRAG Statechart internal flag: header flag frag of next fragments to be sent.*/
146 APP_DWORD bSndLastFrag; /* 4 - 36 */ /*COND_SND_LAST_FRAG Statechart internal flag: header flag lastfrag for PDU to be sent.*/
147 APP_DWORD bInitFack; /* 4 - 40 */ /*COND_INIT_FACK Statechart internal flag: simul first ack.*/
148 APP_DWORD bInProgress; /* 4 - 44 */ /*COND_IN_PROGRESS Machine is progress*/
149 }PACK_ALIGNEMENT(ST_CL_CLIENT_COND); /*48*/
150 
151 /*Set Condition*/
152 #define TR_COND_IN_PROGRESS(machine) ((machine)->stCondition.bInProgress=1)
153 #define TR_COND_BROADCAST(machine) ((machine)->stCondition.bBroadcast=1)
154 #define TR_COND_BURST(machine) ((machine)->stCondition.bBurst=1)
155 #define TR_COND_IDEMPOTENT(machine) ((machine)->stCondition.bIdempotent=1)
156 #define TR_COND_LAST_IN_FRAG(machine) ((machine)->stCondition.bLastInFrag=1)
157 #define TR_COND_MAYBE(machine) ((machine)->stCondition.bMaybe=1)
158 #define TR_COND_REQUEST_ACTIVE(machine) ((machine)->stCondition.bRequestActive=1)
159 #define TR_COND_RESPONSE_ACTIVE(machine) ((machine)->stCondition.bResponseActive=1)
160 #define TR_COND_RT_PENDING_CANCEL(machine) ((machine)->stCondition.bRtPendingCancel=1)
161 #define TR_COND_SND_FRAG(machine) ((machine)->stCondition.bSndFrag=1)
162 #define TR_COND_SND_LAST_FRAG(machine) ((machine)->stCondition.bSndLastFrag=1)
163 #define TR_COND_WORKING_PDU(machine) ((machine)->stCondition.bWorkingPdu=1)
164 #define TR_COND_INIT_FACK(machine) ((machine)->stCondition.bInitFack=1)
165 
166 /*Reset condition*/
167 #define FS_COND_IN_PROGRESS(machine) ((machine)->stCondition.bInProgress=0)
168 #define FS_COND_BROADCAST(machine) ((machine)->stCondition.bBroadcast=0)
169 #define FS_COND_BURST(machine) ((machine)->stCondition.bBurst=0)
170 #define FS_COND_IDEMPOTENT(machine) ((machine)->stCondition.bIdempotent=0)
171 #define FS_COND_LAST_IN_FRAG(machine) ((machine)->stCondition.bLastInFrag=0)
172 #define FS_COND_MAYBE(machine) ((machine)->stCondition.bMaybe=0)
173 #define FS_COND_REQUEST_ACTIVE(machine) ((machine)->stCondition.bRequestActive=0)
174 #define FS_COND_RESPONSE_ACTIVE(machine) ((machine)->stCondition.bResponseActive=0)
175 #define FS_COND_RT_PENDING_CANCEL(machine) ((machine)->stCondition.bRtPendingCancel=0)
176 #define FS_COND_SND_FRAG(machine) ((machine)->stCondition.bSndFrag=0)
177 #define FS_COND_SND_LAST_FRAG(machine) ((machine)->stCondition.bSndLastFrag=0)
178 #define FS_COND_WORKING_PDU(machine) ((machine)->stCondition.bWorkingPdu=0)
179 #define FS_COND_INIT_FACK(machine) ((machine)->stCondition.bInitFack=0)
180 
181 /*Test simple condition*/
182 #define COND_IN_PROGRESS(machine) ((machine)->stCondition.bInProgress)
183 #define COND_BROADCAST(machine) ((machine)->stCondition.bBroadcast)
184 #define COND_BURST(machine) ((machine)->stCondition.bBurst)
185 #define COND_IDEMPOTENT(machine) ((machine)->stCondition.bIdempotent)
186 #define COND_LAST_IN_FRAG(machine) ((machine)->stCondition.bLastInFrag)
187 #define COND_MAYBE(machine) ((machine)->stCondition.bMaybe)
188 #define COND_REQUEST_ACTIVE(machine) ((machine)->stCondition.bRequestActive)
189 #define COND_RESPONSE_ACTIVE(machine) ((machine)->stCondition.bResponseActive)
190 #define COND_RT_PENDING_CANCEL(machine) ((machine)->stCondition.bRtPendingCancel)
191 #define COND_SND_FRAG(machine) ((machine)->stCondition.bSndFrag)
192 #define COND_SND_LAST_FRAG(machine) ((machine)->stCondition.bSndLastFrag)
193 #define COND_INIT_FACK(machine) ((machine)->stCondition.bInitFack)
194 
195 /*---------------------------------------------------------------------------*/
196 /* CLIENT STATE MACHINE CONTEXT */
197 /*---------------------------------------------------------------------------*/
198 typedef enum _enClClient{
199  enClClientNone =0, /*shall be the first, never change it*/
200  enClClientInit =1,
201  enClClientWorking =2,
202  enClClientCommFail=3,
203  enClClientFault =4
204 } EN_CLCLIENT_STATE;
205 
206 typedef enum _enClClientData{
207  enDataNone =0, /*shall be the first, never change it*/
208  enDataReqWait =1,
209  enDataConfIdle =2,
210  enDataComplete =3
211 } EN_CLCLIENT_DATA_STATE;
212 
213 typedef enum _enClClientPing{
214  enPingNone =0,/*shall be the first, never change it*/
215  enPingIdle =1,
216  enPingSnd =2
217 } EN_CLCLIENT_PING_STATE;
218 
219 
220 
221 typedef struct _CL_CLIENT_MACHINE
222 {
223 
224  ST_CL_CLIENT_COND stCondition; /* 48 - 0 */ /*Current Condition of the state machine */
225 
226  ST_CL_CLIENT_MACHINE_RT stRT; /* 34 - 48 */ /* runtime variable of the state machine */
227 #ifdef PADDING
228  APP_WORD wPadding; /* 2 - 82 */
229 #endif
230  ST_CL_CLIENT_MACHINE_PDU stPDU; /* 52 - 84 */ /* information on last packet received */
231  ST_CL_CLIENT_MACHINE_SND stSND; /* 28 - 136*/ /* information on next packet to send */
232  LPST_CBF cbTimer[NB_CLIENT_TIMER]; /*6*4 24 - 164*/ /* Timer Managment */
233 
234  APP_DWORD enClClientState; /* 4 - 188 */ /* Current state of CL_CLIENT machine */
235  APP_DWORD enDataState; /* 4 - 192 */ /* Current state of DATA sub machine */
236  APP_DWORD enPingState; /* 4 - 196 */ /* Current state of PING sub machine */
237 
238  LPST_MSG pstMsg; /* 4 - 200 */ /*Message contening RPCCall*/
239  LPST_RPC_CALL pstRPCCall; /* 4 - 204 */ /*Current call comming from proxy level*/
240 
241  APP_DWORD dwSocket; /* 4 - 208 */ /*Associated Socket*/
242 
243  /* 212 */
244 } PACK_ALIGNEMENT(ST_CL_CLIENT),APP_FAR *LPST_CL_CLIENT;
245 
246 APP_VOID clclient_StartTimer(LPST_CL_CLIENT pstClClient,APP_BYTE byTimerIndex);
247 APP_VOID clclient_StopTimer(LPST_CL_CLIENT pstClClient,APP_BYTE byTimerIndex);
248 
249 /*---------------------------------------------------------------------------*/
250 /* EVENT */
251 /*---------------------------------------------------------------------------*/
252 APP_VOID clclient_event_receive_pdu(LPST_CL_CLIENT pstClClient);
253 APP_VOID clclient_event_invoke_req(LPST_CL_CLIENT pstClClient);
254 APP_VOID clclient_event_client_cancel(LPST_CL_CLIENT pstClClient);
255 
256 APP_VOID clclient_event_tmfrag(LPST_CL_CLIENT pstClClient);
257 APP_VOID clclient_event_tmwait(LPST_CL_CLIENT pstClClient);
258 APP_VOID clclient_event_tmping(LPST_CL_CLIENT pstClClient);
259 APP_VOID clclient_event_tmcancel(LPST_CL_CLIENT pstClClient);
260 APP_VOID clclient_event_tmack(LPST_CL_CLIENT pstClClient);
261 APP_VOID clclient_event_tmbroadcast(LPST_CL_CLIENT pstClClient);
262 
263 /*---------------------------------------------------------------------------*/
264 /* ACTION/ACTIVITY */
265 /*---------------------------------------------------------------------------*/
266 
267 APP_VOID APP_FAR clclient_action_enter_init_state(LPST_CL_CLIENT pstClClient);
268 APP_VOID APP_FAR clclient_action_enter_none_state(LPST_CL_CLIENT pstClClient);
269 APP_VOID APP_FAR clclient_action_resend_in_frags(LPST_CL_CLIENT pstClClient);
270 
271 APP_VOID APP_FAR clclient_activity_send_packet(LPST_CL_CLIENT pstClClient);
272 APP_VOID APP_FAR clclient_activity_response_proxy(LPST_CL_CLIENT pstClClient);
273 
274 
275 /*---------------------------------------------------------------------------*/
276 /* STATE MACHINE MANAGMENT (EXTERNAL INTERFACE) */
277 /*---------------------------------------------------------------------------*/
278 APP_VOID APP_FAR clclient_InitStateMachine(LPST_CL_CLIENT pstClClient);
279 APP_VOID APP_FAR clclient_Step(LPST_CL_CLIENT pstClClient);
280 APP_VOID APP_FAR clclient_ExitStateMachine(LPST_CL_CLIENT pstClClient);
281 
282 #include "os_unpck.h"
283 
284 #ifdef __TEST_SIMU_ERROR__
285  /*Only used for unitary test of this module this function shall be implemented in test module*/
286  /*Return APP_TRUE : This packet shall not be send to simulate a lost packet*/
287  APP_BOOL test_rpcclient_lost_packet(APP_DWORD dwPacket);
288  APP_BOOL test_rpcclient_do_not_rec_packet(APP_DWORD dwPacket);
289 #endif
290 #endif/*__RPC_CLCLIENT_H__*/
Definition: stk_sckt.h:49
Definition: clclient.h:66
Definition: clclient.h:83
Definition: message.h:1163
Definition: clclient.h:221
Definition: clclient.h:134
Definition: schedule.h:40
Definition: clclient.h:116