CLI_Commands.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799
  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 "telnet_server.h"
  35. #include "netconf.h"
  36. #include "control_symbol.h"
  37. #define in_range_digit(c, lo, up) ((uint8_t)c >= lo && (uint8_t)c <= up)
  38. #define isdigit_int(c) in_range_digit(c, '0', '9')
  39. #define isfloatdigit(c) (isdigit_int(c) || in_range_digit(c, '.', '.'))
  40. extern state_telnet_server_t telnetState;
  41. extern uint8_t id_change_pwd;
  42. const int8_t * const pcInvalidCommand = ( int8_t * ) "Command invalid. Enter \"help\" to view a list of available commands.\r\n\r\n";
  43. const int8_t * const pcPermissionDenied = ( int8_t * ) "Permission denied!\r\n\r\n";
  44. const char* info_args_list[] =
  45. {
  46. "address",
  47. "owner",
  48. "comments",
  49. };
  50. const char* ups_args_list[] =
  51. {
  52. "battest",
  53. "shutdown",
  54. };
  55. const char* systime_args_list[] =
  56. {
  57. "date",
  58. "time",
  59. };
  60. const char* network_args_list[] =
  61. {
  62. "info",
  63. "dhcp",
  64. "ip",
  65. "gw",
  66. "mask",
  67. };
  68. const char* snmp_args_list[] =
  69. {
  70. "info",
  71. "server",
  72. "community",
  73. };
  74. const char* ntp_args_list[] =
  75. {
  76. "ENA",
  77. "DIS",
  78. "info",
  79. "set",
  80. };
  81. const char* config_args_list[] =
  82. {
  83. "info",
  84. "load",
  85. "apply",
  86. "confirm",
  87. };
  88. const char* history_args_list[] =
  89. {
  90. "EVENTS",
  91. "UPS",
  92. };
  93. const char* sensor_args_list[] =
  94. {
  95. "info",
  96. };
  97. const char* user_args_list[] =
  98. {
  99. "passwd",
  100. };
  101. /**
  102. * @brief Общая структура настроек
  103. */
  104. extern SETTINGS_t sSettings;
  105. extern user_level_t telnet_code_auth;
  106. /*
  107. * Implements the controller's information command.
  108. */
  109. static portBASE_TYPE prvTaskInfoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  110. /*
  111. * Implements the reboot command.
  112. */
  113. static portBASE_TYPE prvTaskRebootCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  114. /*
  115. * Implements the systime command.
  116. */
  117. static portBASE_TYPE prvTaskSystimeCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  118. /*
  119. * Implements the ntp command.
  120. */
  121. static portBASE_TYPE prvTaskNTPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  122. /*
  123. * Implements the network command.
  124. */
  125. static portBASE_TYPE prvTaskNetworkCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  126. /*
  127. * Implements the snmp command.
  128. */
  129. static portBASE_TYPE prvTaskSNMPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  130. /*
  131. * Implements the change password command.
  132. */
  133. static portBASE_TYPE prvTaskUserCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  134. /*
  135. * Implements the config command.
  136. */
  137. static portBASE_TYPE prvTaskConfigCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  138. /*
  139. * Implements the history command.
  140. */
  141. static portBASE_TYPE prvTaskHistoryCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  142. /*
  143. * Implements the sensor info command.
  144. */
  145. static portBASE_TYPE prvTaskSensorCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  146. /*
  147. * Implements the firmware download http command.
  148. */
  149. static portBASE_TYPE prvTaskUploadCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  150. /*
  151. * Implements the ups command.
  152. */
  153. static portBASE_TYPE prvTaskUPSCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  154. /* Structure that defines the "info" command line command. This
  155. generates a table that shows how much run time each task has */
  156. static const CLI_Command_Definition_t prvInfoCommandDefinition =
  157. {
  158. ( const int8_t * const ) "info", /* The command string to type. */
  159. ( const int8_t * const ) "\tinfo: вывод информации о контроллере\r\n"
  160. "\tinfo address <adrr>: установка поля \"адрес расположения контролируемого объекта\"\r\n"
  161. "\tinfo owner <owner>: установка поля \"организация (собственник)\"\r\n"
  162. "\tinfo comments <comment>: установка поля \"комментарии\"\r\n",
  163. prvTaskInfoCommand, /* The function to run. */
  164. -1 /* The user can enter any number of commands. */
  165. };
  166. /* Structure that defines the "reboot" command line command. This
  167. generates a table that shows how much run time each task has */
  168. static const CLI_Command_Definition_t prvRebootCommandDefinition =
  169. {
  170. ( const int8_t * const ) "reboot", /* The command string to type. */
  171. ( const int8_t * const ) "\treboot: перезагрузка Контроллера\r\n",
  172. prvTaskRebootCommand, /* The function to run. */
  173. 0 /* No parameters are expected. */
  174. };
  175. /* Structure that defines the "systime" command line command. This
  176. generates a table that shows how much run time each task has */
  177. static const CLI_Command_Definition_t prvSystimeCommandDefinition =
  178. {
  179. ( const int8_t * const ) "systime", /* The command string to type. */
  180. ( const int8_t * const ) "\tsystime: вывод системного времени\r\n"
  181. "\tsystime date <YYYY-MM-DD>: установка даты\r\n"
  182. "\tsystime time <HH:MM>: установка времени\r\n",
  183. prvTaskSystimeCommand, /* The function to run. */
  184. -1 /* The user can enter any number of commands. */
  185. };
  186. /* Structure that defines the "ntp" command line command. This
  187. generates a table that shows how much run time each task has */
  188. static const CLI_Command_Definition_t prvNTPCommandDefinition =
  189. {
  190. ( const int8_t * const ) "ntp", /* The command string to type. */
  191. ( const int8_t * const ) "\tntp ENA|DIS: разрешение/запрет синхронизации времени\r\n"
  192. "\tntp set IP <A.B.C.D>: установка сервера NTP\r\n"
  193. "\tntp info: вывод информации о сервере NTP\r\n"
  194. "\tntp set gmt <SIGN><NUM>: установка часового пояса\r\n",
  195. prvTaskNTPCommand, /* The function to run. */
  196. -1 /* The user can enter any number of commands. */
  197. };
  198. /* Structure that defines the "network" command line command. This
  199. generates a table that shows how much run time each task has */
  200. static const CLI_Command_Definition_t prvNetworkCommandDefinition =
  201. {
  202. ( const int8_t * const ) "network", /* The command string to type. */
  203. ( const int8_t * const ) "\tnetwork info вывод информации о текущих сетевых настройках:\r\n"
  204. "\tnetwork dhcp ENA|DIS: разрешение/запрет получения IP по DHCP\r\n"
  205. "\tnetwork ip <A.B.C.D>: установка статического IP\r\n"
  206. "\tnetwork gw <A.B.C.D>: установка шлюза\r\n"
  207. "\tnetwork mask <A.B.C.D>: установка маски подсети\r\n",
  208. prvTaskNetworkCommand, /* The function to run. */
  209. -1 /* The user can enter any number of commands. */
  210. };
  211. /* Structure that defines the "snmp" command line command. This
  212. generates a table that shows how much run time each task has */
  213. static const CLI_Command_Definition_t prvSNMPCommandDefinition =
  214. {
  215. ( const int8_t * const ) "snmp", /* The command string to type. */
  216. ( const int8_t * const ) "\tsnmp info: вывод информации о текущих SNMP настройках\r\n"
  217. "\tsnmp server <NUM> <A.B.C.D>: установка сервера SNMP\r\n"
  218. "\tsnmp community read <read>: установка Read community\r\n"
  219. "\tsnmp community write <write>: установка Write community\r\n",
  220. prvTaskSNMPCommand, /* The function to run. */
  221. -1 /* The user can enter any number of commands. */
  222. };
  223. /* Structure that defines the "user" command line command. This
  224. generates a table that shows how much run time each task has */
  225. static const CLI_Command_Definition_t prvUserCommandDefinition =
  226. {
  227. ( const int8_t * const ) "user", /* The command string to type. */
  228. ( const int8_t * const ) "\tuser passwd <name>: установка пароля для пользователя <name>\r\n",
  229. prvTaskUserCommand, /* The function to run. */
  230. 2 /* Two parameters are expected, which can take any value. */
  231. };
  232. /* Structure that defines the "config" command line command. This
  233. generates a table that shows how much run time each task has */
  234. static const CLI_Command_Definition_t prvConfigCommandDefinition =
  235. {
  236. ( const int8_t * const ) "config", /* The command string to type. */
  237. ( const int8_t * const ) "\tconfig info: вывод информации о состоянии конфигураций\r\n"
  238. "\tconfig load default: загрузка конфигурации по умолчанию\r\n"
  239. "\tconfig apply: применение конфигурации\r\n"
  240. "\tconfig confirm: подтверждение конфигурации\r\n",
  241. prvTaskConfigCommand, /* The function to run. */
  242. -1 /* Two parameters are expected, which can take any value. */
  243. };
  244. /* Structure that defines the "history" command line command. This
  245. generates a table that shows how much run time each task has */
  246. static const CLI_Command_Definition_t prvHistoryCommandDefinition =
  247. {
  248. ( const int8_t * const ) "history", /* The command string to type. */
  249. ( const int8_t * const ) "\thistory show EVENTS|UPS <num_page>: вывод журнала\r\n",
  250. prvTaskHistoryCommand, /* The function to run. */
  251. 3 /* Two parameters are expected, which can take any value. */
  252. };
  253. /* Structure that defines the "sensor info" command line command. This
  254. generates a table that shows how much run time each task has */
  255. static const CLI_Command_Definition_t prvSensorCommandDefinition =
  256. {
  257. ( const int8_t * const ) "sensor info", /* The command string to type. */
  258. ( const int8_t * const ) "\tsensor info: вывод параметров системы\r\n",
  259. prvTaskSensorCommand, /* The function to run. */
  260. 1 /* No parameters are expected. */
  261. };
  262. /* Structure that defines the "firmware dowmload http" command line command. This
  263. generates a table that shows how much run time each task has */
  264. static const CLI_Command_Definition_t prvUploadCommandDefinition =
  265. {
  266. ( const int8_t * const ) "firmware download http", /* The command string to type. */
  267. ( const int8_t * const ) "\tfirmware download http: переход в режим обновления через Web-сервер\r\n",
  268. prvTaskUploadCommand, /* The function to run. */
  269. 2 /* No parameters are expected. */
  270. };
  271. /* Structure that defines the "ups" command line command. This
  272. generates a table that shows how much run time each task has */
  273. static const CLI_Command_Definition_t prvUPSCommandDefinition =
  274. {
  275. ( const int8_t * const ) "ups", /* The command string to type. */
  276. ( const int8_t * const ) "\tups battest <num>: управление процедурой тестирония АКБ:\r\n"
  277. "\t\t\t\t0 - Остановить тестирование\r\n"
  278. "\t\t\t\t1-99 - Запустить тест на x минут\r\n"
  279. "\t\t\t\t100 - Тестирование в течение 10 секунд\r\n"
  280. "\t\t\t\t999 - Тестирование до разряда\r\n"
  281. "\tups shutdown <num>: управление отключением нагрузки ИБП:\r\n"
  282. "\t\t\t\t0 - Остановить процедуру отключения нагрузки\r\n"
  283. "\t\t\t\tn - Отключить нагрузку через n минут\r\n"
  284. "\t\t\t\tn: 0.2, 0.3, ..., 1, 2, ..., 10\r\n",
  285. prvTaskUPSCommand, /* The function to run. */
  286. 2 /* Two parameters are expected, which can take any value. */
  287. };
  288. /*-----------------------------------------------------------*/
  289. void vRegisterCLICommands( void )
  290. {
  291. /* Register all the command line commands defined immediately above. */
  292. FreeRTOS_CLIRegisterCommand( &prvInfoCommandDefinition );
  293. FreeRTOS_CLIRegisterCommand( &prvRebootCommandDefinition );
  294. FreeRTOS_CLIRegisterCommand( &prvSystimeCommandDefinition );
  295. FreeRTOS_CLIRegisterCommand( &prvNTPCommandDefinition );
  296. FreeRTOS_CLIRegisterCommand( &prvNetworkCommandDefinition );
  297. FreeRTOS_CLIRegisterCommand( &prvSNMPCommandDefinition );
  298. FreeRTOS_CLIRegisterCommand( &prvUserCommandDefinition );
  299. FreeRTOS_CLIRegisterCommand( &prvConfigCommandDefinition );
  300. FreeRTOS_CLIRegisterCommand( &prvHistoryCommandDefinition );
  301. FreeRTOS_CLIRegisterCommand( &prvSensorCommandDefinition );
  302. FreeRTOS_CLIRegisterCommand( &prvUploadCommandDefinition );
  303. FreeRTOS_CLIRegisterCommand( &prvUPSCommandDefinition );
  304. }
  305. /*-----------------------------------------------------------*/
  306. static portBASE_TYPE prvTaskInfoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  307. {
  308. int8_t *pcParameterString;
  309. signed portBASE_TYPE xParameterStringLength, xReturn;
  310. portBASE_TYPE xParameterNumber = 1;
  311. char str[110];
  312. uint8_t len;
  313. int8_t num_arg = 0;
  314. uint8_t i;
  315. ( void ) pcCommandString;
  316. ( void ) xWriteBufferLen;
  317. configASSERT( pcWriteBuffer );
  318. num_arg = prvGetNumberOfParameters(pcCommandString);
  319. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  320. if(num_arg == 0){
  321. const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n**************Информация о Контроллере**************\r\n";
  322. /* Return the next command help string, before moving the pointer on to
  323. the next command in the list. */
  324. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  325. GetWorkTimeStr(str, &len);
  326. strcat(( char * ) pcWriteBuffer, "Время работы:\t\t\t");
  327. strncat(( char * ) pcWriteBuffer, str, len);
  328. strcat(( char * ) pcWriteBuffer, "\r\nМодель:\t\t\t\t");
  329. GetModelStr(str, &len);
  330. strncat(( char * ) pcWriteBuffer, str, len);
  331. strcat(( char * ) pcWriteBuffer, "\r\nДата производства:\t\t");
  332. GetProductionDataStr(str, &len);
  333. strncat(( char * ) pcWriteBuffer, str, len);
  334. strcat(( char * ) pcWriteBuffer, "\r\nВерсия ПО:\t\t\t");
  335. GetVersionStr(str, &len);
  336. strncat(( char * ) pcWriteBuffer, str, len);
  337. strcat(( char * ) pcWriteBuffer, "\r\nMAC адрес:\t\t\t");
  338. GetMacStr(str, &len);
  339. strncat(( char * ) pcWriteBuffer, str, len);
  340. strcat(( char * ) pcWriteBuffer, "\r\nСерийный номер:\t\t\t");
  341. GetSerialNumberStr(str, &len);
  342. strncat(( char * ) pcWriteBuffer, str, len);
  343. strcat(( char * ) pcWriteBuffer, "\r\nВладелец:\t\t\t");
  344. GetOwnerStr(str, &len);
  345. strncat(( char * ) pcWriteBuffer, str, len);
  346. strcat(( char * ) pcWriteBuffer, "\r\nМестоположение:\t\t\t");
  347. GetLocationStr(str, &len);
  348. strncat(( char * ) pcWriteBuffer, str, len);
  349. strcat(( char * ) pcWriteBuffer, "\r\nКомментарии:\t\t\t");
  350. GetCommentsStr(str, &len);
  351. strncat(( char * ) pcWriteBuffer, str, len);
  352. strcat(( char * ) pcWriteBuffer, "\r\n");
  353. /* There are no more commands in the list, so there will be no more
  354. strings to return after this one and pdFALSE should be returned. */
  355. xReturn = pdFALSE;
  356. }
  357. else if(num_arg == 1)
  358. {
  359. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  360. xReturn = pdFALSE;
  361. }
  362. else{
  363. /* Obtain the parameter string. */
  364. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  365. (
  366. pcCommandString, /* The command string itself. */
  367. xParameterNumber, /* Return the next parameter. */
  368. &xParameterStringLength /* Store the parameter string length. */
  369. );
  370. for(i = 0; i < INFO_ALL_ARGS; i ++){
  371. if( strncmp( ( const char * ) pcParameterString, info_args_list[i], xParameterStringLength ) == 0 ){
  372. break;
  373. }
  374. }
  375. xParameterNumber ++;
  376. // xParameterNumber ++;
  377. /* Obtain the parameter string. */
  378. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  379. (
  380. pcCommandString, /* The command string itself. */
  381. xParameterNumber, /* Return the next parameter. */
  382. &xParameterStringLength /* Store the parameter string length. */
  383. );
  384. memset(str, 0, sizeof(str));
  385. xParameterStringLength = strlen(( const char * ) pcParameterString);
  386. if(xParameterStringLength > (int32_t)sizeof(str))
  387. xParameterStringLength = sizeof(str) - 1;
  388. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  389. if(control_string_en_digit(str, strlen(str))){
  390. switch(i){
  391. case INFO_ADDRESS:
  392. if(telnet_code_auth == ADMIN)
  393. SetLocation(str);
  394. else
  395. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  396. break;
  397. case INFO_OWNER:
  398. if(telnet_code_auth == ADMIN)
  399. SetOwner(str);
  400. else
  401. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  402. break;
  403. case INFO_COMMENTS:
  404. if(telnet_code_auth == ADMIN)
  405. SetComment(str);
  406. else
  407. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  408. break;
  409. default:
  410. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  411. break;
  412. }
  413. if(i >= INFO_ADDRESS && i <= INFO_COMMENTS){
  414. SETTINGS_Save();
  415. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  416. }
  417. }
  418. else{
  419. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  420. }
  421. xReturn = pdFALSE;
  422. }
  423. return xReturn;
  424. }
  425. static portBASE_TYPE prvTaskRebootCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  426. static bool start_reboot = true;
  427. const int8_t *const pcRebootHeader = ( int8_t * ) "Контроллер будет перезагружен через 1 секунду\r\n";
  428. ( void ) pcCommandString;
  429. ( void ) xWriteBufferLen;
  430. if(telnet_code_auth != ADMIN){
  431. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  432. return pdFALSE;
  433. }
  434. if(start_reboot){
  435. start_reboot = false;
  436. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcRebootHeader );
  437. return pdTRUE;
  438. }
  439. else{
  440. telnet_act = true;
  441. Reboot();
  442. return pdFALSE;
  443. }
  444. }
  445. static portBASE_TYPE prvTaskSystimeCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  446. int8_t *pcParameterString;
  447. signed portBASE_TYPE xParameterStringLength, xReturn;
  448. portBASE_TYPE xParameterNumber = 1;
  449. char str[110];
  450. uint8_t len;
  451. uint8_t i;
  452. uint8_t fail = 0;
  453. uint16_t temp = 0;
  454. ( void ) pcCommandString;
  455. ( void ) xWriteBufferLen;
  456. configASSERT( pcWriteBuffer );
  457. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  458. /* Obtain the parameter string. */
  459. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  460. (
  461. pcCommandString, /* The command string itself. */
  462. xParameterNumber, /* Return the next parameter. */
  463. &xParameterStringLength /* Store the parameter string length. */
  464. );
  465. if(pcParameterString == NULL){
  466. const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n******Системное время Контроллера******\r\n";
  467. /* Return the next command help string, before moving the pointer on to
  468. the next command in the list. */
  469. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  470. GetDateStr(str, &len);
  471. strcat(( char * ) pcWriteBuffer, "Дата:\t\t\t");
  472. strncat(( char * ) pcWriteBuffer, str, len);
  473. strcat(( char * ) pcWriteBuffer, "\r\nВремя:\t\t\t");
  474. GetTimeStr(str, &len);
  475. strncat(( char * ) pcWriteBuffer, str, len);
  476. strcat(( char * ) pcWriteBuffer, "\r\n");
  477. /* There are no more commands in the list, so there will be no more
  478. strings to return after this one and pdFALSE should be returned. */
  479. xReturn = pdFALSE;
  480. }
  481. else{
  482. if(telnet_code_auth != ADMIN){
  483. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  484. return pdFALSE;
  485. }
  486. for(i = 0; i < ARG_SYSTIME_ALL; i ++){
  487. if( strncmp( ( const char * ) pcParameterString, systime_args_list[i], xParameterStringLength ) == 0 ){
  488. break;
  489. }
  490. }
  491. if(i != ARG_SYSTIME_ALL){
  492. if(sSettings.sSNTP.sntpEnable){
  493. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  494. return pdFALSE;
  495. }
  496. }
  497. xParameterNumber ++;
  498. /* Obtain the parameter string. */
  499. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  500. (
  501. pcCommandString, /* The command string itself. */
  502. xParameterNumber, /* Return the next parameter. */
  503. &xParameterStringLength /* Store the parameter string length. */
  504. );
  505. if(pcParameterString == NULL){
  506. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  507. return pdFALSE;
  508. }
  509. memset(str, 0, sizeof(str));
  510. xParameterStringLength = strlen(( const char * ) pcParameterString);
  511. if(xParameterStringLength > (int32_t)sizeof(str))
  512. xParameterStringLength = sizeof(str) - 1;
  513. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  514. switch(i){
  515. case ARG_SYSTIME_DATA:
  516. if(xParameterStringLength == 10){
  517. for(uint8_t j = 0; j < xParameterStringLength; j++)
  518. {
  519. if(j != 4 && j != 7)
  520. {
  521. if(str[j] > 0x39 || str[j] < 0x30){
  522. fail = 1;
  523. }
  524. }
  525. else if(j == 4 || j == 7){
  526. if(str[j] != '-')
  527. fail = 1;
  528. }
  529. }
  530. if(!fail)
  531. {
  532. temp = 1000*(str[0] - 0x30) + 100*(str[1] - 0x30) + 10*(str[2] - 0x30) + str[3] - 0x30;
  533. if(temp > 2099 || temp < 2000)
  534. fail = 1;
  535. temp = 0;
  536. temp = 10*(str[5] - 0x30) + (str[6] - 0x30);
  537. if(temp > 12)
  538. fail = 1;
  539. temp = 0;
  540. temp = 10*(str[8] - 0x30) + (str[9] - 0x30);
  541. if(temp > 31)
  542. fail = 1;
  543. }
  544. }
  545. else{
  546. fail = 1;
  547. }
  548. if(!fail){
  549. SetDateStr(str);
  550. SETTINGS_Save();
  551. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  552. }
  553. else
  554. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  555. break;
  556. case ARG_SYSTIME_TIME:
  557. if(xParameterStringLength == 5){
  558. for(uint8_t j = 0; j < xParameterStringLength; j++)
  559. {
  560. if(j != 2)
  561. {
  562. if(str[j] > 0x39 || str[j] < 0x30)
  563. fail = 1;
  564. }
  565. else if(j == 2){
  566. if(str[j] != ':')
  567. fail = 1;
  568. }
  569. }
  570. if(!fail)
  571. {
  572. temp = 10*(str[0] - 0x30) + (str[1] - 0x30);
  573. if(temp > 23)
  574. fail = 1;
  575. temp = 0;
  576. temp = 10*(str[3] - 0x30) + (str[4] - 0x30);
  577. if(temp > 59)
  578. fail = 1;
  579. }
  580. }
  581. else{
  582. fail = 1;
  583. }
  584. if(!fail){
  585. SetTimeStr(str);
  586. SETTINGS_Save();
  587. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  588. }
  589. else
  590. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  591. break;
  592. default:
  593. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  594. break;
  595. }
  596. xReturn = pdFALSE;
  597. }
  598. return xReturn;
  599. }
  600. /*
  601. * Implements the ntp command.
  602. */
  603. static portBASE_TYPE prvTaskNTPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  604. int8_t *pcParameterString;
  605. signed portBASE_TYPE xParameterStringLength, xReturn;
  606. portBASE_TYPE xParameterNumber = 1;
  607. char str[110];
  608. char str_temp[110];
  609. uint8_t len;
  610. uint8_t i;
  611. bool enable_old_sntp;
  612. const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n************NTP настройки Контроллера************\r\n";
  613. ( void ) pcCommandString;
  614. ( void ) xWriteBufferLen;
  615. configASSERT( pcWriteBuffer );
  616. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  617. /* Obtain the parameter string. */
  618. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  619. (
  620. pcCommandString, /* The command string itself. */
  621. xParameterNumber, /* Return the next parameter. */
  622. &xParameterStringLength /* Store the parameter string length. */
  623. );
  624. if(pcParameterString == NULL){
  625. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  626. return pdFALSE;
  627. }
  628. for(i = 0; i < ARG_NTP_ALL; i ++){
  629. if( strncmp( ( const char * ) pcParameterString, ntp_args_list[i], xParameterStringLength ) == 0 ){
  630. break;
  631. }
  632. }
  633. if(telnet_code_auth != ADMIN && i !=ARG_NTP_INFO){
  634. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  635. return pdFALSE;
  636. }
  637. xParameterNumber ++;
  638. /* Obtain the parameter string. */
  639. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  640. (
  641. pcCommandString, /* The command string itself. */
  642. xParameterNumber, /* Return the next parameter. */
  643. &xParameterStringLength /* Store the parameter string length. */
  644. );
  645. xParameterNumber ++;
  646. if(pcParameterString == NULL){
  647. switch(i){
  648. case ARG_NTP_ENABLE:
  649. enable_old_sntp = sSettings.sSNTP.sntpEnable;
  650. SetSntpStateStr("1");
  651. if(sSettings.sSNTP.sntpEnable != enable_old_sntp){
  652. SETTINGS_Save();
  653. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  654. SNTP_Init();
  655. //vTaskDelay(7000);
  656. SNTP_Poll();
  657. }
  658. break;
  659. case ARG_NTP_DISABLE:
  660. enable_old_sntp = sSettings.sSNTP.sntpEnable;
  661. SetSntpStateStr("0");
  662. if(sSettings.sSNTP.sntpEnable != enable_old_sntp){
  663. SETTINGS_Save();
  664. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  665. SNTP_Init();
  666. //vTaskDelay(7000);
  667. SNTP_Poll();
  668. }
  669. break;
  670. case ARG_NTP_INFO:
  671. /* Return the next command help string, before moving the pointer on to
  672. the next command in the list. */
  673. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  674. GetSntpStateStrRU(str, &len);
  675. strcat(( char * ) pcWriteBuffer, "Режим установки времени:\t");
  676. strncat(( char * ) pcWriteBuffer, str, len);
  677. strcat(( char * ) pcWriteBuffer, "\r\nIP адрес NTP сервера:\t\t");
  678. GetSntpServerIpStr(str, &len);
  679. strncat(( char * ) pcWriteBuffer, str, len);
  680. strcat(( char * ) pcWriteBuffer, "\r\nЧасовой пояс:\t\t\t");
  681. GetSntpTimeZoneStr(str, &len);
  682. strncat(( char * ) pcWriteBuffer, str, len);
  683. strcat(( char * ) pcWriteBuffer, "\r\nПоследняя дата синхронизации:\t");
  684. GetSntpLastDataStr(str, &len);
  685. strncat(( char * ) pcWriteBuffer, str, len);
  686. strcat(( char * ) pcWriteBuffer, "\r\n");
  687. break;
  688. default:
  689. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  690. break;
  691. }
  692. return pdFALSE;
  693. }
  694. if(i == ARG_NTP_SET){
  695. memset(str, 0, sizeof(str));
  696. if(xParameterStringLength > (int32_t)sizeof(str))
  697. xParameterStringLength = sizeof(str) - 1;
  698. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  699. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  700. (
  701. pcCommandString, /* The command string itself. */
  702. xParameterNumber, /* Return the next parameter. */
  703. &xParameterStringLength /* Store the parameter string length. */
  704. );
  705. if(pcParameterString != NULL){
  706. memset(str_temp, 0, sizeof(str_temp));
  707. if(xParameterStringLength > (int32_t)sizeof(str_temp))
  708. xParameterStringLength = sizeof(str_temp) - 1;
  709. strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
  710. if(strncmp(str, "IP", 2) == 0){
  711. if(xParameterStringLength <= 15){
  712. if(ipaddr_addr(str_temp) != IPADDR_NONE){
  713. if(strncmp(str_temp, sSettings.sSNTP.ip, strlen(str_temp)) != 0){
  714. SetSntpServerIpStr(str_temp);
  715. SETTINGS_Save();
  716. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  717. SNTP_Init();
  718. //vTaskDelay(7000);
  719. SNTP_Poll();
  720. }
  721. }
  722. else{
  723. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  724. }
  725. }
  726. else{
  727. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  728. }
  729. }
  730. else if(strncmp(str, "gmt", 3) == 0){
  731. if(xParameterStringLength > 1 && xParameterStringLength < 5){
  732. bool fail = false;
  733. if(str_temp[0] != '-' && str_temp[0] != '+')
  734. fail = true;
  735. if(!isdigit_int(str_temp[1]) && (!isdigit_int(str_temp[2]) && str_temp[2] != '.') && (!isdigit_int(str_temp[3]) && str_temp[3] != '.'))
  736. fail = true;
  737. if(xParameterStringLength == 5){
  738. if(!isdigit_int(str_temp[4]))
  739. fail = true;
  740. }
  741. if(!fail){
  742. float value = atof(str_temp);
  743. if(value > -12.0 && value < 12.0){
  744. SetSntpTimeZoneStr(str_temp);
  745. SETTINGS_Save();
  746. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  747. }
  748. else
  749. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  750. }
  751. else{
  752. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  753. }
  754. }
  755. else{
  756. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  757. }
  758. }
  759. else{
  760. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  761. }
  762. }
  763. else{
  764. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  765. }
  766. }
  767. else{
  768. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  769. }
  770. xReturn = pdFALSE;
  771. return xReturn;
  772. }
  773. /*
  774. * Implements the network command.
  775. */
  776. static portBASE_TYPE prvTaskNetworkCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  777. int8_t *pcParameterString;
  778. signed portBASE_TYPE xParameterStringLength, xReturn;
  779. portBASE_TYPE xParameterNumber = 1;
  780. char str[110];
  781. uint8_t i;
  782. ( void ) pcCommandString;
  783. ( void ) xWriteBufferLen;
  784. configASSERT( pcWriteBuffer );
  785. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  786. /* Obtain the parameter string. */
  787. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  788. (
  789. pcCommandString, /* The command string itself. */
  790. xParameterNumber, /* Return the next parameter. */
  791. &xParameterStringLength /* Store the parameter string length. */
  792. );
  793. if(pcParameterString == NULL){
  794. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  795. return pdFALSE;
  796. }
  797. for(i = 0; i < ARG_NETWORK_ALL; i ++){
  798. if( strncmp( ( const char * ) pcParameterString, network_args_list[i], xParameterStringLength ) == 0 ){
  799. break;
  800. }
  801. }
  802. if(telnet_code_auth != ADMIN && i !=ARG_NETWORK_INFO){
  803. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  804. return pdFALSE;
  805. }
  806. if(i != ARG_NETWORK_ALL && i != ARG_NETWORK_DHCP && i != ARG_NETWORK_INFO){
  807. if(sSettings.sWebTempParams.dhcpEnable){
  808. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  809. return pdFALSE;
  810. }
  811. }
  812. xParameterNumber ++;
  813. /* Obtain the parameter string. */
  814. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  815. (
  816. pcCommandString, /* The command string itself. */
  817. xParameterNumber, /* Return the next parameter. */
  818. &xParameterStringLength /* Store the parameter string length. */
  819. );
  820. if(pcParameterString == NULL){
  821. if(i == ARG_NETWORK_INFO){
  822. net_config_param(pcWriteBuffer);
  823. }
  824. else{
  825. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  826. }
  827. return pdFALSE;
  828. }
  829. memset(str, 0, sizeof(str));
  830. xParameterStringLength = strlen(( const char * ) pcParameterString);
  831. if(xParameterStringLength > (int32_t)sizeof(str))
  832. xParameterStringLength = sizeof(str) - 1;
  833. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  834. switch(i){
  835. case ARG_NETWORK_DHCP:
  836. if(strncmp(str, "ENA", 3) == 0){
  837. SetUDPDhcpStateStr("True");
  838. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  839. }
  840. else if(strncmp(str, "DIS", 3) == 0){
  841. SetUDPDhcpStateStr("False");
  842. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  843. }
  844. else
  845. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  846. break;
  847. case ARG_NETWORK_IP:
  848. if(xParameterStringLength <= 15){
  849. if(ipaddr_addr(str) != IPADDR_NONE){
  850. SetIPStr(str);
  851. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  852. }
  853. else
  854. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  855. }
  856. else{
  857. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  858. }
  859. break;
  860. case ARG_NETWORK_GW:
  861. if(xParameterStringLength <= 15){
  862. if(ipaddr_addr(str) != IPADDR_NONE){
  863. SetGatewayStr(str);
  864. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  865. }
  866. else
  867. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  868. }
  869. else{
  870. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  871. }
  872. break;
  873. case ARG_NETWORK_MASK:
  874. if(xParameterStringLength <= 15){
  875. if(ipaddr_addr(str) != IPADDR_NONE){
  876. SetMaskStr(str);
  877. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  878. }
  879. else
  880. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  881. }
  882. else{
  883. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  884. }
  885. break;
  886. default:
  887. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  888. break;
  889. }
  890. xReturn = pdFALSE;
  891. return xReturn;
  892. }
  893. /*
  894. * Implements the snmp command.
  895. */
  896. static portBASE_TYPE prvTaskSNMPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  897. int8_t *pcParameterString;
  898. signed portBASE_TYPE xParameterStringLength, xReturn;
  899. portBASE_TYPE xParameterNumber = 1;
  900. char str[20];
  901. char temp_str[20];
  902. uint8_t i;
  903. ( void ) pcCommandString;
  904. ( void ) xWriteBufferLen;
  905. configASSERT( pcWriteBuffer );
  906. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  907. /* Obtain the parameter string. */
  908. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  909. (
  910. pcCommandString, /* The command string itself. */
  911. xParameterNumber, /* Return the next parameter. */
  912. &xParameterStringLength /* Store the parameter string length. */
  913. );
  914. if(pcParameterString == NULL){
  915. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  916. return pdFALSE;
  917. }
  918. for(i = 0; i < ARG_SNMP_ALL; i ++){
  919. if( strncmp( ( const char * ) pcParameterString, snmp_args_list[i], xParameterStringLength ) == 0 ){
  920. break;
  921. }
  922. }
  923. if(telnet_code_auth != ADMIN && i !=ARG_SNMP_INFO){
  924. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  925. return pdFALSE;
  926. }
  927. xParameterNumber ++;
  928. /* Obtain the parameter string. */
  929. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  930. (
  931. pcCommandString, /* The command string itself. */
  932. xParameterNumber, /* Return the next parameter. */
  933. &xParameterStringLength /* Store the parameter string length. */
  934. );
  935. xParameterNumber ++;
  936. if(pcParameterString == NULL){
  937. if(i == ARG_SNMP_INFO){
  938. snmp_config_param(pcWriteBuffer);
  939. }
  940. else{
  941. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  942. }
  943. return pdFALSE;
  944. }
  945. memset(str, 0, sizeof(str));
  946. if(xParameterStringLength > (int32_t)sizeof(str))
  947. xParameterStringLength = sizeof(str) - 1;
  948. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  949. switch(i){
  950. case ARG_SNMP_SERVER:
  951. if(xParameterStringLength == 1 && isdigit_int(str[0])){
  952. int32_t temp = atoi(str);
  953. if(temp > 0 && temp < 6){
  954. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  955. (
  956. pcCommandString, /* The command string itself. */
  957. xParameterNumber, /* Return the next parameter. */
  958. &xParameterStringLength /* Store the parameter string length. */
  959. );
  960. if(pcParameterString != NULL){
  961. memset(str, 0, sizeof(str));
  962. xParameterStringLength = strlen(( const char * ) pcParameterString);
  963. if(xParameterStringLength > (int32_t)sizeof(str))
  964. xParameterStringLength = sizeof(str) - 1;
  965. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  966. if(xParameterStringLength <= 15){
  967. if(ipaddr_addr(str) != IPADDR_NONE){
  968. switch(temp){
  969. case 1:
  970. SetManagerIp(str);
  971. break;
  972. case 2:
  973. SetManagerIp2(str);
  974. break;
  975. case 3:
  976. SetManagerIp3(str);
  977. break;
  978. case 4:
  979. SetManagerIp4(str);
  980. break;
  981. case 5:
  982. SetManagerIp5(str);
  983. break;
  984. }
  985. if(temp > 0 && temp < 6){
  986. SETTINGS_Save();
  987. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  988. }
  989. }
  990. else{
  991. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  992. }
  993. }
  994. else{
  995. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  996. }
  997. }
  998. else{
  999. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1000. }
  1001. }
  1002. else{
  1003. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1004. }
  1005. }
  1006. else{
  1007. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1008. }
  1009. break;
  1010. case ARG_SNMP_COMMUNITY:
  1011. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1012. (
  1013. pcCommandString, /* The command string itself. */
  1014. xParameterNumber, /* Return the next parameter. */
  1015. &xParameterStringLength /* Store the parameter string length. */
  1016. );
  1017. if(pcParameterString != NULL){
  1018. memset(temp_str, 0, sizeof(temp_str));
  1019. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1020. if(xParameterStringLength > (int32_t)sizeof(temp_str))
  1021. xParameterStringLength = sizeof(temp_str) - 1;
  1022. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1023. if(control_string_en_digit(temp_str, strlen(temp_str))){
  1024. if(strncmp(str, "read", 4) == 0){
  1025. SetReadCommunity(temp_str);
  1026. SETTINGS_Save();
  1027. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1028. }
  1029. else if(strncmp(str, "write", 5) == 0){
  1030. SetWriteCommunity(temp_str);
  1031. SETTINGS_Save();
  1032. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1033. }
  1034. else
  1035. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1036. }
  1037. else{
  1038. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1039. }
  1040. }
  1041. else{
  1042. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1043. }
  1044. break;
  1045. default:
  1046. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1047. break;
  1048. }
  1049. xReturn = pdFALSE;
  1050. return xReturn;
  1051. }
  1052. /*
  1053. * Implements the change password command.
  1054. */
  1055. static portBASE_TYPE prvTaskUserCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1056. int8_t *pcParameterString;
  1057. signed portBASE_TYPE xParameterStringLength, xReturn;
  1058. portBASE_TYPE xParameterNumber = 1;
  1059. uint8_t i;
  1060. char temp_str[MAX_WEB_LOGIN_LEN];
  1061. char WebLogin[MAX_WEB_LOGIN_LEN];
  1062. uint8_t valueLen, user_id;
  1063. const int8_t * const pcChangePWDHeader = ( int8_t * ) "\r\nВведите новый пароль:";
  1064. ( void ) pcCommandString;
  1065. ( void ) xWriteBufferLen;
  1066. configASSERT( pcWriteBuffer );
  1067. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1068. if(telnet_code_auth != ADMIN){
  1069. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1070. return pdFALSE;
  1071. }
  1072. /* Obtain the parameter string. */
  1073. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1074. (
  1075. pcCommandString, /* The command string itself. */
  1076. xParameterNumber, /* Return the next parameter. */
  1077. &xParameterStringLength /* Store the parameter string length. */
  1078. );
  1079. if(pcParameterString == NULL){
  1080. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1081. return pdFALSE;
  1082. }
  1083. for(i = 0; i < ARG_USER_ALL; i ++){
  1084. if( strncmp( ( const char * ) pcParameterString, user_args_list[i], xParameterStringLength ) == 0 ){
  1085. break;
  1086. }
  1087. }
  1088. xParameterNumber ++;
  1089. /* Obtain the parameter string. */
  1090. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1091. (
  1092. pcCommandString, /* The command string itself. */
  1093. xParameterNumber, /* Return the next parameter. */
  1094. &xParameterStringLength /* Store the parameter string length. */
  1095. );
  1096. if(i == ARG_USER_PWD){
  1097. memset(temp_str, 0, sizeof(temp_str));
  1098. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1099. if(xParameterStringLength > (int32_t)sizeof(temp_str)){
  1100. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1101. }
  1102. else{
  1103. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1104. for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
  1105. GetUserLogin(user_id, WebLogin, &valueLen);
  1106. /* Check login and password */
  1107. if (strncmp(WebLogin, temp_str, MAX_WEB_LOGIN_LEN) == 0) {
  1108. /* Login and pass are valid */
  1109. id_change_pwd = user_id;
  1110. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcChangePWDHeader, strlen( ( char * ) pcChangePWDHeader ) );
  1111. telnetState = TELNET_CHANGE_PWD;
  1112. break;
  1113. }
  1114. }
  1115. if(telnetState != TELNET_CHANGE_PWD){
  1116. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1117. }
  1118. }
  1119. }
  1120. else{
  1121. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1122. }
  1123. xReturn = pdFALSE;
  1124. return xReturn;
  1125. }
  1126. /*
  1127. * Implements the config command.
  1128. */
  1129. static portBASE_TYPE prvTaskConfigCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1130. int8_t *pcParameterString;
  1131. signed portBASE_TYPE xParameterStringLength, xReturn;
  1132. portBASE_TYPE xParameterNumber = 1;
  1133. char str[110];
  1134. uint8_t i;
  1135. static uint8_t config_menu = 0;
  1136. static start = 0;
  1137. const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n*********Конфигурация Контроллера*********\r\n";
  1138. ( void ) pcCommandString;
  1139. ( void ) xWriteBufferLen;
  1140. configASSERT( pcWriteBuffer );
  1141. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1142. /* Obtain the parameter string. */
  1143. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1144. (
  1145. pcCommandString, /* The command string itself. */
  1146. xParameterNumber, /* Return the next parameter. */
  1147. &xParameterStringLength /* Store the parameter string length. */
  1148. );
  1149. if(pcParameterString == NULL){
  1150. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1151. return pdFALSE;
  1152. }
  1153. for(i = 0; i < ARG_CONFIG_ALL; i ++){
  1154. if( strncmp( ( const char * ) pcParameterString, config_args_list[i], xParameterStringLength ) == 0 ){
  1155. break;
  1156. }
  1157. }
  1158. if(telnet_code_auth != ADMIN && i !=ARG_CONFIG_INFO){
  1159. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1160. return pdFALSE;
  1161. }
  1162. xParameterNumber ++;
  1163. /* Obtain the parameter string. */
  1164. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1165. (
  1166. pcCommandString, /* The command string itself. */
  1167. xParameterNumber, /* Return the next parameter. */
  1168. &xParameterStringLength /* Store the parameter string length. */
  1169. );
  1170. if(pcParameterString == NULL){
  1171. switch(i){
  1172. case ARG_CONFIG_INFO:
  1173. switch(config_menu){
  1174. case 0:
  1175. /* Return the next command help string, before moving the pointer on to
  1176. the next command in the list. */
  1177. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  1178. snmp_config_param(pcWriteBuffer);
  1179. break;
  1180. case 1:
  1181. inouts_config_param(pcWriteBuffer);
  1182. break;
  1183. case 2:
  1184. net_config_param(pcWriteBuffer);
  1185. break;
  1186. case 3:
  1187. time_config_param(pcWriteBuffer);
  1188. break;
  1189. }
  1190. config_menu ++;
  1191. if(config_menu == 4){
  1192. config_menu = 0;
  1193. return pdFALSE;
  1194. }
  1195. else{
  1196. return pdTRUE;
  1197. }
  1198. break;
  1199. case ARG_CONFIG_APPLY:
  1200. if(!start){
  1201. /* Если параметры WEB изменились выставляем флаг, сохраняем настройки и перезагружаемся */
  1202. if (GetStateWebReinit() == true)
  1203. {
  1204. start = 1;
  1205. #ifdef HARDWARE_BT6706
  1206. telnet_act = true;
  1207. #endif
  1208. SetWebReinitFlag(true);
  1209. HTTP_SaveSettings();
  1210. strcpy( ( char * ) pcWriteBuffer, "\t\tНастройки сохранены! Контроллер будет перезагружен\r\n\tПосле перезагрузки подтвердите изменения сетевых настроек\r\n");
  1211. return pdTRUE;
  1212. }
  1213. }
  1214. else{
  1215. #ifdef HARDWARE_BT6706
  1216. telnet_act = true;
  1217. #endif
  1218. start = 0;
  1219. vTaskDelay(1010);
  1220. Reboot();
  1221. }
  1222. break;
  1223. case ARG_CONFIG_CONFIRM:
  1224. telnet_act = true;
  1225. SetWebReinitFlag(false);
  1226. SetConfirmWebParamsFlag();
  1227. strcpy( ( char * ) pcWriteBuffer, "\t\tСетевые настройки подтверждены!\r\n");
  1228. break;
  1229. default:
  1230. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1231. break;
  1232. }
  1233. return pdFALSE;
  1234. }
  1235. if(i == ARG_CONFIG_LOAD){
  1236. memset(str, 0, sizeof(str));
  1237. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1238. if(xParameterStringLength > (int32_t)sizeof(str))
  1239. xParameterStringLength = sizeof(str) - 1;
  1240. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1241. if(xParameterStringLength < 13){
  1242. if(strncmp(str, "default", 7) == 0){
  1243. SNMP_SendUserTrap(DEVICE_RESTORED);
  1244. log_event_data(LOG_SYSTEM_DEFCONFIG, name_login_telnet);
  1245. vTaskDelay(500);
  1246. SETTINGS_SetPartDefault();
  1247. SETTINGS_Save();
  1248. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1249. strcpy( ( char * ) pcWriteBuffer, "\t\tНастройки сброшены к настройкам по умолчанию!\r\n");
  1250. }
  1251. else{
  1252. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1253. }
  1254. }
  1255. else{
  1256. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1257. }
  1258. }
  1259. else{
  1260. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1261. }
  1262. xReturn = pdFALSE;
  1263. return xReturn;
  1264. }
  1265. /*
  1266. * Implements the history command.
  1267. */
  1268. static portBASE_TYPE prvTaskHistoryCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1269. int8_t *pcParameterString;
  1270. signed portBASE_TYPE xParameterStringLength, xReturn;
  1271. portBASE_TYPE xParameterNumber = 1;
  1272. char str[110];
  1273. uint8_t i;
  1274. static int16_t num_page = 0;
  1275. static int16_t num_page_temp = 1;
  1276. static bool start = true;
  1277. const int8_t * const pcUPShistoryTableHeader = ( int8_t * ) "\r\n***********Журнал событий ИБП***********\r\n";
  1278. const int8_t * const pcControllerHistoryTableHeader = ( int8_t * ) "\r\n***********Журнал событий Контроллера***********\r\n";
  1279. ( void ) pcCommandString;
  1280. ( void ) xWriteBufferLen;
  1281. configASSERT( pcWriteBuffer );
  1282. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1283. /* Obtain the parameter string. */
  1284. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1285. (
  1286. pcCommandString, /* The command string itself. */
  1287. xParameterNumber, /* Return the next parameter. */
  1288. &xParameterStringLength /* Store the parameter string length. */
  1289. );
  1290. if(pcParameterString == NULL){
  1291. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1292. return pdFALSE;
  1293. }
  1294. if( strncmp( ( const char * ) pcParameterString, "show", xParameterStringLength ) != 0 ){
  1295. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1296. return pdFALSE;
  1297. }
  1298. xParameterNumber ++;
  1299. /* Obtain the parameter string. */
  1300. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1301. (
  1302. pcCommandString, /* The command string itself. */
  1303. xParameterNumber, /* Return the next parameter. */
  1304. &xParameterStringLength /* Store the parameter string length. */
  1305. );
  1306. for(i = 0; i < ARG_HISTORY_ALL; i ++){
  1307. if( strncmp( ( const char * ) pcParameterString, history_args_list[i], xParameterStringLength ) == 0 ){
  1308. break;
  1309. }
  1310. }
  1311. xParameterNumber ++;
  1312. /* Obtain the parameter string. */
  1313. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1314. (
  1315. pcCommandString, /* The command string itself. */
  1316. xParameterNumber, /* Return the next parameter. */
  1317. &xParameterStringLength /* Store the parameter string length. */
  1318. );
  1319. memset(str, 0, sizeof(str));
  1320. if(xParameterStringLength > 5){
  1321. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1322. return pdFALSE;
  1323. }
  1324. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1325. if(num_page == 0){
  1326. num_page = atoi(str);
  1327. if(num_page <= 0){
  1328. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1329. return pdFALSE;
  1330. }
  1331. }
  1332. switch(i){
  1333. case ARG_HISTORY_EVENTS:
  1334. if(start){
  1335. start = false;
  1336. /* Return the next command help string, before moving the pointer on to
  1337. the next command in the list. */
  1338. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcControllerHistoryTableHeader, strlen( ( char * ) pcControllerHistoryTableHeader ) );
  1339. memset(str, 0, sizeof(str));
  1340. strcat(( char * ) pcWriteBuffer, "\r\n");
  1341. sprintf(str, "Количество страниц журнала: %d\r\n", History_GetPageCount());
  1342. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  1343. strcat(( char * ) pcWriteBuffer, "\r\n");
  1344. if(num_page > History_GetPageCount())
  1345. num_page = History_GetPageCount();
  1346. }
  1347. History_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  1348. num_page --;
  1349. num_page_temp ++;
  1350. if(num_page == 0){
  1351. num_page = 0;
  1352. num_page_temp = 1;
  1353. start = true;
  1354. xReturn = pdFALSE;
  1355. }
  1356. else{
  1357. xReturn = pdTRUE;
  1358. }
  1359. break;
  1360. case ARG_HISTORY_UPS:
  1361. if(start){
  1362. start = false;
  1363. /* Return the next command help string, before moving the pointer on to
  1364. the next command in the list. */
  1365. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcUPShistoryTableHeader, strlen( ( char * ) pcUPShistoryTableHeader ) );
  1366. memset(str, 0, sizeof(str));
  1367. sprintf(str, "Количество страниц журнала: %d\r\n", LOG_GetPageCount());
  1368. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  1369. if(num_page > LOG_GetPageCount())
  1370. num_page = LOG_GetPageCount();
  1371. }
  1372. LOG_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  1373. num_page --;
  1374. num_page_temp ++;
  1375. if(num_page == 0){
  1376. num_page = 0;
  1377. num_page_temp = 1;
  1378. start = true;
  1379. xReturn = pdFALSE;
  1380. }
  1381. else{
  1382. xReturn = pdTRUE;
  1383. }
  1384. break;
  1385. default:
  1386. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1387. xReturn = pdFALSE;
  1388. break;
  1389. }
  1390. return xReturn;
  1391. }
  1392. /*
  1393. * Implements the sensor info command.
  1394. */
  1395. static portBASE_TYPE prvTaskSensorCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1396. int8_t *pcParameterString;
  1397. signed portBASE_TYPE xParameterStringLength, xReturn;
  1398. portBASE_TYPE xParameterNumber = 1;
  1399. uint8_t i;
  1400. static uint8_t config_menu = 0;
  1401. const int8_t * const pcSensorTableHeader = ( int8_t * ) "\r\n*********Параметры Контроллера*********\r\n";
  1402. ( void ) pcCommandString;
  1403. ( void ) xWriteBufferLen;
  1404. configASSERT( pcWriteBuffer );
  1405. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1406. /* Obtain the parameter string. */
  1407. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1408. (
  1409. pcCommandString, /* The command string itself. */
  1410. xParameterNumber, /* Return the next parameter. */
  1411. &xParameterStringLength /* Store the parameter string length. */
  1412. );
  1413. if(pcParameterString == NULL){
  1414. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1415. return pdFALSE;
  1416. }
  1417. for(i = 0; i < ARG_SENSOR_ALL; i ++){
  1418. if( strncmp( ( const char * ) pcParameterString, sensor_args_list[i], xParameterStringLength ) == 0 ){
  1419. break;
  1420. }
  1421. }
  1422. xParameterNumber ++;
  1423. /* Obtain the parameter string. */
  1424. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1425. (
  1426. pcCommandString, /* The command string itself. */
  1427. xParameterNumber, /* Return the next parameter. */
  1428. &xParameterStringLength /* Store the parameter string length. */
  1429. );
  1430. if(pcParameterString == NULL){
  1431. if(i == ARG_SENSOR_INFO){
  1432. switch(config_menu){
  1433. case 0:
  1434. /* Return the next command help string, before moving the pointer on to
  1435. the next command in the list. */
  1436. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSensorTableHeader, strlen( ( char * ) pcSensorTableHeader ) );
  1437. ups_sensor_param(pcWriteBuffer);
  1438. break;
  1439. case 1:
  1440. ups_sensor_akb_param(pcWriteBuffer);
  1441. break;
  1442. case 2:
  1443. inouts_sensor_param(pcWriteBuffer);
  1444. break;
  1445. }
  1446. config_menu ++;
  1447. if(config_menu == 3){
  1448. config_menu = 0;
  1449. return pdFALSE;
  1450. }
  1451. else{
  1452. return pdTRUE;
  1453. }
  1454. }
  1455. else{
  1456. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1457. }
  1458. }
  1459. else{
  1460. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1461. }
  1462. xReturn = pdFALSE;
  1463. return xReturn;
  1464. }
  1465. /*
  1466. * Implements the firmware download http command.
  1467. */
  1468. static portBASE_TYPE prvTaskUploadCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1469. static bool start_update = true;
  1470. const int8_t *const pcUploadHeader = ( int8_t * ) "Контроллер переводится в режим загрузчика\r\n";
  1471. ( void ) pcCommandString;
  1472. ( void ) xWriteBufferLen;
  1473. if(telnet_code_auth != ADMIN){
  1474. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1475. return pdFALSE;
  1476. }
  1477. if(start_update){
  1478. start_update = false;
  1479. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcUploadHeader );
  1480. return pdTRUE;
  1481. }
  1482. else{
  1483. telnet_act = true;
  1484. HTTP_StartResetTask(true);
  1485. return pdFALSE;
  1486. }
  1487. }
  1488. /*
  1489. * Implements the ups command.
  1490. */
  1491. static portBASE_TYPE prvTaskUPSCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1492. int8_t *pcParameterString;
  1493. signed portBASE_TYPE xParameterStringLength, xReturn;
  1494. portBASE_TYPE xParameterNumber = 1;
  1495. char str[110];
  1496. int32_t val = 0;
  1497. float val_float = 0;
  1498. int8_t res = 0;
  1499. uint8_t i;
  1500. ( void ) pcCommandString;
  1501. ( void ) xWriteBufferLen;
  1502. configASSERT( pcWriteBuffer );
  1503. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1504. if(telnet_code_auth != ADMIN && i !=ARG_CONFIG_INFO){
  1505. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1506. return pdFALSE;
  1507. }
  1508. /* Obtain the parameter string. */
  1509. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1510. (
  1511. pcCommandString, /* The command string itself. */
  1512. xParameterNumber, /* Return the next parameter. */
  1513. &xParameterStringLength /* Store the parameter string length. */
  1514. );
  1515. for(i = 0; i < ARG_UPS_ALL; i ++){
  1516. if( strncmp( ( const char * ) pcParameterString, ups_args_list[i], xParameterStringLength ) == 0 ){
  1517. break;
  1518. }
  1519. }
  1520. xParameterNumber ++;
  1521. /* Obtain the parameter string. */
  1522. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1523. (
  1524. pcCommandString, /* The command string itself. */
  1525. xParameterNumber, /* Return the next parameter. */
  1526. &xParameterStringLength /* Store the parameter string length. */
  1527. );
  1528. memset(str, 0, sizeof(str));
  1529. if(xParameterStringLength > 3){
  1530. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1531. return pdFALSE;
  1532. }
  1533. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1534. switch(i){
  1535. case ARG_UPS_BATTEST:
  1536. for(uint8_t j = 0; j < xParameterStringLength; j++){
  1537. if(!isdigit_int(str[j])){
  1538. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1539. return pdFALSE;
  1540. }
  1541. }
  1542. val = atoi(str);
  1543. if(val == 0){
  1544. res = ups_metac_service_pdu(ups_cancel_test);
  1545. if(res == 1){
  1546. log_event_data(LOG_TEST_UPS, "Администратор (Останов)");
  1547. strcpy( ( char * ) pcWriteBuffer, "\t\tТест остановлен!\r\n");
  1548. }
  1549. else{
  1550. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось остановить!\r\n");
  1551. }
  1552. }
  1553. else if(val > 0 && val < 100){
  1554. TimeParam = val;
  1555. res = ups_metac_service_pdu(ups_test_time);
  1556. if(res == 1){
  1557. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  1558. strcpy( ( char * ) pcWriteBuffer, "\t\tТест запущен!\r\n");
  1559. }
  1560. else{
  1561. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  1562. }
  1563. }
  1564. else if(val == 100){
  1565. res = ups_metac_service_pdu(ups_test_10sec);
  1566. if(res == 1){
  1567. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  1568. strcpy( ( char * ) pcWriteBuffer, "\t\tТест запущен!\r\n");
  1569. }
  1570. else{
  1571. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  1572. }
  1573. }
  1574. else if(val == 999){
  1575. res = ups_metac_service_pdu(ups_test_low_bat);
  1576. if(res == 1){
  1577. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  1578. strcpy( ( char * ) pcWriteBuffer, "\t\ttТест запущен!\r\n");
  1579. }
  1580. else{
  1581. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  1582. }
  1583. }
  1584. else{
  1585. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1586. }
  1587. break;
  1588. case ARG_UPS_SHUTDOWN:
  1589. for(uint8_t j = 0; j < xParameterStringLength; j++){
  1590. if(!isfloatdigit(str[j])){
  1591. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1592. return pdFALSE;
  1593. }
  1594. }
  1595. val_float = atof(str);
  1596. if(val_float == 0){
  1597. res = ups_metac_service_pdu(ups_cancel_shut_down);
  1598. if(res == 1){
  1599. log_event_data(LOG_SHUTDOWN_UPS, "Администратор (Останов)");
  1600. strcpy( ( char * ) pcWriteBuffer, "\t\t\tВыключение нагрузки ИБП отменено!\r\n");
  1601. }
  1602. else{
  1603. strcpy( ( char * ) pcWriteBuffer, "\t\tВыключение нагрузки ИБП не удалось отменить!\r\n");
  1604. }
  1605. }
  1606. else if(val_float > 0 && val_float <= 10){
  1607. TimeParamFloat = val_float;
  1608. res = ups_metac_service_pdu(ups_shutdown);
  1609. if(res == 1){
  1610. log_event_data(LOG_SHUTDOWN_UPS, "Администратор");
  1611. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП!\r\n");
  1612. }
  1613. else{
  1614. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП не удалось!\r\n");
  1615. }
  1616. }
  1617. else{
  1618. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1619. }
  1620. break;
  1621. default:
  1622. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1623. break;
  1624. }
  1625. xReturn = pdFALSE;
  1626. return xReturn;
  1627. }
  1628. /*-----------------------------------------------------------*/