Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | |
| 3 | (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29 |
| 4 | www.systec-electronic.com |
| 5 | |
| 6 | Project: openPOWERLINK |
| 7 | |
| 8 | Description: source file for api function of EplOBD-Module |
| 9 | |
| 10 | License: |
| 11 | |
| 12 | Redistribution and use in source and binary forms, with or without |
| 13 | modification, are permitted provided that the following conditions |
| 14 | are met: |
| 15 | |
| 16 | 1. Redistributions of source code must retain the above copyright |
| 17 | notice, this list of conditions and the following disclaimer. |
| 18 | |
| 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. |
| 22 | |
| 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. |
| 27 | |
| 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. |
| 40 | |
| 41 | Severability Clause: |
| 42 | |
| 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. |
| 49 | |
| 50 | ------------------------------------------------------------------------- |
| 51 | |
| 52 | $RCSfile: EplObd.c,v $ |
| 53 | |
| 54 | $Author: D.Krueger $ |
| 55 | |
| 56 | $Revision: 1.12 $ $Date: 2008/10/17 15:32:32 $ |
| 57 | |
| 58 | $State: Exp $ |
| 59 | |
| 60 | Build Environment: |
| 61 | Microsoft VC7 |
| 62 | |
| 63 | ------------------------------------------------------------------------- |
| 64 | |
| 65 | Revision History: |
| 66 | |
| 67 | 2006/06/02 k.t.: start of the implementation, version 1.00 |
| 68 | ->based on CANopen OBD-Modul |
| 69 | |
| 70 | ****************************************************************************/ |
| 71 | |
| 72 | #include "EplInc.h" |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 73 | #include "kernel/EplObdk.h" // function prototyps of the EplOBD-Modul |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 74 | |
| 75 | #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDK)) != 0) |
| 76 | |
| 77 | /***************************************************************************/ |
| 78 | /* */ |
| 79 | /* */ |
| 80 | /* G L O B A L D E F I N I T I O N S */ |
| 81 | /* */ |
| 82 | /* */ |
| 83 | /***************************************************************************/ |
| 84 | |
| 85 | //--------------------------------------------------------------------------- |
| 86 | // const defines |
| 87 | //--------------------------------------------------------------------------- |
| 88 | |
| 89 | // float definitions and macros |
| 90 | #define _SHIFTED_EXPONENT_MASK_SP 0xff |
| 91 | #define _BIAS_SP 126 |
| 92 | #define T_SP 23 |
| 93 | #define EXPONENT_DENORM_SP (-_BIAS_SP) |
| 94 | #define BASE_TO_THE_T_SP ((float) 8388608.0) |
| 95 | #define GET_EXPONENT_SP(x) ((((x) >> T_SP) & _SHIFTED_EXPONENT_MASK_SP) - _BIAS_SP) |
| 96 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 97 | //--------------------------------------------------------------------------- |
| 98 | // local types |
| 99 | //--------------------------------------------------------------------------- |
| 100 | |
| 101 | // struct for instance table |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 102 | INSTANCE_TYPE_BEGIN EPL_MCO_DECL_INSTANCE_MEMBER() |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 103 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 104 | STATIC tEplObdInitParam m_ObdInitParam; |
Greg Kroah-Hartman | 44b7117 | 2009-03-23 11:39:15 -0700 | [diff] [blame] | 105 | STATIC tEplObdStoreLoadObjCallback m_fpStoreLoadObjCallback; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 106 | |
| 107 | INSTANCE_TYPE_END |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 108 | // decomposition of float |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 109 | typedef union { |
| 110 | tEplObdReal32 m_flRealPart; |
| 111 | int m_nIntegerPart; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 112 | |
| 113 | } tEplObdRealParts; |
| 114 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 115 | //--------------------------------------------------------------------------- |
| 116 | // modul globale vars |
| 117 | //--------------------------------------------------------------------------- |
| 118 | |
| 119 | // This macro replace the unspecific pointer to an instance through |
| 120 | // the modul specific type for the local instance table. This macro |
| 121 | // must defined in each modul. |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 122 | //#define tEplPtrInstance tEplInstanceInfo * |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 123 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 124 | EPL_MCO_DECL_INSTANCE_VAR() |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 125 | |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 126 | u8 abEplObdTrashObject_g[8]; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 127 | |
| 128 | //--------------------------------------------------------------------------- |
| 129 | // local function prototypes |
| 130 | //--------------------------------------------------------------------------- |
| 131 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 132 | EPL_MCO_DEFINE_INSTANCE_FCT() |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 133 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 134 | static tEplKernel EplObdCallObjectCallback(EPL_MCO_DECL_INSTANCE_PTR_ |
| 135 | tEplObdCallback fpCallback_p, |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 136 | tEplObdCbParam *pCbParam_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 137 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 138 | static tEplObdSize EplObdGetDataSizeIntern(tEplObdSubEntryPtr pSubIndexEntry_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 139 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 140 | static tEplObdSize EplObdGetStrLen(void *pObjData_p, |
| 141 | tEplObdSize ObjLen_p, tEplObdType ObjType_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 142 | |
| 143 | #if (EPL_OBD_CHECK_OBJECT_RANGE != FALSE) |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 144 | static tEplKernel EplObdCheckObjectRange(tEplObdSubEntryPtr pSubindexEntry_p, |
| 145 | void *pData_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 146 | #endif |
| 147 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 148 | static tEplKernel EplObdGetVarEntry(tEplObdSubEntryPtr pSubindexEntry_p, |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 149 | tEplObdVarEntry **ppVarEntry_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 150 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 151 | static tEplKernel EplObdGetEntry(EPL_MCO_DECL_INSTANCE_PTR_ |
| 152 | unsigned int uiIndex_p, |
| 153 | unsigned int uiSubindex_p, |
| 154 | tEplObdEntryPtr * ppObdEntry_p, |
| 155 | tEplObdSubEntryPtr * ppObdSubEntry_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 156 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 157 | static tEplObdSize EplObdGetObjectSize(tEplObdSubEntryPtr pSubIndexEntry_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 158 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 159 | static tEplKernel EplObdGetIndexIntern(tEplObdInitParam *pInitParam_p, |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 160 | unsigned int uiIndex_p, |
| 161 | tEplObdEntryPtr * ppObdEntry_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 162 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 163 | static tEplKernel EplObdGetSubindexIntern(tEplObdEntryPtr pObdEntry_p, |
| 164 | unsigned int uiSubIndex_p, |
| 165 | tEplObdSubEntryPtr * ppObdSubEntry_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 166 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 167 | static tEplKernel EplObdAccessOdPartIntern(EPL_MCO_DECL_INSTANCE_PTR_ |
| 168 | tEplObdPart CurrentOdPart_p, |
| 169 | tEplObdEntryPtr pObdEnty_p, |
| 170 | tEplObdDir Direction_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 171 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 172 | static void *EplObdGetObjectDefaultPtr(tEplObdSubEntryPtr pSubIndexEntry_p); |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 173 | static void *EplObdGetObjectCurrentPtr(tEplObdSubEntryPtr pSubIndexEntry_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 174 | |
| 175 | #if (EPL_OBD_USE_STORE_RESTORE != FALSE) |
| 176 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 177 | static tEplKernel EplObdCallStoreCallback(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdCbStoreParam *pCbStoreParam_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 178 | |
| 179 | #endif // (EPL_OBD_USE_STORE_RESTORE != FALSE) |
| 180 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 181 | static void EplObdCopyObjectData(void *pDstData_p, |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 182 | void *pSrcData_p, |
| 183 | tEplObdSize ObjSize_p, tEplObdType ObjType_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 184 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 185 | void *EplObdGetObjectDataPtrIntern(tEplObdSubEntryPtr pSubindexEntry_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 186 | |
| 187 | static tEplKernel EplObdIsNumericalIntern(tEplObdSubEntryPtr pObdSubEntry_p, |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 188 | BOOL * pfEntryNumerical_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 189 | |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 190 | static tEplKernel EplObdWriteEntryPre(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p, |
| 191 | unsigned int uiSubIndex_p, |
| 192 | void *pSrcData_p, |
| 193 | void **ppDstData_p, |
| 194 | tEplObdSize Size_p, |
| 195 | tEplObdEntryPtr *ppObdEntry_p, |
| 196 | tEplObdSubEntryPtr *ppSubEntry_p, |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 197 | tEplObdCbParam *pCbParam_p, |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 198 | tEplObdSize *pObdSize_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 199 | |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 200 | static tEplKernel EplObdWriteEntryPost(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdEntryPtr pObdEntry_p, |
| 201 | tEplObdSubEntryPtr pSubEntry_p, |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 202 | tEplObdCbParam *pCbParam_p, |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 203 | void *pSrcData_p, |
| 204 | void *pDstData_p, |
| 205 | tEplObdSize ObdSize_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 206 | |
| 207 | //=========================================================================// |
| 208 | // // |
| 209 | // P U B L I C F U N C T I O N S // |
| 210 | // // |
| 211 | //=========================================================================// |
| 212 | |
| 213 | //--------------------------------------------------------------------------- |
| 214 | // |
| 215 | // Function: EplObdInit() |
| 216 | // |
| 217 | // Description: initializes the first instance |
| 218 | // |
| 219 | // Parameters: pInitParam_p = init parameter |
| 220 | // |
| 221 | // Return: tEplKernel = errorcode |
| 222 | // |
| 223 | // State: |
| 224 | // |
| 225 | //--------------------------------------------------------------------------- |
| 226 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 227 | EPLDLLEXPORT tEplKernel EplObdInit(EPL_MCO_DECL_PTR_INSTANCE_PTR_ tEplObdInitParam *pInitParam_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 228 | { |
| 229 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 230 | tEplKernel Ret; |
| 231 | EPL_MCO_DELETE_INSTANCE_TABLE(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 232 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 233 | if (pInitParam_p == NULL) { |
| 234 | Ret = kEplSuccessful; |
| 235 | goto Exit; |
| 236 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 237 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 238 | Ret = EplObdAddInstance(EPL_MCO_PTR_INSTANCE_PTR_ pInitParam_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 239 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 240 | Exit: |
| 241 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 242 | |
| 243 | } |
| 244 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 245 | //--------------------------------------------------------------------------- |
| 246 | // |
| 247 | // Function: EplObdAddInstance() |
| 248 | // |
| 249 | // Description: adds a new instance |
| 250 | // |
| 251 | // Parameters: pInitParam_p |
| 252 | // |
| 253 | // Return: tEplKernel |
| 254 | // |
| 255 | // State: |
| 256 | // |
| 257 | //--------------------------------------------------------------------------- |
| 258 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 259 | EPLDLLEXPORT tEplKernel EplObdAddInstance(EPL_MCO_DECL_PTR_INSTANCE_PTR_ tEplObdInitParam *pInitParam_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 260 | { |
| 261 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 262 | EPL_MCO_DECL_INSTANCE_PTR_LOCAL tEplKernel Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 263 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 264 | // check if pointer to instance pointer valid |
| 265 | // get free instance and set the globale instance pointer |
| 266 | // set also the instance addr to parameterlist |
| 267 | EPL_MCO_CHECK_PTR_INSTANCE_PTR(); |
| 268 | EPL_MCO_GET_FREE_INSTANCE_PTR(); |
| 269 | EPL_MCO_SET_PTR_INSTANCE_PTR(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 270 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 271 | // save init parameters |
| 272 | EPL_MEMCPY(&EPL_MCO_GLB_VAR(m_ObdInitParam), pInitParam_p, |
| 273 | sizeof(tEplObdInitParam)); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 274 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 275 | // clear callback function for command LOAD and STORE |
| 276 | EPL_MCO_GLB_VAR(m_fpStoreLoadObjCallback) = NULL; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 277 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 278 | // sign instance as used |
| 279 | EPL_MCO_WRITE_INSTANCE_STATE(kStateUsed); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 280 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 281 | // initialize object dictionary |
| 282 | // so all all VarEntries will be initialized to trash object and default values will be set to current data |
| 283 | Ret = EplObdAccessOdPart(EPL_MCO_INSTANCE_PTR_ |
| 284 | kEplObdPartAll, kEplObdDirInit); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 285 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 286 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 287 | |
| 288 | } |
| 289 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 290 | //--------------------------------------------------------------------------- |
| 291 | // |
| 292 | // Function: EplObdDeleteInstance() |
| 293 | // |
| 294 | // Description: delete instance |
| 295 | // |
| 296 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR |
| 297 | // |
| 298 | // Return: tEplKernel |
| 299 | // |
| 300 | // State: |
| 301 | // |
| 302 | //--------------------------------------------------------------------------- |
| 303 | #if (EPL_USE_DELETEINST_FUNC != FALSE) |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 304 | EPLDLLEXPORT tEplKernel EplObdDeleteInstance(EPL_MCO_DECL_INSTANCE_PTR) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 305 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 306 | // check for all API function if instance is valid |
| 307 | EPL_MCO_CHECK_INSTANCE_STATE(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 308 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 309 | // sign instance as unused |
| 310 | EPL_MCO_WRITE_INSTANCE_STATE(kStateUnused); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 311 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 312 | return kEplSuccessful; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 313 | |
| 314 | } |
| 315 | #endif // (EPL_USE_DELETEINST_FUNC != FALSE) |
| 316 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 317 | //--------------------------------------------------------------------------- |
| 318 | // |
| 319 | // Function: EplObdWriteEntry() |
| 320 | // |
| 321 | // Description: Function writes data to an OBD entry. Strings |
| 322 | // are stored with added '\0' character. |
| 323 | // |
| 324 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ |
| 325 | // uiIndex_p = Index of the OD entry |
| 326 | // uiSubIndex_p = Subindex of the OD Entry |
| 327 | // pSrcData_p = Pointer to the data to write |
| 328 | // Size_p = Size of the data in Byte |
| 329 | // |
| 330 | // Return: tEplKernel = Errorcode |
| 331 | // |
| 332 | // |
| 333 | // State: |
| 334 | // |
| 335 | //--------------------------------------------------------------------------- |
| 336 | |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 337 | EPLDLLEXPORT tEplKernel EplObdWriteEntry(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p, |
| 338 | unsigned int uiSubIndex_p, |
| 339 | void *pSrcData_p, |
| 340 | tEplObdSize Size_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 341 | { |
| 342 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 343 | tEplKernel Ret; |
| 344 | tEplObdEntryPtr pObdEntry; |
| 345 | tEplObdSubEntryPtr pSubEntry; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 346 | tEplObdCbParam CbParam; |
| 347 | void *pDstData; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 348 | tEplObdSize ObdSize; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 349 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 350 | Ret = EplObdWriteEntryPre(EPL_MCO_INSTANCE_PTR_ |
| 351 | uiIndex_p, |
| 352 | uiSubIndex_p, |
| 353 | pSrcData_p, |
| 354 | &pDstData, |
| 355 | Size_p, |
| 356 | &pObdEntry, &pSubEntry, &CbParam, &ObdSize); |
| 357 | if (Ret != kEplSuccessful) { |
| 358 | goto Exit; |
| 359 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 360 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 361 | Ret = EplObdWriteEntryPost(EPL_MCO_INSTANCE_PTR_ |
| 362 | pObdEntry, |
| 363 | pSubEntry, |
| 364 | &CbParam, pSrcData_p, pDstData, ObdSize); |
| 365 | if (Ret != kEplSuccessful) { |
| 366 | goto Exit; |
| 367 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 368 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 369 | Exit: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 370 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 371 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 372 | |
| 373 | } |
| 374 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 375 | //--------------------------------------------------------------------------- |
| 376 | // |
| 377 | // Function: EplObdReadEntry() |
| 378 | // |
| 379 | // Description: The function reads an object entry. The application |
| 380 | // can always read the data even if attrib kEplObdAccRead |
| 381 | // is not set. The attrib is only checked up for SDO transfer. |
| 382 | // |
| 383 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ |
| 384 | // uiIndex_p = Index oof the OD entry to read |
| 385 | // uiSubIndex_p = Subindex to read |
| 386 | // pDstData_p = pointer to the buffer for data |
| 387 | // Offset_p = offset in data for read access |
| 388 | // pSize_p = IN: Size of the buffer |
| 389 | // OUT: number of readed Bytes |
| 390 | // |
| 391 | // Return: tEplKernel |
| 392 | // |
| 393 | // State: |
| 394 | // |
| 395 | //--------------------------------------------------------------------------- |
| 396 | |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 397 | EPLDLLEXPORT tEplKernel EplObdReadEntry(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p, |
| 398 | unsigned int uiSubIndex_p, |
| 399 | void *pDstData_p, |
| 400 | tEplObdSize *pSize_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 401 | { |
| 402 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 403 | tEplKernel Ret; |
| 404 | tEplObdEntryPtr pObdEntry; |
| 405 | tEplObdSubEntryPtr pSubEntry; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 406 | tEplObdCbParam CbParam; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 407 | void *pSrcData; |
| 408 | tEplObdSize ObdSize; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 409 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 410 | // check for all API function if instance is valid |
| 411 | EPL_MCO_CHECK_INSTANCE_STATE(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 412 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 413 | ASSERT(pDstData_p != NULL); |
| 414 | ASSERT(pSize_p != NULL); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 415 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 416 | // get address of index and subindex entry |
| 417 | Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_ |
| 418 | uiIndex_p, uiSubIndex_p, &pObdEntry, &pSubEntry); |
| 419 | if (Ret != kEplSuccessful) { |
| 420 | goto Exit; |
| 421 | } |
| 422 | // get pointer to object data |
| 423 | pSrcData = EplObdGetObjectDataPtrIntern(pSubEntry); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 424 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 425 | // check source pointer |
| 426 | if (pSrcData == NULL) { |
| 427 | Ret = kEplObdReadViolation; |
| 428 | goto Exit; |
| 429 | } |
| 430 | //------------------------------------------------------------------------ |
| 431 | // address of source data to structure of callback parameters |
| 432 | // so callback function can change this data before reading |
| 433 | CbParam.m_uiIndex = uiIndex_p; |
| 434 | CbParam.m_uiSubIndex = uiSubIndex_p; |
| 435 | CbParam.m_pArg = pSrcData; |
| 436 | CbParam.m_ObdEvent = kEplObdEvPreRead; |
| 437 | Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_ |
| 438 | pObdEntry->m_fpCallback, &CbParam); |
| 439 | if (Ret != kEplSuccessful) { |
| 440 | goto Exit; |
| 441 | } |
| 442 | // get size of data and check if application has reserved enough memory |
| 443 | ObdSize = EplObdGetDataSizeIntern(pSubEntry); |
| 444 | // check if offset given and calc correct number of bytes to read |
| 445 | if (*pSize_p < ObdSize) { |
| 446 | Ret = kEplObdValueLengthError; |
| 447 | goto Exit; |
| 448 | } |
| 449 | // read value from object |
| 450 | EPL_MEMCPY(pDstData_p, pSrcData, ObdSize); |
| 451 | *pSize_p = ObdSize; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 452 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 453 | // write address of destination data to structure of callback parameters |
| 454 | // so callback function can change this data after reading |
| 455 | CbParam.m_pArg = pDstData_p; |
| 456 | CbParam.m_ObdEvent = kEplObdEvPostRead; |
| 457 | Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_ |
| 458 | pObdEntry->m_fpCallback, &CbParam); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 459 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 460 | Exit: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 461 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 462 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 463 | |
| 464 | } |
| 465 | |
| 466 | //--------------------------------------------------------------------------- |
| 467 | // |
| 468 | // Function: EplObdAccessOdPart() |
| 469 | // |
| 470 | // Description: restores default values of one part of OD |
| 471 | // |
| 472 | // Parameters: ObdPart_p |
| 473 | // Direction_p |
| 474 | // |
| 475 | // Return: tEplKernel |
| 476 | // |
| 477 | // State: |
| 478 | // |
| 479 | //--------------------------------------------------------------------------- |
| 480 | |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 481 | EPLDLLEXPORT tEplKernel EplObdAccessOdPart(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdPart ObdPart_p, |
| 482 | tEplObdDir Direction_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 483 | { |
| 484 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 485 | tEplKernel Ret = kEplSuccessful; |
| 486 | BOOL fPartFount; |
| 487 | tEplObdEntryPtr pObdEntry; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 488 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 489 | // check for all API function if instance is valid |
| 490 | EPL_MCO_CHECK_INSTANCE_STATE(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 491 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 492 | // part always has to be unequal to NULL |
| 493 | pObdEntry = EPL_MCO_GLB_VAR(m_ObdInitParam.m_pPart); |
| 494 | ASSERTMSG(pObdEntry != NULL, |
| 495 | "EplObdAccessOdPart(): no OD part is defined!\n"); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 496 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 497 | // if ObdPart_p is not valid fPartFound keeps FALSE and function returns kEplObdIllegalPart |
| 498 | fPartFount = FALSE; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 499 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 500 | // access to part |
| 501 | if ((ObdPart_p & kEplObdPartGen) != 0) { |
| 502 | fPartFount = TRUE; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 503 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 504 | Ret = EplObdAccessOdPartIntern(EPL_MCO_INSTANCE_PTR_ |
| 505 | kEplObdPartGen, pObdEntry, |
| 506 | Direction_p); |
| 507 | if (Ret != kEplSuccessful) { |
| 508 | goto Exit; |
| 509 | } |
| 510 | } |
| 511 | // access to manufacturer part |
| 512 | pObdEntry = EPL_MCO_GLB_VAR(m_ObdInitParam.m_pManufacturerPart); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 513 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 514 | if (((ObdPart_p & kEplObdPartMan) != 0) && (pObdEntry != NULL)) { |
| 515 | fPartFount = TRUE; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 516 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 517 | Ret = EplObdAccessOdPartIntern(EPL_MCO_INSTANCE_PTR_ |
| 518 | kEplObdPartMan, pObdEntry, |
| 519 | Direction_p); |
| 520 | if (Ret != kEplSuccessful) { |
| 521 | goto Exit; |
| 522 | } |
| 523 | } |
| 524 | // access to device part |
| 525 | pObdEntry = EPL_MCO_GLB_VAR(m_ObdInitParam.m_pDevicePart); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 526 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 527 | if (((ObdPart_p & kEplObdPartDev) != 0) && (pObdEntry != NULL)) { |
| 528 | fPartFount = TRUE; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 529 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 530 | Ret = EplObdAccessOdPartIntern(EPL_MCO_INSTANCE_PTR_ |
| 531 | kEplObdPartDev, pObdEntry, |
| 532 | Direction_p); |
| 533 | if (Ret != kEplSuccessful) { |
| 534 | goto Exit; |
| 535 | } |
| 536 | } |
| 537 | #if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE)) |
| 538 | { |
| 539 | // access to user part |
| 540 | pObdEntry = EPL_MCO_GLB_VAR(m_ObdInitParam.m_pUserPart); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 541 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 542 | if (((ObdPart_p & kEplObdPartUsr) != 0) && (pObdEntry != NULL)) { |
| 543 | fPartFount = TRUE; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 544 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 545 | Ret = EplObdAccessOdPartIntern(EPL_MCO_INSTANCE_PTR_ |
| 546 | kEplObdPartUsr, |
| 547 | pObdEntry, Direction_p); |
| 548 | if (Ret != kEplSuccessful) { |
| 549 | goto Exit; |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | #endif |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 554 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 555 | // no access to an OD part was done? illegal OD part was specified! |
| 556 | if (fPartFount == FALSE) { |
| 557 | Ret = kEplObdIllegalPart; |
| 558 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 559 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 560 | Exit: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 561 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 562 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 563 | |
| 564 | } |
| 565 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 566 | //--------------------------------------------------------------------------- |
| 567 | // |
| 568 | // Function: EplObdDefineVar() |
| 569 | // |
| 570 | // Description: defines a variable in OD |
| 571 | // |
| 572 | // Parameters: pEplVarParam_p |
| 573 | // |
| 574 | // Return: tEplKernel |
| 575 | // |
| 576 | // State: |
| 577 | // |
| 578 | //--------------------------------------------------------------------------- |
| 579 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 580 | EPLDLLEXPORT tEplKernel EplObdDefineVar(EPL_MCO_DECL_INSTANCE_PTR_ tEplVarParam *pVarParam_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 581 | { |
| 582 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 583 | tEplKernel Ret; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 584 | tEplObdVarEntry *pVarEntry; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 585 | tEplVarParamValid VarValid; |
| 586 | tEplObdSubEntryPtr pSubindexEntry; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 587 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 588 | // check for all API function if instance is valid |
| 589 | EPL_MCO_CHECK_INSTANCE_STATE(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 590 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 591 | ASSERT(pVarParam_p != NULL); // is not allowed to be NULL |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 592 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 593 | // get address of subindex entry |
| 594 | Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_ |
| 595 | pVarParam_p->m_uiIndex, |
| 596 | pVarParam_p->m_uiSubindex, NULL, &pSubindexEntry); |
| 597 | if (Ret != kEplSuccessful) { |
| 598 | goto Exit; |
| 599 | } |
| 600 | // get var entry |
| 601 | Ret = EplObdGetVarEntry(pSubindexEntry, &pVarEntry); |
| 602 | if (Ret != kEplSuccessful) { |
| 603 | goto Exit; |
| 604 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 605 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 606 | VarValid = pVarParam_p->m_ValidFlag; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 607 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 608 | // copy only this values, which valid flag is set |
| 609 | if ((VarValid & kVarValidSize) != 0) { |
| 610 | if (pSubindexEntry->m_Type != kEplObdTypDomain) { |
| 611 | tEplObdSize DataSize; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 612 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 613 | // check passed size parameter |
| 614 | DataSize = EplObdGetObjectSize(pSubindexEntry); |
| 615 | if (DataSize != pVarParam_p->m_Size) { // size of variable does not match |
| 616 | Ret = kEplObdValueLengthError; |
| 617 | goto Exit; |
| 618 | } |
| 619 | } else { // size can be set only for objects of type DOMAIN |
| 620 | pVarEntry->m_Size = pVarParam_p->m_Size; |
| 621 | } |
| 622 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 623 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 624 | if ((VarValid & kVarValidData) != 0) { |
| 625 | pVarEntry->m_pData = pVarParam_p->m_pData; |
| 626 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 627 | /* |
| 628 | #if (EPL_PDO_USE_STATIC_MAPPING == FALSE) |
| 629 | { |
| 630 | if ((VarValid & kVarValidCallback) != 0) |
| 631 | { |
| 632 | pVarEntry->m_fpCallback = pVarParam_p->m_fpCallback; |
| 633 | } |
| 634 | |
| 635 | if ((VarValid & kVarValidArg) != 0) |
| 636 | { |
| 637 | pVarEntry->m_pArg = pVarParam_p->m_pArg; |
| 638 | } |
| 639 | } |
| 640 | #endif |
| 641 | */ |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 642 | // Ret is already set to kEplSuccessful from ObdGetVarIntern() |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 643 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 644 | Exit: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 645 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 646 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 647 | |
| 648 | } |
| 649 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 650 | //--------------------------------------------------------------------------- |
| 651 | // |
| 652 | // Function: EplObdGetObjectDataPtr() |
| 653 | // |
| 654 | // Description: It returnes the current data pointer. But if object is an |
| 655 | // constant object it returnes the default pointer. |
| 656 | // |
| 657 | // Parameters: uiIndex_p = Index of the entry |
| 658 | // uiSubindex_p = Subindex of the entry |
| 659 | // |
| 660 | // Return: void * = pointer to object data |
| 661 | // |
| 662 | // State: |
| 663 | // |
| 664 | //--------------------------------------------------------------------------- |
| 665 | |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 666 | EPLDLLEXPORT void *EplObdGetObjectDataPtr(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p, |
| 667 | unsigned int uiSubIndex_p) |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 668 | { |
| 669 | tEplKernel Ret; |
| 670 | void *pData; |
| 671 | tEplObdEntryPtr pObdEntry; |
| 672 | tEplObdSubEntryPtr pObdSubEntry; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 673 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 674 | // get pointer to index structure |
| 675 | Ret = EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam), |
| 676 | uiIndex_p, &pObdEntry); |
| 677 | if (Ret != kEplSuccessful) { |
| 678 | pData = NULL; |
| 679 | goto Exit; |
| 680 | } |
| 681 | // get pointer to subindex structure |
| 682 | Ret = EplObdGetSubindexIntern(pObdEntry, uiSubIndex_p, &pObdSubEntry); |
| 683 | if (Ret != kEplSuccessful) { |
| 684 | pData = NULL; |
| 685 | goto Exit; |
| 686 | } |
| 687 | // get Datapointer |
| 688 | pData = EplObdGetObjectDataPtrIntern(pObdSubEntry); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 689 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 690 | Exit: |
| 691 | return pData; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 692 | |
| 693 | } |
| 694 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 695 | #if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE)) |
| 696 | |
| 697 | //--------------------------------------------------------------------------- |
| 698 | // |
| 699 | // Function: EplObdRegisterUserOd() |
| 700 | // |
| 701 | // Description: function registers the user OD |
| 702 | // |
| 703 | // Parameters: pUserOd_p =pointer to user ODd |
| 704 | // |
| 705 | // Return: tEplKernel = errorcode |
| 706 | // |
| 707 | // State: |
| 708 | // |
| 709 | //--------------------------------------------------------------------------- |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 710 | EPLDLLEXPORT tEplKernel EplObdRegisterUserOd(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdEntryPtr pUserOd_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 711 | { |
| 712 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 713 | EPL_MCO_CHECK_INSTANCE_STATE(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 714 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 715 | EPL_MCO_GLB_VAR(m_ObdInitParam.m_pUserPart) = pUserOd_p; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 716 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 717 | return kEplSuccessful; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 718 | |
| 719 | } |
| 720 | |
| 721 | #endif |
| 722 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 723 | //--------------------------------------------------------------------------- |
| 724 | // |
| 725 | // Function: EplObdInitVarEntry() |
| 726 | // |
| 727 | // Description: function to initialize VarEntry dependened on object type |
| 728 | // |
| 729 | // Parameters: pVarEntry_p = pointer to var entry structure |
| 730 | // Type_p = object type |
| 731 | // ObdSize_p = size of object data |
| 732 | // |
| 733 | // Returns: none |
| 734 | // |
| 735 | // State: |
| 736 | // |
| 737 | //--------------------------------------------------------------------------- |
| 738 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 739 | EPLDLLEXPORT void EplObdInitVarEntry(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdVarEntry *pVarEntry_p, |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 740 | tEplObdType Type_p, tEplObdSize ObdSize_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 741 | { |
| 742 | /* |
| 743 | #if (EPL_PDO_USE_STATIC_MAPPING == FALSE) |
| 744 | { |
| 745 | // reset pointer to VAR callback and argument |
| 746 | pVarEntry_p->m_fpCallback = NULL; |
| 747 | pVarEntry_p->m_pArg = NULL; |
| 748 | } |
| 749 | #endif |
| 750 | */ |
| 751 | |
| 752 | // 10-dec-2004 r.d.: this function will not be used for strings |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 753 | if ((Type_p == kEplObdTypDomain)) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 754 | // (bType_p == kEplObdTypVString) /* || |
| 755 | // (bType_p == kEplObdTypOString) || |
| 756 | // (bType_p == kEplObdTypUString) */ ) |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 757 | { |
| 758 | // variables which are defined as DOMAIN or VSTRING should not point to |
| 759 | // trash object, because this trash object contains only 8 bytes. DOMAINS or |
| 760 | // STRINGS can be longer. |
| 761 | pVarEntry_p->m_pData = NULL; |
| 762 | pVarEntry_p->m_Size = 0; |
| 763 | } else { |
| 764 | // set address to variable data to trash object |
| 765 | // This prevents an access violation if user forgets to call EplObdDefineVar() |
| 766 | // for this variable but mappes it in a PDO. |
| 767 | pVarEntry_p->m_pData = &abEplObdTrashObject_g[0]; |
| 768 | pVarEntry_p->m_Size = ObdSize_p; |
| 769 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 770 | |
| 771 | } |
| 772 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 773 | //--------------------------------------------------------------------------- |
| 774 | // |
| 775 | // Function: EplObdGetDataSize() |
| 776 | // |
| 777 | // Description: function to initialize VarEntry dependened on object type |
| 778 | // |
| 779 | // gets the data size of an object |
| 780 | // for string objects it returnes the string length |
| 781 | // |
| 782 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = Instancepointer |
| 783 | // uiIndex_p = Index |
| 784 | // uiSubIndex_p= Subindex |
| 785 | // |
| 786 | // Return: tEplObdSize |
| 787 | // |
| 788 | // State: |
| 789 | // |
| 790 | //--------------------------------------------------------------------------- |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 791 | EPLDLLEXPORT tEplObdSize EplObdGetDataSize(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p, |
| 792 | unsigned int uiSubIndex_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 793 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 794 | tEplKernel Ret; |
| 795 | tEplObdSize ObdSize; |
| 796 | tEplObdEntryPtr pObdEntry; |
| 797 | tEplObdSubEntryPtr pObdSubEntry; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 798 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 799 | // get pointer to index structure |
| 800 | Ret = EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam), |
| 801 | uiIndex_p, &pObdEntry); |
| 802 | if (Ret != kEplSuccessful) { |
| 803 | ObdSize = 0; |
| 804 | goto Exit; |
| 805 | } |
| 806 | // get pointer to subindex structure |
| 807 | Ret = EplObdGetSubindexIntern(pObdEntry, uiSubIndex_p, &pObdSubEntry); |
| 808 | if (Ret != kEplSuccessful) { |
| 809 | ObdSize = 0; |
| 810 | goto Exit; |
| 811 | } |
| 812 | // get size |
| 813 | ObdSize = EplObdGetDataSizeIntern(pObdSubEntry); |
| 814 | Exit: |
| 815 | return ObdSize; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 816 | } |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 817 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 818 | //--------------------------------------------------------------------------- |
| 819 | // |
| 820 | // Function: EplObdGetNodeId() |
| 821 | // |
| 822 | // Description: function returns nodeid from entry 0x1F93 |
| 823 | // |
| 824 | // |
| 825 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR = Instancepointer |
| 826 | // |
| 827 | // Return: unsigned int = Node Id |
| 828 | // |
| 829 | // State: |
| 830 | // |
| 831 | //--------------------------------------------------------------------------- |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 832 | EPLDLLEXPORT unsigned int EplObdGetNodeId(EPL_MCO_DECL_INSTANCE_PTR) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 833 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 834 | tEplKernel Ret; |
| 835 | tEplObdSize ObdSize; |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 836 | u8 bNodeId; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 837 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 838 | bNodeId = 0; |
| 839 | ObdSize = sizeof(bNodeId); |
| 840 | Ret = EplObdReadEntry(EPL_MCO_PTR_INSTANCE_PTR_ |
| 841 | EPL_OBD_NODE_ID_INDEX, |
| 842 | EPL_OBD_NODE_ID_SUBINDEX, &bNodeId, &ObdSize); |
| 843 | if (Ret != kEplSuccessful) { |
| 844 | bNodeId = EPL_C_ADR_INVALID; |
| 845 | goto Exit; |
| 846 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 847 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 848 | Exit: |
| 849 | return (unsigned int)bNodeId; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 850 | |
| 851 | } |
| 852 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 853 | //--------------------------------------------------------------------------- |
| 854 | // |
| 855 | // Function: EplObdSetNodeId() |
| 856 | // |
| 857 | // Description: function sets nodeid in entry 0x1F93 |
| 858 | // |
| 859 | // |
| 860 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = Instancepointer |
| 861 | // uiNodeId_p = Node Id to set |
| 862 | // NodeIdType_p= Type on which way the Node Id was set |
| 863 | // |
| 864 | // Return: tEplKernel = Errorcode |
| 865 | // |
| 866 | // State: |
| 867 | // |
| 868 | //--------------------------------------------------------------------------- |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 869 | EPLDLLEXPORT tEplKernel EplObdSetNodeId(EPL_MCO_DECL_PTR_INSTANCE_PTR_ unsigned int uiNodeId_p, |
| 870 | tEplObdNodeIdType NodeIdType_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 871 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 872 | tEplKernel Ret; |
| 873 | tEplObdSize ObdSize; |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 874 | u8 fHwBool; |
| 875 | u8 bNodeId; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 876 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 877 | // check Node Id |
| 878 | if (uiNodeId_p == EPL_C_ADR_INVALID) { |
| 879 | Ret = kEplInvalidNodeId; |
| 880 | goto Exit; |
| 881 | } |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 882 | bNodeId = (u8) uiNodeId_p; |
| 883 | ObdSize = sizeof(u8); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 884 | // write NodeId to OD entry |
| 885 | Ret = EplObdWriteEntry(EPL_MCO_PTR_INSTANCE_PTR_ |
| 886 | EPL_OBD_NODE_ID_INDEX, |
| 887 | EPL_OBD_NODE_ID_SUBINDEX, &bNodeId, ObdSize); |
| 888 | if (Ret != kEplSuccessful) { |
| 889 | goto Exit; |
| 890 | } |
| 891 | // set HWBOOL-Flag in Subindex EPL_OBD_NODE_ID_HWBOOL_SUBINDEX |
| 892 | switch (NodeIdType_p) { |
| 893 | // type unknown |
| 894 | case kEplObdNodeIdUnknown: |
| 895 | { |
| 896 | fHwBool = OBD_FALSE; |
| 897 | break; |
| 898 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 899 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 900 | case kEplObdNodeIdSoftware: |
| 901 | { |
| 902 | fHwBool = OBD_FALSE; |
| 903 | break; |
| 904 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 905 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 906 | case kEplObdNodeIdHardware: |
| 907 | { |
| 908 | fHwBool = OBD_TRUE; |
| 909 | break; |
| 910 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 911 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 912 | default: |
| 913 | { |
| 914 | fHwBool = OBD_FALSE; |
| 915 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 916 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 917 | } // end of switch (NodeIdType_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 918 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 919 | // write flag |
| 920 | ObdSize = sizeof(fHwBool); |
| 921 | Ret = EplObdWriteEntry(EPL_MCO_PTR_INSTANCE_PTR |
| 922 | EPL_OBD_NODE_ID_INDEX, |
| 923 | EPL_OBD_NODE_ID_HWBOOL_SUBINDEX, |
| 924 | &fHwBool, ObdSize); |
| 925 | if (Ret != kEplSuccessful) { |
| 926 | goto Exit; |
| 927 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 928 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 929 | Exit: |
| 930 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | //--------------------------------------------------------------------------- |
| 934 | // |
| 935 | // Function: EplObdIsNumerical() |
| 936 | // |
| 937 | // Description: function checks if a entry is numerical or not |
| 938 | // |
| 939 | // |
| 940 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = Instancepointer |
| 941 | // uiIndex_p = Index |
| 942 | // uiSubIndex_p = Subindex |
| 943 | // pfEntryNumerical_p = pointer to BOOL for returnvalue |
| 944 | // -> TRUE if entry a numerical value |
| 945 | // -> FALSE if entry not a numerical value |
| 946 | // |
| 947 | // Return: tEplKernel = Errorcode |
| 948 | // |
| 949 | // State: |
| 950 | // |
| 951 | //--------------------------------------------------------------------------- |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 952 | EPLDLLEXPORT tEplKernel EplObdIsNumerical(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p, |
| 953 | unsigned int uiSubIndex_p, |
| 954 | BOOL *pfEntryNumerical_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 955 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 956 | tEplKernel Ret; |
| 957 | tEplObdEntryPtr pObdEntry; |
| 958 | tEplObdSubEntryPtr pObdSubEntry; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 959 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 960 | // get pointer to index structure |
| 961 | Ret = EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam), |
| 962 | uiIndex_p, &pObdEntry); |
| 963 | if (Ret != kEplSuccessful) { |
| 964 | goto Exit; |
| 965 | } |
| 966 | // get pointer to subindex structure |
| 967 | Ret = EplObdGetSubindexIntern(pObdEntry, uiSubIndex_p, &pObdSubEntry); |
| 968 | if (Ret != kEplSuccessful) { |
| 969 | goto Exit; |
| 970 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 971 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 972 | Ret = EplObdIsNumericalIntern(pObdSubEntry, pfEntryNumerical_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 973 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 974 | Exit: |
| 975 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 976 | |
| 977 | } |
| 978 | |
| 979 | //--------------------------------------------------------------------------- |
| 980 | // |
| 981 | // Function: EplObdReadEntryToLe() |
| 982 | // |
| 983 | // Description: The function reads an object entry from the byteoder |
| 984 | // of the system to the little endian byteorder for numerical values. |
| 985 | // For other types a normal read will be processed. This is usefull for |
| 986 | // the PDO and SDO module. The application |
| 987 | // can always read the data even if attrib kEplObdAccRead |
| 988 | // is not set. The attrib is only checked up for SDO transfer. |
| 989 | // |
| 990 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ |
| 991 | // uiIndex_p = Index of the OD entry to read |
| 992 | // uiSubIndex_p = Subindex to read |
| 993 | // pDstData_p = pointer to the buffer for data |
| 994 | // Offset_p = offset in data for read access |
| 995 | // pSize_p = IN: Size of the buffer |
| 996 | // OUT: number of readed Bytes |
| 997 | // |
| 998 | // Return: tEplKernel |
| 999 | // |
| 1000 | // State: |
| 1001 | // |
| 1002 | //--------------------------------------------------------------------------- |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 1003 | EPLDLLEXPORT tEplKernel EplObdReadEntryToLe(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p, |
| 1004 | unsigned int uiSubIndex_p, |
| 1005 | void *pDstData_p, |
| 1006 | tEplObdSize *pSize_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1007 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1008 | tEplKernel Ret; |
| 1009 | tEplObdEntryPtr pObdEntry; |
| 1010 | tEplObdSubEntryPtr pSubEntry; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1011 | tEplObdCbParam CbParam; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1012 | void *pSrcData; |
| 1013 | tEplObdSize ObdSize; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1014 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1015 | // check for all API function if instance is valid |
| 1016 | EPL_MCO_CHECK_INSTANCE_STATE(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1017 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1018 | ASSERT(pDstData_p != NULL); |
| 1019 | ASSERT(pSize_p != NULL); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1020 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1021 | // get address of index and subindex entry |
| 1022 | Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_ |
| 1023 | uiIndex_p, uiSubIndex_p, &pObdEntry, &pSubEntry); |
| 1024 | if (Ret != kEplSuccessful) { |
| 1025 | goto Exit; |
| 1026 | } |
| 1027 | // get pointer to object data |
| 1028 | pSrcData = EplObdGetObjectDataPtrIntern(pSubEntry); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1029 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1030 | // check source pointer |
| 1031 | if (pSrcData == NULL) { |
| 1032 | Ret = kEplObdReadViolation; |
| 1033 | goto Exit; |
| 1034 | } |
| 1035 | //------------------------------------------------------------------------ |
| 1036 | // address of source data to structure of callback parameters |
| 1037 | // so callback function can change this data before reading |
| 1038 | CbParam.m_uiIndex = uiIndex_p; |
| 1039 | CbParam.m_uiSubIndex = uiSubIndex_p; |
| 1040 | CbParam.m_pArg = pSrcData; |
| 1041 | CbParam.m_ObdEvent = kEplObdEvPreRead; |
| 1042 | Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_ |
| 1043 | pObdEntry->m_fpCallback, &CbParam); |
| 1044 | if (Ret != kEplSuccessful) { |
| 1045 | goto Exit; |
| 1046 | } |
| 1047 | // get size of data and check if application has reserved enough memory |
| 1048 | ObdSize = EplObdGetDataSizeIntern(pSubEntry); |
| 1049 | // check if offset given and calc correct number of bytes to read |
| 1050 | if (*pSize_p < ObdSize) { |
| 1051 | Ret = kEplObdValueLengthError; |
| 1052 | goto Exit; |
| 1053 | } |
| 1054 | // check if numerical type |
| 1055 | switch (pSubEntry->m_Type) { |
| 1056 | //----------------------------------------------- |
| 1057 | // types without ami |
| 1058 | case kEplObdTypVString: |
| 1059 | case kEplObdTypOString: |
| 1060 | case kEplObdTypDomain: |
| 1061 | default: |
| 1062 | { |
| 1063 | // read value from object |
| 1064 | EPL_MEMCPY(pDstData_p, pSrcData, ObdSize); |
| 1065 | break; |
| 1066 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1067 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1068 | //----------------------------------------------- |
| 1069 | // numerical type which needs ami-write |
| 1070 | // 8 bit or smaller values |
| 1071 | case kEplObdTypBool: |
| 1072 | case kEplObdTypInt8: |
| 1073 | case kEplObdTypUInt8: |
| 1074 | { |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 1075 | AmiSetByteToLe(pDstData_p, *((u8 *) pSrcData)); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1076 | break; |
| 1077 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1078 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1079 | // 16 bit values |
| 1080 | case kEplObdTypInt16: |
| 1081 | case kEplObdTypUInt16: |
| 1082 | { |
| 1083 | AmiSetWordToLe(pDstData_p, *((WORD *) pSrcData)); |
| 1084 | break; |
| 1085 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1086 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1087 | // 24 bit values |
| 1088 | case kEplObdTypInt24: |
| 1089 | case kEplObdTypUInt24: |
| 1090 | { |
Greg Kroah-Hartman | d539cfb | 2009-03-23 12:51:37 -0700 | [diff] [blame^] | 1091 | AmiSetDword24ToLe(pDstData_p, *((u32 *) pSrcData)); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1092 | break; |
| 1093 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1094 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1095 | // 32 bit values |
| 1096 | case kEplObdTypInt32: |
| 1097 | case kEplObdTypUInt32: |
| 1098 | case kEplObdTypReal32: |
| 1099 | { |
Greg Kroah-Hartman | d539cfb | 2009-03-23 12:51:37 -0700 | [diff] [blame^] | 1100 | AmiSetDwordToLe(pDstData_p, *((u32 *) pSrcData)); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1101 | break; |
| 1102 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1103 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1104 | // 40 bit values |
| 1105 | case kEplObdTypInt40: |
| 1106 | case kEplObdTypUInt40: |
| 1107 | { |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1108 | AmiSetQword40ToLe(pDstData_p, *((u64 *) pSrcData)); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1109 | break; |
| 1110 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1111 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1112 | // 48 bit values |
| 1113 | case kEplObdTypInt48: |
| 1114 | case kEplObdTypUInt48: |
| 1115 | { |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1116 | AmiSetQword48ToLe(pDstData_p, *((u64 *) pSrcData)); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1117 | break; |
| 1118 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1119 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1120 | // 56 bit values |
| 1121 | case kEplObdTypInt56: |
| 1122 | case kEplObdTypUInt56: |
| 1123 | { |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1124 | AmiSetQword56ToLe(pDstData_p, *((u64 *) pSrcData)); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1125 | break; |
| 1126 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1127 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1128 | // 64 bit values |
| 1129 | case kEplObdTypInt64: |
| 1130 | case kEplObdTypUInt64: |
| 1131 | case kEplObdTypReal64: |
| 1132 | { |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1133 | AmiSetQword64ToLe(pDstData_p, *((u64 *) pSrcData)); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1134 | break; |
| 1135 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1136 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1137 | // time of day |
| 1138 | case kEplObdTypTimeOfDay: |
| 1139 | case kEplObdTypTimeDiff: |
| 1140 | { |
| 1141 | AmiSetTimeOfDay(pDstData_p, ((tTimeOfDay *) pSrcData)); |
| 1142 | break; |
| 1143 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1144 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1145 | } // end of switch(pSubEntry->m_Type) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1146 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1147 | *pSize_p = ObdSize; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1148 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1149 | // write address of destination data to structure of callback parameters |
| 1150 | // so callback function can change this data after reading |
| 1151 | CbParam.m_pArg = pDstData_p; |
| 1152 | CbParam.m_ObdEvent = kEplObdEvPostRead; |
| 1153 | Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_ |
| 1154 | pObdEntry->m_fpCallback, &CbParam); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1155 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1156 | Exit: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1157 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1158 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1159 | |
| 1160 | } |
| 1161 | |
| 1162 | //--------------------------------------------------------------------------- |
| 1163 | // |
| 1164 | // Function: EplObdWriteEntryFromLe() |
| 1165 | // |
| 1166 | // Description: Function writes data to an OBD entry from a source with |
| 1167 | // little endian byteorder to the od with system specuific |
| 1168 | // byteorder. Not numerical values will only by copied. Strings |
| 1169 | // are stored with added '\0' character. |
| 1170 | // |
| 1171 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ |
| 1172 | // uiIndex_p = Index of the OD entry |
| 1173 | // uiSubIndex_p = Subindex of the OD Entry |
| 1174 | // pSrcData_p = Pointer to the data to write |
| 1175 | // Size_p = Size of the data in Byte |
| 1176 | // |
| 1177 | // Return: tEplKernel = Errorcode |
| 1178 | // |
| 1179 | // |
| 1180 | // State: |
| 1181 | // |
| 1182 | //--------------------------------------------------------------------------- |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 1183 | EPLDLLEXPORT tEplKernel EplObdWriteEntryFromLe(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p, |
| 1184 | unsigned int uiSubIndex_p, |
| 1185 | void *pSrcData_p, |
| 1186 | tEplObdSize Size_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1187 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1188 | tEplKernel Ret; |
| 1189 | tEplObdEntryPtr pObdEntry; |
| 1190 | tEplObdSubEntryPtr pSubEntry; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1191 | tEplObdCbParam CbParam; |
| 1192 | void *pDstData; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1193 | tEplObdSize ObdSize; |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1194 | u64 qwBuffer; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1195 | void *pBuffer = &qwBuffer; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1196 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1197 | Ret = EplObdWriteEntryPre(EPL_MCO_INSTANCE_PTR_ |
| 1198 | uiIndex_p, |
| 1199 | uiSubIndex_p, |
| 1200 | pSrcData_p, |
| 1201 | &pDstData, |
| 1202 | Size_p, |
| 1203 | &pObdEntry, &pSubEntry, &CbParam, &ObdSize); |
| 1204 | if (Ret != kEplSuccessful) { |
| 1205 | goto Exit; |
| 1206 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1207 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1208 | // check if numerical type |
| 1209 | switch (pSubEntry->m_Type) { |
| 1210 | //----------------------------------------------- |
| 1211 | // types without ami |
| 1212 | default: |
| 1213 | { // do nothing, i.e. use the given source pointer |
| 1214 | pBuffer = pSrcData_p; |
| 1215 | break; |
| 1216 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1217 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1218 | //----------------------------------------------- |
| 1219 | // numerical type which needs ami-write |
| 1220 | // 8 bit or smaller values |
| 1221 | case kEplObdTypBool: |
| 1222 | case kEplObdTypInt8: |
| 1223 | case kEplObdTypUInt8: |
| 1224 | { |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 1225 | *((u8 *) pBuffer) = AmiGetByteFromLe(pSrcData_p); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1226 | break; |
| 1227 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1228 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1229 | // 16 bit values |
| 1230 | case kEplObdTypInt16: |
| 1231 | case kEplObdTypUInt16: |
| 1232 | { |
| 1233 | *((WORD *) pBuffer) = AmiGetWordFromLe(pSrcData_p); |
| 1234 | break; |
| 1235 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1236 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1237 | // 24 bit values |
| 1238 | case kEplObdTypInt24: |
| 1239 | case kEplObdTypUInt24: |
| 1240 | { |
Greg Kroah-Hartman | d539cfb | 2009-03-23 12:51:37 -0700 | [diff] [blame^] | 1241 | *((u32 *) pBuffer) = AmiGetDword24FromLe(pSrcData_p); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1242 | break; |
| 1243 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1244 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1245 | // 32 bit values |
| 1246 | case kEplObdTypInt32: |
| 1247 | case kEplObdTypUInt32: |
| 1248 | case kEplObdTypReal32: |
| 1249 | { |
Greg Kroah-Hartman | d539cfb | 2009-03-23 12:51:37 -0700 | [diff] [blame^] | 1250 | *((u32 *) pBuffer) = AmiGetDwordFromLe(pSrcData_p); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1251 | break; |
| 1252 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1253 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1254 | // 40 bit values |
| 1255 | case kEplObdTypInt40: |
| 1256 | case kEplObdTypUInt40: |
| 1257 | { |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1258 | *((u64 *) pBuffer) = AmiGetQword40FromLe(pSrcData_p); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1259 | break; |
| 1260 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1261 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1262 | // 48 bit values |
| 1263 | case kEplObdTypInt48: |
| 1264 | case kEplObdTypUInt48: |
| 1265 | { |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1266 | *((u64 *) pBuffer) = AmiGetQword48FromLe(pSrcData_p); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1267 | break; |
| 1268 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1269 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1270 | // 56 bit values |
| 1271 | case kEplObdTypInt56: |
| 1272 | case kEplObdTypUInt56: |
| 1273 | { |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1274 | *((u64 *) pBuffer) = AmiGetQword56FromLe(pSrcData_p); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1275 | break; |
| 1276 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1277 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1278 | // 64 bit values |
| 1279 | case kEplObdTypInt64: |
| 1280 | case kEplObdTypUInt64: |
| 1281 | case kEplObdTypReal64: |
| 1282 | { |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1283 | *((u64 *) pBuffer) = AmiGetQword64FromLe(pSrcData_p); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1284 | break; |
| 1285 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1286 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1287 | // time of day |
| 1288 | case kEplObdTypTimeOfDay: |
| 1289 | case kEplObdTypTimeDiff: |
| 1290 | { |
| 1291 | AmiGetTimeOfDay(pBuffer, ((tTimeOfDay *) pSrcData_p)); |
| 1292 | break; |
| 1293 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1294 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1295 | } // end of switch(pSubEntry->m_Type) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1296 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1297 | Ret = EplObdWriteEntryPost(EPL_MCO_INSTANCE_PTR_ |
| 1298 | pObdEntry, |
| 1299 | pSubEntry, |
| 1300 | &CbParam, pBuffer, pDstData, ObdSize); |
| 1301 | if (Ret != kEplSuccessful) { |
| 1302 | goto Exit; |
| 1303 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1304 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1305 | Exit: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1306 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1307 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1308 | |
| 1309 | } |
| 1310 | |
| 1311 | //--------------------------------------------------------------------------- |
| 1312 | // |
| 1313 | // Function: EplObdGetAccessType() |
| 1314 | // |
| 1315 | // Description: Function returns accesstype of the entry |
| 1316 | // |
| 1317 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ |
| 1318 | // uiIndex_p = Index of the OD entry |
| 1319 | // uiSubIndex_p = Subindex of the OD Entry |
| 1320 | // pAccessTyp_p = pointer to buffer to store accesstype |
| 1321 | // |
| 1322 | // Return: tEplKernel = errorcode |
| 1323 | // |
| 1324 | // |
| 1325 | // State: |
| 1326 | // |
| 1327 | //--------------------------------------------------------------------------- |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 1328 | EPLDLLEXPORT tEplKernel EplObdGetAccessType(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p, |
| 1329 | unsigned int uiSubIndex_p, |
| 1330 | tEplObdAccess *pAccessTyp_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1331 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1332 | tEplKernel Ret; |
| 1333 | tEplObdEntryPtr pObdEntry; |
| 1334 | tEplObdSubEntryPtr pObdSubEntry; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1335 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1336 | // get pointer to index structure |
| 1337 | Ret = EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam), |
| 1338 | uiIndex_p, &pObdEntry); |
| 1339 | if (Ret != kEplSuccessful) { |
| 1340 | goto Exit; |
| 1341 | } |
| 1342 | // get pointer to subindex structure |
| 1343 | Ret = EplObdGetSubindexIntern(pObdEntry, uiSubIndex_p, &pObdSubEntry); |
| 1344 | if (Ret != kEplSuccessful) { |
| 1345 | goto Exit; |
| 1346 | } |
| 1347 | // get accessType |
| 1348 | *pAccessTyp_p = pObdSubEntry->m_Access; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1349 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1350 | Exit: |
| 1351 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | //--------------------------------------------------------------------------- |
| 1355 | // |
| 1356 | // Function: EplObdSearchVarEntry() |
| 1357 | // |
| 1358 | // Description: gets variable from OD |
| 1359 | // |
| 1360 | // Parameters: uiIndex_p = index of the var entry to search |
| 1361 | // uiSubindex_p = subindex of var entry to search |
| 1362 | // ppVarEntry_p = pointer to the pointer to the varentry |
| 1363 | // |
| 1364 | // Return: tEplKernel |
| 1365 | // |
| 1366 | // State: |
| 1367 | // |
| 1368 | //--------------------------------------------------------------------------- |
| 1369 | |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 1370 | tEplKernel EplObdSearchVarEntry(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p, |
| 1371 | unsigned int uiSubindex_p, |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1372 | tEplObdVarEntry **ppVarEntry_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1373 | { |
| 1374 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1375 | tEplKernel Ret; |
| 1376 | tEplObdSubEntryPtr pSubindexEntry; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1377 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1378 | // check for all API function if instance is valid |
| 1379 | EPL_MCO_CHECK_INSTANCE_STATE(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1380 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1381 | // get address of subindex entry |
| 1382 | Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_ |
| 1383 | uiIndex_p, uiSubindex_p, NULL, &pSubindexEntry); |
| 1384 | if (Ret == kEplSuccessful) { |
| 1385 | // get var entry |
| 1386 | Ret = EplObdGetVarEntry(pSubindexEntry, ppVarEntry_p); |
| 1387 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1388 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1389 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1390 | |
| 1391 | } |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1392 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1393 | //=========================================================================// |
| 1394 | // // |
| 1395 | // P R I V A T E D E F I N I T I O N S // |
| 1396 | // // |
| 1397 | //=========================================================================// |
| 1398 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1399 | EPL_MCO_DECL_INSTANCE_FCT() |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1400 | //--------------------------------------------------------------------------- |
| 1401 | // |
| 1402 | // Function: EplObdCallObjectCallback() |
| 1403 | // |
| 1404 | // Description: calls callback function of an object or of a variable |
| 1405 | // |
| 1406 | // Parameters: fpCallback_p |
| 1407 | // pCbParam_p |
| 1408 | // |
| 1409 | // Return: tEplKernel |
| 1410 | // |
| 1411 | // State: |
| 1412 | // |
| 1413 | //--------------------------------------------------------------------------- |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1414 | static tEplKernel EplObdCallObjectCallback(EPL_MCO_DECL_INSTANCE_PTR_ |
| 1415 | tEplObdCallback fpCallback_p, |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1416 | tEplObdCbParam *pCbParam_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1417 | { |
| 1418 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1419 | tEplKernel Ret; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1420 | tEplObdCallback fpCallback; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1421 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1422 | // check for all API function if instance is valid |
| 1423 | EPL_MCO_CHECK_INSTANCE_STATE(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1424 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1425 | ASSERT(pCbParam_p != NULL); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1426 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1427 | Ret = kEplSuccessful; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1428 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1429 | // check address of callback function before calling it |
| 1430 | if (fpCallback_p != NULL) { |
| 1431 | // KEIL C51 V6.01 has a bug. |
| 1432 | // Therefore the parameter fpCallback_p has to be copied in local variable fpCallback. |
| 1433 | fpCallback = fpCallback_p; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1434 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1435 | // call callback function for this object |
| 1436 | Ret = fpCallback(EPL_MCO_INSTANCE_PARAM_IDX_() |
| 1437 | pCbParam_p); |
| 1438 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1439 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1440 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | //--------------------------------------------------------------------------- |
| 1444 | // |
| 1445 | // Function: EplObdGetDataSizeIntern() |
| 1446 | // |
| 1447 | // Description: gets the data size of an object |
| 1448 | // for string objects it returnes the string length |
| 1449 | // |
| 1450 | // Parameters: pSubIndexEntry_p |
| 1451 | // |
| 1452 | // Return: tEplObdSize |
| 1453 | // |
| 1454 | // State: |
| 1455 | // |
| 1456 | //--------------------------------------------------------------------------- |
| 1457 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1458 | static tEplObdSize EplObdGetDataSizeIntern(tEplObdSubEntryPtr pSubIndexEntry_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1459 | { |
| 1460 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1461 | tEplObdSize DataSize; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1462 | void *pData; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1463 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1464 | // If OD entry is defined by macro EPL_OBD_SUBINDEX_ROM_VSTRING |
| 1465 | // then the current pointer is always NULL. The function |
| 1466 | // returns the length of default string. |
| 1467 | DataSize = EplObdGetObjectSize(pSubIndexEntry_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1468 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1469 | if (pSubIndexEntry_p->m_Type == kEplObdTypVString) { |
| 1470 | // The pointer to current value can be received from EplObdGetObjectCurrentPtr() |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1471 | pData = ((void *)EplObdGetObjectCurrentPtr(pSubIndexEntry_p)); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1472 | if (pData != NULL) { |
| 1473 | DataSize = |
| 1474 | EplObdGetStrLen((void *)pData, DataSize, |
| 1475 | pSubIndexEntry_p->m_Type); |
| 1476 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1477 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1478 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1479 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1480 | return DataSize; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1481 | |
| 1482 | } |
| 1483 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1484 | //--------------------------------------------------------------------------- |
| 1485 | // |
| 1486 | // Function: EplObdGetStrLen() |
| 1487 | // |
| 1488 | // Description: The function calculates the length of string. The '\0' |
| 1489 | // character is included!! |
| 1490 | // |
| 1491 | // Parameters: pObjData_p = pointer to string |
| 1492 | // ObjLen_p = max. length of objectr entry |
| 1493 | // bObjType_p = object type (VSTRING, ...) |
| 1494 | // |
| 1495 | // Returns: string length + 1 |
| 1496 | // |
| 1497 | // State: |
| 1498 | // |
| 1499 | //--------------------------------------------------------------------------- |
| 1500 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1501 | static tEplObdSize EplObdGetStrLen(void *pObjData_p, |
| 1502 | tEplObdSize ObjLen_p, tEplObdType ObjType_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1503 | { |
| 1504 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1505 | tEplObdSize StrLen = 0; |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 1506 | u8 *pbString; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1507 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1508 | if (pObjData_p == NULL) { |
| 1509 | goto Exit; |
| 1510 | } |
| 1511 | //---------------------------------------- |
| 1512 | // Visible String: data format byte |
| 1513 | if (ObjType_p == kEplObdTypVString) { |
| 1514 | pbString = pObjData_p; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1515 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1516 | for (StrLen = 0; StrLen < ObjLen_p; StrLen++) { |
| 1517 | if (*pbString == '\0') { |
| 1518 | StrLen++; |
| 1519 | break; |
| 1520 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1521 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1522 | pbString++; |
| 1523 | } |
| 1524 | } |
| 1525 | //---------------------------------------- |
| 1526 | // other string types ... |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1527 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1528 | Exit: |
| 1529 | return (StrLen); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1530 | |
| 1531 | } |
| 1532 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1533 | #if (EPL_OBD_CHECK_OBJECT_RANGE != FALSE) |
| 1534 | |
| 1535 | //--------------------------------------------------------------------------- |
| 1536 | // |
| 1537 | // Function: EplObdCheckObjectRange() |
| 1538 | // |
| 1539 | // Description: function to check value range of object data |
| 1540 | // |
| 1541 | // NOTICE: The pointer of data (pData_p) must point out to an even address, |
| 1542 | // if ObjType is unequal to kEplObdTypInt8 or kEplObdTypUInt8! But it is |
| 1543 | // always realiced because pointer m_pDefault points always to an |
| 1544 | // array of the SPECIFIED type. |
| 1545 | // |
| 1546 | // Parameters: pSubindexEntry_p |
| 1547 | // pData_p |
| 1548 | // |
| 1549 | // Return: tEplKernel |
| 1550 | // |
| 1551 | // State: |
| 1552 | // |
| 1553 | //--------------------------------------------------------------------------- |
| 1554 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1555 | static tEplKernel EplObdCheckObjectRange(tEplObdSubEntryPtr pSubindexEntry_p, |
| 1556 | void *pData_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1557 | { |
| 1558 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1559 | tEplKernel Ret; |
| 1560 | void *pRangeData; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1561 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1562 | ASSERTMSG(pSubindexEntry_p != NULL, |
| 1563 | "EplObdCheckObjectRange(): no address to subindex struct!\n"); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1564 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1565 | Ret = kEplSuccessful; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1566 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1567 | // check if data range has to be checked |
| 1568 | if ((pSubindexEntry_p->m_Access & kEplObdAccRange) == 0) { |
| 1569 | goto Exit; |
| 1570 | } |
| 1571 | // get address of default data |
| 1572 | pRangeData = pSubindexEntry_p->m_pDefault; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1573 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1574 | // jump to called object type |
| 1575 | switch ((tEplObdType) pSubindexEntry_p->m_Type) { |
| 1576 | // ----------------------------------------------------------------- |
| 1577 | // ObdType kEplObdTypBool will not be checked because there are only |
| 1578 | // two possible values 0 or 1. |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1579 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1580 | // ----------------------------------------------------------------- |
| 1581 | // ObdTypes which has to be check up because numerical values |
| 1582 | case kEplObdTypInt8: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1583 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1584 | // switch to lower limit |
| 1585 | pRangeData = ((tEplObdInteger8 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1586 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1587 | // check if value is to low |
| 1588 | if (*((tEplObdInteger8 *) pData_p) < |
| 1589 | *((tEplObdInteger8 *) pRangeData)) { |
| 1590 | Ret = kEplObdValueTooLow; |
| 1591 | break; |
| 1592 | } |
| 1593 | // switch to higher limit |
| 1594 | pRangeData = ((tEplObdInteger8 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1595 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1596 | // check if value is to high |
| 1597 | if (*((tEplObdInteger8 *) pData_p) > |
| 1598 | *((tEplObdInteger8 *) pRangeData)) { |
| 1599 | Ret = kEplObdValueTooHigh; |
| 1600 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1601 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1602 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1603 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1604 | case kEplObdTypUInt8: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1605 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1606 | // switch to lower limit |
| 1607 | pRangeData = ((tEplObdUnsigned8 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1608 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1609 | // check if value is to low |
| 1610 | if (*((tEplObdUnsigned8 *) pData_p) < |
| 1611 | *((tEplObdUnsigned8 *) pRangeData)) { |
| 1612 | Ret = kEplObdValueTooLow; |
| 1613 | break; |
| 1614 | } |
| 1615 | // switch to higher limit |
| 1616 | pRangeData = ((tEplObdUnsigned8 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1617 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1618 | // check if value is to high |
| 1619 | if (*((tEplObdUnsigned8 *) pData_p) > |
| 1620 | *((tEplObdUnsigned8 *) pRangeData)) { |
| 1621 | Ret = kEplObdValueTooHigh; |
| 1622 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1623 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1624 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1625 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1626 | case kEplObdTypInt16: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1627 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1628 | // switch to lower limit |
| 1629 | pRangeData = ((tEplObdInteger16 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1630 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1631 | // check if value is to low |
| 1632 | if (*((tEplObdInteger16 *) pData_p) < |
| 1633 | *((tEplObdInteger16 *) pRangeData)) { |
| 1634 | Ret = kEplObdValueTooLow; |
| 1635 | break; |
| 1636 | } |
| 1637 | // switch to higher limit |
| 1638 | pRangeData = ((tEplObdInteger16 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1639 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1640 | // check if value is to high |
| 1641 | if (*((tEplObdInteger16 *) pData_p) > |
| 1642 | *((tEplObdInteger16 *) pRangeData)) { |
| 1643 | Ret = kEplObdValueTooHigh; |
| 1644 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1645 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1646 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1647 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1648 | case kEplObdTypUInt16: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1649 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1650 | // switch to lower limit |
| 1651 | pRangeData = ((tEplObdUnsigned16 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1652 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1653 | // check if value is to low |
| 1654 | if (*((tEplObdUnsigned16 *) pData_p) < |
| 1655 | *((tEplObdUnsigned16 *) pRangeData)) { |
| 1656 | Ret = kEplObdValueTooLow; |
| 1657 | break; |
| 1658 | } |
| 1659 | // switch to higher limit |
| 1660 | pRangeData = ((tEplObdUnsigned16 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1661 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1662 | // check if value is to high |
| 1663 | if (*((tEplObdUnsigned16 *) pData_p) > |
| 1664 | *((tEplObdUnsigned16 *) pRangeData)) { |
| 1665 | Ret = kEplObdValueTooHigh; |
| 1666 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1667 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1668 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1669 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1670 | case kEplObdTypInt32: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1671 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1672 | // switch to lower limit |
| 1673 | pRangeData = ((tEplObdInteger32 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1674 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1675 | // check if value is to low |
| 1676 | if (*((tEplObdInteger32 *) pData_p) < |
| 1677 | *((tEplObdInteger32 *) pRangeData)) { |
| 1678 | Ret = kEplObdValueTooLow; |
| 1679 | break; |
| 1680 | } |
| 1681 | // switch to higher limit |
| 1682 | pRangeData = ((tEplObdInteger32 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1683 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1684 | // check if value is to high |
| 1685 | if (*((tEplObdInteger32 *) pData_p) > |
| 1686 | *((tEplObdInteger32 *) pRangeData)) { |
| 1687 | Ret = kEplObdValueTooHigh; |
| 1688 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1689 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1690 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1691 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1692 | case kEplObdTypUInt32: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1693 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1694 | // switch to lower limit |
| 1695 | pRangeData = ((tEplObdUnsigned32 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1696 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1697 | // check if value is to low |
| 1698 | if (*((tEplObdUnsigned32 *) pData_p) < |
| 1699 | *((tEplObdUnsigned32 *) pRangeData)) { |
| 1700 | Ret = kEplObdValueTooLow; |
| 1701 | break; |
| 1702 | } |
| 1703 | // switch to higher limit |
| 1704 | pRangeData = ((tEplObdUnsigned32 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1705 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1706 | // check if value is to high |
| 1707 | if (*((tEplObdUnsigned32 *) pData_p) > |
| 1708 | *((tEplObdUnsigned32 *) pRangeData)) { |
| 1709 | Ret = kEplObdValueTooHigh; |
| 1710 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1711 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1712 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1713 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1714 | case kEplObdTypReal32: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1715 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1716 | // switch to lower limit |
| 1717 | pRangeData = ((tEplObdReal32 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1718 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1719 | // check if value is to low |
| 1720 | if (*((tEplObdReal32 *) pData_p) < |
| 1721 | *((tEplObdReal32 *) pRangeData)) { |
| 1722 | Ret = kEplObdValueTooLow; |
| 1723 | break; |
| 1724 | } |
| 1725 | // switch to higher limit |
| 1726 | pRangeData = ((tEplObdReal32 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1727 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1728 | // check if value is to high |
| 1729 | if (*((tEplObdReal32 *) pData_p) > |
| 1730 | *((tEplObdReal32 *) pRangeData)) { |
| 1731 | Ret = kEplObdValueTooHigh; |
| 1732 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1733 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1734 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1735 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1736 | // ----------------------------------------------------------------- |
| 1737 | case kEplObdTypInt40: |
| 1738 | case kEplObdTypInt48: |
| 1739 | case kEplObdTypInt56: |
| 1740 | case kEplObdTypInt64: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1741 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1742 | // switch to lower limit |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1743 | pRangeData = ((signed u64 *)pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1744 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1745 | // check if value is to low |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1746 | if (*((signed u64 *)pData_p) < *((signed u64 *)pRangeData)) { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1747 | Ret = kEplObdValueTooLow; |
| 1748 | break; |
| 1749 | } |
| 1750 | // switch to higher limit |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1751 | pRangeData = ((signed u64 *)pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1752 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1753 | // check if value is to high |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1754 | if (*((signed u64 *)pData_p) > *((signed u64 *)pRangeData)) { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1755 | Ret = kEplObdValueTooHigh; |
| 1756 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1757 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1758 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1759 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1760 | // ----------------------------------------------------------------- |
| 1761 | case kEplObdTypUInt40: |
| 1762 | case kEplObdTypUInt48: |
| 1763 | case kEplObdTypUInt56: |
| 1764 | case kEplObdTypUInt64: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1765 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1766 | // switch to lower limit |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1767 | pRangeData = ((unsigned u64 *)pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1768 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1769 | // check if value is to low |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1770 | if (*((unsigned u64 *)pData_p) < |
| 1771 | *((unsigned u64 *)pRangeData)) { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1772 | Ret = kEplObdValueTooLow; |
| 1773 | break; |
| 1774 | } |
| 1775 | // switch to higher limit |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1776 | pRangeData = ((unsigned u64 *)pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1777 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1778 | // check if value is to high |
Greg Kroah-Hartman | a5c30d9 | 2009-03-23 12:43:05 -0700 | [diff] [blame] | 1779 | if (*((unsigned u64 *)pData_p) > |
| 1780 | *((unsigned u64 *)pRangeData)) { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1781 | Ret = kEplObdValueTooHigh; |
| 1782 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1783 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1784 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1785 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1786 | // ----------------------------------------------------------------- |
| 1787 | case kEplObdTypReal64: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1788 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1789 | // switch to lower limit |
| 1790 | pRangeData = ((tEplObdReal64 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1791 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1792 | // check if value is to low |
| 1793 | if (*((tEplObdReal64 *) pData_p) < |
| 1794 | *((tEplObdReal64 *) pRangeData)) { |
| 1795 | Ret = kEplObdValueTooLow; |
| 1796 | break; |
| 1797 | } |
| 1798 | // switch to higher limit |
| 1799 | pRangeData = ((tEplObdReal64 *) pRangeData) + 1; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1800 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1801 | // check if value is to high |
| 1802 | if (*((tEplObdReal64 *) pData_p) > |
| 1803 | *((tEplObdReal64 *) pRangeData)) { |
| 1804 | Ret = kEplObdValueTooHigh; |
| 1805 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1806 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1807 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1808 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1809 | // ----------------------------------------------------------------- |
| 1810 | case kEplObdTypTimeOfDay: |
| 1811 | case kEplObdTypTimeDiff: |
| 1812 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1813 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1814 | // ----------------------------------------------------------------- |
| 1815 | // ObdTypes kEplObdTypXString and kEplObdTypDomain can not be checkt because |
| 1816 | // they have no numerical value. |
| 1817 | default: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1818 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1819 | Ret = kEplObdUnknownObjectType; |
| 1820 | break; |
| 1821 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1822 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1823 | Exit: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1824 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1825 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1826 | |
| 1827 | } |
| 1828 | #endif // (EPL_OBD_CHECK_OBJECT_RANGE != FALSE) |
| 1829 | |
| 1830 | //--------------------------------------------------------------------------- |
| 1831 | // |
| 1832 | // Function: EplObdWriteEntryPre() |
| 1833 | // |
| 1834 | // Description: Function prepares write of data to an OBD entry. Strings |
| 1835 | // are stored with added '\0' character. |
| 1836 | // |
| 1837 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ |
| 1838 | // uiIndex_p = Index of the OD entry |
| 1839 | // uiSubIndex_p = Subindex of the OD Entry |
| 1840 | // pSrcData_p = Pointer to the data to write |
| 1841 | // Size_p = Size of the data in Byte |
| 1842 | // |
| 1843 | // Return: tEplKernel = Errorcode |
| 1844 | // |
| 1845 | // |
| 1846 | // State: |
| 1847 | // |
| 1848 | //--------------------------------------------------------------------------- |
| 1849 | |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 1850 | static tEplKernel EplObdWriteEntryPre(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p, |
| 1851 | unsigned int uiSubIndex_p, |
| 1852 | void *pSrcData_p, |
| 1853 | void **ppDstData_p, |
| 1854 | tEplObdSize Size_p, |
| 1855 | tEplObdEntryPtr *ppObdEntry_p, |
| 1856 | tEplObdSubEntryPtr *ppSubEntry_p, |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1857 | tEplObdCbParam *pCbParam_p, |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 1858 | tEplObdSize *pObdSize_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1859 | { |
| 1860 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1861 | tEplKernel Ret; |
| 1862 | tEplObdEntryPtr pObdEntry; |
| 1863 | tEplObdSubEntryPtr pSubEntry; |
| 1864 | tEplObdAccess Access; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1865 | void *pDstData; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1866 | tEplObdSize ObdSize; |
| 1867 | BOOL fEntryNumerical; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1868 | |
| 1869 | #if (EPL_OBD_USE_STRING_DOMAIN_IN_RAM != FALSE) |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1870 | tEplObdVStringDomain MemVStringDomain; |
| 1871 | void *pCurrData; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1872 | #endif |
| 1873 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1874 | // check for all API function if instance is valid |
| 1875 | EPL_MCO_CHECK_INSTANCE_STATE(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1876 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1877 | ASSERT(pSrcData_p != NULL); // should never be NULL |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1878 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1879 | //------------------------------------------------------------------------ |
| 1880 | // get address of index and subindex entry |
| 1881 | Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_ |
| 1882 | uiIndex_p, uiSubIndex_p, &pObdEntry, &pSubEntry); |
| 1883 | if (Ret != kEplSuccessful) { |
| 1884 | goto Exit; |
| 1885 | } |
| 1886 | // get pointer to object data |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1887 | pDstData = (void *)EplObdGetObjectDataPtrIntern(pSubEntry); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1888 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1889 | Access = (tEplObdAccess) pSubEntry->m_Access; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1890 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1891 | // check access for write |
| 1892 | // access violation if adress to current value is NULL |
| 1893 | if (((Access & kEplObdAccConst) != 0) || (pDstData == NULL)) { |
| 1894 | Ret = kEplObdAccessViolation; |
| 1895 | goto Exit; |
| 1896 | } |
| 1897 | //------------------------------------------------------------------------ |
| 1898 | // get size of object |
| 1899 | // -as ObdSize = ObdGetObjectSize (pSubEntry); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1900 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1901 | //------------------------------------------------------------------------ |
| 1902 | // To use the same callback function for ObdWriteEntry as well as for |
| 1903 | // an SDO download call at first (kEplObdEvPre...) the callback function |
| 1904 | // with the argument pointer to object size. |
| 1905 | pCbParam_p->m_uiIndex = uiIndex_p; |
| 1906 | pCbParam_p->m_uiSubIndex = uiSubIndex_p; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1907 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1908 | // Because object size and object pointer are |
| 1909 | // adapted by user callback function, re-read |
| 1910 | // this values. |
| 1911 | ObdSize = EplObdGetObjectSize(pSubEntry); |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1912 | pDstData = (void *)EplObdGetObjectDataPtrIntern(pSubEntry); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1913 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1914 | // 09-dec-2004 r.d.: |
| 1915 | // Function EplObdWriteEntry() calls new event kEplObdEvWrStringDomain |
| 1916 | // for String or Domain which lets called module directly change |
| 1917 | // the data pointer or size. This prevents a recursive call to |
| 1918 | // the callback function if it calls EplObdGetEntry(). |
| 1919 | #if (EPL_OBD_USE_STRING_DOMAIN_IN_RAM != FALSE) |
| 1920 | if ((pSubEntry->m_Type == kEplObdTypVString) || |
| 1921 | (pSubEntry->m_Type == kEplObdTypDomain) || |
| 1922 | (pSubEntry->m_Type == kEplObdTypOString)) { |
| 1923 | if (pSubEntry->m_Type == kEplObdTypVString) { |
| 1924 | // reserve one byte for 0-termination |
| 1925 | // -as ObdSize -= 1; |
| 1926 | Size_p += 1; |
| 1927 | } |
| 1928 | // fill out new arg-struct |
| 1929 | MemVStringDomain.m_DownloadSize = Size_p; |
| 1930 | MemVStringDomain.m_ObjSize = ObdSize; |
| 1931 | MemVStringDomain.m_pData = pDstData; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1932 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1933 | pCbParam_p->m_ObdEvent = kEplObdEvWrStringDomain; |
| 1934 | pCbParam_p->m_pArg = &MemVStringDomain; |
| 1935 | // call user callback |
| 1936 | Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_ |
| 1937 | pObdEntry->m_fpCallback, |
| 1938 | pCbParam_p); |
| 1939 | if (Ret != kEplSuccessful) { |
| 1940 | goto Exit; |
| 1941 | } |
| 1942 | // write back new settings |
| 1943 | pCurrData = pSubEntry->m_pCurrent; |
| 1944 | if ((pSubEntry->m_Type == kEplObdTypVString) |
| 1945 | || (pSubEntry->m_Type == kEplObdTypOString)) { |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1946 | ((tEplObdVString *)pCurrData)->m_Size = MemVStringDomain.m_ObjSize; |
| 1947 | ((tEplObdVString *)pCurrData)->m_pString = MemVStringDomain.m_pData; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1948 | } else // if (pSdosTableEntry_p->m_bObjType == kEplObdTypDomain) |
| 1949 | { |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1950 | ((tEplObdVarEntry *)pCurrData)->m_Size = MemVStringDomain.m_ObjSize; |
| 1951 | ((tEplObdVarEntry *)pCurrData)->m_pData = (void *)MemVStringDomain.m_pData; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1952 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1953 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1954 | // Because object size and object pointer are |
| 1955 | // adapted by user callback function, re-read |
| 1956 | // this values. |
| 1957 | ObdSize = MemVStringDomain.m_ObjSize; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1958 | pDstData = (void *)MemVStringDomain.m_pData; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1959 | } |
| 1960 | #endif //#if (OBD_USE_STRING_DOMAIN_IN_RAM != FALSE) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1961 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1962 | // 07-dec-2004 r.d.: size from application is needed because callback function can change the object size |
| 1963 | // -as 16.11.04 CbParam.m_pArg = &ObdSize; |
| 1964 | // 09-dec-2004 r.d.: CbParam.m_pArg = &Size_p; |
| 1965 | pCbParam_p->m_pArg = &ObdSize; |
| 1966 | pCbParam_p->m_ObdEvent = kEplObdEvInitWrite; |
| 1967 | Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_ |
| 1968 | pObdEntry->m_fpCallback, pCbParam_p); |
| 1969 | if (Ret != kEplSuccessful) { |
| 1970 | goto Exit; |
| 1971 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1972 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1973 | if (Size_p > ObdSize) { |
| 1974 | Ret = kEplObdValueLengthError; |
| 1975 | goto Exit; |
| 1976 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1977 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1978 | if (pSubEntry->m_Type == kEplObdTypVString) { |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 1979 | if (((char *)pSrcData_p)[Size_p - 1] == '\0') { // last byte of source string contains null character |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1980 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1981 | // reserve one byte in destination for 0-termination |
| 1982 | Size_p -= 1; |
| 1983 | } else if (Size_p >= ObdSize) { // source string is not 0-terminated |
| 1984 | // and destination buffer is too short |
| 1985 | Ret = kEplObdValueLengthError; |
| 1986 | goto Exit; |
| 1987 | } |
| 1988 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1989 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1990 | Ret = EplObdIsNumericalIntern(pSubEntry, &fEntryNumerical); |
| 1991 | if (Ret != kEplSuccessful) { |
| 1992 | goto Exit; |
| 1993 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 1994 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 1995 | if ((fEntryNumerical != FALSE) |
| 1996 | && (Size_p != ObdSize)) { |
| 1997 | // type is numerical, therefor size has to fit, but it does not. |
| 1998 | Ret = kEplObdValueLengthError; |
| 1999 | goto Exit; |
| 2000 | } |
| 2001 | // use given size, because non-numerical objects can be written with shorter values |
| 2002 | ObdSize = Size_p; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2003 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2004 | // set output parameters |
| 2005 | *pObdSize_p = ObdSize; |
| 2006 | *ppObdEntry_p = pObdEntry; |
| 2007 | *ppSubEntry_p = pSubEntry; |
| 2008 | *ppDstData_p = pDstData; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2009 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2010 | // all checks are done |
| 2011 | // the caller may now convert the numerial source value to platform byte order in a temporary buffer |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2012 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2013 | Exit: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2014 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2015 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2016 | |
| 2017 | } |
| 2018 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2019 | //--------------------------------------------------------------------------- |
| 2020 | // |
| 2021 | // Function: EplObdWriteEntryPost() |
| 2022 | // |
| 2023 | // Description: Function finishes write of data to an OBD entry. Strings |
| 2024 | // are stored with added '\0' character. |
| 2025 | // |
| 2026 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ |
| 2027 | // uiIndex_p = Index of the OD entry |
| 2028 | // uiSubIndex_p = Subindex of the OD Entry |
| 2029 | // pSrcData_p = Pointer to the data to write |
| 2030 | // Size_p = Size of the data in Byte |
| 2031 | // |
| 2032 | // Return: tEplKernel = Errorcode |
| 2033 | // |
| 2034 | // |
| 2035 | // State: |
| 2036 | // |
| 2037 | //--------------------------------------------------------------------------- |
| 2038 | |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 2039 | static tEplKernel EplObdWriteEntryPost(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdEntryPtr pObdEntry_p, |
| 2040 | tEplObdSubEntryPtr pSubEntry_p, |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2041 | tEplObdCbParam *pCbParam_p, |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 2042 | void *pSrcData_p, |
| 2043 | void *pDstData_p, |
| 2044 | tEplObdSize ObdSize_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2045 | { |
| 2046 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2047 | tEplKernel Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2048 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2049 | // caller converted the source value to platform byte order |
| 2050 | // now the range of the value may be checked |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2051 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2052 | #if (EPL_OBD_CHECK_OBJECT_RANGE != FALSE) |
| 2053 | { |
| 2054 | // check data range |
| 2055 | Ret = EplObdCheckObjectRange(pSubEntry_p, pSrcData_p); |
| 2056 | if (Ret != kEplSuccessful) { |
| 2057 | goto Exit; |
| 2058 | } |
| 2059 | } |
| 2060 | #endif |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2061 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2062 | // now call user callback function to check value |
| 2063 | // write address of source data to structure of callback parameters |
| 2064 | // so callback function can check this data |
| 2065 | pCbParam_p->m_pArg = pSrcData_p; |
| 2066 | pCbParam_p->m_ObdEvent = kEplObdEvPreWrite; |
| 2067 | Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_ |
| 2068 | pObdEntry_p->m_fpCallback, pCbParam_p); |
| 2069 | if (Ret != kEplSuccessful) { |
| 2070 | goto Exit; |
| 2071 | } |
| 2072 | // copy object data to OBD |
| 2073 | EPL_MEMCPY(pDstData_p, pSrcData_p, ObdSize_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2074 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2075 | // terminate string with 0 |
| 2076 | if (pSubEntry_p->m_Type == kEplObdTypVString) { |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2077 | ((char *)pDstData_p)[ObdSize_p] = '\0'; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2078 | } |
| 2079 | // write address of destination to structure of callback parameters |
| 2080 | // so callback function can change data subsequently |
| 2081 | pCbParam_p->m_pArg = pDstData_p; |
| 2082 | pCbParam_p->m_ObdEvent = kEplObdEvPostWrite; |
| 2083 | Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_ |
| 2084 | pObdEntry_p->m_fpCallback, pCbParam_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2085 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2086 | Exit: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2087 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2088 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2089 | |
| 2090 | } |
| 2091 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2092 | //--------------------------------------------------------------------------- |
| 2093 | // |
| 2094 | // Function: EplObdGetObjectSize() |
| 2095 | // |
| 2096 | // Description: function to get size of object |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 2097 | // The function determines if an object type an fixed data type (u8, WORD, ...) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2098 | // or non fixed object (string, domain). This information is used to decide |
| 2099 | // if download data are stored temporary or not. For objects with fixed data length |
| 2100 | // and types a value range checking can process. |
| 2101 | // For strings the function returns the whole object size not the |
| 2102 | // length of string. |
| 2103 | // |
| 2104 | // Parameters: pSubIndexEntry_p |
| 2105 | // |
| 2106 | // Return: tEplObdSize |
| 2107 | // |
| 2108 | // State: |
| 2109 | // |
| 2110 | //--------------------------------------------------------------------------- |
| 2111 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2112 | static tEplObdSize EplObdGetObjectSize(tEplObdSubEntryPtr pSubIndexEntry_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2113 | { |
| 2114 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2115 | tEplObdSize DataSize = 0; |
| 2116 | void *pData; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2117 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2118 | switch (pSubIndexEntry_p->m_Type) { |
| 2119 | // ----------------------------------------------------------------- |
| 2120 | case kEplObdTypBool: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2121 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2122 | DataSize = 1; |
| 2123 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2124 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2125 | // ----------------------------------------------------------------- |
| 2126 | // ObdTypes which has to be check because numerical values |
| 2127 | case kEplObdTypInt8: |
| 2128 | DataSize = sizeof(tEplObdInteger8); |
| 2129 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2130 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2131 | // ----------------------------------------------------------------- |
| 2132 | case kEplObdTypUInt8: |
| 2133 | DataSize = sizeof(tEplObdUnsigned8); |
| 2134 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2135 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2136 | // ----------------------------------------------------------------- |
| 2137 | case kEplObdTypInt16: |
| 2138 | DataSize = sizeof(tEplObdInteger16); |
| 2139 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2140 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2141 | // ----------------------------------------------------------------- |
| 2142 | case kEplObdTypUInt16: |
| 2143 | DataSize = sizeof(tEplObdUnsigned16); |
| 2144 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2145 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2146 | // ----------------------------------------------------------------- |
| 2147 | case kEplObdTypInt32: |
| 2148 | DataSize = sizeof(tEplObdInteger32); |
| 2149 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2150 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2151 | // ----------------------------------------------------------------- |
| 2152 | case kEplObdTypUInt32: |
| 2153 | DataSize = sizeof(tEplObdUnsigned32); |
| 2154 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2155 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2156 | // ----------------------------------------------------------------- |
| 2157 | case kEplObdTypReal32: |
| 2158 | DataSize = sizeof(tEplObdReal32); |
| 2159 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2160 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2161 | // ----------------------------------------------------------------- |
| 2162 | // ObdTypes which has to be not checked because not NUM values |
| 2163 | case kEplObdTypDomain: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2164 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2165 | pData = (void *)pSubIndexEntry_p->m_pCurrent; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2166 | if ((void *)pData != (void *)NULL) { |
| 2167 | DataSize = ((tEplObdVarEntry *) pData)->m_Size; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2168 | } |
| 2169 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2170 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2171 | // ----------------------------------------------------------------- |
| 2172 | case kEplObdTypVString: |
| 2173 | //case kEplObdTypUString: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2174 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2175 | // If OD entry is defined by macro EPL_OBD_SUBINDEX_ROM_VSTRING |
| 2176 | // then the current pointer is always NULL. The function |
| 2177 | // returns the length of default string. |
| 2178 | pData = (void *)pSubIndexEntry_p->m_pCurrent; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2179 | if ((void *)pData != (void *)NULL) { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2180 | // The max. size of strings defined by STRING-Macro is stored in |
| 2181 | // tEplObdVString of current value. |
| 2182 | // (types tEplObdVString, tEplObdOString and tEplObdUString has the same members) |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2183 | DataSize = ((tEplObdVString *) pData)->m_Size; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2184 | } else { |
| 2185 | // The current position is not decleared. The string |
| 2186 | // is located in ROM, therefor use default pointer. |
| 2187 | pData = (void *)pSubIndexEntry_p->m_pDefault; |
Greg Kroah-Hartman | 5d9d5eb | 2009-03-23 12:24:46 -0700 | [diff] [blame] | 2188 | if ((const void *)pData != (const void *)NULL) { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2189 | // The max. size of strings defined by STRING-Macro is stored in |
| 2190 | // tEplObdVString of default value. |
Greg Kroah-Hartman | 5d9d5eb | 2009-03-23 12:24:46 -0700 | [diff] [blame] | 2191 | DataSize = ((const tEplObdVString *)pData)->m_Size; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2192 | } |
| 2193 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2194 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2195 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2196 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2197 | // ----------------------------------------------------------------- |
| 2198 | case kEplObdTypOString: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2199 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2200 | pData = (void *)pSubIndexEntry_p->m_pCurrent; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2201 | if ((void *)pData != (void *)NULL) { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2202 | // The max. size of strings defined by STRING-Macro is stored in |
| 2203 | // tEplObdVString of current value. |
| 2204 | // (types tEplObdVString, tEplObdOString and tEplObdUString has the same members) |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2205 | DataSize = ((tEplObdOString *) pData)->m_Size; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2206 | } else { |
| 2207 | // The current position is not decleared. The string |
| 2208 | // is located in ROM, therefor use default pointer. |
| 2209 | pData = (void *)pSubIndexEntry_p->m_pDefault; |
Greg Kroah-Hartman | 5d9d5eb | 2009-03-23 12:24:46 -0700 | [diff] [blame] | 2210 | if ((const void *)pData != (const void *)NULL) { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2211 | // The max. size of strings defined by STRING-Macro is stored in |
| 2212 | // tEplObdVString of default value. |
Greg Kroah-Hartman | 5d9d5eb | 2009-03-23 12:24:46 -0700 | [diff] [blame] | 2213 | DataSize = ((const tEplObdOString *)pData)->m_Size; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2214 | } |
| 2215 | } |
| 2216 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2217 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2218 | // ----------------------------------------------------------------- |
| 2219 | case kEplObdTypInt24: |
| 2220 | case kEplObdTypUInt24: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2221 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2222 | DataSize = 3; |
| 2223 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2224 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2225 | // ----------------------------------------------------------------- |
| 2226 | case kEplObdTypInt40: |
| 2227 | case kEplObdTypUInt40: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2228 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2229 | DataSize = 5; |
| 2230 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2231 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2232 | // ----------------------------------------------------------------- |
| 2233 | case kEplObdTypInt48: |
| 2234 | case kEplObdTypUInt48: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2235 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2236 | DataSize = 6; |
| 2237 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2238 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2239 | // ----------------------------------------------------------------- |
| 2240 | case kEplObdTypInt56: |
| 2241 | case kEplObdTypUInt56: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2242 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2243 | DataSize = 7; |
| 2244 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2245 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2246 | // ----------------------------------------------------------------- |
| 2247 | case kEplObdTypInt64: |
| 2248 | case kEplObdTypUInt64: |
| 2249 | case kEplObdTypReal64: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2250 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2251 | DataSize = 8; |
| 2252 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2253 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2254 | // ----------------------------------------------------------------- |
| 2255 | case kEplObdTypTimeOfDay: |
| 2256 | case kEplObdTypTimeDiff: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2257 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2258 | DataSize = 6; |
| 2259 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2260 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2261 | // ----------------------------------------------------------------- |
| 2262 | default: |
| 2263 | break; |
| 2264 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2265 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2266 | return DataSize; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | //--------------------------------------------------------------------------- |
| 2270 | // |
| 2271 | // Function: EplObdGetObjectDefaultPtr() |
| 2272 | // |
| 2273 | // Description: function to get the default pointer (type specific) |
| 2274 | // |
| 2275 | // Parameters: pSubIndexEntry_p = pointer to subindex structure |
| 2276 | // |
| 2277 | // Returns: (void *) = pointer to default value |
| 2278 | // |
| 2279 | // State: |
| 2280 | // |
| 2281 | //--------------------------------------------------------------------------- |
| 2282 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2283 | static void *EplObdGetObjectDefaultPtr(tEplObdSubEntryPtr pSubIndexEntry_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2284 | { |
| 2285 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2286 | void *pDefault; |
| 2287 | tEplObdType Type; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2288 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2289 | ASSERTMSG(pSubIndexEntry_p != NULL, |
| 2290 | "EplObdGetObjectDefaultPtr(): pointer to SubEntry not valid!\n"); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2291 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2292 | // get address to default data from default pointer |
| 2293 | pDefault = pSubIndexEntry_p->m_pDefault; |
| 2294 | if (pDefault != NULL) { |
| 2295 | // there are some special types, whose default pointer always is NULL or has to get from other structure |
| 2296 | // get type from subindex structure |
| 2297 | Type = pSubIndexEntry_p->m_Type; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2298 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2299 | // check if object type is a string value |
| 2300 | if ((Type == kEplObdTypVString) /* || |
| 2301 | (Type == kEplObdTypUString) */ ) { |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2302 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2303 | // EPL_OBD_SUBINDEX_RAM_VSTRING |
| 2304 | // tEplObdSize m_Size; --> size of default string |
| 2305 | // char * m_pDefString; --> pointer to default string |
| 2306 | // char * m_pString; --> pointer to string in RAM |
| 2307 | // |
| 2308 | pDefault = |
| 2309 | (void *)((tEplObdVString *) pDefault)->m_pString; |
| 2310 | } else if (Type == kEplObdTypOString) { |
| 2311 | pDefault = |
| 2312 | (void *)((tEplObdOString *) pDefault)->m_pString; |
| 2313 | } |
| 2314 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2315 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2316 | return pDefault; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2317 | |
| 2318 | } |
| 2319 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2320 | //--------------------------------------------------------------------------- |
| 2321 | // |
| 2322 | // Function: EplObdGetVarEntry() |
| 2323 | // |
| 2324 | // Description: gets a variable entry of an object |
| 2325 | // |
| 2326 | // Parameters: pSubindexEntry_p |
| 2327 | // ppVarEntry_p |
| 2328 | // |
| 2329 | // Return: tCopKernel |
| 2330 | // |
| 2331 | // State: |
| 2332 | // |
| 2333 | //--------------------------------------------------------------------------- |
| 2334 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2335 | static tEplKernel EplObdGetVarEntry(tEplObdSubEntryPtr pSubindexEntry_p, |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2336 | tEplObdVarEntry **ppVarEntry_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2337 | { |
| 2338 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2339 | tEplKernel Ret = kEplObdVarEntryNotExist; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2340 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2341 | ASSERT(ppVarEntry_p != NULL); // is not allowed to be NULL |
| 2342 | ASSERT(pSubindexEntry_p != NULL); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2343 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2344 | // check VAR-Flag - only this object points to variables |
| 2345 | if ((pSubindexEntry_p->m_Access & kEplObdAccVar) != 0) { |
| 2346 | // check if object is an array |
| 2347 | if ((pSubindexEntry_p->m_Access & kEplObdAccArray) != 0) { |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2348 | *ppVarEntry_p = &((tEplObdVarEntry *)pSubindexEntry_p->m_pCurrent)[pSubindexEntry_p->m_uiSubIndex - 1]; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2349 | } else { |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2350 | *ppVarEntry_p = (tEplObdVarEntry *)pSubindexEntry_p->m_pCurrent; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2351 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2352 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2353 | Ret = kEplSuccessful; |
| 2354 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2355 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2356 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2357 | |
| 2358 | } |
| 2359 | |
| 2360 | //--------------------------------------------------------------------------- |
| 2361 | // |
| 2362 | // Function: EplObdGetEntry() |
| 2363 | // |
| 2364 | // Description: gets a index entry from OD |
| 2365 | // |
| 2366 | // Parameters: uiIndex_p = Index number |
| 2367 | // uiSubindex_p = Subindex number |
| 2368 | // ppObdEntry_p = pointer to the pointer to the entry |
| 2369 | // ppObdSubEntry_p = pointer to the pointer to the subentry |
| 2370 | // |
| 2371 | // Return: tEplKernel |
| 2372 | |
| 2373 | // |
| 2374 | // State: |
| 2375 | // |
| 2376 | //--------------------------------------------------------------------------- |
| 2377 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2378 | static tEplKernel EplObdGetEntry(EPL_MCO_DECL_INSTANCE_PTR_ |
| 2379 | unsigned int uiIndex_p, |
| 2380 | unsigned int uiSubindex_p, |
| 2381 | tEplObdEntryPtr * ppObdEntry_p, |
| 2382 | tEplObdSubEntryPtr * ppObdSubEntry_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2383 | { |
| 2384 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2385 | tEplObdEntryPtr pObdEntry; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2386 | tEplObdCbParam CbParam; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2387 | tEplKernel Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2388 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2389 | // check for all API function if instance is valid |
| 2390 | EPL_MCO_CHECK_INSTANCE_STATE(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2391 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2392 | //------------------------------------------------------------------------ |
| 2393 | // get address of entry of index |
| 2394 | Ret = |
| 2395 | EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam), uiIndex_p, |
| 2396 | &pObdEntry); |
| 2397 | if (Ret != kEplSuccessful) { |
| 2398 | goto Exit; |
| 2399 | } |
| 2400 | //------------------------------------------------------------------------ |
| 2401 | // get address of entry of subindex |
| 2402 | Ret = EplObdGetSubindexIntern(pObdEntry, uiSubindex_p, ppObdSubEntry_p); |
| 2403 | if (Ret != kEplSuccessful) { |
| 2404 | goto Exit; |
| 2405 | } |
| 2406 | //------------------------------------------------------------------------ |
| 2407 | // call callback function to inform user/stack that an object will be searched |
| 2408 | // if the called module returnes an error then we abort the searching with kEplObdIndexNotExist |
| 2409 | CbParam.m_uiIndex = uiIndex_p; |
| 2410 | CbParam.m_uiSubIndex = uiSubindex_p; |
| 2411 | CbParam.m_pArg = NULL; |
| 2412 | CbParam.m_ObdEvent = kEplObdEvCheckExist; |
| 2413 | Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_ |
| 2414 | pObdEntry->m_fpCallback, &CbParam); |
| 2415 | if (Ret != kEplSuccessful) { |
| 2416 | Ret = kEplObdIndexNotExist; |
| 2417 | goto Exit; |
| 2418 | } |
| 2419 | //------------------------------------------------------------------------ |
| 2420 | // it is allowed to set ppObdEntry_p to NULL |
| 2421 | // if so, no address will be written to calling function |
| 2422 | if (ppObdEntry_p != NULL) { |
| 2423 | *ppObdEntry_p = pObdEntry; |
| 2424 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2425 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2426 | Exit: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2427 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2428 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2429 | |
| 2430 | } |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2431 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2432 | //--------------------------------------------------------------------------- |
| 2433 | // |
| 2434 | // Function: EplObdGetObjectCurrentPtr() |
| 2435 | // |
| 2436 | // Description: function to get Current pointer (type specific) |
| 2437 | // |
| 2438 | // Parameters: pSubIndexEntry_p |
| 2439 | // |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2440 | // Return: void * |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2441 | // |
| 2442 | // State: |
| 2443 | // |
| 2444 | //--------------------------------------------------------------------------- |
| 2445 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2446 | static void *EplObdGetObjectCurrentPtr(tEplObdSubEntryPtr pSubIndexEntry_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2447 | { |
| 2448 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2449 | void *pData; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2450 | unsigned int uiArrayIndex; |
| 2451 | tEplObdSize Size; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2452 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2453 | pData = pSubIndexEntry_p->m_pCurrent; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2454 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2455 | // check if constant object |
| 2456 | if (pData != NULL) { |
| 2457 | // check if object is an array |
| 2458 | if ((pSubIndexEntry_p->m_Access & kEplObdAccArray) != 0) { |
| 2459 | // calculate correct data pointer |
| 2460 | uiArrayIndex = pSubIndexEntry_p->m_uiSubIndex - 1; |
| 2461 | if ((pSubIndexEntry_p->m_Access & kEplObdAccVar) != 0) { |
| 2462 | Size = sizeof(tEplObdVarEntry); |
| 2463 | } else { |
| 2464 | Size = EplObdGetObjectSize(pSubIndexEntry_p); |
| 2465 | } |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 2466 | pData = ((u8 *) pData) + (Size * uiArrayIndex); |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2467 | } |
| 2468 | // check if VarEntry |
| 2469 | if ((pSubIndexEntry_p->m_Access & kEplObdAccVar) != 0) { |
| 2470 | // The data pointer is stored in VarEntry->pData |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2471 | pData = ((tEplObdVarEntry *) pData)->m_pData; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2472 | } |
| 2473 | // the default pointer is stored for strings in tEplObdVString |
| 2474 | else if ((pSubIndexEntry_p->m_Type == kEplObdTypVString) /* || |
| 2475 | (pSubIndexEntry_p->m_Type == kEplObdTypUString) */ |
| 2476 | ) { |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2477 | pData = (void *)((tEplObdVString *)pData)->m_pString; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2478 | } else if (pSubIndexEntry_p->m_Type == kEplObdTypOString) { |
| 2479 | pData = |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2480 | (void *)((tEplObdOString *)pData)->m_pString; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2481 | } |
| 2482 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2483 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2484 | return pData; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2485 | |
| 2486 | } |
| 2487 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2488 | //--------------------------------------------------------------------------- |
| 2489 | // |
| 2490 | // Function: EplObdGetIndexIntern() |
| 2491 | // |
| 2492 | // Description: gets a index entry from OD |
| 2493 | // |
| 2494 | // Parameters: pInitParam_p |
| 2495 | // uiIndex_p |
| 2496 | // ppObdEntry_p |
| 2497 | // |
| 2498 | // Return: tEplKernel |
| 2499 | // |
| 2500 | // State: |
| 2501 | // |
| 2502 | //--------------------------------------------------------------------------- |
| 2503 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2504 | static tEplKernel EplObdGetIndexIntern(tEplObdInitParam *pInitParam_p, |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2505 | unsigned int uiIndex_p, |
| 2506 | tEplObdEntryPtr * ppObdEntry_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2507 | { |
| 2508 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2509 | tEplObdEntryPtr pObdEntry; |
| 2510 | tEplKernel Ret; |
| 2511 | unsigned int uiIndex; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2512 | |
| 2513 | #if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE)) |
| 2514 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2515 | unsigned int nLoop; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2516 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2517 | // if user OD is used then objekts also has to be searched in user OD |
| 2518 | // there is less code need if we do this in a loop |
| 2519 | nLoop = 2; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2520 | |
| 2521 | #endif |
| 2522 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2523 | ASSERTMSG(ppObdEntry_p != NULL, |
| 2524 | "EplObdGetIndexIntern(): pointer to index entry is NULL!\n"); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2525 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2526 | Ret = kEplObdIndexNotExist; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2527 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2528 | // get start address of OD part |
| 2529 | // start address depends on object index because |
| 2530 | // object dictionary is divided in 3 parts |
| 2531 | if ((uiIndex_p >= 0x1000) && (uiIndex_p < 0x2000)) { |
| 2532 | pObdEntry = pInitParam_p->m_pPart; |
| 2533 | } else if ((uiIndex_p >= 0x2000) && (uiIndex_p < 0x6000)) { |
| 2534 | pObdEntry = pInitParam_p->m_pManufacturerPart; |
| 2535 | } |
| 2536 | // index range 0xA000 to 0xFFFF is reserved for DSP-405 |
| 2537 | // DS-301 defines that range 0x6000 to 0x9FFF (!!!) is stored if "store" was written to 0x1010/3. |
| 2538 | // Therefore default configuration is OBD_INCLUDE_A000_TO_DEVICE_PART = FALSE. |
| 2539 | // But a CANopen Application which does not implement dynamic OD or user-OD but wants to use static objets 0xA000... |
| 2540 | // should set OBD_INCLUDE_A000_TO_DEVICE_PART to TRUE. |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2541 | |
| 2542 | #if (EPL_OBD_INCLUDE_A000_TO_DEVICE_PART == FALSE) |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2543 | else if ((uiIndex_p >= 0x6000) && (uiIndex_p < 0x9FFF)) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2544 | #else |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2545 | else if ((uiIndex_p >= 0x6000) && (uiIndex_p < 0xFFFF)) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2546 | #endif |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2547 | { |
| 2548 | pObdEntry = pInitParam_p->m_pDevicePart; |
| 2549 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2550 | |
| 2551 | #if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE)) |
| 2552 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2553 | // if index does not match in static OD then index only has to be searched in user OD |
| 2554 | else { |
| 2555 | // begin from first entry of user OD part |
| 2556 | pObdEntry = pInitParam_p->m_pUserPart; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2557 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2558 | // no user OD is available |
| 2559 | if (pObdEntry == NULL) { |
| 2560 | goto Exit; |
| 2561 | } |
| 2562 | // loop must only run once |
| 2563 | nLoop = 1; |
| 2564 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2565 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2566 | do { |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2567 | |
| 2568 | #else |
| 2569 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2570 | // no user OD is available |
| 2571 | // so other object can be found in OD |
| 2572 | else { |
| 2573 | Ret = kEplObdIllegalPart; |
| 2574 | goto Exit; |
| 2575 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2576 | |
| 2577 | #endif |
| 2578 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2579 | // note: |
| 2580 | // The end of Index table is marked with m_uiIndex = 0xFFFF. |
| 2581 | // If this function will be called with wIndex_p = 0xFFFF, entry |
| 2582 | // should not be found. Therefor it is important to use |
| 2583 | // while{} instead of do{}while !!! |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2584 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2585 | // get first index of index table |
| 2586 | uiIndex = pObdEntry->m_uiIndex; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2587 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2588 | // search Index in OD part |
| 2589 | while (uiIndex != EPL_OBD_TABLE_INDEX_END) { |
| 2590 | // go to the end of this function if index is found |
| 2591 | if (uiIndex_p == uiIndex) { |
| 2592 | // write address of OD entry to calling function |
| 2593 | *ppObdEntry_p = pObdEntry; |
| 2594 | Ret = kEplSuccessful; |
| 2595 | goto Exit; |
| 2596 | } |
| 2597 | // objects are sorted in OD |
| 2598 | // if the current index in OD is greater than the index which is to search then break loop |
| 2599 | // in this case user OD has to be search too |
| 2600 | if (uiIndex_p < uiIndex) { |
| 2601 | break; |
| 2602 | } |
| 2603 | // next entry in index table |
| 2604 | pObdEntry++; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2605 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2606 | // get next index of index table |
| 2607 | uiIndex = pObdEntry->m_uiIndex; |
| 2608 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2609 | |
| 2610 | #if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE)) |
| 2611 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2612 | // begin from first entry of user OD part |
| 2613 | pObdEntry = pInitParam_p->m_pUserPart; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2614 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2615 | // no user OD is available |
| 2616 | if (pObdEntry == NULL) { |
| 2617 | goto Exit; |
| 2618 | } |
| 2619 | // switch next loop for user OD |
| 2620 | nLoop--; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2621 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2622 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2623 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2624 | while (nLoop > 0) ; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2625 | |
| 2626 | #endif |
| 2627 | |
| 2628 | // in this line Index was not found |
| 2629 | |
| 2630 | Exit: |
| 2631 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2632 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2633 | |
| 2634 | } |
| 2635 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2636 | //--------------------------------------------------------------------------- |
| 2637 | // |
| 2638 | // Function: EplObdGetSubindexIntern() |
| 2639 | // |
| 2640 | // Description: gets a subindex entry from a index entry |
| 2641 | // |
| 2642 | // Parameters: pObdEntry_p |
| 2643 | // bSubIndex_p |
| 2644 | // ppObdSubEntry_p |
| 2645 | // |
| 2646 | // Return: tEplKernel |
| 2647 | // |
| 2648 | // State: |
| 2649 | // |
| 2650 | //--------------------------------------------------------------------------- |
| 2651 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2652 | static tEplKernel EplObdGetSubindexIntern(tEplObdEntryPtr pObdEntry_p, |
| 2653 | unsigned int uiSubIndex_p, |
| 2654 | tEplObdSubEntryPtr * ppObdSubEntry_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2655 | { |
| 2656 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2657 | tEplObdSubEntryPtr pSubEntry; |
| 2658 | unsigned int nSubIndexCount; |
| 2659 | tEplKernel Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2660 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2661 | ASSERTMSG(pObdEntry_p != NULL, |
| 2662 | "EplObdGetSubindexIntern(): pointer to index is NULL!\n"); |
| 2663 | ASSERTMSG(ppObdSubEntry_p != NULL, |
| 2664 | "EplObdGetSubindexIntern(): pointer to subindex is NULL!\n"); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2665 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2666 | Ret = kEplObdSubindexNotExist; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2667 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2668 | // get start address of subindex table and count of subindices |
| 2669 | pSubEntry = pObdEntry_p->m_pSubIndex; |
| 2670 | nSubIndexCount = pObdEntry_p->m_uiCount; |
| 2671 | ASSERTMSG((pSubEntry != NULL) && (nSubIndexCount > 0), "ObdGetSubindexIntern(): invalid subindex table within index table!\n"); // should never be NULL |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2672 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2673 | // search subindex in subindex table |
| 2674 | while (nSubIndexCount > 0) { |
| 2675 | // check if array is found |
| 2676 | if ((pSubEntry->m_Access & kEplObdAccArray) != 0) { |
| 2677 | // check if subindex is in range |
| 2678 | if (uiSubIndex_p < pObdEntry_p->m_uiCount) { |
| 2679 | // update subindex number (subindex entry of an array is always in RAM !!!) |
| 2680 | pSubEntry->m_uiSubIndex = uiSubIndex_p; |
| 2681 | *ppObdSubEntry_p = pSubEntry; |
| 2682 | Ret = kEplSuccessful; |
| 2683 | goto Exit; |
| 2684 | } |
| 2685 | } |
| 2686 | // go to the end of this function if subindex is found |
| 2687 | else if (uiSubIndex_p == pSubEntry->m_uiSubIndex) { |
| 2688 | *ppObdSubEntry_p = pSubEntry; |
| 2689 | Ret = kEplSuccessful; |
| 2690 | goto Exit; |
| 2691 | } |
| 2692 | // objects are sorted in OD |
| 2693 | // if the current subindex in OD is greater than the subindex which is to search then break loop |
| 2694 | // in this case user OD has to be search too |
| 2695 | if (uiSubIndex_p < pSubEntry->m_uiSubIndex) { |
| 2696 | break; |
| 2697 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2698 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2699 | pSubEntry++; |
| 2700 | nSubIndexCount--; |
| 2701 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2702 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2703 | // in this line SubIndex was not fount |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2704 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2705 | Exit: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2706 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2707 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2708 | |
| 2709 | } |
| 2710 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2711 | //--------------------------------------------------------------------------- |
| 2712 | // |
| 2713 | // Function: EplObdSetStoreLoadObjCallback() |
| 2714 | // |
| 2715 | // Description: function set address to callbackfunction for command Store and Load |
| 2716 | // |
| 2717 | // Parameters: fpCallback_p |
| 2718 | // |
| 2719 | // Return: tEplKernel |
| 2720 | // |
| 2721 | // State: |
| 2722 | // |
| 2723 | //--------------------------------------------------------------------------- |
| 2724 | #if (EPL_OBD_USE_STORE_RESTORE != FALSE) |
Greg Kroah-Hartman | d10f469 | 2009-03-23 10:45:12 -0700 | [diff] [blame] | 2725 | EPLDLLEXPORT tEplKernel EplObdSetStoreLoadObjCallback(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdStoreLoadObjCallback fpCallback_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2726 | { |
| 2727 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2728 | EPL_MCO_CHECK_INSTANCE_STATE(); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2729 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2730 | // set new address of callback function |
| 2731 | EPL_MCO_GLB_VAR(m_fpStoreLoadObjCallback) = fpCallback_p; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2732 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2733 | return kEplSuccessful; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2734 | |
| 2735 | } |
| 2736 | #endif // (EPL_OBD_USE_STORE_RESTORE != FALSE) |
| 2737 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2738 | //--------------------------------------------------------------------------- |
| 2739 | // |
| 2740 | // Function: EplObdAccessOdPartIntern() |
| 2741 | // |
| 2742 | // Description: runs through OD and executes a job |
| 2743 | // |
| 2744 | // Parameters: CurrentOdPart_p |
| 2745 | // pObdEnty_p |
| 2746 | // Direction_p = what is to do (load values from flash or EEPROM, store, ...) |
| 2747 | // |
| 2748 | // Return: tEplKernel |
| 2749 | // |
| 2750 | // State: |
| 2751 | // |
| 2752 | //--------------------------------------------------------------------------- |
| 2753 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2754 | static tEplKernel EplObdAccessOdPartIntern(EPL_MCO_DECL_INSTANCE_PTR_ |
| 2755 | tEplObdPart CurrentOdPart_p, |
| 2756 | tEplObdEntryPtr pObdEnty_p, |
| 2757 | tEplObdDir Direction_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2758 | { |
| 2759 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2760 | tEplObdSubEntryPtr pSubIndex; |
| 2761 | unsigned int nSubIndexCount; |
| 2762 | tEplObdAccess Access; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2763 | void *pDstData; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2764 | void *pDefault; |
| 2765 | tEplObdSize ObjSize; |
| 2766 | tEplKernel Ret; |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2767 | tEplObdCbStoreParam CbStore; |
| 2768 | tEplObdVarEntry *pVarEntry; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2769 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2770 | ASSERT(pObdEnty_p != NULL); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2771 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2772 | Ret = kEplSuccessful; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2773 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2774 | // prepare structure for STORE RESTORE callback function |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 2775 | CbStore.m_bCurrentOdPart = (u8) CurrentOdPart_p; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2776 | CbStore.m_pData = NULL; |
| 2777 | CbStore.m_ObjSize = 0; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2778 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2779 | // command of first action depends on direction to access |
| 2780 | #if (EPL_OBD_USE_STORE_RESTORE != FALSE) |
| 2781 | if (Direction_p == kEplObdDirLoad) { |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 2782 | CbStore.m_bCommand = (u8) kEplObdCommOpenRead; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2783 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2784 | // call callback function for previous command |
| 2785 | Ret = EplObdCallStoreCallback(EPL_MCO_INSTANCE_PTR_ & CbStore); |
| 2786 | if (Ret != kEplSuccessful) { |
| 2787 | goto Exit; |
| 2788 | } |
| 2789 | // set command for index and subindex loop |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 2790 | CbStore.m_bCommand = (u8) kEplObdCommReadObj; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2791 | } else if (Direction_p == kEplObdDirStore) { |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 2792 | CbStore.m_bCommand = (u8) kEplObdCommOpenWrite; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2793 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2794 | // call callback function for previous command |
| 2795 | Ret = EplObdCallStoreCallback(EPL_MCO_INSTANCE_PTR_ & CbStore); |
| 2796 | if (Ret != kEplSuccessful) { |
| 2797 | goto Exit; |
| 2798 | } |
| 2799 | // set command for index and subindex loop |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 2800 | CbStore.m_bCommand = (u8) kEplObdCommWriteObj; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2801 | } |
| 2802 | #endif // (EPL_OBD_USE_STORE_RESTORE != FALSE) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2803 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2804 | // we should not restore the OD values here |
| 2805 | // the next NMT command "Reset Node" or "Reset Communication" resets the OD data |
| 2806 | if (Direction_p != kEplObdDirRestore) { |
| 2807 | // walk through OD part till end is found |
| 2808 | while (pObdEnty_p->m_uiIndex != EPL_OBD_TABLE_INDEX_END) { |
| 2809 | // get address to subindex table and count of subindices |
| 2810 | pSubIndex = pObdEnty_p->m_pSubIndex; |
| 2811 | nSubIndexCount = pObdEnty_p->m_uiCount; |
| 2812 | ASSERT((pSubIndex != NULL) && (nSubIndexCount > 0)); // should never be NULL |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2813 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2814 | // walk through subindex table till all subinices were restored |
| 2815 | while (nSubIndexCount != 0) { |
| 2816 | Access = (tEplObdAccess) pSubIndex->m_Access; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2817 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2818 | // get pointer to current and default data |
| 2819 | pDefault = EplObdGetObjectDefaultPtr(pSubIndex); |
| 2820 | pDstData = EplObdGetObjectCurrentPtr(pSubIndex); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2821 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2822 | // NOTE (for kEplObdTypVString): |
| 2823 | // The function returnes the max. number of bytes for a |
| 2824 | // current string. |
| 2825 | // r.d.: For stings the default-size will be read in other lines following (kEplObdDirInit). |
| 2826 | ObjSize = EplObdGetObjectSize(pSubIndex); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2827 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2828 | // switch direction of OD access |
| 2829 | switch (Direction_p) { |
| 2830 | // -------------------------------------------------------------------------- |
| 2831 | // VarEntry structures has to be initialized |
| 2832 | case kEplObdDirInit: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2833 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2834 | // If VAR-Flag is set, m_pCurrent means not address of data |
| 2835 | // but address of tEplObdVarEntry. Address of data has to be get from |
| 2836 | // this structure. |
| 2837 | if ((Access & kEplObdAccVar) != 0) { |
| 2838 | EplObdGetVarEntry(pSubIndex, |
| 2839 | &pVarEntry); |
| 2840 | EplObdInitVarEntry(pVarEntry, |
| 2841 | pSubIndex-> |
| 2842 | m_Type, |
| 2843 | ObjSize); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2844 | /* |
| 2845 | if ((Access & kEplObdAccArray) == 0) |
| 2846 | { |
| 2847 | EplObdInitVarEntry (pSubIndex->m_pCurrent, pSubIndex->m_Type, ObjSize); |
| 2848 | } |
| 2849 | else |
| 2850 | { |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 2851 | EplObdInitVarEntry ((tEplObdVarEntry *) (((u8 *) pSubIndex->m_pCurrent) + (sizeof (tEplObdVarEntry) * pSubIndex->m_uiSubIndex)), |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2852 | pSubIndex->m_Type, ObjSize); |
| 2853 | } |
| 2854 | */ |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2855 | // at this time no application variable is defined !!! |
| 2856 | // therefore data can not be copied. |
| 2857 | break; |
| 2858 | } else if (pSubIndex->m_Type == |
| 2859 | kEplObdTypVString) { |
| 2860 | // If pointer m_pCurrent is not equal to NULL then the |
| 2861 | // string was defined with EPL_OBD_SUBINDEX_RAM_VSTRING. The current |
| 2862 | // pointer points to struct tEplObdVString located in MEM. |
| 2863 | // The element size includes the max. number of |
| 2864 | // bytes. The element m_pString includes the pointer |
| 2865 | // to string in MEM. The memory location of default string |
| 2866 | // must be copied to memory location of current string. |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2867 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2868 | pDstData = |
| 2869 | pSubIndex->m_pCurrent; |
| 2870 | if (pDstData != NULL) { |
| 2871 | // 08-dec-2004: code optimization !!! |
Greg Kroah-Hartman | 5318487 | 2009-03-23 11:48:19 -0700 | [diff] [blame] | 2872 | // entries ((tEplObdVStringDef*) pSubIndex->m_pDefault)->m_pString |
| 2873 | // and ((tEplObdVStringDef*) pSubIndex->m_pDefault)->m_Size were read |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2874 | // twice. thats not necessary! |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2875 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2876 | // For copying data we have to set the destination pointer to the real RAM string. This |
| 2877 | // pointer to RAM string is located in default string info structure. (translated r.d.) |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2878 | pDstData = (void *)((tEplObdVStringDef*) pSubIndex->m_pDefault)->m_pString; |
Greg Kroah-Hartman | 5318487 | 2009-03-23 11:48:19 -0700 | [diff] [blame] | 2879 | ObjSize = ((tEplObdVStringDef *)pSubIndex->m_pDefault)->m_Size; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2880 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2881 | ((tEplObdVString *)pSubIndex->m_pCurrent)->m_pString = pDstData; |
| 2882 | ((tEplObdVString *)pSubIndex->m_pCurrent)->m_Size = ObjSize; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2883 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2884 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2885 | } else if (pSubIndex->m_Type == |
| 2886 | kEplObdTypOString) { |
| 2887 | pDstData = |
| 2888 | pSubIndex->m_pCurrent; |
| 2889 | if (pDstData != NULL) { |
| 2890 | // 08-dec-2004: code optimization !!! |
Greg Kroah-Hartman | 5318487 | 2009-03-23 11:48:19 -0700 | [diff] [blame] | 2891 | // entries ((tEplObdOStringDef*) pSubIndex->m_pDefault)->m_pString |
| 2892 | // and ((tEplObdOStringDef*) pSubIndex->m_pDefault)->m_Size were read |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2893 | // twice. thats not necessary! |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2894 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2895 | // For copying data we have to set the destination pointer to the real RAM string. This |
| 2896 | // pointer to RAM string is located in default string info structure. (translated r.d.) |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2897 | pDstData = (void *)((tEplObdOStringDef *) pSubIndex->m_pDefault)->m_pString; |
Greg Kroah-Hartman | 5318487 | 2009-03-23 11:48:19 -0700 | [diff] [blame] | 2898 | ObjSize = ((tEplObdOStringDef *)pSubIndex->m_pDefault)->m_Size; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2899 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 2900 | ((tEplObdOString *)pSubIndex->m_pCurrent)->m_pString = pDstData; |
| 2901 | ((tEplObdOString *)pSubIndex->m_pCurrent)->m_Size = ObjSize; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2902 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2903 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2904 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2905 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2906 | // no break !! because copy of data has to done too. |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2907 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2908 | // -------------------------------------------------------------------------- |
| 2909 | // all objects has to be restored with default values |
| 2910 | case kEplObdDirRestore: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2911 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2912 | // 09-dec-2004 r.d.: optimization! the same code for kEplObdDirRestore and kEplObdDirLoad |
| 2913 | // is replaced to function ObdCopyObjectData() with a new parameter. |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2914 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2915 | // restore object data for init phase |
| 2916 | EplObdCopyObjectData(pDstData, pDefault, |
| 2917 | ObjSize, |
| 2918 | pSubIndex->m_Type); |
| 2919 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2920 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2921 | // -------------------------------------------------------------------------- |
| 2922 | // objects with attribute kEplObdAccStore has to be load from EEPROM or from a file |
| 2923 | case kEplObdDirLoad: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2924 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2925 | // restore object data for init phase |
| 2926 | EplObdCopyObjectData(pDstData, pDefault, |
| 2927 | ObjSize, |
| 2928 | pSubIndex->m_Type); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2929 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2930 | // no break !! because callback function has to be called too. |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2931 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2932 | // -------------------------------------------------------------------------- |
| 2933 | // objects with attribute kEplObdAccStore has to be stored in EEPROM or in a file |
| 2934 | case kEplObdDirStore: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2935 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2936 | // when attribute kEplObdAccStore is set, then call callback function |
| 2937 | #if (EPL_OBD_USE_STORE_RESTORE != FALSE) |
| 2938 | if ((Access & kEplObdAccStore) != 0) { |
| 2939 | // fill out data pointer and size of data |
| 2940 | CbStore.m_pData = pDstData; |
| 2941 | CbStore.m_ObjSize = ObjSize; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2942 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2943 | // call callback function for read or write object |
| 2944 | Ret = |
| 2945 | ObdCallStoreCallback |
| 2946 | (EPL_MCO_INSTANCE_PTR_ & |
| 2947 | CbStore); |
| 2948 | if (Ret != kEplSuccessful) { |
| 2949 | goto Exit; |
| 2950 | } |
| 2951 | } |
| 2952 | #endif // (EPL_OBD_USE_STORE_RESTORE != FALSE) |
| 2953 | break; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2954 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2955 | // -------------------------------------------------------------------------- |
| 2956 | // if OD Builder key has to be checked no access to subindex and data should be made |
| 2957 | case kEplObdDirOBKCheck: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2958 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2959 | // no break !! because we want to break the second loop too. |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2960 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2961 | // -------------------------------------------------------------------------- |
| 2962 | // unknown Direction |
| 2963 | default: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2964 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2965 | // so we can break the second loop earler |
| 2966 | nSubIndexCount = 1; |
| 2967 | break; |
| 2968 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2969 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2970 | nSubIndexCount--; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2971 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2972 | // next subindex entry |
| 2973 | if ((Access & kEplObdAccArray) == 0) { |
| 2974 | pSubIndex++; |
| 2975 | if ((nSubIndexCount > 0) |
| 2976 | && |
| 2977 | ((pSubIndex-> |
| 2978 | m_Access & kEplObdAccArray) != |
| 2979 | 0)) { |
| 2980 | // next subindex points to an array |
| 2981 | // reset subindex number |
| 2982 | pSubIndex->m_uiSubIndex = 1; |
| 2983 | } |
| 2984 | } else { |
| 2985 | if (nSubIndexCount > 0) { |
| 2986 | // next subindex points to an array |
| 2987 | // increment subindex number |
| 2988 | pSubIndex->m_uiSubIndex++; |
| 2989 | } |
| 2990 | } |
| 2991 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 2992 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 2993 | // next index entry |
| 2994 | pObdEnty_p++; |
| 2995 | } |
| 2996 | } |
| 2997 | // ----------------------------------------------------------------------------------------- |
| 2998 | // command of last action depends on direction to access |
| 2999 | if (Direction_p == kEplObdDirOBKCheck) { |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3000 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3001 | goto Exit; |
| 3002 | } |
| 3003 | #if (EPL_OBD_USE_STORE_RESTORE != FALSE) |
| 3004 | else { |
| 3005 | if (Direction_p == kEplObdDirLoad) { |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 3006 | CbStore.m_bCommand = (u8) kEplObdCommCloseRead; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3007 | } else if (Direction_p == kEplObdDirStore) { |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 3008 | CbStore.m_bCommand = (u8) kEplObdCommCloseWrite; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3009 | } else if (Direction_p == kEplObdDirRestore) { |
Greg Kroah-Hartman | 2ed53cf | 2009-03-23 12:36:38 -0700 | [diff] [blame] | 3010 | CbStore.m_bCommand = (u8) kEplObdCommClear; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3011 | } else { |
| 3012 | goto Exit; |
| 3013 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3014 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3015 | // call callback function for last command |
| 3016 | Ret = EplObdCallStoreCallback(EPL_MCO_INSTANCE_PTR_ & CbStore); |
| 3017 | } |
| 3018 | #endif // (EPL_OBD_USE_STORE_RESTORE != FALSE) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3019 | |
| 3020 | // goto Exit; |
| 3021 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3022 | Exit: |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3023 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3024 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3025 | |
| 3026 | } |
| 3027 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3028 | // ---------------------------------------------------------------------------- |
| 3029 | // Function: EplObdCopyObjectData() |
| 3030 | // |
| 3031 | // Description: checks pointers to object data and copy them from source to destination |
| 3032 | // |
| 3033 | // Parameters: pDstData_p = destination pointer |
| 3034 | // pSrcData_p = source pointer |
| 3035 | // ObjSize_p = size of object |
| 3036 | // ObjType_p = |
| 3037 | // |
| 3038 | // Returns: tEplKernel = error code |
| 3039 | // ---------------------------------------------------------------------------- |
| 3040 | |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 3041 | static void EplObdCopyObjectData(void *pDstData_p, |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3042 | void *pSrcData_p, |
| 3043 | tEplObdSize ObjSize_p, tEplObdType ObjType_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3044 | { |
| 3045 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3046 | tEplObdSize StrSize = 0; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3047 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3048 | // it is allowed to set default and current address to NULL (nothing to copy) |
| 3049 | if (pDstData_p != NULL) { |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3050 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3051 | if (ObjType_p == kEplObdTypVString) { |
| 3052 | // The function calculates the really number of characters of string. The |
| 3053 | // object entry size can be bigger as string size of default string. |
| 3054 | // The '\0'-termination is included. A string with no characters has a |
| 3055 | // size of 1. |
| 3056 | StrSize = |
| 3057 | EplObdGetStrLen((void *)pSrcData_p, ObjSize_p, |
| 3058 | kEplObdTypVString); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3059 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3060 | // If the string length is greater than or equal to the entry size in OD then only copy |
| 3061 | // entry size - 1 and always set the '\0'-termination. |
| 3062 | if (StrSize >= ObjSize_p) { |
| 3063 | StrSize = ObjSize_p - 1; |
| 3064 | } |
| 3065 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3066 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3067 | if (pSrcData_p != NULL) { |
| 3068 | // copy data |
| 3069 | EPL_MEMCPY(pDstData_p, pSrcData_p, ObjSize_p); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3070 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3071 | if (ObjType_p == kEplObdTypVString) { |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 3072 | ((char *)pDstData_p)[StrSize] = '\0'; |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3073 | } |
| 3074 | } |
| 3075 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3076 | |
| 3077 | } |
| 3078 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3079 | //--------------------------------------------------------------------------- |
| 3080 | // |
| 3081 | // Function: EplObdIsNumericalIntern() |
| 3082 | // |
| 3083 | // Description: function checks if a entry is numerical or not |
| 3084 | // |
| 3085 | // |
| 3086 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = Instancepointer |
| 3087 | // uiIndex_p = Index |
| 3088 | // uiSubIndex_p = Subindex |
| 3089 | // pfEntryNumerical_p = pointer to BOOL for returnvalue |
| 3090 | // -> TRUE if entry a numerical value |
| 3091 | // -> FALSE if entry not a numerical value |
| 3092 | // |
| 3093 | // Return: tEplKernel = Errorcode |
| 3094 | // |
| 3095 | // State: |
| 3096 | // |
| 3097 | //--------------------------------------------------------------------------- |
| 3098 | static tEplKernel EplObdIsNumericalIntern(tEplObdSubEntryPtr pObdSubEntry_p, |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3099 | BOOL * pfEntryNumerical_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3100 | { |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3101 | tEplKernel Ret = kEplSuccessful; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3102 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3103 | // get Type |
| 3104 | if ((pObdSubEntry_p->m_Type == kEplObdTypVString) |
| 3105 | || (pObdSubEntry_p->m_Type == kEplObdTypOString) |
| 3106 | || (pObdSubEntry_p->m_Type == kEplObdTypDomain)) { // not numerical types |
| 3107 | *pfEntryNumerical_p = FALSE; |
| 3108 | } else { // numerical types |
| 3109 | *pfEntryNumerical_p = TRUE; |
| 3110 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3111 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3112 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3113 | |
| 3114 | } |
| 3115 | |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3116 | // ------------------------------------------------------------------------- |
| 3117 | // function to classify object type (fixed/non fixed) |
| 3118 | // ------------------------------------------------------------------------- |
| 3119 | |
| 3120 | // ---------------------------------------------------------------------------- |
| 3121 | // Function: EplObdCallStoreCallback() |
| 3122 | // |
| 3123 | // Description: checks address to callback function and calles it when unequal |
| 3124 | // to NULL |
| 3125 | // |
| 3126 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = (instance pointer) |
| 3127 | // pCbStoreParam_p = address to callback parameters |
| 3128 | // |
| 3129 | // Returns: tEplKernel = error code |
| 3130 | // ---------------------------------------------------------------------------- |
| 3131 | #if (EPL_OBD_USE_STORE_RESTORE != FALSE) |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3132 | static tEplKernel EplObdCallStoreCallback(EPL_MCO_DECL_INSTANCE_PTR_ |
Greg Kroah-Hartman | 5e9f6bc | 2009-03-23 12:09:26 -0700 | [diff] [blame] | 3133 | tEplObdCbStoreParam * |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3134 | pCbStoreParam_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3135 | { |
| 3136 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3137 | tEplKernel Ret = kEplSuccessful; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3138 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3139 | ASSERT(pCbStoreParam_p != NULL); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3140 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3141 | // check if function pointer is NULL - if so, no callback should be called |
| 3142 | if (EPL_MCO_GLB_VAR(m_fpStoreLoadObjCallback) != NULL) { |
| 3143 | Ret = |
| 3144 | EPL_MCO_GLB_VAR(m_fpStoreLoadObjCallback) |
| 3145 | (EPL_MCO_INSTANCE_PARAM_IDX_() |
| 3146 | pCbStoreParam_p); |
| 3147 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3148 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3149 | return Ret; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3150 | |
| 3151 | } |
| 3152 | #endif // (EPL_OBD_USE_STORE_RESTORE != FALSE) |
| 3153 | //--------------------------------------------------------------------------- |
| 3154 | // |
| 3155 | // Function: EplObdGetObjectDataPtrIntern() |
| 3156 | // |
| 3157 | // Description: Function gets the data pointer of an object. |
| 3158 | // It returnes the current data pointer. But if object is an |
| 3159 | // constant object it returnes the default pointer. |
| 3160 | // |
| 3161 | // Parameters: pSubindexEntry_p = pointer to subindex entry |
| 3162 | // |
| 3163 | // Return: void * = pointer to object data |
| 3164 | // |
| 3165 | // State: |
| 3166 | // |
| 3167 | //--------------------------------------------------------------------------- |
| 3168 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3169 | void *EplObdGetObjectDataPtrIntern(tEplObdSubEntryPtr pSubindexEntry_p) |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3170 | { |
| 3171 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3172 | void *pData; |
| 3173 | tEplObdAccess Access; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3174 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3175 | ASSERTMSG(pSubindexEntry_p != NULL, |
| 3176 | "EplObdGetObjectDataPtrIntern(): pointer to SubEntry not valid!\n"); |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3177 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3178 | // there are are some objects whose data pointer has to get from other structure |
| 3179 | // get access type for this object |
| 3180 | Access = pSubindexEntry_p->m_Access; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3181 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3182 | // If object has access type = const, |
| 3183 | // for data only exists default values. |
| 3184 | if ((Access & kEplObdAccConst) != 0) { |
| 3185 | // The pointer to defualt value can be received from ObdGetObjectDefaultPtr() |
| 3186 | pData = ((void *)EplObdGetObjectDefaultPtr(pSubindexEntry_p)); |
| 3187 | } else { |
| 3188 | // The pointer to current value can be received from ObdGetObjectCurrentPtr() |
| 3189 | pData = ((void *)EplObdGetObjectCurrentPtr(pSubindexEntry_p)); |
| 3190 | } |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3191 | |
Greg Kroah-Hartman | 833dfbe | 2008-12-19 17:11:52 -0800 | [diff] [blame] | 3192 | return pData; |
Daniel Krueger | 9d7164c | 2008-12-19 11:41:57 -0800 | [diff] [blame] | 3193 | |
| 3194 | } |
| 3195 | #endif // end of #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDK)) != 0) |
| 3196 | // EOF |