Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
cop.c
00001 /******************************************************************************* 00002 ******************************************************************************** 00003 ** ** 00004 ** ABCC Starter Kit version 2.01.01 (2015-12-14) ** 00005 ** ** 00006 ** Delivered with: ** 00007 ** ABCC Driver 4.01.01 (2015-12-14) ** 00008 ** ABP 7.16.01 (2015-10-14) ** 00009 ** */ 00010 /******************************************************************************* 00011 ******************************************************************************** 00012 ** COPYRIGHT NOTIFICATION (c) 2015 HMS Industrial Networks AB ** 00013 ** ** 00014 ** This code is the property of HMS Industrial Networks AB. ** 00015 ** The source code may not be reproduced, distributed, or used without ** 00016 ** permission. When used together with a product from HMS, permission is ** 00017 ** granted to modify, reproduce and distribute the code in binary form ** 00018 ** without any restrictions. ** 00019 ** ** 00020 ** THE CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. HMS DOES NOT ** 00021 ** WARRANT THAT THE FUNCTIONS OF THE CODE WILL MEET YOUR REQUIREMENTS, OR ** 00022 ** THAT THE OPERATION OF THE CODE WILL BE UNINTERRUPTED OR ERROR-FREE, OR ** 00023 ** THAT DEFECTS IN IT CAN BE CORRECTED. ** 00024 ******************************************************************************** 00025 ******************************************************************************** 00026 ** Source file for the CANopen Object. 00027 ******************************************************************************** 00028 ******************************************************************************** 00029 */ 00030 00031 #include "abcc_td.h" 00032 #include "abcc.h" 00033 #include "abcc_obj_cfg.h" 00034 #include "cop.h" 00035 #include "abp.h" 00036 #include "abp_cop.h" 00037 #include "string.h" 00038 #include "appl_abcc_handler.h" 00039 #include "abcc_port.h" 00040 00041 #if COP_OBJ_ENABLE 00042 00043 /******************************************************************************* 00044 ** Defines 00045 ******************************************************************************** 00046 */ 00047 00048 /*------------------------------------------------------------------------------ 00049 ** Object attribute values 00050 **------------------------------------------------------------------------------ 00051 */ 00052 #define COP_OA_NAME_VALUE "CANopen" 00053 #define COP_OA_REV_VALUE 1 00054 #define COP_OA_NUM_INST_VALUE 1 00055 #define COP_OA_HIGHEST_INST_VALUE 1 00056 00057 /******************************************************************************* 00058 ** Typedefs 00059 ******************************************************************************** 00060 */ 00061 00062 /*------------------------------------------------------------------------------ 00063 ** Structure describing an CANopen Object. 00064 **------------------------------------------------------------------------------ 00065 */ 00066 typedef struct cop_Object 00067 { 00068 const char* pcName; 00069 UINT8 bRevision; 00070 UINT16 iNumberOfInstances; 00071 UINT16 iHighestInstanceNo; 00072 } 00073 cop_ObjectType; 00074 00075 00076 /*------------------------------------------------------------------------------ 00077 ** Forward declarations 00078 **------------------------------------------------------------------------------ 00079 */ 00080 static void InstanceCommand( ABP_MsgType* psNewMessage ); 00081 static void ObjectCommand( ABP_MsgType* psNewMessage ); 00082 00083 /******************************************************************************* 00084 ** Private Globals 00085 ******************************************************************************** 00086 */ 00087 00088 static const cop_ObjectType cop_sObject = 00089 { 00090 COP_OA_NAME_VALUE, /* Name. */ 00091 COP_OA_REV_VALUE, /* Revision. */ 00092 COP_OA_NUM_INST_VALUE, /* Number of instances. */ 00093 COP_OA_HIGHEST_INST_VALUE /* Highest instance number. */ 00094 }; 00095 00096 /******************************************************************************* 00097 ** Public Services 00098 ******************************************************************************** 00099 */ 00100 00101 void COP_ProcessCmdMsg( ABP_MsgType* psNewMessage ) 00102 { 00103 /* 00104 ** This function processes commands to the CANopen Object and its Instance. 00105 */ 00106 if( ABCC_GetMsgInstance( psNewMessage ) == ABP_INST_OBJ ) 00107 { 00108 /* 00109 ** The CANopen object Command. 00110 */ 00111 ObjectCommand( psNewMessage ); 00112 } 00113 else 00114 { 00115 /* 00116 ** The CANopen instance Command. 00117 */ 00118 InstanceCommand( psNewMessage ); 00119 } 00120 00121 ABCC_SendRespMsg( psNewMessage ); 00122 } 00123 00124 /******************************************************************************* 00125 ** Private Services 00126 ******************************************************************************** 00127 */ 00128 00129 /*------------------------------------------------------------------------------ 00130 ** Processes commands to COP Instances 00131 **------------------------------------------------------------------------------ 00132 ** Arguments: 00133 ** psNewMessage - Pointer to a ABP_MsgType message. 00134 ** 00135 ** Returns: 00136 ** None 00137 **------------------------------------------------------------------------------ 00138 */ 00139 static void InstanceCommand( ABP_MsgType* psNewMessage ) 00140 { 00141 /* 00142 ** This function processes commands to the DeviceNet Instance. 00143 */ 00144 if( ABCC_GetMsgInstance( psNewMessage ) != 1 ) 00145 { 00146 /* 00147 ** The Instance does not exist. 00148 */ 00149 ABP_SetMsgErrorResponse( psNewMessage, 1, ABP_ERR_UNSUP_INST ); 00150 return; 00151 } 00152 00153 switch ( ABCC_GetMsgCmdBits( psNewMessage ) ) 00154 { 00155 case ABP_CMD_GET_ATTR: 00156 { 00157 switch( ABCC_GetMsgCmdExt0( psNewMessage ) ) 00158 { 00159 #ifdef COP_IA_VENDOR_ID_ENABLE 00160 case ABP_COP_IA_VENDOR_ID: 00161 00162 /* 00163 ** Copy the 1st Instance 1 attribute (Vendor ID) to the message. 00164 */ 00165 ABCC_SetMsgData32( psNewMessage, COP_IA_VENDOR_ID_VALUE, 0 ); 00166 ABP_SetMsgResponse( psNewMessage, ABP_COP_IA_VENDOR_ID_DS ); 00167 break; 00168 #endif 00169 #ifdef COP_IA_PRODUCT_CODE_ENABLE 00170 case ABP_COP_IA_PRODUCT_CODE: 00171 00172 /* 00173 ** Copy the 2nd Instance 1 attribute (Product code) to the message. 00174 */ 00175 ABCC_SetMsgData32( psNewMessage, COP_IA_PRODUCT_CODE_VALUE, 0 ); 00176 ABP_SetMsgResponse( psNewMessage, ABP_COP_IA_PRODUCT_CODE_DS ); 00177 break; 00178 #endif 00179 #ifdef COP_IA_REV_MAJOR_ENABLE 00180 case ABP_COP_IA_MAJOR_REV: 00181 00182 /* 00183 ** Copy the 3rd Instance 1 attribute (Major revision) to the message. 00184 */ 00185 ABCC_SetMsgData16( psNewMessage, COP_IA_REV_MAJOR_VALUE, 0 ); 00186 ABP_SetMsgResponse( psNewMessage, ABP_COP_IA_MAJOR_REV_DS ); 00187 break; 00188 #endif 00189 #ifdef COP_IA_REV_MINOR_ENABLE 00190 case ABP_COP_IA_MINOR_REV: 00191 00192 /* 00193 ** Copy the 4th Instance 1 attribute (Minor revision) to the message. 00194 */ 00195 ABCC_SetMsgData16( psNewMessage, COP_IA_REV_MINOR_VALUE, 0 ); 00196 ABP_SetMsgResponse( psNewMessage, ABP_COP_IA_MINOR_REV_DS ); 00197 break; 00198 #endif 00199 #ifdef COP_IA_SERIAL_NUMBER_ENABLE 00200 case ABP_COP_IA_SERIAL_NUMBER: 00201 00202 /* 00203 ** Copy the 5th Instance 1 attribute (Serial number) to the message. 00204 */ 00205 ABCC_SetMsgData32( psNewMessage, COP_IA_SERIAL_NUMBER_VALUE, 0 ); 00206 ABP_SetMsgResponse( psNewMessage, ABP_COP_IA_SERIAL_NUMBER_DS ); 00207 break; 00208 #endif 00209 #ifdef COP_IA_MANF_DEV_NAME_ENABLE 00210 case ABP_COP_IA_MANF_DEV_NAME: 00211 { 00212 UINT16 iStrLength; 00213 00214 iStrLength = (UINT16)strlen( COP_IA_MANF_DEV_NAME_VALUE ); 00215 00216 /* 00217 ** Copy the 6th Instance 1 attribute (Manufacture device name) to the message. 00218 */ 00219 ABCC_SetMsgString( psNewMessage, COP_IA_MANF_DEV_NAME_VALUE, iStrLength, 0 ); 00220 ABP_SetMsgResponse( psNewMessage, iStrLength ); 00221 break; 00222 } 00223 #endif 00224 #ifdef COP_IA_MANF_HW_VER_ENABLE 00225 case ABP_COP_IA_MANF_HW_VER: 00226 { 00227 UINT16 iStrLength; 00228 00229 iStrLength = (UINT16)strlen( COP_IA_MANF_HW_VER_VALUE ); 00230 00231 /* 00232 ** Copy the 7th Instance 1 attribute (Manufacture hardware version) to the message. 00233 */ 00234 ABCC_SetMsgString( psNewMessage, COP_IA_MANF_HW_VER_VALUE, iStrLength, 0 ); 00235 ABP_SetMsgResponse( psNewMessage, iStrLength ); 00236 break; 00237 } 00238 #endif 00239 #ifdef COP_IA_MANF_SW_VER_ENABLE 00240 case ABP_COP_IA_MANF_SW_VER: 00241 { 00242 UINT16 iStrLength; 00243 00244 iStrLength = (UINT16)strlen( COP_IA_MANF_SW_VER_VALUE ); 00245 00246 /* 00247 ** Copy the 8th Instance 1 attribute (Manufacture software version) to the message. 00248 */ 00249 ABCC_SetMsgString( psNewMessage, COP_IA_MANF_SW_VER_VALUE, iStrLength, 0 ); 00250 ABP_SetMsgResponse( psNewMessage, iStrLength ); 00251 break; 00252 } 00253 #endif 00254 default: 00255 00256 /* 00257 ** Unsupported attribute. 00258 */ 00259 ABP_SetMsgErrorResponse( psNewMessage, 1, ABP_ERR_INV_CMD_EXT_0 ); 00260 break; 00261 } 00262 break; 00263 } 00264 default: 00265 00266 /* 00267 ** Unsupported command. 00268 */ 00269 ABP_SetMsgErrorResponse( psNewMessage, 1, ABP_ERR_UNSUP_CMD ); 00270 break; 00271 00272 } /* End of switch( Command number ) */ 00273 } 00274 00275 /*------------------------------------------------------------------------------ 00276 ** Processes commands to the COP Object (Instance 0) 00277 **------------------------------------------------------------------------------ 00278 ** Arguments: 00279 ** psNewMessage - Pointer to a ABP_MsgType message. 00280 ** 00281 ** Returns: 00282 ** None 00283 **------------------------------------------------------------------------------ 00284 */ 00285 static void ObjectCommand( ABP_MsgType* psNewMessage ) 00286 { 00287 /* 00288 ** This function processes commands to the CANopen Object (Instance 0). 00289 */ 00290 switch ( ABCC_GetMsgCmdBits( psNewMessage ) ) 00291 { 00292 case ABP_CMD_GET_ATTR: 00293 { 00294 switch( ABCC_GetMsgCmdExt0( psNewMessage ) ) 00295 { 00296 case ABP_OA_NAME: 00297 { 00298 UINT16 iStrLength; 00299 00300 /* 00301 ** Copy the attribute to a message. 00302 */ 00303 iStrLength = (UINT16)strlen( cop_sObject.pcName ); 00304 ABCC_SetMsgString( psNewMessage, cop_sObject.pcName, iStrLength, 0 ); 00305 ABP_SetMsgResponse( psNewMessage, (UINT8)iStrLength ); 00306 break; 00307 } 00308 00309 case ABP_OA_REV: 00310 00311 /* 00312 ** Copy the attribute to a message. 00313 */ 00314 ABCC_SetMsgData8( psNewMessage, cop_sObject.bRevision, 0 ); 00315 ABP_SetMsgResponse( psNewMessage, ABP_OA_REV_DS ); 00316 break; 00317 00318 case ABP_OA_NUM_INST: 00319 00320 /* 00321 ** Copy the attribute to a message. 00322 */ 00323 ABCC_SetMsgData16( psNewMessage, cop_sObject.iNumberOfInstances, 0 ); 00324 ABP_SetMsgResponse( psNewMessage, ABP_OA_NUM_INST_DS ); 00325 break; 00326 00327 case ABP_OA_HIGHEST_INST: 00328 00329 /* 00330 ** Copy the attribute to a message. 00331 */ 00332 ABCC_SetMsgData16( psNewMessage, cop_sObject.iHighestInstanceNo, 0 ); 00333 ABP_SetMsgResponse( psNewMessage, ABP_OA_HIGHEST_INST_DS ); 00334 break; 00335 00336 default: 00337 00338 /* 00339 ** Unsupported attribute. 00340 */ 00341 ABP_SetMsgErrorResponse( psNewMessage, 1, ABP_ERR_INV_CMD_EXT_0 ); 00342 break; 00343 00344 } /* End of switch( Attribute number ) */ 00345 00346 break; 00347 } 00348 00349 default: 00350 00351 /* 00352 ** Unsupported command. 00353 */ 00354 ABP_SetMsgErrorResponse( psNewMessage, 1, ABP_ERR_UNSUP_CMD ); 00355 break; 00356 00357 } /* End of switch( Command number ) */ 00358 } 00359 00360 #endif /* COP_OBJ_ENABLE */
Generated on Tue Jul 12 2022 15:51:57 by
