CLI_Commands.c 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819
  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. const int8_t *const pcInvalidCommand = ( int8_t * )
  38. "Неправильно введены параметры команды. Введите \"help\" для просмотра списка поддерживаемых команд.\r\n\r\n";
  39. const int8_t *const pcPermissionDenied = ( int8_t * ) "Отказ в доступе!\r\n\r\n";
  40. const int8_t *const pcSystymeDenied = ( int8_t * )
  41. "Ручной ввод времени не доступен!\r\n\r\n";
  42. const char *info_args_list[] = {
  43. "name",
  44. "address",
  45. "owner",
  46. "comments",
  47. };
  48. const char *ups_args_list[] = {
  49. "battest",
  50. "shutdown",
  51. };
  52. const char *systime_args_list[] = {
  53. "date",
  54. "time",
  55. };
  56. const char *network_args_list[] = {
  57. "info",
  58. "dhcp",
  59. "ip",
  60. "gw",
  61. "mask",
  62. };
  63. const char *snmp_args_list[] = {
  64. "info",
  65. "server",
  66. "community",
  67. };
  68. const char *akb_args_list[] = {
  69. "info",
  70. "voltcellmin",
  71. "voltcellmax",
  72. #ifdef HARDWARE_BT6709
  73. "capacity",
  74. "voltakb",
  75. "lifetime",
  76. "dataset",
  77. "upspower",
  78. #endif
  79. };
  80. const char *type_alarm_args_list[] = {
  81. "info",
  82. "temp",
  83. "load",
  84. "vout",
  85. };
  86. const char *alarm_args_list[] = {
  87. "low",
  88. "high",
  89. "hist",
  90. };
  91. const char *notification_args_list[] = {
  92. "info",
  93. "set",
  94. };
  95. const char *whitelist_args_list[] = {
  96. "info",
  97. "range",
  98. "reset",
  99. };
  100. const char *ntp_args_list[] = {
  101. "ENA",
  102. "DIS",
  103. "info",
  104. "set",
  105. };
  106. const char *config_args_list[] = {
  107. "info",
  108. "load",
  109. };
  110. const char *netconfig_args_list[] = {
  111. "apply",
  112. "confirm",
  113. };
  114. const char *history_args_list[] = {
  115. "EVENTS",
  116. "UPS",
  117. };
  118. const char *sensor_args_list[] = {
  119. "info",
  120. "setup",
  121. };
  122. const char *user_args_list[] = {
  123. "passwd",
  124. };
  125. /**
  126. * @brief Общая структура настроек
  127. */
  128. extern SETTINGS_t sSettings;
  129. /*
  130. * Implements the controller's information command.
  131. */
  132. static portBASE_TYPE prvTaskInfoCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  133. /*
  134. * Implements the reboot command.
  135. */
  136. static portBASE_TYPE prvTaskRebootCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  137. const int8_t *pcCommandString );
  138. /*
  139. * Implements the systime command.
  140. */
  141. static portBASE_TYPE prvTaskSystimeCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  142. const int8_t *pcCommandString );
  143. /*
  144. * Implements the ntp command.
  145. */
  146. static portBASE_TYPE prvTaskNTPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  147. /*
  148. * Implements the network command.
  149. */
  150. static portBASE_TYPE prvTaskNetworkCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  151. const int8_t *pcCommandString );
  152. /*
  153. * Implements the snmp command.
  154. */
  155. static portBASE_TYPE prvTaskSNMPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  156. /*
  157. * Implements the AKB command.
  158. */
  159. static portBASE_TYPE prvTaskAKBCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  160. /*
  161. * Implements the alarm command.
  162. */
  163. static portBASE_TYPE prvTaskAlarmCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  164. const int8_t *pcCommandString );
  165. #ifdef NOTIFICATION_CONTROL_ENABLE
  166. /*
  167. * Implements the notification command.
  168. */
  169. static portBASE_TYPE prvTaskNotificationCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  170. const int8_t *pcCommandString );
  171. #endif
  172. #ifdef WHITELIST_ENABLE
  173. /*
  174. * Implements the whitelist command.
  175. */
  176. static portBASE_TYPE prvTaskWhiteListCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  177. const int8_t *pcCommandString );
  178. #endif
  179. /*
  180. * Implements the change password command.
  181. */
  182. static portBASE_TYPE prvTaskUserCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  183. /*
  184. * Implements the config command.
  185. */
  186. static portBASE_TYPE prvTaskConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  187. const int8_t *pcCommandString );
  188. /*
  189. * Implements the netconfig command.
  190. */
  191. static portBASE_TYPE prvTaskNetConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  192. const int8_t *pcCommandString );
  193. /*
  194. * Implements the history command.
  195. */
  196. static portBASE_TYPE prvTaskHistoryCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  197. const int8_t *pcCommandString );
  198. /*
  199. * Implements the sensor info command.
  200. */
  201. static portBASE_TYPE prvTaskSensorCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  202. const int8_t *pcCommandString );
  203. /*
  204. * Implements the firmware download http command.
  205. */
  206. static portBASE_TYPE prvTaskUploadCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  207. const int8_t *pcCommandString );
  208. /*
  209. * Implements the ups command.
  210. */
  211. static portBASE_TYPE prvTaskUPSCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  212. /* Structure that defines the "info" command line command. This
  213. generates a table that shows how much run time each task has */
  214. static const CLI_Command_Definition_t prvInfoCommandDefinition = {
  215. ( const int8_t *const ) "info", /* The command string to type. */
  216. ( const int8_t *const ) "\tinfo: вывод информации о контроллере\r\n"
  217. "\tinfo name <name>: установка поля \"название устройства\"\r\n"
  218. "\tinfo address <adrr>: установка поля \"адрес расположения контролируемого объекта\"\r\n"
  219. "\tinfo owner <owner>: установка поля \"организация (собственник)\"\r\n"
  220. "\tinfo comments <comment>: установка поля \"комментарии\"\r\n",
  221. prvTaskInfoCommand, /* The function to run. */
  222. -1 /* The user can enter any number of commands. */
  223. };
  224. /* Structure that defines the "reboot" command line command. This
  225. generates a table that shows how much run time each task has */
  226. static const CLI_Command_Definition_t prvRebootCommandDefinition = {
  227. ( const int8_t *const ) "reboot", /* The command string to type. */
  228. ( const int8_t *const ) "\treboot: перезагрузка Контроллера\r\n",
  229. prvTaskRebootCommand, /* The function to run. */
  230. 0 /* No parameters are expected. */
  231. };
  232. /* Structure that defines the "systime" command line command. This
  233. generates a table that shows how much run time each task has */
  234. static const CLI_Command_Definition_t prvSystimeCommandDefinition = {
  235. ( const int8_t *const ) "systime", /* The command string to type. */
  236. ( const int8_t *const ) "\tsystime: вывод системного времени\r\n"
  237. "\tsystime date <YYYY-MM-DD>: установка даты\r\n"
  238. "\tsystime time <HH:MM>: установка времени\r\n",
  239. prvTaskSystimeCommand, /* The function to run. */
  240. -1 /* The user can enter any number of commands. */
  241. };
  242. /* Structure that defines the "ntp" command line command. This
  243. generates a table that shows how much run time each task has */
  244. static const CLI_Command_Definition_t prvNTPCommandDefinition = {
  245. ( const int8_t *const ) "ntp", /* The command string to type. */
  246. ( const int8_t *const ) "\tntp ENA|DIS: разрешение/запрет синхронизации времени\r\n"
  247. "\tntp set IP <A.B.C.D>: установка сервера NTP\r\n"
  248. "\tntp info: вывод информации о сервере NTP\r\n"
  249. "\tntp set gmt <SIGN><NUM>: установка часового пояса\r\n",
  250. prvTaskNTPCommand, /* The function to run. */
  251. -1 /* The user can enter any number of commands. */
  252. };
  253. /* Structure that defines the "network" command line command. This
  254. generates a table that shows how much run time each task has */
  255. static const CLI_Command_Definition_t prvNetworkCommandDefinition = {
  256. ( const int8_t *const ) "network", /* The command string to type. */
  257. ( const int8_t *const ) "\tnetwork info вывод информации о текущих сетевых настройках:\r\n"
  258. "\tnetwork dhcp ENA|DIS: разрешение/запрет получения IP по DHCP\r\n"
  259. "\tnetwork ip <A.B.C.D>: установка статического IP\r\n"
  260. "\tnetwork gw <A.B.C.D>: установка шлюза\r\n"
  261. "\tnetwork mask <A.B.C.D>: установка маски подсети\r\n",
  262. prvTaskNetworkCommand, /* The function to run. */
  263. -1 /* The user can enter any number of commands. */
  264. };
  265. /* Structure that defines the "snmp" command line command. This
  266. generates a table that shows how much run time each task has */
  267. static const CLI_Command_Definition_t prvSNMPCommandDefinition = {
  268. ( const int8_t *const ) "snmp", /* The command string to type. */
  269. ( const int8_t *const ) "\tsnmp info: вывод информации о текущих SNMP настройках\r\n"
  270. "\tsnmp server <NUM> <A.B.C.D>: установка сервера SNMP\r\n"
  271. "\tsnmp community read <read>: установка Read community\r\n"
  272. "\tsnmp community write <write>: установка Write community\r\n",
  273. prvTaskSNMPCommand, /* The function to run. */
  274. -1 /* The user can enter any number of commands. */
  275. };
  276. /* Structure that defines the "akb" command line command. This
  277. generates a table that shows how much run time each task has */
  278. static const CLI_Command_Definition_t prvAKBCommandDefinition = {
  279. ( const int8_t *const ) "akb", /* The command string to type. */
  280. ( const int8_t *const ) "\takb info: вывод информации о параметрах АКБ\r\n"
  281. "\takb voltcellmin <value>: ввод минимального напряжения на ячейки АКБ (В)\r\n"
  282. "\takb voltcellmax <value>: ввод максимального напряжения на ячейки АКБ (В)\r\n"
  283. #ifdef HARDWARE_BT6709
  284. "\takb capacity <value>: ввод ёмкости АКБ (Ач)\r\n"
  285. "\takb voltakb <value>: ввод номинального напряжения АКБ (В)\r\n"
  286. "\takb lifetime <value>: ввод срока службы АКБ (лет)\r\n"
  287. "\takb dataset <YYYY-MM-DD>: ввод даты установки АКБ\r\n"
  288. "\takb upspower <value>: ввод полной мощности ИБП (ВА)\r\n"
  289. #endif
  290. ,
  291. prvTaskAKBCommand, /* The function to run. */
  292. -1 /* The user can enter any number of commands. */
  293. };
  294. /* Structure that defines the "alarm" command line command. This
  295. generates a table that shows how much run time each task has */
  296. static const CLI_Command_Definition_t prvAlarmCommandDefinition = {
  297. ( const int8_t *const ) "alarm", /* The command string to type. */
  298. ( const int8_t *const ) "\talarm info: вывод информации о параметрах АКБ\r\n"
  299. "\talarm temp low <value>: ввод нижней границы аварии по температуре (С)\r\n"
  300. "\talarm temp high <value>: ввод верxней границы аварии по температуре (С)\r\n"
  301. "\talarm temp hist <value>: ввод гистерезиса аварии по температуре (С)\r\n"
  302. "\talarm load high <value>: ввод верхней границы аварии по нагрузке (%)\r\n"
  303. "\talarm load hist <value>: ввод гистерезиса аварии по нагрузке (%)\r\n"
  304. "\talarm vout low <value>: ввод нижней границы аварии по вых. напряжению (В)\r\n"
  305. "\talarm vout high <value>: ввод верxней границы аварии по вых. напряжению (В)\r\n"
  306. "\talarm vout hist <value>: ввод гистерезиса аварии по вых. напряжению (В)\r\n",
  307. prvTaskAlarmCommand, /* The function to run. */
  308. -1 /* The user can enter any number of commands. */
  309. };
  310. #ifdef NOTIFICATION_CONTROL_ENABLE
  311. /* Structure that defines the "notification" command line command. This
  312. generates a table that shows how much run time each task has */
  313. static const CLI_Command_Definition_t prvNotificationCommandDefinition = {
  314. ( const int8_t *const ) "notification", /* The command string to type. */
  315. ( const int8_t *const ) "\tnotification info: вывод списка уведомлений\r\n"
  316. "\tnotification set <NUM> ENA|DIS: вкл/выкл уведомления\r\n",
  317. prvTaskNotificationCommand, /* The function to run. */
  318. -1 /* The user can enter any number of commands. */
  319. };
  320. #endif
  321. #ifdef WHITELIST_ENABLE
  322. /* Structure that defines the "whitelist" command line command. This
  323. generates a table that shows how much run time each task has */
  324. static const CLI_Command_Definition_t prvWhiteListCommandDefinition = {
  325. ( const int8_t *const ) "whitelist", /* The command string to type. */
  326. ( const int8_t *const ) "\twhitelist info: вывод информации о текущем белом списке IP адресов контроллера\r\n"
  327. "\twhitelist range <NUM> <A.B.C.D/E>: установка диапазона IP адресов\r\n"
  328. "\twhitelist reset <NUM>: сброс диапазона IP адресов\r\n",
  329. prvTaskWhiteListCommand, /* The function to run. */
  330. -1 /* The user can enter any number of commands. */
  331. };
  332. #endif
  333. /* Structure that defines the "user" command line command. This
  334. generates a table that shows how much run time each task has */
  335. static const CLI_Command_Definition_t prvUserCommandDefinition = {
  336. ( const int8_t *const ) "user", /* The command string to type. */
  337. ( const int8_t *const ) "\tuser passwd <name>: установка пароля для пользователя <name>\r\n",
  338. prvTaskUserCommand, /* The function to run. */
  339. 2 /* Two parameters are expected, which can take any value. */
  340. };
  341. /* Structure that defines the "config" command line command. This
  342. generates a table that shows how much run time each task has */
  343. static const CLI_Command_Definition_t prvConfigCommandDefinition = {
  344. ( const int8_t *const ) "config", /* The command string to type. */
  345. ( const int8_t *const ) "\tconfig info: вывод информации о состоянии конфигураций\r\n"
  346. "\tconfig load default: загрузка конфигурации по умолчанию\r\n",
  347. prvTaskConfigCommand, /* The function to run. */
  348. -1 /* Two parameters are expected, which can take any value. */
  349. };
  350. /* Structure that defines the "config" command line command. This
  351. generates a table that shows how much run time each task has */
  352. static const CLI_Command_Definition_t prvNetConfigCommandDefinition = {
  353. ( const int8_t *const ) "netconfig", /* The command string to type. */
  354. ( const int8_t *const ) "\tnetconfig apply: применение конфигурации сетевых настроек\r\n"
  355. "\tnetconfig confirm: подтверждение конфигурации сетевых настроек\r\n",
  356. prvTaskNetConfigCommand, /* The function to run. */
  357. 1 /* Two parameters are expected, which can take any value. */
  358. };
  359. /* Structure that defines the "history" command line command. This
  360. generates a table that shows how much run time each task has */
  361. static const CLI_Command_Definition_t prvHistoryCommandDefinition = {
  362. ( const int8_t *const ) "history", /* The command string to type. */
  363. ( const int8_t *const ) "\thistory show EVENTS|UPS <num_page>: вывод журнала\r\n",
  364. prvTaskHistoryCommand, /* The function to run. */
  365. 3 /* Two parameters are expected, which can take any value. */
  366. };
  367. /* Structure that defines the "sensor info" command line command. This
  368. generates a table that shows how much run time each task has */
  369. static const CLI_Command_Definition_t prvSensorCommandDefinition = {
  370. ( const int8_t *const ) "sensor", /* The command string to type. */
  371. ( const int8_t *const ) "\tsensor info: вывод параметров системы (выход из режима Ctrl+C далее Enter)\r\n"
  372. #ifdef DINS_ENABLE
  373. "\tsensor setup DI <num> <state>: установка нормального состояния сухого контакта:\r\n"
  374. "\t\t\t\t0 - разомкнутое состояние\r\n"
  375. "\t\t\t\t1 - замкнутое состояние\r\n"
  376. #endif
  377. #ifdef DOUTS_ENABLE
  378. "\tsensor setup DO <num> <issue>: установка источника срабатывания реле:\r\n"
  379. "\t\t\t\t1 - Наличие сети\r\n"
  380. "\t\t\t\t2 - Наличие выходного напряжения\r\n"
  381. "\t\t\t\t3 - Разряд АКБ\r\n"
  382. "\t\t\t\t4 - Отключение АКБ\r\n"
  383. "\t\t\t\t5 - SNMP SET\r\n"
  384. #endif
  385. ,
  386. prvTaskSensorCommand, /* The function to run. */
  387. -1 /* No parameters are expected. */
  388. };
  389. /* Structure that defines the "firmware dowmload http" command line command. This
  390. generates a table that shows how much run time each task has */
  391. static const CLI_Command_Definition_t prvUploadCommandDefinition = {
  392. ( const int8_t *const ) "firmware download http", /* The command string to type. */
  393. ( const int8_t *const ) "\tfirmware download http: переход в режим обновления через Web-сервер\r\n",
  394. prvTaskUploadCommand, /* The function to run. */
  395. 2 /* No parameters are expected. */
  396. };
  397. /* Structure that defines the "ups" command line command. This
  398. generates a table that shows how much run time each task has */
  399. static const CLI_Command_Definition_t prvUPSCommandDefinition = {
  400. ( const int8_t *const ) "ups", /* The command string to type. */
  401. ( const int8_t *const ) "\tups battest <num>: управление процедурой тестирования АКБ:\r\n"
  402. "\t\t\t\t0 - Остановить тестирование\r\n"
  403. "\t\t\t\t1-99 - Запустить тест на x минут\r\n"
  404. "\t\t\t\t100 - Тестирование в течение 10 секунд\r\n"
  405. "\t\t\t\t999 - Тестирование до разряда\r\n"
  406. "\tups shutdown <num>: управление отключением нагрузки ИБП:\r\n"
  407. "\t\t\t\t0 - Остановить процедуру отключения нагрузки\r\n"
  408. "\t\t\t\tn - Отключить нагрузку через n минут\r\n"
  409. "\t\t\t\tn: 0.2, 0.3, ..., 1, 2, ..., 10\r\n",
  410. prvTaskUPSCommand, /* The function to run. */
  411. 2 /* Two parameters are expected, which can take any value. */
  412. };
  413. /* Structure that defines the "quit" command line command. This
  414. generates a table that shows how much run time each task has */
  415. static const CLI_Command_Definition_t prvQuitCommandDefinition = {
  416. ( const int8_t *const ) "quit", /* The command string to type. */
  417. ( const int8_t *const ) "\tquit: завершение сессии\r\n",
  418. NULL, /* The function to run. */
  419. -1 /* The user can enter any number of commands. */
  420. };
  421. /*-----------------------------------------------------------*/
  422. void vRegisterCLICommands( void )
  423. {
  424. /* Register all the command line commands defined immediately above. */
  425. FreeRTOS_CLIRegisterCommand( &prvInfoCommandDefinition );
  426. FreeRTOS_CLIRegisterCommand( &prvRebootCommandDefinition );
  427. FreeRTOS_CLIRegisterCommand( &prvSystimeCommandDefinition );
  428. FreeRTOS_CLIRegisterCommand( &prvNTPCommandDefinition );
  429. FreeRTOS_CLIRegisterCommand( &prvNetworkCommandDefinition );
  430. FreeRTOS_CLIRegisterCommand( &prvSNMPCommandDefinition );
  431. FreeRTOS_CLIRegisterCommand( &prvAKBCommandDefinition );
  432. FreeRTOS_CLIRegisterCommand( &prvAlarmCommandDefinition );
  433. #ifdef NOTIFICATION_CONTROL_ENABLE
  434. FreeRTOS_CLIRegisterCommand( &prvNotificationCommandDefinition );
  435. #endif
  436. #ifdef WHITELIST_ENABLE
  437. FreeRTOS_CLIRegisterCommand( &prvWhiteListCommandDefinition );
  438. #endif
  439. FreeRTOS_CLIRegisterCommand( &prvUserCommandDefinition );
  440. FreeRTOS_CLIRegisterCommand( &prvConfigCommandDefinition );
  441. FreeRTOS_CLIRegisterCommand( &prvNetConfigCommandDefinition );
  442. FreeRTOS_CLIRegisterCommand( &prvHistoryCommandDefinition );
  443. FreeRTOS_CLIRegisterCommand( &prvSensorCommandDefinition );
  444. FreeRTOS_CLIRegisterCommand( &prvUploadCommandDefinition );
  445. FreeRTOS_CLIRegisterCommand( &prvUPSCommandDefinition );
  446. FreeRTOS_CLIRegisterCommand( &prvQuitCommandDefinition );
  447. }
  448. /*-----------------------------------------------------------*/
  449. static portBASE_TYPE prvTaskInfoCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  450. {
  451. int8_t *pcParameterString;
  452. signed portBASE_TYPE xParameterStringLength, xReturn;
  453. portBASE_TYPE xParameterNumber = 1;
  454. char str[110];
  455. uint8_t len;
  456. int8_t num_arg = 0;
  457. uint8_t i;
  458. static uint8_t page = 0;
  459. ( void ) pcCommandString;
  460. ( void ) xWriteBufferLen;
  461. configASSERT( pcWriteBuffer );
  462. num_arg = prvGetNumberOfParameters(pcCommandString);
  463. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  464. if (num_arg == 0) {
  465. const int8_t *const pcInfoTableHeader = ( int8_t * )
  466. "\r\n**************Информация о Контроллере**************\r\n";
  467. const int8_t *const pcUPSInfoTableHeader = ( int8_t * )
  468. "\r\n*****************Информация об ИБП******************\r\n";
  469. if (!page) {
  470. /* Return the next command help string, before moving the pointer on to
  471. the next command in the list. */
  472. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  473. GetWorkTimeStr(str, &len);
  474. strcat(( char * ) pcWriteBuffer, "Время работы:\t\t\t");
  475. strncat(( char * ) pcWriteBuffer, str, len);
  476. strcat(( char * ) pcWriteBuffer, "\r\nМодель:\t\t\t\t");
  477. GetModelStr(str, &len);
  478. strncat(( char * ) pcWriteBuffer, str, len);
  479. strcat(( char * ) pcWriteBuffer, "\r\nДата производства:\t\t");
  480. GetProductionDataStr(str, &len);
  481. strncat(( char * ) pcWriteBuffer, str, len);
  482. strcat(( char * ) pcWriteBuffer, "\r\nВерсия ПО:\t\t\t");
  483. GetVersionStr(str, &len);
  484. strncat(( char * ) pcWriteBuffer, str, len);
  485. strcat(( char * ) pcWriteBuffer, "\r\nMAC адрес:\t\t\t");
  486. GetMacStr(str, &len);
  487. strncat(( char * ) pcWriteBuffer, str, len);
  488. strcat(( char * ) pcWriteBuffer, "\r\nСерийный номер:\t\t\t");
  489. GetSerialNumberStr(str, &len);
  490. strncat(( char * ) pcWriteBuffer, str, len);
  491. strcat(( char * ) pcWriteBuffer, "\r\nНазвание устройства:\t\t");
  492. GetNameDeviceStr(str, &len);
  493. strncat(( char * ) pcWriteBuffer, str, len);
  494. strcat(( char * ) pcWriteBuffer, "\r\nВладелец:\t\t\t");
  495. GetOwnerStr(str, &len);
  496. strncat(( char * ) pcWriteBuffer, str, len);
  497. strcat(( char * ) pcWriteBuffer, "\r\nМестоположение:\t\t\t");
  498. GetLocationStr(str, &len);
  499. strncat(( char * ) pcWriteBuffer, str, len);
  500. strcat(( char * ) pcWriteBuffer, "\r\nКомментарии:\t\t\t");
  501. GetCommentsStr(str, &len);
  502. strncat(( char * ) pcWriteBuffer, str, len);
  503. page = 1;
  504. xReturn = pdTRUE;
  505. } else {
  506. strncat( ( char * ) pcWriteBuffer, ( const char * ) pcUPSInfoTableHeader, strlen( ( char * ) pcUPSInfoTableHeader ) );
  507. strcat(( char * ) pcWriteBuffer, "\r\nКомпания:\t\t\tАО\"НПК РоТеК\"");
  508. strcat(( char * ) pcWriteBuffer, "\r\nМодель:\t\t\t\t");
  509. GetUPSModelStr(str, &len);
  510. strncat(( char * ) pcWriteBuffer, str, len);
  511. strcat(( char * ) pcWriteBuffer, "\r\nВерсия ПО:\t\t\t");
  512. GetUPSVersionStr(str, &len);
  513. strncat(( char * ) pcWriteBuffer, str, len);
  514. strcat(( char * ) pcWriteBuffer, "\r\n");
  515. page = 0;
  516. /* There are no more commands in the list, so there will be no more
  517. strings to return after this one and pdFALSE should be returned. */
  518. xReturn = pdFALSE;
  519. }
  520. } else if (num_arg == 1) {
  521. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  522. xReturn = pdFALSE;
  523. } else {
  524. /* Obtain the parameter string. */
  525. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  526. (
  527. pcCommandString, /* The command string itself. */
  528. xParameterNumber, /* Return the next parameter. */
  529. &xParameterStringLength /* Store the parameter string length. */
  530. );
  531. for (i = 0; i < INFO_ALL_ARGS; i ++) {
  532. if ( strncmp( ( const char * ) pcParameterString, info_args_list[i], strlen(info_args_list[i]) ) == 0
  533. && xParameterStringLength == strlen(info_args_list[i])) {
  534. break;
  535. }
  536. }
  537. xParameterNumber ++;
  538. // xParameterNumber ++;
  539. /* Obtain the parameter string. */
  540. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  541. (
  542. pcCommandString, /* The command string itself. */
  543. xParameterNumber, /* Return the next parameter. */
  544. &xParameterStringLength /* Store the parameter string length. */
  545. );
  546. memset(str, 0, sizeof(str));
  547. xParameterStringLength = strlen(( const char * ) pcParameterString);
  548. if (xParameterStringLength > (int32_t)sizeof(str)) {
  549. xParameterStringLength = sizeof(str) - 1;
  550. }
  551. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  552. if (control_string_en_digit(str, strlen(str))) {
  553. switch (i) {
  554. case INFO_DEV_NAME:
  555. if (cli_state->user_id == ADMIN) {
  556. str[19] = 0;
  557. SetNameDeviceStr(str);
  558. } else {
  559. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  560. }
  561. break;
  562. case INFO_ADDRESS:
  563. if (cli_state->user_id == ADMIN) {
  564. str[109] = 0;
  565. SetLocation(str);
  566. } else {
  567. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  568. }
  569. break;
  570. case INFO_OWNER:
  571. if (cli_state->user_id == ADMIN) {
  572. str[49] = 0;
  573. SetOwner(str);
  574. } else {
  575. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  576. }
  577. break;
  578. case INFO_COMMENTS:
  579. if (cli_state->user_id == ADMIN) {
  580. str[109] = 0;
  581. SetComment(str);
  582. } else {
  583. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  584. }
  585. break;
  586. default:
  587. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  588. break;
  589. }
  590. if (i >= INFO_DEV_NAME && i <= INFO_COMMENTS) {
  591. cli_save_config(cli_state);
  592. }
  593. } else {
  594. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  595. }
  596. xReturn = pdFALSE;
  597. }
  598. return xReturn;
  599. }
  600. static portBASE_TYPE prvTaskRebootCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  601. const int8_t *pcCommandString )
  602. {
  603. static bool start_reboot = true;
  604. const int8_t *const pcRebootHeader = ( int8_t * )
  605. "Контроллер будет перезагружен через 1 секунду\r\n";
  606. ( void ) pcCommandString;
  607. ( void ) xWriteBufferLen;
  608. if (cli_state->user_id != ADMIN) {
  609. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  610. return pdFALSE;
  611. }
  612. if (start_reboot) {
  613. start_reboot = false;
  614. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcRebootHeader );
  615. return pdTRUE;
  616. } else {
  617. Reboot(CLI_ACT);
  618. return pdFALSE;
  619. }
  620. }
  621. static portBASE_TYPE prvTaskSystimeCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  622. const int8_t *pcCommandString )
  623. {
  624. int8_t *pcParameterString;
  625. signed portBASE_TYPE xParameterStringLength, xReturn;
  626. portBASE_TYPE xParameterNumber = 1;
  627. char str[110];
  628. uint8_t len;
  629. uint8_t i;
  630. uint8_t fail = 0;
  631. uint16_t temp = 0;
  632. ( void ) pcCommandString;
  633. ( void ) xWriteBufferLen;
  634. configASSERT( pcWriteBuffer );
  635. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  636. /* Obtain the parameter string. */
  637. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  638. (
  639. pcCommandString, /* The command string itself. */
  640. xParameterNumber, /* Return the next parameter. */
  641. &xParameterStringLength /* Store the parameter string length. */
  642. );
  643. if (pcParameterString == NULL) {
  644. const int8_t *const pcInfoTableHeader = ( int8_t * )
  645. "\r\n******Системное время Контроллера******\r\n";
  646. /* Return the next command help string, before moving the pointer on to
  647. the next command in the list. */
  648. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  649. GetDateStr(str, &len);
  650. strcat(( char * ) pcWriteBuffer, "Дата:\t\t\t");
  651. strncat(( char * ) pcWriteBuffer, str, len);
  652. strcat(( char * ) pcWriteBuffer, "\r\nВремя:\t\t\t");
  653. GetTimeStr(str, &len);
  654. strncat(( char * ) pcWriteBuffer, str, len);
  655. strcat(( char * ) pcWriteBuffer, "\r\n");
  656. /* There are no more commands in the list, so there will be no more
  657. strings to return after this one and pdFALSE should be returned. */
  658. xReturn = pdFALSE;
  659. } else {
  660. if (cli_state->user_id != ADMIN) {
  661. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  662. return pdFALSE;
  663. }
  664. for (i = 0; i < ARG_SYSTIME_ALL; i ++) {
  665. if ( strncmp( ( const char * ) pcParameterString, systime_args_list[i], strlen(systime_args_list[i]) ) == 0
  666. && xParameterStringLength == strlen(systime_args_list[i])) {
  667. break;
  668. }
  669. }
  670. if (i != ARG_SYSTIME_ALL) {
  671. if (sSettings.sSNTP.sntpEnable) {
  672. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSystymeDenied, strlen( ( char * ) pcSystymeDenied ) );
  673. return pdFALSE;
  674. }
  675. }
  676. xParameterNumber ++;
  677. /* Obtain the parameter string. */
  678. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  679. (
  680. pcCommandString, /* The command string itself. */
  681. xParameterNumber, /* Return the next parameter. */
  682. &xParameterStringLength /* Store the parameter string length. */
  683. );
  684. if (pcParameterString == NULL) {
  685. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  686. return pdFALSE;
  687. }
  688. memset(str, 0, sizeof(str));
  689. xParameterStringLength = strlen(( const char * ) pcParameterString);
  690. if (xParameterStringLength > (int32_t)sizeof(str)) {
  691. xParameterStringLength = sizeof(str) - 1;
  692. }
  693. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  694. switch (i) {
  695. case ARG_SYSTIME_DATA:
  696. if (xParameterStringLength == 10) {
  697. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  698. if (j != 4 && j != 7) {
  699. if (str[j] > 0x39 || str[j] < 0x30) {
  700. fail = 1;
  701. }
  702. } else if (j == 4 || j == 7) {
  703. if (str[j] != '-') {
  704. fail = 1;
  705. }
  706. }
  707. }
  708. if (!fail) {
  709. temp = 1000 * (str[0] - 0x30) + 100 * (str[1] - 0x30) + 10 * (str[2] - 0x30) + str[3] - 0x30;
  710. if (temp > 2099 || temp < 2000) {
  711. fail = 1;
  712. }
  713. temp = 0;
  714. temp = 10 * (str[5] - 0x30) + (str[6] - 0x30);
  715. if (temp > 12) {
  716. fail = 1;
  717. }
  718. temp = 0;
  719. temp = 10 * (str[8] - 0x30) + (str[9] - 0x30);
  720. if (temp > 31) {
  721. fail = 1;
  722. }
  723. }
  724. } else {
  725. fail = 1;
  726. }
  727. if (!fail) {
  728. SetDateStr(str);
  729. cli_save_config(cli_state);
  730. } else {
  731. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  732. }
  733. break;
  734. case ARG_SYSTIME_TIME:
  735. if (xParameterStringLength == 5) {
  736. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  737. if (j != 2) {
  738. if (str[j] > 0x39 || str[j] < 0x30) {
  739. fail = 1;
  740. }
  741. } else if (j == 2) {
  742. if (str[j] != ':') {
  743. fail = 1;
  744. }
  745. }
  746. }
  747. if (!fail) {
  748. temp = 10 * (str[0] - 0x30) + (str[1] - 0x30);
  749. if (temp > 23) {
  750. fail = 1;
  751. }
  752. temp = 0;
  753. temp = 10 * (str[3] - 0x30) + (str[4] - 0x30);
  754. if (temp > 59) {
  755. fail = 1;
  756. }
  757. }
  758. } else {
  759. fail = 1;
  760. }
  761. if (!fail) {
  762. SetTimeStr(str);
  763. cli_save_config(cli_state);
  764. } else {
  765. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  766. }
  767. break;
  768. default:
  769. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  770. break;
  771. }
  772. xReturn = pdFALSE;
  773. }
  774. return xReturn;
  775. }
  776. /*
  777. * Implements the ntp command.
  778. */
  779. static portBASE_TYPE prvTaskNTPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  780. {
  781. int8_t *pcParameterString;
  782. signed portBASE_TYPE xParameterStringLength, xReturn;
  783. portBASE_TYPE xParameterNumber = 1;
  784. char str[110];
  785. char str_temp[110];
  786. uint8_t len;
  787. uint8_t i;
  788. bool enable_old_sntp;
  789. const int8_t *const pcInfoTableHeader = ( int8_t * )
  790. "\r\n************NTP настройки Контроллера************\r\n";
  791. ( void ) pcCommandString;
  792. ( void ) xWriteBufferLen;
  793. configASSERT( pcWriteBuffer );
  794. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  795. /* Obtain the parameter string. */
  796. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  797. (
  798. pcCommandString, /* The command string itself. */
  799. xParameterNumber, /* Return the next parameter. */
  800. &xParameterStringLength /* Store the parameter string length. */
  801. );
  802. if (pcParameterString == NULL) {
  803. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  804. return pdFALSE;
  805. }
  806. for (i = 0; i < ARG_NTP_ALL; i ++) {
  807. if ( strncmp( ( const char * ) pcParameterString, ntp_args_list[i], strlen(ntp_args_list[i]) ) == 0
  808. && xParameterStringLength == strlen(ntp_args_list[i])) {
  809. break;
  810. }
  811. }
  812. if (cli_state->user_id != ADMIN && i != ARG_NTP_INFO) {
  813. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  814. return pdFALSE;
  815. }
  816. xParameterNumber ++;
  817. /* Obtain the parameter string. */
  818. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  819. (
  820. pcCommandString, /* The command string itself. */
  821. xParameterNumber, /* Return the next parameter. */
  822. &xParameterStringLength /* Store the parameter string length. */
  823. );
  824. xParameterNumber ++;
  825. if (pcParameterString == NULL) {
  826. switch (i) {
  827. case ARG_NTP_ENABLE:
  828. enable_old_sntp = sSettings.sSNTP.sntpEnable;
  829. SetSntpStateStr("1");
  830. if (sSettings.sSNTP.sntpEnable != enable_old_sntp) {
  831. cli_save_config(cli_state);
  832. }
  833. break;
  834. case ARG_NTP_DISABLE:
  835. enable_old_sntp = sSettings.sSNTP.sntpEnable;
  836. SetSntpStateStr("0");
  837. if (sSettings.sSNTP.sntpEnable != enable_old_sntp) {
  838. cli_save_config(cli_state);
  839. }
  840. break;
  841. case ARG_NTP_INFO:
  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. GetSntpStateStrRU(str, &len);
  846. strcat(( char * ) pcWriteBuffer, "Режим установки времени:\t");
  847. strncat(( char * ) pcWriteBuffer, str, len);
  848. strcat(( char * ) pcWriteBuffer, "\r\nIP адрес NTP сервера:\t\t");
  849. GetSntpServerIpStr(str, &len);
  850. strncat(( char * ) pcWriteBuffer, str, len);
  851. strcat(( char * ) pcWriteBuffer, "\r\nЧасовой пояс:\t\t\t");
  852. GetSntpTimeZoneStr(str, &len);
  853. strncat(( char * ) pcWriteBuffer, str, len);
  854. strcat(( char * ) pcWriteBuffer, "\r\nПоследняя дата синхронизации:\t");
  855. GetSntpLastDataStr(str, &len);
  856. strncat(( char * ) pcWriteBuffer, str, len);
  857. strcat(( char * ) pcWriteBuffer, "\r\n");
  858. break;
  859. default:
  860. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  861. break;
  862. }
  863. return pdFALSE;
  864. }
  865. if (i == ARG_NTP_SET) {
  866. memset(str, 0, sizeof(str));
  867. if (xParameterStringLength > (int32_t)sizeof(str)) {
  868. xParameterStringLength = sizeof(str) - 1;
  869. }
  870. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  871. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  872. (
  873. pcCommandString, /* The command string itself. */
  874. xParameterNumber, /* Return the next parameter. */
  875. &xParameterStringLength /* Store the parameter string length. */
  876. );
  877. if (pcParameterString != NULL) {
  878. memset(str_temp, 0, sizeof(str_temp));
  879. if (xParameterStringLength > (int32_t)sizeof(str_temp)) {
  880. xParameterStringLength = sizeof(str_temp) - 1;
  881. }
  882. strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
  883. if (strncmp(str, "IP", 2) == 0) {
  884. if (xParameterStringLength <= 15) {
  885. if (ipaddr_addr(str_temp) != IPADDR_NONE) {
  886. if (strncmp(str_temp, sSettings.sSNTP.ip, strlen(str_temp)) != 0) {
  887. SetSntpServerIpStr(str_temp);
  888. cli_save_config(cli_state);
  889. }
  890. } else {
  891. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  892. }
  893. } else {
  894. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  895. }
  896. } else if (strncmp(str, "gmt", 3) == 0) {
  897. if (xParameterStringLength > 1 && xParameterStringLength < 5) {
  898. bool fail = false;
  899. if (str_temp[0] != '-' && str_temp[0] != '+') {
  900. fail = true;
  901. }
  902. if (!isdigit_int(str_temp[1]) && (!isdigit_int(str_temp[2]) && str_temp[2] != '.') && (!isdigit_int(str_temp[3]) &&
  903. str_temp[3] != '.')) {
  904. fail = true;
  905. }
  906. if (xParameterStringLength == 5) {
  907. if (!isdigit_int(str_temp[4])) {
  908. fail = true;
  909. }
  910. }
  911. if (!fail) {
  912. float value = atof(str_temp);
  913. if (value >= -12.0 && value <= 12.0) {
  914. SetSntpTimeZoneStr(str_temp);
  915. cli_save_config(cli_state);
  916. } else {
  917. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  918. }
  919. } else {
  920. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  921. }
  922. } else {
  923. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  924. }
  925. } else {
  926. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  927. }
  928. } else {
  929. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  930. }
  931. } else {
  932. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  933. }
  934. xReturn = pdFALSE;
  935. return xReturn;
  936. }
  937. /*
  938. * Implements the network command.
  939. */
  940. static portBASE_TYPE prvTaskNetworkCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  941. const int8_t *pcCommandString )
  942. {
  943. int8_t *pcParameterString;
  944. signed portBASE_TYPE xParameterStringLength, xReturn;
  945. portBASE_TYPE xParameterNumber = 1;
  946. char str[110];
  947. uint8_t i;
  948. ( void ) pcCommandString;
  949. ( void ) xWriteBufferLen;
  950. configASSERT( pcWriteBuffer );
  951. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  952. /* Obtain the parameter string. */
  953. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  954. (
  955. pcCommandString, /* The command string itself. */
  956. xParameterNumber, /* Return the next parameter. */
  957. &xParameterStringLength /* Store the parameter string length. */
  958. );
  959. if (pcParameterString == NULL) {
  960. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  961. return pdFALSE;
  962. }
  963. for (i = 0; i < ARG_NETWORK_ALL; i ++) {
  964. if ( strncmp( ( const char * ) pcParameterString, network_args_list[i], strlen(network_args_list[i]) ) == 0
  965. && xParameterStringLength == strlen(network_args_list[i])) {
  966. break;
  967. }
  968. }
  969. if (cli_state->user_id != ADMIN && i != ARG_NETWORK_INFO) {
  970. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  971. return pdFALSE;
  972. }
  973. if (i != ARG_NETWORK_ALL && i != ARG_NETWORK_DHCP && i != ARG_NETWORK_INFO) {
  974. if (sSettings.sWebTempParams.dhcpEnable) {
  975. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  976. return pdFALSE;
  977. }
  978. }
  979. xParameterNumber ++;
  980. /* Obtain the parameter string. */
  981. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  982. (
  983. pcCommandString, /* The command string itself. */
  984. xParameterNumber, /* Return the next parameter. */
  985. &xParameterStringLength /* Store the parameter string length. */
  986. );
  987. if (pcParameterString == NULL) {
  988. if (i == ARG_NETWORK_INFO) {
  989. net_config_param(pcWriteBuffer);
  990. } else {
  991. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  992. }
  993. return pdFALSE;
  994. }
  995. memset(str, 0, sizeof(str));
  996. xParameterStringLength = strlen(( const char * ) pcParameterString);
  997. if (xParameterStringLength > (int32_t)sizeof(str)) {
  998. xParameterStringLength = sizeof(str) - 1;
  999. }
  1000. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1001. switch (i) {
  1002. case ARG_NETWORK_DHCP:
  1003. if (strncmp(str, "ENA", 3) == 0) {
  1004. SetUDPDhcpStateStr("True");
  1005. strcpy( ( char * ) pcWriteBuffer,
  1006. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1007. } else if (strncmp(str, "DIS", 3) == 0) {
  1008. SetUDPDhcpStateStr("False");
  1009. strcpy( ( char * ) pcWriteBuffer,
  1010. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1011. } else {
  1012. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1013. }
  1014. break;
  1015. case ARG_NETWORK_IP:
  1016. if (xParameterStringLength <= 15) {
  1017. if (ipaddr_addr(str) != IPADDR_NONE) {
  1018. SetIPStr(str);
  1019. strcpy( ( char * ) pcWriteBuffer,
  1020. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1021. } else {
  1022. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1023. }
  1024. } else {
  1025. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1026. }
  1027. break;
  1028. case ARG_NETWORK_GW:
  1029. if (xParameterStringLength <= 15) {
  1030. if (ipaddr_addr(str) != IPADDR_NONE) {
  1031. SetGatewayStr(str);
  1032. strcpy( ( char * ) pcWriteBuffer,
  1033. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1034. } else {
  1035. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1036. }
  1037. } else {
  1038. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1039. }
  1040. break;
  1041. case ARG_NETWORK_MASK:
  1042. if (xParameterStringLength <= 15) {
  1043. if (ipaddr_addr(str) != IPADDR_NONE) {
  1044. SetMaskStr(str);
  1045. strcpy( ( char * ) pcWriteBuffer,
  1046. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1047. } else {
  1048. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1049. }
  1050. } else {
  1051. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1052. }
  1053. break;
  1054. default:
  1055. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1056. break;
  1057. }
  1058. xReturn = pdFALSE;
  1059. return xReturn;
  1060. }
  1061. /*
  1062. * Implements the snmp command.
  1063. */
  1064. static portBASE_TYPE prvTaskSNMPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1065. {
  1066. int8_t *pcParameterString;
  1067. signed portBASE_TYPE xParameterStringLength, xReturn;
  1068. portBASE_TYPE xParameterNumber = 1;
  1069. char str[20];
  1070. char temp_str[20];
  1071. uint8_t i;
  1072. ( void ) pcCommandString;
  1073. ( void ) xWriteBufferLen;
  1074. configASSERT( pcWriteBuffer );
  1075. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1076. /* Obtain the parameter string. */
  1077. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1078. (
  1079. pcCommandString, /* The command string itself. */
  1080. xParameterNumber, /* Return the next parameter. */
  1081. &xParameterStringLength /* Store the parameter string length. */
  1082. );
  1083. if (pcParameterString == NULL) {
  1084. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1085. return pdFALSE;
  1086. }
  1087. for (i = 0; i < ARG_SNMP_ALL; i ++) {
  1088. if ( strncmp( ( const char * ) pcParameterString, snmp_args_list[i], strlen(snmp_args_list[i]) ) == 0
  1089. && xParameterStringLength == strlen(snmp_args_list[i])) {
  1090. break;
  1091. }
  1092. }
  1093. if (cli_state->user_id != ADMIN && i != ARG_SNMP_INFO) {
  1094. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1095. return pdFALSE;
  1096. }
  1097. xParameterNumber ++;
  1098. /* Obtain the parameter string. */
  1099. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1100. (
  1101. pcCommandString, /* The command string itself. */
  1102. xParameterNumber, /* Return the next parameter. */
  1103. &xParameterStringLength /* Store the parameter string length. */
  1104. );
  1105. xParameterNumber ++;
  1106. if (pcParameterString == NULL) {
  1107. if (i == ARG_SNMP_INFO) {
  1108. snmp_config_param(pcWriteBuffer);
  1109. } else {
  1110. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1111. }
  1112. return pdFALSE;
  1113. }
  1114. memset(str, 0, sizeof(str));
  1115. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1116. xParameterStringLength = sizeof(str) - 1;
  1117. }
  1118. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1119. switch (i) {
  1120. case ARG_SNMP_SERVER:
  1121. if (xParameterStringLength == 1 && isdigit_int(str[0])) {
  1122. int32_t temp = atoi(str);
  1123. if (temp > 0 && temp < 6) {
  1124. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1125. (
  1126. pcCommandString, /* The command string itself. */
  1127. xParameterNumber, /* Return the next parameter. */
  1128. &xParameterStringLength /* Store the parameter string length. */
  1129. );
  1130. if (pcParameterString != NULL) {
  1131. memset(str, 0, sizeof(str));
  1132. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1133. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1134. xParameterStringLength = sizeof(str) - 1;
  1135. }
  1136. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1137. if (xParameterStringLength <= 15) {
  1138. if (ipaddr_addr(str) != IPADDR_NONE) {
  1139. switch (temp) {
  1140. case 1:
  1141. SetManagerIp(str);
  1142. break;
  1143. case 2:
  1144. SetManagerIp2(str);
  1145. break;
  1146. case 3:
  1147. SetManagerIp3(str);
  1148. break;
  1149. case 4:
  1150. SetManagerIp4(str);
  1151. break;
  1152. case 5:
  1153. SetManagerIp5(str);
  1154. break;
  1155. }
  1156. if (temp > 0 && temp < 6) {
  1157. cli_save_config(cli_state);
  1158. }
  1159. } else {
  1160. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1161. }
  1162. } else {
  1163. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1164. }
  1165. } else {
  1166. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1167. }
  1168. } else {
  1169. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1170. }
  1171. } else {
  1172. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1173. }
  1174. break;
  1175. case ARG_SNMP_COMMUNITY:
  1176. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1177. (
  1178. pcCommandString, /* The command string itself. */
  1179. xParameterNumber, /* Return the next parameter. */
  1180. &xParameterStringLength /* Store the parameter string length. */
  1181. );
  1182. if (pcParameterString != NULL) {
  1183. memset(temp_str, 0, sizeof(temp_str));
  1184. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1185. if (xParameterStringLength > (int32_t)sizeof(temp_str)) {
  1186. xParameterStringLength = sizeof(temp_str) - 1;
  1187. }
  1188. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1189. if (control_string_en_digit(temp_str, strlen(temp_str))) {
  1190. if (strncmp(str, "read", 4) == 0) {
  1191. SetReadCommunity(temp_str);
  1192. cli_save_config(cli_state);
  1193. } else if (strncmp(str, "write", 5) == 0) {
  1194. SetWriteCommunity(temp_str);
  1195. cli_save_config(cli_state);
  1196. } else {
  1197. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1198. }
  1199. } else {
  1200. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1201. }
  1202. } else {
  1203. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1204. }
  1205. break;
  1206. default:
  1207. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1208. break;
  1209. }
  1210. xReturn = pdFALSE;
  1211. return xReturn;
  1212. }
  1213. /*
  1214. * Implements the akb command.
  1215. */
  1216. static portBASE_TYPE prvTaskAKBCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1217. {
  1218. int8_t *pcParameterString;
  1219. signed portBASE_TYPE xParameterStringLength, xReturn;
  1220. portBASE_TYPE xParameterNumber = 1;
  1221. char str[110];
  1222. uint8_t i;
  1223. uint8_t fail = 0;
  1224. uint16_t temp = 0;
  1225. float value = 0;
  1226. ( void ) pcCommandString;
  1227. ( void ) xWriteBufferLen;
  1228. configASSERT( pcWriteBuffer );
  1229. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1230. /* Obtain the parameter string. */
  1231. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1232. (
  1233. pcCommandString, /* The command string itself. */
  1234. xParameterNumber, /* Return the next parameter. */
  1235. &xParameterStringLength /* Store the parameter string length. */
  1236. );
  1237. if (pcParameterString == NULL) {
  1238. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1239. return pdFALSE;
  1240. }
  1241. for (i = 0; i < ARG_AKB_ALL; i ++) {
  1242. if ( strncmp( ( const char * ) pcParameterString, akb_args_list[i], strlen(akb_args_list[i]) ) == 0
  1243. && xParameterStringLength == strlen(akb_args_list[i])) {
  1244. break;
  1245. }
  1246. }
  1247. if (cli_state->user_id != ADMIN && i != ARG_AKB_INFO) {
  1248. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1249. return pdFALSE;
  1250. }
  1251. xParameterNumber ++;
  1252. /* Obtain the parameter string. */
  1253. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1254. (
  1255. pcCommandString, /* The command string itself. */
  1256. xParameterNumber, /* Return the next parameter. */
  1257. &xParameterStringLength /* Store the parameter string length. */
  1258. );
  1259. if (pcParameterString == NULL) {
  1260. if (i == ARG_AKB_INFO) {
  1261. akb_config_param(pcWriteBuffer);
  1262. } else {
  1263. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1264. }
  1265. return pdFALSE;
  1266. }
  1267. memset(str, 0, sizeof(str));
  1268. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1269. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1270. xParameterStringLength = sizeof(str) - 2;
  1271. }
  1272. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1273. #ifdef HARDWARE_BT6709
  1274. if (i != ARG_AKB_DATASET)
  1275. #endif
  1276. {
  1277. for (uint8_t j = 0; j < xParameterStringLength; j ++) {
  1278. if (!isfloatdigit(str[j])) {
  1279. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1280. return pdFALSE;
  1281. }
  1282. }
  1283. value = atof(str);
  1284. }
  1285. switch (i) {
  1286. case ARG_AKB_VOLT_CELL_MIN:
  1287. if (value < sSettings.UPS_Setting.Ucellmax && value > MIN_VOLT_CELL_RANGE) {
  1288. SetUPSVoltCellMinStr(str);
  1289. cli_save_config(cli_state);
  1290. } else {
  1291. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1292. }
  1293. break;
  1294. case ARG_AKB_VOLT_CELL_MAX:
  1295. if (value > sSettings.UPS_Setting.Ucellmin && value <= MAX_VOLT_CELL_RANGE) {
  1296. SetUPSVoltCellMaxStr(str);
  1297. cli_save_config(cli_state);
  1298. } else {
  1299. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1300. }
  1301. break;
  1302. #ifdef HARDWARE_BT6709
  1303. case ARG_AKB_CAPACITY:
  1304. if (value >= CAPACITY_MIN_RANGE && value <= CAPACITY_MAX_RANGE && (value - (int32_t)value) == 0) {
  1305. SetCapacityNominalAKBStr(str);
  1306. cli_save_config(cli_state);
  1307. } else {
  1308. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1309. }
  1310. break;
  1311. case ARG_AKB_VOLT:
  1312. if (value >= AKB_VOLTAGE_MIN_RANGE && value <= AKB_VOLTAGE_MAX_RANGE && ((int32_t)value % 12) == 0 && (value - (int32_t)value) == 0) {
  1313. SetVoltageAKBNominalStr(str);
  1314. cli_save_config(cli_state);
  1315. } else {
  1316. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1317. }
  1318. break;
  1319. case ARG_AKB_LIFETIME:
  1320. if (value >= LIFETIME_MIN_RANGE && value <= LIFETIME_MAX_RANGE && (value - (int32_t)value) == 0) {
  1321. SetLifeTimeAKBStr(str);
  1322. cli_save_config(cli_state);
  1323. } else {
  1324. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1325. }
  1326. break;
  1327. case ARG_AKB_DATASET:
  1328. if (xParameterStringLength == 10) {
  1329. if (strncmp( str, "0000-00-00", 10) == 0) {
  1330. memset(str, 0, sizeof(str));
  1331. SetDataSetAKBStr(str);
  1332. SETTINGS_Save();
  1333. xReturn = pdFALSE;
  1334. return xReturn;
  1335. }
  1336. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  1337. if (j != 4 && j != 7) {
  1338. if (str[j] > 0x39 || str[j] < 0x30) {
  1339. fail = 1;
  1340. }
  1341. } else if (j == 4 || j == 7) {
  1342. if (str[j] != '-') {
  1343. fail = 1;
  1344. }
  1345. }
  1346. }
  1347. if (!fail) {
  1348. temp = 1000 * (str[0] - 0x30) + 100 * (str[1] - 0x30) + 10 * (str[2] - 0x30) + str[3] - 0x30;
  1349. if (temp > 2099 || temp < 2000) {
  1350. fail = 1;
  1351. }
  1352. temp = 0;
  1353. temp = 10 * (str[5] - 0x30) + (str[6] - 0x30);
  1354. if (temp > 12) {
  1355. fail = 1;
  1356. }
  1357. temp = 0;
  1358. temp = 10 * (str[8] - 0x30) + (str[9] - 0x30);
  1359. if (temp > 31) {
  1360. fail = 1;
  1361. }
  1362. }
  1363. } else {
  1364. fail = 1;
  1365. }
  1366. if (!fail) {
  1367. SetDataSetAKBStr(str);
  1368. cli_save_config(cli_state);
  1369. } else {
  1370. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1371. }
  1372. break;
  1373. case ARG_AKB_UPS_POWER:
  1374. if (value >= UPS_POWER_MIN_RANGE && value <= UPS_POWER_MAX_RANGE && ((int32_t)value % 50) == 0 && (value - (int32_t)value) == 0) {
  1375. SetUPSPowerStr(str);
  1376. cli_save_config(cli_state);
  1377. } else {
  1378. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1379. }
  1380. break;
  1381. #endif
  1382. default:
  1383. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1384. break;
  1385. }
  1386. xReturn = pdFALSE;
  1387. return xReturn;
  1388. }
  1389. /*
  1390. * Implements the alarm command.
  1391. */
  1392. static portBASE_TYPE prvTaskAlarmCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1393. {
  1394. int8_t *pcParameterString;
  1395. signed portBASE_TYPE xParameterStringLength, xReturn;
  1396. portBASE_TYPE xParameterNumber = 1;
  1397. char str[110];
  1398. uint8_t i, j;
  1399. float value = 0;
  1400. uint8_t k;
  1401. ( void ) pcCommandString;
  1402. ( void ) xWriteBufferLen;
  1403. configASSERT( pcWriteBuffer );
  1404. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1405. /* Obtain the parameter string. */
  1406. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1407. (
  1408. pcCommandString, /* The command string itself. */
  1409. xParameterNumber, /* Return the next parameter. */
  1410. &xParameterStringLength /* Store the parameter string length. */
  1411. );
  1412. if (pcParameterString == NULL) {
  1413. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1414. return pdFALSE;
  1415. }
  1416. for (i = 0; i < ARG_ALARM_TYPE_ALL; i ++) {
  1417. if ( strncmp( ( const char * ) pcParameterString, type_alarm_args_list[i], strlen(type_alarm_args_list[i]) ) == 0
  1418. && xParameterStringLength == strlen(type_alarm_args_list[i])) {
  1419. break;
  1420. }
  1421. }
  1422. if (cli_state->user_id != ADMIN && i != ARG_ALARM_INFO) {
  1423. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1424. return pdFALSE;
  1425. }
  1426. xParameterNumber ++;
  1427. /* Obtain the parameter string. */
  1428. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1429. (
  1430. pcCommandString, /* The command string itself. */
  1431. xParameterNumber, /* Return the next parameter. */
  1432. &xParameterStringLength /* Store the parameter string length. */
  1433. );
  1434. if (pcParameterString == NULL) {
  1435. if (i == ARG_ALARM_INFO) {
  1436. alarm_config_param(pcWriteBuffer);
  1437. } else {
  1438. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1439. }
  1440. return pdFALSE;
  1441. }
  1442. for (j = 0; j < ARG_ALARM_ALL; j ++) {
  1443. if ( strncmp( ( const char * ) pcParameterString, alarm_args_list[j], strlen(alarm_args_list[j]) ) == 0 ) {
  1444. break;
  1445. }
  1446. }
  1447. xParameterNumber ++;
  1448. /* Obtain the parameter string. */
  1449. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1450. (
  1451. pcCommandString, /* The command string itself. */
  1452. xParameterNumber, /* Return the next parameter. */
  1453. &xParameterStringLength /* Store the parameter string length. */
  1454. );
  1455. if (pcParameterString == NULL) {
  1456. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1457. return pdFALSE;
  1458. }
  1459. memset(str, 0, sizeof(str));
  1460. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1461. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1462. xParameterStringLength = sizeof(str) - 2;
  1463. }
  1464. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1465. switch (i) {
  1466. case ARG_ALARM_TEMP:
  1467. switch (j) {
  1468. case ARG_ALARM_LINE_LOW:
  1469. for (k = 0; k < xParameterStringLength; k ++) {
  1470. if (!isdigit_int(str[k])) {
  1471. if (k == 0 && str[k] == '-') {
  1472. continue;
  1473. } else {
  1474. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1475. return pdFALSE;
  1476. }
  1477. }
  1478. }
  1479. value = atof(str);
  1480. if (value >= MIN_TEMP_MIN_RANGE && value <= MIN_TEMP_MAX_RANGE) {
  1481. SetTemperatureAlarmLowRangeStr(str);
  1482. cli_save_config(cli_state);
  1483. } else {
  1484. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1485. }
  1486. break;
  1487. case ARG_ALARM_LINE_HIGH:
  1488. for (k = 0; k < xParameterStringLength; k ++) {
  1489. if (!isdigit_int(str[k])) {
  1490. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1491. return pdFALSE;
  1492. }
  1493. }
  1494. value = atof(str);
  1495. if (value >= MAX_TEMP_MIN_RANGE && value <= MAX_TEMP_MAX_RANGE) {
  1496. SetTemperatureAlarmHighRangeStr(str);
  1497. cli_save_config(cli_state);
  1498. } else {
  1499. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1500. }
  1501. break;
  1502. case ARG_ALARM_LINE_HIST:
  1503. for (k = 0; k < xParameterStringLength; k ++) {
  1504. if (!isfloatdigit(str[k])) {
  1505. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1506. return pdFALSE;
  1507. }
  1508. }
  1509. value = atof(str);
  1510. if (value >= HIST_TEMP_MIN_RANGE && value <= HIST_TEMP_MAX_RANGE) {
  1511. SetTemperatureAlarmHisteStr(str);
  1512. cli_save_config(cli_state);
  1513. } else {
  1514. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1515. }
  1516. break;
  1517. default:
  1518. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1519. break;
  1520. }
  1521. break;
  1522. case ARG_ALARM_LOAD:
  1523. switch (j) {
  1524. case ARG_ALARM_LINE_LOW:
  1525. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1526. break;
  1527. case ARG_ALARM_LINE_HIGH:
  1528. for (k = 0; k < xParameterStringLength; k ++) {
  1529. if (!isdigit_int(str[k])) {
  1530. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1531. return pdFALSE;
  1532. }
  1533. }
  1534. value = atof(str);
  1535. if (value >= MAX_LOAD_MIN_RANGE && value <= MAX_LOAD_MAX_RANGE) {
  1536. SetLoadAlarmHighRangeStr(str);
  1537. cli_save_config(cli_state);
  1538. } else {
  1539. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1540. }
  1541. break;
  1542. case ARG_ALARM_LINE_HIST:
  1543. for (k = 0; k < xParameterStringLength; k ++) {
  1544. if (!isfloatdigit(str[k])) {
  1545. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1546. return pdFALSE;
  1547. }
  1548. }
  1549. value = atof(str);
  1550. if (value >= HIST_LOAD_MIN_RANGE && value <= HIST_LOAD_MAX_RANGE) {
  1551. SetLoadAlarmHistStr(str);
  1552. cli_save_config(cli_state);
  1553. } else {
  1554. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1555. }
  1556. break;
  1557. default:
  1558. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1559. break;
  1560. }
  1561. break;
  1562. case ARG_ALARM_VOUT:
  1563. switch (j) {
  1564. case ARG_ALARM_LINE_LOW:
  1565. for (k = 0; k < xParameterStringLength; k ++) {
  1566. if (!isdigit_int(str[k])) {
  1567. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1568. return pdFALSE;
  1569. }
  1570. }
  1571. value = atof(str);
  1572. if (value >= MIN_VAC_MIN_RANGE && value <= MIN_VAC_MAX_RANGE) {
  1573. SetVACAlarmLowRangeStr(str);
  1574. cli_save_config(cli_state);
  1575. } else {
  1576. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1577. }
  1578. break;
  1579. case ARG_ALARM_LINE_HIGH:
  1580. for (k = 0; k < xParameterStringLength; k ++) {
  1581. if (!isdigit_int(str[k])) {
  1582. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1583. return pdFALSE;
  1584. }
  1585. }
  1586. value = atof(str);
  1587. if (value >= MAX_VAC_MIN_RANGE && value <= MAX_VAC_MAX_RANGE) {
  1588. SetVACAlarmHighRangeStr(str);
  1589. cli_save_config(cli_state);
  1590. } else {
  1591. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1592. }
  1593. break;
  1594. case ARG_ALARM_LINE_HIST:
  1595. for (k = 0; k < xParameterStringLength; k ++) {
  1596. if (!isdigit_int(str[k])) {
  1597. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1598. return pdFALSE;
  1599. }
  1600. }
  1601. value = atof(str);
  1602. if (value >= HIST_VAC_MIN_RANGE && value <= HIST_VAC_MAX_RANGE) {
  1603. SetVACAlarmHisteStr(str);
  1604. cli_save_config(cli_state);
  1605. } else {
  1606. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1607. }
  1608. break;
  1609. default:
  1610. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1611. break;
  1612. }
  1613. break;
  1614. default:
  1615. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1616. break;
  1617. }
  1618. xReturn = pdFALSE;
  1619. return xReturn;
  1620. }
  1621. #ifdef NOTIFICATION_CONTROL_ENABLE
  1622. /*
  1623. * Implements the notification command.
  1624. */
  1625. static portBASE_TYPE prvTaskNotificationCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  1626. const int8_t *pcCommandString )
  1627. {
  1628. int8_t *pcParameterString;
  1629. signed portBASE_TYPE xParameterStringLength, xReturn;
  1630. portBASE_TYPE xParameterNumber = 1;
  1631. char str[20];
  1632. char temp_str[20];
  1633. uint8_t i;
  1634. char *beginValue;
  1635. uint8_t len;
  1636. ( void ) pcCommandString;
  1637. ( void ) xWriteBufferLen;
  1638. configASSERT( pcWriteBuffer );
  1639. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1640. /* Obtain the parameter string. */
  1641. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1642. (
  1643. pcCommandString, /* The command string itself. */
  1644. xParameterNumber, /* Return the next parameter. */
  1645. &xParameterStringLength /* Store the parameter string length. */
  1646. );
  1647. if (pcParameterString == NULL) {
  1648. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1649. return pdFALSE;
  1650. }
  1651. for (i = 0; i < ARG_NOTIFICATION_ALL; i ++) {
  1652. if ( strncmp( ( const char * ) pcParameterString, notification_args_list[i], strlen(notification_args_list[i]) ) == 0
  1653. && xParameterStringLength == strlen(notification_args_list[i])) {
  1654. break;
  1655. }
  1656. }
  1657. if (cli_state->user_id != ADMIN && i != ARG_NOTIFICATION_INFO) {
  1658. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1659. return pdFALSE;
  1660. }
  1661. xParameterNumber ++;
  1662. /* Obtain the parameter string. */
  1663. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1664. (
  1665. pcCommandString, /* The command string itself. */
  1666. xParameterNumber, /* Return the next parameter. */
  1667. &xParameterStringLength /* Store the parameter string length. */
  1668. );
  1669. xParameterNumber ++;
  1670. if (pcParameterString == NULL) {
  1671. if (i == ARG_NOTIFICATION_INFO) {
  1672. notification_param(pcWriteBuffer);
  1673. } else {
  1674. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1675. }
  1676. return pdFALSE;
  1677. }
  1678. memset(str, 0, sizeof(str));
  1679. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1680. xParameterStringLength = sizeof(str) - 1;
  1681. }
  1682. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1683. switch (i) {
  1684. case ARG_NOTIFICATION_SET:
  1685. if (xParameterStringLength >= 1) {
  1686. for(uint32_t k = 0; k < xParameterStringLength; k ++) {
  1687. if (!isdigit_int(str[k])) {
  1688. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1689. return pdFALSE;
  1690. }
  1691. }
  1692. int32_t temp = atoi(str);
  1693. uint8_t value_notification = 0;
  1694. if (temp > 0 && temp < ALL_TRAPS) {
  1695. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1696. (
  1697. pcCommandString, /* The command string itself. */
  1698. xParameterNumber, /* Return the next parameter. */
  1699. &xParameterStringLength /* Store the parameter string length. */
  1700. );
  1701. if (pcParameterString != NULL && xParameterStringLength == 3) {
  1702. if (strncmp(pcParameterString, "ENA", 3) == 0) {
  1703. value_notification = 1;
  1704. SetNotificationFlagsStr(&value_notification, (uint8_t)temp);
  1705. SETTINGS_Save();
  1706. } else if (strncmp(pcParameterString, "DIS", 3) == 0) {
  1707. SetNotificationFlagsStr(&value_notification, (uint8_t)temp);
  1708. SETTINGS_Save();
  1709. } else {
  1710. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1711. }
  1712. } else {
  1713. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1714. }
  1715. } else {
  1716. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1717. }
  1718. } else {
  1719. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1720. }
  1721. break;
  1722. default:
  1723. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1724. break;
  1725. }
  1726. xReturn = pdFALSE;
  1727. return xReturn;
  1728. }
  1729. #endif
  1730. #ifdef WHITELIST_ENABLE
  1731. /*
  1732. * Implements the whitelist command.
  1733. */
  1734. static portBASE_TYPE prvTaskWhiteListCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  1735. const int8_t *pcCommandString )
  1736. {
  1737. int8_t *pcParameterString;
  1738. signed portBASE_TYPE xParameterStringLength, xReturn;
  1739. portBASE_TYPE xParameterNumber = 1;
  1740. char str[20];
  1741. char temp_str[20];
  1742. uint8_t i;
  1743. char *beginValue;
  1744. uint8_t len;
  1745. int32_t temp;
  1746. ( void ) pcCommandString;
  1747. ( void ) xWriteBufferLen;
  1748. configASSERT( pcWriteBuffer );
  1749. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1750. /* Obtain the parameter string. */
  1751. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1752. (
  1753. pcCommandString, /* The command string itself. */
  1754. xParameterNumber, /* Return the next parameter. */
  1755. &xParameterStringLength /* Store the parameter string length. */
  1756. );
  1757. if (pcParameterString == NULL) {
  1758. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1759. return pdFALSE;
  1760. }
  1761. for (i = 0; i < ARG_WHITELIST_ALL; i ++) {
  1762. if ( strncmp( ( const char * ) pcParameterString, whitelist_args_list[i], strlen(whitelist_args_list[i]) ) == 0
  1763. && xParameterStringLength == strlen(whitelist_args_list[i])) {
  1764. break;
  1765. }
  1766. }
  1767. if (cli_state->user_id != ADMIN && i != ARG_WHITELIST_INFO) {
  1768. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1769. return pdFALSE;
  1770. }
  1771. xParameterNumber ++;
  1772. /* Obtain the parameter string. */
  1773. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1774. (
  1775. pcCommandString, /* The command string itself. */
  1776. xParameterNumber, /* Return the next parameter. */
  1777. &xParameterStringLength /* Store the parameter string length. */
  1778. );
  1779. xParameterNumber ++;
  1780. if (pcParameterString == NULL) {
  1781. if (i == ARG_WHITELIST_INFO) {
  1782. whitelist_config_param(pcWriteBuffer);
  1783. } else {
  1784. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1785. }
  1786. return pdFALSE;
  1787. }
  1788. memset(str, 0, sizeof(str));
  1789. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1790. xParameterStringLength = sizeof(str) - 1;
  1791. }
  1792. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1793. switch (i) {
  1794. case ARG_WHITELIST_RANGE:
  1795. if (xParameterStringLength == 1 && isdigit_int(str[0])) {
  1796. temp = atoi(str);
  1797. if (temp > 0 && temp < 6) {
  1798. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1799. (
  1800. pcCommandString, /* The command string itself. */
  1801. xParameterNumber, /* Return the next parameter. */
  1802. &xParameterStringLength /* Store the parameter string length. */
  1803. );
  1804. if (pcParameterString != NULL) {
  1805. memset(str, 0, sizeof(str));
  1806. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1807. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1808. xParameterStringLength = sizeof(str) - 1;
  1809. }
  1810. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1811. if (xParameterStringLength <= 19) {
  1812. beginValue = strpbrk(str, "/");
  1813. if (beginValue == NULL) {
  1814. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1815. return pdFALSE;
  1816. }
  1817. int32_t mask = atoi(&beginValue[1]);
  1818. len = beginValue - str;
  1819. memset(temp_str, 0, sizeof(temp_str));
  1820. strncpy(temp_str, str, len);
  1821. for (uint8_t j = (len + 1); j < xParameterStringLength; j++) {
  1822. if (!isdigit_int(str[j])) {
  1823. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1824. return pdFALSE;
  1825. }
  1826. }
  1827. if (ipaddr_addr(temp_str) != IPADDR_NONE && (mask <= 32 && mask >= 0)) {
  1828. SetWhiteListSTR(str, (temp - 1));
  1829. strcpy( ( char * ) pcWriteBuffer,
  1830. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1831. } else {
  1832. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1833. }
  1834. } else {
  1835. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1836. }
  1837. } else {
  1838. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1839. }
  1840. } else {
  1841. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1842. }
  1843. } else {
  1844. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1845. }
  1846. break;
  1847. case ARG_WHITELIST_RESET:
  1848. if (xParameterStringLength == 1 && isdigit_int(str[0])) {
  1849. temp = atoi(str);
  1850. if (temp > 0 && temp < 6) {
  1851. memset(str, 0, sizeof(str));
  1852. SetWhiteListSTR(str, (temp - 1));
  1853. strcpy( ( char * ) pcWriteBuffer,
  1854. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1855. } else {
  1856. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1857. }
  1858. } else {
  1859. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1860. }
  1861. break;
  1862. default:
  1863. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1864. break;
  1865. }
  1866. xReturn = pdFALSE;
  1867. return xReturn;
  1868. }
  1869. #endif
  1870. /*
  1871. * Implements the change password command.
  1872. */
  1873. static portBASE_TYPE prvTaskUserCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1874. {
  1875. int8_t *pcParameterString;
  1876. signed portBASE_TYPE xParameterStringLength, xReturn;
  1877. portBASE_TYPE xParameterNumber = 1;
  1878. uint8_t i;
  1879. char temp_str[MAX_WEB_LOGIN_LEN];
  1880. char WebLogin[MAX_WEB_LOGIN_LEN];
  1881. uint8_t valueLen, user_id;
  1882. const int8_t *const pcChangePWDHeader = ( int8_t * ) "\r\nВведите новый пароль:";
  1883. ( void ) pcCommandString;
  1884. ( void ) xWriteBufferLen;
  1885. configASSERT( pcWriteBuffer );
  1886. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1887. if (cli_state->user_id != ADMIN) {
  1888. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1889. return pdFALSE;
  1890. }
  1891. /* Obtain the parameter string. */
  1892. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1893. (
  1894. pcCommandString, /* The command string itself. */
  1895. xParameterNumber, /* Return the next parameter. */
  1896. &xParameterStringLength /* Store the parameter string length. */
  1897. );
  1898. if (pcParameterString == NULL) {
  1899. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1900. return pdFALSE;
  1901. }
  1902. for (i = 0; i < ARG_USER_ALL; i ++) {
  1903. if ( strncmp( ( const char * ) pcParameterString, user_args_list[i], strlen(user_args_list[i]) ) == 0 ) {
  1904. break;
  1905. }
  1906. }
  1907. xParameterNumber ++;
  1908. /* Obtain the parameter string. */
  1909. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1910. (
  1911. pcCommandString, /* The command string itself. */
  1912. xParameterNumber, /* Return the next parameter. */
  1913. &xParameterStringLength /* Store the parameter string length. */
  1914. );
  1915. if (i == ARG_USER_PWD) {
  1916. memset(temp_str, 0, sizeof(temp_str));
  1917. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1918. if (xParameterStringLength > (int32_t)sizeof(temp_str)) {
  1919. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1920. } else {
  1921. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1922. for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
  1923. GetUserLogin(user_id, WebLogin, &valueLen);
  1924. /* Check login and password */
  1925. if (strncmp(WebLogin, temp_str, MAX_WEB_LOGIN_LEN) == 0) {
  1926. /* Login and pass are valid */
  1927. cli_state->id_change_pwd = user_id;
  1928. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcChangePWDHeader, strlen( ( char * ) pcChangePWDHeader ) );
  1929. cli_state->input_state = CLI_CHANGE_PWD;
  1930. break;
  1931. }
  1932. }
  1933. if (cli_state->input_state != CLI_CHANGE_PWD) {
  1934. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1935. }
  1936. }
  1937. } else {
  1938. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1939. }
  1940. xReturn = pdFALSE;
  1941. return xReturn;
  1942. }
  1943. /*
  1944. * Implements the config command.
  1945. */
  1946. static portBASE_TYPE prvTaskConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  1947. const int8_t *pcCommandString )
  1948. {
  1949. int8_t *pcParameterString;
  1950. signed portBASE_TYPE xParameterStringLength, xReturn;
  1951. portBASE_TYPE xParameterNumber = 1;
  1952. char str[110];
  1953. uint8_t i;
  1954. static uint8_t config_menu = 0;
  1955. const int8_t *const pcInfoTableHeader = ( int8_t * )
  1956. "\r\n*********Конфигурация Контроллера*********\r\n";
  1957. ( void ) pcCommandString;
  1958. ( void ) xWriteBufferLen;
  1959. configASSERT( pcWriteBuffer );
  1960. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1961. /* Obtain the parameter string. */
  1962. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1963. (
  1964. pcCommandString, /* The command string itself. */
  1965. xParameterNumber, /* Return the next parameter. */
  1966. &xParameterStringLength /* Store the parameter string length. */
  1967. );
  1968. if (pcParameterString == NULL) {
  1969. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1970. return pdFALSE;
  1971. }
  1972. for (i = 0; i < ARG_CONFIG_ALL; i ++) {
  1973. if ( strncmp( ( const char * ) pcParameterString, config_args_list[i], strlen(config_args_list[i]) ) == 0
  1974. && xParameterStringLength == strlen(config_args_list[i])) {
  1975. break;
  1976. }
  1977. }
  1978. if (cli_state->user_id != ADMIN && i != ARG_CONFIG_INFO) {
  1979. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1980. return pdFALSE;
  1981. }
  1982. xParameterNumber ++;
  1983. /* Obtain the parameter string. */
  1984. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1985. (
  1986. pcCommandString, /* The command string itself. */
  1987. xParameterNumber, /* Return the next parameter. */
  1988. &xParameterStringLength /* Store the parameter string length. */
  1989. );
  1990. if (pcParameterString == NULL) {
  1991. switch (i) {
  1992. case ARG_CONFIG_INFO:
  1993. switch (config_menu) {
  1994. case PARAM_CONFIG_SNMP:
  1995. /* Return the next command help string, before moving the pointer on to
  1996. the next command in the list. */
  1997. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  1998. snmp_config_param(pcWriteBuffer);
  1999. break;
  2000. #ifdef DINS_ENABLE || DOUTS_ENABLE
  2001. case PARAM_CONFIG_INOUTS:
  2002. inouts_config_param(pcWriteBuffer);
  2003. break;
  2004. #endif
  2005. case PARAM_CONFIG_AKB:
  2006. akb_config_param(pcWriteBuffer);
  2007. break;
  2008. case PARAM_CONFIG_ALARM:
  2009. alarm_config_param(pcWriteBuffer);
  2010. break;
  2011. #ifdef WHITELIST_ENABLE
  2012. case PARAM_CONFIG_WHITELIST:
  2013. whitelist_config_param(pcWriteBuffer);
  2014. break;
  2015. #endif
  2016. case PARAM_CONFIG_NET:
  2017. net_config_param(pcWriteBuffer);
  2018. break;
  2019. case PARAM_CONFIG_TIME:
  2020. time_config_param(pcWriteBuffer);
  2021. break;
  2022. }
  2023. config_menu ++;
  2024. if (config_menu == PARAM_CONFIG_ALL) {
  2025. config_menu = 0;
  2026. return pdFALSE;
  2027. } else {
  2028. return pdTRUE;
  2029. }
  2030. break;
  2031. default:
  2032. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2033. break;
  2034. }
  2035. return pdFALSE;
  2036. }
  2037. if (i == ARG_CONFIG_LOAD) {
  2038. memset(str, 0, sizeof(str));
  2039. xParameterStringLength = strlen(( const char * ) pcParameterString);
  2040. if (xParameterStringLength > (int32_t)sizeof(str)) {
  2041. xParameterStringLength = sizeof(str) - 1;
  2042. }
  2043. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2044. if (xParameterStringLength < 13) {
  2045. if (strncmp(str, "default", 7) == 0) {
  2046. SNMP_SendUserTrap(DEVICE_RESTORED);
  2047. log_event_data(LOG_SYSTEM_DEFCONFIG, "Администратор");
  2048. vTaskDelay(500);
  2049. SETTINGS_SetPartDefault();
  2050. cli_save_config(cli_state);
  2051. strcpy( ( char * ) pcWriteBuffer,
  2052. "\t\tНастройки сброшены к настройкам по умолчанию!\r\n");
  2053. } else {
  2054. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2055. }
  2056. } else {
  2057. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2058. }
  2059. } else {
  2060. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2061. }
  2062. xReturn = pdFALSE;
  2063. return xReturn;
  2064. }
  2065. /*
  2066. * Implements the config command.
  2067. */
  2068. static portBASE_TYPE prvTaskNetConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2069. const int8_t *pcCommandString )
  2070. {
  2071. int8_t *pcParameterString;
  2072. portBASE_TYPE xParameterNumber = 1;
  2073. signed portBASE_TYPE xParameterStringLength;
  2074. uint8_t i;
  2075. static start = 0;
  2076. ( void ) pcCommandString;
  2077. ( void ) xWriteBufferLen;
  2078. configASSERT( pcWriteBuffer );
  2079. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2080. /* Obtain the parameter string. */
  2081. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2082. (
  2083. pcCommandString, /* The command string itself. */
  2084. xParameterNumber, /* Return the next parameter. */
  2085. &xParameterStringLength /* Store the parameter string length. */
  2086. );
  2087. for (i = 0; i < ARG_NETCONFIG_ALL; i ++) {
  2088. if ( strncmp( ( const char * ) pcParameterString, netconfig_args_list[i], strlen(netconfig_args_list[i]) ) == 0
  2089. && xParameterStringLength == strlen(netconfig_args_list[i])) {
  2090. break;
  2091. }
  2092. }
  2093. if (cli_state->user_id != ADMIN) {
  2094. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2095. return pdFALSE;
  2096. }
  2097. switch (i) {
  2098. case ARG_NETCONFIG_APPLY:
  2099. if (!start) {
  2100. /* Если параметры WEB изменились выставляем флаг, сохраняем настройки и перезагружаемся */
  2101. if (GetStateWebReinit() == true) {
  2102. start = 1;
  2103. SetWebReinitFlag(true);
  2104. cli_save_config(cli_state);
  2105. strcpy( ( char * ) pcWriteBuffer,
  2106. "\t\tНастройки сохранены! Контроллер будет перезагружен\r\n\tПосле перезагрузки подтвердите изменения сетевых настроек\r\n");
  2107. return pdTRUE;
  2108. }
  2109. } else {
  2110. start = 0;
  2111. vTaskDelay(1010);
  2112. Reboot(CLI_ACT);
  2113. }
  2114. break;
  2115. case ARG_NETCONFIG_CONFIRM:
  2116. SetWebReinitFlag(false);
  2117. SetConfirmWebParamsFlag();
  2118. strcpy( ( char * ) pcWriteBuffer, "\t\tСетевые настройки подтверждены!\r\n");
  2119. break;
  2120. default:
  2121. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2122. break;
  2123. }
  2124. return pdFALSE;
  2125. }
  2126. /*
  2127. * Implements the history command.
  2128. */
  2129. static portBASE_TYPE prvTaskHistoryCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2130. const int8_t *pcCommandString )
  2131. {
  2132. int8_t *pcParameterString;
  2133. signed portBASE_TYPE xParameterStringLength, xReturn;
  2134. portBASE_TYPE xParameterNumber = 1;
  2135. char str[110];
  2136. uint8_t i;
  2137. static int16_t num_page = 0;
  2138. static int16_t num_page_temp = 1;
  2139. static bool start = true;
  2140. const int8_t *const pcUPShistoryTableHeader = ( int8_t * )
  2141. "\r\n***********Журнал событий ИБП***********\r\n";
  2142. const int8_t *const pcControllerHistoryTableHeader = ( int8_t * )
  2143. "\r\n***********Журнал событий Контроллера***********\r\n";
  2144. ( void ) pcCommandString;
  2145. ( void ) xWriteBufferLen;
  2146. configASSERT( pcWriteBuffer );
  2147. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2148. /* Obtain the parameter string. */
  2149. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2150. (
  2151. pcCommandString, /* The command string itself. */
  2152. xParameterNumber, /* Return the next parameter. */
  2153. &xParameterStringLength /* Store the parameter string length. */
  2154. );
  2155. if (pcParameterString == NULL) {
  2156. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2157. return pdFALSE;
  2158. }
  2159. if ( strncmp( ( const char * ) pcParameterString, "show", xParameterStringLength ) != 0 ) {
  2160. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2161. return pdFALSE;
  2162. }
  2163. xParameterNumber ++;
  2164. /* Obtain the parameter string. */
  2165. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2166. (
  2167. pcCommandString, /* The command string itself. */
  2168. xParameterNumber, /* Return the next parameter. */
  2169. &xParameterStringLength /* Store the parameter string length. */
  2170. );
  2171. for (i = 0; i < ARG_HISTORY_ALL; i ++) {
  2172. if ( strncmp( ( const char * ) pcParameterString, history_args_list[i], strlen(history_args_list[i]) ) == 0
  2173. && xParameterStringLength == strlen(history_args_list[i])) {
  2174. break;
  2175. }
  2176. }
  2177. xParameterNumber ++;
  2178. /* Obtain the parameter string. */
  2179. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2180. (
  2181. pcCommandString, /* The command string itself. */
  2182. xParameterNumber, /* Return the next parameter. */
  2183. &xParameterStringLength /* Store the parameter string length. */
  2184. );
  2185. memset(str, 0, sizeof(str));
  2186. if (xParameterStringLength > 5) {
  2187. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2188. return pdFALSE;
  2189. }
  2190. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2191. if (num_page == 0) {
  2192. num_page = atoi(str);
  2193. if (num_page <= 0) {
  2194. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2195. return pdFALSE;
  2196. }
  2197. }
  2198. switch (i) {
  2199. case ARG_HISTORY_EVENTS:
  2200. if (start) {
  2201. start = false;
  2202. /* Return the next command help string, before moving the pointer on to
  2203. the next command in the list. */
  2204. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcControllerHistoryTableHeader,
  2205. strlen( ( char * ) pcControllerHistoryTableHeader ) );
  2206. memset(str, 0, sizeof(str));
  2207. strcat(( char * ) pcWriteBuffer, "\r\n");
  2208. sprintf(str, "Количество страниц журнала: %d\r\n", History_GetPageCount());
  2209. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  2210. strcat(( char * ) pcWriteBuffer, "\r\n");
  2211. if (num_page > History_GetPageCount()) {
  2212. num_page = History_GetPageCount();
  2213. }
  2214. }
  2215. History_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  2216. num_page --;
  2217. num_page_temp ++;
  2218. if (num_page == 0) {
  2219. num_page = 0;
  2220. num_page_temp = 1;
  2221. start = true;
  2222. xReturn = pdFALSE;
  2223. } else {
  2224. xReturn = pdTRUE;
  2225. }
  2226. break;
  2227. case ARG_HISTORY_UPS:
  2228. if (start) {
  2229. start = false;
  2230. /* Return the next command help string, before moving the pointer on to
  2231. the next command in the list. */
  2232. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcUPShistoryTableHeader,
  2233. strlen( ( char * ) pcUPShistoryTableHeader ) );
  2234. memset(str, 0, sizeof(str));
  2235. sprintf(str, "Количество страниц журнала: %d\r\n", LOG_GetPageCount());
  2236. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  2237. if (num_page > LOG_GetPageCount()) {
  2238. num_page = LOG_GetPageCount();
  2239. }
  2240. }
  2241. LOG_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  2242. num_page --;
  2243. num_page_temp ++;
  2244. if (num_page == 0) {
  2245. num_page = 0;
  2246. num_page_temp = 1;
  2247. start = true;
  2248. xReturn = pdFALSE;
  2249. } else {
  2250. xReturn = pdTRUE;
  2251. }
  2252. break;
  2253. default:
  2254. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2255. xReturn = pdFALSE;
  2256. break;
  2257. }
  2258. return xReturn;
  2259. }
  2260. /*
  2261. * Implements the sensor info command.
  2262. */
  2263. static portBASE_TYPE prvTaskSensorCommand(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. uint8_t i;
  2270. char str[10];
  2271. char temp_str[10];
  2272. int32_t val = 0, val2 = 0;
  2273. uint8_t fail = 0;
  2274. static uint8_t config_menu = 0;
  2275. uint8_t MAX_CONFIG_PARAM = 0;
  2276. #ifdef DINS_ENABLE || DOUTS_ENABLE
  2277. MAX_CONFIG_PARAM = 3;
  2278. #else
  2279. MAX_CONFIG_PARAM = 2;
  2280. #endif
  2281. const int8_t *const pcSensorTableHeader = ( int8_t * )
  2282. "\r\n*********Параметры Контроллера*********\r\n";
  2283. ( void ) pcCommandString;
  2284. ( void ) xWriteBufferLen;
  2285. configASSERT( pcWriteBuffer );
  2286. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2287. /* Obtain the parameter string. */
  2288. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2289. (
  2290. pcCommandString, /* The command string itself. */
  2291. xParameterNumber, /* Return the next parameter. */
  2292. &xParameterStringLength /* Store the parameter string length. */
  2293. );
  2294. if (pcParameterString == NULL) {
  2295. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2296. return pdFALSE;
  2297. }
  2298. for (i = 0; i < ARG_SENSOR_ALL; i ++) {
  2299. if ( strncmp( ( const char * ) pcParameterString, sensor_args_list[i], strlen(sensor_args_list[i]) ) == 0
  2300. && xParameterStringLength == strlen(sensor_args_list[i])) {
  2301. break;
  2302. }
  2303. }
  2304. xParameterNumber ++;
  2305. /* Obtain the parameter string. */
  2306. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2307. (
  2308. pcCommandString, /* The command string itself. */
  2309. xParameterNumber, /* Return the next parameter. */
  2310. &xParameterStringLength /* Store the parameter string length. */
  2311. );
  2312. if (pcParameterString == NULL) {
  2313. if (i == ARG_SENSOR_INFO) {
  2314. switch (config_menu) {
  2315. case 0:
  2316. /* Return the next command help string, before moving the pointer on to
  2317. the next command in the list. */
  2318. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSensorTableHeader, strlen( ( char * ) pcSensorTableHeader ) );
  2319. ups_sensor_param(pcWriteBuffer);
  2320. break;
  2321. case 1:
  2322. ups_sensor_akb_param(pcWriteBuffer);
  2323. break;
  2324. #ifdef DINS_ENABLE || DOUTS_ENABLE
  2325. case 2:
  2326. inouts_sensor_param(pcWriteBuffer);
  2327. break;
  2328. #endif
  2329. }
  2330. config_menu ++;
  2331. if (config_menu == MAX_CONFIG_PARAM) {
  2332. config_menu = 0;
  2333. return pdFALSE;
  2334. } else {
  2335. return pdTRUE;
  2336. }
  2337. } else {
  2338. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2339. }
  2340. } else {
  2341. switch (i) {
  2342. #ifdef DINS_ENABLE || DOUTS_ENABLE
  2343. case ARG_SENSOR_SETUP:
  2344. if (cli_state->user_id != ADMIN) {
  2345. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2346. return pdFALSE;
  2347. }
  2348. memset(str, 0, sizeof(str));
  2349. if (xParameterStringLength > (int32_t)sizeof(str)) {
  2350. xParameterStringLength = sizeof(str) - 1;
  2351. }
  2352. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2353. if (xParameterStringLength < 3) {
  2354. xParameterNumber ++;
  2355. /* Obtain the parameter string. */
  2356. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2357. (
  2358. pcCommandString, /* The command string itself. */
  2359. xParameterNumber, /* Return the next parameter. */
  2360. &xParameterStringLength /* Store the parameter string length. */
  2361. );
  2362. memset(temp_str, 0, sizeof(str));
  2363. if (xParameterStringLength > 1) {
  2364. fail = 1;
  2365. break;
  2366. }
  2367. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2368. if (!isdigit_int(temp_str[0])) {
  2369. fail = 1;
  2370. break;
  2371. }
  2372. val = atoi(temp_str);
  2373. xParameterNumber ++;
  2374. /* Obtain the parameter string. */
  2375. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2376. (
  2377. pcCommandString, /* The command string itself. */
  2378. xParameterNumber, /* Return the next parameter. */
  2379. &xParameterStringLength /* Store the parameter string length. */
  2380. );
  2381. memset(temp_str, 0, sizeof(str));
  2382. if (xParameterStringLength > 1) {
  2383. fail = 1;
  2384. break;
  2385. }
  2386. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2387. if (!isdigit_int(temp_str[0])) {
  2388. fail = 1;
  2389. break;
  2390. }
  2391. fail = 1;
  2392. #ifdef DINS_ENABLE
  2393. if (strncmp(str, "DI", 2) == 0) {
  2394. if (val != 1) {
  2395. break;
  2396. }
  2397. val2 = atoi(temp_str);
  2398. if (val2 < 0 || val2 > 1) {
  2399. break;
  2400. }
  2401. SetDINTypeActStr(temp_str, (val - 1));
  2402. cli_save_config(cli_state);
  2403. fail = 0;
  2404. }
  2405. #endif
  2406. #ifdef DOUTS_ENABLE
  2407. if (strncmp(str, "DO", 2) == 0) {
  2408. if (val < 1 || val > 3) {
  2409. break;
  2410. }
  2411. val2 = atoi(temp_str);
  2412. if (val2 < 1 || val2 > 5) {
  2413. break;
  2414. }
  2415. SetROTypeActStr(temp_str, (val - 1));
  2416. cli_save_config(cli_state);
  2417. fail = 0;
  2418. }
  2419. }
  2420. #endif
  2421. break;
  2422. #endif
  2423. default:
  2424. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2425. break;
  2426. }
  2427. }
  2428. if (fail) {
  2429. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2430. }
  2431. xReturn = pdFALSE;
  2432. return xReturn;
  2433. }
  2434. /*
  2435. * Implements the firmware download http command.
  2436. */
  2437. static portBASE_TYPE prvTaskUploadCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2438. const int8_t *pcCommandString )
  2439. {
  2440. static bool start_update = true;
  2441. const int8_t *const pcUploadHeader = ( int8_t * )
  2442. "Контроллер переводится в режим загрузчика\r\n";
  2443. ( void ) pcCommandString;
  2444. ( void ) xWriteBufferLen;
  2445. if (cli_state->user_id != ADMIN) {
  2446. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2447. return pdFALSE;
  2448. }
  2449. if (start_update) {
  2450. start_update = false;
  2451. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcUploadHeader );
  2452. return pdTRUE;
  2453. } else {
  2454. HTTP_StartResetTask(true);
  2455. return pdFALSE;
  2456. }
  2457. }
  2458. /*
  2459. * Implements the ups command.
  2460. */
  2461. static portBASE_TYPE prvTaskUPSCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  2462. {
  2463. int8_t *pcParameterString;
  2464. signed portBASE_TYPE xParameterStringLength, xReturn;
  2465. portBASE_TYPE xParameterNumber = 1;
  2466. char str[110];
  2467. int32_t val = 0;
  2468. float val_float = 0;
  2469. int8_t res = 0;
  2470. uint8_t i;
  2471. ( void ) pcCommandString;
  2472. ( void ) xWriteBufferLen;
  2473. configASSERT( pcWriteBuffer );
  2474. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2475. if (cli_state->user_id != ADMIN && i != ARG_CONFIG_INFO) {
  2476. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2477. return pdFALSE;
  2478. }
  2479. /* Obtain the parameter string. */
  2480. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2481. (
  2482. pcCommandString, /* The command string itself. */
  2483. xParameterNumber, /* Return the next parameter. */
  2484. &xParameterStringLength /* Store the parameter string length. */
  2485. );
  2486. for (i = 0; i < ARG_UPS_ALL; i ++) {
  2487. if ( strncmp( ( const char * ) pcParameterString, ups_args_list[i], strlen(ups_args_list[i]) ) == 0
  2488. && xParameterStringLength == strlen(ups_args_list[i])) {
  2489. break;
  2490. }
  2491. }
  2492. xParameterNumber ++;
  2493. /* Obtain the parameter string. */
  2494. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2495. (
  2496. pcCommandString, /* The command string itself. */
  2497. xParameterNumber, /* Return the next parameter. */
  2498. &xParameterStringLength /* Store the parameter string length. */
  2499. );
  2500. memset(str, 0, sizeof(str));
  2501. if (xParameterStringLength > 3) {
  2502. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2503. return pdFALSE;
  2504. }
  2505. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2506. switch (i) {
  2507. case ARG_UPS_BATTEST:
  2508. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  2509. if (!isdigit_int(str[j])) {
  2510. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2511. return pdFALSE;
  2512. }
  2513. }
  2514. val = atoi(str);
  2515. if (val == 0) {
  2516. res = ups_metac_service_pdu(ups_cancel_test);
  2517. set_act_source(CLI_ACT);
  2518. if (res == 1) {
  2519. log_event_data(LOG_TEST_UPS, "Администратор (Останов)");
  2520. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Останов теста\" принята ИБП!\r\n");
  2521. } else {
  2522. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Останов теста\" отклонена ИБП!\r\n");
  2523. }
  2524. } else if (val > 0 && val < 100) {
  2525. TimeParam = val;
  2526. res = ups_metac_service_pdu(ups_test_time);
  2527. if (res == 1) {
  2528. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2529. } else {
  2530. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2531. }
  2532. } else if (val == 100) {
  2533. res = ups_metac_service_pdu(ups_test_10sec);
  2534. if (res == 1) {
  2535. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2536. } else {
  2537. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2538. }
  2539. } else if (val == 999) {
  2540. res = ups_metac_service_pdu(ups_test_low_bat);
  2541. if (res == 1) {
  2542. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2543. } else {
  2544. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2545. }
  2546. } else {
  2547. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2548. }
  2549. break;
  2550. case ARG_UPS_SHUTDOWN:
  2551. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  2552. if (!isfloatdigit(str[j])) {
  2553. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2554. return pdFALSE;
  2555. }
  2556. }
  2557. val_float = atof(str);
  2558. if (val_float == 0) {
  2559. res = ups_metac_service_pdu(ups_cancel_shut_down);
  2560. if (res == 1) {
  2561. log_event_data(LOG_SHUTDOWN_UPS, "Администратор (Останов)");
  2562. strcpy( ( char * ) pcWriteBuffer, "\t\t\tВыключение нагрузки ИБП отменено!\r\n");
  2563. } else {
  2564. strcpy( ( char * ) pcWriteBuffer,
  2565. "\t\tВыключение нагрузки ИБП не удалось отменить!\r\n");
  2566. }
  2567. } else if (val_float > 0 && val_float <= 10) {
  2568. TimeParamFloat = val_float;
  2569. res = ups_metac_service_pdu(ups_shutdown);
  2570. if (res == 1) {
  2571. log_event_data(LOG_SHUTDOWN_UPS, "Администратор");
  2572. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП!\r\n");
  2573. } else {
  2574. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП не удалось!\r\n");
  2575. }
  2576. } else {
  2577. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2578. }
  2579. break;
  2580. default:
  2581. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2582. break;
  2583. }
  2584. xReturn = pdFALSE;
  2585. return xReturn;
  2586. }
  2587. /*-----------------------------------------------------------*/