CLI_Commands.c 164 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873
  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. #ifdef DALLAS_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. "parity",
  554. "odd",
  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\t0 - нечетный\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
  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. case PARAM_CONFIG_TIME:
  2347. time_config_param(pcWriteBuffer);
  2348. break;
  2349. }
  2350. config_menu ++;
  2351. if (config_menu == PARAM_CONFIG_ALL) {
  2352. config_menu = 0;
  2353. return pdFALSE;
  2354. } else {
  2355. return pdTRUE;
  2356. }
  2357. break;
  2358. default:
  2359. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2360. break;
  2361. }
  2362. return pdFALSE;
  2363. }
  2364. if (i == ARG_CONFIG_LOAD) {
  2365. memset(str, 0, sizeof(str));
  2366. xParameterStringLength = strlen(( const char * ) pcParameterString);
  2367. if (xParameterStringLength > (int32_t)sizeof(str)) {
  2368. xParameterStringLength = sizeof(str) - 1;
  2369. }
  2370. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2371. if (xParameterStringLength < 13) {
  2372. if (strncmp(str, "default", 7) == 0) {
  2373. SNMP_SendUserTrap(DEVICE_RESTORED);
  2374. log_event_data(LOG_SYSTEM_DEFCONFIG, "Администратор");
  2375. vTaskDelay(500);
  2376. SETTINGS_SetPartDefault();
  2377. cli_save_config(cli_state);
  2378. syslog_str(SYSLOG_INFORMATIONAL, "Сброс настроек (Администратор)");
  2379. strcpy( ( char * ) pcWriteBuffer,
  2380. "\t\tНастройки сброшены к настройкам по умолчанию!\r\n");
  2381. } else {
  2382. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2383. }
  2384. } else {
  2385. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2386. }
  2387. } else {
  2388. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2389. }
  2390. xReturn = pdFALSE;
  2391. return xReturn;
  2392. }
  2393. /*
  2394. * Implements the config command.
  2395. */
  2396. static portBASE_TYPE prvTaskNetConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2397. const int8_t *pcCommandString )
  2398. {
  2399. int8_t *pcParameterString;
  2400. portBASE_TYPE xParameterNumber = 1;
  2401. signed portBASE_TYPE xParameterStringLength;
  2402. uint8_t i;
  2403. static start = 0;
  2404. ( void ) pcCommandString;
  2405. ( void ) xWriteBufferLen;
  2406. configASSERT( pcWriteBuffer );
  2407. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2408. /* Obtain the parameter string. */
  2409. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2410. (
  2411. pcCommandString, /* The command string itself. */
  2412. xParameterNumber, /* Return the next parameter. */
  2413. &xParameterStringLength /* Store the parameter string length. */
  2414. );
  2415. for (i = 0; i < ARG_NETCONFIG_ALL; i ++) {
  2416. if ( strncmp( ( const char * ) pcParameterString, netconfig_args_list[i], strlen(netconfig_args_list[i]) ) == 0
  2417. && xParameterStringLength == strlen(netconfig_args_list[i])) {
  2418. break;
  2419. }
  2420. }
  2421. if (cli_state->user_id != ADMIN) {
  2422. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2423. return pdFALSE;
  2424. }
  2425. switch (i) {
  2426. case ARG_NETCONFIG_APPLY:
  2427. if (!start) {
  2428. /* Если параметры WEB изменились выставляем флаг, сохраняем настройки и перезагружаемся */
  2429. if (GetStateWebReinit() == true) {
  2430. start = 1;
  2431. SetWebReinitFlag(true);
  2432. cli_save_config(cli_state);
  2433. strcpy( ( char * ) pcWriteBuffer,
  2434. "\t\tНастройки сохранены! Контроллер будет перезагружен\r\n\tПосле перезагрузки подтвердите изменения сетевых настроек\r\n");
  2435. return pdTRUE;
  2436. }
  2437. } else {
  2438. start = 0;
  2439. vTaskDelay(1010);
  2440. Reboot(CLI_ACT);
  2441. }
  2442. break;
  2443. case ARG_NETCONFIG_CONFIRM:
  2444. SetWebReinitFlag(false);
  2445. SetConfirmWebParamsFlag();
  2446. strcpy( ( char * ) pcWriteBuffer, "\t\tСетевые настройки подтверждены!\r\n");
  2447. break;
  2448. default:
  2449. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2450. break;
  2451. }
  2452. return pdFALSE;
  2453. }
  2454. /*
  2455. * Implements the history command.
  2456. */
  2457. static portBASE_TYPE prvTaskHistoryCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2458. const int8_t *pcCommandString )
  2459. {
  2460. int8_t *pcParameterString;
  2461. signed portBASE_TYPE xParameterStringLength, xReturn;
  2462. portBASE_TYPE xParameterNumber = 1;
  2463. char str[110];
  2464. uint8_t i;
  2465. static int16_t num_page = 0;
  2466. static int16_t num_page_temp = 1;
  2467. static bool start = true;
  2468. const int8_t *const pcUPShistoryTableHeader = ( int8_t * )
  2469. "\r\n***********Журнал событий ИБП***********\r\n";
  2470. const int8_t *const pcControllerHistoryTableHeader = ( int8_t * )
  2471. "\r\n***********Журнал событий Контроллера***********\r\n";
  2472. ( void ) pcCommandString;
  2473. ( void ) xWriteBufferLen;
  2474. configASSERT( pcWriteBuffer );
  2475. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2476. /* Obtain the parameter string. */
  2477. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2478. (
  2479. pcCommandString, /* The command string itself. */
  2480. xParameterNumber, /* Return the next parameter. */
  2481. &xParameterStringLength /* Store the parameter string length. */
  2482. );
  2483. if (pcParameterString == NULL) {
  2484. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2485. return pdFALSE;
  2486. }
  2487. if ( strncmp( ( const char * ) pcParameterString, "show", xParameterStringLength ) != 0 ) {
  2488. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2489. return pdFALSE;
  2490. }
  2491. xParameterNumber ++;
  2492. /* Obtain the parameter string. */
  2493. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2494. (
  2495. pcCommandString, /* The command string itself. */
  2496. xParameterNumber, /* Return the next parameter. */
  2497. &xParameterStringLength /* Store the parameter string length. */
  2498. );
  2499. for (i = 0; i < ARG_HISTORY_ALL; i ++) {
  2500. if ( strncmp( ( const char * ) pcParameterString, history_args_list[i], strlen(history_args_list[i]) ) == 0
  2501. && xParameterStringLength == strlen(history_args_list[i])) {
  2502. break;
  2503. }
  2504. }
  2505. xParameterNumber ++;
  2506. /* Obtain the parameter string. */
  2507. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2508. (
  2509. pcCommandString, /* The command string itself. */
  2510. xParameterNumber, /* Return the next parameter. */
  2511. &xParameterStringLength /* Store the parameter string length. */
  2512. );
  2513. memset(str, 0, sizeof(str));
  2514. if (xParameterStringLength > 5) {
  2515. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2516. return pdFALSE;
  2517. }
  2518. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2519. if (num_page == 0) {
  2520. num_page = atoi(str);
  2521. if (num_page <= 0) {
  2522. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2523. return pdFALSE;
  2524. }
  2525. }
  2526. switch (i) {
  2527. case ARG_HISTORY_EVENTS:
  2528. if (start) {
  2529. start = false;
  2530. /* Return the next command help string, before moving the pointer on to
  2531. the next command in the list. */
  2532. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcControllerHistoryTableHeader,
  2533. strlen( ( char * ) pcControllerHistoryTableHeader ) );
  2534. memset(str, 0, sizeof(str));
  2535. strcat(( char * ) pcWriteBuffer, "\r\n");
  2536. sprintf(str, "Количество страниц журнала: %d\r\n", History_GetPageCount());
  2537. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  2538. strcat(( char * ) pcWriteBuffer, "\r\n");
  2539. if (num_page > History_GetPageCount()) {
  2540. num_page = History_GetPageCount();
  2541. }
  2542. }
  2543. History_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  2544. num_page --;
  2545. num_page_temp ++;
  2546. if (num_page == 0) {
  2547. num_page = 0;
  2548. num_page_temp = 1;
  2549. start = true;
  2550. xReturn = pdFALSE;
  2551. } else {
  2552. xReturn = pdTRUE;
  2553. }
  2554. break;
  2555. case ARG_HISTORY_UPS:
  2556. if (start) {
  2557. start = false;
  2558. /* Return the next command help string, before moving the pointer on to
  2559. the next command in the list. */
  2560. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcUPShistoryTableHeader,
  2561. strlen( ( char * ) pcUPShistoryTableHeader ) );
  2562. memset(str, 0, sizeof(str));
  2563. sprintf(str, "Количество страниц журнала: %d\r\n", LOG_GetPageCount());
  2564. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  2565. if (num_page > LOG_GetPageCount()) {
  2566. num_page = LOG_GetPageCount();
  2567. }
  2568. }
  2569. LOG_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  2570. num_page --;
  2571. num_page_temp ++;
  2572. if (num_page == 0) {
  2573. num_page = 0;
  2574. num_page_temp = 1;
  2575. start = true;
  2576. xReturn = pdFALSE;
  2577. } else {
  2578. xReturn = pdTRUE;
  2579. }
  2580. break;
  2581. default:
  2582. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2583. xReturn = pdFALSE;
  2584. break;
  2585. }
  2586. return xReturn;
  2587. }
  2588. /*
  2589. * Implements the sensor info command.
  2590. */
  2591. static portBASE_TYPE prvTaskSensorCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2592. const int8_t *pcCommandString )
  2593. {
  2594. int8_t *pcParameterString;
  2595. signed portBASE_TYPE xParameterStringLength, xReturn;
  2596. portBASE_TYPE xParameterNumber = 1;
  2597. uint8_t i;
  2598. char str[10];
  2599. char temp_str[10];
  2600. int32_t val = 0, val2 = 0;
  2601. uint8_t fail = 0;
  2602. static uint8_t config_menu = 0;
  2603. uint8_t MAX_CONFIG_PARAM = 0;
  2604. #ifdef DINS_ENABLE || DOUTS_ENABLE || DALLAS_SENSOR_ENABLE
  2605. MAX_CONFIG_PARAM = 3;
  2606. #else
  2607. MAX_CONFIG_PARAM = 2;
  2608. #endif
  2609. const int8_t *const pcSensorTableHeader = ( int8_t * )
  2610. "\r\n*********Параметры Контроллера*********\r\n";
  2611. ( void ) pcCommandString;
  2612. ( void ) xWriteBufferLen;
  2613. configASSERT( pcWriteBuffer );
  2614. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2615. /* Obtain the parameter string. */
  2616. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2617. (
  2618. pcCommandString, /* The command string itself. */
  2619. xParameterNumber, /* Return the next parameter. */
  2620. &xParameterStringLength /* Store the parameter string length. */
  2621. );
  2622. if (pcParameterString == NULL) {
  2623. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2624. return pdFALSE;
  2625. }
  2626. for (i = 0; i < ARG_SENSOR_ALL; i ++) {
  2627. if ( strncmp( ( const char * ) pcParameterString, sensor_args_list[i], strlen(sensor_args_list[i]) ) == 0
  2628. && xParameterStringLength == strlen(sensor_args_list[i])) {
  2629. break;
  2630. }
  2631. }
  2632. xParameterNumber ++;
  2633. /* Obtain the parameter string. */
  2634. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2635. (
  2636. pcCommandString, /* The command string itself. */
  2637. xParameterNumber, /* Return the next parameter. */
  2638. &xParameterStringLength /* Store the parameter string length. */
  2639. );
  2640. if (pcParameterString == NULL) {
  2641. if (i == ARG_SENSOR_INFO) {
  2642. switch (config_menu) {
  2643. case 0:
  2644. /* Return the next command help string, before moving the pointer on to
  2645. the next command in the list. */
  2646. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSensorTableHeader, strlen( ( char * ) pcSensorTableHeader ) );
  2647. ups_sensor_param(pcWriteBuffer);
  2648. break;
  2649. case 1:
  2650. ups_sensor_akb_param(pcWriteBuffer);
  2651. break;
  2652. #ifdef DINS_ENABLE || DOUTS_ENABLE || DALLAS_SENSOR_ENABLE
  2653. case 2:
  2654. inouts_sensor_param(pcWriteBuffer);
  2655. break;
  2656. #endif
  2657. }
  2658. config_menu ++;
  2659. if (config_menu == MAX_CONFIG_PARAM) {
  2660. config_menu = 0;
  2661. return pdFALSE;
  2662. } else {
  2663. return pdTRUE;
  2664. }
  2665. } else {
  2666. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2667. }
  2668. } else {
  2669. switch (i) {
  2670. #ifdef DINS_ENABLE || DOUTS_ENABLE || DALLAS_SENSOR_ENABLE
  2671. case ARG_SENSOR_SETUP:
  2672. if (cli_state->user_id != ADMIN) {
  2673. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2674. return pdFALSE;
  2675. }
  2676. memset(str, 0, sizeof(str));
  2677. if (xParameterStringLength > (int32_t)sizeof(str)) {
  2678. xParameterStringLength = sizeof(str) - 1;
  2679. }
  2680. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2681. if (xParameterStringLength < 3) {
  2682. xParameterNumber ++;
  2683. /* Obtain the parameter string. */
  2684. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2685. (
  2686. pcCommandString, /* The command string itself. */
  2687. xParameterNumber, /* Return the next parameter. */
  2688. &xParameterStringLength /* Store the parameter string length. */
  2689. );
  2690. memset(temp_str, 0, sizeof(str));
  2691. if (xParameterStringLength > 1) {
  2692. fail = 1;
  2693. break;
  2694. }
  2695. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2696. if (!isdigit_int(temp_str[0])) {
  2697. fail = 1;
  2698. break;
  2699. }
  2700. val = atoi(temp_str);
  2701. xParameterNumber ++;
  2702. /* Obtain the parameter string. */
  2703. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2704. (
  2705. pcCommandString, /* The command string itself. */
  2706. xParameterNumber, /* Return the next parameter. */
  2707. &xParameterStringLength /* Store the parameter string length. */
  2708. );
  2709. memset(temp_str, 0, sizeof(str));
  2710. if (xParameterStringLength > 1) {
  2711. fail = 1;
  2712. break;
  2713. }
  2714. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2715. if (!isdigit_int(temp_str[0])) {
  2716. fail = 1;
  2717. break;
  2718. }
  2719. fail = 1;
  2720. #ifdef DINS_ENABLE
  2721. if (strncmp(str, "DI", 2) == 0) {
  2722. if (val < 0 || val > INPUTS_TOTAL_COUNT) {
  2723. break;
  2724. }
  2725. val2 = atoi(temp_str);
  2726. if (val2 < 0 || val2 > 1) {
  2727. break;
  2728. }
  2729. SetDINTypeActStr(temp_str, (val - 1));
  2730. cli_save_config(cli_state);
  2731. fail = 0;
  2732. }
  2733. #ifdef HARDWARE_BT6710
  2734. else if (strncmp(str, "DIname", 6) == 0) {
  2735. if (val < 0 || val > INPUTS_TOTAL_COUNT) {
  2736. break;
  2737. }
  2738. val2 = strlen(temp_str);
  2739. if (val2 < 0 || val2 >= 21) {
  2740. break;
  2741. }
  2742. SetDINNameStr(temp_str, (val - 1));
  2743. cli_save_config(cli_state);
  2744. fail = 0;
  2745. }
  2746. #endif
  2747. #endif
  2748. #ifdef DALLAS_SENSOR_ENABLE
  2749. if (strncmp(str, "TS", 2) == 0) {
  2750. if (val < 1 || val > (MAX_T_SENSORS + 1)) {
  2751. break;
  2752. }
  2753. val2 = atoi(temp_str);
  2754. if (val2 < TS_NONE || val2 > TS_AKB) {
  2755. break;
  2756. }
  2757. SetTSlocationStr(temp_str, (val - 1));
  2758. cli_save_config(cli_state);
  2759. fail = 0;
  2760. }
  2761. #endif
  2762. #ifdef DOUTS_ENABLE
  2763. if (strncmp(str, "DO", 2) == 0) {
  2764. if (val < 1 || val > 3) {
  2765. break;
  2766. }
  2767. val2 = atoi(temp_str);
  2768. if (val2 < 1 || val2 > 5) {
  2769. break;
  2770. }
  2771. SetROTypeActStr(temp_str, (val - 1));
  2772. cli_save_config(cli_state);
  2773. fail = 0;
  2774. }
  2775. #endif
  2776. }
  2777. break;
  2778. #endif
  2779. default:
  2780. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2781. break;
  2782. }
  2783. }
  2784. if (fail) {
  2785. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2786. }
  2787. xReturn = pdFALSE;
  2788. return xReturn;
  2789. }
  2790. /*
  2791. * Implements the firmware download http command.
  2792. */
  2793. static portBASE_TYPE prvTaskUploadCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2794. const int8_t *pcCommandString )
  2795. {
  2796. static bool start_update = true;
  2797. const int8_t *const pcUploadHeader = ( int8_t * )
  2798. "Контроллер переводится в режим загрузчика\r\n";
  2799. ( void ) pcCommandString;
  2800. ( void ) xWriteBufferLen;
  2801. if (cli_state->user_id != ADMIN) {
  2802. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2803. return pdFALSE;
  2804. }
  2805. if (start_update) {
  2806. start_update = false;
  2807. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcUploadHeader );
  2808. return pdTRUE;
  2809. } else {
  2810. HTTP_StartResetTask(true);
  2811. return pdFALSE;
  2812. }
  2813. }
  2814. /*
  2815. * Implements the ups command.
  2816. */
  2817. static portBASE_TYPE prvTaskUPSCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  2818. {
  2819. int8_t *pcParameterString;
  2820. signed portBASE_TYPE xParameterStringLength, xReturn;
  2821. portBASE_TYPE xParameterNumber = 1;
  2822. char str[110];
  2823. int32_t val = 0;
  2824. float val_float = 0;
  2825. int8_t res = 0;
  2826. uint8_t i;
  2827. ( void ) pcCommandString;
  2828. ( void ) xWriteBufferLen;
  2829. configASSERT( pcWriteBuffer );
  2830. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2831. if (cli_state->user_id != ADMIN) {
  2832. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2833. return pdFALSE;
  2834. }
  2835. /* Obtain the parameter string. */
  2836. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2837. (
  2838. pcCommandString, /* The command string itself. */
  2839. xParameterNumber, /* Return the next parameter. */
  2840. &xParameterStringLength /* Store the parameter string length. */
  2841. );
  2842. for (i = 0; i < ARG_UPS_ALL; i ++) {
  2843. if ( strncmp( ( const char * ) pcParameterString, ups_args_list[i], strlen(ups_args_list[i]) ) == 0
  2844. && xParameterStringLength == strlen(ups_args_list[i])) {
  2845. break;
  2846. }
  2847. }
  2848. xParameterNumber ++;
  2849. /* Obtain the parameter string. */
  2850. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2851. (
  2852. pcCommandString, /* The command string itself. */
  2853. xParameterNumber, /* Return the next parameter. */
  2854. &xParameterStringLength /* Store the parameter string length. */
  2855. );
  2856. memset(str, 0, sizeof(str));
  2857. if (xParameterStringLength > 3) {
  2858. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2859. return pdFALSE;
  2860. }
  2861. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2862. switch (i) {
  2863. case ARG_UPS_BATTEST:
  2864. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  2865. if (!isdigit_int(str[j])) {
  2866. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2867. return pdFALSE;
  2868. }
  2869. }
  2870. val = atoi(str);
  2871. if (val == 0) {
  2872. res = ups_metac_service_pdu(ups_cancel_test);
  2873. set_act_source(CLI_ACT);
  2874. if (res == 1) {
  2875. log_event_data(LOG_TEST_UPS, "Администратор (Останов)");
  2876. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Останов теста\" принята ИБП!\r\n");
  2877. } else {
  2878. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Останов теста\" отклонена ИБП!\r\n");
  2879. }
  2880. } else if (val > 0 && val < 100) {
  2881. TimeParam = val;
  2882. res = ups_metac_service_pdu(ups_test_time);
  2883. if (res == 1) {
  2884. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2885. } else {
  2886. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2887. }
  2888. } else if (val == 100) {
  2889. res = ups_metac_service_pdu(ups_test_10sec);
  2890. if (res == 1) {
  2891. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2892. } else {
  2893. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2894. }
  2895. } else if (val == 999) {
  2896. res = ups_metac_service_pdu(ups_test_low_bat);
  2897. if (res == 1) {
  2898. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2899. } else {
  2900. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2901. }
  2902. } else {
  2903. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2904. }
  2905. break;
  2906. case ARG_UPS_SHUTDOWN:
  2907. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  2908. if (!isfloatdigit(str[j])) {
  2909. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2910. return pdFALSE;
  2911. }
  2912. }
  2913. val_float = atof(str);
  2914. if (val_float == 0) {
  2915. res = ups_metac_service_pdu(ups_cancel_shut_down);
  2916. if (res == 1) {
  2917. log_event_data(LOG_SHUTDOWN_UPS, "Администратор (Останов)");
  2918. strcpy( ( char * ) pcWriteBuffer, "\t\t\tВыключение нагрузки ИБП отменено!\r\n");
  2919. } else {
  2920. strcpy( ( char * ) pcWriteBuffer,
  2921. "\t\tВыключение нагрузки ИБП не удалось отменить!\r\n");
  2922. }
  2923. } else if (val_float > 0 && val_float <= 10) {
  2924. TimeParamFloat = val_float;
  2925. res = ups_metac_service_pdu(ups_shutdown);
  2926. if (res == 1) {
  2927. log_event_data(LOG_SHUTDOWN_UPS, "Администратор");
  2928. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП!\r\n");
  2929. } else {
  2930. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП не удалось!\r\n");
  2931. }
  2932. } else {
  2933. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2934. }
  2935. break;
  2936. default:
  2937. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2938. break;
  2939. }
  2940. xReturn = pdFALSE;
  2941. return xReturn;
  2942. }
  2943. #ifdef SYSLOG_ENABLE
  2944. static portBASE_TYPE prvTaskSysLogCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  2945. {
  2946. int8_t *pcParameterString;
  2947. signed portBASE_TYPE xParameterStringLength, xReturn;
  2948. portBASE_TYPE xParameterNumber = 1;
  2949. char str[110];
  2950. char str_temp[110];
  2951. uint8_t len;
  2952. uint8_t i;
  2953. bool enable_old_syslog;
  2954. ( void ) pcCommandString;
  2955. ( void ) xWriteBufferLen;
  2956. configASSERT( pcWriteBuffer );
  2957. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2958. /* Obtain the parameter string. */
  2959. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2960. (
  2961. pcCommandString, /* The command string itself. */
  2962. xParameterNumber, /* Return the next parameter. */
  2963. &xParameterStringLength /* Store the parameter string length. */
  2964. );
  2965. if (pcParameterString == NULL) {
  2966. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2967. return pdFALSE;
  2968. }
  2969. for (i = 0; i < ARG_SYSLOG_ALL; i ++) {
  2970. if ( strncmp( ( const char * ) pcParameterString, syslog_args_list[i], strlen(syslog_args_list[i]) ) == 0
  2971. && xParameterStringLength == strlen(syslog_args_list[i])) {
  2972. break;
  2973. }
  2974. }
  2975. if (cli_state->user_id != ADMIN && i != ARG_SYSLOG_INFO) {
  2976. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2977. return pdFALSE;
  2978. }
  2979. xParameterNumber ++;
  2980. /* Obtain the parameter string. */
  2981. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2982. (
  2983. pcCommandString, /* The command string itself. */
  2984. xParameterNumber, /* Return the next parameter. */
  2985. &xParameterStringLength /* Store the parameter string length. */
  2986. );
  2987. if (pcParameterString == NULL) {
  2988. switch (i) {
  2989. case ARG_SYSLOG_INFO:
  2990. /* Return the next command help string, before moving the pointer on to
  2991. the next command in the list. */
  2992. syslog_config_param(pcWriteBuffer);
  2993. break;
  2994. case ARG_SYSLOG_ENABLE:
  2995. enable_old_syslog = sSettings.sSyslog.enabled;
  2996. SetSyslogEnable("on");
  2997. if (sSettings.sSyslog.enabled != enable_old_syslog) {
  2998. cli_save_config(cli_state);
  2999. }
  3000. break;
  3001. case ARG_SYSLOG_DISABLE:
  3002. enable_old_syslog = sSettings.sSyslog.enabled;
  3003. SetSyslogEnable("off");
  3004. if (sSettings.sSyslog.enabled != enable_old_syslog) {
  3005. cli_save_config(cli_state);
  3006. }
  3007. break;
  3008. default:
  3009. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3010. break;
  3011. }
  3012. } else {
  3013. memset(str_temp, 0, sizeof(str_temp));
  3014. if (xParameterStringLength > (int32_t)sizeof(str_temp)) {
  3015. xParameterStringLength = sizeof(str_temp) - 1;
  3016. }
  3017. strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
  3018. switch (i) {
  3019. case ARG_SYSLOG_IP:
  3020. if (xParameterStringLength <= 15) {
  3021. if (ipaddr_addr(str_temp) != IPADDR_NONE) {
  3022. GetSyslogServer(str, &len);
  3023. if (strncmp(str_temp, str, strlen(str_temp)) != 0 || strlen(str_temp) != strlen(str)) {
  3024. SetSyslogServer(str_temp);
  3025. cli_save_config(cli_state);
  3026. }
  3027. } else {
  3028. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3029. }
  3030. } else {
  3031. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3032. }
  3033. break;
  3034. case ARG_SYSLOG_PORT:
  3035. if (xParameterStringLength <= 5) {
  3036. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3037. if (!isdigit_int(str_temp[j])) {
  3038. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3039. return pdFALSE;
  3040. }
  3041. }
  3042. int temp = atoi(str_temp);
  3043. if (temp > 0 && temp < 65535) {
  3044. GetSyslogPort(str, &len);
  3045. if (strncmp(str_temp, str, strlen(str_temp)) != 0) {
  3046. SetSyslogPort(str_temp);
  3047. cli_save_config(cli_state);
  3048. }
  3049. } else {
  3050. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3051. }
  3052. } else {
  3053. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3054. }
  3055. break;
  3056. default:
  3057. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3058. break;
  3059. }
  3060. }
  3061. xReturn = pdFALSE;
  3062. return xReturn;
  3063. }
  3064. #endif
  3065. #ifdef RADIUS_SERVER_ENABLE
  3066. static portBASE_TYPE prvTaskRADIUSCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  3067. {
  3068. int8_t *pcParameterString;
  3069. signed portBASE_TYPE xParameterStringLength, xReturn;
  3070. portBASE_TYPE xParameterNumber = 1;
  3071. char str[110];
  3072. char str_temp[110];
  3073. uint8_t len;
  3074. uint8_t i;
  3075. bool enable_old_radius;
  3076. ( void ) pcCommandString;
  3077. ( void ) xWriteBufferLen;
  3078. configASSERT( pcWriteBuffer );
  3079. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  3080. /* Obtain the parameter string. */
  3081. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  3082. (
  3083. pcCommandString, /* The command string itself. */
  3084. xParameterNumber, /* Return the next parameter. */
  3085. &xParameterStringLength /* Store the parameter string length. */
  3086. );
  3087. if (pcParameterString == NULL) {
  3088. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3089. return pdFALSE;
  3090. }
  3091. for (i = 0; i < ARG_RADIUS_ALL; i ++) {
  3092. if ( strncmp( ( const char * ) pcParameterString, radius_args_list[i], strlen(radius_args_list[i]) ) == 0
  3093. && xParameterStringLength == strlen(radius_args_list[i])) {
  3094. break;
  3095. }
  3096. }
  3097. if (cli_state->user_id != ADMIN && i != ARG_RADIUS_INFO) {
  3098. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  3099. return pdFALSE;
  3100. }
  3101. xParameterNumber ++;
  3102. /* Obtain the parameter string. */
  3103. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  3104. (
  3105. pcCommandString, /* The command string itself. */
  3106. xParameterNumber, /* Return the next parameter. */
  3107. &xParameterStringLength /* Store the parameter string length. */
  3108. );
  3109. if (pcParameterString == NULL) {
  3110. switch (i) {
  3111. case ARG_RADIUS_INFO:
  3112. /* Return the next command help string, before moving the pointer on to
  3113. the next command in the list. */
  3114. radius_config_param(pcWriteBuffer);
  3115. break;
  3116. case ARG_RADIUS_ENABLE:
  3117. enable_old_radius = sSettings.sRADIUS.RDSEnable;
  3118. SetRDSEnableStateStr("on");
  3119. if (sSettings.sRADIUS.RDSEnable != enable_old_radius) {
  3120. cli_save_config(cli_state);
  3121. }
  3122. break;
  3123. case ARG_RADIUS_DISABLE:
  3124. enable_old_radius = sSettings.sRADIUS.RDSEnable;
  3125. SetRDSEnableStateStr("off");
  3126. if (sSettings.sRADIUS.RDSEnable != enable_old_radius) {
  3127. cli_save_config(cli_state);
  3128. }
  3129. break;
  3130. default:
  3131. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3132. break;
  3133. }
  3134. } else {
  3135. memset(str_temp, 0, sizeof(str_temp));
  3136. if (xParameterStringLength > (int32_t)sizeof(str_temp)) {
  3137. xParameterStringLength = sizeof(str_temp) - 1;
  3138. }
  3139. strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
  3140. switch (i) {
  3141. case ARG_RADIUS_IP:
  3142. if (xParameterStringLength <= 15) {
  3143. if (ipaddr_addr(str_temp) != IPADDR_NONE) {
  3144. GetRDSIpStr(str, &len);
  3145. if (strncmp(str_temp, str, strlen(str_temp)) != 0 || strlen(str_temp) != strlen(str)) {
  3146. SetRDSIpStr(str_temp);
  3147. cli_save_config(cli_state);
  3148. }
  3149. } else {
  3150. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3151. }
  3152. } else {
  3153. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3154. }
  3155. break;
  3156. case ARG_RADIUS_PORT:
  3157. if (xParameterStringLength <= 5) {
  3158. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3159. if (!isdigit_int(str_temp[j])) {
  3160. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3161. return pdFALSE;
  3162. }
  3163. }
  3164. int temp = atoi(str_temp);
  3165. if (temp > 0 && temp < 65535) {
  3166. GetRDSPortStr(str, &len);
  3167. if (strncmp(str_temp, str, strlen(str_temp)) != 0) {
  3168. SetRDSPortStr(str_temp);
  3169. cli_save_config(cli_state);
  3170. }
  3171. } else {
  3172. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3173. }
  3174. } else {
  3175. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3176. }
  3177. break;
  3178. case ARG_RADIUS_SECRET:
  3179. if (xParameterStringLength <= 17) {
  3180. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3181. if ( str_temp[j] < 33 || str_temp[j] > 127 ) {
  3182. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3183. return pdFALSE;
  3184. }
  3185. }
  3186. GetRDSPasswordkStr(str, &len);
  3187. if (strncmp(str_temp, str, strlen(str_temp)) != 0 || strlen(str_temp) != strlen(str)) {
  3188. SetRDSPasswordkStr(str_temp);
  3189. cli_save_config(cli_state);
  3190. }
  3191. } else {
  3192. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3193. }
  3194. break;
  3195. default:
  3196. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3197. break;
  3198. }
  3199. }
  3200. xReturn = pdFALSE;
  3201. return xReturn;
  3202. }
  3203. #endif
  3204. #ifdef PORTGW_ENABLE
  3205. static portBASE_TYPE prvTaskPGWCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  3206. {
  3207. int8_t *pcParameterString;
  3208. signed portBASE_TYPE xParameterStringLength, xReturn;
  3209. portBASE_TYPE xParameterNumber = 1;
  3210. char str[110];
  3211. char str_temp[110];
  3212. uint8_t len;
  3213. uint8_t i;
  3214. bool enable_old_pgw;
  3215. ( void ) pcCommandString;
  3216. ( void ) xWriteBufferLen;
  3217. configASSERT( pcWriteBuffer );
  3218. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  3219. /* Obtain the parameter string. */
  3220. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  3221. (
  3222. pcCommandString, /* The command string itself. */
  3223. xParameterNumber, /* Return the next parameter. */
  3224. &xParameterStringLength /* Store the parameter string length. */
  3225. );
  3226. if (pcParameterString == NULL) {
  3227. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3228. return pdFALSE;
  3229. }
  3230. for (i = 0; i < ARG_PGW_ALL; i ++) {
  3231. if ( strncmp( ( const char * ) pcParameterString, pgw_args_list[i], strlen(pgw_args_list[i]) ) == 0
  3232. && xParameterStringLength == strlen(pgw_args_list[i])) {
  3233. break;
  3234. }
  3235. }
  3236. if (cli_state->user_id != ADMIN && i != ARG_PGW_INFO) {
  3237. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  3238. return pdFALSE;
  3239. }
  3240. xParameterNumber ++;
  3241. /* Obtain the parameter string. */
  3242. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  3243. (
  3244. pcCommandString, /* The command string itself. */
  3245. xParameterNumber, /* Return the next parameter. */
  3246. &xParameterStringLength /* Store the parameter string length. */
  3247. );
  3248. if (pcParameterString == NULL) {
  3249. switch (i) {
  3250. case ARG_PGW_INFO:
  3251. /* Return the next command help string, before moving the pointer on to
  3252. the next command in the list. */
  3253. pgw_config_param(pcWriteBuffer);
  3254. break;
  3255. case ARG_PGW_ENABLE:
  3256. enable_old_pgw = sSettings.sPortGw.enabled;
  3257. SetPortGwEnabledStr("on");
  3258. if (sSettings.sPortGw.enabled != enable_old_pgw) {
  3259. cli_save_config(cli_state);
  3260. }
  3261. break;
  3262. case ARG_PGW_DISABLE:
  3263. enable_old_pgw = sSettings.sPortGw.enabled;
  3264. SetPortGwEnabledStr("off");
  3265. if (sSettings.sPortGw.enabled != enable_old_pgw) {
  3266. cli_save_config(cli_state);
  3267. }
  3268. break;
  3269. default:
  3270. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3271. break;
  3272. }
  3273. } else {
  3274. memset(str_temp, 0, sizeof(str_temp));
  3275. if (xParameterStringLength > (int32_t)sizeof(str_temp)) {
  3276. xParameterStringLength = sizeof(str_temp) - 1;
  3277. }
  3278. strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
  3279. switch (i) {
  3280. case ARG_PGW_PORT:
  3281. if (xParameterStringLength <= 5) {
  3282. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3283. if (!isdigit_int(str_temp[j])) {
  3284. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3285. return pdFALSE;
  3286. }
  3287. }
  3288. int temp = atoi(str_temp);
  3289. if (temp > 0 && temp < 65535) {
  3290. GetPortGwPortnumStr(str, &len);
  3291. if (strncmp(str_temp, str, strlen(str_temp)) != 0) {
  3292. SetPortGwPortnumStr(str_temp);
  3293. cli_save_config(cli_state);
  3294. }
  3295. } else {
  3296. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3297. }
  3298. } else {
  3299. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3300. }
  3301. break;
  3302. case ARG_PGW_RATE:
  3303. if (xParameterStringLength <= 6) {
  3304. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3305. if (!isdigit_int(str_temp[j])) {
  3306. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3307. return pdFALSE;
  3308. }
  3309. }
  3310. int temp_rate = atoi(str_temp);
  3311. if (temp_rate == 1200 || temp_rate == 2400 || temp_rate == 4800 || temp_rate == 9600
  3312. || temp_rate == 19200 || temp_rate == 38400 || temp_rate == 57600 || temp_rate == 115200) {
  3313. GetPortGwBaudStr(str, &len);
  3314. if (strncmp(str_temp, str, strlen(str_temp)) != 0 || strlen(str_temp) != strlen(str)) {
  3315. SetPortGwBaudStr(str_temp);
  3316. cli_save_config(cli_state);
  3317. }
  3318. } else {
  3319. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3320. }
  3321. } else {
  3322. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3323. }
  3324. break;
  3325. case ARG_PGW_PARITY:
  3326. if (xParameterStringLength == 1) {
  3327. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3328. if (!isdigit_int(str_temp[j])) {
  3329. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3330. return pdFALSE;
  3331. }
  3332. }
  3333. int temp_parity = atoi(str_temp);
  3334. if (temp_parity >= GW_NO_PAR || temp_parity < MAX_PARITY_TYPES) {
  3335. uint32_t parity;
  3336. GetPortGwParityInt(&parity);
  3337. if ((int)parity != temp_parity) {
  3338. SetPortGwParityInt(temp_parity);
  3339. cli_save_config(cli_state);
  3340. }
  3341. } else {
  3342. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3343. }
  3344. } else {
  3345. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3346. }
  3347. break;
  3348. case ARG_PGW_DATALEN:
  3349. case ARG_PGW_STOPBIT:
  3350. if (xParameterStringLength == 1) {
  3351. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  3352. if (!isdigit_int(str_temp[j])) {
  3353. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3354. return pdFALSE;
  3355. }
  3356. }
  3357. char limit1, limit2;
  3358. if (i == ARG_PGW_DATALEN) {
  3359. GetPortGwDatabitsStr(str, &len);
  3360. limit1 = 0x37;
  3361. limit2 = 0x38;
  3362. } else {
  3363. GetPortGwStopbitsStr(str, &len);
  3364. limit1 = 0x31;
  3365. limit2 = 0x32;
  3366. }
  3367. if (str_temp[0] == limit1 || str_temp[0] == limit2) {
  3368. if (str[0] != str_temp[0]) {
  3369. if (i == ARG_PGW_DATALEN) {
  3370. SetPortGwDatabitsStr(str_temp);
  3371. } else {
  3372. SetPortGwStopbitsStr(str_temp);
  3373. }
  3374. cli_save_config(cli_state);
  3375. }
  3376. } else {
  3377. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3378. }
  3379. } else {
  3380. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3381. }
  3382. break;
  3383. default:
  3384. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3385. break;
  3386. }
  3387. }
  3388. xReturn = pdFALSE;
  3389. return xReturn;
  3390. }
  3391. #endif
  3392. #ifdef FTP_ENABLE
  3393. #pragma GCC diagnostic error "-Wall"
  3394. #pragma GCC diagnostic error "-Wextra"
  3395. static portBASE_TYPE prvTaskFTPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString)
  3396. {
  3397. int8_t *pcParameterString;
  3398. unsigned portBASE_TYPE xParameterStringLength;
  3399. signed portBASE_TYPE xReturn;
  3400. portBASE_TYPE xParameterNumber = 1;
  3401. char str[110];
  3402. uint8_t i;
  3403. ( void ) xWriteBufferLen;
  3404. configASSERT( pcWriteBuffer );
  3405. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  3406. if (cli_state->user_id != ADMIN && i != ARG_FTP_info) {
  3407. strncpy((char *)pcWriteBuffer, (const char *)pcPermissionDenied, strlen((char *)pcPermissionDenied));
  3408. return pdFALSE;
  3409. }
  3410. /* Obtain the subcommand */
  3411. pcParameterString = (int8_t *)FreeRTOS_CLIGetParameter
  3412. (
  3413. pcCommandString, /* The command string itself. */
  3414. xParameterNumber, /* Return the next parameter. */
  3415. &xParameterStringLength /* Store the parameter string length. */
  3416. );
  3417. for (i = 0; i < ARG_FTP_ALL; i++) {
  3418. if (strncmp((const char *)pcParameterString, ftp_args_list[i], strlen(ftp_args_list[i])) == 0
  3419. && xParameterStringLength == strlen(ftp_args_list[i])) {
  3420. break;
  3421. }
  3422. }
  3423. xParameterNumber++;
  3424. /* Obtain the subcommand parameter */
  3425. pcParameterString = (int8_t *)FreeRTOS_CLIGetParameter
  3426. (
  3427. pcCommandString, /* The command string itself. */
  3428. xParameterNumber, /* Return the next parameter. */
  3429. &xParameterStringLength /* Store the parameter string length. */
  3430. );
  3431. memset(str, 0, sizeof(str));
  3432. strncat(str, (const char *) pcParameterString, xParameterStringLength);
  3433. switch (i) {
  3434. case ARG_FTP_info:
  3435. ;
  3436. snprintf((char *)pcWriteBuffer, configCOMMAND_INT_MAX_OUTPUT_SIZE, "\r\n"
  3437. "*******************Настройки FTP********************\r\n"
  3438. "Адрес сервера: \t\t%s\r\n"
  3439. "Порт: \t\t\t%u\r\n"
  3440. "Путь к файлу: \t\t%s\r\n"
  3441. "Имя пользователя: \t%s\r\n"
  3442. "Пароль: \t\t%s\r\n",
  3443. ipaddr_ntoa(&sSettings.sFTPUpdate.server_ip),
  3444. sSettings.sFTPUpdate.server_port,
  3445. sSettings.sFTPUpdate.remote_path,
  3446. sSettings.sFTPUpdate.user,
  3447. sSettings.sFTPUpdate.pass);
  3448. break;
  3449. case ARG_FTP_server_ip:
  3450. ;
  3451. ip_addr_t server_ip_old = sSettings.sFTPUpdate.server_ip;
  3452. if (!ipaddr_aton(str, &sSettings.sFTPUpdate.server_ip)) {
  3453. strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
  3454. return pdFALSE;
  3455. }
  3456. if (!ip_addr_cmp(&sSettings.sFTPUpdate.server_ip, &server_ip_old)) {
  3457. cli_save_config(cli_state);
  3458. }
  3459. break;
  3460. case ARG_FTP_server_port:
  3461. ;
  3462. u16_t server_port_old = sSettings.sFTPUpdate.server_port;
  3463. int temp = atoi(str);
  3464. if (temp < 1 || temp > 65535) {
  3465. strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
  3466. return pdFALSE;
  3467. } else {
  3468. sSettings.sFTPUpdate.server_port = temp;
  3469. if (sSettings.sFTPUpdate.server_port != server_port_old) {
  3470. cli_save_config(cli_state);
  3471. }
  3472. }
  3473. break;
  3474. case ARG_FTP_remote_path: {
  3475. if (xParameterStringLength < 1 || xParameterStringLength >= sizeof(sSettings.sFTPUpdate.remote_path)) {
  3476. strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
  3477. return pdFALSE;
  3478. } else {
  3479. strcpy(&sSettings.sFTPUpdate.remote_path, str);
  3480. cli_save_config(cli_state);
  3481. }
  3482. break; }
  3483. case ARG_FTP_user: {
  3484. if (xParameterStringLength < 1 || xParameterStringLength >= sizeof(sSettings.sFTPUpdate.user)) {
  3485. strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
  3486. return pdFALSE;
  3487. } else {
  3488. strcpy(&sSettings.sFTPUpdate.user, str);
  3489. cli_save_config(cli_state);
  3490. }
  3491. break; }
  3492. case ARG_FTP_pass: {
  3493. if (xParameterStringLength < 1 || xParameterStringLength >= sizeof(sSettings.sFTPUpdate.pass)) {
  3494. strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
  3495. return pdFALSE;
  3496. } else {
  3497. strcpy(&sSettings.sFTPUpdate.pass, str);
  3498. cli_save_config(cli_state);
  3499. }
  3500. break; }
  3501. case ARG_FTP_run: {
  3502. static bool ran = false;
  3503. if (ran) {
  3504. vTaskDelay(500 / portTICK_PERIOD_MS);
  3505. char *status = get_ftp_progress();
  3506. unsigned statuslen = strlen(status);
  3507. sprintf((char *)pcWriteBuffer, "Статус обновления по FTP: %s%%\r\n", status);
  3508. // stop polling when we get an error message or 100%
  3509. bool resume = statuslen < 3;
  3510. if (!resume) {
  3511. ran = false;
  3512. }
  3513. return resume;
  3514. } else {
  3515. // run!
  3516. ftpcfg.settings = &sSettings.sFTPUpdate;
  3517. start_ftp_client(&ftpcfg);
  3518. strcpy((char *)pcWriteBuffer, "Начато обновление ПО по FTP\r\n");
  3519. ran = true;
  3520. // tell the caller to poll us for more data
  3521. return pdTRUE;
  3522. }
  3523. break; }
  3524. default:
  3525. strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
  3526. break;
  3527. }
  3528. xReturn = pdFALSE;
  3529. return xReturn;
  3530. }
  3531. #endif // FTP_ENABLE
  3532. /*
  3533. * Implements the ups serial command.
  3534. */
  3535. static portBASE_TYPE prvSetUPSserialCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  3536. int8_t *pcParameterString;
  3537. signed portBASE_TYPE xParameterStringLength;
  3538. portBASE_TYPE xParameterNumber = 1;
  3539. char str[10];
  3540. ( void ) pcCommandString;
  3541. ( void ) xWriteBufferLen;
  3542. configASSERT( pcWriteBuffer );
  3543. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  3544. /* Obtain the parameter string. */
  3545. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  3546. (
  3547. pcCommandString, /* The command string itself. */
  3548. xParameterNumber, /* Return the next parameter. */
  3549. &xParameterStringLength /* Store the parameter string length. */
  3550. );
  3551. if(pcParameterString == NULL){
  3552. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3553. return pdFALSE;
  3554. }
  3555. if( strncmp( ( const char * ) pcParameterString, "SvUsn", xParameterStringLength ) != 0 ){
  3556. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3557. return pdFALSE;
  3558. }
  3559. xParameterNumber ++;
  3560. /* Obtain the parameter string. */
  3561. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  3562. (
  3563. pcCommandString, /* The command string itself. */
  3564. xParameterNumber, /* Return the next parameter. */
  3565. &xParameterStringLength /* Store the parameter string length. */
  3566. );
  3567. memset(str, 0, sizeof(str));
  3568. if(xParameterStringLength != 8){
  3569. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3570. return pdFALSE;
  3571. }
  3572. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  3573. for(uint8_t j = 0; j < xParameterStringLength; j++){
  3574. if(!isdigit_int(str[j])){
  3575. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  3576. return pdFALSE;
  3577. }
  3578. }
  3579. SetUPSSerialStr(str);
  3580. cli_save_config(cli_state);
  3581. return pdFALSE;
  3582. }
  3583. /*-----------------------------------------------------------*/