main.c 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * www.st.com/SLA0044
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. #include "cmsis_os.h"
  23. #include "FreeRTOS.h"
  24. #include "task.h"
  25. #include "timers.h"
  26. #include "event_groups.h"
  27. /* Private includes ----------------------------------------------------------*/
  28. /* USER CODE BEGIN Includes */
  29. #include "string.h"
  30. #include "stdio.h"
  31. #include "usart.h"
  32. #include "config.h"
  33. #include "rkg.h"
  34. #include "cang.h"
  35. #include "kzq.h"
  36. #include "level.h"
  37. #include "tem.h"
  38. #include "angle.h"
  39. #include "xyf.h"
  40. #include "hdf.h"
  41. #include "bgy.h"
  42. #include "yqhs.h"
  43. #include "pressure.h"
  44. #include "iap.h"
  45. /* USER CODE END Includes */
  46. #if 0
  47. #define IR_ROM1 0x08000000
  48. #else
  49. #define IR_ROM1 0x08020000
  50. #endif
  51. /* Private typedef -----------------------------------------------------------*/
  52. /* USER CODE BEGIN PTD */
  53. #define ADDR_Is_In_ElecFence 0x05D0 // 1488 车是否在电子围栏内
  54. uint8_t REST = 0;
  55. uint32_t usage_Tsk12=0;
  56. //============================================================
  57. sT2C_RemoteCaliDat T2C_RemoteCaliDat001 =
  58. {
  59. 0x3901,
  60. 0x9551000,
  61. 0x0003,
  62. ADDR_Is_In_ElecFence,//0x0000,
  63. 0x0001, //操作的数据个数
  64. 0x55aa55aa, //保留字4字节
  65. {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,\
  66. 25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44},
  67. 0x7788,//保留字2字节
  68. 0x99aa //校验2字节
  69. };
  70. sT2C_RemoteCaliDat *pT2C_RemoteCaliData = &T2C_RemoteCaliDat001;
  71. /* USER CODE END PTD */
  72. /* Private define ------------------------------------------------------------*/
  73. /* USER CODE BEGIN PD */
  74. #define RT_ERRORCNT 60 //串口收发数据错误上限
  75. /* USER CODE END PD */
  76. /* Private macro -------------------------------------------------------------*/
  77. /* USER CODE BEGIN PM */
  78. uint8_t CMD_KZQ[256] =
  79. {0x39,0x01,0x95,0x50,0x00,0x01,0x00,0x03,
  80. 0x00,0x00,0x00,0x00,0x95,0x05,0xaa,0xaa,
  81. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  82. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  83. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  84. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  85. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  86. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  87. };
  88. //卸油阀指令
  89. uint8_t CMD_XYF[8] = {0x11,0x03,0x00,0x00,0x00,0x01,0x00,0x00};
  90. uint8_t Data_Head[2] = {0x0D,0x0A};
  91. //海底阀指令
  92. uint8_t CMD_HDF[16] =
  93. {0x21,0x03,0x2a,0,0,0,0,0,0xaa,0xbb,0xcc,0xdd,0xee,0xdd,0xcc,0xbb};
  94. //人孔盖指令31 03 00 02 00 02
  95. uint8_t CMD_RKG[8] = {0x31,0x03,0x00,0x02,0x00,0x02,0x00,0x00};
  96. uint8_t CMD_RKG_CBM[12] = {0x0D,0x0A,0x31,0x03,0x00,0x02,0x00,0x02,0x00,0x00,0x0D,0x0A};
  97. uint8_t CMD_RKG_XG[12] = {0x41,0x03,0x00,0x02,0x00,0x02,0x00,0x00};
  98. //油气回收
  99. uint8_t CMD_YQHS[8] = {0xE4,0x03,0x00,0x00,0x00,0x01,0x00,0x00};
  100. //倾角传感器读取协议 01 03 00 02 00 02 CRC
  101. uint8_t CMD_Angle_XY[] = {0x71,0x03,0x00,0x3d,0x00,0x03,0x00,0x00};
  102. //卸尽传感器读取协议
  103. uint8_t CMD_Biguayou[] = {0x81,0x03,0x00,0x00,0x00,0x01,0x9B,0xCA};
  104. //uint8_t CMD_Angle_X[] = {0xE0,0x03,0x00,0x02,0x00,0x02,0x00,0x00};
  105. //uint8_t CMD_Angle_Y[] = {0xE1,0x03,0x00,0x02,0x00,0x02,0x00,0x00};
  106. uint8_t CMD_LDYW[8]={LEVEL_STARTADDR,0x04,0x0a,0x0f,0x00,0x02, 0, 0};//设备地址,功能码,地址4字节 反回:设备地址,功能码,数据长度,数据4字节
  107. uint8_t CMD_GetTempAndYewei[8]={0x51, 0x04, 00, 00, 00, 0x10, 0x03 ,0xae};//读取编号为04地址的温度传感器数据
  108. //61-6f 03 00 04 00 01 C6 8A----读取华天传感器的第1个温度点,地址为x10;最接近电子仓的温度点
  109. uint8_t CMD_GetTempHuaTian[8]={0x61, 0x03, 00, 04, 00, 01,0,0};//读取华天传感器的第一个温度点
  110. uint8_t CMD_TemAng[8]={TEM_STARTADDR, 0x03, 00, 00, 00, 02,0,0};//FST100-611 通过模拟量模块,读取温度
  111. uint8_t CMD_Temperature[8]={TEM_STARTADDR, 0x03, 00, 02, 00, 02,0,0};
  112. uint8_t CMD_Pressure[8]={PRESSURE_STARTADDR, 0x03, 0x00, 0x00, 0x00, 0x02,0,0}; //FST800-801 读取压力数据, 没有标零指令
  113. //uint8_t CMD_FSTTem[8]={TEM_STARTADDR, 0x03, 00, 02, 00, 02,0,0};//FST100-1007G371C //温压一体, 读温度指令
  114. //uint8_t CMD_FSTPressure[8]={PRESSURE_STARTADDR, 0x03, 00, 00, 00, 02,0,0};//FST100-1007G371C //温压一体, 读压力指令
  115. //磁编码传感器读取协议 。
  116. /* USER CODE END PM */
  117. /* Private variables ---------------------------------------------------------*/
  118. CRC_HandleTypeDef hcrc;
  119. DAC_HandleTypeDef hdac;
  120. DMA_HandleTypeDef hdma_dac_ch2;
  121. TIM_HandleTypeDef htim1;
  122. TIM_HandleTypeDef htim4;
  123. UART_HandleTypeDef huart5;
  124. UART_HandleTypeDef huart1;
  125. UART_HandleTypeDef huart2;
  126. UART_HandleTypeDef huart3;
  127. DMA_HandleTypeDef hdma_usart1_rx;
  128. DMA_HandleTypeDef hdma_usart1_tx;
  129. DMA_HandleTypeDef hdma_usart2_rx;
  130. DMA_HandleTypeDef hdma_usart3_rx;
  131. uint8_t bufMain[128];
  132. /* Definitions for defaultTask */
  133. osThreadId_t defaultTaskHandle;
  134. const osThreadAttr_t defaultTask_attributes = {
  135. .name = "defaultTask",
  136. .stack_size = 128 * 4,
  137. .priority = (osPriority_t) osPriorityNormal,
  138. };
  139. /* Definitions for myTask02 */
  140. osThreadId_t myTask02Handle;
  141. const osThreadAttr_t myTask02_attributes = {
  142. .name = "myTask02",
  143. .stack_size = 256 * 4,
  144. .priority = (osPriority_t) osPriorityLow,
  145. };
  146. /* Definitions for myTask03 */
  147. osThreadId_t myTask03Handle;
  148. const osThreadAttr_t myTask03_attributes = {
  149. .name = "myTask03",
  150. .stack_size = 256 * 4,
  151. .priority = (osPriority_t) osPriorityLow,
  152. };
  153. /* Definitions for myTask04 */
  154. osThreadId_t myTask04Handle;
  155. const osThreadAttr_t myTask04_attributes = {
  156. .name = "myTask04",
  157. .stack_size = 256 * 4,
  158. .priority = (osPriority_t) osPriorityLow,
  159. };
  160. /* Definitions for myTask05 */
  161. osThreadId_t myTask05Handle;
  162. const osThreadAttr_t myTask05_attributes = {
  163. .name = "myTask05",
  164. .stack_size = 128 * 4,
  165. .priority = (osPriority_t) osPriorityLow,
  166. };
  167. /* Definitions for myTask06 */
  168. osThreadId_t myTask06Handle;
  169. const osThreadAttr_t myTask06_attributes = {
  170. .name = "myTask06",
  171. .stack_size = 128 * 4,
  172. .priority = (osPriority_t) osPriorityLow,
  173. };
  174. /* Definitions for myTask07 */
  175. osThreadId_t myTask07Handle;
  176. const osThreadAttr_t myTask07_attributes = {
  177. .name = "myTask07",
  178. .stack_size = 128 * 4,
  179. .priority = (osPriority_t) osPriorityLow,
  180. };
  181. /* Definitions for myTask08 */
  182. osThreadId_t myTask08Handle;
  183. const osThreadAttr_t myTask08_attributes = {
  184. .name = "myTask08",
  185. .stack_size = 128 * 4,
  186. .priority = (osPriority_t) osPriorityLow,
  187. };
  188. /* Definitions for myTask09 */
  189. osThreadId_t myTask09Handle;
  190. const osThreadAttr_t myTask09_attributes = {
  191. .name = "myTask09",
  192. .stack_size = 128 * 4,
  193. .priority = (osPriority_t) osPriorityLow,
  194. };
  195. /* Definitions for myTask10 */
  196. osThreadId_t myTask10Handle;
  197. const osThreadAttr_t myTask10_attributes = {
  198. .name = "myTask10",
  199. .stack_size = 128 * 4,
  200. .priority = (osPriority_t) osPriorityLow,
  201. };
  202. /* Definitions for myTask11 */
  203. osThreadId_t myTask11Handle;
  204. const osThreadAttr_t myTask11_attributes = {
  205. .name = "myTask11",
  206. .stack_size = 128 * 4,
  207. .priority = (osPriority_t) osPriorityLow,
  208. };
  209. /* Definitions for myTask12 */
  210. osThreadId_t myTask12Handle;
  211. const osThreadAttr_t myTask12_attributes = {
  212. .name = "myTask12",
  213. .stack_size = 128 * 4,
  214. .priority = (osPriority_t) (osPriorityLow-6),
  215. };
  216. /* Definitions for myQueue01 */
  217. osMessageQueueId_t myQueue01Handle;
  218. const osMessageQueueAttr_t myQueue01_attributes = {
  219. .name = "myQueue01"
  220. };
  221. /* Definitions for myQueue02 */
  222. osMessageQueueId_t myQueue02Handle;
  223. const osMessageQueueAttr_t myQueue02_attributes = {
  224. .name = "myQueue02"
  225. };
  226. /* Definitions for myQueue03 */
  227. osMessageQueueId_t myQueue03Handle;
  228. const osMessageQueueAttr_t myQueue03_attributes = {
  229. .name = "myQueue03"
  230. };
  231. /* Definitions for myQueue04 */
  232. osMessageQueueId_t myQueue04Handle;
  233. const osMessageQueueAttr_t myQueue04_attributes = {
  234. .name = "myQueue04"
  235. };
  236. /* Definitions for myQueue05 */
  237. osMessageQueueId_t myQueue05Handle;
  238. const osMessageQueueAttr_t myQueue05_attributes = {
  239. .name = "myQueue05"
  240. };
  241. /* Definitions for myQueue06 */
  242. osMessageQueueId_t myQueue06Handle;
  243. const osMessageQueueAttr_t myQueue06_attributes = {
  244. .name = "myQueue06"
  245. };
  246. /* Definitions for myTimer01 */
  247. osTimerId_t myTimer01Handle;
  248. const osTimerAttr_t myTimer01_attributes = {
  249. .name = "myTimer01"
  250. };
  251. /* Definitions for myTimer02 */
  252. osTimerId_t myTimer02Handle;
  253. const osTimerAttr_t myTimer02_attributes = {
  254. .name = "myTimer02"
  255. };
  256. /* Definitions for myTimer03 */
  257. osTimerId_t myTimer03Handle;
  258. const osTimerAttr_t myTimer03_attributes = {
  259. .name = "myTimer03"
  260. };
  261. /* Definitions for myTimer04 */
  262. osTimerId_t myTimer04Handle;
  263. const osTimerAttr_t myTimer04_attributes = {
  264. .name = "myTimer04"
  265. };
  266. /* Definitions for myTimer05 */
  267. osTimerId_t myTimer05Handle;
  268. const osTimerAttr_t myTimer05_attributes = {
  269. .name = "myTimer05"
  270. };
  271. /* Definitions for myTimer06 */
  272. osTimerId_t myTimer06Handle;
  273. const osTimerAttr_t myTimer06_attributes = {
  274. .name = "myTimer06"
  275. };
  276. /* Definitions for myTimer07 */
  277. osTimerId_t myTimer07Handle;
  278. const osTimerAttr_t myTimer07_attributes = {
  279. .name = "myTimer07"
  280. };
  281. /* Definitions for myTimer08 */
  282. osTimerId_t myTimer08Handle;
  283. const osTimerAttr_t myTimer08_attributes = {
  284. .name = "myTimer08"
  285. };
  286. /* Definitions for myTimer09 */
  287. osTimerId_t myTimer09Handle;
  288. const osTimerAttr_t myTimer09_attributes = {
  289. .name = "myTimer09"
  290. };
  291. /* Definitions for myTimer10 */
  292. osTimerId_t myTimer10Handle;
  293. const osTimerAttr_t myTimer10_attributes = {
  294. .name = "myTimer10"
  295. };
  296. /* Definitions for myMutex01 */
  297. osMutexId_t myMutex01Handle;
  298. const osMutexAttr_t myMutex01_attributes = {
  299. .name = "myMutex01"
  300. };
  301. /* Definitions for myMutex02 */
  302. osMutexId_t myMutex02Handle;
  303. const osMutexAttr_t myMutex02_attributes = {
  304. .name = "myMutex02"
  305. };
  306. /* Definitions for myMutex03 */
  307. osMutexId_t myMutex03Handle;
  308. const osMutexAttr_t myMutex03_attributes = {
  309. .name = "myMutex03"
  310. };
  311. /* Definitions for myMutex04 */
  312. osMutexId_t myMutex04Handle;
  313. const osMutexAttr_t myMutex04_attributes = {
  314. .name = "myMutex04"
  315. };
  316. /* Definitions for myMutex05 */
  317. osMutexId_t myMutex05Handle;
  318. const osMutexAttr_t myMutex05_attributes = {
  319. .name = "myMutex05"
  320. };
  321. /* Definitions for myMutex06 */
  322. osMutexId_t myMutex06Handle;
  323. const osMutexAttr_t myMutex06_attributes = {
  324. .name = "myMutex06"
  325. };
  326. /* Definitions for myMutex07 */
  327. osMutexId_t myMutex07Handle;
  328. const osMutexAttr_t myMutex07_attributes = {
  329. .name = "myMutex07"
  330. };
  331. /* Definitions for myMutex08 */
  332. osMutexId_t myMutex08Handle;
  333. const osMutexAttr_t myMutex08_attributes = {
  334. .name = "myMutex08"
  335. };
  336. /* Definitions for myRecursiveMutex01 */
  337. osMutexId_t myRecursiveMutex01Handle;
  338. const osMutexAttr_t myRecursiveMutex01_attributes = {
  339. .name = "myRecursiveMutex01",
  340. .attr_bits = osMutexRecursive,
  341. };
  342. /* Definitions for myRecursiveMutex02 */
  343. osMutexId_t myRecursiveMutex02Handle;
  344. const osMutexAttr_t myRecursiveMutex02_attributes = {
  345. .name = "myRecursiveMutex02",
  346. .attr_bits = osMutexRecursive,
  347. };
  348. /* Definitions for myRecursiveMutex03 */
  349. osMutexId_t myRecursiveMutex03Handle;
  350. const osMutexAttr_t myRecursiveMutex03_attributes = {
  351. .name = "myRecursiveMutex03",
  352. .attr_bits = osMutexRecursive,
  353. };
  354. /* Definitions for myRecursiveMutex04 */
  355. osMutexId_t myRecursiveMutex04Handle;
  356. const osMutexAttr_t myRecursiveMutex04_attributes = {
  357. .name = "myRecursiveMutex04",
  358. .attr_bits = osMutexRecursive,
  359. };
  360. /* Definitions for myBinarySem01 */
  361. osSemaphoreId_t myBinarySem01Handle;
  362. const osSemaphoreAttr_t myBinarySem01_attributes = {
  363. .name = "myBinarySem01"
  364. };
  365. /* Definitions for myBinarySem02 */
  366. osSemaphoreId_t myBinarySem02Handle;
  367. const osSemaphoreAttr_t myBinarySem02_attributes = {
  368. .name = "myBinarySem02"
  369. };
  370. /* Definitions for myBinarySem03 */
  371. osSemaphoreId_t myBinarySem03Handle;
  372. const osSemaphoreAttr_t myBinarySem03_attributes = {
  373. .name = "myBinarySem03"
  374. };
  375. /* Definitions for myBinarySem04 */
  376. osSemaphoreId_t myBinarySem04Handle;
  377. const osSemaphoreAttr_t myBinarySem04_attributes = {
  378. .name = "myBinarySem04"
  379. };
  380. /* Definitions for myBinarySem05 */
  381. osSemaphoreId_t myBinarySem05Handle;
  382. const osSemaphoreAttr_t myBinarySem05_attributes = {
  383. .name = "myBinarySem05"
  384. };
  385. /* Definitions for myBinarySem06 */
  386. osSemaphoreId_t myBinarySem06Handle;
  387. const osSemaphoreAttr_t myBinarySem06_attributes = {
  388. .name = "myBinarySem06"
  389. };
  390. /* Definitions for myBinarySem07 */
  391. osSemaphoreId_t myBinarySem07Handle;
  392. const osSemaphoreAttr_t myBinarySem07_attributes = {
  393. .name = "myBinarySem07"
  394. };
  395. /* Definitions for myBinarySem08 */
  396. osSemaphoreId_t myBinarySem08Handle;
  397. const osSemaphoreAttr_t myBinarySem08_attributes = {
  398. .name = "myBinarySem08"
  399. };
  400. /* Definitions for myCountingSem01 */
  401. osSemaphoreId_t myCountingSem01Handle;
  402. const osSemaphoreAttr_t myCountingSem01_attributes = {
  403. .name = "myCountingSem01"
  404. };
  405. /* Definitions for myCountingSem02 */
  406. osSemaphoreId_t myCountingSem02Handle;
  407. const osSemaphoreAttr_t myCountingSem02_attributes = {
  408. .name = "myCountingSem02"
  409. };
  410. /* Definitions for myCountingSem03 */
  411. osSemaphoreId_t myCountingSem03Handle;
  412. const osSemaphoreAttr_t myCountingSem03_attributes = {
  413. .name = "myCountingSem03"
  414. };
  415. /* Definitions for myCountingSem04 */
  416. osSemaphoreId_t myCountingSem04Handle;
  417. const osSemaphoreAttr_t myCountingSem04_attributes = {
  418. .name = "myCountingSem04"
  419. };
  420. /* Definitions for myEvent01 */
  421. osEventFlagsId_t myEvent01Handle;
  422. const osEventFlagsAttr_t myEvent01_attributes = {
  423. .name = "myEvent01"
  424. };
  425. /* Definitions for myEvent02 */
  426. osEventFlagsId_t myEvent02Handle;
  427. const osEventFlagsAttr_t myEvent02_attributes = {
  428. .name = "myEvent02"
  429. };
  430. /* Definitions for myEvent03 */
  431. osEventFlagsId_t myEvent03Handle;
  432. const osEventFlagsAttr_t myEvent03_attributes = {
  433. .name = "myEvent03"
  434. };
  435. /* Definitions for myEvent04 */
  436. osEventFlagsId_t myEvent04Handle;
  437. const osEventFlagsAttr_t myEvent04_attributes = {
  438. .name = "myEvent04"
  439. };
  440. /* Definitions for myEvent05 */
  441. osEventFlagsId_t myEvent05Handle;
  442. const osEventFlagsAttr_t myEvent05_attributes = {
  443. .name = "myEvent05"
  444. };
  445. /* Definitions for myEvent06 */
  446. osEventFlagsId_t myEvent06Handle;
  447. const osEventFlagsAttr_t myEvent06_attributes = {
  448. .name = "myEvent06"
  449. };
  450. /* Definitions for myEvent07 */
  451. osEventFlagsId_t myEvent07Handle;
  452. const osEventFlagsAttr_t myEvent07_attributes = {
  453. .name = "myEvent07"
  454. };
  455. /* Definitions for myEvent08 */
  456. osEventFlagsId_t myEvent08Handle;
  457. const osEventFlagsAttr_t myEvent08_attributes = {
  458. .name = "myEvent08"
  459. };
  460. /* USER CODE BEGIN PV */
  461. /* USER CODE END PV */
  462. /* Private function prototypes -----------------------------------------------*/
  463. void SystemClock_Config(void);
  464. static void MX_GPIO_Init(void);
  465. static void MX_DMA_Init(void);
  466. static void MX_USART1_UART_Init(void);
  467. static void MX_UART5_Init(void);
  468. static void MX_USART2_UART_Init(void);
  469. static void MX_USART3_UART_Init(void);
  470. static void MX_CRC_Init(void);
  471. static void MX_DAC_Init(void);
  472. static void MX_TIM1_Init(void);
  473. static void MX_TIM4_Init(void);
  474. void StartDefaultTask(void *argument);
  475. void StartTask02(void *argument);
  476. void StartTask03(void *argument);
  477. void StartTask04(void *argument);
  478. void StartTask05(void *argument);
  479. void StartTask06(void *argument);
  480. void StartTask07(void *argument);
  481. void StartTask08(void *argument);
  482. void StartTask09(void *argument);
  483. void StartTask10(void *argument);
  484. void StartTask11(void *argument);
  485. void StartTask12(void *argument);
  486. void Callback01(void *argument);
  487. void Callback02(void *argument);
  488. void Callback03(void *argument);
  489. void Callback04(void *argument);
  490. void Callback05(void *argument);
  491. void Callback06(void *argument);
  492. void Callback07(void *argument);
  493. void Callback08(void *argument);
  494. void Callback09(void *argument);
  495. void Callback010(void *argument);
  496. void Cang_Init(void);
  497. static void MX_NVIC_Init(void);
  498. // for debug,将信息输出到指定的uart总线上
  499. static void DumpMsg(uint8_t *msg)
  500. {
  501. HAL_GPIO_WritePin(GPIOA,con03_uart2_kongzhiqi_Pin,GPIO_PIN_RESET);
  502. delay_sys_us(80);
  503. HAL_UART_Transmit_IT(&huart2,msg,strlen(msg));
  504. while (huart2.gState == HAL_UART_STATE_BUSY_TX)
  505. {
  506. osDelay(1);
  507. }
  508. delay_sys_us(80);
  509. HAL_GPIO_WritePin(GPIOA,con03_uart2_kongzhiqi_Pin,GPIO_PIN_SET);
  510. }
  511. #include <stdarg.h>
  512. void printx(const char *log,...)
  513. {
  514. osMutexAcquire(myMutex01Handle, portMAX_DELAY);
  515. va_list ap;
  516. va_start(ap,log);
  517. vsnprintf(bufMain,sizeof(bufMain),log,ap);
  518. va_end(ap);
  519. DumpMsg(bufMain);
  520. osMutexRelease(myMutex01Handle);
  521. }
  522. /* USER CODE BEGIN PFP */
  523. void Flash_ReadBytes(uint16_t* sorBuf,uint32_t FlashAddr,uint16_t len)
  524. {
  525. uint16_t* p = sorBuf;
  526. uint8_t i = 0,j = 0;
  527. uint32_t addr = FlashAddr;
  528. while(len--)
  529. {
  530. i = *(uint32_t*)addr++;
  531. j = *(uint32_t*)addr++;
  532. *p++ = j<<8|i;
  533. }
  534. }
  535. uint16_t Flashbuf[2048]__attribute__ ((at(0X20001000)));// {0};
  536. //uint8_t UART_RX_BUF[1024] __attribute__ ((at(0X20001000)));
  537. void Flash_WriteBytes(uint16_t* sorBuf,uint32_t FlashAddr,uint16_t len)
  538. {
  539. uint32_t Offset_ADDR = 0,Page_StartAddr = 0,i = 0;
  540. Offset_ADDR = FlashAddr%0x800;
  541. Page_StartAddr = FlashAddr - Offset_ADDR;
  542. //设置PageError
  543. uint32_t PageError = 0;
  544. FLASH_EraseInitTypeDef f;
  545. f.TypeErase = FLASH_TYPEERASE_PAGES;
  546. __nop();
  547. f.PageAddress =Page_StartAddr;
  548. f.NbPages = 1;
  549. Flash_ReadBytes(Flashbuf,Page_StartAddr,0x400);
  550. for(i = 0;i<len;i++)
  551. Flashbuf[Offset_ADDR/2+i] = sorBuf[i];
  552. //1、解锁FLASH
  553. HAL_FLASH_Unlock();
  554. __nop();
  555. //2、擦除FLASH
  556. //初始化FLASH_EraseInitTypeDef
  557. //调用擦除函数
  558. HAL_FLASHEx_Erase(&f, &PageError);
  559. __nop();
  560. //3、对FLASH烧写
  561. for(uint16_t i = 0;i< 0x400 ;i++)
  562. {
  563. HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD , Page_StartAddr + (i * 2), Flashbuf[i]);
  564. }
  565. //4、锁住FLASH
  566. HAL_FLASH_Lock();
  567. }
  568. typedef union{
  569. float Ldcal_zero_temp; //青鸟贵和磁致伸缩液位温度一体传感器
  570. uint8_t arr[4];
  571. }Hex_to_float1;
  572. Hex_to_float1 hex_to_float1;
  573. void Cang_Init(void)
  574. {
  575. Cang_Inf* pcang = &cang_inf;
  576. RKG_Inf* prkg = rkg_inf;
  577. XYF_Inf* pxyf = xyf_inf;
  578. HDF_Inf* phdf = hdf_inf;
  579. Angle_Inf* pangle = &angle_inf;
  580. Level_Inf* plevel = level_inf;
  581. Tem_Inf* ptem = tem_inf;
  582. uint16_t Flash_buff[64] = {0};
  583. uint16_t i = 0;
  584. Flash_ReadBytes(Flash_buff,ADDR_CANG_NUM,6);
  585. if(Flash_buff[0] == 0xffff)
  586. {
  587. //Flash_WriteBytes(Volume_1cang,ADD_CANG1_TABLE,200);
  588. //Flash_WriteBytes(Volume_2cang,ADD_CANG2_TABLE,200);
  589. //Flash_WriteBytes(Volume_3cang,ADD_CANG3_TABLE,200);
  590. //Flash_WriteBytes(Volume_4cang,ADD_CANG4_TABLE,200);
  591. pcang->Cang_Num = 3; //默认三仓
  592. }
  593. else
  594. pcang->Cang_Num = Flash_buff[0];
  595. if(Flash_buff[1] == 0xffff)
  596. {
  597. i = 0;
  598. while(i < pcang->Cang_Num)
  599. {
  600. pcang->RKG_Num[i] = 1; //默认每仓1人孔大盖
  601. pcang->RKG_DG = 1; //默认有大盖
  602. i++;
  603. }
  604. }
  605. else
  606. {
  607. i = 0;
  608. while(i <pcang->Cang_Num)
  609. {
  610. pcang->RKG_Num[i] = Flash_buff[1]; //默认每仓1人孔盖
  611. pcang->RKG_DG = Flash_buff[1];
  612. i++;
  613. }
  614. }
  615. if(Flash_buff[2] == 0xffff)
  616. pcang->RKG_XG = 0; //默认无人孔小盖
  617. else
  618. pcang->RKG_XG = Flash_buff[2];
  619. if(Flash_buff[3] == 0xffff)
  620. {
  621. i = 0;
  622. while(i <pcang->Cang_Num)
  623. {
  624. pcang->XYF_INSTALL = 1; // 默认有卸油阀SLM
  625. pcang->XYF_Num[i] = 1; //默认每仓1卸油阀
  626. i++;
  627. }
  628. }
  629. else
  630. {
  631. i = 0;
  632. while(i <pcang->Cang_Num)
  633. {
  634. pcang->XYF_INSTALL = 1; // 默认有卸油阀SLM
  635. pcang->XYF_Num[i] = Flash_buff[3]; i++;
  636. }
  637. }
  638. if(Flash_buff[4] == 0xffff)
  639. {
  640. i = 0;
  641. while(i <pcang->Cang_Num)
  642. {
  643. pcang->HDF_INSTALL = 1;
  644. pcang->HDF_Num[i] = 1; //默认每仓1海底阀
  645. i++;
  646. }
  647. }
  648. else
  649. {
  650. i = 0;
  651. while(i <pcang->Cang_Num)
  652. {
  653. pcang->HDF_INSTALL = 1;//slm
  654. pcang->HDF_Num[i] = Flash_buff[4];
  655. i++;
  656. }
  657. }
  658. Flash_ReadBytes(Flash_buff,ADDR_RKGSENSOR_TYPE,1);
  659. if(Flash_buff[0] == 0xffff)
  660. pcang->RKG_Type = 1; //默认人孔盖角度传感器 1磁电编码传感器
  661. else
  662. pcang->RKG_Type = Flash_buff[0];
  663. Flash_ReadBytes(Flash_buff,ADDR_XYFSENSOR_TYPE,1);
  664. if(Flash_buff[0] == 0xffff)
  665. pcang->XYF_Type = 0; //默认卸油阀霍尔二合一
  666. else
  667. pcang->XYF_Type = Flash_buff[0];
  668. Flash_ReadBytes(Flash_buff,ADDR_HDFSENSOR_TYPE,1);
  669. if(Flash_buff[0] == 0xffff)
  670. pcang->HDF_Type = 1; //默认底阀监测器 1智能底阀
  671. else
  672. pcang->HDF_Type = Flash_buff[0];
  673. Flash_ReadBytes(Flash_buff,ADDR_RKG_NUM,8); //检测是否对阀门种类及数量进行配置
  674. for(i = 0;i < 8;i++)
  675. {
  676. if((Flash_buff[i] < 8))
  677. pcang->RKG_Num[i] = Flash_buff[i];
  678. else
  679. pcang->RKG_Num[i] = 1; //默认每仓1人孔阀
  680. }
  681. Flash_ReadBytes(Flash_buff,ADDR_XYF_NUM,8);
  682. for(i = 0;i < 8;i++)
  683. {
  684. if((Flash_buff[i] < 8))
  685. pcang->XYF_Num[i] = Flash_buff[i];
  686. else
  687. pcang->XYF_Num[i] = 1; //默认每仓1卸油阀 slm
  688. }
  689. Flash_ReadBytes(Flash_buff,ADDR_HDF_NUM,8);
  690. for(i = 0;i < 8;i++)
  691. {
  692. if((Flash_buff[i] < 8))
  693. pcang->HDF_Num[i] = Flash_buff[i];
  694. else
  695. pcang->HDF_Num[i] = 1; //默认每仓1海底阀 slm
  696. }
  697. Flash_ReadBytes(Flash_buff,ADDR_YQHS_TYPE,1);
  698. if(Flash_buff[0] == 0xffff)
  699. pcang->YQHS = 0; //默认无油气回收 slm
  700. else
  701. pcang->YQHS = Flash_buff[0];
  702. Flash_ReadBytes(Flash_buff,ADDR_LEVEL_TYPE,1);
  703. if(Flash_buff[0] == 0xffff)
  704. pcang->Level = LEVEL_NONE; //默认无液位传感器 slm
  705. else
  706. pcang->Level = Flash_buff[0];
  707. Flash_ReadBytes(Flash_buff,CANG1_LEVEL_CAL,8);
  708. if(Flash_buff[0] == 0xffff)
  709. {
  710. for(i=0;i<pcang->Cang_Num;++i)
  711. {
  712. plevel[i].zero = 0;
  713. }
  714. }
  715. else
  716. {
  717. for (i = 0; i < pcang->Cang_Num; ++i)
  718. {
  719. hex_to_float1.arr[3] = (uint8_t)(Flash_buff[0+2*i] >> 8);
  720. hex_to_float1.arr[2] = (uint8_t)(Flash_buff[0+2*i] & 0xFF); // Flash_buff[3];
  721. hex_to_float1.arr[1] = (uint8_t)(Flash_buff[1+2*i] >> 8);
  722. hex_to_float1.arr[0] = (uint8_t)(Flash_buff[1+2*i] & 0xFF);
  723. plevel[i].zero = hex_to_float1.Ldcal_zero_temp;
  724. }
  725. }
  726. Flash_ReadBytes(Flash_buff,ADDR_SENSOR_BUS_MAX_RETRY,1);
  727. if(Flash_buff[0] == 0xffff)
  728. pcang->sensorBusMaxReTry = 10;
  729. else
  730. pcang->sensorBusMaxReTry = Flash_buff[0];
  731. Flash_ReadBytes(Flash_buff,ADDR_PIN_IO_HIT_SAME,1);
  732. if(Flash_buff[0] == 0xffff)
  733. pcang->pinIOHitSameParam = 3;
  734. else
  735. pcang->pinIOHitSameParam = Flash_buff[0];
  736. Flash_ReadBytes(Flash_buff,ADDR_TEM_TYPE,1);
  737. if(Flash_buff[0] == 0xffff)
  738. pcang->Temperture = 1; //默认无温度传感器
  739. else
  740. pcang->Temperture = Flash_buff[0];
  741. Flash_ReadBytes(Flash_buff,ADDR_ANGLE_TYPE,1);
  742. if(Flash_buff[0] == 0xffff)
  743. pcang->Angle = 1; //默认无姿态传感器
  744. else
  745. pcang->Angle = Flash_buff[0];
  746. Flash_ReadBytes(Flash_buff,ADDR_SDATEJUDGE_NUM,1);
  747. if(Flash_buff[0] == 0xffff)
  748. {
  749. for (i = 0; i < 8; i++)
  750. {
  751. prkg[i].RKG_StateKeepNum = 5; //默认人孔盖角度传感器
  752. pxyf[i].XYF_StateKeepNum = 5;
  753. plevel[i].StateKeepNum = 5;
  754. ptem[i].StateKeepNum = 5;
  755. }
  756. phdf->HDF_StateKeepNum = 5;
  757. pangle->Angle_StateKeepNum = 5;
  758. //plevel->StateKeepNum = 5;
  759. //ptem->TEM_StateKeepNum = 5;
  760. }
  761. else
  762. {
  763. for (i = 0; i < 8; i++)
  764. {
  765. prkg[i].RKG_StateKeepNum = Flash_buff[0];
  766. pxyf[i].XYF_StateKeepNum = Flash_buff[0];
  767. plevel[i].StateKeepNum = Flash_buff[0];
  768. ptem[i].StateKeepNum = Flash_buff[0];
  769. }
  770. pxyf->XYF_StateKeepNum = Flash_buff[0];
  771. phdf->HDF_StateKeepNum = Flash_buff[0];
  772. __NOP();
  773. pangle->Angle_StateKeepNum = Flash_buff[0];
  774. //plevel->StateKeepNum = Flash_buff[0];
  775. //ptem->TEM_StateKeepNum = Flash_buff[0];
  776. }
  777. }
  778. /* USER CODE END PFP */
  779. /* Private user code ---------------------------------------------------------*/
  780. /* USER CODE BEGIN 0 */
  781. /* USER CODE END 0 */
  782. /**4
  783. * @brief The application entry point.
  784. * @retval int
  785. */
  786. int main(void)
  787. {
  788. /* USER CODE BEGIN 1 */
  789. GPIO_InitTypeDef GPIO_InitStruct = {0};
  790. int spr000;
  791. /* USER CODE END 1 */
  792. #if IR_ROM1 == 0x08000000
  793. Start_BootLoader();
  794. #else
  795. SCB->VTOR = 0x08020000;
  796. __set_PRIMASK(0);
  797. #endif
  798. /* MCU Configuration--------------------------------------------------------*/
  799. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  800. HAL_Init();
  801. /* USER CODE BEGIN Init */
  802. Cang_Init(); //应用程序初始化函数
  803. RKG_Init();
  804. XYF_Init();
  805. BGY_Init();
  806. Pressure_Init();
  807. /* USER CODE END Init */
  808. /* Configure the system clock */
  809. SystemClock_Config();
  810. /* USER CODE BEGIN SysInit */
  811. /* USER CODE END SysInit */
  812. /* Initialize all configured peripherals */
  813. MX_GPIO_Init();
  814. MX_DMA_Init();
  815. MX_USART1_UART_Init();
  816. MX_UART5_Init();
  817. MX_USART2_UART_Init();
  818. MX_USART3_UART_Init();
  819. MX_CRC_Init();
  820. MX_DAC_Init();
  821. MX_TIM1_Init();
  822. MX_TIM4_Init();
  823. /* Initialize interrupts */
  824. MX_NVIC_Init();
  825. /* USER CODE BEGIN 2 */
  826. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//切换为接收模式
  827. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET);//切换为接收模式
  828. HAL_GPIO_WritePin(con03_uart2_kongzhiqi_GPIO_Port,con03_uart2_kongzhiqi_Pin,GPIO_PIN_SET);//切换为接收模式
  829. //看门狗重新根据宏定义初始化
  830. GPIO_InitStruct.Pin = WDI_sp706_kanmemgou_Pin;
  831. if(WatchDogOn)//打开看门狗sp706
  832. //if(1)//打开看门狗sp706
  833. {
  834. //
  835. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  836. }
  837. else
  838. {
  839. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  840. }
  841. GPIO_InitStruct.Pull = GPIO_NOPULL;
  842. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  843. HAL_GPIO_Init(WDI_sp706_kanmemgou_GPIO_Port, &GPIO_InitStruct);
  844. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//切换为发送模式CON=0;//
  845. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//切换为接收模式
  846. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_RESET);//切换为接收模式
  847. HAL_GPIO_WritePin(con03_uart2_kongzhiqi_GPIO_Port,con03_uart2_kongzhiqi_Pin,GPIO_PIN_RESET);//切换为接收模式
  848. HAL_Delay(2);
  849. memset(bufMain,0,128);
  850. spr000=sprintf((char*)bufMain,"sysytem reset...%5d, watchDogOn=%d, version:%d-%d",5,WatchDogOn,Version_Soft[7],Version_Soft[3]);
  851. //HAL_UART_Transmit(&huart1,bufMain,32,300);
  852. HAL_UART_Transmit(&huart2,bufMain,spr000,300);
  853. //HAL_UART_Transmit(&huart3,bufMain,32,300);
  854. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//切换为接收模式
  855. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET);//切换为接收模式
  856. HAL_GPIO_WritePin(con03_uart2_kongzhiqi_GPIO_Port,con03_uart2_kongzhiqi_Pin,GPIO_PIN_SET);//切换为接收模式
  857. /* USER CODE END 2 */
  858. /* Init scheduler */
  859. osKernelInitialize();
  860. /* Create the mutex(es) */
  861. /* creation of myMutex01 */
  862. myMutex01Handle = osMutexNew(&myMutex01_attributes);
  863. /* creation of myMutex02 */
  864. myMutex02Handle = osMutexNew(&myMutex02_attributes);
  865. /* creation of myMutex03 */
  866. myMutex03Handle = osMutexNew(&myMutex03_attributes);
  867. /* creation of myMutex04 */
  868. myMutex04Handle = osMutexNew(&myMutex04_attributes);
  869. /* creation of myMutex05 */
  870. myMutex05Handle = osMutexNew(&myMutex05_attributes);
  871. /* creation of myMutex06 */
  872. myMutex06Handle = osMutexNew(&myMutex06_attributes);
  873. /* creation of myMutex07 */
  874. myMutex07Handle = osMutexNew(&myMutex07_attributes);
  875. /* creation of myMutex08 */
  876. myMutex08Handle = osMutexNew(&myMutex08_attributes);
  877. /* Create the recursive mutex(es) */
  878. /* creation of myRecursiveMutex01 */
  879. myRecursiveMutex01Handle = osMutexNew(&myRecursiveMutex01_attributes);
  880. /* creation of myRecursiveMutex02 */
  881. myRecursiveMutex02Handle = osMutexNew(&myRecursiveMutex02_attributes);
  882. /* creation of myRecursiveMutex03 */
  883. myRecursiveMutex03Handle = osMutexNew(&myRecursiveMutex03_attributes);
  884. /* creation of myRecursiveMutex04 */
  885. myRecursiveMutex04Handle = osMutexNew(&myRecursiveMutex04_attributes);
  886. /* USER CODE BEGIN RTOS_MUTEX */
  887. /* add mutexes, ... */
  888. /* USER CODE END RTOS_MUTEX */
  889. /* Create the semaphores(s) */
  890. /* creation of myBinarySem01 */
  891. myBinarySem01Handle = osSemaphoreNew(1, 1, &myBinarySem01_attributes);
  892. /* creation of myBinarySem02 */
  893. myBinarySem02Handle = osSemaphoreNew(1, 1, &myBinarySem02_attributes);
  894. /* creation of myBinarySem03 */
  895. myBinarySem03Handle = osSemaphoreNew(1, 1, &myBinarySem03_attributes);
  896. /* creation of myBinarySem04 */
  897. myBinarySem04Handle = osSemaphoreNew(1, 1, &myBinarySem04_attributes);
  898. /* creation of myBinarySem05 */
  899. myBinarySem05Handle = osSemaphoreNew(1, 1, &myBinarySem05_attributes);
  900. /* creation of myBinarySem06 */
  901. myBinarySem06Handle = osSemaphoreNew(1, 1, &myBinarySem06_attributes);
  902. /* creation of myBinarySem07 */
  903. myBinarySem07Handle = osSemaphoreNew(1, 1, &myBinarySem07_attributes);
  904. /* creation of myBinarySem08 */
  905. myBinarySem08Handle = osSemaphoreNew(1, 1, &myBinarySem08_attributes);
  906. /* creation of myCountingSem01 */
  907. myCountingSem01Handle = osSemaphoreNew(2, 2, &myCountingSem01_attributes);
  908. /* creation of myCountingSem02 */
  909. myCountingSem02Handle = osSemaphoreNew(2, 2, &myCountingSem02_attributes);
  910. /* creation of myCountingSem03 */
  911. myCountingSem03Handle = osSemaphoreNew(2, 2, &myCountingSem03_attributes);
  912. /* creation of myCountingSem04 */
  913. myCountingSem04Handle = osSemaphoreNew(2, 2, &myCountingSem04_attributes);
  914. /* USER CODE BEGIN RTOS_SEMAPHORES */
  915. /* add semaphores, ... */
  916. /* USER CODE END RTOS_SEMAPHORES */
  917. /* Create the timer(s) */
  918. /* creation of myTimer01 */
  919. myTimer01Handle = osTimerNew(Callback01, osTimerPeriodic, NULL, &myTimer01_attributes);
  920. /* creation of myTimer02 */
  921. myTimer02Handle = osTimerNew(Callback02, osTimerPeriodic, NULL, &myTimer02_attributes);
  922. /* creation of myTimer03 */
  923. myTimer03Handle = osTimerNew(Callback03, osTimerPeriodic, NULL, &myTimer03_attributes);
  924. /* creation of myTimer04 */
  925. myTimer04Handle = osTimerNew(Callback04, osTimerPeriodic, NULL, &myTimer04_attributes);
  926. /* creation of myTimer05 */
  927. myTimer05Handle = osTimerNew(Callback05, osTimerPeriodic, NULL, &myTimer05_attributes);
  928. /* creation of myTimer06 */
  929. myTimer06Handle = osTimerNew(Callback06, osTimerPeriodic, NULL, &myTimer06_attributes);
  930. /* creation of myTimer07 */
  931. myTimer07Handle = osTimerNew(Callback07, osTimerPeriodic, NULL, &myTimer07_attributes);
  932. /* creation of myTimer08 */
  933. myTimer08Handle = osTimerNew(Callback08, osTimerPeriodic, NULL, &myTimer08_attributes);
  934. /* creation of myTimer09 */
  935. myTimer09Handle = osTimerNew(Callback09, osTimerPeriodic, NULL, &myTimer09_attributes);
  936. /* creation of myTimer10 */
  937. myTimer10Handle = osTimerNew(Callback010, osTimerPeriodic, NULL, &myTimer10_attributes);
  938. /* USER CODE BEGIN RTOS_TIMERS */
  939. /* start timers, add new ones, ... */
  940. /* USER CODE END RTOS_TIMERS */
  941. /* Create the queue(s) */
  942. /* creation of myQueue01 */
  943. myQueue01Handle = osMessageQueueNew (16, sizeof(uint16_t), &myQueue01_attributes);
  944. /* creation of myQueue02 */
  945. myQueue02Handle = osMessageQueueNew (16, sizeof(uint16_t), &myQueue02_attributes);
  946. /* creation of myQueue03 */
  947. myQueue03Handle = osMessageQueueNew (16, sizeof(uint16_t), &myQueue03_attributes);
  948. /* creation of myQueue04 */
  949. myQueue04Handle = osMessageQueueNew (16, sizeof(uint16_t), &myQueue04_attributes);
  950. /* creation of myQueue05 */
  951. myQueue05Handle = osMessageQueueNew (16, sizeof(uint16_t), &myQueue05_attributes);
  952. /* creation of myQueue06 */
  953. myQueue06Handle = osMessageQueueNew (16, sizeof(uint16_t), &myQueue06_attributes);
  954. /* USER CODE BEGIN RTOS_QUEUES */
  955. /* add queues, ... */
  956. /* USER CODE END RTOS_QUEUES */
  957. /* Create the thread(s) */
  958. /* creation of defaultTask */
  959. defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
  960. /* creation of myTask02 */
  961. myTask02Handle = osThreadNew(StartTask02, NULL, &myTask02_attributes);
  962. /* creation of myTask03 */
  963. myTask03Handle = osThreadNew(StartTask03, NULL, &myTask03_attributes);
  964. /* creation of myTask04 */
  965. myTask04Handle = osThreadNew(StartTask04, NULL, &myTask04_attributes);
  966. /* creation of myTask05 */
  967. myTask05Handle = osThreadNew(StartTask05, NULL, &myTask05_attributes);
  968. /* creation of myTask06 */
  969. myTask06Handle = osThreadNew(StartTask06, NULL, &myTask06_attributes);
  970. /* creation of myTask07 */
  971. myTask07Handle = osThreadNew(StartTask07, NULL, &myTask07_attributes);
  972. /* creation of myTask08 */
  973. myTask08Handle = osThreadNew(StartTask08, NULL, &myTask08_attributes);
  974. /* creation of myTask09 */
  975. myTask09Handle = osThreadNew(StartTask09, NULL, &myTask09_attributes);
  976. /* creation of myTask10 */
  977. myTask10Handle = osThreadNew(StartTask10, NULL, &myTask10_attributes);
  978. /* creation of myTask11 */
  979. myTask11Handle = osThreadNew(StartTask11, NULL, &myTask11_attributes);
  980. /* creation of myTask12 */
  981. myTask12Handle = osThreadNew(StartTask12, NULL, &myTask12_attributes);
  982. /* USER CODE BEGIN RTOS_THREADS */
  983. /* add threads, ... */
  984. /* USER CODE END RTOS_THREADS */
  985. /* creation of myEvent01 */
  986. myEvent01Handle = osEventFlagsNew(&myEvent01_attributes);
  987. /* creation of myEvent02 */
  988. myEvent02Handle = osEventFlagsNew(&myEvent02_attributes);
  989. /* creation of myEvent03 */
  990. myEvent03Handle = osEventFlagsNew(&myEvent03_attributes);
  991. /* creation of myEvent04 */
  992. myEvent04Handle = osEventFlagsNew(&myEvent04_attributes);
  993. /* creation of myEvent05 */
  994. myEvent05Handle = osEventFlagsNew(&myEvent05_attributes);
  995. /* creation of myEvent06 */
  996. myEvent06Handle = osEventFlagsNew(&myEvent06_attributes);
  997. /* creation of myEvent07 */
  998. myEvent07Handle = osEventFlagsNew(&myEvent07_attributes);
  999. /* creation of myEvent08 */
  1000. myEvent08Handle = osEventFlagsNew(&myEvent08_attributes);
  1001. /* USER CODE BEGIN RTOS_EVENTS */
  1002. /* add events, ... */
  1003. /* USER CODE END RTOS_EVENTS */
  1004. /* Start scheduler */
  1005. osKernelStart();
  1006. /* We should never get here as control is now taken by the scheduler */
  1007. /* Infinite loop */
  1008. /* USER CODE BEGIN WHILE */
  1009. while (1)
  1010. {
  1011. }
  1012. /* USER CODE END WHILE */
  1013. /* USER CODE BEGIN 3 */
  1014. /* USER CODE END 3 */
  1015. }
  1016. /**
  1017. * @brief System Clock Configuration
  1018. * @retval None
  1019. */
  1020. void SystemClock_Config(void)
  1021. {
  1022. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  1023. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  1024. /** Initializes the RCC Oscillators according to the specified parameters
  1025. * in the RCC_OscInitTypeDef structure.
  1026. */
  1027. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  1028. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  1029. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  1030. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  1031. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  1032. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  1033. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  1034. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  1035. {
  1036. Error_Handler();
  1037. }
  1038. /** Initializes the CPU, AHB and APB buses clocks
  1039. */
  1040. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  1041. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  1042. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  1043. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  1044. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  1045. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  1046. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  1047. {
  1048. Error_Handler();
  1049. }
  1050. }
  1051. /**
  1052. * @brief NVIC Configuration.
  1053. * @retval None
  1054. */
  1055. static void MX_NVIC_Init(void)
  1056. {
  1057. /* USART3_IRQn interrupt configuration */
  1058. HAL_NVIC_SetPriority(USART3_IRQn, 5, 0);
  1059. HAL_NVIC_EnableIRQ(USART3_IRQn);
  1060. /* USART1_IRQn interrupt configuration */
  1061. HAL_NVIC_SetPriority(USART1_IRQn, 5, 0);
  1062. HAL_NVIC_EnableIRQ(USART1_IRQn);
  1063. /* USART2_IRQn interrupt configuration */
  1064. HAL_NVIC_SetPriority(USART2_IRQn, 5, 0);
  1065. HAL_NVIC_EnableIRQ(USART2_IRQn);
  1066. /* TIM4_IRQn interrupt configuration */
  1067. HAL_NVIC_SetPriority(TIM4_IRQn, 5, 0);
  1068. HAL_NVIC_EnableIRQ(TIM4_IRQn);
  1069. /* TIM1_UP_IRQn interrupt configuration */
  1070. HAL_NVIC_SetPriority(TIM1_UP_IRQn, 5, 0);
  1071. HAL_NVIC_EnableIRQ(TIM1_UP_IRQn);
  1072. /* DMA1_Channel6_IRQn interrupt configuration */
  1073. HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 5, 0);
  1074. HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
  1075. /* DMA1_Channel5_IRQn interrupt configuration */
  1076. HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 5, 0);
  1077. HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
  1078. /* DMA1_Channel3_IRQn interrupt configuration */
  1079. HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 5, 0);
  1080. HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn);
  1081. }
  1082. /**
  1083. * @brief CRC Initialization Function
  1084. * @param None
  1085. * @retval None
  1086. */
  1087. static void MX_CRC_Init(void)
  1088. {
  1089. /* USER CODE BEGIN CRC_Init 0 */
  1090. /* USER CODE END CRC_Init 0 */
  1091. /* USER CODE BEGIN CRC_Init 1 */
  1092. /* USER CODE END CRC_Init 1 */
  1093. hcrc.Instance = CRC;
  1094. if (HAL_CRC_Init(&hcrc) != HAL_OK)
  1095. {
  1096. Error_Handler();
  1097. }
  1098. /* USER CODE BEGIN CRC_Init 2 */
  1099. /* USER CODE END CRC_Init 2 */
  1100. }
  1101. /**
  1102. * @brief DAC Initialization Function
  1103. * @param None
  1104. * @retval None
  1105. */
  1106. static void MX_DAC_Init(void)
  1107. {
  1108. /* USER CODE BEGIN DAC_Init 0 */
  1109. /* USER CODE END DAC_Init 0 */
  1110. DAC_ChannelConfTypeDef sConfig = {0};
  1111. /* USER CODE BEGIN DAC_Init 1 */
  1112. /* USER CODE END DAC_Init 1 */
  1113. /** DAC Initialization
  1114. */
  1115. hdac.Instance = DAC;
  1116. if (HAL_DAC_Init(&hdac) != HAL_OK)
  1117. {
  1118. Error_Handler();
  1119. }
  1120. /** DAC channel OUT2 config
  1121. */
  1122. sConfig.DAC_Trigger = DAC_TRIGGER_SOFTWARE;
  1123. sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
  1124. if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_2) != HAL_OK)
  1125. {
  1126. Error_Handler();
  1127. }
  1128. /* USER CODE BEGIN DAC_Init 2 */
  1129. /* USER CODE END DAC_Init 2 */
  1130. }
  1131. /**
  1132. * @brief TIM1 Initialization Function
  1133. * @param None
  1134. * @retval None
  1135. */
  1136. static void MX_TIM1_Init(void)
  1137. {
  1138. /* USER CODE BEGIN TIM1_Init 0 */
  1139. /* USER CODE END TIM1_Init 0 */
  1140. TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  1141. TIM_MasterConfigTypeDef sMasterConfig = {0};
  1142. /* USER CODE BEGIN TIM1_Init 1 */
  1143. /* USER CODE END TIM1_Init 1 */
  1144. htim1.Instance = TIM1;
  1145. htim1.Init.Prescaler = 0;
  1146. htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
  1147. htim1.Init.Period = 65535;
  1148. htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4;
  1149. htim1.Init.RepetitionCounter = 0;
  1150. htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1151. if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
  1152. {
  1153. Error_Handler();
  1154. }
  1155. sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  1156. if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
  1157. {
  1158. Error_Handler();
  1159. }
  1160. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  1161. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  1162. if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
  1163. {
  1164. Error_Handler();
  1165. }
  1166. /* USER CODE BEGIN TIM1_Init 2 */
  1167. /* USER CODE END TIM1_Init 2 */
  1168. }
  1169. /**
  1170. * @brief TIM4 Initialization Function
  1171. * @param None
  1172. * @retval None
  1173. */
  1174. static void MX_TIM4_Init(void)
  1175. {
  1176. /* USER CODE BEGIN TIM4_Init 0 */
  1177. /* USER CODE END TIM4_Init 0 */
  1178. TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  1179. TIM_MasterConfigTypeDef sMasterConfig = {0};
  1180. /* USER CODE BEGIN TIM4_Init 1 */
  1181. /* USER CODE END TIM4_Init 1 */
  1182. htim4.Instance = TIM4;
  1183. htim4.Init.Prescaler = 0;
  1184. htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
  1185. htim4.Init.Period = 65535;
  1186. htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  1187. htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1188. if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
  1189. {
  1190. Error_Handler();
  1191. }
  1192. sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  1193. if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK)
  1194. {
  1195. Error_Handler();
  1196. }
  1197. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  1198. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  1199. if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
  1200. {
  1201. Error_Handler();
  1202. }
  1203. /* USER CODE BEGIN TIM4_Init 2 */
  1204. /* USER CODE END TIM4_Init 2 */
  1205. }
  1206. /**
  1207. * @brief UART5 Initialization Function
  1208. * @param None
  1209. * @retval None
  1210. */
  1211. static void MX_UART5_Init(void)
  1212. {
  1213. /* USER CODE BEGIN UART5_Init 0 */
  1214. /* USER CODE END UART5_Init 0 */
  1215. /* USER CODE BEGIN UART5_Init 1 */
  1216. /* USER CODE END UART5_Init 1 */
  1217. huart5.Instance = UART5;
  1218. huart5.Init.BaudRate = 115200;
  1219. huart5.Init.WordLength = UART_WORDLENGTH_8B;
  1220. huart5.Init.StopBits = UART_STOPBITS_1;
  1221. huart5.Init.Parity = UART_PARITY_NONE;
  1222. huart5.Init.Mode = UART_MODE_TX_RX;
  1223. huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  1224. huart5.Init.OverSampling = UART_OVERSAMPLING_16;
  1225. if (HAL_UART_Init(&huart5) != HAL_OK)
  1226. {
  1227. Error_Handler();
  1228. }
  1229. /* USER CODE BEGIN UART5_Init 2 */
  1230. /* USER CODE END UART5_Init 2 */
  1231. }
  1232. /**
  1233. * @brief USART1 Initialization Function
  1234. * @param None
  1235. * @retval None
  1236. */
  1237. static void MX_USART1_UART_Init(void)
  1238. {
  1239. /* USER CODE BEGIN USART1_Init 0 */
  1240. extern uint8_t USART1_RX_BUF[Uart1_BUF_SIZE];
  1241. /* USER CODE END USART1_Init 0 */
  1242. /* USER CODE BEGIN USART1_Init 1 */
  1243. /* USER CODE END USART1_Init 1 */
  1244. huart1.Instance = USART1;
  1245. huart1.Init.BaudRate = 9600;
  1246. huart1.Init.WordLength = UART_WORDLENGTH_8B;
  1247. huart1.Init.StopBits = UART_STOPBITS_1;
  1248. huart1.Init.Parity = UART_PARITY_NONE;
  1249. huart1.Init.Mode = UART_MODE_TX_RX;
  1250. huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  1251. huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  1252. if (HAL_UART_Init(&huart1) != HAL_OK)
  1253. {
  1254. Error_Handler();
  1255. }
  1256. /* USER CODE BEGIN USART1_Init 2 */
  1257. __HAL_UART_ENABLE_IT(&huart1, UART_IT_IDLE);
  1258. HAL_UART_Receive_DMA(&huart1,USART1_RX_BUF,Uart1_BUF_SIZE);
  1259. /* USER CODE END USART1_Init 2 */
  1260. }
  1261. /**
  1262. * @brief USART2 Initialization Function
  1263. * @param None
  1264. * @retval None
  1265. */
  1266. static void MX_USART2_UART_Init(void)
  1267. {
  1268. /* USER CODE BEGIN USART2_Init 0 */
  1269. /* USER CODE END USART2_Init 0 */
  1270. /* USER CODE BEGIN USART2_Init 1 */
  1271. /* USER CODE END USART2_Init 1 */
  1272. huart2.Instance = USART2;
  1273. huart2.Init.BaudRate = 19200;//19200
  1274. huart2.Init.WordLength = UART_WORDLENGTH_8B;
  1275. huart2.Init.StopBits = UART_STOPBITS_1;
  1276. huart2.Init.Parity = UART_PARITY_NONE;
  1277. huart2.Init.Mode = UART_MODE_TX_RX;
  1278. huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  1279. huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  1280. if (HAL_UART_Init(&huart2) != HAL_OK)
  1281. {
  1282. Error_Handler();
  1283. }
  1284. /* USER CODE BEGIN USART2_Init 2 */
  1285. __HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE);
  1286. HAL_UART_Receive_DMA(&huart2,USART2_RX_BUF,Uart2_BUF_SIZE);
  1287. /* USER CODE END USART2_Init 2 */
  1288. }
  1289. /**
  1290. * @brief USART3 Initialization Function
  1291. * @param None
  1292. * @retval None
  1293. */
  1294. static void MX_USART3_UART_Init(void)
  1295. {
  1296. /* USER CODE BEGIN USART3_Init 0 */
  1297. /* USER CODE END USART3_Init 0 */
  1298. /* USER CODE BEGIN USART3_Init 1 */
  1299. /* USER CODE END USART3_Init 1 */
  1300. huart3.Instance = USART3;
  1301. huart3.Init.BaudRate = 9600;
  1302. huart3.Init.WordLength = UART_WORDLENGTH_8B;
  1303. huart3.Init.StopBits = UART_STOPBITS_1;
  1304. huart3.Init.Parity = UART_PARITY_NONE;
  1305. huart3.Init.Mode = UART_MODE_TX_RX;
  1306. huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  1307. huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  1308. if (HAL_UART_Init(&huart3) != HAL_OK)
  1309. {
  1310. Error_Handler();
  1311. }
  1312. /* USER CODE BEGIN USART3_Init 2 */
  1313. __HAL_UART_ENABLE_IT(&huart3, UART_IT_IDLE);
  1314. HAL_UART_Receive_DMA(&huart3,USART3_RX_BUF,Uart3_BUF_SIZE);
  1315. /* USER CODE END USART3_Init 2 */
  1316. }
  1317. /**
  1318. * Enable DMA controller clock
  1319. */
  1320. static void MX_DMA_Init(void)
  1321. {
  1322. /* DMA controller clock enable */
  1323. __HAL_RCC_DMA1_CLK_ENABLE();
  1324. __HAL_RCC_DMA2_CLK_ENABLE();
  1325. /* DMA interrupt init */
  1326. /* DMA1_Channel4_IRQn interrupt configuration */
  1327. HAL_NVIC_SetPriority(DMA1_Channel4_IRQn, 5, 0);
  1328. HAL_NVIC_EnableIRQ(DMA1_Channel4_IRQn);
  1329. /* DMA2_Channel4_5_IRQn interrupt configuration */
  1330. HAL_NVIC_SetPriority(DMA2_Channel4_5_IRQn, 5, 0);
  1331. HAL_NVIC_EnableIRQ(DMA2_Channel4_5_IRQn);
  1332. }
  1333. /**
  1334. * @brief GPIO Initialization Function
  1335. * @param None
  1336. * @retval None
  1337. */
  1338. static void MX_GPIO_Init(void)
  1339. {
  1340. GPIO_InitTypeDef GPIO_InitStruct = {0};
  1341. /* GPIO Ports Clock Enable */
  1342. __HAL_RCC_GPIOD_CLK_ENABLE();
  1343. __HAL_RCC_GPIOA_CLK_ENABLE();
  1344. __HAL_RCC_GPIOB_CLK_ENABLE();
  1345. __HAL_RCC_GPIOC_CLK_ENABLE();
  1346. /*Configure GPIO pin Output Level */
  1347. HAL_GPIO_WritePin(GPIOA, LED1_Pin|LED2_Pin|con03_uart2_kongzhiqi_Pin, GPIO_PIN_RESET);
  1348. /*Configure GPIO pin Output Level */
  1349. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin|Con01_uart1_rankonggai_Pin, GPIO_PIN_RESET);
  1350. /*Configure GPIO pin Output Level */
  1351. HAL_GPIO_WritePin(WDI_sp706_kanmemgou_GPIO_Port, WDI_sp706_kanmemgou_Pin, GPIO_PIN_RESET);
  1352. /*Configure GPIO pins : LED1_Pin LED2_Pin con03_uart2_kongzhiqi_Pin */
  1353. GPIO_InitStruct.Pin = LED1_Pin|LED2_Pin|con03_uart2_kongzhiqi_Pin;
  1354. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1355. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1356. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1357. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  1358. /*Configure GPIO pins : con02_uart3_xieyoufa_Pin Con01_uart1_rankonggai_Pin */
  1359. GPIO_InitStruct.Pin = con02_uart3_xieyoufa_Pin|Con01_uart1_rankonggai_Pin;
  1360. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1361. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1362. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1363. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  1364. /*Configure GPIO pins : IN01_Pin PB15 */
  1365. GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
  1366. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1367. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1368. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  1369. /*Configure GPIO pins : PC6 PC7 PC8 PC9 */
  1370. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;
  1371. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1372. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1373. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  1374. /*Configure GPIO pins : PA8 PA11 */
  1375. GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_11;
  1376. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1377. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1378. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  1379. /*Configure GPIO pin : WDI_sp706_kanmemgou_Pin */
  1380. GPIO_InitStruct.Pin = WDI_sp706_kanmemgou_Pin;
  1381. if(WatchDogOn)//打开看门狗sp706
  1382. //if(1)//打开看门狗sp706
  1383. {
  1384. //
  1385. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1386. }
  1387. else
  1388. {
  1389. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1390. }
  1391. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1392. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1393. HAL_GPIO_Init(WDI_sp706_kanmemgou_GPIO_Port, &GPIO_InitStruct);
  1394. }
  1395. /* USER CODE BEGIN 4 */
  1396. /**
  1397. * @funNm : delay_sys_us
  1398. * @brief : 延时nus
  1399. * @param : nus:要延时的us数. 0~204522252(最大值即2^32/fac_us@fac_us=168)
  1400. * @retval: void
  1401. */
  1402. void delay_sys_us(uint32_t Delay)//1个delay,大概1.5us
  1403. {
  1404. uint32_t cnt = Delay * 8;
  1405. uint32_t i = 0;
  1406. for(i = 0; i < cnt; i++)__NOP();
  1407. }
  1408. /* USER CODE END 4 */
  1409. /* USER CODE BEGIN Header_StartDefaultTask */
  1410. /**
  1411. * @brief Function implementing the defaultTask thread.
  1412. * @param argument: Not used
  1413. * @retval None
  1414. */
  1415. /* USER CODE END Header_StartDefaultTask */
  1416. void StartDefaultTask(void *argument)
  1417. {
  1418. /* USER CODE BEGIN 5 */
  1419. /* Infinite loop */
  1420. for(;;)
  1421. {
  1422. osDelay(1);
  1423. }
  1424. /* USER CODE END 5 */
  1425. }
  1426. /* USER CODE BEGIN Header_StartTask02 */
  1427. /**
  1428. * @brief Function implementing the myTask02 thread.
  1429. * @param argument: Not used
  1430. * @retval None
  1431. */
  1432. uint8_t Flash_Change = 0; //定义接收数组
  1433. uni_float tprture001,tprture002,tprture003,Yewei001,tprtureAver;
  1434. /* USER CODE END Header_StartTask02 */
  1435. /*
  1436. //发送卸油阀传感器命令轮询
  1437. //发送角度传感器命令轮询
  1438. //发送壁挂油传感器命令轮询
  1439. //发送智能海底阀传感器命令轮询
  1440. //发送油气回收传感器命令轮询
  1441. */
  1442. void StartTask02(void *argument) //卸油阀总线传感器命令轮询 UART3
  1443. {
  1444. /* USER CODE BEGIN StartTask02 */
  1445. uint8_t i001=0,i002 = 0;
  1446. uint16_t ModbusCRC = 0,xyfaddr_max = 0,hdfaddr_max; //xyfaddr_max:卸油阀最高地址,根据每仓卸油阀之和计算得出
  1447. static uint16_t i = 0,j = 0,receive_error = 0;
  1448. HDF_Inf* phdf = hdf_inf;
  1449. KZQ_Inf* pkzq = &kzq_inf;
  1450. XYF_Inf* pxyf = xyf_inf;
  1451. Cang_Inf* pcang = &cang_inf;
  1452. Angle_Inf* pangle = &angle_inf;
  1453. Pressure_Inf* pPressure = pressure_inf;
  1454. uint8_t pressureaddr_max = 0;
  1455. xyfaddr_max=0;
  1456. hdfaddr_max=0;
  1457. for(i = 0;i < pcang->Cang_Num;i++)
  1458. {
  1459. xyfaddr_max += pcang->XYF_Num[i];
  1460. hdfaddr_max += pcang->HDF_Num[i];
  1461. pressureaddr_max += pcang->Pressure_Num[i];
  1462. }
  1463. i = 0;
  1464. extern uint8_t USART2_RX_BUF002[Uart2_BUF_SIZE];
  1465. extern uint8_t USART1_RX_BUF002[Uart2_BUF_SIZE];
  1466. extern uint8_t USART3_RX_BUF002[Uart2_BUF_SIZE];
  1467. extern int data_lengthU2,data_lengthU1,data_lengthU3;
  1468. extern int flagU1Rx,flagU2Rx,flagU3Rx;
  1469. extern uint8_t USART3_RX_BUF002_print[Uart3_BUF_SIZE];
  1470. extern uint8_t XYF_TxBuf[70];
  1471. extern uint16_t Uart_len_TouChuan;
  1472. /* Infinite loop */
  1473. for(;;)
  1474. {
  1475. osDelay(10); //以ms为单位
  1476. //HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_0);
  1477. HAL_GPIO_TogglePin(WDI_sp706_kanmemgou_GPIO_Port, WDI_sp706_kanmemgou_Pin);
  1478. // continue;
  1479. if(Flash_Change) //如果有对Flash进行改动,则重新计算xyfaddr_max
  1480. {
  1481. xyfaddr_max = 0;
  1482. hdfaddr_max = 0;
  1483. pressureaddr_max = 0;
  1484. for(i = 0;i < pcang->Cang_Num;i++)
  1485. {
  1486. xyfaddr_max += pcang->XYF_Num[i];
  1487. hdfaddr_max += pcang->HDF_Num[i];
  1488. pressureaddr_max += pcang->Pressure_Num[i];
  1489. }
  1490. Flash_Change = 0;
  1491. }
  1492. if(pkzq->USE_XYF == 0) //平台未控制卸油阀总线,正常轮询数据
  1493. {
  1494. if(i001==0) //发送卸油阀传感器命令轮询
  1495. {
  1496. //pcang->XYF_Type=2;
  1497. if ((pcang->XYF_INSTALL != 0) && (pcang->XYF_Type != 2))
  1498. {
  1499. ModbusCRC = LIB_CRC_MODBUS(CMD_XYF, 6);
  1500. CMD_XYF[6] = ModbusCRC >> 8;
  1501. CMD_XYF[7] = ModbusCRC & 0xff;
  1502. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_RESET); //
  1503. delay_sys_us(80);
  1504. HAL_UART_Transmit_IT(&huart3, CMD_XYF, 8);
  1505. while (huart3.gState == HAL_UART_STATE_BUSY_TX)
  1506. {
  1507. osDelay(1);
  1508. }
  1509. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_SET); //
  1510. pxyf[CMD_XYF[0] - 0x10].RTData_Num++; //每个传感器发送帧累加
  1511. if (CMD_XYF[0] - 0x10 < xyfaddr_max)
  1512. CMD_XYF[0]++;
  1513. else
  1514. CMD_XYF[0] = 0x11;
  1515. }
  1516. else
  1517. {
  1518. i001 = 3;
  1519. }
  1520. }
  1521. if (i001 == 3) //发送姿态传感器轮询
  1522. {
  1523. if (pcang->Angle) //发送角度传感器命令轮询
  1524. {
  1525. ModbusCRC = LIB_CRC_MODBUS(CMD_Angle_XY, 6);
  1526. CMD_Angle_XY[6] = ModbusCRC >> 8;
  1527. CMD_Angle_XY[7] = ModbusCRC & 0xff;
  1528. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_RESET);
  1529. delay_sys_us(80);
  1530. HAL_UART_Transmit(&huart3, CMD_Angle_XY, 8, 100); //只支持单指令读角度取传感器数据
  1531. delay_sys_us(80);
  1532. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_SET);
  1533. if (pangle->RTData_NumX > RT_ERRORCNT)
  1534. {
  1535. pangle->RTData_NumX = RT_ERRORCNT;
  1536. pangle->Angle_ErrorCnt = RT_ERRORCNT;
  1537. }
  1538. else
  1539. pangle->RTData_NumX++;
  1540. }
  1541. else
  1542. {
  1543. i001 = 6;
  1544. }
  1545. }
  1546. if(i001==6) //发送壁挂油传感器命令轮询
  1547. {
  1548. if(pcang->BGY_INSTALL)
  1549. {
  1550. ModbusCRC = LIB_CRC_MODBUS(CMD_Biguayou,6);
  1551. CMD_Biguayou[6] = ModbusCRC>>8;
  1552. CMD_Biguayou[7] = ModbusCRC&0xff;
  1553. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_RESET);
  1554. delay_sys_us(80);
  1555. HAL_UART_Transmit(&huart3,CMD_Biguayou,8,100); //只支持单指令读角度取传感器数据
  1556. delay_sys_us(80);
  1557. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET);
  1558. }
  1559. else
  1560. {
  1561. i001=9;
  1562. }
  1563. }
  1564. if (i001 == 9) //发送智能海底阀传感器命令轮询
  1565. {
  1566. if (pcang->HDF_INSTALL != 0 && pcang->HDF_Type)
  1567. {
  1568. ModbusCRC = LIB_CRC_MODBUS(CMD_HDF, 14);
  1569. CMD_HDF[14] = ModbusCRC >> 8;
  1570. CMD_HDF[15] = ModbusCRC & 0xff;
  1571. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_RESET);
  1572. delay_sys_us(80);
  1573. HAL_UART_Transmit(&huart3, CMD_HDF, 16, 100); //只支持单指令读角度取传感器数据
  1574. delay_sys_us(80);
  1575. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_SET);
  1576. if (phdf[CMD_HDF[0] - 0x20].RTData_Num > 50) //收发数据错误次数RT_ERRORCNT
  1577. {
  1578. // phdf[CMD_HDF[0]-0x20].RTData_Num = RT_ERRORCNT;
  1579. // phdf[CMD_HDF[0]-0x20].HDF_ErrorCnt = RT_ERRORCNT;
  1580. }
  1581. else
  1582. phdf[CMD_HDF[0] - 0x20].RTData_Num++; //每个传感器发送帧累加
  1583. if (CMD_HDF[0] - 0x21 < hdfaddr_max)
  1584. CMD_HDF[0]++;
  1585. else
  1586. CMD_HDF[0] = 0x21;
  1587. }
  1588. else
  1589. {
  1590. i001 = 12;
  1591. }
  1592. }
  1593. if(i001==12) //发送油气回收传感器命令轮询
  1594. {
  1595. if(pcang->YQHS)
  1596. {
  1597. ModbusCRC = LIB_CRC_MODBUS(CMD_YQHS,6);
  1598. CMD_YQHS[6] = ModbusCRC>>8;
  1599. CMD_YQHS[7] = ModbusCRC&0xff;
  1600. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_RESET);
  1601. delay_sys_us(80);
  1602. HAL_UART_Transmit(&huart3,CMD_YQHS,8,100); //只支持单指令读角度取传感器数据
  1603. delay_sys_us(80);
  1604. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET);
  1605. }
  1606. else
  1607. {
  1608. i001=15;
  1609. }
  1610. }
  1611. if(i001 == 15){
  1612. if(Pressure_FST800_801 == pcang->Pressure){
  1613. ModbusCRC = LIB_CRC_MODBUS(CMD_Pressure, 6);
  1614. CMD_Pressure[6] = ModbusCRC >> 8;
  1615. CMD_Pressure[7] = ModbusCRC & 0xff;
  1616. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_RESET);
  1617. delay_sys_us(80);
  1618. HAL_UART_Transmit(&huart3, CMD_Pressure, 8, 200); //只支持单指令读角度取传感器数据
  1619. delay_sys_us(80);
  1620. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_SET);
  1621. pPressure[CMD_Pressure[0] - PRESSURE_STARTADDR].RTData_Num++; //每个传感器发送帧累加
  1622. if (CMD_Pressure[0] - PRESSURE_STARTADDR +1 < pressureaddr_max)
  1623. CMD_Pressure[0]++;
  1624. else
  1625. CMD_Pressure[0] = PRESSURE_STARTADDR;
  1626. }else{
  1627. i001=0;
  1628. continue;
  1629. }
  1630. }
  1631. }
  1632. else //平台通过卸油阀总线直接操作传感器
  1633. {
  1634. if(i002 == 3)
  1635. {
  1636. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_RESET);//
  1637. delay_sys_us(80);
  1638. #if 0
  1639. if((XYF_TxBuf[0] == 0x0D)&&(XYF_TxBuf[0] == 0x0A))
  1640. HAL_UART_Transmit(&huart3,XYF_TxBuf,12,100);
  1641. else
  1642. HAL_UART_Transmit(&huart3,XYF_TxBuf,8,100);
  1643. delay_sys_us(80);
  1644. #else
  1645. HAL_UART_Transmit_IT(&huart3,XYF_TxBuf,Uart_len_TouChuan);
  1646. while (huart3.gState == HAL_UART_STATE_BUSY_TX)
  1647. {
  1648. osDelay(1);
  1649. }
  1650. #endif
  1651. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET); //
  1652. }
  1653. else if(i002 == 0x06)
  1654. {
  1655. #if 0
  1656. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_RESET);//
  1657. delay_sys_us(80);
  1658. HAL_UART_Transmit(&huart3,ALL_TxBuf,16,100);
  1659. delay_sys_us(80);
  1660. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET);//
  1661. }
  1662. else if(i002 == 0x09)//slm 0x0c
  1663. {
  1664. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_RESET);//
  1665. delay_sys_us(80);
  1666. HAL_UART_Transmit(&huart3,ALL_TxBuf,Uart_len_TouChuan,100);
  1667. delay_sys_us(80);
  1668. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET);//
  1669. #endif
  1670. pkzq->USE_XYF = 0;
  1671. i002 = 0;
  1672. }
  1673. i002++;
  1674. if((flagU3Rx==1) && (i002 > 3))
  1675. {
  1676. pkzq->USE_XYF = 0;
  1677. i002 = 0;
  1678. continue;
  1679. }
  1680. }
  1681. //来自UART3的命令 电路板上标志位卸油阀
  1682. if(flagU3Rx==1)
  1683. {
  1684. flagU3Rx=0;
  1685. #if 0
  1686. if(USART3_RX_BUF002[0]!=0x11)
  1687. {
  1688. pxyf[1].XYF_ErrorCnt++;
  1689. if(pxyf[1].XYF_ErrorCnt>35)
  1690. {
  1691. pxyf[1].XYF_Error = 1;
  1692. }
  1693. }
  1694. if(USART3_RX_BUF002[0]!=0x12)
  1695. {
  1696. pxyf[2].XYF_ErrorCnt++;
  1697. if(pxyf[2].XYF_ErrorCnt>35)
  1698. {
  1699. pxyf[2].XYF_Error = 1;
  1700. }
  1701. }
  1702. #endif
  1703. if(USART3_RX_BUF002[0] >= 0x10 && USART3_RX_BUF002[0] <= 0x1F) //卸油阀数据
  1704. {
  1705. ModbusCRC = USART3_RX_BUF002[5]<<8;
  1706. ModbusCRC |= USART3_RX_BUF002[6];
  1707. //pxyf[USART3_RX_BUF002[0]-0x10].RTData_Num = 1;
  1708. if(USART3_RX_BUF002[1]!=0x03&&USART3_RX_BUF002[1]!=0x06) //校验读写属性
  1709. {
  1710. receive_error = 1;
  1711. }
  1712. else if(USART3_RX_BUF002[2] != 0x02) //校验数据长度
  1713. {
  1714. receive_error = 1;
  1715. }
  1716. else if(ModbusCRC != LIB_CRC_MODBUS(USART3_RX_BUF002,5)) //校验CRC
  1717. {
  1718. receive_error = 1;
  1719. }
  1720. if(receive_error == 0)
  1721. {
  1722. pxyf[USART3_RX_BUF002[0]-0x10].XYF_ErrorCnt = 0;
  1723. pxyf[USART3_RX_BUF002[0]-0x10].XYF_Error = 0;
  1724. if(USART3_RX_BUF002[1] == 0x03) //读取数据返回
  1725. {
  1726. #if 0
  1727. if(USART3_RX_BUF002[3]>0x01)//阀门开关状态
  1728. {
  1729. pxyf[i].XYF_ErrorCnt++;
  1730. }
  1731. else if(i < XYF_BUF_DEP)
  1732. {
  1733. i++;
  1734. }
  1735. if(i == XYF_BUF_DEP)
  1736. {
  1737. i = 0;
  1738. }
  1739. #else
  1740. pxyf[USART3_RX_BUF002[0] - 0x10].XYF_Data1[0] = USART3_RX_BUF002[3];
  1741. //pxyf[USART3_RX_BUF002[0] - 0x10].XYF_Data2[0] = USART3_RX_BUF002[4];
  1742. pxyf[USART3_RX_BUF002[0] - 0x10].XYF_Data2[0] = 0xFF; //泄尽状态,比IO 输入获取
  1743. #endif
  1744. XYF_state(USART3_RX_BUF002[0] - 0x10);
  1745. }
  1746. else if(USART3_RX_BUF002[1] == 0x06) //写入数据返回 判断写入是否成功
  1747. {
  1748. //清除控制器占用标志
  1749. //整理卸油阀协议后添加
  1750. }
  1751. i001=12;
  1752. //continue;
  1753. }
  1754. }
  1755. else if(USART3_RX_BUF002[0] >=0x70 && USART3_RX_BUF002[0] <= 0x7f) //姿态数据,目前最多支持3轴
  1756. {
  1757. ModbusCRC = USART3_RX_BUF002[7]<<8;
  1758. ModbusCRC |= USART3_RX_BUF002[8];
  1759. pangle->RTData_NumX = 1;
  1760. if(USART3_RX_BUF002[1]!=0x03&&USART3_RX_BUF002[1]!=0x06) //校验读写属性
  1761. {
  1762. receive_error = 1;
  1763. }
  1764. else if(USART3_RX_BUF002[2] >= 0x08) //校验数据长度
  1765. {
  1766. receive_error = 1;
  1767. }
  1768. else if(ModbusCRC != LIB_CRC_MODBUS(USART3_RX_BUF002,USART3_RX_BUF002[2]+3)) //校验CRC
  1769. {
  1770. //receive_error = 1;
  1771. }
  1772. if(receive_error == 0)
  1773. {
  1774. if(USART3_RX_BUF002[1] ==0x03)
  1775. {
  1776. if(j < ANGLE_BUF_DEP)
  1777. {
  1778. pangle->Angle_ErrorCnt = 0;
  1779. //if(USART3_RX_BUF002[2] == 0x02)
  1780. pangle->Angle_DataX[j] = USART3_RX_BUF002[3]<<8|USART3_RX_BUF002[4];
  1781. //if(USART3_RX_BUF002[2] > 0x02)
  1782. pangle->Angle_DataY[j] = USART3_RX_BUF002[5]<<8|USART3_RX_BUF002[6];
  1783. // if(USART3_RX_BUF002[2] > 0x04)
  1784. pangle->Angle_DataZ[j] = USART3_RX_BUF002[7]<<8|USART3_RX_BUF002[8];
  1785. j++;
  1786. }
  1787. if(j == ANGLE_BUF_DEP)
  1788. {
  1789. j = 0;
  1790. }
  1791. }
  1792. else
  1793. {
  1794. //整理卸油阀协议后添加
  1795. }
  1796. i001=6;
  1797. continue;
  1798. }
  1799. }
  1800. else if(USART3_RX_BUF002[0] >= 0x20 && USART3_RX_BUF002[0] <= 0x2F ) //智能海底阀数据
  1801. {
  1802. Get_ZN_hdf_data();
  1803. i001 = 12;
  1804. continue;
  1805. }
  1806. else if(USART3_RX_BUF002[0] == 0xe4) //油气回收数据
  1807. {
  1808. Get_Yqhuishou_data();
  1809. i001 = 15;
  1810. continue;
  1811. }
  1812. else if(USART3_RX_BUF002[0] >= 0x81 && USART3_RX_BUF002[0] <= 0x8F) //壁挂油数据
  1813. {
  1814. Get_Biguayou_data();
  1815. i001 = 9;
  1816. continue;
  1817. }else if(USART3_RX_BUF002[0] >= 0x91 && USART3_RX_BUF002[0] <= 0x9F)
  1818. {
  1819. if(0 == Prase_Pressure(USART3_RX_BUF002, 9)){
  1820. //i001 = 0;
  1821. //continue;
  1822. }
  1823. }
  1824. receive_error = 0;
  1825. }
  1826. else
  1827. {
  1828. if (i001 == 2)
  1829. {
  1830. if(CMD_XYF[0] == 0x11)
  1831. {
  1832. i = xyfaddr_max;
  1833. }
  1834. else
  1835. {
  1836. i = CMD_XYF[0] - 0x11;
  1837. }
  1838. pxyf[i].XYF_ErrorCnt++;
  1839. if (pxyf[i].XYF_ErrorCnt > pcang->sensorBusMaxReTry)
  1840. {
  1841. pxyf[i].XYF_ErrorCnt = pcang->sensorBusMaxReTry + 1;
  1842. pxyf[i].XYF_Error = 1;
  1843. }
  1844. }
  1845. }
  1846. if(i001< 18)
  1847. i001++;
  1848. else
  1849. i001 = 0;
  1850. osDelay(40);
  1851. }
  1852. /* USER CODE END StartTask02 */
  1853. }
  1854. /* USER CODE BEGIN Header_StartTask03 */
  1855. /**
  1856. * @brief Function implementing the myTask03 thread.
  1857. * @param argument: Not used
  1858. * @retval None
  1859. */
  1860. /* USER CODE END Header_StartTask03 */
  1861. /*
  1862. //发送华天三点式温度传感器命令轮询
  1863. //发送人控大盖盖命令轮询
  1864. //雷达液位传感器命令
  1865. //发送小盖传感器轮询
  1866. //发送磁致伸缩液位计命令轮询
  1867. ?
  1868. */
  1869. #include "rkg.h"
  1870. void StartTask03(void *argument) //人孔盖总线传感器 UART1
  1871. {
  1872. /* USER CODE BEGIN StartTask03 */
  1873. /* Infinite loop */
  1874. /* USER CODE BEGIN StartTask02 */
  1875. static uint8_t i001=0,i002 = 0,i003 = 0,receive_error = 0;
  1876. uint16_t rkgaddr_max = 0,temaddr_max = 0,leveladdr_max = 0,RKG_angle = 0;
  1877. static uint16_t i = 0,rkdg_cnt = 0,rkxg_cnt = 0,level_cnt = 0,tem_cnt = 0,temp_dot_cnt=0,temp_dot_dex=0,ModbusCRC = 0,ModbusCRC1 = 0;
  1878. uint16_t rx_len,head = 0;
  1879. S_ANGLEDATA* psATsk3 = gs_AngleData;
  1880. KZQ_Inf* pkzq = &kzq_inf;
  1881. RKG_Inf* prkg = rkg_inf;
  1882. Cang_Inf* pcang = &cang_inf;
  1883. Level_Inf* plevel = level_inf;
  1884. Tem_Inf* ptem = tem_inf;
  1885. Pressure_Inf* pPressure = pressure_inf;
  1886. typedef union{
  1887. float QDGH_data_temp; //青鸟贵和磁致伸缩液位温度一体传感器
  1888. uint8_t arr[4];
  1889. }Hex_to_float;
  1890. static Hex_to_float hex_to_float;
  1891. uint8_t pressureaddr_max = 0;
  1892. leveladdr_max=0;
  1893. if(pcang->Temperture==2)
  1894. pcang->Temperture=3;
  1895. for(i = 0;i < pcang->Cang_Num;i++)
  1896. {
  1897. rkgaddr_max += pcang->RKG_Num[i];
  1898. pressureaddr_max += pcang->Pressure_Num[i]; //人孔盖最大地址
  1899. leveladdr_max++;
  1900. temaddr_max++;
  1901. }
  1902. /*if(pcang->RKG_Type==0)
  1903. {
  1904. rkgaddr_max += 1;
  1905. }*/
  1906. i = 0;
  1907. extern uint8_t USART1_RX_BUF002[Uart2_BUF_SIZE];
  1908. extern int data_lengthU1;
  1909. extern int flagU1Rx;
  1910. extern uint8_t USART1_RX_BUF002_print[Uart1_BUF_SIZE];
  1911. /* Infinite loop */
  1912. for(;;)
  1913. {
  1914. osDelay(10); //以ms为单位
  1915. //HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_0); //已经移至task12 500ms闪烁 邵磊明修改
  1916. HAL_GPIO_TogglePin(WDI_sp706_kanmemgou_GPIO_Port, WDI_sp706_kanmemgou_Pin);
  1917. if(Flash_Change)
  1918. {
  1919. rkgaddr_max = 0;
  1920. leveladdr_max=0;
  1921. temaddr_max = 0;
  1922. pressureaddr_max = 0;
  1923. if(pcang->Temperture==2)
  1924. pcang->Temperture=3;
  1925. for(i = 0;i < pcang->Cang_Num;i++)
  1926. {
  1927. rkgaddr_max += pcang->RKG_Num[i];
  1928. pressureaddr_max += pcang->Pressure_Num[i]; //人孔盖最大地址
  1929. leveladdr_max++;
  1930. temaddr_max++;
  1931. }
  1932. /*if(pcang->RKG_Type==0)
  1933. {
  1934. rkgaddr_max += 1;
  1935. }*/
  1936. Flash_Change = 0;
  1937. }
  1938. if(pkzq->USE_RKG == 0) //平台未控制卸油阀总线,正常轮询数据
  1939. {
  1940. if(i001==0) //发送人控大盖盖命令轮询
  1941. {
  1942. if((pcang->RKG_DG != 0) && (pcang->RKG_Type!=2))
  1943. {
  1944. if(pcang->RKG_Type == 0)
  1945. {
  1946. if(CMD_RKG[0] == 0x1)
  1947. {
  1948. if(i003 >= rkgaddr_max)
  1949. i003 = 0;
  1950. ++i003;
  1951. CMD_RKG[0] = 1+i003*2;
  1952. prkg[i003].RTData_Num++;
  1953. }
  1954. else
  1955. {
  1956. CMD_RKG[0] = 0x1;
  1957. prkg[0].RTData_Num++;
  1958. }
  1959. }
  1960. else
  1961. {
  1962. prkg[CMD_RKG[0] - 0x30].RTData_Num++;
  1963. if(CMD_RKG[0] - 0x30 < rkgaddr_max)
  1964. {
  1965. ++i003;
  1966. CMD_RKG[0]=0x30+i003;
  1967. }
  1968. else
  1969. {
  1970. CMD_RKG[0] = 0x31;
  1971. i003 = 1;
  1972. }
  1973. }
  1974. ModbusCRC = LIB_CRC_MODBUS(CMD_RKG,6);
  1975. CMD_RKG[6] = ModbusCRC>>8;
  1976. CMD_RKG[7] = ModbusCRC&0xff;
  1977. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//
  1978. delay_sys_us(80);
  1979. //if(pcang->RKG_Type == 0x01)
  1980. // HAL_UART_Transmit(&huart1,Data_Head,2,10);
  1981. {
  1982. HAL_UART_Transmit_IT(&huart1,CMD_RKG,8);
  1983. while (huart1.gState == HAL_UART_STATE_BUSY_TX)
  1984. {
  1985. osDelay(1);
  1986. }
  1987. } //HAL_UART_Transmit(&huart1,CMD_RKG,8,100);
  1988. //if(pcang->RKG_Type == 0x01)
  1989. // HAL_UART_Transmit(&huart1,Data_Head,2,10);
  1990. //delay_sys_us(80);
  1991. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//
  1992. #if 0
  1993. if(prkg[CMD_RKG[0] - 0x30].RTData_Num > RT_ERRORCNT) //每个传感器每发送一帧 基准角度为0x30
  1994. {
  1995. prkg[CMD_RKG[0] - 0x30].RTData_Num = RT_ERRORCNT;
  1996. prkg[CMD_RKG[0] - 0x30].RKDG_ErrorCnt = RT_ERRORCNT;
  1997. }
  1998. else
  1999. #endif
  2000. }
  2001. else
  2002. i001 = 3;
  2003. }
  2004. if(i001==3) //发送小盖传感器轮询
  2005. {
  2006. if(pcang->RKG_XG == 0x01)
  2007. {
  2008. ModbusCRC = LIB_CRC_MODBUS(CMD_RKG_XG,6);
  2009. CMD_RKG_XG[6] = ModbusCRC>>8;
  2010. CMD_RKG_XG[7] = ModbusCRC&0xff;
  2011. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//
  2012. delay_sys_us(80);
  2013. if(pcang->RKG_Type == 0x01)
  2014. HAL_UART_Transmit(&huart1,Data_Head,2,10);
  2015. HAL_UART_Transmit(&huart1,CMD_RKG_XG,8,100);
  2016. if(pcang->RKG_Type == 0x01)
  2017. HAL_UART_Transmit(&huart1,Data_Head,2,10);
  2018. delay_sys_us(80);
  2019. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//
  2020. if(prkg[CMD_RKG_XG[0]-0x40].RTData_Num > RT_ERRORCNT)
  2021. {
  2022. prkg[CMD_RKG_XG[0]-0x40].RTData_Num = RT_ERRORCNT;
  2023. prkg[CMD_RKG_XG[0]-0x40].RKXG_ErrorCnt = RT_ERRORCNT;
  2024. }
  2025. else
  2026. prkg[CMD_RKG_XG[0]-0x40].RTData_Num++; //每个传感器发送帧累加
  2027. if(CMD_RKG_XG[0] - 0x41 < rkgaddr_max -1)
  2028. CMD_RKG_XG[0]++;
  2029. else
  2030. CMD_RKG_XG[0] = 0x41;
  2031. }
  2032. else
  2033. i001 = 6;
  2034. }
  2035. if(i001==6) //发送磁致伸缩液位计命令轮询 邵磊明增加
  2036. {
  2037. if(pcang->Level == LEVEL_CZSS) //磁致伸缩传感器轮询 邵磊明增加
  2038. {
  2039. ModbusCRC = LIB_CRC_MODBUS(CMD_GetTempAndYewei,6);
  2040. CMD_GetTempAndYewei[6] = ModbusCRC>>8;
  2041. CMD_GetTempAndYewei[7] = ModbusCRC&0xff;
  2042. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//
  2043. delay_sys_us(80);
  2044. //HAL_UART_Transmit(&huart1,CMD_GetTempAndYewei,8,100);
  2045. //delay_sys_us(80);
  2046. HAL_UART_Transmit_IT(&huart1,CMD_GetTempAndYewei,8);
  2047. while (huart1.gState == HAL_UART_STATE_BUSY_TX)
  2048. {
  2049. osDelay(1);
  2050. }
  2051. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//
  2052. /*if(plevel[CMD_GetTempAndYewei[0]-0x50].RTData_Num > RT_ERRORCNT)
  2053. {
  2054. plevel[CMD_GetTempAndYewei[0]-0x50].RTData_Num = RT_ERRORCNT;
  2055. plevel[CMD_GetTempAndYewei[0]-0x50].Level_ErrorCnt = RT_ERRORCNT;
  2056. }
  2057. else*/
  2058. plevel[CMD_GetTempAndYewei[0]-0x50].RTData_Num++; //每个传感器发送帧累加 基准角度为0x30
  2059. if(CMD_GetTempAndYewei[0]-0x50 < leveladdr_max)
  2060. CMD_GetTempAndYewei[0]++;
  2061. else
  2062. CMD_GetTempAndYewei[0] = 0x51;
  2063. }
  2064. else if(pcang->Level == LEVEL_LDYW) //雷达液位传感器命令轮询 20210818邵增加
  2065. {
  2066. ModbusCRC = LIB_CRC_MODBUS(CMD_LDYW,6);
  2067. CMD_LDYW[6] = ModbusCRC>>8;
  2068. CMD_LDYW[7] = ModbusCRC&0xff;
  2069. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//
  2070. delay_sys_us(80);
  2071. //HAL_UART_Transmit(&huart1,CMD_LDYW,8,100);
  2072. //delay_sys_us(80);
  2073. HAL_UART_Transmit_IT(&huart1, CMD_LDYW, 8);
  2074. while (huart1.gState == HAL_UART_STATE_BUSY_TX)
  2075. {
  2076. osDelay(1);
  2077. }
  2078. HAL_GPIO_WritePin(GPIOB, Con01_uart1_rankonggai_Pin, GPIO_PIN_SET); //
  2079. /*if (prkg[CMD_RKG[0] - 0x50].RTData_Num > RT_ERRORCNT) //每个传感器每发送一帧 基准角度为0x30
  2080. {
  2081. plevel[CMD_RKG[0] - 0x50].RTData_Num = RT_ERRORCNT;
  2082. plevel[CMD_RKG[0] - 0x50].Level_ErrorCnt = RT_ERRORCNT;
  2083. }
  2084. else*/
  2085. plevel[CMD_LDYW[0] - LEVEL_STARTADDR].RTData_Num++;
  2086. if ((CMD_LDYW[0] - LEVEL_STARTADDR+1) < leveladdr_max)
  2087. CMD_LDYW[0]++;
  2088. else
  2089. CMD_LDYW[0] = LEVEL_STARTADDR;
  2090. }
  2091. else
  2092. i001=9;
  2093. }
  2094. if(i001==9) //发送华天三点式温度传感器命令轮询 邵磊明增加
  2095. {
  2096. if(Tem_FST100_611 == pcang->Temperture )
  2097. {
  2098. // taskENTER_CRITICAL();
  2099. ModbusCRC = LIB_CRC_MODBUS(CMD_TemAng,6);
  2100. CMD_TemAng[6] = ModbusCRC>>8;
  2101. CMD_TemAng[7] = ModbusCRC&0xff;
  2102. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//
  2103. delay_sys_us(80);
  2104. HAL_UART_Transmit_IT(&huart1,CMD_TemAng,8);
  2105. while (huart1.gState == HAL_UART_STATE_BUSY_TX)
  2106. {
  2107. osDelay(1);
  2108. }
  2109. //HAL_UART_Transmit(&huart1,CMD_GetTempHuaTian,8,100);
  2110. //delay_sys_us(80);
  2111. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//
  2112. // taskEXIT_CRITICAL();
  2113. ptem[CMD_TemAng[0] - TEM_STARTADDR].RTData_Num++;
  2114. ptem[CMD_TemAng[0] - TEM_STARTADDR+1].RTData_Num++;
  2115. if((CMD_TemAng[0] - TEM_STARTADDR+1)*2 < temaddr_max)
  2116. CMD_TemAng[0] = CMD_TemAng[0]+1;
  2117. else
  2118. CMD_TemAng[0] = TEM_STARTADDR;
  2119. }else if(Tem_FST100_1007 == pcang->Temperture )
  2120. {
  2121. // taskENTER_CRITICAL();
  2122. ModbusCRC = LIB_CRC_MODBUS(CMD_Temperature,6);
  2123. CMD_Temperature[6] = ModbusCRC>>8;
  2124. CMD_Temperature[7] = ModbusCRC&0xff;
  2125. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//
  2126. delay_sys_us(80);
  2127. HAL_UART_Transmit_IT(&huart1,CMD_Temperature,8);
  2128. while (huart1.gState == HAL_UART_STATE_BUSY_TX)
  2129. {
  2130. osDelay(1);
  2131. }
  2132. //HAL_UART_Transmit(&huart1,CMD_GetTempHuaTian,8,100);
  2133. //delay_sys_us(80);
  2134. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//
  2135. // taskEXIT_CRITICAL();
  2136. ptem[CMD_Temperature[0] - TEM_STARTADDR].RTData_Num++;
  2137. if((CMD_Temperature[0] - TEM_STARTADDR+1) < temaddr_max)
  2138. CMD_Temperature[0] = CMD_Temperature[0]+1;
  2139. else
  2140. CMD_Temperature[0] = TEM_STARTADDR;
  2141. }else
  2142. {
  2143. i001=12;
  2144. }
  2145. }
  2146. if(i001==12){
  2147. if(Pressure_FST100_1007 == pcang->Pressure )
  2148. {
  2149. ModbusCRC = LIB_CRC_MODBUS(CMD_Pressure, 6);
  2150. CMD_Pressure[6] = ModbusCRC >> 8;
  2151. CMD_Pressure[7] = ModbusCRC & 0xff;
  2152. HAL_GPIO_WritePin(GPIOB, Con01_uart1_rankonggai_Pin, GPIO_PIN_RESET);
  2153. delay_sys_us(80);
  2154. HAL_UART_Transmit(&huart1, CMD_Pressure, 8, 200);
  2155. delay_sys_us(80);
  2156. HAL_GPIO_WritePin(GPIOB, Con01_uart1_rankonggai_Pin, GPIO_PIN_SET);
  2157. pPressure[CMD_Pressure[0] - PRESSURE_STARTADDR].RTData_Num++;
  2158. if (CMD_Pressure[0] - PRESSURE_STARTADDR +1 < pressureaddr_max)
  2159. CMD_Pressure[0]++;
  2160. else
  2161. CMD_Pressure[0] = PRESSURE_STARTADDR;
  2162. }else
  2163. {
  2164. i001=0x0;
  2165. continue;
  2166. }
  2167. }
  2168. }
  2169. else //平台通过卸油阀总线直接操作传感器
  2170. {
  2171. if(i002 == 3)
  2172. {
  2173. extern uint16_t Uart_len_TouChuan;
  2174. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//
  2175. delay_sys_us(80);
  2176. #if 0
  2177. if((RKG_TxBuf[0] == 0x0D)&&(RKG_TxBuf[1] == 0x0A))
  2178. HAL_UART_Transmit(&huart1,RKG_TxBuf,12,100);
  2179. else
  2180. HAL_UART_Transmit(&huart1,RKG_TxBuf,8,100);
  2181. delay_sys_us(80);
  2182. #else
  2183. HAL_UART_Transmit_IT(&huart1,RKG_TxBuf,Uart_len_TouChuan);
  2184. while (huart1.gState == HAL_UART_STATE_BUSY_TX)
  2185. {
  2186. osDelay(1);
  2187. }
  2188. #endif
  2189. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//
  2190. flagU1Rx=0;
  2191. }
  2192. i002++;
  2193. if(((flagU1Rx==1) && (i002 > 3)) || i002>10)
  2194. {
  2195. pkzq->USE_RKG = 0;
  2196. i002 = 0;
  2197. continue;
  2198. }
  2199. }
  2200. //来自UART1,即人孔盖总线的命令 电路板上标志位人孔盖
  2201. if(flagU1Rx==1)
  2202. {
  2203. flagU1Rx = 0;
  2204. receive_error = 0;
  2205. rx_len = USART1_RX_BUF002[2];
  2206. ModbusCRC = USART1_RX_BUF002[(3+rx_len)]<<8;
  2207. ModbusCRC |= USART1_RX_BUF002[(3+rx_len+1)];
  2208. if((USART1_RX_BUF002[head+0] >= 0x30 && USART1_RX_BUF002[head+0] <= 0x3F) || (USART1_RX_BUF002[head+0] >= 0x1 && USART1_RX_BUF002[head+0] <= 0x10)) //人孔大盖数据 地址0x30为基准传感器
  2209. {
  2210. if(USART1_RX_BUF002[head+1]!=0x03&&USART1_RX_BUF002[head+1]!=0x06) //校验读写属性
  2211. {
  2212. receive_error = 1;
  2213. }
  2214. else if(USART1_RX_BUF002[head+2] != 0x04) //校验数据长度
  2215. {
  2216. receive_error = 1;
  2217. }
  2218. else if(ModbusCRC != LIB_CRC_MODBUS(USART1_RX_BUF002,7)) //校验CRC
  2219. {
  2220. receive_error = 1;
  2221. }
  2222. // if((pcang->RKG_Type == 0)&&(USART1_RX_BUF002[head]>=0x30)&&(USART1_RX_BUF002[head] <=0x4F))
  2223. RKG_angle = (USART1_RX_BUF002[head+4]<<8)|USART1_RX_BUF002[head+3];
  2224. // else
  2225. // RKG_angle = (USART1_RX_BUF002[head+3]<<8)|USART1_RX_BUF002[head+4];
  2226. if((USART1_RX_BUF002[head+1] == 0x03)&&(receive_error == 0)) //读取数据返回
  2227. {//童赟 磁电编码 磁编码 人孔盖
  2228. if(USART1_RX_BUF002[head]==1)
  2229. {
  2230. prkg[0].RKDG_ErrorCnt = 0;
  2231. prkg[0].RKDG_Error=0;
  2232. }
  2233. else
  2234. {
  2235. prkg[i003].RKDG_ErrorCnt = 0;
  2236. prkg[i003].RKDG_Error=0;
  2237. }
  2238. if(USART1_RX_BUF002[head]==1)
  2239. {
  2240. AGL_AddNewData(RKG_angle,0);
  2241. }
  2242. else
  2243. {
  2244. AGL_AddNewData(RKG_angle,i003);
  2245. }
  2246. #if 0
  2247. //邵磊明修改 20211027 从rkg.c剪切到此处
  2248. if(psATsk3[i003].uiDG < 0 ||psATsk3[USART1_RX_BUF002[head]-0x30].uiDG >= 27000)//角度
  2249. {
  2250. prkg[USART1_RX_BUF002[head]-0x30].RKDG_ErrorCnt++;
  2251. }
  2252. #endif
  2253. // if( - psATsk3[USART1_RX_BUF002[head]-0x30].uiDG > prkg->RKG_Threshold || psATsk3[USART1_RX_BUF002[head]-0x30].uiDG > prkg->RKG_Threshold)
  2254. // prkg[USART1_RX_BUF002[head]-0x30].RKDG_StateCnt++;
  2255. // else
  2256. // prkg[USART1_RX_BUF002[head]-0x30].RKDG_StateCnt = 0;
  2257. if(pcang->RKG_Type == 0)
  2258. {
  2259. AGL_CalcDeltaAll(USART1_RX_BUF002[head],0);
  2260. }
  2261. #if 0 //倾角大盖计算
  2262. if(rkdg_cnt < RKG_BUF_DEP)
  2263. {
  2264. if(USART1_RX_BUF002[head] == 0x30)
  2265. {
  2266. prkg[USART1_RX_BUF002[head] - 0x30].RKG_JZData[rkdg_cnt] = RKG_angle;
  2267. }
  2268. else
  2269. {
  2270. prkg[USART1_RX_BUF002[head] - 0x30].RKG_DGData[rkdg_cnt] = RKG_angle;
  2271. rkdg_cnt++;
  2272. }
  2273. }
  2274. if(rkdg_cnt == RKG_BUF_DEP)
  2275. {
  2276. rkdg_cnt = 0;
  2277. }
  2278. #endif
  2279. //李伟修改 20211027 从rkg.c剪切到此处;开始
  2280. if (USART1_RX_BUF002[head] != 1)
  2281. {
  2282. if (psATsk3[i003].uiDG >= 0 || psATsk3[i003].uiDG <= 27000) //角度
  2283. {
  2284. if (-psATsk3[i003].uiDG > prkg->RKG_Threshold || psATsk3[i003].uiDG > prkg->RKG_Threshold)
  2285. prkg[i003].RKDG_StateCnt++;
  2286. else
  2287. prkg[i003].RKDG_StateCnt = 0;
  2288. if (prkg[i003].RKDG_StateCnt >= prkg[i003].RKG_StateKeepNum)
  2289. {
  2290. // RisingEdge++;
  2291. prkg[i003].RKDG_StateCnt = prkg[i003].RKG_StateKeepNum;
  2292. prkg[i003].RKDG_State = 1;
  2293. }
  2294. else
  2295. {
  2296. prkg[i003].RKDG_State = 0;
  2297. }
  2298. }
  2299. }
  2300. //李伟修改 20211027 从rkg.c剪切到此处;开始
  2301. i001 = 3;
  2302. continue;
  2303. }
  2304. }
  2305. else if(USART1_RX_BUF002[head+0] >= 0x40 && USART1_RX_BUF002[head+0] <= 0x4F) //人孔小盖数据 地址0x30为基准传感器
  2306. {
  2307. prkg[USART1_RX_BUF002[head] - 0x30].RKXG_ErrorCnt = 0;
  2308. prkg[USART1_RX_BUF002[head+0]-0x40].RTData_Num = 1;
  2309. if(USART1_RX_BUF002[head+1]!=0x03&&USART1_RX_BUF002[head+1]!=0x06) //校验读写属性
  2310. {
  2311. receive_error = 1;
  2312. }
  2313. else if(USART1_RX_BUF002[head+2] != 0x04) //校验数据长度
  2314. {
  2315. receive_error = 1;
  2316. }
  2317. else if(ModbusCRC != LIB_CRC_MODBUS(USART1_RX_BUF002,7)) //校验CRC
  2318. {
  2319. receive_error = 1;
  2320. }
  2321. if((USART1_RX_BUF002[head+1] == 0x03)&&(receive_error == 0)) //读取数据返回
  2322. {
  2323. AGL_AddNewData((USART1_RX_BUF002[head+3]<<8)|USART1_RX_BUF002[head+4],USART1_RX_BUF002[head]);
  2324. if(rkxg_cnt < RKG_BUF_DEP)
  2325. {
  2326. prkg[USART1_RX_BUF002[head] - 0x40].RKG_XGData[rkxg_cnt] = USART1_RX_BUF002[head+4]<<8;
  2327. prkg[USART1_RX_BUF002[head] - 0x40].RKG_XGData[rkxg_cnt] |= USART1_RX_BUF002[head+3];
  2328. rkxg_cnt++;
  2329. }
  2330. if(rkxg_cnt == RKG_BUF_DEP)
  2331. {
  2332. rkxg_cnt = 0;
  2333. }
  2334. }
  2335. else if((USART1_RX_BUF002[head+1] == 0x06)&&(receive_error == 0)) //写入数据返回
  2336. {
  2337. }
  2338. i001 = 6;
  2339. continue;
  2340. }
  2341. else if(USART1_RX_BUF002[0] >= 0x50 && USART1_RX_BUF002[0] <= 0x5F) //液位计数据 邵磊明增加
  2342. {
  2343. Prase_Level(USART1_RX_BUF002, pcang->Level);
  2344. i001 = 9;
  2345. continue;
  2346. }
  2347. else if(USART1_RX_BUF002[0] >=0x60 && USART1_RX_BUF002[0] <= 0x6f) //华天三点式温度传感器接收数据 邵磊明增加
  2348. {
  2349. Parse_Tem(USART1_RX_BUF002, pcang->Temperture);
  2350. i001 = 15;
  2351. continue;
  2352. }
  2353. else if(USART1_RX_BUF002[0] >=0xA0 && USART1_RX_BUF002[0] <= 0xAF) //暂未使用
  2354. {
  2355. if (i001 < 9){
  2356. }else if(i001 < 12){
  2357. Parse_Tem(USART1_RX_BUF002, pcang->Temperture);
  2358. i001 = 12;
  2359. continue;
  2360. }else if(i001 < 15){
  2361. Prase_Pressure(USART1_RX_BUF002, pcang->Pressure);
  2362. i001 = 0;
  2363. continue;
  2364. }
  2365. }
  2366. else if(0) //暂未使用
  2367. {
  2368. }
  2369. }
  2370. else
  2371. {
  2372. if (i001 == 2)
  2373. {
  2374. if(pcang->RKG_Type == 0)
  2375. {
  2376. if(CMD_RKG[0] == 0x1)
  2377. {
  2378. i = 0;
  2379. }
  2380. else
  2381. {
  2382. i = i003;
  2383. }
  2384. }
  2385. else
  2386. {
  2387. i = i003;
  2388. }
  2389. prkg[i].RKDG_ErrorCnt++;
  2390. if (prkg[i].RKDG_ErrorCnt > pcang->sensorBusMaxReTry)
  2391. {
  2392. prkg[i].RKDG_ErrorCnt = pcang->sensorBusMaxReTry + 1;
  2393. prkg[i].RKDG_Error = 1;
  2394. }
  2395. }
  2396. if (i001 == 8) //液位错误
  2397. {
  2398. Level_Error(CMD_LDYW[0]);
  2399. }else if(i001 == 11){
  2400. if(Tem_FST100_611 == pcang->Temperture){
  2401. Tem_Error(CMD_TemAng[0]);
  2402. }else if(Tem_FST100_1007 == pcang->Temperture){
  2403. Tem_Error(CMD_Temperature[0]);
  2404. }
  2405. }else if(i001 == 15){
  2406. Pressure_Error(CMD_Pressure[0]);
  2407. }
  2408. }
  2409. if(i001<16)
  2410. i001++;
  2411. else
  2412. i001 = 0;
  2413. osDelay(40);
  2414. }
  2415. /* USER CODE END StartTask03 */
  2416. }
  2417. /* USER CODE BEGIN Header_StartTask04 */
  2418. /**
  2419. * @brief Function implementing the myTask04 thread.
  2420. * @param argument: Not used
  2421. * @retval None
  2422. */
  2423. #include "Data_deal.h"
  2424. uint8_t USART2_RX_BUF003[128];
  2425. uint8_t F_STATE[70] = {0};
  2426. uint8_t ptxCang01Temp[150];
  2427. uint32_t KZQ_RTerror = 0;
  2428. /* USER CODE END Header_StartTask04 */
  2429. void StartTask04(void *argument) //控制器数据处理 uart2
  2430. {
  2431. /* USER CODE BEGIN StartTask04 */
  2432. /* Infinite loop */
  2433. uint8_t* ptx = CMD_KZQ;
  2434. uint16_t ModbusCRC_lsb = 0,ModbusCRC = 0,SetSuccess = 0,ModbusCRC1 = 0,SetSuccess1 = 0,SetSuccess2=0,SetSuccess3=0;
  2435. static uint16_t i = 0;
  2436. int i000;
  2437. uint8_t* send_ptr;
  2438. uint16_t send_len;
  2439. uint32_t tmpU32;
  2440. KZQ_Inf* pkzq = &kzq_inf;
  2441. extern uint8_t USART2_RX_BUF002[Uart2_BUF_SIZE];
  2442. extern int data_lengthU2;
  2443. extern int flagU2Rx;
  2444. extern uint8_t USART2_RX_BUF002_print[Uart2_BUF_SIZE];
  2445. //延时1S 启动
  2446. osDelay(1000);
  2447. /* Infinite loop */
  2448. for(;;)
  2449. {
  2450. osDelay(2); //以ms为单位
  2451. // HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_0);
  2452. HAL_GPIO_TogglePin(WDI_sp706_kanmemgou_GPIO_Port, WDI_sp706_kanmemgou_Pin);
  2453. if (flagU2Rx == 1)
  2454. {
  2455. flagU2Rx = 0;
  2456. if ((rx1_len > 300) || ((USART2_RX_BUF002[0] == 0xa5) && (USART2_RX_BUF002[1] == 0x5a)))
  2457. {
  2458. tmpU32 = (USART2_RX_BUF002[0] << 24) | (USART2_RX_BUF002[1] << 16) | (USART2_RX_BUF002[2] << 8) | (USART2_RX_BUF002[3]);
  2459. if (StartBytes_IAP == tmpU32)
  2460. {
  2461. Process_CMD_IAP_Update();
  2462. continue;
  2463. }
  2464. }
  2465. // KZQ_RTerror = 0;
  2466. // ASC转换为16进制,收到数据为:3901开头的数据总长度131字节
  2467. if ((USART2_RX_BUF002[0] == 0x3A) && (USART2_RX_BUF002[1] == 0x33) && (USART2_RX_BUF002[2] == 0x39) && (USART2_RX_BUF002[3] == 0x30)) //判断帧头
  2468. {
  2469. if (data_lengthU2 != 131)
  2470. {
  2471. ++KZQ_RTerror;
  2472. continue;
  2473. }
  2474. for (i000 = 0; i000 < (data_lengthU2 - 3) / 2; i000++)
  2475. {
  2476. T2C_RemoteCaliDat001.PayLoadData[i000] = MODBUS_ASCII_AsciiToHex(USART2_RX_BUF002 + 1 + 0 + i000 * 2);
  2477. USART2_RX_BUF003[i000] = MODBUS_ASCII_AsciiToHex(USART2_RX_BUF002 + 1 + 0 + i000 * 2);
  2478. }
  2479. //解析后的数据拷贝过来
  2480. memcpy(USART2_RX_BUF002, USART2_RX_BUF003, (data_lengthU2 - 3) / 2);
  2481. data_lengthU2 = (data_lengthU2 - 3) / 2;
  2482. }
  2483. if (data_lengthU2 < 5)
  2484. continue;
  2485. ModbusCRC = USART2_RX_BUF002[data_lengthU2 - 1] << 8;
  2486. ModbusCRC |= USART2_RX_BUF002[data_lengthU2 - 2];
  2487. ModbusCRC_lsb = USART2_RX_BUF002[data_lengthU2 - 2] << 8;
  2488. ModbusCRC_lsb |= USART2_RX_BUF002[data_lengthU2 - 1];
  2489. ModbusCRC1 = LIB_CRC_MODBUS(USART2_RX_BUF002, data_lengthU2 - 2);
  2490. if ((USART2_RX_BUF002[0] != 0x39) && (USART2_RX_BUF002[1] <= 0x01) && (USART2_RX_BUF002[2] <= 0x95) && (USART2_RX_BUF002[3] <= 0x50)) //判断帧头
  2491. {
  2492. pkzq->KZQ_Error++;
  2493. KZQ_RTerror = 1;
  2494. }
  2495. else if (USART2_RX_BUF002[5] != 0x01) //校验地址
  2496. {
  2497. pkzq->KZQ_Error++;
  2498. KZQ_RTerror = 1;
  2499. }
  2500. else if ((USART2_RX_BUF002[7] != 0x03) && (USART2_RX_BUF002[7] != 0x06)) //校验数据长度
  2501. {
  2502. pkzq->KZQ_Error++;
  2503. KZQ_RTerror = 1;
  2504. }
  2505. /*else if(ModbusCRC != ModbusCRC1 && ModbusCRC_lsb != ModbusCRC1) //校验CRC
  2506. {
  2507. pkzq->KZQ_Error++;
  2508. KZQ_RTerror = 1;
  2509. }*/
  2510. else
  2511. {
  2512. pkzq->KZQ_Error = 0;
  2513. KZQ_RTerror = 0;
  2514. for (i = 0; i < 64; i++)
  2515. pkzq->data_buf[i] = USART2_RX_BUF002[i];
  2516. for(i = 0;i < 16;i++)
  2517. ptx[i] = USART2_RX_BUF002[i];
  2518. }
  2519. if(KZQ_RTerror == 0)
  2520. {
  2521. send_len=0;
  2522. pkzq->sensor_reg = USART2_RX_BUF002[8];
  2523. pkzq->sensor_reg = pkzq->sensor_reg<<8;
  2524. pkzq->sensor_reg |= USART2_RX_BUF002[9];
  2525. switch(pkzq->sensor_reg)
  2526. {
  2527. case 0x10:
  2528. RstCPU(); //复位
  2529. break;
  2530. case 0x13:
  2531. Sen_CangState_old(F_STATE); //老协议 传输阀门状态
  2532. send_ptr = F_STATE;
  2533. send_len = 62;
  2534. break;
  2535. case 0x20:
  2536. SetSuccess = Read_CangState(ptx); //读取仓状态
  2537. break;
  2538. case 0x27:
  2539. SetSuccess = Read_CangSensorData(ptx); //读取仓传感器
  2540. break;
  2541. case 0x40:
  2542. SetSuccess = Angle_SetZero(ptx); //姿态传感器置零
  2543. for(i = 0;i < 64;i++)
  2544. ptx[i] = USART2_RX_BUF002[i];
  2545. break;
  2546. case 0x50:
  2547. SetSuccess = XYF_SetOFF(ptx); //远程卸油阀标定关 slm
  2548. for(i = 0;i < 64;i++)
  2549. ptx[i] = USART2_RX_BUF002[i];
  2550. break;
  2551. case 0x51:
  2552. SetSuccess = XYF_SetThreshold(ptx); //设置卸油阀传感器开关门限
  2553. break;
  2554. case 0x52:
  2555. SetSuccess = RKG_SetZero(ptx); //人孔盖传感器置零
  2556. for(i = 0;i < 64;i++)
  2557. ptx[i] = USART2_RX_BUF002[i];
  2558. break;
  2559. case 0x55:
  2560. SetSuccess = Read_Sensor(ptx); // 远程读取传感器数据 slm
  2561. break;
  2562. case 0x70:
  2563. break;
  2564. case 0x71:
  2565. SetSuccess = BGY_SetThreshold(ptx); //设置壁挂油门限
  2566. break;
  2567. case 0x72:
  2568. SetSuccess = RKG_SetThreshold(ptx); //设置人孔盖开关门限
  2569. break;
  2570. case 0x73:
  2571. SetSuccess = Sensor_SetJudgefNum(ptx); //设置开关判断次数
  2572. break;
  2573. case 0x74:
  2574. SetSuccess = CJQ_SetConfig(ptx); //设置采集器参数
  2575. Flash_Change = 1;
  2576. break;
  2577. case 0x75:
  2578. SetSuccess = RKG_SetTypeNum(ptx); //设置人孔盖种类、数量
  2579. Flash_Change = 1;
  2580. break;
  2581. case 0x76:
  2582. SetSuccess = XYF_SetTypeNum(ptx); //设置卸油阀种类、数量
  2583. Flash_Change = 1;
  2584. break;
  2585. case 0x77:
  2586. SetSuccess = HDF_SetTypeNum(ptx); //设置海底阀种类、数量
  2587. Flash_Change = 1;
  2588. break;
  2589. case 0x78:
  2590. SetSuccess = Level_SetType(ptx); //设置液位计种类
  2591. Flash_Change = 1;
  2592. break;
  2593. case 0x79:
  2594. SetSuccess = Angle_SetType(ptx); //设置姿态传感器种类
  2595. Flash_Change = 1;
  2596. break;
  2597. case 0x7a:
  2598. SetSuccess = Tem_SetType(ptx); //设置温度传感器种类
  2599. //Flash_Change = 1;
  2600. break;
  2601. case 0x7b:
  2602. HDF_Set_CloseVal(ptx); //设置智能海底阀放大倍数
  2603. Flash_Change = 1;
  2604. break;
  2605. case 0x7c:
  2606. HDF_Set_Threshold(ptx); //设置智能海底阀放大倍数
  2607. Flash_Change = 1;
  2608. break;
  2609. case 0x7d:
  2610. HDF_Set_Gain(ptx); //设置智能海底阀放大倍数
  2611. Flash_Change = 1;
  2612. break;
  2613. case 0x7e: HDF_Reset(ptx); //设置智能海底阀放大倍数
  2614. Flash_Change = 1;
  2615. break;
  2616. case 0x80:
  2617. SetSuccess = RW_SensorBusMaxRetry(ptx); //传感器总线重试最大值来获取异常
  2618. break;
  2619. case 0x81:
  2620. SetSuccess = RW_PinIoHitSameParam(ptx); //
  2621. break;
  2622. case 0x017e:
  2623. TOUCHUAN_UART_NUM(ptx); //设置智能海底阀放大倍数
  2624. Flash_Change = 1;
  2625. break;
  2626. //case 0x0180:
  2627. // SetSuccess = GRB_SET_Table(ptx); //罐容表配置 邵磊明增加
  2628. // Flash_Change = 1;
  2629. // break;
  2630. case 0x0190:
  2631. SetSuccess = Level_SetCalvalue(ptx); //设置液位计零点 邵磊明增加
  2632. Flash_Change = 1;
  2633. case 0x0121:
  2634. //SetSuccess = Level_SetCalvalue(ptx); //设置液位计种类
  2635. // Flash_Change = 1;
  2636. break;
  2637. case 0x0122:
  2638. //SetSuccess = Level_SetCalvalue(ptx); //设置液位计种类
  2639. // Flash_Change = 1;
  2640. break;
  2641. case 0x0220:
  2642. SetSuccess=Read_SoftVersion(ptx);
  2643. break;
  2644. case 0x1121:
  2645. SetSuccess1 = Read_CangSensorData_1to4(ptx); //读仓1-4传感器
  2646. if(SetSuccess1)
  2647. {
  2648. SetSuccess1=0;
  2649. ptx[232] = 0x00;
  2650. ptx[233] = 0x00;
  2651. send_ptr = ptx;
  2652. send_len = 234;
  2653. }
  2654. break;
  2655. #if 0
  2656. #else
  2657. case 0x1193:
  2658. case 0x1194:
  2659. case 0x1195:
  2660. case 0x1196:
  2661. case 0x1197:
  2662. case 0x1198:
  2663. case 0x1199:
  2664. case 0x119a:
  2665. SetSuccess2 = Read_CangSensorData_V2(ptx, (uint8_t)(pkzq->sensor_reg-0x1193+1));
  2666. if(SetSuccess2){
  2667. send_ptr = ptx;
  2668. send_len = 148;
  2669. SetSuccess2 = 0;
  2670. }
  2671. break;
  2672. #endif
  2673. case 0x119b:
  2674. SetSuccess3 = Read_ZhencheSensorData1(ptx); //读仓1-4传感器
  2675. if(SetSuccess3)
  2676. {
  2677. SetSuccess3=0;
  2678. send_ptr = ptx;
  2679. send_len = 96;
  2680. }
  2681. break;
  2682. case 0x1130:
  2683. Read_SensorData_New(ptx, &send_len);
  2684. send_ptr = ptx;
  2685. break;
  2686. default:
  2687. break;
  2688. }
  2689. //send_len=0;
  2690. if(0 == send_len){
  2691. if(SetSuccess){
  2692. ptx[60] = 0x00;
  2693. ptx[61] = 0x00;
  2694. }else{
  2695. ptx[60] = 0xFF;
  2696. ptx[61] = 0xFF;
  2697. }
  2698. send_ptr = ptx;
  2699. send_len = 62;
  2700. }
  2701. SetSuccess = 0;
  2702. if(send_len)
  2703. {
  2704. ModbusCRC = LIB_CRC_MODBUS(send_ptr,send_len);
  2705. send_ptr[send_len] = ModbusCRC>>8;
  2706. send_ptr[send_len+1] = ModbusCRC&0xff;
  2707. HAL_GPIO_WritePin(GPIOA,con03_uart2_kongzhiqi_Pin,GPIO_PIN_RESET);//
  2708. delay_sys_us(80);
  2709. HAL_UART_Transmit_IT(&huart2,send_ptr,send_len+2);
  2710. while (huart2.gState == HAL_UART_STATE_BUSY_TX)
  2711. {
  2712. osDelay(1);
  2713. }
  2714. delay_sys_us(80);
  2715. HAL_GPIO_WritePin(GPIOA,con03_uart2_kongzhiqi_Pin,GPIO_PIN_SET);//
  2716. }
  2717. }
  2718. flagU2Rx = 0;
  2719. }
  2720. }
  2721. /* USER CODE END StartTask04 */
  2722. }
  2723. /* USER CODE BEGIN Header_StartTask05 */
  2724. /**
  2725. * @brief Function implementing the myTask05 thread.
  2726. * @param argument: Not used
  2727. * @retval None
  2728. */
  2729. /* USER CODE END Header_StartTask05 */
  2730. //#include"level.h"
  2731. void StartTask05(void *argument)
  2732. {
  2733. /* USER CODE BEGIN StartTask05 */
  2734. /* Infinite loop */
  2735. Level_Inf *plevel = level_inf;
  2736. Cang_Inf *pcang = &cang_inf;
  2737. uint8_t i;
  2738. //float v000;
  2739. //uint16_t *VolArrayTsk05 = Volume_1cang;
  2740. //const uint16_t *HArrayTsk05 = H_1cang;
  2741. for (;;)
  2742. {
  2743. HAL_GPIO_TogglePin(WDI_sp706_kanmemgou_GPIO_Port, WDI_sp706_kanmemgou_Pin);
  2744. AGL_JudgeState();
  2745. for (i = 0; i < pcang->Cang_Num; i++)
  2746. {
  2747. // Value_Manage(i);
  2748. // for(uint8_t i = 0;i < 5;i++)
  2749. {
  2750. #if 0
  2751. switch (i)
  2752. {
  2753. case 0:
  2754. VolArrayTsk05 = Volume_1cang;
  2755. HArrayTsk05 = H_1cang;
  2756. break;
  2757. case 1:
  2758. VolArrayTsk05 = Volume_1cang;
  2759. HArrayTsk05 = H_1cang;
  2760. break;
  2761. case 2:
  2762. VolArrayTsk05 = Volume_2cang;
  2763. HArrayTsk05 = H_2cang;
  2764. break;
  2765. case 3:
  2766. VolArrayTsk05 = Volume_3cang;
  2767. HArrayTsk05 = H_3cang;
  2768. break;
  2769. case 4:
  2770. VolArrayTsk05 = Volume_4cang;
  2771. HArrayTsk05 = H_4cang;
  2772. break;
  2773. default:
  2774. VolArrayTsk05 = Volume_4cang;
  2775. HArrayTsk05 = H_4cang;
  2776. break;
  2777. }
  2778. v000 = Calc_Vol(plevel[i].Level_Data, VolArrayTsk05, HArrayTsk05, i);
  2779. plevel[i].Volume_Data = v000;
  2780. #endif
  2781. DF_State(i);
  2782. // BGY_state(i);
  2783. osDelay(100);
  2784. }
  2785. }
  2786. }
  2787. /* USER CODE END StartTask05 */
  2788. }
  2789. /* USER CODE BEGIN Header_StartTask06 */
  2790. /**
  2791. * @brief Function implementing the myTask06 thread.
  2792. * @param argument: Not used
  2793. * @retval None
  2794. */
  2795. /* USER CODE END Header_StartTask06 */
  2796. void StartTask06(void *argument)
  2797. {
  2798. /* USER CODE BEGIN StartTask06 */
  2799. /* Infinite loop */
  2800. for(;;)
  2801. {
  2802. osDelay(1);
  2803. }
  2804. /* USER CODE END StartTask06 */
  2805. }
  2806. /* USER CODE BEGIN Header_StartTask07 */
  2807. /**
  2808. * @brief Function implementing the myTask07 thread.
  2809. * @param argument: Not used
  2810. * @retval None
  2811. */
  2812. /* USER CODE END Header_StartTask07 */
  2813. void StartTask07(void *argument)
  2814. {
  2815. /* USER CODE BEGIN StartTask07 */
  2816. /* Infinite loop */
  2817. for(;;)
  2818. {
  2819. osDelay(1);
  2820. }
  2821. /* USER CODE END StartTask07 */
  2822. }
  2823. /* USER CODE BEGIN Header_StartTask08 */
  2824. /**
  2825. * @brief Function implementing the myTask08 thread.
  2826. * @param argument: Not used
  2827. * @retval None
  2828. */
  2829. /* USER CODE END Header_StartTask08 */
  2830. void StartTask08(void *argument)
  2831. {
  2832. /* USER CODE BEGIN StartTask08 */
  2833. /* Infinite loop */
  2834. for(;;)
  2835. {
  2836. osDelay(1);
  2837. }
  2838. /* USER CODE END StartTask08 */
  2839. }
  2840. /* USER CODE BEGIN Header_StartTask09 */
  2841. /**
  2842. * @brief Function implementing the myTask09 thread.
  2843. * @param argument: Not used
  2844. * @retval None
  2845. */
  2846. /* USER CODE END Header_StartTask09 */
  2847. void StartTask09(void *argument)
  2848. {
  2849. /* USER CODE BEGIN StartTask09 */
  2850. /* Infinite loop */
  2851. for(;;)
  2852. {
  2853. osDelay(1);
  2854. }
  2855. /* USER CODE END StartTask09 */
  2856. }
  2857. /* USER CODE BEGIN Header_StartTask10 */
  2858. /**
  2859. * @brief Function implementing the myTask10 thread.
  2860. * @param argument: Not used
  2861. * @retval None
  2862. */
  2863. /* USER CODE END Header_StartTask10 */
  2864. void StartTask10(void *argument)
  2865. {
  2866. /* USER CODE BEGIN StartTask10 */
  2867. /* Infinite loop */
  2868. for(;;)
  2869. {
  2870. osDelay(1);
  2871. }
  2872. /* USER CODE END StartTask10 */
  2873. }
  2874. /* USER CODE BEGIN Header_StartTask11 */
  2875. /**
  2876. * @brief Function implementing the myTask11 thread.
  2877. * @param argument: Not used
  2878. * @retval None
  2879. */
  2880. /* USER CODE END Header_StartTask11 */
  2881. void StartTask11(void *argument)
  2882. {
  2883. /* USER CODE BEGIN StartTask11 */
  2884. /* Infinite loop */
  2885. for(;;)
  2886. {
  2887. osDelay(1);
  2888. }
  2889. /* USER CODE END StartTask11 */
  2890. }
  2891. /* USER CODE BEGIN Header_StartTask12 */
  2892. /**
  2893. * @brief Function implementing the myTask12 thread.
  2894. * @param argument: Not used
  2895. * @retval None
  2896. */
  2897. /* USER CODE END Header_StartTask12 */
  2898. void StartTask12(void *argument)
  2899. {
  2900. /* USER CODE BEGIN StartTask12 */
  2901. /* Infinite loop */
  2902. for(;;)
  2903. {
  2904. osDelay(500);
  2905. usage_Tsk12++;
  2906. HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_0);
  2907. HAL_GPIO_TogglePin(WDI_sp706_kanmemgou_GPIO_Port, WDI_sp706_kanmemgou_Pin);
  2908. }
  2909. /* USER CODE END StartTask12 */
  2910. }
  2911. /* Callback01 function */
  2912. void Callback01(void *argument)
  2913. {
  2914. /* USER CODE BEGIN Callback01 */
  2915. /* USER CODE END Callback01 */
  2916. }
  2917. /* Callback02 function */
  2918. void Callback02(void *argument)
  2919. {
  2920. /* USER CODE BEGIN Callback02 */
  2921. /* USER CODE END Callback02 */
  2922. }
  2923. /* Callback03 function */
  2924. void Callback03(void *argument)
  2925. {
  2926. /* USER CODE BEGIN Callback03 */
  2927. /* USER CODE END Callback03 */
  2928. }
  2929. /* Callback04 function */
  2930. void Callback04(void *argument)
  2931. {
  2932. /* USER CODE BEGIN Callback04 */
  2933. /* USER CODE END Callback04 */
  2934. }
  2935. /* Callback05 function */
  2936. void Callback05(void *argument)
  2937. {
  2938. /* USER CODE BEGIN Callback05 */
  2939. /* USER CODE END Callback05 */
  2940. }
  2941. /* Callback06 function */
  2942. void Callback06(void *argument)
  2943. {
  2944. /* USER CODE BEGIN Callback06 */
  2945. /* USER CODE END Callback06 */
  2946. }
  2947. /* Callback07 function */
  2948. void Callback07(void *argument)
  2949. {
  2950. /* USER CODE BEGIN Callback07 */
  2951. /* USER CODE END Callback07 */
  2952. }
  2953. /* Callback08 function */
  2954. void Callback08(void *argument)
  2955. {
  2956. /* USER CODE BEGIN Callback08 */
  2957. /* USER CODE END Callback08 */
  2958. }
  2959. /* Callback09 function */
  2960. void Callback09(void *argument)
  2961. {
  2962. /* USER CODE BEGIN Callback09 */
  2963. /* USER CODE END Callback09 */
  2964. }
  2965. /* Callback010 function */
  2966. void Callback010(void *argument)
  2967. {
  2968. /* USER CODE BEGIN Callback010 */
  2969. /* USER CODE END Callback010 */
  2970. }
  2971. /**
  2972. * @brief Period elapsed callback in non blocking mode
  2973. * @note This function is called when TIM8 interrupt took place, inside
  2974. * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  2975. * a global variable "uwTick" used as application time base.
  2976. * @param htim : TIM handle
  2977. * @retval None
  2978. */
  2979. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  2980. {
  2981. /* USER CODE BEGIN Callback 0 */
  2982. /* USER CODE END Callback 0 */
  2983. if (htim->Instance == TIM8) {
  2984. HAL_IncTick();
  2985. }
  2986. /* USER CODE BEGIN Callback 1 */
  2987. /* USER CODE END Callback 1 */
  2988. }
  2989. /**
  2990. * @brief This function is executed in case of error occurrence.
  2991. * @retval None
  2992. */
  2993. void Error_Handler(void)
  2994. {
  2995. /* USER CODE BEGIN Error_Handler_Debug */
  2996. /* User can add his own implementation to report the HAL error return state */
  2997. __disable_irq();
  2998. while (1)
  2999. {
  3000. }
  3001. /* USER CODE END Error_Handler_Debug */
  3002. }
  3003. #ifdef USE_FULL_ASSERT
  3004. /**
  3005. * @brief Reports the name of the source file and the source line number
  3006. * where the assert_param error has occurred.
  3007. * @param file: pointer to the source file name
  3008. * @param line: assert_param error line source number
  3009. * @retval None
  3010. */
  3011. void assert_failed(uint8_t *file, uint32_t line)
  3012. {
  3013. /* USER CODE BEGIN 6 */
  3014. /* User can add his own implementation to report the file name and line number,
  3015. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  3016. /* USER CODE END 6 */
  3017. }
  3018. #endif /* USE_FULL_ASSERT */
  3019. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/