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 //---------------------------------------------------------------------------
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 tEplIdentResponse *m_apIdentResponse[254]; // the IdentResponse are managed dynamically
127 tEplIdentuCbResponse m_apfnCbResponse[254];
129 } tEplIdentuInstance;
131 //---------------------------------------------------------------------------
133 //---------------------------------------------------------------------------
135 static tEplIdentuInstance EplIdentuInstance_g;
137 //---------------------------------------------------------------------------
138 // local function prototypes
139 //---------------------------------------------------------------------------
141 static tEplKernel EplIdentuCbIdentResponse(tEplFrameInfo *pFrameInfo_p);
143 //=========================================================================//
145 // P U B L I C F U N C T I O N S //
147 //=========================================================================//
149 //---------------------------------------------------------------------------
151 // Function: EplIdentuInit
153 // Description: init first instance of the module
160 // Returns: tEplKernel = errorcode
165 //---------------------------------------------------------------------------
167 EPLDLLEXPORT tEplKernel EplIdentuInit(void)
171 Ret = EplIdentuAddInstance();
176 //---------------------------------------------------------------------------
178 // Function: EplIdentuAddInstance
180 // Description: init other instances of the module
187 // Returns: tEplKernel = errorcode
192 //---------------------------------------------------------------------------
194 EPLDLLEXPORT tEplKernel EplIdentuAddInstance(void)
198 Ret = kEplSuccessful;
200 // reset instance structure
201 EPL_MEMSET(&EplIdentuInstance_g, 0, sizeof(EplIdentuInstance_g));
203 // register IdentResponse callback function
205 EplDlluCalRegAsndService(kEplDllAsndIdentResponse,
206 EplIdentuCbIdentResponse,
207 kEplDllAsndFilterAny);
213 //---------------------------------------------------------------------------
215 // Function: EplIdentuDelInstance
217 // Description: delete instance
224 // Returns: tEplKernel = errorcode
229 //---------------------------------------------------------------------------
231 EPLDLLEXPORT tEplKernel EplIdentuDelInstance(void)
235 Ret = kEplSuccessful;
237 // deregister IdentResponse callback function
239 EplDlluCalRegAsndService(kEplDllAsndIdentResponse, NULL,
240 kEplDllAsndFilterNone);
242 Ret = EplIdentuReset();
248 //---------------------------------------------------------------------------
250 // Function: EplIdentuReset
252 // Description: resets this instance
259 // Returns: tEplKernel = errorcode
264 //---------------------------------------------------------------------------
266 EPLDLLEXPORT tEplKernel EplIdentuReset(void)
271 Ret = kEplSuccessful;
274 iIndex < tabentries(EplIdentuInstance_g.m_apIdentResponse);
276 if (EplIdentuInstance_g.m_apIdentResponse[iIndex] != NULL) { // free memory
277 EPL_FREE(EplIdentuInstance_g.m_apIdentResponse[iIndex]);
281 EPL_MEMSET(&EplIdentuInstance_g, 0, sizeof(EplIdentuInstance_g));
287 //---------------------------------------------------------------------------
289 // Function: EplIdentuGetIdentResponse
291 // Description: returns the IdentResponse for the specified node.
293 // Parameters: uiNodeId_p = IN: node ID
294 // ppIdentResponse_p = OUT: pointer to pointer of IdentResponse
295 // equals NULL, if no IdentResponse available
297 // Return: tEplKernel = error code
301 //---------------------------------------------------------------------------
303 tEplKernel EplIdentuGetIdentResponse(unsigned int uiNodeId_p,
304 tEplIdentResponse **ppIdentResponse_p)
308 Ret = kEplSuccessful;
310 // decrement node ID, because array is zero based
312 if (uiNodeId_p < tabentries(EplIdentuInstance_g.m_apIdentResponse)) {
314 EplIdentuInstance_g.m_apIdentResponse[uiNodeId_p];
315 } else { // invalid node ID specified
316 *ppIdentResponse_p = NULL;
317 Ret = kEplInvalidNodeId;
324 //---------------------------------------------------------------------------
326 // Function: EplIdentuRequestIdentResponse
328 // Description: returns the IdentResponse for the specified node.
330 // Parameters: uiNodeId_p = IN: node ID
331 // pfnCbResponse_p = IN: function pointer to callback function
332 // which will be called if IdentResponse is received
334 // Return: tEplKernel = error code
338 //---------------------------------------------------------------------------
340 tEplKernel EplIdentuRequestIdentResponse(unsigned int uiNodeId_p,
341 tEplIdentuCbResponse pfnCbResponse_p)
345 Ret = kEplSuccessful;
347 // decrement node ID, because array is zero based
349 if (uiNodeId_p < tabentries(EplIdentuInstance_g.m_apfnCbResponse)) {
350 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
351 if (EplIdentuInstance_g.m_apfnCbResponse[uiNodeId_p] != NULL) { // request already issued (maybe by someone else)
352 Ret = kEplInvalidOperation;
354 EplIdentuInstance_g.m_apfnCbResponse[uiNodeId_p] =
357 EplDlluCalIssueRequest(kEplDllReqServiceIdent,
358 (uiNodeId_p + 1), 0xFF);
361 Ret = kEplInvalidOperation;
363 } else { // invalid node ID specified
364 Ret = kEplInvalidNodeId;
371 //---------------------------------------------------------------------------
373 // Function: EplIdentuGetRunningRequests
375 // Description: returns a bit field with the running requests for node-ID 1-32
376 // just for debugging purposes
382 // Returns: tEplKernel = errorcode
387 //---------------------------------------------------------------------------
389 EPLDLLEXPORT DWORD EplIdentuGetRunningRequests(void)
392 unsigned int uiIndex;
394 for (uiIndex = 0; uiIndex < 32; uiIndex++) {
395 if (EplIdentuInstance_g.m_apfnCbResponse[uiIndex] != NULL) {
396 dwReqs |= (1 << uiIndex);
403 //=========================================================================//
405 // P R I V A T E F U N C T I O N S //
407 //=========================================================================//
409 //---------------------------------------------------------------------------
411 // Function: EplIdentuCbIdentResponse
413 // Description: callback funktion for IdentResponse
417 // Parameters: pFrameInfo_p = Frame with the IdentResponse
420 // Returns: tEplKernel = error code
425 //---------------------------------------------------------------------------
427 static tEplKernel EplIdentuCbIdentResponse(tEplFrameInfo *pFrameInfo_p)
429 tEplKernel Ret = kEplSuccessful;
430 unsigned int uiNodeId;
431 unsigned int uiIndex;
432 tEplIdentuCbResponse pfnCbResponse;
434 uiNodeId = AmiGetByteFromLe(&pFrameInfo_p->m_pFrame->m_le_bSrcNodeId);
436 uiIndex = uiNodeId - 1;
438 if (uiIndex < tabentries(EplIdentuInstance_g.m_apfnCbResponse)) {
439 // memorize pointer to callback function
440 pfnCbResponse = EplIdentuInstance_g.m_apfnCbResponse[uiIndex];
441 // reset callback function pointer so that caller may issue next request immediately
442 EplIdentuInstance_g.m_apfnCbResponse[uiIndex] = NULL;
444 if (pFrameInfo_p->m_uiFrameSize < EPL_C_DLL_MINSIZE_IDENTRES) { // IdentResponse not received or it has invalid size
445 if (pfnCbResponse == NULL) { // response was not requested
448 Ret = pfnCbResponse(uiNodeId, NULL);
449 } else { // IdentResponse received
450 if (EplIdentuInstance_g.m_apIdentResponse[uiIndex] == NULL) { // memory for IdentResponse must be allocated
451 EplIdentuInstance_g.m_apIdentResponse[uiIndex] =
452 EPL_MALLOC(sizeof(tEplIdentResponse));
453 if (EplIdentuInstance_g.m_apIdentResponse[uiIndex] == NULL) { // malloc failed
454 if (pfnCbResponse == NULL) { // response was not requested
458 pfnCbResponse(uiNodeId,
466 // copy IdentResponse to instance structure
467 EPL_MEMCPY(EplIdentuInstance_g.
468 m_apIdentResponse[uiIndex],
469 &pFrameInfo_p->m_pFrame->m_Data.m_Asnd.
470 m_Payload.m_IdentResponse,
471 sizeof(tEplIdentResponse));
472 if (pfnCbResponse == NULL) { // response was not requested
476 pfnCbResponse(uiNodeId,
478 m_apIdentResponse[uiIndex]);