1 /****************************************************************************
3 (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4 www.systec-electronic.com
8 Description: source file for Statusu-Module
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
16 1. Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
19 2. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
23 3. Neither the name of SYSTEC electronic GmbH nor the names of its
24 contributors may be used to endorse or promote products derived
25 from this software without prior written permission. For written
26 permission, please contact info@systec-electronic.com.
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32 COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 POSSIBILITY OF SUCH DAMAGE.
43 If a provision of this License is or becomes illegal, invalid or
44 unenforceable in any jurisdiction, that shall not affect:
45 1. the validity or enforceability in that jurisdiction of any other
46 provision of this License; or
47 2. the validity or enforceability in other jurisdictions of that or
48 any other provision of this License.
50 -------------------------------------------------------------------------
52 $RCSfile: EplStatusu.c,v $
56 $Revision: 1.5 $ $Date: 2008/10/17 15:32:32 $
63 -------------------------------------------------------------------------
67 2006/11/15 d.k.: start of the implementation
69 ****************************************************************************/
71 #include "user/EplStatusu.h"
72 #include "user/EplDlluCal.h"
74 /***************************************************************************/
77 /* G L O B A L D E F I N I T I O N S */
80 /***************************************************************************/
82 //---------------------------------------------------------------------------
84 //---------------------------------------------------------------------------
86 //---------------------------------------------------------------------------
88 //---------------------------------------------------------------------------
90 //---------------------------------------------------------------------------
92 //---------------------------------------------------------------------------
94 //---------------------------------------------------------------------------
95 // local function prototypes
96 //---------------------------------------------------------------------------
99 /***************************************************************************/
102 /* C L A S S <xxxxx> */
105 /***************************************************************************/
110 /***************************************************************************/
113 //=========================================================================//
115 // P R I V A T E D E F I N I T I O N S //
117 //=========================================================================//
119 //---------------------------------------------------------------------------
121 //---------------------------------------------------------------------------
123 //---------------------------------------------------------------------------
125 //---------------------------------------------------------------------------
129 tEplStatusuCbResponse m_apfnCbResponse[254];
131 } tEplStatusuInstance;
133 //---------------------------------------------------------------------------
135 //---------------------------------------------------------------------------
137 static tEplStatusuInstance EplStatusuInstance_g;
139 //---------------------------------------------------------------------------
140 // local function prototypes
141 //---------------------------------------------------------------------------
143 static tEplKernel PUBLIC EplStatusuCbStatusResponse(tEplFrameInfo * pFrameInfo_p);
145 //=========================================================================//
147 // P U B L I C F U N C T I O N S //
149 //=========================================================================//
151 //---------------------------------------------------------------------------
153 // Function: EplStatusuInit
155 // Description: init first instance of the module
162 // Returns: tEplKernel = errorcode
167 //---------------------------------------------------------------------------
169 EPLDLLEXPORT tEplKernel PUBLIC EplStatusuInit()
173 Ret = EplStatusuAddInstance();
179 //---------------------------------------------------------------------------
181 // Function: EplStatusuAddInstance
183 // Description: init other instances of the module
190 // Returns: tEplKernel = errorcode
195 //---------------------------------------------------------------------------
197 EPLDLLEXPORT tEplKernel PUBLIC EplStatusuAddInstance()
201 Ret = kEplSuccessful;
203 // reset instance structure
204 EPL_MEMSET(&EplStatusuInstance_g, 0, sizeof (EplStatusuInstance_g));
206 // register StatusResponse callback function
207 Ret = EplDlluCalRegAsndService(kEplDllAsndStatusResponse, EplStatusuCbStatusResponse, kEplDllAsndFilterAny);
214 //---------------------------------------------------------------------------
216 // Function: EplStatusuDelInstance
218 // Description: delete instance
225 // Returns: tEplKernel = errorcode
230 //---------------------------------------------------------------------------
232 EPLDLLEXPORT tEplKernel PUBLIC EplStatusuDelInstance()
236 Ret = kEplSuccessful;
238 // deregister StatusResponse callback function
239 Ret = EplDlluCalRegAsndService(kEplDllAsndStatusResponse, NULL, kEplDllAsndFilterNone);
246 //---------------------------------------------------------------------------
248 // Function: EplStatusuReset
250 // Description: resets this instance
254 // Returns: tEplKernel = errorcode
259 //---------------------------------------------------------------------------
261 EPLDLLEXPORT tEplKernel PUBLIC EplStatusuReset()
265 Ret = kEplSuccessful;
267 // reset instance structure
268 EPL_MEMSET(&EplStatusuInstance_g, 0, sizeof (EplStatusuInstance_g));
275 //---------------------------------------------------------------------------
277 // Function: EplStatusuRequestStatusResponse
279 // Description: returns the StatusResponse for the specified node.
281 // Parameters: uiNodeId_p = IN: node ID
282 // pfnCbResponse_p = IN: function pointer to callback function
283 // which will be called if StatusResponse is received
285 // Return: tEplKernel = error code
289 //---------------------------------------------------------------------------
291 tEplKernel PUBLIC EplStatusuRequestStatusResponse(
292 unsigned int uiNodeId_p,
293 tEplStatusuCbResponse pfnCbResponse_p)
297 Ret = kEplSuccessful;
299 // decrement node ID, because array is zero based
301 if (uiNodeId_p < tabentries (EplStatusuInstance_g.m_apfnCbResponse))
303 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
304 if (EplStatusuInstance_g.m_apfnCbResponse[uiNodeId_p] != NULL)
305 { // request already issued (maybe by someone else)
306 Ret = kEplInvalidOperation;
310 EplStatusuInstance_g.m_apfnCbResponse[uiNodeId_p] = pfnCbResponse_p;
311 Ret = EplDlluCalIssueRequest(kEplDllReqServiceStatus, (uiNodeId_p + 1), 0xFF);
314 Ret = kEplInvalidOperation;
318 { // invalid node ID specified
319 Ret = kEplInvalidNodeId;
327 //=========================================================================//
329 // P R I V A T E F U N C T I O N S //
331 //=========================================================================//
333 //---------------------------------------------------------------------------
335 // Function: EplStatusuCbStatusResponse
337 // Description: callback funktion for StatusResponse
341 // Parameters: pFrameInfo_p = Frame with the StatusResponse
344 // Returns: tEplKernel = error code
349 //---------------------------------------------------------------------------
350 static tEplKernel PUBLIC EplStatusuCbStatusResponse(tEplFrameInfo * pFrameInfo_p)
352 tEplKernel Ret = kEplSuccessful;
353 unsigned int uiNodeId;
354 unsigned int uiIndex;
355 tEplStatusuCbResponse pfnCbResponse;
357 uiNodeId = AmiGetByteFromLe(&pFrameInfo_p->m_pFrame->m_le_bSrcNodeId);
359 uiIndex = uiNodeId - 1;
361 if (uiIndex < tabentries (EplStatusuInstance_g.m_apfnCbResponse))
363 // memorize pointer to callback function
364 pfnCbResponse = EplStatusuInstance_g.m_apfnCbResponse[uiIndex];
365 if (pfnCbResponse == NULL)
366 { // response was not requested
369 // reset callback function pointer so that caller may issue next request
370 EplStatusuInstance_g.m_apfnCbResponse[uiIndex] = NULL;
372 if (pFrameInfo_p->m_uiFrameSize < EPL_C_DLL_MINSIZE_STATUSRES)
373 { // StatusResponse not received or it has invalid size
374 Ret = pfnCbResponse(uiNodeId, NULL);
377 { // StatusResponse received
378 Ret = pfnCbResponse(uiNodeId, &pFrameInfo_p->m_pFrame->m_Data.m_Asnd.m_Payload.m_StatusResponse);