【灵冰肌】CAPL编程语言基础学习

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1CAPLProgramming-BasicsPreparedBy百度灵冰肌.Date:2015-06-022OverviewOfCAPL•ForCAN-basednetworks,modules,anddistributedembeddedsystems,CommunicationApplicationProgrammingLanguage,CAPL,makesitpossibletoprogramtheCANalyzerfordeveloper-specificapplicationsthatusetheCANprotocol.•CAPLmayalsobeusedintheCANoetoolfordistributedproductdevelopment.•ThesyntaxisC-like,butthereareanumberofsupplementalfeaturesnotincludedinC:–Amissingresulttypeisinterpretedasvoid–AnemptyparameterlistispermittedasinC++–Overloadingoffunctions(i.e.multiplefunctionswiththesamenamebutdifferentparameterlists)ispossibleasinC++–AparametercheckisperformedasinC++–Arraysofarbitrarydimensionandsizemaybepassed–CAPLprovidesyouwithalibraryofintrinsicfunctions.3ApplicationUsesforCAPL•CreateandmodifythebehavioroftheCANalyzermeasurementenvironment.•Designacustommoduletester.•Createablackboxtosimulatetherestofthenetwork.•Createamodulesimulator.•Createacustommodulemanufacturingtester.•Createacustommodulediagnosticorservicetool.•Createprogramstoperformcustomizedanalysisofnetworklogging(playback)files.•Createcomplexloggingfilters.•Createacomprehensivemessageordatacontentgenerationtesterformodule/networkvalidation.•CreateafunctionalgatewaybetweentodifferentCANnetworks.4SimulationUsesforCAPL•SimulatenodeorsystembehaviorusingreadableEnglishratherthanhex.•Simulateeventmessages,periodicmessages,orconditionallyrepetitivemessages.•SimulatehumaneventslikebuttonpressesusingthePCkeyboard•Simulatetimednodeornetworkevents.•Simulatemultipletimeeventseachwithitsownprogrammablebehavior.•Simulatenormaloperation,diagnosticoperation,ormanufacturingoperation.•Simulatechangesinphysicalparametersorsymbolicvalues(“ON”,“OFF”).•GenerateCANerrorframestoevaluatemodulenetworksoftwarestrategy.•Simulatemoduleandnetworkandnetworkfaultstoevaluatelimitedoperationstrategy.•Simulatesimpleorcomplexfunctions(sin,cos).5CAPL–EventDrivenSoftware6CAPLProgrammingEnvironment7CAPLEVENTS8CANalyzer–CAPLProgrammingEnvironment9CANoe–CAPLProgrammingEnvironment10CAPLProgramOrganization•1.GlobalVariableDeclarations–Inthissection,youdeclarevariablesthatcanbereadorchangedbyanypartofyourCAPLprogram.–Itisagoodideatodeclaremessagesandtimersinthissection.•2.EventProcedures–Eventproceduresareblocksofcodethatareexecutedwhenaneventoccurs.–CAPLallowsyoutodefineeventproceduresforseveraldifferentkindsofevents.–Mostofyourprogramcodewillbeineventprocedures,sincemostactionsareperformedafteranevent,suchasamessagebeingreceivedontheCANbus.–Eventprocedurescannotreturnavalue.•3.User-DefinedFunctions–YourprogramscancontainproceduresthatcanbeusedtocomplementCAPL’sbuilt-infunctions.–TheseprocedurescancontainanylegalCAPLcodeandaregloballyaccessible.–Puttingfrequently-usedcodeinaproceduremakesprogramsmoreefficient.–User-definedfunctionscanreturnavalueofanysimpletype.11CAPLBrowser-Organization12CAPLFileTypes•CAPLutilizestwotypesoffiles.•Sourcecodefiles(*.CAN)containCAPLprogramsaswellasspecialformattingcodesusedbytheCAPLBrowser.•ThesefilesareinASCIItextformat.•Whenyoucompilea.CANfileintheCAPLBrowser,CANalyzer,orCANoeabinaryfilewiththeextension.CBF(CAPLBinaryFile)iscreated.•ThesebinaryfilescanonlybeinterpretedandexecutedbyaCANalyzerorCANoesimulation.13CAPL–DataTypes14CAPL-Operators15ControlStatements–if&if-else16ControlStatements–switch17ControlStatements–while18ControlStatements–(do-while)19ControlStatements–For20ControlStatements–Break&Continue21ControlStatements–Return&“this”Keyword22Functionoverloadingisallowed•CAPLhastheabilitytooverloadfunctions,similartothewayC++does.•Thismeansthatmultiplefunctionscanhavethesamenamebutdifferentparameterlists.•Thefunctionthatiscalleddependsontheparametersthatarepassed.•Forexample,wecouldcreatetwofunctionsthatusewrite()tooutputdifferenttypesofnumbers:voidprint(doublenum){write(“Floatingpoint%f”,num);}voidprint(intnum,charunits[]){write(“%d%s”,num,units);}•Aftersettingthesefunctionsup,wegettheseresults:print(5.7);“Floatingpoint5.700000”print(2.5,“angstroms”,22);“2angstroms”23Localvariablesarestatic•InaCAPLfunction,incontrasttoC,alllocallydeclaredvariablesarestatic.Thismeansthatonceavariableisdeclaredandassignedavalueduringoneiterationofafunction,thevariableretainsthatvaluethenexttimethefunctioniscalled.ThiscancauseconfusiontoprogrammersaccustomedtotheCsemantic.•Forexample:voidmyFunc(){bytevalue=10;write(“value=%d”,value);value=35;}•ThefirsttimemyFunciscalled,itwillprint“value=10”asexpected.However,thesecondandallsubsequenttimesthefunctioniscalled,itwillprint“value=35”.Duetothissemantic,thepreferredwaytoinitializenon-staticvariablesistouseaseparateassignmentafterthevariableshasbeendeclared.Inthisexample,thevariablesareresettotheirinitialvaluesatthebeginningofeveryiterationofthefunction:•voidmyFunc(){//Variabledeclarationsbytevalue;intx,y;//Variableinitializationsvalue=10;x=0;y=5;//Maincodeofthefunction...}24VariableandObjectTypesandDeclarationsExamplesofvariabledeclarations:intj,k=2;/*j=0implicitly*/doublex=33.7;charp;Examplesofarraydeclarations:longdata[10];intvector[5]={0,1,2,3,4};intmatrix[2][4]={{2,4,6

1 / 35
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功