CLI_Commands.c 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825
  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. SNTP_Init();
  831. //vTaskDelay(7000);
  832. SNTP_Poll();
  833. }
  834. break;
  835. case ARG_NTP_DISABLE:
  836. enable_old_sntp = sSettings.sSNTP.sntpEnable;
  837. SetSntpStateStr("0");
  838. if (sSettings.sSNTP.sntpEnable != enable_old_sntp) {
  839. cli_save_config(cli_state);
  840. SNTP_Init();
  841. //vTaskDelay(7000);
  842. SNTP_Poll();
  843. }
  844. break;
  845. case ARG_NTP_INFO:
  846. /* Return the next command help string, before moving the pointer on to
  847. the next command in the list. */
  848. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  849. GetSntpStateStrRU(str, &len);
  850. strcat(( char * ) pcWriteBuffer, "Режим установки времени:\t");
  851. strncat(( char * ) pcWriteBuffer, str, len);
  852. strcat(( char * ) pcWriteBuffer, "\r\nIP адрес NTP сервера:\t\t");
  853. GetSntpServerIpStr(str, &len);
  854. strncat(( char * ) pcWriteBuffer, str, len);
  855. strcat(( char * ) pcWriteBuffer, "\r\nЧасовой пояс:\t\t\t");
  856. GetSntpTimeZoneStr(str, &len);
  857. strncat(( char * ) pcWriteBuffer, str, len);
  858. strcat(( char * ) pcWriteBuffer, "\r\nПоследняя дата синхронизации:\t");
  859. GetSntpLastDataStr(str, &len);
  860. strncat(( char * ) pcWriteBuffer, str, len);
  861. strcat(( char * ) pcWriteBuffer, "\r\n");
  862. break;
  863. default:
  864. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  865. break;
  866. }
  867. return pdFALSE;
  868. }
  869. if (i == ARG_NTP_SET) {
  870. memset(str, 0, sizeof(str));
  871. if (xParameterStringLength > (int32_t)sizeof(str)) {
  872. xParameterStringLength = sizeof(str) - 1;
  873. }
  874. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  875. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  876. (
  877. pcCommandString, /* The command string itself. */
  878. xParameterNumber, /* Return the next parameter. */
  879. &xParameterStringLength /* Store the parameter string length. */
  880. );
  881. if (pcParameterString != NULL) {
  882. memset(str_temp, 0, sizeof(str_temp));
  883. if (xParameterStringLength > (int32_t)sizeof(str_temp)) {
  884. xParameterStringLength = sizeof(str_temp) - 1;
  885. }
  886. strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
  887. if (strncmp(str, "IP", 2) == 0) {
  888. if (xParameterStringLength <= 15) {
  889. if (ipaddr_addr(str_temp) != IPADDR_NONE) {
  890. if (strncmp(str_temp, sSettings.sSNTP.ip, strlen(str_temp)) != 0) {
  891. SetSntpServerIpStr(str_temp);
  892. cli_save_config(cli_state);
  893. SNTP_Init();
  894. //vTaskDelay(7000);
  895. SNTP_Poll();
  896. }
  897. } else {
  898. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  899. }
  900. } else {
  901. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  902. }
  903. } else if (strncmp(str, "gmt", 3) == 0) {
  904. if (xParameterStringLength > 1 && xParameterStringLength < 5) {
  905. bool fail = false;
  906. if (str_temp[0] != '-' && str_temp[0] != '+') {
  907. fail = true;
  908. }
  909. if (!isdigit_int(str_temp[1]) && (!isdigit_int(str_temp[2]) && str_temp[2] != '.') && (!isdigit_int(str_temp[3]) &&
  910. str_temp[3] != '.')) {
  911. fail = true;
  912. }
  913. if (xParameterStringLength == 5) {
  914. if (!isdigit_int(str_temp[4])) {
  915. fail = true;
  916. }
  917. }
  918. if (!fail) {
  919. float value = atof(str_temp);
  920. if (value >= -12.0 && value <= 12.0) {
  921. SetSntpTimeZoneStr(str_temp);
  922. cli_save_config(cli_state);
  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. } else {
  933. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  934. }
  935. } else {
  936. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  937. }
  938. } else {
  939. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  940. }
  941. xReturn = pdFALSE;
  942. return xReturn;
  943. }
  944. /*
  945. * Implements the network command.
  946. */
  947. static portBASE_TYPE prvTaskNetworkCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  948. const int8_t *pcCommandString )
  949. {
  950. int8_t *pcParameterString;
  951. signed portBASE_TYPE xParameterStringLength, xReturn;
  952. portBASE_TYPE xParameterNumber = 1;
  953. char str[110];
  954. uint8_t i;
  955. ( void ) pcCommandString;
  956. ( void ) xWriteBufferLen;
  957. configASSERT( pcWriteBuffer );
  958. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  959. /* Obtain the parameter string. */
  960. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  961. (
  962. pcCommandString, /* The command string itself. */
  963. xParameterNumber, /* Return the next parameter. */
  964. &xParameterStringLength /* Store the parameter string length. */
  965. );
  966. if (pcParameterString == NULL) {
  967. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  968. return pdFALSE;
  969. }
  970. for (i = 0; i < ARG_NETWORK_ALL; i ++) {
  971. if ( strncmp( ( const char * ) pcParameterString, network_args_list[i], strlen(network_args_list[i]) ) == 0
  972. && xParameterStringLength == strlen(network_args_list[i])) {
  973. break;
  974. }
  975. }
  976. if (cli_state->user_id != ADMIN && i != ARG_NETWORK_INFO) {
  977. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  978. return pdFALSE;
  979. }
  980. if (i != ARG_NETWORK_ALL && i != ARG_NETWORK_DHCP && i != ARG_NETWORK_INFO) {
  981. if (sSettings.sWebTempParams.dhcpEnable) {
  982. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  983. return pdFALSE;
  984. }
  985. }
  986. xParameterNumber ++;
  987. /* Obtain the parameter string. */
  988. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  989. (
  990. pcCommandString, /* The command string itself. */
  991. xParameterNumber, /* Return the next parameter. */
  992. &xParameterStringLength /* Store the parameter string length. */
  993. );
  994. if (pcParameterString == NULL) {
  995. if (i == ARG_NETWORK_INFO) {
  996. net_config_param(pcWriteBuffer);
  997. } else {
  998. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  999. }
  1000. return pdFALSE;
  1001. }
  1002. memset(str, 0, sizeof(str));
  1003. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1004. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1005. xParameterStringLength = sizeof(str) - 1;
  1006. }
  1007. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1008. switch (i) {
  1009. case ARG_NETWORK_DHCP:
  1010. if (strncmp(str, "ENA", 3) == 0) {
  1011. SetUDPDhcpStateStr("True");
  1012. strcpy( ( char * ) pcWriteBuffer,
  1013. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1014. } else if (strncmp(str, "DIS", 3) == 0) {
  1015. SetUDPDhcpStateStr("False");
  1016. strcpy( ( char * ) pcWriteBuffer,
  1017. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1018. } else {
  1019. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1020. }
  1021. break;
  1022. case ARG_NETWORK_IP:
  1023. if (xParameterStringLength <= 15) {
  1024. if (ipaddr_addr(str) != IPADDR_NONE) {
  1025. SetIPStr(str);
  1026. strcpy( ( char * ) pcWriteBuffer,
  1027. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1028. } else {
  1029. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1030. }
  1031. } else {
  1032. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1033. }
  1034. break;
  1035. case ARG_NETWORK_GW:
  1036. if (xParameterStringLength <= 15) {
  1037. if (ipaddr_addr(str) != IPADDR_NONE) {
  1038. SetGatewayStr(str);
  1039. strcpy( ( char * ) pcWriteBuffer,
  1040. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1041. } else {
  1042. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1043. }
  1044. } else {
  1045. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1046. }
  1047. break;
  1048. case ARG_NETWORK_MASK:
  1049. if (xParameterStringLength <= 15) {
  1050. if (ipaddr_addr(str) != IPADDR_NONE) {
  1051. SetMaskStr(str);
  1052. strcpy( ( char * ) pcWriteBuffer,
  1053. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1054. } else {
  1055. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1056. }
  1057. } else {
  1058. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1059. }
  1060. break;
  1061. default:
  1062. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1063. break;
  1064. }
  1065. xReturn = pdFALSE;
  1066. return xReturn;
  1067. }
  1068. /*
  1069. * Implements the snmp command.
  1070. */
  1071. static portBASE_TYPE prvTaskSNMPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1072. {
  1073. int8_t *pcParameterString;
  1074. signed portBASE_TYPE xParameterStringLength, xReturn;
  1075. portBASE_TYPE xParameterNumber = 1;
  1076. char str[20];
  1077. char temp_str[20];
  1078. uint8_t i;
  1079. ( void ) pcCommandString;
  1080. ( void ) xWriteBufferLen;
  1081. configASSERT( pcWriteBuffer );
  1082. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1083. /* Obtain the parameter string. */
  1084. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1085. (
  1086. pcCommandString, /* The command string itself. */
  1087. xParameterNumber, /* Return the next parameter. */
  1088. &xParameterStringLength /* Store the parameter string length. */
  1089. );
  1090. if (pcParameterString == NULL) {
  1091. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1092. return pdFALSE;
  1093. }
  1094. for (i = 0; i < ARG_SNMP_ALL; i ++) {
  1095. if ( strncmp( ( const char * ) pcParameterString, snmp_args_list[i], strlen(snmp_args_list[i]) ) == 0
  1096. && xParameterStringLength == strlen(snmp_args_list[i])) {
  1097. break;
  1098. }
  1099. }
  1100. if (cli_state->user_id != ADMIN && i != ARG_SNMP_INFO) {
  1101. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1102. return pdFALSE;
  1103. }
  1104. xParameterNumber ++;
  1105. /* Obtain the parameter string. */
  1106. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1107. (
  1108. pcCommandString, /* The command string itself. */
  1109. xParameterNumber, /* Return the next parameter. */
  1110. &xParameterStringLength /* Store the parameter string length. */
  1111. );
  1112. xParameterNumber ++;
  1113. if (pcParameterString == NULL) {
  1114. if (i == ARG_SNMP_INFO) {
  1115. snmp_config_param(pcWriteBuffer);
  1116. } else {
  1117. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1118. }
  1119. return pdFALSE;
  1120. }
  1121. memset(str, 0, sizeof(str));
  1122. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1123. xParameterStringLength = sizeof(str) - 1;
  1124. }
  1125. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1126. switch (i) {
  1127. case ARG_SNMP_SERVER:
  1128. if (xParameterStringLength == 1 && isdigit_int(str[0])) {
  1129. int32_t temp = atoi(str);
  1130. if (temp > 0 && temp < 6) {
  1131. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1132. (
  1133. pcCommandString, /* The command string itself. */
  1134. xParameterNumber, /* Return the next parameter. */
  1135. &xParameterStringLength /* Store the parameter string length. */
  1136. );
  1137. if (pcParameterString != NULL) {
  1138. memset(str, 0, sizeof(str));
  1139. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1140. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1141. xParameterStringLength = sizeof(str) - 1;
  1142. }
  1143. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1144. if (xParameterStringLength <= 15) {
  1145. if (ipaddr_addr(str) != IPADDR_NONE) {
  1146. switch (temp) {
  1147. case 1:
  1148. SetManagerIp(str);
  1149. break;
  1150. case 2:
  1151. SetManagerIp2(str);
  1152. break;
  1153. case 3:
  1154. SetManagerIp3(str);
  1155. break;
  1156. case 4:
  1157. SetManagerIp4(str);
  1158. break;
  1159. case 5:
  1160. SetManagerIp5(str);
  1161. break;
  1162. }
  1163. if (temp > 0 && temp < 6) {
  1164. cli_save_config(cli_state);
  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. } else {
  1173. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1174. }
  1175. } else {
  1176. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1177. }
  1178. } else {
  1179. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1180. }
  1181. break;
  1182. case ARG_SNMP_COMMUNITY:
  1183. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1184. (
  1185. pcCommandString, /* The command string itself. */
  1186. xParameterNumber, /* Return the next parameter. */
  1187. &xParameterStringLength /* Store the parameter string length. */
  1188. );
  1189. if (pcParameterString != NULL) {
  1190. memset(temp_str, 0, sizeof(temp_str));
  1191. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1192. if (xParameterStringLength > (int32_t)sizeof(temp_str)) {
  1193. xParameterStringLength = sizeof(temp_str) - 1;
  1194. }
  1195. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1196. if (control_string_en_digit(temp_str, strlen(temp_str))) {
  1197. if (strncmp(str, "read", 4) == 0) {
  1198. SetReadCommunity(temp_str);
  1199. cli_save_config(cli_state);
  1200. } else if (strncmp(str, "write", 5) == 0) {
  1201. SetWriteCommunity(temp_str);
  1202. cli_save_config(cli_state);
  1203. } else {
  1204. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1205. }
  1206. } else {
  1207. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1208. }
  1209. } else {
  1210. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1211. }
  1212. break;
  1213. default:
  1214. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1215. break;
  1216. }
  1217. xReturn = pdFALSE;
  1218. return xReturn;
  1219. }
  1220. /*
  1221. * Implements the akb command.
  1222. */
  1223. static portBASE_TYPE prvTaskAKBCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1224. {
  1225. int8_t *pcParameterString;
  1226. signed portBASE_TYPE xParameterStringLength, xReturn;
  1227. portBASE_TYPE xParameterNumber = 1;
  1228. char str[110];
  1229. uint8_t i;
  1230. uint8_t fail = 0;
  1231. uint16_t temp = 0;
  1232. float value = 0;
  1233. ( void ) pcCommandString;
  1234. ( void ) xWriteBufferLen;
  1235. configASSERT( pcWriteBuffer );
  1236. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1237. /* Obtain the parameter string. */
  1238. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1239. (
  1240. pcCommandString, /* The command string itself. */
  1241. xParameterNumber, /* Return the next parameter. */
  1242. &xParameterStringLength /* Store the parameter string length. */
  1243. );
  1244. if (pcParameterString == NULL) {
  1245. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1246. return pdFALSE;
  1247. }
  1248. for (i = 0; i < ARG_AKB_ALL; i ++) {
  1249. if ( strncmp( ( const char * ) pcParameterString, akb_args_list[i], strlen(akb_args_list[i]) ) == 0
  1250. && xParameterStringLength == strlen(akb_args_list[i])) {
  1251. break;
  1252. }
  1253. }
  1254. if (cli_state->user_id != ADMIN && i != ARG_AKB_INFO) {
  1255. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1256. return pdFALSE;
  1257. }
  1258. xParameterNumber ++;
  1259. /* Obtain the parameter string. */
  1260. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1261. (
  1262. pcCommandString, /* The command string itself. */
  1263. xParameterNumber, /* Return the next parameter. */
  1264. &xParameterStringLength /* Store the parameter string length. */
  1265. );
  1266. if (pcParameterString == NULL) {
  1267. if (i == ARG_AKB_INFO) {
  1268. akb_config_param(pcWriteBuffer);
  1269. } else {
  1270. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1271. }
  1272. return pdFALSE;
  1273. }
  1274. memset(str, 0, sizeof(str));
  1275. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1276. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1277. xParameterStringLength = sizeof(str) - 2;
  1278. }
  1279. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1280. #ifdef HARDWARE_BT6709
  1281. if (i != ARG_AKB_DATASET)
  1282. #endif
  1283. {
  1284. for (uint8_t j = 0; j < xParameterStringLength; j ++) {
  1285. if (!isfloatdigit(str[j])) {
  1286. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1287. return pdFALSE;
  1288. }
  1289. }
  1290. value = atof(str);
  1291. }
  1292. switch (i) {
  1293. case ARG_AKB_VOLT_CELL_MIN:
  1294. if (value < sSettings.UPS_Setting.Ucellmax && value > MIN_VOLT_CELL_RANGE) {
  1295. SetUPSVoltCellMinStr(str);
  1296. cli_save_config(cli_state);
  1297. } else {
  1298. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1299. }
  1300. break;
  1301. case ARG_AKB_VOLT_CELL_MAX:
  1302. if (value > sSettings.UPS_Setting.Ucellmin && value <= MAX_VOLT_CELL_RANGE) {
  1303. SetUPSVoltCellMaxStr(str);
  1304. cli_save_config(cli_state);
  1305. } else {
  1306. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1307. }
  1308. break;
  1309. #ifdef HARDWARE_BT6709
  1310. case ARG_AKB_CAPACITY:
  1311. if (value >= CAPACITY_MIN_RANGE && value <= CAPACITY_MAX_RANGE && (value - (int32_t)value) == 0) {
  1312. SetCapacityNominalAKBStr(str);
  1313. cli_save_config(cli_state);
  1314. } else {
  1315. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1316. }
  1317. break;
  1318. case ARG_AKB_VOLT:
  1319. if (value >= AKB_VOLTAGE_MIN_RANGE && value <= AKB_VOLTAGE_MAX_RANGE && ((int32_t)value % 12) == 0 && (value - (int32_t)value) == 0) {
  1320. SetVoltageAKBNominalStr(str);
  1321. cli_save_config(cli_state);
  1322. } else {
  1323. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1324. }
  1325. break;
  1326. case ARG_AKB_LIFETIME:
  1327. if (value >= LIFETIME_MIN_RANGE && value <= LIFETIME_MAX_RANGE && (value - (int32_t)value) == 0) {
  1328. SetLifeTimeAKBStr(str);
  1329. cli_save_config(cli_state);
  1330. } else {
  1331. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1332. }
  1333. break;
  1334. case ARG_AKB_DATASET:
  1335. if (xParameterStringLength == 10) {
  1336. if (strncmp( str, "0000-00-00", 10) == 0) {
  1337. memset(str, 0, sizeof(str));
  1338. SetDataSetAKBStr(str);
  1339. SETTINGS_Save();
  1340. xReturn = pdFALSE;
  1341. return xReturn;
  1342. }
  1343. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  1344. if (j != 4 && j != 7) {
  1345. if (str[j] > 0x39 || str[j] < 0x30) {
  1346. fail = 1;
  1347. }
  1348. } else if (j == 4 || j == 7) {
  1349. if (str[j] != '-') {
  1350. fail = 1;
  1351. }
  1352. }
  1353. }
  1354. if (!fail) {
  1355. temp = 1000 * (str[0] - 0x30) + 100 * (str[1] - 0x30) + 10 * (str[2] - 0x30) + str[3] - 0x30;
  1356. if (temp > 2099 || temp < 2000) {
  1357. fail = 1;
  1358. }
  1359. temp = 0;
  1360. temp = 10 * (str[5] - 0x30) + (str[6] - 0x30);
  1361. if (temp > 12) {
  1362. fail = 1;
  1363. }
  1364. temp = 0;
  1365. temp = 10 * (str[8] - 0x30) + (str[9] - 0x30);
  1366. if (temp > 31) {
  1367. fail = 1;
  1368. }
  1369. }
  1370. } else {
  1371. fail = 1;
  1372. }
  1373. if (!fail) {
  1374. SetDataSetAKBStr(str);
  1375. cli_save_config(cli_state);
  1376. } else {
  1377. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1378. }
  1379. break;
  1380. case ARG_AKB_UPS_POWER:
  1381. if (value >= UPS_POWER_MIN_RANGE && value <= UPS_POWER_MAX_RANGE && ((int32_t)value % 50) == 0 && (value - (int32_t)value) == 0) {
  1382. SetUPSPowerStr(str);
  1383. cli_save_config(cli_state);
  1384. } else {
  1385. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1386. }
  1387. break;
  1388. #endif
  1389. default:
  1390. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1391. break;
  1392. }
  1393. xReturn = pdFALSE;
  1394. return xReturn;
  1395. }
  1396. /*
  1397. * Implements the alarm command.
  1398. */
  1399. static portBASE_TYPE prvTaskAlarmCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1400. {
  1401. int8_t *pcParameterString;
  1402. signed portBASE_TYPE xParameterStringLength, xReturn;
  1403. portBASE_TYPE xParameterNumber = 1;
  1404. char str[110];
  1405. uint8_t i, j;
  1406. float value = 0;
  1407. uint8_t k;
  1408. ( void ) pcCommandString;
  1409. ( void ) xWriteBufferLen;
  1410. configASSERT( pcWriteBuffer );
  1411. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1412. /* Obtain the parameter string. */
  1413. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1414. (
  1415. pcCommandString, /* The command string itself. */
  1416. xParameterNumber, /* Return the next parameter. */
  1417. &xParameterStringLength /* Store the parameter string length. */
  1418. );
  1419. if (pcParameterString == NULL) {
  1420. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1421. return pdFALSE;
  1422. }
  1423. for (i = 0; i < ARG_ALARM_TYPE_ALL; i ++) {
  1424. if ( strncmp( ( const char * ) pcParameterString, type_alarm_args_list[i], strlen(type_alarm_args_list[i]) ) == 0
  1425. && xParameterStringLength == strlen(type_alarm_args_list[i])) {
  1426. break;
  1427. }
  1428. }
  1429. if (cli_state->user_id != ADMIN && i != ARG_ALARM_INFO) {
  1430. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1431. return pdFALSE;
  1432. }
  1433. xParameterNumber ++;
  1434. /* Obtain the parameter string. */
  1435. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1436. (
  1437. pcCommandString, /* The command string itself. */
  1438. xParameterNumber, /* Return the next parameter. */
  1439. &xParameterStringLength /* Store the parameter string length. */
  1440. );
  1441. if (pcParameterString == NULL) {
  1442. if (i == ARG_ALARM_INFO) {
  1443. alarm_config_param(pcWriteBuffer);
  1444. } else {
  1445. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1446. }
  1447. return pdFALSE;
  1448. }
  1449. for (j = 0; j < ARG_ALARM_ALL; j ++) {
  1450. if ( strncmp( ( const char * ) pcParameterString, alarm_args_list[j], strlen(alarm_args_list[j]) ) == 0 ) {
  1451. break;
  1452. }
  1453. }
  1454. xParameterNumber ++;
  1455. /* Obtain the parameter string. */
  1456. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1457. (
  1458. pcCommandString, /* The command string itself. */
  1459. xParameterNumber, /* Return the next parameter. */
  1460. &xParameterStringLength /* Store the parameter string length. */
  1461. );
  1462. if (pcParameterString == NULL) {
  1463. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1464. return pdFALSE;
  1465. }
  1466. memset(str, 0, sizeof(str));
  1467. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1468. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1469. xParameterStringLength = sizeof(str) - 2;
  1470. }
  1471. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1472. switch (i) {
  1473. case ARG_ALARM_TEMP:
  1474. switch (j) {
  1475. case ARG_ALARM_LINE_LOW:
  1476. for (k = 0; k < xParameterStringLength; k ++) {
  1477. if (!isdigit_int(str[k])) {
  1478. if (k == 0 && str[k] == '-') {
  1479. continue;
  1480. } else {
  1481. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1482. return pdFALSE;
  1483. }
  1484. }
  1485. }
  1486. value = atof(str);
  1487. if (value >= MIN_TEMP_MIN_RANGE && value <= MIN_TEMP_MAX_RANGE) {
  1488. SetTemperatureAlarmLowRangeStr(str);
  1489. cli_save_config(cli_state);
  1490. } else {
  1491. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1492. }
  1493. break;
  1494. case ARG_ALARM_LINE_HIGH:
  1495. for (k = 0; k < xParameterStringLength; k ++) {
  1496. if (!isdigit_int(str[k])) {
  1497. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1498. return pdFALSE;
  1499. }
  1500. }
  1501. value = atof(str);
  1502. if (value >= MAX_TEMP_MIN_RANGE && value <= MAX_TEMP_MAX_RANGE) {
  1503. SetTemperatureAlarmHighRangeStr(str);
  1504. cli_save_config(cli_state);
  1505. } else {
  1506. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1507. }
  1508. break;
  1509. case ARG_ALARM_LINE_HIST:
  1510. for (k = 0; k < xParameterStringLength; k ++) {
  1511. if (!isfloatdigit(str[k])) {
  1512. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1513. return pdFALSE;
  1514. }
  1515. }
  1516. value = atof(str);
  1517. if (value >= HIST_TEMP_MIN_RANGE && value <= HIST_TEMP_MAX_RANGE) {
  1518. SetTemperatureAlarmHisteStr(str);
  1519. cli_save_config(cli_state);
  1520. } else {
  1521. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1522. }
  1523. break;
  1524. default:
  1525. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1526. break;
  1527. }
  1528. break;
  1529. case ARG_ALARM_LOAD:
  1530. switch (j) {
  1531. case ARG_ALARM_LINE_LOW:
  1532. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1533. break;
  1534. case ARG_ALARM_LINE_HIGH:
  1535. for (k = 0; k < xParameterStringLength; k ++) {
  1536. if (!isdigit_int(str[k])) {
  1537. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1538. return pdFALSE;
  1539. }
  1540. }
  1541. value = atof(str);
  1542. if (value >= MAX_LOAD_MIN_RANGE && value <= MAX_LOAD_MAX_RANGE) {
  1543. SetLoadAlarmHighRangeStr(str);
  1544. cli_save_config(cli_state);
  1545. } else {
  1546. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1547. }
  1548. break;
  1549. case ARG_ALARM_LINE_HIST:
  1550. for (k = 0; k < xParameterStringLength; k ++) {
  1551. if (!isfloatdigit(str[k])) {
  1552. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1553. return pdFALSE;
  1554. }
  1555. }
  1556. value = atof(str);
  1557. if (value >= HIST_LOAD_MIN_RANGE && value <= HIST_LOAD_MAX_RANGE) {
  1558. SetLoadAlarmHistStr(str);
  1559. cli_save_config(cli_state);
  1560. } else {
  1561. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1562. }
  1563. break;
  1564. default:
  1565. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1566. break;
  1567. }
  1568. break;
  1569. case ARG_ALARM_VOUT:
  1570. switch (j) {
  1571. case ARG_ALARM_LINE_LOW:
  1572. for (k = 0; k < xParameterStringLength; k ++) {
  1573. if (!isdigit_int(str[k])) {
  1574. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1575. return pdFALSE;
  1576. }
  1577. }
  1578. value = atof(str);
  1579. if (value >= MIN_VAC_MIN_RANGE && value <= MIN_VAC_MAX_RANGE) {
  1580. SetVACAlarmLowRangeStr(str);
  1581. cli_save_config(cli_state);
  1582. } else {
  1583. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1584. }
  1585. break;
  1586. case ARG_ALARM_LINE_HIGH:
  1587. for (k = 0; k < xParameterStringLength; k ++) {
  1588. if (!isdigit_int(str[k])) {
  1589. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1590. return pdFALSE;
  1591. }
  1592. }
  1593. value = atof(str);
  1594. if (value >= MAX_VAC_MIN_RANGE && value <= MAX_VAC_MAX_RANGE) {
  1595. SetVACAlarmHighRangeStr(str);
  1596. cli_save_config(cli_state);
  1597. } else {
  1598. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1599. }
  1600. break;
  1601. case ARG_ALARM_LINE_HIST:
  1602. for (k = 0; k < xParameterStringLength; k ++) {
  1603. if (!isdigit_int(str[k])) {
  1604. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1605. return pdFALSE;
  1606. }
  1607. }
  1608. value = atof(str);
  1609. if (value >= HIST_VAC_MIN_RANGE && value <= HIST_VAC_MAX_RANGE) {
  1610. SetVACAlarmHisteStr(str);
  1611. cli_save_config(cli_state);
  1612. } else {
  1613. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1614. }
  1615. break;
  1616. default:
  1617. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1618. break;
  1619. }
  1620. break;
  1621. default:
  1622. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1623. break;
  1624. }
  1625. xReturn = pdFALSE;
  1626. return xReturn;
  1627. }
  1628. #ifdef NOTIFICATION_CONTROL_ENABLE
  1629. /*
  1630. * Implements the notification command.
  1631. */
  1632. static portBASE_TYPE prvTaskNotificationCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  1633. const int8_t *pcCommandString )
  1634. {
  1635. int8_t *pcParameterString;
  1636. signed portBASE_TYPE xParameterStringLength, xReturn;
  1637. portBASE_TYPE xParameterNumber = 1;
  1638. char str[20];
  1639. char temp_str[20];
  1640. uint8_t i;
  1641. char *beginValue;
  1642. uint8_t len;
  1643. ( void ) pcCommandString;
  1644. ( void ) xWriteBufferLen;
  1645. configASSERT( pcWriteBuffer );
  1646. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1647. /* Obtain the parameter string. */
  1648. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1649. (
  1650. pcCommandString, /* The command string itself. */
  1651. xParameterNumber, /* Return the next parameter. */
  1652. &xParameterStringLength /* Store the parameter string length. */
  1653. );
  1654. if (pcParameterString == NULL) {
  1655. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1656. return pdFALSE;
  1657. }
  1658. for (i = 0; i < ARG_NOTIFICATION_ALL; i ++) {
  1659. if ( strncmp( ( const char * ) pcParameterString, notification_args_list[i], strlen(notification_args_list[i]) ) == 0
  1660. && xParameterStringLength == strlen(notification_args_list[i])) {
  1661. break;
  1662. }
  1663. }
  1664. if (cli_state->user_id != ADMIN && i != ARG_NOTIFICATION_INFO) {
  1665. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1666. return pdFALSE;
  1667. }
  1668. xParameterNumber ++;
  1669. /* Obtain the parameter string. */
  1670. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1671. (
  1672. pcCommandString, /* The command string itself. */
  1673. xParameterNumber, /* Return the next parameter. */
  1674. &xParameterStringLength /* Store the parameter string length. */
  1675. );
  1676. xParameterNumber ++;
  1677. if (pcParameterString == NULL) {
  1678. if (i == ARG_NOTIFICATION_INFO) {
  1679. notification_param(pcWriteBuffer);
  1680. } else {
  1681. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1682. }
  1683. return pdFALSE;
  1684. }
  1685. memset(str, 0, sizeof(str));
  1686. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1687. xParameterStringLength = sizeof(str) - 1;
  1688. }
  1689. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1690. switch (i) {
  1691. case ARG_NOTIFICATION_SET:
  1692. if (xParameterStringLength >= 1) {
  1693. for(uint32_t k = 0; k < xParameterStringLength; k ++) {
  1694. if (!isdigit_int(str[k])) {
  1695. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1696. return pdFALSE;
  1697. }
  1698. }
  1699. int32_t temp = atoi(str);
  1700. uint8_t value_notification = 0;
  1701. if (temp > 0 && temp < ALL_TRAPS) {
  1702. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1703. (
  1704. pcCommandString, /* The command string itself. */
  1705. xParameterNumber, /* Return the next parameter. */
  1706. &xParameterStringLength /* Store the parameter string length. */
  1707. );
  1708. if (pcParameterString != NULL && xParameterStringLength == 3) {
  1709. if (strncmp(pcParameterString, "ENA", 3) == 0) {
  1710. value_notification = 1;
  1711. SetNotificationFlagsStr(&value_notification, (uint8_t)temp);
  1712. SETTINGS_Save();
  1713. } else if (strncmp(pcParameterString, "DIS", 3) == 0) {
  1714. SetNotificationFlagsStr(&value_notification, (uint8_t)temp);
  1715. SETTINGS_Save();
  1716. } else {
  1717. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1718. }
  1719. } else {
  1720. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1721. }
  1722. } else {
  1723. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1724. }
  1725. } else {
  1726. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1727. }
  1728. break;
  1729. default:
  1730. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1731. break;
  1732. }
  1733. xReturn = pdFALSE;
  1734. return xReturn;
  1735. }
  1736. #endif
  1737. #ifdef WHITELIST_ENABLE
  1738. /*
  1739. * Implements the whitelist command.
  1740. */
  1741. static portBASE_TYPE prvTaskWhiteListCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  1742. const int8_t *pcCommandString )
  1743. {
  1744. int8_t *pcParameterString;
  1745. signed portBASE_TYPE xParameterStringLength, xReturn;
  1746. portBASE_TYPE xParameterNumber = 1;
  1747. char str[20];
  1748. char temp_str[20];
  1749. uint8_t i;
  1750. char *beginValue;
  1751. uint8_t len;
  1752. int32_t temp;
  1753. ( void ) pcCommandString;
  1754. ( void ) xWriteBufferLen;
  1755. configASSERT( pcWriteBuffer );
  1756. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1757. /* Obtain the parameter string. */
  1758. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1759. (
  1760. pcCommandString, /* The command string itself. */
  1761. xParameterNumber, /* Return the next parameter. */
  1762. &xParameterStringLength /* Store the parameter string length. */
  1763. );
  1764. if (pcParameterString == NULL) {
  1765. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1766. return pdFALSE;
  1767. }
  1768. for (i = 0; i < ARG_WHITELIST_ALL; i ++) {
  1769. if ( strncmp( ( const char * ) pcParameterString, whitelist_args_list[i], strlen(whitelist_args_list[i]) ) == 0
  1770. && xParameterStringLength == strlen(whitelist_args_list[i])) {
  1771. break;
  1772. }
  1773. }
  1774. if (cli_state->user_id != ADMIN && i != ARG_WHITELIST_INFO) {
  1775. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1776. return pdFALSE;
  1777. }
  1778. xParameterNumber ++;
  1779. /* Obtain the parameter string. */
  1780. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1781. (
  1782. pcCommandString, /* The command string itself. */
  1783. xParameterNumber, /* Return the next parameter. */
  1784. &xParameterStringLength /* Store the parameter string length. */
  1785. );
  1786. xParameterNumber ++;
  1787. if (pcParameterString == NULL) {
  1788. if (i == ARG_WHITELIST_INFO) {
  1789. whitelist_config_param(pcWriteBuffer);
  1790. } else {
  1791. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1792. }
  1793. return pdFALSE;
  1794. }
  1795. memset(str, 0, sizeof(str));
  1796. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1797. xParameterStringLength = sizeof(str) - 1;
  1798. }
  1799. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1800. switch (i) {
  1801. case ARG_WHITELIST_RANGE:
  1802. if (xParameterStringLength == 1 && isdigit_int(str[0])) {
  1803. temp = atoi(str);
  1804. if (temp > 0 && temp < 6) {
  1805. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1806. (
  1807. pcCommandString, /* The command string itself. */
  1808. xParameterNumber, /* Return the next parameter. */
  1809. &xParameterStringLength /* Store the parameter string length. */
  1810. );
  1811. if (pcParameterString != NULL) {
  1812. memset(str, 0, sizeof(str));
  1813. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1814. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1815. xParameterStringLength = sizeof(str) - 1;
  1816. }
  1817. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1818. if (xParameterStringLength <= 19) {
  1819. beginValue = strpbrk(str, "/");
  1820. if (beginValue == NULL) {
  1821. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1822. return pdFALSE;
  1823. }
  1824. int32_t mask = atoi(&beginValue[1]);
  1825. len = beginValue - str;
  1826. memset(temp_str, 0, sizeof(temp_str));
  1827. strncpy(temp_str, str, len);
  1828. for (uint8_t j = (len + 1); j < xParameterStringLength; j++) {
  1829. if (!isdigit_int(str[j])) {
  1830. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1831. return pdFALSE;
  1832. }
  1833. }
  1834. if (ipaddr_addr(temp_str) != IPADDR_NONE && (mask <= 32 && mask >= 0)) {
  1835. SetWhiteListSTR(str, (temp - 1));
  1836. strcpy( ( char * ) pcWriteBuffer,
  1837. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  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. } else {
  1845. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1846. }
  1847. } else {
  1848. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1849. }
  1850. } else {
  1851. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1852. }
  1853. break;
  1854. case ARG_WHITELIST_RESET:
  1855. if (xParameterStringLength == 1 && isdigit_int(str[0])) {
  1856. temp = atoi(str);
  1857. if (temp > 0 && temp < 6) {
  1858. memset(str, 0, sizeof(str));
  1859. SetWhiteListSTR(str, (temp - 1));
  1860. strcpy( ( char * ) pcWriteBuffer,
  1861. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1862. } else {
  1863. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1864. }
  1865. } else {
  1866. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1867. }
  1868. break;
  1869. default:
  1870. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1871. break;
  1872. }
  1873. xReturn = pdFALSE;
  1874. return xReturn;
  1875. }
  1876. #endif
  1877. /*
  1878. * Implements the change password command.
  1879. */
  1880. static portBASE_TYPE prvTaskUserCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1881. {
  1882. int8_t *pcParameterString;
  1883. signed portBASE_TYPE xParameterStringLength, xReturn;
  1884. portBASE_TYPE xParameterNumber = 1;
  1885. uint8_t i;
  1886. char temp_str[MAX_WEB_LOGIN_LEN];
  1887. char WebLogin[MAX_WEB_LOGIN_LEN];
  1888. uint8_t valueLen, user_id;
  1889. const int8_t *const pcChangePWDHeader = ( int8_t * ) "\r\nВведите новый пароль:";
  1890. ( void ) pcCommandString;
  1891. ( void ) xWriteBufferLen;
  1892. configASSERT( pcWriteBuffer );
  1893. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1894. if (cli_state->user_id != ADMIN) {
  1895. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1896. return pdFALSE;
  1897. }
  1898. /* Obtain the parameter string. */
  1899. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1900. (
  1901. pcCommandString, /* The command string itself. */
  1902. xParameterNumber, /* Return the next parameter. */
  1903. &xParameterStringLength /* Store the parameter string length. */
  1904. );
  1905. if (pcParameterString == NULL) {
  1906. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1907. return pdFALSE;
  1908. }
  1909. for (i = 0; i < ARG_USER_ALL; i ++) {
  1910. if ( strncmp( ( const char * ) pcParameterString, user_args_list[i], strlen(user_args_list[i]) ) == 0 ) {
  1911. break;
  1912. }
  1913. }
  1914. xParameterNumber ++;
  1915. /* Obtain the parameter string. */
  1916. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1917. (
  1918. pcCommandString, /* The command string itself. */
  1919. xParameterNumber, /* Return the next parameter. */
  1920. &xParameterStringLength /* Store the parameter string length. */
  1921. );
  1922. if (i == ARG_USER_PWD) {
  1923. memset(temp_str, 0, sizeof(temp_str));
  1924. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1925. if (xParameterStringLength > (int32_t)sizeof(temp_str)) {
  1926. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1927. } else {
  1928. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1929. for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
  1930. GetUserLogin(user_id, WebLogin, &valueLen);
  1931. /* Check login and password */
  1932. if (strncmp(WebLogin, temp_str, MAX_WEB_LOGIN_LEN) == 0) {
  1933. /* Login and pass are valid */
  1934. cli_state->id_change_pwd = user_id;
  1935. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcChangePWDHeader, strlen( ( char * ) pcChangePWDHeader ) );
  1936. cli_state->input_state = CLI_CHANGE_PWD;
  1937. break;
  1938. }
  1939. }
  1940. if (cli_state->input_state != CLI_CHANGE_PWD) {
  1941. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1942. }
  1943. }
  1944. } else {
  1945. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1946. }
  1947. xReturn = pdFALSE;
  1948. return xReturn;
  1949. }
  1950. /*
  1951. * Implements the config command.
  1952. */
  1953. static portBASE_TYPE prvTaskConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  1954. const int8_t *pcCommandString )
  1955. {
  1956. int8_t *pcParameterString;
  1957. signed portBASE_TYPE xParameterStringLength, xReturn;
  1958. portBASE_TYPE xParameterNumber = 1;
  1959. char str[110];
  1960. uint8_t i;
  1961. static uint8_t config_menu = 0;
  1962. const int8_t *const pcInfoTableHeader = ( int8_t * )
  1963. "\r\n*********Конфигурация Контроллера*********\r\n";
  1964. ( void ) pcCommandString;
  1965. ( void ) xWriteBufferLen;
  1966. configASSERT( pcWriteBuffer );
  1967. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1968. /* Obtain the parameter string. */
  1969. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1970. (
  1971. pcCommandString, /* The command string itself. */
  1972. xParameterNumber, /* Return the next parameter. */
  1973. &xParameterStringLength /* Store the parameter string length. */
  1974. );
  1975. if (pcParameterString == NULL) {
  1976. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1977. return pdFALSE;
  1978. }
  1979. for (i = 0; i < ARG_CONFIG_ALL; i ++) {
  1980. if ( strncmp( ( const char * ) pcParameterString, config_args_list[i], strlen(config_args_list[i]) ) == 0
  1981. && xParameterStringLength == strlen(config_args_list[i])) {
  1982. break;
  1983. }
  1984. }
  1985. if (cli_state->user_id != ADMIN && i != ARG_CONFIG_INFO) {
  1986. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1987. return pdFALSE;
  1988. }
  1989. xParameterNumber ++;
  1990. /* Obtain the parameter string. */
  1991. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1992. (
  1993. pcCommandString, /* The command string itself. */
  1994. xParameterNumber, /* Return the next parameter. */
  1995. &xParameterStringLength /* Store the parameter string length. */
  1996. );
  1997. if (pcParameterString == NULL) {
  1998. switch (i) {
  1999. case ARG_CONFIG_INFO:
  2000. switch (config_menu) {
  2001. case PARAM_CONFIG_SNMP:
  2002. /* Return the next command help string, before moving the pointer on to
  2003. the next command in the list. */
  2004. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  2005. snmp_config_param(pcWriteBuffer);
  2006. break;
  2007. #ifdef INOUTS_ENABLE
  2008. case PARAM_CONFIG_INOUTS:
  2009. inouts_config_param(pcWriteBuffer);
  2010. break;
  2011. #endif
  2012. case PARAM_CONFIG_AKB:
  2013. akb_config_param(pcWriteBuffer);
  2014. break;
  2015. case PARAM_CONFIG_ALARM:
  2016. alarm_config_param(pcWriteBuffer);
  2017. break;
  2018. #ifdef WHITELIST_ENABLE
  2019. case PARAM_CONFIG_WHITELIST:
  2020. whitelist_config_param(pcWriteBuffer);
  2021. break;
  2022. #endif
  2023. case PARAM_CONFIG_NET:
  2024. net_config_param(pcWriteBuffer);
  2025. break;
  2026. case PARAM_CONFIG_TIME:
  2027. time_config_param(pcWriteBuffer);
  2028. break;
  2029. }
  2030. config_menu ++;
  2031. if (config_menu == PARAM_CONFIG_ALL) {
  2032. config_menu = 0;
  2033. return pdFALSE;
  2034. } else {
  2035. return pdTRUE;
  2036. }
  2037. break;
  2038. default:
  2039. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2040. break;
  2041. }
  2042. return pdFALSE;
  2043. }
  2044. if (i == ARG_CONFIG_LOAD) {
  2045. memset(str, 0, sizeof(str));
  2046. xParameterStringLength = strlen(( const char * ) pcParameterString);
  2047. if (xParameterStringLength > (int32_t)sizeof(str)) {
  2048. xParameterStringLength = sizeof(str) - 1;
  2049. }
  2050. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2051. if (xParameterStringLength < 13) {
  2052. if (strncmp(str, "default", 7) == 0) {
  2053. SNMP_SendUserTrap(DEVICE_RESTORED);
  2054. log_event_data(LOG_SYSTEM_DEFCONFIG, "Администратор");
  2055. vTaskDelay(500);
  2056. SETTINGS_SetPartDefault();
  2057. cli_save_config(cli_state);
  2058. strcpy( ( char * ) pcWriteBuffer,
  2059. "\t\tНастройки сброшены к настройкам по умолчанию!\r\n");
  2060. } else {
  2061. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2062. }
  2063. } else {
  2064. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2065. }
  2066. } else {
  2067. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2068. }
  2069. xReturn = pdFALSE;
  2070. return xReturn;
  2071. }
  2072. /*
  2073. * Implements the config command.
  2074. */
  2075. static portBASE_TYPE prvTaskNetConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2076. const int8_t *pcCommandString )
  2077. {
  2078. int8_t *pcParameterString;
  2079. portBASE_TYPE xParameterNumber = 1;
  2080. signed portBASE_TYPE xParameterStringLength;
  2081. uint8_t i;
  2082. static start = 0;
  2083. ( void ) pcCommandString;
  2084. ( void ) xWriteBufferLen;
  2085. configASSERT( pcWriteBuffer );
  2086. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2087. /* Obtain the parameter string. */
  2088. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2089. (
  2090. pcCommandString, /* The command string itself. */
  2091. xParameterNumber, /* Return the next parameter. */
  2092. &xParameterStringLength /* Store the parameter string length. */
  2093. );
  2094. for (i = 0; i < ARG_NETCONFIG_ALL; i ++) {
  2095. if ( strncmp( ( const char * ) pcParameterString, netconfig_args_list[i], strlen(netconfig_args_list[i]) ) == 0
  2096. && xParameterStringLength == strlen(netconfig_args_list[i])) {
  2097. break;
  2098. }
  2099. }
  2100. if (cli_state->user_id != ADMIN) {
  2101. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2102. return pdFALSE;
  2103. }
  2104. switch (i) {
  2105. case ARG_NETCONFIG_APPLY:
  2106. if (!start) {
  2107. /* Если параметры WEB изменились выставляем флаг, сохраняем настройки и перезагружаемся */
  2108. if (GetStateWebReinit() == true) {
  2109. start = 1;
  2110. SetWebReinitFlag(true);
  2111. cli_save_config(cli_state);
  2112. strcpy( ( char * ) pcWriteBuffer,
  2113. "\t\tНастройки сохранены! Контроллер будет перезагружен\r\n\tПосле перезагрузки подтвердите изменения сетевых настроек\r\n");
  2114. return pdTRUE;
  2115. }
  2116. } else {
  2117. start = 0;
  2118. vTaskDelay(1010);
  2119. Reboot(CLI_ACT);
  2120. }
  2121. break;
  2122. case ARG_NETCONFIG_CONFIRM:
  2123. SetWebReinitFlag(false);
  2124. SetConfirmWebParamsFlag();
  2125. strcpy( ( char * ) pcWriteBuffer, "\t\tСетевые настройки подтверждены!\r\n");
  2126. break;
  2127. default:
  2128. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2129. break;
  2130. }
  2131. return pdFALSE;
  2132. }
  2133. /*
  2134. * Implements the history command.
  2135. */
  2136. static portBASE_TYPE prvTaskHistoryCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2137. const int8_t *pcCommandString )
  2138. {
  2139. int8_t *pcParameterString;
  2140. signed portBASE_TYPE xParameterStringLength, xReturn;
  2141. portBASE_TYPE xParameterNumber = 1;
  2142. char str[110];
  2143. uint8_t i;
  2144. static int16_t num_page = 0;
  2145. static int16_t num_page_temp = 1;
  2146. static bool start = true;
  2147. const int8_t *const pcUPShistoryTableHeader = ( int8_t * )
  2148. "\r\n***********Журнал событий ИБП***********\r\n";
  2149. const int8_t *const pcControllerHistoryTableHeader = ( int8_t * )
  2150. "\r\n***********Журнал событий Контроллера***********\r\n";
  2151. ( void ) pcCommandString;
  2152. ( void ) xWriteBufferLen;
  2153. configASSERT( pcWriteBuffer );
  2154. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2155. /* Obtain the parameter string. */
  2156. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2157. (
  2158. pcCommandString, /* The command string itself. */
  2159. xParameterNumber, /* Return the next parameter. */
  2160. &xParameterStringLength /* Store the parameter string length. */
  2161. );
  2162. if (pcParameterString == NULL) {
  2163. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2164. return pdFALSE;
  2165. }
  2166. if ( strncmp( ( const char * ) pcParameterString, "show", xParameterStringLength ) != 0 ) {
  2167. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2168. return pdFALSE;
  2169. }
  2170. xParameterNumber ++;
  2171. /* Obtain the parameter string. */
  2172. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2173. (
  2174. pcCommandString, /* The command string itself. */
  2175. xParameterNumber, /* Return the next parameter. */
  2176. &xParameterStringLength /* Store the parameter string length. */
  2177. );
  2178. for (i = 0; i < ARG_HISTORY_ALL; i ++) {
  2179. if ( strncmp( ( const char * ) pcParameterString, history_args_list[i], strlen(history_args_list[i]) ) == 0
  2180. && xParameterStringLength == strlen(history_args_list[i])) {
  2181. break;
  2182. }
  2183. }
  2184. xParameterNumber ++;
  2185. /* Obtain the parameter string. */
  2186. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2187. (
  2188. pcCommandString, /* The command string itself. */
  2189. xParameterNumber, /* Return the next parameter. */
  2190. &xParameterStringLength /* Store the parameter string length. */
  2191. );
  2192. memset(str, 0, sizeof(str));
  2193. if (xParameterStringLength > 5) {
  2194. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2195. return pdFALSE;
  2196. }
  2197. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2198. if (num_page == 0) {
  2199. num_page = atoi(str);
  2200. if (num_page <= 0) {
  2201. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2202. return pdFALSE;
  2203. }
  2204. }
  2205. switch (i) {
  2206. case ARG_HISTORY_EVENTS:
  2207. if (start) {
  2208. start = false;
  2209. /* Return the next command help string, before moving the pointer on to
  2210. the next command in the list. */
  2211. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcControllerHistoryTableHeader,
  2212. strlen( ( char * ) pcControllerHistoryTableHeader ) );
  2213. memset(str, 0, sizeof(str));
  2214. strcat(( char * ) pcWriteBuffer, "\r\n");
  2215. sprintf(str, "Количество страниц журнала: %d\r\n", History_GetPageCount());
  2216. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  2217. strcat(( char * ) pcWriteBuffer, "\r\n");
  2218. if (num_page > History_GetPageCount()) {
  2219. num_page = History_GetPageCount();
  2220. }
  2221. }
  2222. History_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  2223. num_page --;
  2224. num_page_temp ++;
  2225. if (num_page == 0) {
  2226. num_page = 0;
  2227. num_page_temp = 1;
  2228. start = true;
  2229. xReturn = pdFALSE;
  2230. } else {
  2231. xReturn = pdTRUE;
  2232. }
  2233. break;
  2234. case ARG_HISTORY_UPS:
  2235. if (start) {
  2236. start = false;
  2237. /* Return the next command help string, before moving the pointer on to
  2238. the next command in the list. */
  2239. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcUPShistoryTableHeader,
  2240. strlen( ( char * ) pcUPShistoryTableHeader ) );
  2241. memset(str, 0, sizeof(str));
  2242. sprintf(str, "Количество страниц журнала: %d\r\n", LOG_GetPageCount());
  2243. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  2244. if (num_page > LOG_GetPageCount()) {
  2245. num_page = LOG_GetPageCount();
  2246. }
  2247. }
  2248. LOG_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  2249. num_page --;
  2250. num_page_temp ++;
  2251. if (num_page == 0) {
  2252. num_page = 0;
  2253. num_page_temp = 1;
  2254. start = true;
  2255. xReturn = pdFALSE;
  2256. } else {
  2257. xReturn = pdTRUE;
  2258. }
  2259. break;
  2260. default:
  2261. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2262. xReturn = pdFALSE;
  2263. break;
  2264. }
  2265. return xReturn;
  2266. }
  2267. /*
  2268. * Implements the sensor info command.
  2269. */
  2270. static portBASE_TYPE prvTaskSensorCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2271. const int8_t *pcCommandString )
  2272. {
  2273. int8_t *pcParameterString;
  2274. signed portBASE_TYPE xParameterStringLength, xReturn;
  2275. portBASE_TYPE xParameterNumber = 1;
  2276. uint8_t i;
  2277. char str[10];
  2278. char temp_str[10];
  2279. int32_t val = 0, val2 = 0;
  2280. uint8_t fail = 0;
  2281. static uint8_t config_menu = 0;
  2282. uint8_t MAX_CONFIG_PARAM = 0;
  2283. #ifdef HARDWARE_BT6707
  2284. MAX_CONFIG_PARAM = 3;
  2285. #else
  2286. MAX_CONFIG_PARAM = 2;
  2287. #endif
  2288. const int8_t *const pcSensorTableHeader = ( int8_t * )
  2289. "\r\n*********Параметры Контроллера*********\r\n";
  2290. ( void ) pcCommandString;
  2291. ( void ) xWriteBufferLen;
  2292. configASSERT( pcWriteBuffer );
  2293. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2294. /* Obtain the parameter string. */
  2295. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2296. (
  2297. pcCommandString, /* The command string itself. */
  2298. xParameterNumber, /* Return the next parameter. */
  2299. &xParameterStringLength /* Store the parameter string length. */
  2300. );
  2301. if (pcParameterString == NULL) {
  2302. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2303. return pdFALSE;
  2304. }
  2305. for (i = 0; i < ARG_SENSOR_ALL; i ++) {
  2306. if ( strncmp( ( const char * ) pcParameterString, sensor_args_list[i], strlen(sensor_args_list[i]) ) == 0
  2307. && xParameterStringLength == strlen(sensor_args_list[i])) {
  2308. break;
  2309. }
  2310. }
  2311. xParameterNumber ++;
  2312. /* Obtain the parameter string. */
  2313. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2314. (
  2315. pcCommandString, /* The command string itself. */
  2316. xParameterNumber, /* Return the next parameter. */
  2317. &xParameterStringLength /* Store the parameter string length. */
  2318. );
  2319. if (pcParameterString == NULL) {
  2320. if (i == ARG_SENSOR_INFO) {
  2321. switch (config_menu) {
  2322. case 0:
  2323. /* Return the next command help string, before moving the pointer on to
  2324. the next command in the list. */
  2325. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSensorTableHeader, strlen( ( char * ) pcSensorTableHeader ) );
  2326. ups_sensor_param(pcWriteBuffer);
  2327. break;
  2328. case 1:
  2329. ups_sensor_akb_param(pcWriteBuffer);
  2330. break;
  2331. #ifdef INOUTS_ENABLE
  2332. case 2:
  2333. inouts_sensor_param(pcWriteBuffer);
  2334. break;
  2335. #endif
  2336. }
  2337. config_menu ++;
  2338. if (config_menu == MAX_CONFIG_PARAM) {
  2339. config_menu = 0;
  2340. return pdFALSE;
  2341. } else {
  2342. return pdTRUE;
  2343. }
  2344. } else {
  2345. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2346. }
  2347. } else {
  2348. switch (i) {
  2349. #ifdef HARDWARE_BT6707
  2350. case ARG_SENSOR_SETUP:
  2351. if (cli_state->user_id != ADMIN) {
  2352. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2353. return pdFALSE;
  2354. }
  2355. memset(str, 0, sizeof(str));
  2356. if (xParameterStringLength > (int32_t)sizeof(str)) {
  2357. xParameterStringLength = sizeof(str) - 1;
  2358. }
  2359. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2360. if (xParameterStringLength < 3) {
  2361. xParameterNumber ++;
  2362. /* Obtain the parameter string. */
  2363. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2364. (
  2365. pcCommandString, /* The command string itself. */
  2366. xParameterNumber, /* Return the next parameter. */
  2367. &xParameterStringLength /* Store the parameter string length. */
  2368. );
  2369. memset(temp_str, 0, sizeof(str));
  2370. if (xParameterStringLength > 1) {
  2371. fail = 1;
  2372. break;
  2373. }
  2374. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2375. if (!isdigit_int(temp_str[0])) {
  2376. fail = 1;
  2377. break;
  2378. }
  2379. val = atoi(temp_str);
  2380. xParameterNumber ++;
  2381. /* Obtain the parameter string. */
  2382. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2383. (
  2384. pcCommandString, /* The command string itself. */
  2385. xParameterNumber, /* Return the next parameter. */
  2386. &xParameterStringLength /* Store the parameter string length. */
  2387. );
  2388. memset(temp_str, 0, sizeof(str));
  2389. if (xParameterStringLength > 1) {
  2390. fail = 1;
  2391. break;
  2392. }
  2393. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2394. if (!isdigit_int(temp_str[0])) {
  2395. fail = 1;
  2396. break;
  2397. }
  2398. if (strncmp(str, "DI", 2) == 0) {
  2399. if (val != 1) {
  2400. fail = 1;
  2401. break;
  2402. }
  2403. val2 = atoi(temp_str);
  2404. if (val2 < 0 || val2 > 1) {
  2405. fail = 1;
  2406. break;
  2407. }
  2408. SetDINTypeActStr(temp_str, (val - 1));
  2409. cli_save_config(cli_state);
  2410. } else if (strncmp(str, "DO", 2) == 0) {
  2411. if (val < 1 || val > 3) {
  2412. fail = 1;
  2413. break;
  2414. }
  2415. val2 = atoi(temp_str);
  2416. if (val2 < 1 || val2 > 5) {
  2417. fail = 1;
  2418. break;
  2419. }
  2420. SetROTypeActStr(temp_str, (val - 1));
  2421. cli_save_config(cli_state);
  2422. }
  2423. } else {
  2424. fail = 1;
  2425. }
  2426. break;
  2427. #endif
  2428. default:
  2429. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2430. break;
  2431. }
  2432. }
  2433. if (fail) {
  2434. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2435. }
  2436. xReturn = pdFALSE;
  2437. return xReturn;
  2438. }
  2439. /*
  2440. * Implements the firmware download http command.
  2441. */
  2442. static portBASE_TYPE prvTaskUploadCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2443. const int8_t *pcCommandString )
  2444. {
  2445. static bool start_update = true;
  2446. const int8_t *const pcUploadHeader = ( int8_t * )
  2447. "Контроллер переводится в режим загрузчика\r\n";
  2448. ( void ) pcCommandString;
  2449. ( void ) xWriteBufferLen;
  2450. if (cli_state->user_id != ADMIN) {
  2451. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2452. return pdFALSE;
  2453. }
  2454. if (start_update) {
  2455. start_update = false;
  2456. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcUploadHeader );
  2457. return pdTRUE;
  2458. } else {
  2459. HTTP_StartResetTask(true);
  2460. return pdFALSE;
  2461. }
  2462. }
  2463. /*
  2464. * Implements the ups command.
  2465. */
  2466. static portBASE_TYPE prvTaskUPSCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  2467. {
  2468. int8_t *pcParameterString;
  2469. signed portBASE_TYPE xParameterStringLength, xReturn;
  2470. portBASE_TYPE xParameterNumber = 1;
  2471. char str[110];
  2472. int32_t val = 0;
  2473. float val_float = 0;
  2474. int8_t res = 0;
  2475. uint8_t i;
  2476. ( void ) pcCommandString;
  2477. ( void ) xWriteBufferLen;
  2478. configASSERT( pcWriteBuffer );
  2479. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2480. if (cli_state->user_id != ADMIN && i != ARG_CONFIG_INFO) {
  2481. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2482. return pdFALSE;
  2483. }
  2484. /* Obtain the parameter string. */
  2485. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2486. (
  2487. pcCommandString, /* The command string itself. */
  2488. xParameterNumber, /* Return the next parameter. */
  2489. &xParameterStringLength /* Store the parameter string length. */
  2490. );
  2491. for (i = 0; i < ARG_UPS_ALL; i ++) {
  2492. if ( strncmp( ( const char * ) pcParameterString, ups_args_list[i], strlen(ups_args_list[i]) ) == 0
  2493. && xParameterStringLength == strlen(ups_args_list[i])) {
  2494. break;
  2495. }
  2496. }
  2497. xParameterNumber ++;
  2498. /* Obtain the parameter string. */
  2499. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2500. (
  2501. pcCommandString, /* The command string itself. */
  2502. xParameterNumber, /* Return the next parameter. */
  2503. &xParameterStringLength /* Store the parameter string length. */
  2504. );
  2505. memset(str, 0, sizeof(str));
  2506. if (xParameterStringLength > 3) {
  2507. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2508. return pdFALSE;
  2509. }
  2510. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2511. switch (i) {
  2512. case ARG_UPS_BATTEST:
  2513. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  2514. if (!isdigit_int(str[j])) {
  2515. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2516. return pdFALSE;
  2517. }
  2518. }
  2519. val = atoi(str);
  2520. if (val == 0) {
  2521. res = ups_metac_service_pdu(ups_cancel_test);
  2522. set_act_source(CLI_ACT);
  2523. if (res == 1) {
  2524. log_event_data(LOG_TEST_UPS, "Администратор (Останов)");
  2525. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Останов теста\" принята ИБП!\r\n");
  2526. } else {
  2527. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Останов теста\" отклонена ИБП!\r\n");
  2528. }
  2529. } else if (val > 0 && val < 100) {
  2530. TimeParam = val;
  2531. res = ups_metac_service_pdu(ups_test_time);
  2532. if (res == 1) {
  2533. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2534. } else {
  2535. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2536. }
  2537. } else if (val == 100) {
  2538. res = ups_metac_service_pdu(ups_test_10sec);
  2539. if (res == 1) {
  2540. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2541. } else {
  2542. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2543. }
  2544. } else if (val == 999) {
  2545. res = ups_metac_service_pdu(ups_test_low_bat);
  2546. if (res == 1) {
  2547. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2548. } else {
  2549. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2550. }
  2551. } else {
  2552. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2553. }
  2554. break;
  2555. case ARG_UPS_SHUTDOWN:
  2556. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  2557. if (!isfloatdigit(str[j])) {
  2558. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2559. return pdFALSE;
  2560. }
  2561. }
  2562. val_float = atof(str);
  2563. if (val_float == 0) {
  2564. res = ups_metac_service_pdu(ups_cancel_shut_down);
  2565. if (res == 1) {
  2566. log_event_data(LOG_SHUTDOWN_UPS, "Администратор (Останов)");
  2567. strcpy( ( char * ) pcWriteBuffer, "\t\t\tВыключение нагрузки ИБП отменено!\r\n");
  2568. } else {
  2569. strcpy( ( char * ) pcWriteBuffer,
  2570. "\t\tВыключение нагрузки ИБП не удалось отменить!\r\n");
  2571. }
  2572. } else if (val_float > 0 && val_float <= 10) {
  2573. TimeParamFloat = val_float;
  2574. res = ups_metac_service_pdu(ups_shutdown);
  2575. if (res == 1) {
  2576. log_event_data(LOG_SHUTDOWN_UPS, "Администратор");
  2577. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП!\r\n");
  2578. } else {
  2579. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП не удалось!\r\n");
  2580. }
  2581. } else {
  2582. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2583. }
  2584. break;
  2585. default:
  2586. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2587. break;
  2588. }
  2589. xReturn = pdFALSE;
  2590. return xReturn;
  2591. }
  2592. /*-----------------------------------------------------------*/