CLI_Commands.c 165 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896
  1. /*
  2. * CLI_Commands.c
  3. *
  4. * Created on: 28.11.2017
  5. * Author: balbekova
  6. */
  7. /* FreeRTOS includes. */
  8. #include "FreeRTOS.h"
  9. #include "task.h"
  10. /* Standard includes. */
  11. #include <stdint.h>
  12. #ifdef PRINTF_STDLIB
  13. #include <stdio.h>
  14. #endif
  15. #ifdef PRINTF_CUSTOM
  16. #include "tinystdio.h"
  17. #endif
  18. #include <string.h>
  19. #include <stdlib.h>
  20. /* FreeRTOS+CLI includes. */
  21. #include "FreeRTOS_CLI.h"
  22. #include "snmp_api.h"
  23. #include "trap_api.h"
  24. #include "sntp_api.h"
  25. #include "lwip/ip_addr.h"
  26. #include "settings_api.h"
  27. #include "log.h"
  28. #include "megatec.h"
  29. #include "web_params_api.h"
  30. #include "hal.h"
  31. #include "parameters.h"
  32. #include "CLI_Commands.h"
  33. #include "CLI_Parameters.h"
  34. #include "cli.h"
  35. #include "netconf.h"
  36. #include "control_symbol.h"
  37. #include "syslog.h"
  38. const int8_t *const pcInvalidCommand = ( int8_t * )
  39. "Неправильно введены параметры команды. Введите \"help\" для просмотра списка поддерживаемых команд.\r\n\r\n";
  40. const int8_t *const pcPermissionDenied = ( int8_t * ) "Отказ в доступе!\r\n\r\n";
  41. const int8_t *const pcSystymeDenied = ( int8_t * )
  42. "Ручной ввод времени не доступен!\r\n\r\n";
  43. const char *info_args_list[] = {
  44. "name",
  45. "address",
  46. "owner",
  47. "comments",
  48. };
  49. const char *ups_args_list[] = {
  50. "battest",
  51. "shutdown",
  52. };
  53. const char *systime_args_list[] = {
  54. "date",
  55. "time",
  56. };
  57. const char *network_args_list[] = {
  58. "info",
  59. "dhcp",
  60. "ip",
  61. "gw",
  62. "mask",
  63. };
  64. const char *snmp_args_list[] = {
  65. "info",
  66. "server",
  67. "community",
  68. };
  69. const char *akb_args_list[] = {
  70. "info",
  71. "voltcellmin",
  72. "voltcellmax",
  73. #if HARDWARE_BT6709 || HARDWARE_BT6709_MTS || HARDWARE_BT6710
  74. "capacity",
  75. "voltakb",
  76. "lifetime",
  77. "dataset",
  78. "upspower",
  79. #else if HARDWARE_BT6711 || HARDWARE_BT6711_V1
  80. "capacity",
  81. "voltakb",
  82. "upspower",
  83. #endif
  84. };
  85. const char *type_alarm_args_list[] = {
  86. "info",
  87. "temp",
  88. #ifndef HARDWARE_BT6710
  89. "load",
  90. #endif
  91. "vout",
  92. #ifdef TEMP_CABINET_MONITOR
  93. "temp_cabinet"
  94. #endif
  95. #ifdef VAC_IN_MONITOR
  96. "vacin",
  97. #endif
  98. };
  99. const char *alarm_args_list[] = {
  100. "low",
  101. "high",
  102. "hist",
  103. };
  104. const char *notification_args_list[] = {
  105. "info",
  106. "set",
  107. };
  108. const char *whitelist_args_list[] = {
  109. "info",
  110. "range",
  111. "reset",
  112. };
  113. const char *ntp_args_list[] = {
  114. "ENA",
  115. "DIS",
  116. "info",
  117. "set",
  118. };
  119. const char *config_args_list[] = {
  120. "info",
  121. "load",
  122. };
  123. const char *netconfig_args_list[] = {
  124. "apply",
  125. "confirm",
  126. };
  127. const char *history_args_list[] = {
  128. "EVENTS",
  129. "UPS",
  130. };
  131. const char *sensor_args_list[] = {
  132. "info",
  133. "setup",
  134. };
  135. const char *user_args_list[] = {
  136. "passwd",
  137. };
  138. /**
  139. * @brief Общая структура настроек
  140. */
  141. extern SETTINGS_t sSettings;
  142. /*
  143. * Implements the controller's information command.
  144. */
  145. static portBASE_TYPE prvTaskInfoCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  146. /*
  147. * Implements the reboot command.
  148. */
  149. static portBASE_TYPE prvTaskRebootCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  150. const int8_t *pcCommandString );
  151. /*
  152. * Implements the systime command.
  153. */
  154. static portBASE_TYPE prvTaskSystimeCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  155. const int8_t *pcCommandString );
  156. /*
  157. * Implements the ntp command.
  158. */
  159. static portBASE_TYPE prvTaskNTPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  160. /*
  161. * Implements the network command.
  162. */
  163. static portBASE_TYPE prvTaskNetworkCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  164. const int8_t *pcCommandString );
  165. /*
  166. * Implements the snmp command.
  167. */
  168. static portBASE_TYPE prvTaskSNMPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  169. /*
  170. * Implements the AKB command.
  171. */
  172. static portBASE_TYPE prvTaskAKBCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  173. /*
  174. * Implements the alarm command.
  175. */
  176. static portBASE_TYPE prvTaskAlarmCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  177. const int8_t *pcCommandString );
  178. #ifdef NOTIFICATION_CONTROL_ENABLE
  179. /*
  180. * Implements the notification command.
  181. */
  182. static portBASE_TYPE prvTaskNotificationCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  183. const int8_t *pcCommandString );
  184. #endif
  185. #ifdef WHITELIST_ENABLE
  186. /*
  187. * Implements the whitelist command.
  188. */
  189. static portBASE_TYPE prvTaskWhiteListCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  190. const int8_t *pcCommandString );
  191. #endif
  192. /*
  193. * Implements the change password command.
  194. */
  195. static portBASE_TYPE prvTaskUserCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  196. /*
  197. * Implements the config command.
  198. */
  199. static portBASE_TYPE prvTaskConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  200. const int8_t *pcCommandString );
  201. /*
  202. * Implements the netconfig command.
  203. */
  204. static portBASE_TYPE prvTaskNetConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  205. const int8_t *pcCommandString );
  206. /*
  207. * Implements the history command.
  208. */
  209. static portBASE_TYPE prvTaskHistoryCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  210. const int8_t *pcCommandString );
  211. /*
  212. * Implements the sensor info command.
  213. */
  214. static portBASE_TYPE prvTaskSensorCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  215. const int8_t *pcCommandString );
  216. /*
  217. * Implements the firmware download http command.
  218. */
  219. static portBASE_TYPE prvTaskUploadCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  220. const int8_t *pcCommandString );
  221. /*
  222. * Implements the ups command.
  223. */
  224. static portBASE_TYPE prvTaskUPSCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  225. /*
  226. * Implements the гзs serial command.
  227. */
  228. static portBASE_TYPE prvSetUPSserialCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  229. /* Structure that defines the "info" command line command. This
  230. generates a table that shows how much run time each task has */
  231. static const CLI_Command_Definition_t prvInfoCommandDefinition = {
  232. ( const int8_t *const ) "info", /* The command string to type. */
  233. ( const int8_t *const ) "\tinfo: вывод информации о контроллере\r\n"
  234. "\tinfo name <name>: установка поля \"название устройства\"\r\n"
  235. "\tinfo address <adrr>: установка поля \"адрес расположения контролируемого объекта\"\r\n"
  236. "\tinfo owner <owner>: установка поля \"организация (собственник)\"\r\n"
  237. "\tinfo comments <comment>: установка поля \"комментарии\"\r\n",
  238. prvTaskInfoCommand, /* The function to run. */
  239. -1 /* The user can enter any number of commands. */
  240. };
  241. /* Structure that defines the "reboot" command line command. This
  242. generates a table that shows how much run time each task has */
  243. static const CLI_Command_Definition_t prvRebootCommandDefinition = {
  244. ( const int8_t *const ) "reboot", /* The command string to type. */
  245. ( const int8_t *const ) "\treboot: перезагрузка Контроллера\r\n",
  246. prvTaskRebootCommand, /* The function to run. */
  247. 0 /* No parameters are expected. */
  248. };
  249. /* Structure that defines the "systime" command line command. This
  250. generates a table that shows how much run time each task has */
  251. static const CLI_Command_Definition_t prvSystimeCommandDefinition = {
  252. ( const int8_t *const ) "systime", /* The command string to type. */
  253. ( const int8_t *const ) "\tsystime: вывод системного времени\r\n"
  254. "\tsystime date <YYYY-MM-DD>: установка даты\r\n"
  255. "\tsystime time <HH:MM>: установка времени\r\n",
  256. prvTaskSystimeCommand, /* The function to run. */
  257. -1 /* The user can enter any number of commands. */
  258. };
  259. /* Structure that defines the "ntp" command line command. This
  260. generates a table that shows how much run time each task has */
  261. static const CLI_Command_Definition_t prvNTPCommandDefinition = {
  262. ( const int8_t *const ) "ntp", /* The command string to type. */
  263. ( const int8_t *const ) "\tntp ENA|DIS: разрешение/запрет синхронизации времени\r\n"
  264. "\tntp set IP <A.B.C.D>: установка сервера NTP\r\n"
  265. "\tntp info: вывод информации о сервере NTP\r\n"
  266. "\tntp set gmt <SIGN><NUM>: установка часового пояса\r\n",
  267. prvTaskNTPCommand, /* The function to run. */
  268. -1 /* The user can enter any number of commands. */
  269. };
  270. /* Structure that defines the "network" command line command. This
  271. generates a table that shows how much run time each task has */
  272. static const CLI_Command_Definition_t prvNetworkCommandDefinition = {
  273. ( const int8_t *const ) "network", /* The command string to type. */
  274. ( const int8_t *const ) "\tnetwork info вывод информации о текущих сетевых настройках:\r\n"
  275. "\tnetwork dhcp ENA|DIS: разрешение/запрет получения IP по DHCP\r\n"
  276. "\tnetwork ip <A.B.C.D>: установка статического IP\r\n"
  277. "\tnetwork gw <A.B.C.D>: установка шлюза\r\n"
  278. "\tnetwork mask <A.B.C.D>: установка маски подсети\r\n",
  279. prvTaskNetworkCommand, /* The function to run. */
  280. -1 /* The user can enter any number of commands. */
  281. };
  282. /* Structure that defines the "snmp" command line command. This
  283. generates a table that shows how much run time each task has */
  284. static const CLI_Command_Definition_t prvSNMPCommandDefinition = {
  285. ( const int8_t *const ) "snmp", /* The command string to type. */
  286. ( const int8_t *const ) "\tsnmp info: вывод информации о текущих SNMP настройках\r\n"
  287. "\tsnmp server <NUM> <A.B.C.D>: установка сервера SNMP\r\n"
  288. "\tsnmp community read <read>: установка Read community\r\n"
  289. "\tsnmp community write <write>: установка Write community\r\n",
  290. prvTaskSNMPCommand, /* The function to run. */
  291. -1 /* The user can enter any number of commands. */
  292. };
  293. /* Structure that defines the "akb" command line command. This
  294. generates a table that shows how much run time each task has */
  295. static const CLI_Command_Definition_t prvAKBCommandDefinition = {
  296. ( const int8_t *const ) "akb", /* The command string to type. */
  297. ( const int8_t *const ) "\takb info: вывод информации о параметрах АКБ\r\n"
  298. "\takb voltcellmin <value>: ввод минимального напряжения на ячейки АКБ (В)\r\n"
  299. "\takb voltcellmax <value>: ввод максимального напряжения на ячейки АКБ (В)\r\n"
  300. #if HARDWARE_BT6709 || HARDWARE_BT6709_MTS || HARDWARE_BT6710
  301. "\takb capacity <value>: ввод ёмкости АКБ (Ач)\r\n"
  302. "\takb voltakb <value>: ввод номинального напряжения АКБ (В)\r\n"
  303. "\takb lifetime <value>: ввод срока службы АКБ (лет)\r\n"
  304. "\takb dataset <YYYY-MM-DD>: ввод даты установки АКБ\r\n"
  305. "\takb upspower <value>: ввод полной мощности ИБП (ВА)\r\n"
  306. #else if HARDWARE_BT6711 || HARDWARE_BT6711_V1
  307. "\takb capacity <value>: ввод ёмкости АКБ (Ач)\r\n"
  308. "\takb voltakb <value>: ввод номинального напряжения АКБ (В)\r\n"
  309. "\takb upspower <value>: ввод полной мощности ИБП (ВА)\r\n"
  310. #endif
  311. ,
  312. prvTaskAKBCommand, /* The function to run. */
  313. -1 /* The user can enter any number of commands. */
  314. };
  315. /* Structure that defines the "alarm" command line command. This
  316. generates a table that shows how much run time each task has */
  317. static const CLI_Command_Definition_t prvAlarmCommandDefinition = {
  318. ( const int8_t *const ) "alarm", /* The command string to type. */
  319. ( const int8_t *const ) "\talarm info: вывод информации о параметрах АКБ\r\n"
  320. "\talarm temp low <value>: ввод нижней границы аварии по температуре (С)\r\n"
  321. "\talarm temp high <value>: ввод верxней границы аварии по температуре (С)\r\n"
  322. "\talarm temp hist <value>: ввод гистерезиса аварии по температуре (С)\r\n"
  323. #ifndef HARDWARE_BT6710
  324. "\talarm load high <value>: ввод верхней границы аварии по нагрузке (%)\r\n"
  325. "\talarm load hist <value>: ввод гистерезиса аварии по нагрузке (%)\r\n"
  326. #endif
  327. "\talarm vout low <value>: ввод нижней границы аварии по вых. напряжению (В)\r\n"
  328. "\talarm vout high <value>: ввод верxней границы аварии по вых. напряжению (В)\r\n"
  329. "\talarm vout hist <value>: ввод гистерезиса аварии по вых. напряжению (В)\r\n"
  330. #ifdef TEMP_CABINET_MONITOR
  331. "\talarm temp_cabinet low <value>: ввод нижней границы аварии по температуре в шкафу (С)\r\n"
  332. "\talarm temp_cabinet high <value>: ввод верxней границы аварии по температуре в шкафу (С)\r\n"
  333. "\talarm temp_cabinet hist <value>: ввод гистерезиса аварии по температуре в шкафу (С)\r\n"
  334. #endif
  335. #ifdef VAC_IN_MONITOR
  336. "\talarm vacin low <value>: ввод нижней границы аварии по вх. напряжению (В)\r\n"
  337. "\talarm vacin high <value>: ввод верxней границы аварии по вх. напряжению (В)\r\n"
  338. "\talarm vacin hist <value>: ввод гистерезиса аварии по вх. напряжению (В)\r\n"
  339. #endif
  340. ,prvTaskAlarmCommand, /* The function to run. */
  341. -1 /* The user can enter any number of commands. */
  342. };
  343. #ifdef NOTIFICATION_CONTROL_ENABLE
  344. /* Structure that defines the "notification" command line command. This
  345. generates a table that shows how much run time each task has */
  346. static const CLI_Command_Definition_t prvNotificationCommandDefinition = {
  347. ( const int8_t *const ) "notification", /* The command string to type. */
  348. ( const int8_t *const ) "\tnotification info: вывод списка уведомлений\r\n"
  349. "\tnotification set <NUM> ENA|DIS: вкл/выкл уведомления\r\n",
  350. prvTaskNotificationCommand, /* The function to run. */
  351. -1 /* The user can enter any number of commands. */
  352. };
  353. #endif
  354. #ifdef WHITELIST_ENABLE
  355. /* Structure that defines the "whitelist" command line command. This
  356. generates a table that shows how much run time each task has */
  357. static const CLI_Command_Definition_t prvWhiteListCommandDefinition = {
  358. ( const int8_t *const ) "whitelist", /* The command string to type. */
  359. ( const int8_t *const ) "\twhitelist info: вывод информации о текущем белом списке IP адресов контроллера\r\n"
  360. "\twhitelist range <NUM> <A.B.C.D/E>: установка диапазона IP адресов\r\n"
  361. "\twhitelist reset <NUM>: сброс диапазона IP адресов\r\n",
  362. prvTaskWhiteListCommand, /* The function to run. */
  363. -1 /* The user can enter any number of commands. */
  364. };
  365. #endif
  366. /* Structure that defines the "user" command line command. This
  367. generates a table that shows how much run time each task has */
  368. static const CLI_Command_Definition_t prvUserCommandDefinition = {
  369. ( const int8_t *const ) "user", /* The command string to type. */
  370. ( const int8_t *const ) "\tuser passwd <name>: установка пароля для пользователя <name>\r\n",
  371. prvTaskUserCommand, /* The function to run. */
  372. 2 /* Two parameters are expected, which can take any value. */
  373. };
  374. /* Structure that defines the "config" command line command. This
  375. generates a table that shows how much run time each task has */
  376. static const CLI_Command_Definition_t prvConfigCommandDefinition = {
  377. ( const int8_t *const ) "config", /* The command string to type. */
  378. ( const int8_t *const ) "\tconfig info: вывод информации о состоянии конфигураций\r\n"
  379. "\tconfig load default: загрузка конфигурации по умолчанию\r\n",
  380. prvTaskConfigCommand, /* The function to run. */
  381. -1 /* Two parameters are expected, which can take any value. */
  382. };
  383. /* Structure that defines the "config" command line command. This
  384. generates a table that shows how much run time each task has */
  385. static const CLI_Command_Definition_t prvNetConfigCommandDefinition = {
  386. ( const int8_t *const ) "netconfig", /* The command string to type. */
  387. ( const int8_t *const ) "\tnetconfig apply: применение конфигурации сетевых настроек\r\n"
  388. "\tnetconfig confirm: подтверждение конфигурации сетевых настроек\r\n",
  389. prvTaskNetConfigCommand, /* The function to run. */
  390. 1 /* Two parameters are expected, which can take any value. */
  391. };
  392. /* Structure that defines the "history" command line command. This
  393. generates a table that shows how much run time each task has */
  394. static const CLI_Command_Definition_t prvHistoryCommandDefinition = {
  395. ( const int8_t *const ) "history", /* The command string to type. */
  396. ( const int8_t *const ) "\thistory show EVENTS|UPS <num_page>: вывод журнала\r\n",
  397. prvTaskHistoryCommand, /* The function to run. */
  398. 3 /* Two parameters are expected, which can take any value. */
  399. };
  400. /* Structure that defines the "sensor info" command line command. This
  401. generates a table that shows how much run time each task has */
  402. static const CLI_Command_Definition_t prvSensorCommandDefinition = {
  403. ( const int8_t *const ) "sensor", /* The command string to type. */
  404. ( const int8_t *const ) "\tsensor info: вывод параметров системы (выход из режима Ctrl+C далее Enter)\r\n"
  405. #ifdef DINS_ENABLE
  406. "\tsensor setup DI <num> <state>: установка нормального состояния сухого контакта:\r\n"
  407. "\t\t\t\t0 - разомкнутое состояние\r\n"
  408. "\t\t\t\t1 - замкнутое состояние\r\n"
  409. #ifdef HARDWARE_BT6710
  410. "\tsensor setup DIname <num> <name>: установка названия сухого контакта\r\n"
  411. #endif
  412. #endif
  413. #if defined(DALLAS_SENSOR_ENABLE) || defined(AM2301_SENSOR_ENABLE)
  414. "\tsensor setup TS <num> <function>: установка назначения датчика температуры:\r\n"
  415. "\t\t\t\t0 - нет\r\n"
  416. "\t\t\t\t1 - Шкаф\r\n"
  417. "\t\t\t\t2 - АКБ\r\n"
  418. #endif
  419. #ifdef DOUTS_ENABLE
  420. "\tsensor setup DO <num> <issue>: установка источника срабатывания реле:\r\n"
  421. "\t\t\t\t1 - Наличие сети\r\n"
  422. "\t\t\t\t2 - Наличие выходного напряжения\r\n"
  423. "\t\t\t\t3 - Разряд АКБ\r\n"
  424. "\t\t\t\t4 - Отключение АКБ\r\n"
  425. "\t\t\t\t5 - SNMP SET\r\n"
  426. #endif
  427. ,
  428. prvTaskSensorCommand, /* The function to run. */
  429. -1 /* No parameters are expected. */
  430. };
  431. /* Structure that defines the "firmware dowmload http" command line command. This
  432. generates a table that shows how much run time each task has */
  433. static const CLI_Command_Definition_t prvUploadCommandDefinition = {
  434. ( const int8_t *const ) "firmware download http", /* The command string to type. */
  435. ( const int8_t *const ) "\tfirmware download http: переход в режим обновления через Web-сервер\r\n",
  436. prvTaskUploadCommand, /* The function to run. */
  437. 2 /* No parameters are expected. */
  438. };
  439. /* Structure that defines the "ups" command line command. This
  440. generates a table that shows how much run time each task has */
  441. static const CLI_Command_Definition_t prvUPSCommandDefinition = {
  442. ( const int8_t *const ) "ups", /* The command string to type. */
  443. ( const int8_t *const ) "\tups battest <num>: управление процедурой тестирования АКБ:\r\n"
  444. "\t\t\t\t0 - Остановить тестирование\r\n"
  445. "\t\t\t\t1-99 - Запустить тест на x минут\r\n"
  446. "\t\t\t\t100 - Тестирование в течение 10 секунд\r\n"
  447. "\t\t\t\t999 - Тестирование до разряда\r\n"
  448. "\tups shutdown <num>: управление отключением нагрузки ИБП:\r\n"
  449. "\t\t\t\t0 - Остановить процедуру отключения нагрузки\r\n"
  450. "\t\t\t\tn - Отключить нагрузку через n минут\r\n"
  451. "\t\t\t\tn: 0.2, 0.3, ..., 1, 2, ..., 10\r\n",
  452. prvTaskUPSCommand, /* The function to run. */
  453. 2 /* Two parameters are expected, which can take any value. */
  454. };
  455. #ifdef FTP_ENABLE
  456. #include "ftp.h"
  457. #define FTP_ARGS_LIST \
  458. X(info) \
  459. X(server_ip) \
  460. X(server_port) \
  461. X(remote_path) \
  462. X(user) \
  463. X(pass) \
  464. X(run) \
  465. typedef enum {
  466. #define X(name) ARG_FTP_##name,
  467. FTP_ARGS_LIST
  468. #undef X
  469. ARG_FTP_ALL,
  470. } ftp_args_t;
  471. const char *ftp_args_list[] = {
  472. #define X(name) #name,
  473. FTP_ARGS_LIST
  474. #undef X
  475. };
  476. static portBASE_TYPE prvTaskFTPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  477. static const CLI_Command_Definition_t prvFTPCommandDefinition = {
  478. (const int8_t *const)"ftp", /* The command string to type. */
  479. (const int8_t *const)"\tftp info: вывод информации о настройках обновления по ftp\r\n"
  480. "\tftp server_ip <ip address>: задать адрес FTP-сервера\r\n"
  481. "\tftp server_port <port>: задать порт FTP-сервера\r\n"
  482. "\tftp remote_path <file path>: задать путь к файлу обновления ПО\r\n"
  483. "\tftp user <username>: задать имя пользователя для аутентификации на FTP-сервере\r\n"
  484. "\tftp pass <password>: задать пароль для аутентификации на FTP-сервере\r\n"
  485. "\tftp run: запустить процесс обновления через FTP\r\n",
  486. prvTaskFTPCommand, /* The function to run. */
  487. -1 /* The user can enter any number of commands. */
  488. };
  489. #endif
  490. #ifdef SYSLOG_ENABLE
  491. const char *syslog_args_list[] = {
  492. "info",
  493. "ENA",
  494. "DIS",
  495. "server_ip",
  496. "server_port",
  497. };
  498. typedef enum{
  499. ARG_SYSLOG_INFO = 0,
  500. ARG_SYSLOG_ENABLE,
  501. ARG_SYSLOG_DISABLE,
  502. ARG_SYSLOG_IP,
  503. ARG_SYSLOG_PORT,
  504. ARG_SYSLOG_ALL
  505. }syslog_args_t;
  506. static portBASE_TYPE prvTaskSysLogCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  507. static const CLI_Command_Definition_t prvSysLogCommandDefinition = {
  508. (const int8_t *const)"syslog", /* The command string to type. */
  509. (const int8_t *const)"\tsyslog info: вывод информации о настройках Syslog\r\n"
  510. "\tsyslog ENA|DIS: вкл./выкл. Syslog\r\n"
  511. "\tsyslog server_ip <ip address>: установка ip-адреса Syslog-сервера\r\n"
  512. "\tsyslog server_port <port>: установка порта Syslog-сервера\r\n",
  513. prvTaskSysLogCommand, /* The function to run. */
  514. -1 /* The user can enter any number of commands. */
  515. };
  516. #endif
  517. #ifdef RADIUS_SERVER_ENABLE
  518. const char *radius_args_list[] = {
  519. "info",
  520. "ENA",
  521. "DIS",
  522. "server_ip",
  523. "server_port",
  524. "secret",
  525. };
  526. typedef enum{
  527. ARG_RADIUS_INFO = 0,
  528. ARG_RADIUS_ENABLE,
  529. ARG_RADIUS_DISABLE,
  530. ARG_RADIUS_IP,
  531. ARG_RADIUS_PORT,
  532. ARG_RADIUS_SECRET,
  533. ARG_RADIUS_ALL
  534. }radius_args_t;
  535. static portBASE_TYPE prvTaskRADIUSCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  536. static const CLI_Command_Definition_t prvRADIUSCommandDefinition = {
  537. (const int8_t *const)"radius", /* The command string to type. */
  538. (const int8_t *const)"\tradius info: вывод информации о настройках RADIUS\r\n"
  539. "\tradius ENA|DIS: вкл./выкл. авторизации через RADIUS\r\n"
  540. "\tradius server_ip <ip address>: установка ip-адреса RADIUS-сервера\r\n"
  541. "\tradius server_port <port>: установка порта RADIUS-сервера\r\n"
  542. "\tradius secret <secret>: установка пароля RADIUS-сервера\r\n",
  543. prvTaskRADIUSCommand, /* The function to run. */
  544. -1 /* The user can enter any number of commands. */
  545. };
  546. #endif
  547. #ifdef PORTGW_ENABLE
  548. const char *pgw_args_list[] = {
  549. "info",
  550. "ENA",
  551. "DIS",
  552. "port",
  553. "boardrate",
  554. "parity",
  555. "datalen",
  556. "stopbit"
  557. };
  558. typedef enum{
  559. ARG_PGW_INFO = 0,
  560. ARG_PGW_ENABLE,
  561. ARG_PGW_DISABLE,
  562. ARG_PGW_PORT,
  563. ARG_PGW_RATE,
  564. ARG_PGW_PARITY,
  565. ARG_PGW_DATALEN,
  566. ARG_PGW_STOPBIT,
  567. ARG_PGW_ALL
  568. }pgw_args_t;
  569. static portBASE_TYPE prvTaskPGWCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  570. static const CLI_Command_Definition_t prvPGWCommandDefinition = {
  571. (const int8_t *const)"pgw", /* The command string to type. */
  572. (const int8_t *const)"\tpgw info: вывод информации о настройках прозрачного канала\r\n"
  573. "\tpgw ENA|DIS: вкл./выкл. прозрачного канала\r\n"
  574. "\tpgw port <port>: установка сетевого парта\r\n"
  575. "\tpgw boardrate <boardrate>: установка скорости (бит/с) порта RS-485\r\n"
  576. "\tpgw parity <parity>: установка четности порта RS-485:\r\n"
  577. "\t\t\t\t0 - нет\r\n"
  578. "\t\t\t\t1 - нечетный\r\n"
  579. "\t\t\t\t2 - четный\r\n"
  580. "\tpgw datalen <datalen>: установка битов данных порта RS-485\r\n"
  581. "\tpgw stopbit <stopbit>: установка стоповых бит порта RS-485\r\n",
  582. prvTaskPGWCommand, /* The function to run. */
  583. -1 /* The user can enter any number of commands. */
  584. };
  585. #endif
  586. static const CLI_Command_Definition_t prvSetUPSserialCommandDefinition =
  587. {
  588. ( const int8_t * const ) "setupsid", /* The command string to type. */
  589. ( const int8_t * const ) "",//\tsetupsid <password> <SN>: установка серийного номера ИБП\r\n
  590. prvSetUPSserialCommand, /* The function to run. */
  591. 2 /* Two parameters are expected, which can take any value. */
  592. };
  593. /* Structure that defines the "quit" command line command. This
  594. generates a table that shows how much run time each task has */
  595. static const CLI_Command_Definition_t prvQuitCommandDefinition = {
  596. ( const int8_t *const ) "quit", /* The command string to type. */
  597. ( const int8_t *const ) "\tquit: завершение сессии\r\n",
  598. NULL, /* The function to run. */
  599. -1 /* The user can enter any number of commands. */
  600. };
  601. /*-----------------------------------------------------------*/
  602. void vRegisterCLICommands( void )
  603. {
  604. /* Register all the command line commands defined immediately above. */
  605. FreeRTOS_CLIRegisterCommand( &prvInfoCommandDefinition );
  606. FreeRTOS_CLIRegisterCommand( &prvRebootCommandDefinition );
  607. FreeRTOS_CLIRegisterCommand( &prvSystimeCommandDefinition );
  608. FreeRTOS_CLIRegisterCommand( &prvNTPCommandDefinition );
  609. FreeRTOS_CLIRegisterCommand( &prvNetworkCommandDefinition );
  610. FreeRTOS_CLIRegisterCommand( &prvSNMPCommandDefinition );
  611. FreeRTOS_CLIRegisterCommand( &prvAKBCommandDefinition );
  612. FreeRTOS_CLIRegisterCommand( &prvAlarmCommandDefinition );
  613. #ifdef NOTIFICATION_CONTROL_ENABLE
  614. FreeRTOS_CLIRegisterCommand( &prvNotificationCommandDefinition );
  615. #endif
  616. #ifdef WHITELIST_ENABLE
  617. FreeRTOS_CLIRegisterCommand( &prvWhiteListCommandDefinition );
  618. #endif
  619. FreeRTOS_CLIRegisterCommand( &prvUserCommandDefinition );
  620. FreeRTOS_CLIRegisterCommand( &prvConfigCommandDefinition );
  621. FreeRTOS_CLIRegisterCommand( &prvNetConfigCommandDefinition );
  622. FreeRTOS_CLIRegisterCommand( &prvHistoryCommandDefinition );
  623. FreeRTOS_CLIRegisterCommand( &prvSensorCommandDefinition );
  624. FreeRTOS_CLIRegisterCommand( &prvUploadCommandDefinition );
  625. FreeRTOS_CLIRegisterCommand( &prvUPSCommandDefinition );
  626. #ifdef FTP_ENABLE
  627. FreeRTOS_CLIRegisterCommand( &prvFTPCommandDefinition );
  628. #endif
  629. #ifdef SYSLOG_ENABLE
  630. FreeRTOS_CLIRegisterCommand( &prvSysLogCommandDefinition );
  631. #endif
  632. #ifdef RADIUS_SERVER_ENABLE
  633. FreeRTOS_CLIRegisterCommand( &prvRADIUSCommandDefinition );
  634. #endif
  635. #ifdef PORTGW_ENABLE
  636. FreeRTOS_CLIRegisterCommand( &prvPGWCommandDefinition );
  637. #endif
  638. FreeRTOS_CLIRegisterCommand( &prvSetUPSserialCommandDefinition );
  639. FreeRTOS_CLIRegisterCommand( &prvQuitCommandDefinition );
  640. }
  641. /*-----------------------------------------------------------*/
  642. static portBASE_TYPE prvTaskInfoCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  643. {
  644. int8_t *pcParameterString;
  645. signed portBASE_TYPE xParameterStringLength, xReturn;
  646. portBASE_TYPE xParameterNumber = 1;
  647. char str[110];
  648. uint8_t len;
  649. int8_t num_arg = 0;
  650. uint8_t i;
  651. static uint8_t page = 0;
  652. ( void ) pcCommandString;
  653. ( void ) xWriteBufferLen;
  654. configASSERT( pcWriteBuffer );
  655. num_arg = prvGetNumberOfParameters(pcCommandString);
  656. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  657. if (num_arg == 0) {
  658. const int8_t *const pcInfoTableHeader = ( int8_t * )
  659. "\r\n**************Информация о Контроллере**************\r\n";
  660. const int8_t *const pcUPSInfoTableHeader = ( int8_t * )
  661. "\r\n*****************Информация об ИБП******************\r\n";
  662. if (!page) {
  663. /* Return the next command help string, before moving the pointer on to
  664. the next command in the list. */
  665. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  666. GetWorkTimeStr(str, &len);
  667. strcat(( char * ) pcWriteBuffer, "Время работы:\t\t\t");
  668. strncat(( char * ) pcWriteBuffer, str, len);
  669. strcat(( char * ) pcWriteBuffer, "\r\nМодель:\t\t\t\t");
  670. GetModelStr(str, &len);
  671. strncat(( char * ) pcWriteBuffer, str, len);
  672. strcat(( char * ) pcWriteBuffer, "\r\nДата производства:\t\t");
  673. GetProductionDataStr(str, &len);
  674. strncat(( char * ) pcWriteBuffer, str, len);
  675. strcat(( char * ) pcWriteBuffer, "\r\nВерсия ПО:\t\t\t");
  676. GetVersionStr(str, &len);
  677. strncat(( char * ) pcWriteBuffer, str, len);
  678. strcat(( char * ) pcWriteBuffer, "\r\nMAC адрес:\t\t\t");
  679. GetMacStr(str, &len);
  680. strncat(( char * ) pcWriteBuffer, str, len);
  681. strcat(( char * ) pcWriteBuffer, "\r\nСерийный номер:\t\t\t");
  682. GetSerialNumberStr(str, &len);
  683. strncat(( char * ) pcWriteBuffer, str, len);
  684. strcat(( char * ) pcWriteBuffer, "\r\nНазвание устройства:\t\t");
  685. GetNameDeviceStr(str, &len);
  686. strncat(( char * ) pcWriteBuffer, str, len);
  687. strcat(( char * ) pcWriteBuffer, "\r\nВладелец:\t\t\t");
  688. GetOwnerStr(str, &len);
  689. strncat(( char * ) pcWriteBuffer, str, len);
  690. strcat(( char * ) pcWriteBuffer, "\r\nМестоположение:\t\t\t");
  691. GetLocationStr(str, &len);
  692. strncat(( char * ) pcWriteBuffer, str, len);
  693. strcat(( char * ) pcWriteBuffer, "\r\nКомментарии:\t\t\t");
  694. GetCommentsStr(str, &len);
  695. strncat(( char * ) pcWriteBuffer, str, len);
  696. page = 1;
  697. xReturn = pdTRUE;
  698. } else {
  699. strncat( ( char * ) pcWriteBuffer, ( const char * ) pcUPSInfoTableHeader, strlen( ( char * ) pcUPSInfoTableHeader ) );
  700. strcat(( char * ) pcWriteBuffer, "\r\nКомпания:\t\t\tАО\"НПК РоТеК\"");
  701. strcat(( char * ) pcWriteBuffer, "\r\nМодель:\t\t\t\t");
  702. GetUPSModelStr(str, &len);
  703. strncat(( char * ) pcWriteBuffer, str, len);
  704. strcat(( char * ) pcWriteBuffer, "\r\nСерийный номер:\t\t\t");
  705. GetUPSSerialStr(str, &len);
  706. strncat(( char * ) pcWriteBuffer, str, len);
  707. strcat(( char * ) pcWriteBuffer, "\r\nВерсия ПО:\t\t\t");
  708. GetUPSVersionStr(str, &len);
  709. strncat(( char * ) pcWriteBuffer, str, len);
  710. strcat(( char * ) pcWriteBuffer, "\r\n");
  711. page = 0;
  712. /* There are no more commands in the list, so there will be no more
  713. strings to return after this one and pdFALSE should be returned. */
  714. xReturn = pdFALSE;
  715. }
  716. } else if (num_arg == 1) {
  717. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  718. xReturn = pdFALSE;
  719. } else {
  720. /* Obtain the parameter string. */
  721. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  722. (
  723. pcCommandString, /* The command string itself. */
  724. xParameterNumber, /* Return the next parameter. */
  725. &xParameterStringLength /* Store the parameter string length. */
  726. );
  727. for (i = 0; i < INFO_ALL_ARGS; i ++) {
  728. if ( strncmp( ( const char * ) pcParameterString, info_args_list[i], strlen(info_args_list[i]) ) == 0
  729. && xParameterStringLength == strlen(info_args_list[i])) {
  730. break;
  731. }
  732. }
  733. xParameterNumber ++;
  734. // xParameterNumber ++;
  735. /* Obtain the parameter string. */
  736. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  737. (
  738. pcCommandString, /* The command string itself. */
  739. xParameterNumber, /* Return the next parameter. */
  740. &xParameterStringLength /* Store the parameter string length. */
  741. );
  742. memset(str, 0, sizeof(str));
  743. xParameterStringLength = strlen(( const char * ) pcParameterString);
  744. if (xParameterStringLength > (int32_t)sizeof(str)) {
  745. xParameterStringLength = sizeof(str) - 1;
  746. }
  747. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  748. if (control_string_en_digit(str, strlen(str))) {
  749. switch (i) {
  750. case INFO_DEV_NAME:
  751. if (cli_state->user_id == ADMIN) {
  752. str[19] = 0;
  753. SetNameDeviceStr(str);
  754. } else {
  755. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  756. }
  757. break;
  758. case INFO_ADDRESS:
  759. if (cli_state->user_id == ADMIN) {
  760. str[109] = 0;
  761. SetLocation(str);
  762. } else {
  763. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  764. }
  765. break;
  766. case INFO_OWNER:
  767. if (cli_state->user_id == ADMIN) {
  768. str[49] = 0;
  769. SetOwner(str);
  770. } else {
  771. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  772. }
  773. break;
  774. case INFO_COMMENTS:
  775. if (cli_state->user_id == ADMIN) {
  776. str[109] = 0;
  777. SetComment(str);
  778. } else {
  779. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  780. }
  781. break;
  782. default:
  783. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  784. break;
  785. }
  786. if (i >= INFO_DEV_NAME && i <= INFO_COMMENTS) {
  787. cli_save_config(cli_state);
  788. }
  789. } else {
  790. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  791. }
  792. xReturn = pdFALSE;
  793. }
  794. return xReturn;
  795. }
  796. static portBASE_TYPE prvTaskRebootCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  797. const int8_t *pcCommandString )
  798. {
  799. static bool start_reboot = true;
  800. const int8_t *const pcRebootHeader = ( int8_t * )
  801. "Контроллер будет перезагружен через 1 секунду\r\n";
  802. ( void ) pcCommandString;
  803. ( void ) xWriteBufferLen;
  804. if (cli_state->user_id != ADMIN) {
  805. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  806. return pdFALSE;
  807. }
  808. if (start_reboot) {
  809. start_reboot = false;
  810. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcRebootHeader );
  811. return pdTRUE;
  812. } else {
  813. Reboot(CLI_ACT);
  814. return pdFALSE;
  815. }
  816. }
  817. static portBASE_TYPE prvTaskSystimeCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  818. const int8_t *pcCommandString )
  819. {
  820. int8_t *pcParameterString;
  821. signed portBASE_TYPE xParameterStringLength, xReturn;
  822. portBASE_TYPE xParameterNumber = 1;
  823. char str[110];
  824. uint8_t len;
  825. uint8_t i;
  826. uint8_t fail = 0;
  827. uint16_t temp = 0;
  828. ( void ) pcCommandString;
  829. ( void ) xWriteBufferLen;
  830. configASSERT( pcWriteBuffer );
  831. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  832. /* Obtain the parameter string. */
  833. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  834. (
  835. pcCommandString, /* The command string itself. */
  836. xParameterNumber, /* Return the next parameter. */
  837. &xParameterStringLength /* Store the parameter string length. */
  838. );
  839. if (pcParameterString == NULL) {
  840. const int8_t *const pcInfoTableHeader = ( int8_t * )
  841. "\r\n******Системное время Контроллера******\r\n";
  842. /* Return the next command help string, before moving the pointer on to
  843. the next command in the list. */
  844. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  845. GetDateStr(str, &len);
  846. strcat(( char * ) pcWriteBuffer, "Дата:\t\t\t");
  847. strncat(( char * ) pcWriteBuffer, str, len);
  848. strcat(( char * ) pcWriteBuffer, "\r\nВремя:\t\t\t");
  849. GetTimeStr(str, &len);
  850. strncat(( char * ) pcWriteBuffer, str, len);
  851. strcat(( char * ) pcWriteBuffer, "\r\n");
  852. /* There are no more commands in the list, so there will be no more
  853. strings to return after this one and pdFALSE should be returned. */
  854. xReturn = pdFALSE;
  855. } else {
  856. if (cli_state->user_id != ADMIN) {
  857. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  858. return pdFALSE;
  859. }
  860. for (i = 0; i < ARG_SYSTIME_ALL; i ++) {
  861. if ( strncmp( ( const char * ) pcParameterString, systime_args_list[i], strlen(systime_args_list[i]) ) == 0
  862. && xParameterStringLength == strlen(systime_args_list[i])) {
  863. break;
  864. }
  865. }
  866. if (i != ARG_SYSTIME_ALL) {
  867. if (sSettings.sSNTP.sntpEnable) {
  868. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSystymeDenied, strlen( ( char * ) pcSystymeDenied ) );
  869. return pdFALSE;
  870. }
  871. }
  872. xParameterNumber ++;
  873. /* Obtain the parameter string. */
  874. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  875. (
  876. pcCommandString, /* The command string itself. */
  877. xParameterNumber, /* Return the next parameter. */
  878. &xParameterStringLength /* Store the parameter string length. */
  879. );
  880. if (pcParameterString == NULL) {
  881. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  882. return pdFALSE;
  883. }
  884. memset(str, 0, sizeof(str));
  885. xParameterStringLength = strlen(( const char * ) pcParameterString);
  886. if (xParameterStringLength > (int32_t)sizeof(str)) {
  887. xParameterStringLength = sizeof(str) - 1;
  888. }
  889. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  890. switch (i) {
  891. case ARG_SYSTIME_DATA:
  892. if (xParameterStringLength == 10) {
  893. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  894. if (j != 4 && j != 7) {
  895. if (str[j] > 0x39 || str[j] < 0x30) {
  896. fail = 1;
  897. }
  898. } else if (j == 4 || j == 7) {
  899. if (str[j] != '-') {
  900. fail = 1;
  901. }
  902. }
  903. }
  904. if (!fail) {
  905. temp = 1000 * (str[0] - 0x30) + 100 * (str[1] - 0x30) + 10 * (str[2] - 0x30) + str[3] - 0x30;
  906. if (temp > 2099 || temp < 2000) {
  907. fail = 1;
  908. }
  909. temp = 0;
  910. temp = 10 * (str[5] - 0x30) + (str[6] - 0x30);
  911. if (temp > 12) {
  912. fail = 1;
  913. }
  914. temp = 0;
  915. temp = 10 * (str[8] - 0x30) + (str[9] - 0x30);
  916. if (temp > 31) {
  917. fail = 1;
  918. }
  919. }
  920. } else {
  921. fail = 1;
  922. }
  923. if (!fail) {
  924. SetDateStr(str);
  925. cli_save_config(cli_state);
  926. } else {
  927. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  928. }
  929. break;
  930. case ARG_SYSTIME_TIME:
  931. if (xParameterStringLength == 5) {
  932. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  933. if (j != 2) {
  934. if (str[j] > 0x39 || str[j] < 0x30) {
  935. fail = 1;
  936. }
  937. } else if (j == 2) {
  938. if (str[j] != ':') {
  939. fail = 1;
  940. }
  941. }
  942. }
  943. if (!fail) {
  944. temp = 10 * (str[0] - 0x30) + (str[1] - 0x30);
  945. if (temp > 23) {
  946. fail = 1;
  947. }
  948. temp = 0;
  949. temp = 10 * (str[3] - 0x30) + (str[4] - 0x30);
  950. if (temp > 59) {
  951. fail = 1;
  952. }
  953. }
  954. } else {
  955. fail = 1;
  956. }
  957. if (!fail) {
  958. SetTimeStr(str);
  959. cli_save_config(cli_state);
  960. } else {
  961. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  962. }
  963. break;
  964. default:
  965. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  966. break;
  967. }
  968. xReturn = pdFALSE;
  969. }
  970. return xReturn;
  971. }
  972. /*
  973. * Implements the ntp command.
  974. */
  975. static portBASE_TYPE prvTaskNTPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  976. {
  977. int8_t *pcParameterString;
  978. signed portBASE_TYPE xParameterStringLength, xReturn;
  979. portBASE_TYPE xParameterNumber = 1;
  980. char str[110];
  981. char str_temp[110];
  982. uint8_t len;
  983. uint8_t i;
  984. bool enable_old_sntp;
  985. const int8_t *const pcInfoTableHeader = ( int8_t * )
  986. "\r\n************NTP настройки Контроллера************\r\n";
  987. ( void ) pcCommandString;
  988. ( void ) xWriteBufferLen;
  989. configASSERT( pcWriteBuffer );
  990. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  991. /* Obtain the parameter string. */
  992. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  993. (
  994. pcCommandString, /* The command string itself. */
  995. xParameterNumber, /* Return the next parameter. */
  996. &xParameterStringLength /* Store the parameter string length. */
  997. );
  998. if (pcParameterString == NULL) {
  999. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1000. return pdFALSE;
  1001. }
  1002. for (i = 0; i < ARG_NTP_ALL; i ++) {
  1003. if ( strncmp( ( const char * ) pcParameterString, ntp_args_list[i], strlen(ntp_args_list[i]) ) == 0
  1004. && xParameterStringLength == strlen(ntp_args_list[i])) {
  1005. break;
  1006. }
  1007. }
  1008. if (cli_state->user_id != ADMIN && i != ARG_NTP_INFO) {
  1009. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1010. return pdFALSE;
  1011. }
  1012. xParameterNumber ++;
  1013. /* Obtain the parameter string. */
  1014. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1015. (
  1016. pcCommandString, /* The command string itself. */
  1017. xParameterNumber, /* Return the next parameter. */
  1018. &xParameterStringLength /* Store the parameter string length. */
  1019. );
  1020. xParameterNumber ++;
  1021. if (pcParameterString == NULL) {
  1022. switch (i) {
  1023. case ARG_NTP_ENABLE:
  1024. enable_old_sntp = sSettings.sSNTP.sntpEnable;
  1025. SetSntpStateStr("1");
  1026. if (sSettings.sSNTP.sntpEnable != enable_old_sntp) {
  1027. cli_save_config(cli_state);
  1028. }
  1029. break;
  1030. case ARG_NTP_DISABLE:
  1031. enable_old_sntp = sSettings.sSNTP.sntpEnable;
  1032. SetSntpStateStr("0");
  1033. if (sSettings.sSNTP.sntpEnable != enable_old_sntp) {
  1034. cli_save_config(cli_state);
  1035. }
  1036. break;
  1037. case ARG_NTP_INFO:
  1038. /* Return the next command help string, before moving the pointer on to
  1039. the next command in the list. */
  1040. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  1041. GetSntpStateStrRU(str, &len);
  1042. strcat(( char * ) pcWriteBuffer, "Режим установки времени:\t");
  1043. strncat(( char * ) pcWriteBuffer, str, len);
  1044. strcat(( char * ) pcWriteBuffer, "\r\nIP адрес NTP сервера:\t\t");
  1045. GetSntpServerIpStr(str, &len);
  1046. strncat(( char * ) pcWriteBuffer, str, len);
  1047. strcat(( char * ) pcWriteBuffer, "\r\nЧасовой пояс:\t\t\t");
  1048. GetSntpTimeZoneStr(str, &len);
  1049. strncat(( char * ) pcWriteBuffer, str, len);
  1050. strcat(( char * ) pcWriteBuffer, "\r\nПоследняя дата синхронизации:\t");
  1051. GetSntpLastDataStr(str, &len);
  1052. strncat(( char * ) pcWriteBuffer, str, len);
  1053. strcat(( char * ) pcWriteBuffer, "\r\n");
  1054. break;
  1055. default:
  1056. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1057. break;
  1058. }
  1059. return pdFALSE;
  1060. }
  1061. if (i == ARG_NTP_SET) {
  1062. memset(str, 0, sizeof(str));
  1063. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1064. xParameterStringLength = sizeof(str) - 1;
  1065. }
  1066. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1067. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1068. (
  1069. pcCommandString, /* The command string itself. */
  1070. xParameterNumber, /* Return the next parameter. */
  1071. &xParameterStringLength /* Store the parameter string length. */
  1072. );
  1073. if (pcParameterString != NULL) {
  1074. memset(str_temp, 0, sizeof(str_temp));
  1075. if (xParameterStringLength > (int32_t)sizeof(str_temp)) {
  1076. xParameterStringLength = sizeof(str_temp) - 1;
  1077. }
  1078. strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
  1079. if (strncmp(str, "IP", 2) == 0) {
  1080. if (xParameterStringLength <= 15) {
  1081. if (ipaddr_addr(str_temp) != IPADDR_NONE) {
  1082. if (strncmp(str_temp, sSettings.sSNTP.ip, strlen(str_temp)) != 0 || strlen(sSettings.sSNTP.ip) != strlen(str_temp)) {
  1083. SetSntpServerIpStr(str_temp);
  1084. cli_save_config(cli_state);
  1085. }
  1086. } else {
  1087. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1088. }
  1089. } else {
  1090. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1091. }
  1092. } else if (strncmp(str, "gmt", 3) == 0) {
  1093. if (xParameterStringLength > 1 && xParameterStringLength < 5) {
  1094. bool fail = false;
  1095. if (str_temp[0] != '-' && str_temp[0] != '+') {
  1096. fail = true;
  1097. }
  1098. if (!isdigit_int(str_temp[1]) && (!isdigit_int(str_temp[2]) && str_temp[2] != '.') && (!isdigit_int(str_temp[3]) &&
  1099. str_temp[3] != '.')) {
  1100. fail = true;
  1101. }
  1102. if (xParameterStringLength == 5) {
  1103. if (!isdigit_int(str_temp[4])) {
  1104. fail = true;
  1105. }
  1106. }
  1107. if (!fail) {
  1108. float value = atof(str_temp);
  1109. if (value >= -12.0 && value <= 12.0) {
  1110. SetSntpTimeZoneStr(str_temp);
  1111. cli_save_config(cli_state);
  1112. } else {
  1113. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1114. }
  1115. } else {
  1116. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1117. }
  1118. } else {
  1119. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1120. }
  1121. } else {
  1122. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1123. }
  1124. } else {
  1125. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1126. }
  1127. } else {
  1128. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1129. }
  1130. xReturn = pdFALSE;
  1131. return xReturn;
  1132. }
  1133. /*
  1134. * Implements the network command.
  1135. */
  1136. static portBASE_TYPE prvTaskNetworkCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  1137. const int8_t *pcCommandString )
  1138. {
  1139. int8_t *pcParameterString;
  1140. signed portBASE_TYPE xParameterStringLength, xReturn;
  1141. portBASE_TYPE xParameterNumber = 1;
  1142. char str[110];
  1143. uint8_t i;
  1144. ( void ) pcCommandString;
  1145. ( void ) xWriteBufferLen;
  1146. configASSERT( pcWriteBuffer );
  1147. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1148. /* Obtain the parameter string. */
  1149. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1150. (
  1151. pcCommandString, /* The command string itself. */
  1152. xParameterNumber, /* Return the next parameter. */
  1153. &xParameterStringLength /* Store the parameter string length. */
  1154. );
  1155. if (pcParameterString == NULL) {
  1156. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1157. return pdFALSE;
  1158. }
  1159. for (i = 0; i < ARG_NETWORK_ALL; i ++) {
  1160. if ( strncmp( ( const char * ) pcParameterString, network_args_list[i], strlen(network_args_list[i]) ) == 0
  1161. && xParameterStringLength == strlen(network_args_list[i])) {
  1162. break;
  1163. }
  1164. }
  1165. if (cli_state->user_id != ADMIN && i != ARG_NETWORK_INFO) {
  1166. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1167. return pdFALSE;
  1168. }
  1169. if (i != ARG_NETWORK_ALL && i != ARG_NETWORK_DHCP && i != ARG_NETWORK_INFO) {
  1170. if (sSettings.sWebTempParams.dhcpEnable) {
  1171. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1172. return pdFALSE;
  1173. }
  1174. }
  1175. xParameterNumber ++;
  1176. /* Obtain the parameter string. */
  1177. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1178. (
  1179. pcCommandString, /* The command string itself. */
  1180. xParameterNumber, /* Return the next parameter. */
  1181. &xParameterStringLength /* Store the parameter string length. */
  1182. );
  1183. if (pcParameterString == NULL) {
  1184. if (i == ARG_NETWORK_INFO) {
  1185. net_config_param(pcWriteBuffer);
  1186. } else {
  1187. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1188. }
  1189. return pdFALSE;
  1190. }
  1191. memset(str, 0, sizeof(str));
  1192. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1193. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1194. xParameterStringLength = sizeof(str) - 1;
  1195. }
  1196. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1197. switch (i) {
  1198. case ARG_NETWORK_DHCP:
  1199. if (strncmp(str, "ENA", 3) == 0) {
  1200. SetUDPDhcpStateStr("True");
  1201. strcpy( ( char * ) pcWriteBuffer,
  1202. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1203. } else if (strncmp(str, "DIS", 3) == 0) {
  1204. SetUDPDhcpStateStr("False");
  1205. strcpy( ( char * ) pcWriteBuffer,
  1206. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1207. } else {
  1208. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1209. }
  1210. break;
  1211. case ARG_NETWORK_IP:
  1212. if (xParameterStringLength <= 15) {
  1213. if (ipaddr_addr(str) != IPADDR_NONE) {
  1214. SetIPStr(str);
  1215. strcpy( ( char * ) pcWriteBuffer,
  1216. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1217. } else {
  1218. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1219. }
  1220. } else {
  1221. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1222. }
  1223. break;
  1224. case ARG_NETWORK_GW:
  1225. if (xParameterStringLength <= 15) {
  1226. if (ipaddr_addr(str) != IPADDR_NONE) {
  1227. SetGatewayStr(str);
  1228. strcpy( ( char * ) pcWriteBuffer,
  1229. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1230. } else {
  1231. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1232. }
  1233. } else {
  1234. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1235. }
  1236. break;
  1237. case ARG_NETWORK_MASK:
  1238. if (xParameterStringLength <= 15) {
  1239. uint32_t mask = ipaddr_addr(str);
  1240. if (mask != IPADDR_NONE) {
  1241. if(ip4_addr_netmask_valid(mask)) {
  1242. SetMaskStr(str);
  1243. strcpy( ( char * ) pcWriteBuffer,
  1244. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1245. } else {
  1246. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1247. }
  1248. } else {
  1249. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1250. }
  1251. } else {
  1252. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1253. }
  1254. break;
  1255. default:
  1256. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1257. break;
  1258. }
  1259. xReturn = pdFALSE;
  1260. return xReturn;
  1261. }
  1262. /*
  1263. * Implements the snmp command.
  1264. */
  1265. static portBASE_TYPE prvTaskSNMPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1266. {
  1267. int8_t *pcParameterString;
  1268. signed portBASE_TYPE xParameterStringLength, xReturn;
  1269. portBASE_TYPE xParameterNumber = 1;
  1270. char str[20];
  1271. char temp_str[20];
  1272. uint8_t i;
  1273. ( void ) pcCommandString;
  1274. ( void ) xWriteBufferLen;
  1275. configASSERT( pcWriteBuffer );
  1276. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1277. /* Obtain the parameter string. */
  1278. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1279. (
  1280. pcCommandString, /* The command string itself. */
  1281. xParameterNumber, /* Return the next parameter. */
  1282. &xParameterStringLength /* Store the parameter string length. */
  1283. );
  1284. if (pcParameterString == NULL) {
  1285. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1286. return pdFALSE;
  1287. }
  1288. for (i = 0; i < ARG_SNMP_ALL; i ++) {
  1289. if ( strncmp( ( const char * ) pcParameterString, snmp_args_list[i], strlen(snmp_args_list[i]) ) == 0
  1290. && xParameterStringLength == strlen(snmp_args_list[i])) {
  1291. break;
  1292. }
  1293. }
  1294. if (cli_state->user_id != ADMIN && i != ARG_SNMP_INFO) {
  1295. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1296. return pdFALSE;
  1297. }
  1298. xParameterNumber ++;
  1299. /* Obtain the parameter string. */
  1300. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1301. (
  1302. pcCommandString, /* The command string itself. */
  1303. xParameterNumber, /* Return the next parameter. */
  1304. &xParameterStringLength /* Store the parameter string length. */
  1305. );
  1306. xParameterNumber ++;
  1307. if (pcParameterString == NULL) {
  1308. if (i == ARG_SNMP_INFO) {
  1309. snmp_config_param(pcWriteBuffer);
  1310. } else {
  1311. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1312. }
  1313. return pdFALSE;
  1314. }
  1315. memset(str, 0, sizeof(str));
  1316. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1317. xParameterStringLength = sizeof(str) - 1;
  1318. }
  1319. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1320. switch (i) {
  1321. case ARG_SNMP_SERVER:
  1322. if (xParameterStringLength == 1 && isdigit_int(str[0])) {
  1323. int32_t temp = atoi(str);
  1324. if (temp > 0 && temp < 6) {
  1325. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1326. (
  1327. pcCommandString, /* The command string itself. */
  1328. xParameterNumber, /* Return the next parameter. */
  1329. &xParameterStringLength /* Store the parameter string length. */
  1330. );
  1331. if (pcParameterString != NULL) {
  1332. memset(str, 0, sizeof(str));
  1333. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1334. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1335. xParameterStringLength = sizeof(str) - 1;
  1336. }
  1337. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1338. if (xParameterStringLength <= 15) {
  1339. if (ipaddr_addr(str) != IPADDR_NONE) {
  1340. switch (temp) {
  1341. case 1:
  1342. SetManagerIp(str);
  1343. break;
  1344. case 2:
  1345. SetManagerIp2(str);
  1346. break;
  1347. case 3:
  1348. SetManagerIp3(str);
  1349. break;
  1350. case 4:
  1351. SetManagerIp4(str);
  1352. break;
  1353. case 5:
  1354. SetManagerIp5(str);
  1355. break;
  1356. }
  1357. if (temp > 0 && temp < 6) {
  1358. cli_save_config(cli_state);
  1359. }
  1360. } else {
  1361. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1362. }
  1363. } else {
  1364. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1365. }
  1366. } else {
  1367. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1368. }
  1369. } else {
  1370. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1371. }
  1372. } else {
  1373. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1374. }
  1375. break;
  1376. case ARG_SNMP_COMMUNITY:
  1377. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1378. (
  1379. pcCommandString, /* The command string itself. */
  1380. xParameterNumber, /* Return the next parameter. */
  1381. &xParameterStringLength /* Store the parameter string length. */
  1382. );
  1383. if (pcParameterString != NULL) {
  1384. memset(temp_str, 0, sizeof(temp_str));
  1385. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1386. if (xParameterStringLength > (int32_t)sizeof(temp_str)) {
  1387. xParameterStringLength = sizeof(temp_str) - 1;
  1388. }
  1389. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1390. if (control_string_en_digit(temp_str, strlen(temp_str))) {
  1391. if (strncmp(str, "read", 4) == 0) {
  1392. SetReadCommunity(temp_str);
  1393. cli_save_config(cli_state);
  1394. } else if (strncmp(str, "write", 5) == 0) {
  1395. SetWriteCommunity(temp_str);
  1396. cli_save_config(cli_state);
  1397. } else {
  1398. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1399. }
  1400. } else {
  1401. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1402. }
  1403. } else {
  1404. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1405. }
  1406. break;
  1407. default:
  1408. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1409. break;
  1410. }
  1411. xReturn = pdFALSE;
  1412. return xReturn;
  1413. }
  1414. /*
  1415. * Implements the akb command.
  1416. */
  1417. static portBASE_TYPE prvTaskAKBCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1418. {
  1419. int8_t *pcParameterString;
  1420. signed portBASE_TYPE xParameterStringLength, xReturn;
  1421. portBASE_TYPE xParameterNumber = 1;
  1422. char str[110];
  1423. uint8_t i;
  1424. uint8_t fail = 0;
  1425. uint16_t temp = 0;
  1426. float value = 0;
  1427. ( void ) pcCommandString;
  1428. ( void ) xWriteBufferLen;
  1429. configASSERT( pcWriteBuffer );
  1430. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1431. /* Obtain the parameter string. */
  1432. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1433. (
  1434. pcCommandString, /* The command string itself. */
  1435. xParameterNumber, /* Return the next parameter. */
  1436. &xParameterStringLength /* Store the parameter string length. */
  1437. );
  1438. if (pcParameterString == NULL) {
  1439. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1440. return pdFALSE;
  1441. }
  1442. for (i = 0; i < ARG_AKB_ALL; i ++) {
  1443. if ( strncmp( ( const char * ) pcParameterString, akb_args_list[i], strlen(akb_args_list[i]) ) == 0
  1444. && xParameterStringLength == strlen(akb_args_list[i])) {
  1445. break;
  1446. }
  1447. }
  1448. if (cli_state->user_id != ADMIN && i != ARG_AKB_INFO) {
  1449. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1450. return pdFALSE;
  1451. }
  1452. xParameterNumber ++;
  1453. /* Obtain the parameter string. */
  1454. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1455. (
  1456. pcCommandString, /* The command string itself. */
  1457. xParameterNumber, /* Return the next parameter. */
  1458. &xParameterStringLength /* Store the parameter string length. */
  1459. );
  1460. if (pcParameterString == NULL) {
  1461. if (i == ARG_AKB_INFO) {
  1462. akb_config_param(pcWriteBuffer);
  1463. } else {
  1464. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1465. }
  1466. return pdFALSE;
  1467. }
  1468. memset(str, 0, sizeof(str));
  1469. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1470. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1471. xParameterStringLength = sizeof(str) - 2;
  1472. }
  1473. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1474. #if HARDWARE_BT6709 || HARDWARE_BT6709_MTS || HARDWARE_BT6710
  1475. if (i != ARG_AKB_DATASET)
  1476. #endif
  1477. {
  1478. for (uint8_t j = 0; j < xParameterStringLength; j ++) {
  1479. if (!isfloatdigit(str[j])) {
  1480. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1481. return pdFALSE;
  1482. }
  1483. }
  1484. value = atof(str);
  1485. }
  1486. switch (i) {
  1487. case ARG_AKB_VOLT_CELL_MIN:
  1488. if (value < sSettings.UPS_Setting.Ucellmax && value >= MIN_VOLT_CELL_RANGE) {
  1489. SetUPSVoltCellMinStr(str);
  1490. cli_save_config(cli_state);
  1491. } else {
  1492. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1493. }
  1494. break;
  1495. case ARG_AKB_VOLT_CELL_MAX:
  1496. if (value > sSettings.UPS_Setting.Ucellmin && value <= MAX_VOLT_CELL_RANGE) {
  1497. SetUPSVoltCellMaxStr(str);
  1498. cli_save_config(cli_state);
  1499. } else {
  1500. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1501. }
  1502. break;
  1503. #if HARDWARE_BT6709 || HARDWARE_BT6709_MTS || HARDWARE_BT6711 || HARDWARE_BT6711_V1 || HARDWARE_BT6710
  1504. case ARG_AKB_CAPACITY:
  1505. if (value >= CAPACITY_MIN_RANGE && value <= CAPACITY_MAX_RANGE && (value - (int32_t)value) == 0) {
  1506. SetCapacityNominalAKBStr(str);
  1507. cli_save_config(cli_state);
  1508. } else {
  1509. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1510. }
  1511. break;
  1512. case ARG_AKB_VOLT:
  1513. if (value >= AKB_VOLTAGE_MIN_RANGE && value <= AKB_VOLTAGE_MAX_RANGE && ((int32_t)value % 12) == 0 && (value - (int32_t)value) == 0) {
  1514. SetVoltageAKBNominalStr(str);
  1515. cli_save_config(cli_state);
  1516. } else {
  1517. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1518. }
  1519. break;
  1520. #if HARDWARE_BT6709 || HARDWARE_BT6709_MTS || HARDWARE_BT6710
  1521. case ARG_AKB_LIFETIME:
  1522. if (value >= LIFETIME_MIN_RANGE && value <= LIFETIME_MAX_RANGE && (value - (int32_t)value) == 0) {
  1523. SetLifeTimeAKBStr(str);
  1524. cli_save_config(cli_state);
  1525. } else {
  1526. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1527. }
  1528. break;
  1529. case ARG_AKB_DATASET:
  1530. if (xParameterStringLength == 10) {
  1531. if (strncmp( str, "0000-00-00", 10) == 0) {
  1532. memset(str, 0, sizeof(str));
  1533. SetDataSetAKBStr(str);
  1534. SETTINGS_Save();
  1535. xReturn = pdFALSE;
  1536. return xReturn;
  1537. }
  1538. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  1539. if (j != 4 && j != 7) {
  1540. if (str[j] > 0x39 || str[j] < 0x30) {
  1541. fail = 1;
  1542. }
  1543. } else if (j == 4 || j == 7) {
  1544. if (str[j] != '-') {
  1545. fail = 1;
  1546. }
  1547. }
  1548. }
  1549. if (!fail) {
  1550. temp = 1000 * (str[0] - 0x30) + 100 * (str[1] - 0x30) + 10 * (str[2] - 0x30) + str[3] - 0x30;
  1551. if (temp > 2099 || temp < 2000) {
  1552. fail = 1;
  1553. }
  1554. temp = 0;
  1555. temp = 10 * (str[5] - 0x30) + (str[6] - 0x30);
  1556. if (temp > 12) {
  1557. fail = 1;
  1558. }
  1559. temp = 0;
  1560. temp = 10 * (str[8] - 0x30) + (str[9] - 0x30);
  1561. if (temp > 31) {
  1562. fail = 1;
  1563. }
  1564. }
  1565. } else {
  1566. fail = 1;
  1567. }
  1568. if (!fail) {
  1569. SetDataSetAKBStr(str);
  1570. cli_save_config(cli_state);
  1571. } else {
  1572. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1573. }
  1574. break;
  1575. #endif
  1576. case ARG_AKB_UPS_POWER:
  1577. if (value >= UPS_POWER_MIN_RANGE && value <= UPS_POWER_MAX_RANGE && ((int32_t)value % 50) == 0 && (value - (int32_t)value) == 0) {
  1578. SetUPSPowerStr(str);
  1579. cli_save_config(cli_state);
  1580. } else {
  1581. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1582. }
  1583. break;
  1584. #endif
  1585. default:
  1586. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1587. break;
  1588. }
  1589. xReturn = pdFALSE;
  1590. return xReturn;
  1591. }
  1592. /*
  1593. * Implements the alarm command.
  1594. */
  1595. static portBASE_TYPE prvTaskAlarmCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1596. {
  1597. int8_t *pcParameterString;
  1598. signed portBASE_TYPE xParameterStringLength, xReturn;
  1599. portBASE_TYPE xParameterNumber = 1;
  1600. char str[110];
  1601. uint8_t i, j;
  1602. float value = 0;
  1603. uint8_t k;
  1604. ( void ) pcCommandString;
  1605. ( void ) xWriteBufferLen;
  1606. configASSERT( pcWriteBuffer );
  1607. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1608. /* Obtain the parameter string. */
  1609. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1610. (
  1611. pcCommandString, /* The command string itself. */
  1612. xParameterNumber, /* Return the next parameter. */
  1613. &xParameterStringLength /* Store the parameter string length. */
  1614. );
  1615. if (pcParameterString == NULL) {
  1616. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1617. return pdFALSE;
  1618. }
  1619. for (i = 0; i < ARG_ALARM_TYPE_ALL; i ++) {
  1620. if ( strncmp( ( const char * ) pcParameterString, type_alarm_args_list[i], strlen(type_alarm_args_list[i]) ) == 0
  1621. && xParameterStringLength == strlen(type_alarm_args_list[i])) {
  1622. break;
  1623. }
  1624. }
  1625. if (cli_state->user_id != ADMIN && i != ARG_ALARM_INFO) {
  1626. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1627. return pdFALSE;
  1628. }
  1629. xParameterNumber ++;
  1630. /* Obtain the parameter string. */
  1631. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1632. (
  1633. pcCommandString, /* The command string itself. */
  1634. xParameterNumber, /* Return the next parameter. */
  1635. &xParameterStringLength /* Store the parameter string length. */
  1636. );
  1637. if (pcParameterString == NULL) {
  1638. if (i == ARG_ALARM_INFO) {
  1639. alarm_config_param(pcWriteBuffer);
  1640. } else {
  1641. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1642. }
  1643. return pdFALSE;
  1644. }
  1645. for (j = 0; j < ARG_ALARM_ALL; j ++) {
  1646. if ( strncmp( ( const char * ) pcParameterString, alarm_args_list[j], strlen(alarm_args_list[j]) ) == 0 ) {
  1647. break;
  1648. }
  1649. }
  1650. xParameterNumber ++;
  1651. /* Obtain the parameter string. */
  1652. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1653. (
  1654. pcCommandString, /* The command string itself. */
  1655. xParameterNumber, /* Return the next parameter. */
  1656. &xParameterStringLength /* Store the parameter string length. */
  1657. );
  1658. if (pcParameterString == NULL) {
  1659. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1660. return pdFALSE;
  1661. }
  1662. memset(str, 0, sizeof(str));
  1663. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1664. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1665. xParameterStringLength = sizeof(str) - 2;
  1666. }
  1667. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1668. switch (i) {
  1669. case ARG_ALARM_TEMP:
  1670. switch (j) {
  1671. case ARG_ALARM_LINE_LOW:
  1672. for (k = 0; k < xParameterStringLength; k ++) {
  1673. if (!isdigit_int(str[k])) {
  1674. if (k == 0 && str[k] == '-') {
  1675. continue;
  1676. } else {
  1677. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1678. return pdFALSE;
  1679. }
  1680. }
  1681. }
  1682. value = atof(str);
  1683. if (value >= MIN_TEMP_MIN_RANGE && value <= MIN_TEMP_MAX_RANGE) {
  1684. SetTemperatureAlarmLowRangeStr(str);
  1685. cli_save_config(cli_state);
  1686. } else {
  1687. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1688. }
  1689. break;
  1690. case ARG_ALARM_LINE_HIGH:
  1691. for (k = 0; k < xParameterStringLength; k ++) {
  1692. if (!isdigit_int(str[k])) {
  1693. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1694. return pdFALSE;
  1695. }
  1696. }
  1697. value = atof(str);
  1698. if (value >= MAX_TEMP_MIN_RANGE && value <= MAX_TEMP_MAX_RANGE) {
  1699. SetTemperatureAlarmHighRangeStr(str);
  1700. cli_save_config(cli_state);
  1701. } else {
  1702. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1703. }
  1704. break;
  1705. case ARG_ALARM_LINE_HIST:
  1706. for (k = 0; k < xParameterStringLength; k ++) {
  1707. if (!isfloatdigit(str[k])) {
  1708. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1709. return pdFALSE;
  1710. }
  1711. }
  1712. value = atof(str);
  1713. if (value >= HIST_TEMP_MIN_RANGE && value <= HIST_TEMP_MAX_RANGE) {
  1714. SetTemperatureAlarmHisteStr(str);
  1715. cli_save_config(cli_state);
  1716. } else {
  1717. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1718. }
  1719. break;
  1720. default:
  1721. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1722. break;
  1723. }
  1724. break;
  1725. #ifndef HARDWARE_BT6710
  1726. case ARG_ALARM_LOAD:
  1727. switch (j) {
  1728. case ARG_ALARM_LINE_LOW:
  1729. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1730. break;
  1731. case ARG_ALARM_LINE_HIGH:
  1732. for (k = 0; k < xParameterStringLength; k ++) {
  1733. if (!isdigit_int(str[k])) {
  1734. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1735. return pdFALSE;
  1736. }
  1737. }
  1738. value = atof(str);
  1739. if (value >= MAX_LOAD_MIN_RANGE && value <= MAX_LOAD_MAX_RANGE) {
  1740. SetLoadAlarmHighRangeStr(str);
  1741. cli_save_config(cli_state);
  1742. } else {
  1743. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1744. }
  1745. break;
  1746. case ARG_ALARM_LINE_HIST:
  1747. for (k = 0; k < xParameterStringLength; k ++) {
  1748. if (!isfloatdigit(str[k])) {
  1749. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1750. return pdFALSE;
  1751. }
  1752. }
  1753. value = atof(str);
  1754. if (value >= HIST_LOAD_MIN_RANGE && value <= HIST_LOAD_MAX_RANGE) {
  1755. SetLoadAlarmHistStr(str);
  1756. cli_save_config(cli_state);
  1757. } else {
  1758. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1759. }
  1760. break;
  1761. default:
  1762. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1763. break;
  1764. }
  1765. break;
  1766. #endif
  1767. case ARG_ALARM_VOUT:
  1768. switch (j) {
  1769. case ARG_ALARM_LINE_LOW:
  1770. for (k = 0; k < xParameterStringLength; k ++) {
  1771. if (!isdigit_int(str[k])) {
  1772. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1773. return pdFALSE;
  1774. }
  1775. }
  1776. value = atof(str);
  1777. if (value >= MIN_VAC_MIN_RANGE && value <= MIN_VAC_MAX_RANGE) {
  1778. SetVACAlarmLowRangeStr(str);
  1779. cli_save_config(cli_state);
  1780. } else {
  1781. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1782. }
  1783. break;
  1784. case ARG_ALARM_LINE_HIGH:
  1785. for (k = 0; k < xParameterStringLength; k ++) {
  1786. if (!isdigit_int(str[k])) {
  1787. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1788. return pdFALSE;
  1789. }
  1790. }
  1791. value = atof(str);
  1792. if (value >= MAX_VAC_MIN_RANGE && value <= MAX_VAC_MAX_RANGE) {
  1793. SetVACAlarmHighRangeStr(str);
  1794. cli_save_config(cli_state);
  1795. } else {
  1796. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1797. }
  1798. break;
  1799. case ARG_ALARM_LINE_HIST:
  1800. for (k = 0; k < xParameterStringLength; k ++) {
  1801. if (!isdigit_int(str[k])) {
  1802. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1803. return pdFALSE;
  1804. }
  1805. }
  1806. value = atof(str);
  1807. if (value >= HIST_VAC_MIN_RANGE && value <= HIST_VAC_MAX_RANGE) {
  1808. SetVACAlarmHisteStr(str);
  1809. cli_save_config(cli_state);
  1810. } else {
  1811. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1812. }
  1813. break;
  1814. default:
  1815. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1816. break;
  1817. }
  1818. break;
  1819. #ifdef TEMP_CABINET_MONITOR
  1820. case ARG_TEMP_CABINAT:
  1821. switch (j) {
  1822. case ARG_ALARM_LINE_LOW:
  1823. for (k = 0; k < xParameterStringLength; k ++) {
  1824. if (!isdigit_int(str[k])) {
  1825. if (k == 0 && str[k] == '-') {
  1826. continue;
  1827. } else {
  1828. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1829. return pdFALSE;
  1830. }
  1831. }
  1832. }
  1833. value = atof(str);
  1834. if (value >= MIN_TEMP_MIN_RANGE && value <= MIN_TEMP_MAX_RANGE) {
  1835. SetTemperatureCabinetAlarmLowRangeStr(str);
  1836. cli_save_config(cli_state);
  1837. } else {
  1838. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1839. }
  1840. break;
  1841. case ARG_ALARM_LINE_HIGH:
  1842. for (k = 0; k < xParameterStringLength; k ++) {
  1843. if (!isdigit_int(str[k])) {
  1844. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1845. return pdFALSE;
  1846. }
  1847. }
  1848. value = atof(str);
  1849. if (value >= MAX_TEMP_MIN_RANGE && value <= MAX_TEMP_MAX_RANGE) {
  1850. SetTemperatureCabinetAlarmHighRangeStr(str);
  1851. cli_save_config(cli_state);
  1852. } else {
  1853. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1854. }
  1855. break;
  1856. case ARG_ALARM_LINE_HIST:
  1857. for (k = 0; k < xParameterStringLength; k ++) {
  1858. if (!isfloatdigit(str[k])) {
  1859. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1860. return pdFALSE;
  1861. }
  1862. }
  1863. value = atof(str);
  1864. if (value >= HIST_TEMP_MIN_RANGE && value <= HIST_TEMP_MAX_RANGE) {
  1865. SetTemperatureCabinetAlarmHisteStr(str);
  1866. cli_save_config(cli_state);
  1867. } else {
  1868. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1869. }
  1870. break;
  1871. default:
  1872. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1873. break;
  1874. }
  1875. break;
  1876. #endif
  1877. #ifdef VAC_IN_MONITOR
  1878. case ARG_ALARM_VACIN:
  1879. switch (j) {
  1880. case ARG_ALARM_LINE_LOW:
  1881. for (k = 0; k < xParameterStringLength; k ++) {
  1882. if (!isdigit_int(str[k])) {
  1883. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1884. return pdFALSE;
  1885. }
  1886. }
  1887. value = atof(str);
  1888. if (value >= MIN_VAC_MIN_RANGE && value <= MIN_VAC_MAX_RANGE) {
  1889. SetVACInputAlarmLowRangeStr(str);
  1890. cli_save_config(cli_state);
  1891. } else {
  1892. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1893. }
  1894. break;
  1895. case ARG_ALARM_LINE_HIGH:
  1896. for (k = 0; k < xParameterStringLength; k ++) {
  1897. if (!isdigit_int(str[k])) {
  1898. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1899. return pdFALSE;
  1900. }
  1901. }
  1902. value = atof(str);
  1903. if (value >= MAX_VAC_MIN_RANGE && value <= MAX_VAC_MAX_RANGE) {
  1904. SetVACInputAlarmHighRangeStr(str);
  1905. cli_save_config(cli_state);
  1906. } else {
  1907. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1908. }
  1909. break;
  1910. case ARG_ALARM_LINE_HIST:
  1911. for (k = 0; k < xParameterStringLength; k ++) {
  1912. if (!isdigit_int(str[k])) {
  1913. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1914. return pdFALSE;
  1915. }
  1916. }
  1917. value = atof(str);
  1918. if (value >= HIST_VAC_MIN_RANGE && value <= HIST_VAC_MAX_RANGE) {
  1919. SetVACinputAlarmHisteStr(str);
  1920. cli_save_config(cli_state);
  1921. } else {
  1922. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1923. }
  1924. break;
  1925. default:
  1926. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1927. break;
  1928. }
  1929. break;
  1930. #endif
  1931. default:
  1932. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1933. break;
  1934. }
  1935. xReturn = pdFALSE;
  1936. return xReturn;
  1937. }
  1938. #ifdef NOTIFICATION_CONTROL_ENABLE
  1939. /*
  1940. * Implements the notification command.
  1941. */
  1942. static portBASE_TYPE prvTaskNotificationCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  1943. const int8_t *pcCommandString )
  1944. {
  1945. int8_t *pcParameterString;
  1946. signed portBASE_TYPE xParameterStringLength, xReturn;
  1947. portBASE_TYPE xParameterNumber = 1;
  1948. char str[20];
  1949. char temp_str[20];
  1950. uint8_t i;
  1951. char *beginValue;
  1952. uint8_t len;
  1953. ( void ) pcCommandString;
  1954. ( void ) xWriteBufferLen;
  1955. configASSERT( pcWriteBuffer );
  1956. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1957. /* Obtain the parameter string. */
  1958. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1959. (
  1960. pcCommandString, /* The command string itself. */
  1961. xParameterNumber, /* Return the next parameter. */
  1962. &xParameterStringLength /* Store the parameter string length. */
  1963. );
  1964. if (pcParameterString == NULL) {
  1965. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1966. return pdFALSE;
  1967. }
  1968. for (i = 0; i < ARG_NOTIFICATION_ALL; i ++) {
  1969. if ( strncmp( ( const char * ) pcParameterString, notification_args_list[i], strlen(notification_args_list[i]) ) == 0
  1970. && xParameterStringLength == strlen(notification_args_list[i])) {
  1971. break;
  1972. }
  1973. }
  1974. if (cli_state->user_id != ADMIN && i != ARG_NOTIFICATION_INFO) {
  1975. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1976. return pdFALSE;
  1977. }
  1978. xParameterNumber ++;
  1979. /* Obtain the parameter string. */
  1980. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1981. (
  1982. pcCommandString, /* The command string itself. */
  1983. xParameterNumber, /* Return the next parameter. */
  1984. &xParameterStringLength /* Store the parameter string length. */
  1985. );
  1986. xParameterNumber ++;
  1987. if (pcParameterString == NULL) {
  1988. if (i == ARG_NOTIFICATION_INFO) {
  1989. notification_param(pcWriteBuffer);
  1990. } else {
  1991. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1992. }
  1993. return pdFALSE;
  1994. }
  1995. memset(str, 0, sizeof(str));
  1996. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1997. xParameterStringLength = sizeof(str) - 1;
  1998. }
  1999. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2000. switch (i) {
  2001. case ARG_NOTIFICATION_SET:
  2002. if (xParameterStringLength >= 1) {
  2003. for(uint32_t k = 0; k < xParameterStringLength; k ++) {
  2004. if (!isdigit_int(str[k])) {
  2005. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2006. return pdFALSE;
  2007. }
  2008. }
  2009. int32_t temp = atoi(str);
  2010. uint8_t value_notification = 0;
  2011. if (temp > 0 && temp < ALL_TRAPS) {
  2012. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2013. (
  2014. pcCommandString, /* The command string itself. */
  2015. xParameterNumber, /* Return the next parameter. */
  2016. &xParameterStringLength /* Store the parameter string length. */
  2017. );
  2018. if (pcParameterString != NULL && xParameterStringLength == 3) {
  2019. if (strncmp(pcParameterString, "ENA", 3) == 0) {
  2020. value_notification = 1;
  2021. SetNotificationFlagsStr(&value_notification, (uint8_t)temp);
  2022. SETTINGS_Save();
  2023. } else if (strncmp(pcParameterString, "DIS", 3) == 0) {
  2024. SetNotificationFlagsStr(&value_notification, (uint8_t)temp);
  2025. SETTINGS_Save();
  2026. } else {
  2027. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2028. }
  2029. } else {
  2030. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2031. }
  2032. } else {
  2033. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2034. }
  2035. } else {
  2036. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2037. }
  2038. break;
  2039. default:
  2040. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2041. break;
  2042. }
  2043. xReturn = pdFALSE;
  2044. return xReturn;
  2045. }
  2046. #endif
  2047. #ifdef WHITELIST_ENABLE
  2048. /*
  2049. * Implements the whitelist command.
  2050. */
  2051. static portBASE_TYPE prvTaskWhiteListCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2052. const int8_t *pcCommandString )
  2053. {
  2054. int8_t *pcParameterString;
  2055. signed portBASE_TYPE xParameterStringLength, xReturn;
  2056. portBASE_TYPE xParameterNumber = 1;
  2057. char str[20];
  2058. char temp_str[20];
  2059. uint8_t i;
  2060. char *beginValue;
  2061. uint8_t len;
  2062. int32_t temp;
  2063. ( void ) pcCommandString;
  2064. ( void ) xWriteBufferLen;
  2065. configASSERT( pcWriteBuffer );
  2066. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2067. /* Obtain the parameter string. */
  2068. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2069. (
  2070. pcCommandString, /* The command string itself. */
  2071. xParameterNumber, /* Return the next parameter. */
  2072. &xParameterStringLength /* Store the parameter string length. */
  2073. );
  2074. if (pcParameterString == NULL) {
  2075. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2076. return pdFALSE;
  2077. }
  2078. for (i = 0; i < ARG_WHITELIST_ALL; i ++) {
  2079. if ( strncmp( ( const char * ) pcParameterString, whitelist_args_list[i], strlen(whitelist_args_list[i]) ) == 0
  2080. && xParameterStringLength == strlen(whitelist_args_list[i])) {
  2081. break;
  2082. }
  2083. }
  2084. if (cli_state->user_id != ADMIN && i != ARG_WHITELIST_INFO) {
  2085. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2086. return pdFALSE;
  2087. }
  2088. xParameterNumber ++;
  2089. /* Obtain the parameter string. */
  2090. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2091. (
  2092. pcCommandString, /* The command string itself. */
  2093. xParameterNumber, /* Return the next parameter. */
  2094. &xParameterStringLength /* Store the parameter string length. */
  2095. );
  2096. xParameterNumber ++;
  2097. if (pcParameterString == NULL) {
  2098. if (i == ARG_WHITELIST_INFO) {
  2099. whitelist_config_param(pcWriteBuffer);
  2100. } else {
  2101. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2102. }
  2103. return pdFALSE;
  2104. }
  2105. memset(str, 0, sizeof(str));
  2106. if (xParameterStringLength > (int32_t)sizeof(str)) {
  2107. xParameterStringLength = sizeof(str) - 1;
  2108. }
  2109. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2110. switch (i) {
  2111. case ARG_WHITELIST_RANGE:
  2112. if (xParameterStringLength == 1 && isdigit_int(str[0])) {
  2113. temp = atoi(str);
  2114. if (temp > 0 && temp < 6) {
  2115. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2116. (
  2117. pcCommandString, /* The command string itself. */
  2118. xParameterNumber, /* Return the next parameter. */
  2119. &xParameterStringLength /* Store the parameter string length. */
  2120. );
  2121. if (pcParameterString != NULL) {
  2122. memset(str, 0, sizeof(str));
  2123. xParameterStringLength = strlen(( const char * ) pcParameterString);
  2124. if (xParameterStringLength > (int32_t)sizeof(str)) {
  2125. xParameterStringLength = sizeof(str) - 1;
  2126. }
  2127. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  2128. if (xParameterStringLength <= 19) {
  2129. beginValue = strpbrk(str, "/");
  2130. if (beginValue == NULL) {
  2131. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2132. return pdFALSE;
  2133. }
  2134. int32_t mask = atoi(&beginValue[1]);
  2135. len = beginValue - str;
  2136. memset(temp_str, 0, sizeof(temp_str));
  2137. strncpy(temp_str, str, len);
  2138. for (uint8_t j = (len + 1); j < xParameterStringLength; j++) {
  2139. if (!isdigit_int(str[j])) {
  2140. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2141. return pdFALSE;
  2142. }
  2143. }
  2144. if (ipaddr_addr(temp_str) != IPADDR_NONE && (mask <= 32 && mask >= 0)) {
  2145. SetWhiteListSTR(str, (temp - 1));
  2146. strcpy( ( char * ) pcWriteBuffer,
  2147. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  2148. } else {
  2149. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2150. }
  2151. } else {
  2152. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2153. }
  2154. } else {
  2155. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2156. }
  2157. } else {
  2158. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2159. }
  2160. } else {
  2161. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2162. }
  2163. break;
  2164. case ARG_WHITELIST_RESET:
  2165. if (xParameterStringLength == 1 && isdigit_int(str[0])) {
  2166. temp = atoi(str);
  2167. if (temp > 0 && temp < 6) {
  2168. memset(str, 0, sizeof(str));
  2169. SetWhiteListSTR(str, (temp - 1));
  2170. strcpy( ( char * ) pcWriteBuffer,
  2171. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  2172. } else {
  2173. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2174. }
  2175. } else {
  2176. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2177. }
  2178. break;
  2179. default:
  2180. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2181. break;
  2182. }
  2183. xReturn = pdFALSE;
  2184. return xReturn;
  2185. }
  2186. #endif
  2187. /*
  2188. * Implements the change password command.
  2189. */
  2190. static portBASE_TYPE prvTaskUserCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  2191. {
  2192. int8_t *pcParameterString;
  2193. signed portBASE_TYPE xParameterStringLength, xReturn;
  2194. portBASE_TYPE xParameterNumber = 1;
  2195. uint8_t i;
  2196. char temp_str[MAX_WEB_LOGIN_LEN];
  2197. char WebLogin[MAX_WEB_LOGIN_LEN];
  2198. uint8_t valueLen, user_id;
  2199. const int8_t *const pcChangePWDHeader = ( int8_t * ) "\r\nВведите новый пароль:";
  2200. ( void ) pcCommandString;
  2201. ( void ) xWriteBufferLen;
  2202. configASSERT( pcWriteBuffer );
  2203. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2204. if (cli_state->user_id != ADMIN) {
  2205. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2206. return pdFALSE;
  2207. }
  2208. /* Obtain the parameter string. */
  2209. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2210. (
  2211. pcCommandString, /* The command string itself. */
  2212. xParameterNumber, /* Return the next parameter. */
  2213. &xParameterStringLength /* Store the parameter string length. */
  2214. );
  2215. if (pcParameterString == NULL) {
  2216. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2217. return pdFALSE;
  2218. }
  2219. for (i = 0; i < ARG_USER_ALL; i ++) {
  2220. if ( strncmp( ( const char * ) pcParameterString, user_args_list[i], strlen(user_args_list[i]) ) == 0 ) {
  2221. break;
  2222. }
  2223. }
  2224. xParameterNumber ++;
  2225. /* Obtain the parameter string. */
  2226. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2227. (
  2228. pcCommandString, /* The command string itself. */
  2229. xParameterNumber, /* Return the next parameter. */
  2230. &xParameterStringLength /* Store the parameter string length. */
  2231. );
  2232. if (i == ARG_USER_PWD) {
  2233. memset(temp_str, 0, sizeof(temp_str));
  2234. xParameterStringLength = strlen(( const char * ) pcParameterString);
  2235. if (xParameterStringLength > (int32_t)sizeof(temp_str)) {
  2236. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2237. } else {
  2238. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  2239. for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
  2240. GetUserLogin(user_id, WebLogin, &valueLen);
  2241. /* Check login and password */
  2242. if (strncmp(WebLogin, temp_str, MAX_WEB_LOGIN_LEN) == 0) {
  2243. /* Login and pass are valid */
  2244. cli_state->id_change_pwd = user_id;
  2245. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcChangePWDHeader, strlen( ( char * ) pcChangePWDHeader ) );
  2246. cli_state->input_state = CLI_CHANGE_PWD;
  2247. break;
  2248. }
  2249. }
  2250. if (cli_state->input_state != CLI_CHANGE_PWD) {
  2251. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2252. }
  2253. }
  2254. } else {
  2255. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2256. }
  2257. xReturn = pdFALSE;
  2258. return xReturn;
  2259. }
  2260. /*
  2261. * Implements the config command.
  2262. */
  2263. static portBASE_TYPE prvTaskConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2264. const int8_t *pcCommandString )
  2265. {
  2266. int8_t *pcParameterString;
  2267. signed portBASE_TYPE xParameterStringLength, xReturn;
  2268. portBASE_TYPE xParameterNumber = 1;
  2269. char str[110];
  2270. uint8_t i;
  2271. static uint8_t config_menu = 0;
  2272. const int8_t *const pcInfoTableHeader = ( int8_t * )
  2273. "\r\n*********Конфигурация Контроллера*********\r\n";
  2274. ( void ) pcCommandString;
  2275. ( void ) xWriteBufferLen;
  2276. configASSERT( pcWriteBuffer );
  2277. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2278. /* Obtain the parameter string. */
  2279. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2280. (
  2281. pcCommandString, /* The command string itself. */
  2282. xParameterNumber, /* Return the next parameter. */
  2283. &xParameterStringLength /* Store the parameter string length. */
  2284. );
  2285. if (pcParameterString == NULL) {
  2286. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2287. return pdFALSE;
  2288. }
  2289. for (i = 0; i < ARG_CONFIG_ALL; i ++) {
  2290. if ( strncmp( ( const char * ) pcParameterString, config_args_list[i], strlen(config_args_list[i]) ) == 0
  2291. && xParameterStringLength == strlen(config_args_list[i])) {
  2292. break;
  2293. }
  2294. }
  2295. if (cli_state->user_id != ADMIN && i != ARG_CONFIG_INFO) {
  2296. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2297. return pdFALSE;
  2298. }
  2299. xParameterNumber ++;
  2300. /* Obtain the parameter string. */
  2301. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2302. (
  2303. pcCommandString, /* The command string itself. */
  2304. xParameterNumber, /* Return the next parameter. */
  2305. &xParameterStringLength /* Store the parameter string length. */
  2306. );
  2307. if (pcParameterString == NULL) {
  2308. switch (i) {
  2309. case ARG_CONFIG_INFO:
  2310. switch (config_menu) {
  2311. case PARAM_CONFIG_SNMP:
  2312. /* Return the next command help string, before moving the pointer on to
  2313. the next command in the list. */
  2314. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  2315. snmp_config_param(pcWriteBuffer);
  2316. break;
  2317. #ifdef DINS_ENABLE || DOUTS_ENABLE || DALLAS_SENSOR_ENABLE || AM2301_SENSOR_ENABLE
  2318. case PARAM_CONFIG_INOUTS:
  2319. inouts_config_param(pcWriteBuffer);
  2320. break;
  2321. #endif
  2322. #ifdef SYSLOG_ENABLE
  2323. case PARAM_CONFIG_SYSLOG:
  2324. syslog_config_param(pcWriteBuffer);
  2325. break;
  2326. #endif
  2327. #ifdef RADIUS_SERVER_ENABLE
  2328. case PARAM_CONFIG_RADIUS:
  2329. radius_config_param(pcWriteBuffer);
  2330. break;
  2331. #endif
  2332. case PARAM_CONFIG_AKB:
  2333. akb_config_param(pcWriteBuffer);
  2334. break;
  2335. case PARAM_CONFIG_ALARM:
  2336. alarm_config_param(pcWriteBuffer);
  2337. break;
  2338. #ifdef WHITELIST_ENABLE
  2339. case PARAM_CONFIG_WHITELIST:
  2340. whitelist_config_param(pcWriteBuffer);
  2341. break;
  2342. #endif
  2343. case PARAM_CONFIG_NET:
  2344. net_config_param(pcWriteBuffer);
  2345. break;
  2346. #ifdef PORTGW_ENABLE
  2347. case PARAM_CONFIG_PGW:
  2348. pgw_config_param(pcWriteBuffer);
  2349. break;
  2350. #endif
  2351. case PARAM_CONFIG_TIME:
  2352. time_config_param(pcWriteBuffer);
  2353. break;
  2354. }
  2355. config_menu ++;
  2356. if (config_menu == PARAM_CONFIG_ALL) {
  2357. config_menu = 0;
  2358. return pdFALSE;
  2359. } else {
  2360. return pdTRUE;
  2361. }
  2362. break;
  2363. default:
  2364. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2365. break;
  2366. }
  2367. return pdFALSE;
  2368. }
  2369. if (i == ARG_CONFIG_LOAD) {
  2370. memset(str, 0, sizeof(str));
  2371. xParameterStringLength = strlen(( const char * ) pcParameterString);
  2372. if (xParameterStringLength > (int32_t)sizeof(str)) {
  2373. xParameterStringLength = sizeof(str) - 1;
  2374. }
  2375. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2376. if (xParameterStringLength < 13) {
  2377. if (strncmp(str, "default", 7) == 0) {
  2378. SNMP_SendUserTrap(DEVICE_RESTORED);
  2379. log_event_data(LOG_SYSTEM_DEFCONFIG, "Администратор");
  2380. vTaskDelay(500);
  2381. SETTINGS_SetPartDefault();
  2382. cli_save_config(cli_state);
  2383. syslog_str(SYSLOG_INFORMATIONAL, "Сброс настроек (Администратор)");
  2384. strcpy( ( char * ) pcWriteBuffer,
  2385. "\t\tНастройки сброшены к настройкам по умолчанию!\r\n");
  2386. } else {
  2387. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2388. }
  2389. } else {
  2390. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2391. }
  2392. } else {
  2393. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2394. }
  2395. xReturn = pdFALSE;
  2396. return xReturn;
  2397. }
  2398. /*
  2399. * Implements the config command.
  2400. */
  2401. static portBASE_TYPE prvTaskNetConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2402. const int8_t *pcCommandString )
  2403. {
  2404. int8_t *pcParameterString;
  2405. portBASE_TYPE xParameterNumber = 1;
  2406. signed portBASE_TYPE xParameterStringLength;
  2407. uint8_t i;
  2408. static start = 0;
  2409. ( void ) pcCommandString;
  2410. ( void ) xWriteBufferLen;
  2411. configASSERT( pcWriteBuffer );
  2412. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2413. /* Obtain the parameter string. */
  2414. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2415. (
  2416. pcCommandString, /* The command string itself. */
  2417. xParameterNumber, /* Return the next parameter. */
  2418. &xParameterStringLength /* Store the parameter string length. */
  2419. );
  2420. for (i = 0; i < ARG_NETCONFIG_ALL; i ++) {
  2421. if ( strncmp( ( const char * ) pcParameterString, netconfig_args_list[i], strlen(netconfig_args_list[i]) ) == 0
  2422. && xParameterStringLength == strlen(netconfig_args_list[i])) {
  2423. break;
  2424. }
  2425. }
  2426. if (cli_state->user_id != ADMIN) {
  2427. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2428. return pdFALSE;
  2429. }
  2430. switch (i) {
  2431. case ARG_NETCONFIG_APPLY:
  2432. if (!start) {
  2433. /* Если параметры WEB изменились выставляем флаг, сохраняем настройки и перезагружаемся */
  2434. if (GetStateWebReinit() == true) {
  2435. start = 1;
  2436. SetWebReinitFlag(true);
  2437. cli_save_config(cli_state);
  2438. strcpy( ( char * ) pcWriteBuffer,
  2439. "\t\tНастройки сохранены! Контроллер будет перезагружен\r\n\tПосле перезагрузки подтвердите изменения сетевых настроек\r\n");
  2440. return pdTRUE;
  2441. }
  2442. } else {
  2443. start = 0;
  2444. vTaskDelay(1010);
  2445. Reboot(CLI_ACT);
  2446. }
  2447. break;
  2448. case ARG_NETCONFIG_CONFIRM:
  2449. SetWebReinitFlag(false);
  2450. SetConfirmWebParamsFlag();
  2451. strcpy( ( char * ) pcWriteBuffer, "\t\tСетевые настройки подтверждены!\r\n");
  2452. break;
  2453. default:
  2454. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2455. break;
  2456. }
  2457. return pdFALSE;
  2458. }
  2459. /*
  2460. * Implements the history command.
  2461. */
  2462. static portBASE_TYPE prvTaskHistoryCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2463. const int8_t *pcCommandString )
  2464. {
  2465. int8_t *pcParameterString;
  2466. signed portBASE_TYPE xParameterStringLength, xReturn;
  2467. portBASE_TYPE xParameterNumber = 1;
  2468. char str[110];
  2469. uint8_t i;
  2470. static int16_t num_page = 0;
  2471. static int16_t num_page_temp = 1;
  2472. static bool start = true;
  2473. const int8_t *const pcUPShistoryTableHeader = ( int8_t * )
  2474. "\r\n***********Журнал событий ИБП***********\r\n";
  2475. const int8_t *const pcControllerHistoryTableHeader = ( int8_t * )
  2476. "\r\n***********Журнал событий Контроллера***********\r\n";
  2477. ( void ) pcCommandString;
  2478. ( void ) xWriteBufferLen;
  2479. configASSERT( pcWriteBuffer );
  2480. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2481. /* Obtain the parameter string. */
  2482. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2483. (
  2484. pcCommandString, /* The command string itself. */
  2485. xParameterNumber, /* Return the next parameter. */
  2486. &xParameterStringLength /* Store the parameter string length. */
  2487. );
  2488. if (pcParameterString == NULL) {
  2489. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2490. return pdFALSE;
  2491. }
  2492. if ( strncmp( ( const char * ) pcParameterString, "show", xParameterStringLength ) != 0 ) {
  2493. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2494. return pdFALSE;
  2495. }
  2496. xParameterNumber ++;
  2497. /* Obtain the parameter string. */
  2498. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2499. (
  2500. pcCommandString, /* The command string itself. */
  2501. xParameterNumber, /* Return the next parameter. */
  2502. &xParameterStringLength /* Store the parameter string length. */
  2503. );
  2504. for (i = 0; i < ARG_HISTORY_ALL; i ++) {
  2505. if ( strncmp( ( const char * ) pcParameterString, history_args_list[i], strlen(history_args_list[i]) ) == 0
  2506. && xParameterStringLength == strlen(history_args_list[i])) {
  2507. break;
  2508. }
  2509. }
  2510. xParameterNumber ++;
  2511. /* Obtain the parameter string. */
  2512. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2513. (
  2514. pcCommandString, /* The command string itself. */
  2515. xParameterNumber, /* Return the next parameter. */
  2516. &xParameterStringLength /* Store the parameter string length. */
  2517. );
  2518. memset(str, 0, sizeof(str));
  2519. if (xParameterStringLength > 5) {
  2520. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2521. return pdFALSE;
  2522. }
  2523. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2524. if (num_page == 0) {
  2525. num_page = atoi(str);
  2526. if (num_page <= 0) {
  2527. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2528. return pdFALSE;
  2529. }
  2530. }
  2531. switch (i) {
  2532. case ARG_HISTORY_EVENTS:
  2533. if (start) {
  2534. start = false;
  2535. /* Return the next command help string, before moving the pointer on to
  2536. the next command in the list. */
  2537. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcControllerHistoryTableHeader,
  2538. strlen( ( char * ) pcControllerHistoryTableHeader ) );
  2539. memset(str, 0, sizeof(str));
  2540. strcat(( char * ) pcWriteBuffer, "\r\n");
  2541. sprintf(str, "Количество страниц журнала: %d\r\n", History_GetPageCount());
  2542. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  2543. strcat(( char * ) pcWriteBuffer, "\r\n");
  2544. if (num_page > History_GetPageCount()) {
  2545. num_page = History_GetPageCount();
  2546. }
  2547. }
  2548. History_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  2549. num_page --;
  2550. num_page_temp ++;
  2551. if (num_page == 0) {
  2552. num_page = 0;
  2553. num_page_temp = 1;
  2554. start = true;
  2555. xReturn = pdFALSE;
  2556. } else {
  2557. xReturn = pdTRUE;
  2558. }
  2559. break;
  2560. case ARG_HISTORY_UPS:
  2561. if (start) {
  2562. start = false;
  2563. /* Return the next command help string, before moving the pointer on to
  2564. the next command in the list. */
  2565. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcUPShistoryTableHeader,
  2566. strlen( ( char * ) pcUPShistoryTableHeader ) );
  2567. memset(str, 0, sizeof(str));
  2568. sprintf(str, "Количество страниц журнала: %d\r\n", LOG_GetPageCount());
  2569. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  2570. if (num_page > LOG_GetPageCount()) {
  2571. num_page = LOG_GetPageCount();
  2572. }
  2573. }
  2574. LOG_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  2575. num_page --;
  2576. num_page_temp ++;
  2577. if (num_page == 0) {
  2578. num_page = 0;
  2579. num_page_temp = 1;
  2580. start = true;
  2581. xReturn = pdFALSE;
  2582. } else {
  2583. xReturn = pdTRUE;
  2584. }
  2585. break;
  2586. default:
  2587. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2588. xReturn = pdFALSE;
  2589. break;
  2590. }
  2591. return xReturn;
  2592. }
  2593. /*
  2594. * Implements the sensor info command.
  2595. */
  2596. static portBASE_TYPE prvTaskSensorCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2597. const int8_t *pcCommandString )
  2598. {
  2599. int8_t *pcParameterString;
  2600. signed portBASE_TYPE xParameterStringLength, xReturn;
  2601. portBASE_TYPE xParameterNumber = 1;
  2602. uint8_t i;
  2603. char str[10];
  2604. char temp_str[10];
  2605. int32_t val = 0, val2 = 0;
  2606. uint8_t fail = 0;
  2607. static uint8_t config_menu = 0;
  2608. uint8_t MAX_CONFIG_PARAM = 0;
  2609. #ifdef DINS_ENABLE || DOUTS_ENABLE || DALLAS_SENSOR_ENABLE || AM2301_SENSOR_ENABLE
  2610. MAX_CONFIG_PARAM = 3;
  2611. #else
  2612. MAX_CONFIG_PARAM = 2;
  2613. #endif
  2614. const int8_t *const pcSensorTableHeader = ( int8_t * )
  2615. "\r\n*********Параметры Контроллера*********\r\n";
  2616. ( void ) pcCommandString;
  2617. ( void ) xWriteBufferLen;
  2618. configASSERT( pcWriteBuffer );
  2619. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2620. /* Obtain the parameter string. */
  2621. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2622. (
  2623. pcCommandString, /* The command string itself. */
  2624. xParameterNumber, /* Return the next parameter. */
  2625. &xParameterStringLength /* Store the parameter string length. */
  2626. );
  2627. if (pcParameterString == NULL) {
  2628. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2629. return pdFALSE;
  2630. }
  2631. for (i = 0; i < ARG_SENSOR_ALL; i ++) {
  2632. if ( strncmp( ( const char * ) pcParameterString, sensor_args_list[i], strlen(sensor_args_list[i]) ) == 0
  2633. && xParameterStringLength == strlen(sensor_args_list[i])) {
  2634. break;
  2635. }
  2636. }
  2637. xParameterNumber ++;
  2638. /* Obtain the parameter string. */
  2639. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2640. (
  2641. pcCommandString, /* The command string itself. */
  2642. xParameterNumber, /* Return the next parameter. */
  2643. &xParameterStringLength /* Store the parameter string length. */
  2644. );
  2645. if (pcParameterString == NULL) {
  2646. if (i == ARG_SENSOR_INFO) {
  2647. switch (config_menu) {
  2648. case 0:
  2649. /* Return the next command help string, before moving the pointer on to
  2650. the next command in the list. */
  2651. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSensorTableHeader, strlen( ( char * ) pcSensorTableHeader ) );
  2652. ups_sensor_param(pcWriteBuffer);
  2653. break;
  2654. case 1:
  2655. ups_sensor_akb_param(pcWriteBuffer);
  2656. break;
  2657. #ifdef DINS_ENABLE || DOUTS_ENABLE || DALLAS_SENSOR_ENABLE || AM2301_SENSOR_ENABLE
  2658. case 2:
  2659. inouts_sensor_param(pcWriteBuffer);
  2660. break;
  2661. #endif
  2662. }
  2663. config_menu ++;
  2664. if (config_menu == MAX_CONFIG_PARAM) {
  2665. config_menu = 0;
  2666. return pdFALSE;
  2667. } else {
  2668. return pdTRUE;
  2669. }
  2670. } else {
  2671. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2672. }
  2673. } else {
  2674. switch (i) {
  2675. #ifdef DINS_ENABLE || DOUTS_ENABLE || DALLAS_SENSOR_ENABLE || AM2301_SENSOR_ENABLE
  2676. case ARG_SENSOR_SETUP:
  2677. if (cli_state->user_id != ADMIN) {
  2678. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2679. return pdFALSE;
  2680. }
  2681. memset(str, 0, sizeof(str));
  2682. if (xParameterStringLength > (int32_t)sizeof(str)) {
  2683. xParameterStringLength = sizeof(str) - 1;
  2684. }
  2685. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2686. if (xParameterStringLength < 7) {
  2687. xParameterNumber ++;
  2688. /* Obtain the parameter string. */
  2689. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2690. (
  2691. pcCommandString, /* The command string itself. */
  2692. xParameterNumber, /* Return the next parameter. */
  2693. &xParameterStringLength /* Store the parameter string length. */
  2694. );
  2695. memset(temp_str, 0, sizeof(str));
  2696. if (xParameterStringLength > 1) {
  2697. fail = 1;
  2698. break;
  2699. }
  2700. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2701. if (!isdigit_int(temp_str[0])) {
  2702. fail = 1;
  2703. break;
  2704. }
  2705. val = atoi(temp_str);
  2706. xParameterNumber ++;
  2707. /* Obtain the parameter string. */
  2708. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2709. (
  2710. pcCommandString, /* The command string itself. */
  2711. xParameterNumber, /* Return the next parameter. */
  2712. &xParameterStringLength /* Store the parameter string length. */
  2713. );
  2714. memset(temp_str, 0, sizeof(str));
  2715. fail = 1;
  2716. #ifdef DINS_ENABLE
  2717. if (strncmp(str, "DI", 2) == 0 && strlen(str) == 2) {
  2718. if (xParameterStringLength > 1) {
  2719. break;
  2720. }
  2721. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2722. if (!isdigit_int(temp_str[0])) {
  2723. break;
  2724. }
  2725. if (val < 1 || val > INPUTS_TOTAL_COUNT) {
  2726. break;
  2727. }
  2728. val2 = atoi(temp_str);
  2729. if (val2 < 0 || val2 > 1) {
  2730. break;
  2731. }
  2732. SetDINTypeActStr(temp_str, (val - 1));
  2733. cli_save_config(cli_state);
  2734. fail = 0;
  2735. }
  2736. #ifdef HARDWARE_BT6710
  2737. else if (strncmp(str, "DIname", 6) == 0) {
  2738. if (val < 1 || val > INPUTS_TOTAL_COUNT) {
  2739. break;
  2740. }
  2741. if (xParameterStringLength > 21) {
  2742. fail = 1;
  2743. break;
  2744. }
  2745. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2746. if (!control_string_en_digit(temp_str, strlen(temp_str))) {
  2747. break;
  2748. }
  2749. SetDINNameStr(temp_str, (val - 1));
  2750. cli_save_config(cli_state);
  2751. fail = 0;
  2752. }
  2753. #endif
  2754. #endif
  2755. #if defined(DALLAS_SENSOR_ENABLE) || defined(AM2301_SENSOR_ENABLE)
  2756. if (strncmp(str, "TS", 2) == 0) {
  2757. if (xParameterStringLength > 1) {
  2758. break;
  2759. }
  2760. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2761. if (!isdigit_int(temp_str[0])) {
  2762. break;
  2763. }
  2764. if (val < 1 || val > MAX_T_SENSORS) {
  2765. break;
  2766. }
  2767. val2 = atoi(temp_str);
  2768. if (val2 < TS_NONE || val2 > TS_AKB) {
  2769. break;
  2770. }
  2771. SetTSlocationStr(temp_str, (val - 1));
  2772. cli_save_config(cli_state);
  2773. fail = 0;
  2774. }
  2775. #endif
  2776. #ifdef DOUTS_ENABLE
  2777. if (strncmp(str, "DO", 2) == 0) {
  2778. if (xParameterStringLength > 1) {
  2779. break;
  2780. }
  2781. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2782. if (!isdigit_int(temp_str[0])) {
  2783. break;
  2784. }
  2785. if (val < 1 || val > 3) {
  2786. break;
  2787. }
  2788. val2 = atoi(temp_str);
  2789. if (val2 < 1 || val2 > 5) {
  2790. break;
  2791. }
  2792. SetROTypeActStr(temp_str, (val - 1));
  2793. cli_save_config(cli_state);
  2794. fail = 0;
  2795. }
  2796. #endif
  2797. }
  2798. break;
  2799. #endif
  2800. default:
  2801. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2802. break;
  2803. }
  2804. }
  2805. if (fail) {
  2806. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2807. }
  2808. xReturn = pdFALSE;
  2809. return xReturn;
  2810. }
  2811. /*
  2812. * Implements the firmware download http command.
  2813. */
  2814. static portBASE_TYPE prvTaskUploadCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2815. const int8_t *pcCommandString )
  2816. {
  2817. static bool start_update = true;
  2818. const int8_t *const pcUploadHeader = ( int8_t * )
  2819. "Контроллер переводится в режим загрузчика\r\n";
  2820. ( void ) pcCommandString;
  2821. ( void ) xWriteBufferLen;
  2822. if (cli_state->user_id != ADMIN) {
  2823. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2824. return pdFALSE;
  2825. }
  2826. if (start_update) {
  2827. start_update = false;
  2828. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcUploadHeader );
  2829. return pdTRUE;
  2830. } else {
  2831. HTTP_StartResetTask(true);
  2832. return pdFALSE;
  2833. }
  2834. }
  2835. /*
  2836. * Implements the ups command.
  2837. */
  2838. static portBASE_TYPE prvTaskUPSCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  2839. {
  2840. int8_t *pcParameterString;
  2841. signed portBASE_TYPE xParameterStringLength, xReturn;
  2842. portBASE_TYPE xParameterNumber = 1;
  2843. char str[110];
  2844. int32_t val = 0;
  2845. float val_float = 0;
  2846. int8_t res = 0;
  2847. uint8_t i;
  2848. ( void ) pcCommandString;
  2849. ( void ) xWriteBufferLen;
  2850. configASSERT( pcWriteBuffer );
  2851. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2852. if (cli_state->user_id != ADMIN) {
  2853. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2854. return pdFALSE;
  2855. }
  2856. /* Obtain the parameter string. */
  2857. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2858. (
  2859. pcCommandString, /* The command string itself. */
  2860. xParameterNumber, /* Return the next parameter. */
  2861. &xParameterStringLength /* Store the parameter string length. */
  2862. );
  2863. for (i = 0; i < ARG_UPS_ALL; i ++) {
  2864. if ( strncmp( ( const char * ) pcParameterString, ups_args_list[i], strlen(ups_args_list[i]) ) == 0
  2865. && xParameterStringLength == strlen(ups_args_list[i])) {
  2866. break;
  2867. }
  2868. }
  2869. xParameterNumber ++;
  2870. /* Obtain the parameter string. */
  2871. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2872. (
  2873. pcCommandString, /* The command string itself. */
  2874. xParameterNumber, /* Return the next parameter. */
  2875. &xParameterStringLength /* Store the parameter string length. */
  2876. );
  2877. memset(str, 0, sizeof(str));
  2878. if (xParameterStringLength > 3) {
  2879. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2880. return pdFALSE;
  2881. }
  2882. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2883. switch (i) {
  2884. case ARG_UPS_BATTEST:
  2885. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  2886. if (!isdigit_int(str[j])) {
  2887. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2888. return pdFALSE;
  2889. }
  2890. }
  2891. val = atoi(str);
  2892. if (val == 0) {
  2893. res = ups_metac_service_pdu(ups_cancel_test);
  2894. set_act_source(CLI_ACT);
  2895. if (res == 1) {
  2896. log_event_data(LOG_TEST_UPS, "Администратор (Останов)");
  2897. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Останов теста\" принята ИБП!\r\n");
  2898. } else {
  2899. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Останов теста\" отклонена ИБП!\r\n");
  2900. }
  2901. } else if (val > 0 && val < 100) {
  2902. TimeParam = val;
  2903. res = ups_metac_service_pdu(ups_test_time);
  2904. if (res == 1) {
  2905. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2906. } else {
  2907. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2908. }
  2909. } else if (val == 100) {
  2910. res = ups_metac_service_pdu(ups_test_10sec);
  2911. if (res == 1) {
  2912. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2913. } else {
  2914. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2915. }
  2916. } else if (val == 999) {
  2917. res = ups_metac_service_pdu(ups_test_low_bat);
  2918. if (res == 1) {
  2919. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2920. } else {
  2921. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2922. }
  2923. } else {
  2924. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2925. }
  2926. break;
  2927. case ARG_UPS_SHUTDOWN:
  2928. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  2929. if (!isfloatdigit(str[j])) {
  2930. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2931. return pdFALSE;
  2932. }
  2933. }
  2934. val_float = atof(str);
  2935. if (val_float == 0) {
  2936. res = ups_metac_service_pdu(ups_cancel_shut_down);
  2937. if (res == 1) {
  2938. log_event_data(LOG_SHUTDOWN_UPS, "Администратор (Останов)");
  2939. strcpy( ( char * ) pcWriteBuffer, "\t\t\tВыключение нагрузки ИБП отменено!\r\n");
  2940. } else {
  2941. strcpy( ( char * ) pcWriteBuffer,
  2942. "\t\tВыключение нагрузки ИБП не удалось отменить!\r\n");
  2943. }
  2944. } else if (val_float > 0 && val_float <= 10) {
  2945. TimeParamFloat = val_float;
  2946. res = ups_metac_service_pdu(ups_shutdown);
  2947. if (res == 1) {
  2948. log_event_data(LOG_SHUTDOWN_UPS, "Администратор");
  2949. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП!\r\n");
  2950. } else {
  2951. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП не удалось!\r\n");
  2952. }
  2953. } else {
  2954. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2955. }
  2956. break;
  2957. default:
  2958. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2959. break;
  2960. }
  2961. xReturn = pdFALSE;
  2962. return xReturn;
  2963. }
  2964. #ifdef SYSLOG_ENABLE
  2965. static portBASE_TYPE prvTaskSysLogCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  2966. {
  2967. int8_t *pcParameterString;
  2968. signed portBASE_TYPE xParameterStringLength, xReturn;
  2969. portBASE_TYPE xParameterNumber = 1;
  2970. char str[110];
  2971. char str_temp[110];
  2972. uint8_t len;
  2973. uint8_t i;
  2974. bool enable_old_syslog;
  2975. ( void ) pcCommandString;
  2976. ( void ) xWriteBufferLen;
  2977. configASSERT( pcWriteBuffer );
  2978. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2979. /* Obtain the parameter string. */
  2980. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2981. (
  2982. pcCommandString, /* The command string itself. */
  2983. xParameterNumber, /* Return the next parameter. */
  2984. &xParameterStringLength /* Store the parameter string length. */
  2985. );
  2986. if (pcParameterString == NULL) {
  2987. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2988. return pdFALSE;
  2989. }
  2990. for (i = 0; i < ARG_SYSLOG_ALL; i ++) {
  2991. if ( strncmp( ( const char * ) pcParameterString, syslog_args_list[i], strlen(syslog_args_list[i]) ) == 0
  2992. && xParameterStringLength == strlen(syslog_args_list[i])) {
  2993. break;
  2994. }
  2995. }
  2996. if (cli_state->user_id != ADMIN && i != ARG_SYSLOG_INFO) {
  2997. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2998. return pdFALSE;
  2999. }
  3000. xParameterNumber ++;
  3001. /* Obtain the parameter string. */
  3002. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  3003. (
  3004. pcCommandString, /* The command string itself. */
  3005. xParameterNumber, /* Return the next parameter. */
  3006. &xParameterStringLength /* Store the parameter string length. */
  3007. );
  3008. if (pcParameterString == NULL) {
  3009. switch (i) {
  3010. case ARG_SYSLOG_INFO:
  3011. /* Return the next command help string, before moving the pointer on to
  3012. the next command in the list. */
  3013. syslog_config_param(pcWriteBuffer);
  3014. break;
  3015. case ARG_SYSLOG_ENABLE:
  3016. enable_old_syslog = sSettings.sSyslog.enabled;
  3017. SetSyslogEnable("on");
  3018. if (sSettings.sSyslog.enabled != enable_old_syslog) {
  3019. cli_save_config(cli_state);
  3020. }
  3021. break;
  3022. case ARG_SYSLOG_DISABLE:
  3023. enable_old_syslog = sSettings.sSyslog.enabled;
  3024. SetSyslogEnable("off");
  3025. if (sSettings.sSyslog.enabled != enable_old_syslog) {
  3026. cli_save_config(cli_state);
  3027. }
  3028. break;
  3029. default:
  3030. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3031. break;
  3032. }
  3033. } else {
  3034. memset(str_temp, 0, sizeof(str_temp));
  3035. if (xParameterStringLength > (int32_t)sizeof(str_temp)) {
  3036. xParameterStringLength = sizeof(str_temp) - 1;
  3037. }
  3038. strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
  3039. switch (i) {
  3040. case ARG_SYSLOG_IP:
  3041. if (xParameterStringLength <= 15) {
  3042. if (ipaddr_addr(str_temp) != IPADDR_NONE) {
  3043. GetSyslogServer(str, &len);
  3044. if (strncmp(str_temp, str, strlen(str_temp)) != 0 || strlen(str_temp) != strlen(str)) {
  3045. SetSyslogServer(str_temp);
  3046. cli_save_config(cli_state);
  3047. }
  3048. } else {
  3049. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3050. }
  3051. } else {
  3052. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3053. }
  3054. break;
  3055. case ARG_SYSLOG_PORT:
  3056. if (xParameterStringLength <= 5) {
  3057. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3058. if (!isdigit_int(str_temp[j])) {
  3059. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3060. return pdFALSE;
  3061. }
  3062. }
  3063. int temp = atoi(str_temp);
  3064. if (temp > 0 && temp < 65535) {
  3065. GetSyslogPort(str, &len);
  3066. if (strncmp(str_temp, str, strlen(str_temp)) != 0) {
  3067. SetSyslogPort(str_temp);
  3068. cli_save_config(cli_state);
  3069. }
  3070. } else {
  3071. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3072. }
  3073. } else {
  3074. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3075. }
  3076. break;
  3077. default:
  3078. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3079. break;
  3080. }
  3081. }
  3082. xReturn = pdFALSE;
  3083. return xReturn;
  3084. }
  3085. #endif
  3086. #ifdef RADIUS_SERVER_ENABLE
  3087. static portBASE_TYPE prvTaskRADIUSCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  3088. {
  3089. int8_t *pcParameterString;
  3090. signed portBASE_TYPE xParameterStringLength, xReturn;
  3091. portBASE_TYPE xParameterNumber = 1;
  3092. char str[110];
  3093. char str_temp[110];
  3094. uint8_t len;
  3095. uint8_t i;
  3096. bool enable_old_radius;
  3097. ( void ) pcCommandString;
  3098. ( void ) xWriteBufferLen;
  3099. configASSERT( pcWriteBuffer );
  3100. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  3101. /* Obtain the parameter string. */
  3102. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  3103. (
  3104. pcCommandString, /* The command string itself. */
  3105. xParameterNumber, /* Return the next parameter. */
  3106. &xParameterStringLength /* Store the parameter string length. */
  3107. );
  3108. if (pcParameterString == NULL) {
  3109. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3110. return pdFALSE;
  3111. }
  3112. for (i = 0; i < ARG_RADIUS_ALL; i ++) {
  3113. if ( strncmp( ( const char * ) pcParameterString, radius_args_list[i], strlen(radius_args_list[i]) ) == 0
  3114. && xParameterStringLength == strlen(radius_args_list[i])) {
  3115. break;
  3116. }
  3117. }
  3118. if (cli_state->user_id != ADMIN && i != ARG_RADIUS_INFO) {
  3119. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  3120. return pdFALSE;
  3121. }
  3122. xParameterNumber ++;
  3123. /* Obtain the parameter string. */
  3124. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  3125. (
  3126. pcCommandString, /* The command string itself. */
  3127. xParameterNumber, /* Return the next parameter. */
  3128. &xParameterStringLength /* Store the parameter string length. */
  3129. );
  3130. if (pcParameterString == NULL) {
  3131. switch (i) {
  3132. case ARG_RADIUS_INFO:
  3133. /* Return the next command help string, before moving the pointer on to
  3134. the next command in the list. */
  3135. radius_config_param(pcWriteBuffer);
  3136. break;
  3137. case ARG_RADIUS_ENABLE:
  3138. enable_old_radius = sSettings.sRADIUS.RDSEnable;
  3139. SetRDSEnableStateStr("on");
  3140. if (sSettings.sRADIUS.RDSEnable != enable_old_radius) {
  3141. cli_save_config(cli_state);
  3142. }
  3143. break;
  3144. case ARG_RADIUS_DISABLE:
  3145. enable_old_radius = sSettings.sRADIUS.RDSEnable;
  3146. SetRDSEnableStateStr("off");
  3147. if (sSettings.sRADIUS.RDSEnable != enable_old_radius) {
  3148. cli_save_config(cli_state);
  3149. }
  3150. break;
  3151. default:
  3152. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3153. break;
  3154. }
  3155. } else {
  3156. memset(str_temp, 0, sizeof(str_temp));
  3157. if (xParameterStringLength > (int32_t)sizeof(str_temp)) {
  3158. xParameterStringLength = sizeof(str_temp) - 1;
  3159. }
  3160. strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
  3161. switch (i) {
  3162. case ARG_RADIUS_IP:
  3163. if (xParameterStringLength <= 15) {
  3164. if (ipaddr_addr(str_temp) != IPADDR_NONE) {
  3165. GetRDSIpStr(str, &len);
  3166. if (strncmp(str_temp, str, strlen(str_temp)) != 0 || strlen(str_temp) != strlen(str)) {
  3167. SetRDSIpStr(str_temp);
  3168. cli_save_config(cli_state);
  3169. }
  3170. } else {
  3171. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3172. }
  3173. } else {
  3174. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3175. }
  3176. break;
  3177. case ARG_RADIUS_PORT:
  3178. if (xParameterStringLength <= 5) {
  3179. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3180. if (!isdigit_int(str_temp[j])) {
  3181. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3182. return pdFALSE;
  3183. }
  3184. }
  3185. int temp = atoi(str_temp);
  3186. if (temp > 0 && temp < 65535) {
  3187. GetRDSPortStr(str, &len);
  3188. if (strncmp(str_temp, str, strlen(str_temp)) != 0) {
  3189. SetRDSPortStr(str_temp);
  3190. cli_save_config(cli_state);
  3191. }
  3192. } else {
  3193. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3194. }
  3195. } else {
  3196. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3197. }
  3198. break;
  3199. case ARG_RADIUS_SECRET:
  3200. if (xParameterStringLength <= 17) {
  3201. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3202. if ( str_temp[j] < 33 || str_temp[j] > 127 ) {
  3203. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3204. return pdFALSE;
  3205. }
  3206. }
  3207. GetRDSPasswordkStr(str, &len);
  3208. if (strncmp(str_temp, str, strlen(str_temp)) != 0 || strlen(str_temp) != strlen(str)) {
  3209. SetRDSPasswordkStr(str_temp);
  3210. cli_save_config(cli_state);
  3211. }
  3212. } else {
  3213. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3214. }
  3215. break;
  3216. default:
  3217. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3218. break;
  3219. }
  3220. }
  3221. xReturn = pdFALSE;
  3222. return xReturn;
  3223. }
  3224. #endif
  3225. #ifdef PORTGW_ENABLE
  3226. static portBASE_TYPE prvTaskPGWCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  3227. {
  3228. int8_t *pcParameterString;
  3229. signed portBASE_TYPE xParameterStringLength, xReturn;
  3230. portBASE_TYPE xParameterNumber = 1;
  3231. char str[110];
  3232. char str_temp[110];
  3233. uint8_t len;
  3234. uint8_t i;
  3235. bool enable_old_pgw;
  3236. ( void ) pcCommandString;
  3237. ( void ) xWriteBufferLen;
  3238. configASSERT( pcWriteBuffer );
  3239. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  3240. /* Obtain the parameter string. */
  3241. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  3242. (
  3243. pcCommandString, /* The command string itself. */
  3244. xParameterNumber, /* Return the next parameter. */
  3245. &xParameterStringLength /* Store the parameter string length. */
  3246. );
  3247. if (pcParameterString == NULL) {
  3248. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3249. return pdFALSE;
  3250. }
  3251. for (i = 0; i < ARG_PGW_ALL; i ++) {
  3252. if ( strncmp( ( const char * ) pcParameterString, pgw_args_list[i], strlen(pgw_args_list[i]) ) == 0
  3253. && xParameterStringLength == strlen(pgw_args_list[i])) {
  3254. break;
  3255. }
  3256. }
  3257. if (cli_state->user_id != ADMIN && i != ARG_PGW_INFO) {
  3258. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  3259. return pdFALSE;
  3260. }
  3261. xParameterNumber ++;
  3262. /* Obtain the parameter string. */
  3263. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  3264. (
  3265. pcCommandString, /* The command string itself. */
  3266. xParameterNumber, /* Return the next parameter. */
  3267. &xParameterStringLength /* Store the parameter string length. */
  3268. );
  3269. if (pcParameterString == NULL) {
  3270. switch (i) {
  3271. case ARG_PGW_INFO:
  3272. /* Return the next command help string, before moving the pointer on to
  3273. the next command in the list. */
  3274. pgw_config_param(pcWriteBuffer);
  3275. break;
  3276. case ARG_PGW_ENABLE:
  3277. enable_old_pgw = sSettings.sPortGw.enabled;
  3278. SetPortGwEnabledStr("on");
  3279. if (sSettings.sPortGw.enabled != enable_old_pgw) {
  3280. cli_save_config(cli_state);
  3281. }
  3282. break;
  3283. case ARG_PGW_DISABLE:
  3284. enable_old_pgw = sSettings.sPortGw.enabled;
  3285. SetPortGwEnabledStr("off");
  3286. if (sSettings.sPortGw.enabled != enable_old_pgw) {
  3287. cli_save_config(cli_state);
  3288. }
  3289. break;
  3290. default:
  3291. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3292. break;
  3293. }
  3294. } else {
  3295. memset(str_temp, 0, sizeof(str_temp));
  3296. if (xParameterStringLength > (int32_t)sizeof(str_temp)) {
  3297. xParameterStringLength = sizeof(str_temp) - 1;
  3298. }
  3299. strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
  3300. switch (i) {
  3301. case ARG_PGW_PORT:
  3302. if (xParameterStringLength <= 5) {
  3303. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3304. if (!isdigit_int(str_temp[j])) {
  3305. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3306. return pdFALSE;
  3307. }
  3308. }
  3309. int temp = atoi(str_temp);
  3310. if (temp > 0 && temp < 65535) {
  3311. GetPortGwPortnumStr(str, &len);
  3312. if (strncmp(str_temp, str, strlen(str_temp)) != 0) {
  3313. SetPortGwPortnumStr(str_temp);
  3314. cli_save_config(cli_state);
  3315. }
  3316. } else {
  3317. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3318. }
  3319. } else {
  3320. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3321. }
  3322. break;
  3323. case ARG_PGW_RATE:
  3324. if (xParameterStringLength <= 6) {
  3325. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3326. if (!isdigit_int(str_temp[j])) {
  3327. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3328. return pdFALSE;
  3329. }
  3330. }
  3331. int temp_rate = atoi(str_temp);
  3332. if (temp_rate == 1200 || temp_rate == 2400 || temp_rate == 4800 || temp_rate == 9600
  3333. || temp_rate == 19200 || temp_rate == 38400 || temp_rate == 57600 || temp_rate == 115200) {
  3334. GetPortGwBaudStr(str, &len);
  3335. if (strncmp(str_temp, str, strlen(str_temp)) != 0 || strlen(str_temp) != strlen(str)) {
  3336. SetPortGwBaudStr(str_temp);
  3337. cli_save_config(cli_state);
  3338. }
  3339. } else {
  3340. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3341. }
  3342. } else {
  3343. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3344. }
  3345. break;
  3346. case ARG_PGW_PARITY:
  3347. if (xParameterStringLength == 1) {
  3348. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3349. if (!isdigit_int(str_temp[j])) {
  3350. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3351. return pdFALSE;
  3352. }
  3353. }
  3354. int temp_parity = atoi(str_temp);
  3355. if (temp_parity >= GW_NO_PAR && temp_parity < MAX_PARITY_TYPES) {
  3356. uint32_t parity;
  3357. GetPortGwParityInt(&parity);
  3358. if ((int)parity != temp_parity) {
  3359. SetPortGwParityInt(temp_parity);
  3360. cli_save_config(cli_state);
  3361. }
  3362. } else {
  3363. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3364. }
  3365. } else {
  3366. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3367. }
  3368. break;
  3369. case ARG_PGW_DATALEN:
  3370. case ARG_PGW_STOPBIT:
  3371. if (xParameterStringLength == 1) {
  3372. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3373. if (!isdigit_int(str_temp[j])) {
  3374. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3375. return pdFALSE;
  3376. }
  3377. }
  3378. char limit1, limit2;
  3379. if (i == ARG_PGW_DATALEN) {
  3380. GetPortGwDatabitsStr(str, &len);
  3381. limit1 = 0x37;
  3382. limit2 = 0x38;
  3383. } else {
  3384. GetPortGwStopbitsStr(str, &len);
  3385. limit1 = 0x31;
  3386. limit2 = 0x32;
  3387. }
  3388. if (str_temp[0] == limit1 || str_temp[0] == limit2) {
  3389. if (str[0] != str_temp[0]) {
  3390. if (i == ARG_PGW_DATALEN) {
  3391. SetPortGwDatabitsStr(str_temp);
  3392. } else {
  3393. SetPortGwStopbitsStr(str_temp);
  3394. }
  3395. cli_save_config(cli_state);
  3396. }
  3397. } else {
  3398. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3399. }
  3400. } else {
  3401. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3402. }
  3403. break;
  3404. default:
  3405. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3406. break;
  3407. }
  3408. }
  3409. xReturn = pdFALSE;
  3410. return xReturn;
  3411. }
  3412. #endif
  3413. #ifdef FTP_ENABLE
  3414. #pragma GCC diagnostic error "-Wall"
  3415. #pragma GCC diagnostic error "-Wextra"
  3416. static portBASE_TYPE prvTaskFTPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString)
  3417. {
  3418. int8_t *pcParameterString;
  3419. unsigned portBASE_TYPE xParameterStringLength;
  3420. signed portBASE_TYPE xReturn;
  3421. portBASE_TYPE xParameterNumber = 1;
  3422. char str[110];
  3423. uint8_t i;
  3424. ( void ) xWriteBufferLen;
  3425. configASSERT( pcWriteBuffer );
  3426. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  3427. if (cli_state->user_id != ADMIN && i != ARG_FTP_info) {
  3428. strncpy((char *)pcWriteBuffer, (const char *)pcPermissionDenied, strlen((char *)pcPermissionDenied));
  3429. return pdFALSE;
  3430. }
  3431. /* Obtain the subcommand */
  3432. pcParameterString = (int8_t *)FreeRTOS_CLIGetParameter
  3433. (
  3434. pcCommandString, /* The command string itself. */
  3435. xParameterNumber, /* Return the next parameter. */
  3436. &xParameterStringLength /* Store the parameter string length. */
  3437. );
  3438. for (i = 0; i < ARG_FTP_ALL; i++) {
  3439. if (strncmp((const char *)pcParameterString, ftp_args_list[i], strlen(ftp_args_list[i])) == 0
  3440. && xParameterStringLength == strlen(ftp_args_list[i])) {
  3441. break;
  3442. }
  3443. }
  3444. xParameterNumber++;
  3445. /* Obtain the subcommand parameter */
  3446. pcParameterString = (int8_t *)FreeRTOS_CLIGetParameter
  3447. (
  3448. pcCommandString, /* The command string itself. */
  3449. xParameterNumber, /* Return the next parameter. */
  3450. &xParameterStringLength /* Store the parameter string length. */
  3451. );
  3452. memset(str, 0, sizeof(str));
  3453. strncat(str, (const char *) pcParameterString, xParameterStringLength);
  3454. switch (i) {
  3455. case ARG_FTP_info:
  3456. ;
  3457. snprintf((char *)pcWriteBuffer, configCOMMAND_INT_MAX_OUTPUT_SIZE, "\r\n"
  3458. "*******************Настройки FTP********************\r\n"
  3459. "Адрес сервера: \t\t%s\r\n"
  3460. "Порт: \t\t\t%u\r\n"
  3461. "Путь к файлу: \t\t%s\r\n"
  3462. "Имя пользователя: \t%s\r\n"
  3463. "Пароль: \t\t%s\r\n",
  3464. ipaddr_ntoa(&sSettings.sFTPUpdate.server_ip),
  3465. sSettings.sFTPUpdate.server_port,
  3466. sSettings.sFTPUpdate.remote_path,
  3467. sSettings.sFTPUpdate.user,
  3468. sSettings.sFTPUpdate.pass);
  3469. break;
  3470. case ARG_FTP_server_ip:
  3471. ;
  3472. ip_addr_t server_ip_old = sSettings.sFTPUpdate.server_ip;
  3473. if (!ipaddr_aton(str, &sSettings.sFTPUpdate.server_ip)) {
  3474. strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
  3475. return pdFALSE;
  3476. }
  3477. if (!ip_addr_cmp(&sSettings.sFTPUpdate.server_ip, &server_ip_old)) {
  3478. cli_save_config(cli_state);
  3479. }
  3480. break;
  3481. case ARG_FTP_server_port:
  3482. ;
  3483. u16_t server_port_old = sSettings.sFTPUpdate.server_port;
  3484. int temp = atoi(str);
  3485. if (temp < 1 || temp > 65535) {
  3486. strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
  3487. return pdFALSE;
  3488. } else {
  3489. sSettings.sFTPUpdate.server_port = temp;
  3490. if (sSettings.sFTPUpdate.server_port != server_port_old) {
  3491. cli_save_config(cli_state);
  3492. }
  3493. }
  3494. break;
  3495. case ARG_FTP_remote_path: {
  3496. if (xParameterStringLength < 1 || xParameterStringLength >= sizeof(sSettings.sFTPUpdate.remote_path)) {
  3497. strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
  3498. return pdFALSE;
  3499. } else {
  3500. strcpy(&sSettings.sFTPUpdate.remote_path, str);
  3501. cli_save_config(cli_state);
  3502. }
  3503. break; }
  3504. case ARG_FTP_user: {
  3505. if (xParameterStringLength < 1 || xParameterStringLength >= sizeof(sSettings.sFTPUpdate.user)) {
  3506. strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
  3507. return pdFALSE;
  3508. } else {
  3509. strcpy(&sSettings.sFTPUpdate.user, str);
  3510. cli_save_config(cli_state);
  3511. }
  3512. break; }
  3513. case ARG_FTP_pass: {
  3514. if (xParameterStringLength < 1 || xParameterStringLength >= sizeof(sSettings.sFTPUpdate.pass)) {
  3515. strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
  3516. return pdFALSE;
  3517. } else {
  3518. strcpy(&sSettings.sFTPUpdate.pass, str);
  3519. cli_save_config(cli_state);
  3520. }
  3521. break; }
  3522. case ARG_FTP_run: {
  3523. static bool ran = false;
  3524. if (ran) {
  3525. vTaskDelay(500 / portTICK_PERIOD_MS);
  3526. char *status = get_ftp_progress();
  3527. unsigned statuslen = strlen(status);
  3528. sprintf((char *)pcWriteBuffer, "Статус обновления по FTP: %s%%\r\n", status);
  3529. // stop polling when we get an error message or 100%
  3530. bool resume = statuslen < 3;
  3531. if (!resume) {
  3532. ran = false;
  3533. }
  3534. return resume;
  3535. } else {
  3536. // run!
  3537. ftpcfg.settings = &sSettings.sFTPUpdate;
  3538. start_ftp_client(&ftpcfg);
  3539. strcpy((char *)pcWriteBuffer, "Начато обновление ПО по FTP\r\n");
  3540. ran = true;
  3541. // tell the caller to poll us for more data
  3542. return pdTRUE;
  3543. }
  3544. break; }
  3545. default:
  3546. strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
  3547. break;
  3548. }
  3549. xReturn = pdFALSE;
  3550. return xReturn;
  3551. }
  3552. #endif // FTP_ENABLE
  3553. /*
  3554. * Implements the ups serial command.
  3555. */
  3556. static portBASE_TYPE prvSetUPSserialCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  3557. int8_t *pcParameterString;
  3558. signed portBASE_TYPE xParameterStringLength;
  3559. portBASE_TYPE xParameterNumber = 1;
  3560. char str[10];
  3561. ( void ) pcCommandString;
  3562. ( void ) xWriteBufferLen;
  3563. configASSERT( pcWriteBuffer );
  3564. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  3565. /* Obtain the parameter string. */
  3566. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  3567. (
  3568. pcCommandString, /* The command string itself. */
  3569. xParameterNumber, /* Return the next parameter. */
  3570. &xParameterStringLength /* Store the parameter string length. */
  3571. );
  3572. if(pcParameterString == NULL){
  3573. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3574. return pdFALSE;
  3575. }
  3576. if( strncmp( ( const char * ) pcParameterString, "SvUsn", xParameterStringLength ) != 0 ){
  3577. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3578. return pdFALSE;
  3579. }
  3580. xParameterNumber ++;
  3581. /* Obtain the parameter string. */
  3582. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  3583. (
  3584. pcCommandString, /* The command string itself. */
  3585. xParameterNumber, /* Return the next parameter. */
  3586. &xParameterStringLength /* Store the parameter string length. */
  3587. );
  3588. memset(str, 0, sizeof(str));
  3589. if(xParameterStringLength != 8){
  3590. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3591. return pdFALSE;
  3592. }
  3593. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  3594. for(uint8_t j = 0; j < xParameterStringLength; j++){
  3595. if(!isdigit_int(str[j])){
  3596. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3597. return pdFALSE;
  3598. }
  3599. }
  3600. SetUPSSerialStr(str);
  3601. cli_save_config(cli_state);
  3602. return pdFALSE;
  3603. }
  3604. /*-----------------------------------------------------------*/