1 /****************************************************************************
3 (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4 www.systec-electronic.com
8 Description: source file for Identu-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: EplIdentu.c,v $
56 $Revision: 1.8 $ $Date: 2008/11/21 09:00:38 $
63 -------------------------------------------------------------------------
67 2006/11/15 d.k.: start of the implementation
69 ****************************************************************************/
71 #include "user/EplIdentu.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 tEplIdentResponse* m_apIdentResponse[254]; // the IdentResponse are managed dynamically
130 tEplIdentuCbResponse m_apfnCbResponse[254];
132 } tEplIdentuInstance;
134 //---------------------------------------------------------------------------
136 //---------------------------------------------------------------------------
138 static tEplIdentuInstance EplIdentuInstance_g;
140 //---------------------------------------------------------------------------
141 // local function prototypes
142 //---------------------------------------------------------------------------
144 static tEplKernel PUBLIC EplIdentuCbIdentResponse(tEplFrameInfo * pFrameInfo_p);
146 //=========================================================================//
148 // P U B L I C F U N C T I O N S //
150 //=========================================================================//
152 //---------------------------------------------------------------------------
154 // Function: EplIdentuInit
156 // Description: init first instance of the module
163 // Returns: tEplKernel = errorcode
168 //---------------------------------------------------------------------------
170 EPLDLLEXPORT tEplKernel PUBLIC EplIdentuInit()
174 Ret = EplIdentuAddInstance();
180 //---------------------------------------------------------------------------
182 // Function: EplIdentuAddInstance
184 // Description: init other instances of the module
191 // Returns: tEplKernel = errorcode
196 //---------------------------------------------------------------------------
198 EPLDLLEXPORT tEplKernel PUBLIC EplIdentuAddInstance()
202 Ret = kEplSuccessful;
204 // reset instance structure
205 EPL_MEMSET(&EplIdentuInstance_g, 0, sizeof (EplIdentuInstance_g));
207 // register IdentResponse callback function
208 Ret = EplDlluCalRegAsndService(kEplDllAsndIdentResponse, EplIdentuCbIdentResponse, kEplDllAsndFilterAny);
215 //---------------------------------------------------------------------------
217 // Function: EplIdentuDelInstance
219 // Description: delete instance
226 // Returns: tEplKernel = errorcode
231 //---------------------------------------------------------------------------
233 EPLDLLEXPORT tEplKernel PUBLIC EplIdentuDelInstance()
237 Ret = kEplSuccessful;
239 // deregister IdentResponse callback function
240 Ret = EplDlluCalRegAsndService(kEplDllAsndIdentResponse, NULL, kEplDllAsndFilterNone);
242 Ret = EplIdentuReset();
249 //---------------------------------------------------------------------------
251 // Function: EplIdentuReset
253 // Description: resets this instance
260 // Returns: tEplKernel = errorcode
265 //---------------------------------------------------------------------------
267 EPLDLLEXPORT tEplKernel PUBLIC EplIdentuReset()
272 Ret = kEplSuccessful;
274 for (iIndex = 0; iIndex < tabentries (EplIdentuInstance_g.m_apIdentResponse); iIndex++)
276 if (EplIdentuInstance_g.m_apIdentResponse[iIndex] != NULL)
278 EPL_FREE(EplIdentuInstance_g.m_apIdentResponse[iIndex]);
282 EPL_MEMSET(&EplIdentuInstance_g, 0, sizeof (EplIdentuInstance_g));
289 //---------------------------------------------------------------------------
291 // Function: EplIdentuGetIdentResponse
293 // Description: returns the IdentResponse for the specified node.
295 // Parameters: uiNodeId_p = IN: node ID
296 // ppIdentResponse_p = OUT: pointer to pointer of IdentResponse
297 // equals NULL, if no IdentResponse available
299 // Return: tEplKernel = error code
303 //---------------------------------------------------------------------------
305 tEplKernel PUBLIC EplIdentuGetIdentResponse(
306 unsigned int uiNodeId_p,
307 tEplIdentResponse** ppIdentResponse_p)
311 Ret = kEplSuccessful;
313 // decrement node ID, because array is zero based
315 if (uiNodeId_p < tabentries (EplIdentuInstance_g.m_apIdentResponse))
317 *ppIdentResponse_p = EplIdentuInstance_g.m_apIdentResponse[uiNodeId_p];
320 { // invalid node ID specified
321 *ppIdentResponse_p = NULL;
322 Ret = kEplInvalidNodeId;
330 //---------------------------------------------------------------------------
332 // Function: EplIdentuRequestIdentResponse
334 // Description: returns the IdentResponse for the specified node.
336 // Parameters: uiNodeId_p = IN: node ID
337 // pfnCbResponse_p = IN: function pointer to callback function
338 // which will be called if IdentResponse is received
340 // Return: tEplKernel = error code
344 //---------------------------------------------------------------------------
346 tEplKernel PUBLIC EplIdentuRequestIdentResponse(
347 unsigned int uiNodeId_p,
348 tEplIdentuCbResponse pfnCbResponse_p)
352 Ret = kEplSuccessful;
354 // decrement node ID, because array is zero based
356 if (uiNodeId_p < tabentries (EplIdentuInstance_g.m_apfnCbResponse))
358 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
359 if (EplIdentuInstance_g.m_apfnCbResponse[uiNodeId_p] != NULL)
360 { // request already issued (maybe by someone else)
361 Ret = kEplInvalidOperation;
365 EplIdentuInstance_g.m_apfnCbResponse[uiNodeId_p] = pfnCbResponse_p;
366 Ret = EplDlluCalIssueRequest(kEplDllReqServiceIdent, (uiNodeId_p + 1), 0xFF);
369 Ret = kEplInvalidOperation;
373 { // invalid node ID specified
374 Ret = kEplInvalidNodeId;
382 //---------------------------------------------------------------------------
384 // Function: EplIdentuGetRunningRequests
386 // Description: returns a bit field with the running requests for node-ID 1-32
387 // just for debugging purposes
393 // Returns: tEplKernel = errorcode
398 //---------------------------------------------------------------------------
400 EPLDLLEXPORT DWORD PUBLIC EplIdentuGetRunningRequests(void)
403 unsigned int uiIndex;
405 for (uiIndex = 0; uiIndex < 32; uiIndex++)
407 if (EplIdentuInstance_g.m_apfnCbResponse[uiIndex] != NULL)
409 dwReqs |= (1 << uiIndex);
417 //=========================================================================//
419 // P R I V A T E F U N C T I O N S //
421 //=========================================================================//
423 //---------------------------------------------------------------------------
425 // Function: EplIdentuCbIdentResponse
427 // Description: callback funktion for IdentResponse
431 // Parameters: pFrameInfo_p = Frame with the IdentResponse
434 // Returns: tEplKernel = error code
439 //---------------------------------------------------------------------------
441 static tEplKernel PUBLIC EplIdentuCbIdentResponse(tEplFrameInfo * pFrameInfo_p)
443 tEplKernel Ret = kEplSuccessful;
444 unsigned int uiNodeId;
445 unsigned int uiIndex;
446 tEplIdentuCbResponse pfnCbResponse;
448 uiNodeId = AmiGetByteFromLe(&pFrameInfo_p->m_pFrame->m_le_bSrcNodeId);
450 uiIndex = uiNodeId - 1;
452 if (uiIndex < tabentries (EplIdentuInstance_g.m_apfnCbResponse))
454 // memorize pointer to callback function
455 pfnCbResponse = EplIdentuInstance_g.m_apfnCbResponse[uiIndex];
456 // reset callback function pointer so that caller may issue next request immediately
457 EplIdentuInstance_g.m_apfnCbResponse[uiIndex] = NULL;
459 if (pFrameInfo_p->m_uiFrameSize < EPL_C_DLL_MINSIZE_IDENTRES)
460 { // IdentResponse not received or it has invalid size
461 if (pfnCbResponse == NULL)
462 { // response was not requested
465 Ret = pfnCbResponse(uiNodeId, NULL);
468 { // IdentResponse received
469 if (EplIdentuInstance_g.m_apIdentResponse[uiIndex] == NULL)
470 { // memory for IdentResponse must be allocated
471 EplIdentuInstance_g.m_apIdentResponse[uiIndex] = EPL_MALLOC(sizeof (tEplIdentResponse));
472 if (EplIdentuInstance_g.m_apIdentResponse[uiIndex] == NULL)
474 if (pfnCbResponse == NULL)
475 { // response was not requested
478 Ret = pfnCbResponse(uiNodeId, &pFrameInfo_p->m_pFrame->m_Data.m_Asnd.m_Payload.m_IdentResponse);
482 // copy IdentResponse to instance structure
483 EPL_MEMCPY(EplIdentuInstance_g.m_apIdentResponse[uiIndex], &pFrameInfo_p->m_pFrame->m_Data.m_Asnd.m_Payload.m_IdentResponse, sizeof(tEplIdentResponse));
484 if (pfnCbResponse == NULL)
485 { // response was not requested
488 Ret = pfnCbResponse(uiNodeId, EplIdentuInstance_g.m_apIdentResponse[uiIndex]);