CLI_Commands.c 119 KB

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