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 //---------------------------------------------------------------------------
98 /***************************************************************************/
101 /* C L A S S <xxxxx> */
104 /***************************************************************************/
109 /***************************************************************************/
111 //=========================================================================//
113 // P R I V A T E D E F I N I T I O N S //
115 //=========================================================================//
117 //---------------------------------------------------------------------------
119 //---------------------------------------------------------------------------
121 //---------------------------------------------------------------------------
123 //---------------------------------------------------------------------------
126 tEplStatusuCbResponse m_apfnCbResponse[254];
128 } tEplStatusuInstance;
130 //---------------------------------------------------------------------------
132 //---------------------------------------------------------------------------
134 static tEplStatusuInstance EplStatusuInstance_g;
136 //---------------------------------------------------------------------------
137 // local function prototypes
138 //---------------------------------------------------------------------------
140 static tEplKernel PUBLIC EplStatusuCbStatusResponse(tEplFrameInfo *
143 //=========================================================================//
145 // P U B L I C F U N C T I O N S //
147 //=========================================================================//
149 //---------------------------------------------------------------------------
151 // Function: EplStatusuInit
153 // Description: init first instance of the module
160 // Returns: tEplKernel = errorcode
165 //---------------------------------------------------------------------------
167 EPLDLLEXPORT tEplKernel PUBLIC EplStatusuInit()
171 Ret = EplStatusuAddInstance();
176 //---------------------------------------------------------------------------
178 // Function: EplStatusuAddInstance
180 // Description: init other instances of the module
187 // Returns: tEplKernel = errorcode
192 //---------------------------------------------------------------------------
194 EPLDLLEXPORT tEplKernel PUBLIC EplStatusuAddInstance()
198 Ret = kEplSuccessful;
200 // reset instance structure
201 EPL_MEMSET(&EplStatusuInstance_g, 0, sizeof(EplStatusuInstance_g));
203 // register StatusResponse callback function
205 EplDlluCalRegAsndService(kEplDllAsndStatusResponse,
206 EplStatusuCbStatusResponse,
207 kEplDllAsndFilterAny);
213 //---------------------------------------------------------------------------
215 // Function: EplStatusuDelInstance
217 // Description: delete instance
224 // Returns: tEplKernel = errorcode
229 //---------------------------------------------------------------------------
231 EPLDLLEXPORT tEplKernel PUBLIC EplStatusuDelInstance()
235 Ret = kEplSuccessful;
237 // deregister StatusResponse callback function
239 EplDlluCalRegAsndService(kEplDllAsndStatusResponse, NULL,
240 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));
274 //---------------------------------------------------------------------------
276 // Function: EplStatusuRequestStatusResponse
278 // Description: returns the StatusResponse for the specified node.
280 // Parameters: uiNodeId_p = IN: node ID
281 // pfnCbResponse_p = IN: function pointer to callback function
282 // which will be called if StatusResponse is received
284 // Return: tEplKernel = error code
288 //---------------------------------------------------------------------------
290 tEplKernel PUBLIC EplStatusuRequestStatusResponse(unsigned int uiNodeId_p,
291 tEplStatusuCbResponse
296 Ret = kEplSuccessful;
298 // decrement node ID, because array is zero based
300 if (uiNodeId_p < tabentries(EplStatusuInstance_g.m_apfnCbResponse)) {
301 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
302 if (EplStatusuInstance_g.m_apfnCbResponse[uiNodeId_p] != NULL) { // request already issued (maybe by someone else)
303 Ret = kEplInvalidOperation;
305 EplStatusuInstance_g.m_apfnCbResponse[uiNodeId_p] =
308 EplDlluCalIssueRequest(kEplDllReqServiceStatus,
309 (uiNodeId_p + 1), 0xFF);
312 Ret = kEplInvalidOperation;
314 } else { // invalid node ID specified
315 Ret = kEplInvalidNodeId;
322 //=========================================================================//
324 // P R I V A T E F U N C T I O N S //
326 //=========================================================================//
328 //---------------------------------------------------------------------------
330 // Function: EplStatusuCbStatusResponse
332 // Description: callback funktion for StatusResponse
336 // Parameters: pFrameInfo_p = Frame with the StatusResponse
339 // Returns: tEplKernel = error code
344 //---------------------------------------------------------------------------
345 static tEplKernel PUBLIC EplStatusuCbStatusResponse(tEplFrameInfo *
348 tEplKernel Ret = kEplSuccessful;
349 unsigned int uiNodeId;
350 unsigned int uiIndex;
351 tEplStatusuCbResponse pfnCbResponse;
353 uiNodeId = AmiGetByteFromLe(&pFrameInfo_p->m_pFrame->m_le_bSrcNodeId);
355 uiIndex = uiNodeId - 1;
357 if (uiIndex < tabentries(EplStatusuInstance_g.m_apfnCbResponse)) {
358 // memorize pointer to callback function
359 pfnCbResponse = EplStatusuInstance_g.m_apfnCbResponse[uiIndex];
360 if (pfnCbResponse == NULL) { // response was not requested
363 // reset callback function pointer so that caller may issue next request
364 EplStatusuInstance_g.m_apfnCbResponse[uiIndex] = NULL;
366 if (pFrameInfo_p->m_uiFrameSize < EPL_C_DLL_MINSIZE_STATUSRES) { // StatusResponse not received or it has invalid size
367 Ret = pfnCbResponse(uiNodeId, NULL);
368 } else { // StatusResponse received
370 pfnCbResponse(uiNodeId,
371 &pFrameInfo_p->m_pFrame->m_Data.
372 m_Asnd.m_Payload.m_StatusResponse);