|
@@ -471,6 +471,43 @@ static const CLI_Command_Definition_t prvUPSCommandDefinition = {
|
|
|
2 /* Two parameters are expected, which can take any value. */
|
|
|
};
|
|
|
|
|
|
+#ifdef FTP_ENABLE
|
|
|
+#include "ftp.h"
|
|
|
+
|
|
|
+#define FTP_ARGS_LIST \
|
|
|
+X(server_ip) \
|
|
|
+X(server_port) \
|
|
|
+X(remote_path) \
|
|
|
+X(user) \
|
|
|
+X(pass) \
|
|
|
+X(run) \
|
|
|
+
|
|
|
+typedef enum {
|
|
|
+#define X(name) ARG_FTP_##name,
|
|
|
+FTP_ARGS_LIST
|
|
|
+#undef X
|
|
|
+ARG_FTP_ALL,
|
|
|
+} ftp_args_t;
|
|
|
+const char *ftp_args_list[] = {
|
|
|
+#define X(name) #name,
|
|
|
+FTP_ARGS_LIST
|
|
|
+#undef X
|
|
|
+};
|
|
|
+
|
|
|
+static portBASE_TYPE prvTaskFTPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
|
|
+static const CLI_Command_Definition_t prvFTPCommandDefinition = {
|
|
|
+ (const int8_t *const)"ftp", /* The command string to type. */
|
|
|
+ (const int8_t *const)"\tftp server_ip <ip address>: задать адрес FTP-сервера\r\n"
|
|
|
+ "\tftp server_port <port>: задать порт FTP-сервера\r\n"
|
|
|
+ "\tftp remote_path <file path>: задать путь к файлу обновления ПО\r\n"
|
|
|
+ "\tftp user <username>: задать имя пользователя для аутентификации на FTP-сервере\r\n"
|
|
|
+ "\tftp pass <password>: задать пароль для аутентификации на FTP-сервере\r\n"
|
|
|
+ "\tftp run: запустить процесс обновления через FTP\r\n",
|
|
|
+ prvTaskFTPCommand, /* The function to run. */
|
|
|
+ 2
|
|
|
+};
|
|
|
+#endif
|
|
|
+
|
|
|
/* Structure that defines the "quit" command line command. This
|
|
|
generates a table that shows how much run time each task has */
|
|
|
static const CLI_Command_Definition_t prvQuitCommandDefinition = {
|
|
@@ -506,6 +543,9 @@ void vRegisterCLICommands( void )
|
|
|
FreeRTOS_CLIRegisterCommand( &prvSensorCommandDefinition );
|
|
|
FreeRTOS_CLIRegisterCommand( &prvUploadCommandDefinition );
|
|
|
FreeRTOS_CLIRegisterCommand( &prvUPSCommandDefinition );
|
|
|
+#ifdef FTP_ENABLE
|
|
|
+ FreeRTOS_CLIRegisterCommand( &prvFTPCommandDefinition );
|
|
|
+#endif
|
|
|
FreeRTOS_CLIRegisterCommand( &prvQuitCommandDefinition );
|
|
|
}
|
|
|
/*-----------------------------------------------------------*/
|
|
@@ -2821,5 +2861,125 @@ static portBASE_TYPE prvTaskUPSCommand(cli_state_t *cli_state, int8_t *pcWriteBu
|
|
|
return xReturn;
|
|
|
}
|
|
|
|
|
|
+#ifdef FTP_ENABLE
|
|
|
+#pragma GCC diagnostic error "-Wall"
|
|
|
+#pragma GCC diagnostic error "-Wextra"
|
|
|
+static portBASE_TYPE prvTaskFTPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString)
|
|
|
+{
|
|
|
+ int8_t *pcParameterString;
|
|
|
+ unsigned portBASE_TYPE xParameterStringLength;
|
|
|
+ signed portBASE_TYPE xReturn;
|
|
|
+ portBASE_TYPE xParameterNumber = 1;
|
|
|
+ char str[110];
|
|
|
+ uint8_t i;
|
|
|
+
|
|
|
+ ( void ) xWriteBufferLen;
|
|
|
+ configASSERT( pcWriteBuffer );
|
|
|
+
|
|
|
+ memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
|
|
|
+
|
|
|
+ if (cli_state->user_id != ADMIN) {
|
|
|
+ strncpy((char *)pcWriteBuffer, (const char *)pcPermissionDenied, strlen((char *)pcPermissionDenied));
|
|
|
+ return pdFALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Obtain the parameter string. */
|
|
|
+ pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
|
|
|
+ (
|
|
|
+ pcCommandString, /* The command string itself. */
|
|
|
+ xParameterNumber, /* Return the next parameter. */
|
|
|
+ &xParameterStringLength /* Store the parameter string length. */
|
|
|
+ );
|
|
|
+ for (i = 0; i < ARG_FTP_ALL; i ++) {
|
|
|
+ if ( strncmp( ( const char * ) pcParameterString, ftp_args_list[i], strlen(ftp_args_list[i]) ) == 0
|
|
|
+ && xParameterStringLength == strlen(ftp_args_list[i])) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ xParameterNumber ++;
|
|
|
+
|
|
|
+ /* Obtain the parameter string. */
|
|
|
+ pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
|
|
|
+ (
|
|
|
+ pcCommandString, /* The command string itself. */
|
|
|
+ xParameterNumber, /* Return the next parameter. */
|
|
|
+ &xParameterStringLength /* Store the parameter string length. */
|
|
|
+ );
|
|
|
+ memset(str, 0, sizeof(str));
|
|
|
+ if (xParameterStringLength > 3) {
|
|
|
+ strncpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand, strlen((char *)pcInvalidCommand));
|
|
|
+ return pdFALSE;
|
|
|
+ }
|
|
|
+ strncat(str, (const char *) pcParameterString, xParameterStringLength);
|
|
|
+
|
|
|
+ switch (i) {
|
|
|
+ case ARG_FTP_server_ip:
|
|
|
+ ;
|
|
|
+ ip_addr_t server_ip_old = sSettings.sFTPUpdate.server_ip;
|
|
|
+ if (!ipaddr_aton(str, &sSettings.sFTPUpdate.server_ip)) {
|
|
|
+ strncpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand, strlen((char *)pcInvalidCommand));
|
|
|
+ return pdFALSE;
|
|
|
+ }
|
|
|
+ if (!ip_addr_cmp(&sSettings.sFTPUpdate.server_ip, &server_ip_old)) {
|
|
|
+ cli_save_config(cli_state);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ARG_FTP_server_port:
|
|
|
+ ;
|
|
|
+ u16_t server_port_old = sSettings.sFTPUpdate.server_port;
|
|
|
+ int temp = atoi(str);
|
|
|
+ if (temp < 0 || temp > 65535) {
|
|
|
+ strncpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand, strlen((char *)pcInvalidCommand));
|
|
|
+ return pdFALSE;
|
|
|
+ } else {
|
|
|
+ sSettings.sFTPUpdate.server_port = temp;
|
|
|
+ if (sSettings.sFTPUpdate.server_port != server_port_old) {
|
|
|
+ cli_save_config(cli_state);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ARG_FTP_remote_path: {
|
|
|
+ unsigned len = strlen(str);
|
|
|
+ if (len < 1 || len >= sizeof(sSettings.sFTPUpdate.remote_path)) {
|
|
|
+ strncpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand, strlen((char *)pcInvalidCommand));
|
|
|
+ return pdFALSE;
|
|
|
+ } else {
|
|
|
+ strcpy(&sSettings.sFTPUpdate.remote_path, str);
|
|
|
+ cli_save_config(cli_state);
|
|
|
+ }
|
|
|
+ break; }
|
|
|
+ case ARG_FTP_user: {
|
|
|
+ unsigned len = strlen(str);
|
|
|
+ if (len < 1 || len >= sizeof(sSettings.sFTPUpdate.user)) {
|
|
|
+ strncpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand, strlen((char *)pcInvalidCommand));
|
|
|
+ return pdFALSE;
|
|
|
+ } else {
|
|
|
+ strcpy(&sSettings.sFTPUpdate.user, str);
|
|
|
+ cli_save_config(cli_state);
|
|
|
+ }
|
|
|
+ break; }
|
|
|
+ case ARG_FTP_pass: {
|
|
|
+ unsigned len = strlen(str);
|
|
|
+ if (len < 1 || len >= sizeof(sSettings.sFTPUpdate.pass)) {
|
|
|
+ strncpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand, strlen((char *)pcInvalidCommand));
|
|
|
+ return pdFALSE;
|
|
|
+ } else {
|
|
|
+ strcpy(&sSettings.sFTPUpdate.pass, str);
|
|
|
+ cli_save_config(cli_state);
|
|
|
+ }
|
|
|
+ break; }
|
|
|
+ case ARG_FTP_run: {
|
|
|
+ ftpcfg.settings = &sSettings.sFTPUpdate;
|
|
|
+ start_ftp_client(&ftpcfg);
|
|
|
+ break; }
|
|
|
+ default:
|
|
|
+ strncpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand, strlen((char *)pcInvalidCommand));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ xReturn = pdFALSE;
|
|
|
+
|
|
|
+ return xReturn;
|
|
|
+}
|
|
|
+#endif // FTP_ENABLE
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|