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