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 PUBLIC 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 PUBLIC EplIdentuInit()
171 Ret = EplIdentuAddInstance();
176 //---------------------------------------------------------------------------
178 // Function: EplIdentuAddInstance
180 // Description: init other instances of the module
187 // Returns: tEplKernel = errorcode
192 //---------------------------------------------------------------------------
194 EPLDLLEXPORT tEplKernel PUBLIC EplIdentuAddInstance()
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 PUBLIC EplIdentuDelInstance()
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 PUBLIC EplIdentuReset()
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 PUBLIC EplIdentuGetIdentResponse(unsigned int uiNodeId_p,
309 Ret = kEplSuccessful;
311 // decrement node ID, because array is zero based
313 if (uiNodeId_p < tabentries(EplIdentuInstance_g.m_apIdentResponse)) {
315 EplIdentuInstance_g.m_apIdentResponse[uiNodeId_p];
316 } else { // invalid node ID specified
317 *ppIdentResponse_p = NULL;
318 Ret = kEplInvalidNodeId;
325 //---------------------------------------------------------------------------
327 // Function: EplIdentuRequestIdentResponse
329 // Description: returns the IdentResponse for the specified node.
331 // Parameters: uiNodeId_p = IN: node ID
332 // pfnCbResponse_p = IN: function pointer to callback function
333 // which will be called if IdentResponse is received
335 // Return: tEplKernel = error code
339 //---------------------------------------------------------------------------
341 tEplKernel PUBLIC EplIdentuRequestIdentResponse(unsigned int uiNodeId_p,
347 Ret = kEplSuccessful;
349 // decrement node ID, because array is zero based
351 if (uiNodeId_p < tabentries(EplIdentuInstance_g.m_apfnCbResponse)) {
352 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
353 if (EplIdentuInstance_g.m_apfnCbResponse[uiNodeId_p] != NULL) { // request already issued (maybe by someone else)
354 Ret = kEplInvalidOperation;
356 EplIdentuInstance_g.m_apfnCbResponse[uiNodeId_p] =
359 EplDlluCalIssueRequest(kEplDllReqServiceIdent,
360 (uiNodeId_p + 1), 0xFF);
363 Ret = kEplInvalidOperation;
365 } else { // invalid node ID specified
366 Ret = kEplInvalidNodeId;
373 //---------------------------------------------------------------------------
375 // Function: EplIdentuGetRunningRequests
377 // Description: returns a bit field with the running requests for node-ID 1-32
378 // just for debugging purposes
384 // Returns: tEplKernel = errorcode
389 //---------------------------------------------------------------------------
391 EPLDLLEXPORT DWORD PUBLIC EplIdentuGetRunningRequests(void)
394 unsigned int uiIndex;
396 for (uiIndex = 0; uiIndex < 32; uiIndex++) {
397 if (EplIdentuInstance_g.m_apfnCbResponse[uiIndex] != NULL) {
398 dwReqs |= (1 << uiIndex);
405 //=========================================================================//
407 // P R I V A T E F U N C T I O N S //
409 //=========================================================================//
411 //---------------------------------------------------------------------------
413 // Function: EplIdentuCbIdentResponse
415 // Description: callback funktion for IdentResponse
419 // Parameters: pFrameInfo_p = Frame with the IdentResponse
422 // Returns: tEplKernel = error code
427 //---------------------------------------------------------------------------
429 static tEplKernel PUBLIC EplIdentuCbIdentResponse(tEplFrameInfo * pFrameInfo_p)
431 tEplKernel Ret = kEplSuccessful;
432 unsigned int uiNodeId;
433 unsigned int uiIndex;
434 tEplIdentuCbResponse pfnCbResponse;
436 uiNodeId = AmiGetByteFromLe(&pFrameInfo_p->m_pFrame->m_le_bSrcNodeId);
438 uiIndex = uiNodeId - 1;
440 if (uiIndex < tabentries(EplIdentuInstance_g.m_apfnCbResponse)) {
441 // memorize pointer to callback function
442 pfnCbResponse = EplIdentuInstance_g.m_apfnCbResponse[uiIndex];
443 // reset callback function pointer so that caller may issue next request immediately
444 EplIdentuInstance_g.m_apfnCbResponse[uiIndex] = NULL;
446 if (pFrameInfo_p->m_uiFrameSize < EPL_C_DLL_MINSIZE_IDENTRES) { // IdentResponse not received or it has invalid size
447 if (pfnCbResponse == NULL) { // response was not requested
450 Ret = pfnCbResponse(uiNodeId, NULL);
451 } else { // IdentResponse received
452 if (EplIdentuInstance_g.m_apIdentResponse[uiIndex] == NULL) { // memory for IdentResponse must be allocated
453 EplIdentuInstance_g.m_apIdentResponse[uiIndex] =
454 EPL_MALLOC(sizeof(tEplIdentResponse));
455 if (EplIdentuInstance_g.m_apIdentResponse[uiIndex] == NULL) { // malloc failed
456 if (pfnCbResponse == NULL) { // response was not requested
460 pfnCbResponse(uiNodeId,
468 // copy IdentResponse to instance structure
469 EPL_MEMCPY(EplIdentuInstance_g.
470 m_apIdentResponse[uiIndex],
471 &pFrameInfo_p->m_pFrame->m_Data.m_Asnd.
472 m_Payload.m_IdentResponse,
473 sizeof(tEplIdentResponse));
474 if (pfnCbResponse == NULL) { // response was not requested
478 pfnCbResponse(uiNodeId,
480 m_apIdentResponse[uiIndex]);