Versão sem FFT e aquisição por DMA. 256 amostras.

Dependencies:   EthernetInterface NTPClient mbed-rtos mbed

Committer:
rebonatto
Date:
Tue Jan 05 11:45:44 2016 +0000
Revision:
0:e57bc370d339
Vers?o est?vel sem calculo de FFT. Aquisi??o por DMA. Usa 256 amostras.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rebonatto 0:e57bc370d339 1 #include "TelnetServer.h"
rebonatto 0:e57bc370d339 2 #include "Settings.h"
rebonatto 0:e57bc370d339 3 #include "Pmed_reset.h"
rebonatto 0:e57bc370d339 4
rebonatto 0:e57bc370d339 5 char *header_msg = "firmware update\r\n\r\n";
rebonatto 0:e57bc370d339 6 char *usage_msg = "Wrong arguments\r\nUsage: update <firmware filename>\r\n\r\n";
rebonatto 0:e57bc370d339 7 char *invalid_filename_msg = "Invalid filename. It must have at most 8 characters in the name and 3 in the extension\r\n\r\n";
rebonatto 0:e57bc370d339 8 char *file_does_not_exist_msg = "A file with the supplied filename does not exist.\r\n\r\n";
rebonatto 0:e57bc370d339 9 char *version_does_not_exist_msg = "Could not open version.txt. The update operation cannot continue.\r\n\r\n";
rebonatto 0:e57bc370d339 10 char *unable_to_create_remove_msg = "Unable to create remove.txt. The update operation cannot continue.\r\n\r\n";
rebonatto 0:e57bc370d339 11 char *unable_to_truncate_version_msg = "Unable to truncate version.txt. The update operation cannot continue.\r\n\r\n";
rebonatto 0:e57bc370d339 12 char *operation_successful_msg = "Operation was completed successfully. Now resetting...\r\n\r\n";
rebonatto 0:e57bc370d339 13
rebonatto 0:e57bc370d339 14 extern LocalFileSystem local;
rebonatto 0:e57bc370d339 15
rebonatto 0:e57bc370d339 16 int TelnetServer::UpdateCommand(TCPSocketConnection *conn,char** argv,int argc)
rebonatto 0:e57bc370d339 17 {
rebonatto 0:e57bc370d339 18 char old_filename[20];
rebonatto 0:e57bc370d339 19 char new_filename[20];
rebonatto 0:e57bc370d339 20
rebonatto 0:e57bc370d339 21 conn->send(header_msg,strlen(header_msg));
rebonatto 0:e57bc370d339 22 //0 - check if the file informed exists
rebonatto 0:e57bc370d339 23 if(argc != 2)
rebonatto 0:e57bc370d339 24 {
rebonatto 0:e57bc370d339 25 conn->send(usage_msg,strlen(usage_msg));
rebonatto 0:e57bc370d339 26 return 0;
rebonatto 0:e57bc370d339 27 }
rebonatto 0:e57bc370d339 28
rebonatto 0:e57bc370d339 29 strcpy(new_filename,"/local/");
rebonatto 0:e57bc370d339 30 strcat(new_filename,argv[1]);
rebonatto 0:e57bc370d339 31 new_filename[19] = '\0';
rebonatto 0:e57bc370d339 32 printf("New filename = %s\n",new_filename);
rebonatto 0:e57bc370d339 33
rebonatto 0:e57bc370d339 34 if(strlen(new_filename) > 19)
rebonatto 0:e57bc370d339 35 {
rebonatto 0:e57bc370d339 36 conn->send(invalid_filename_msg,strlen(invalid_filename_msg));
rebonatto 0:e57bc370d339 37 return 0;
rebonatto 0:e57bc370d339 38 }
rebonatto 0:e57bc370d339 39
rebonatto 0:e57bc370d339 40 FILE* fn = fopen(new_filename,"r");
rebonatto 0:e57bc370d339 41 if(fn == NULL)
rebonatto 0:e57bc370d339 42 {
rebonatto 0:e57bc370d339 43 conn->send(file_does_not_exist_msg,strlen(file_does_not_exist_msg));
rebonatto 0:e57bc370d339 44 return 0;
rebonatto 0:e57bc370d339 45 }
rebonatto 0:e57bc370d339 46 fclose(fn);
rebonatto 0:e57bc370d339 47
rebonatto 0:e57bc370d339 48 //1 - write remove.txt with the current FW filename
rebonatto 0:e57bc370d339 49 fn = fopen("/local/version.txt","r");
rebonatto 0:e57bc370d339 50 if(fn == NULL)
rebonatto 0:e57bc370d339 51 {
rebonatto 0:e57bc370d339 52 conn->send(version_does_not_exist_msg,strlen(version_does_not_exist_msg));
rebonatto 0:e57bc370d339 53 return 0;
rebonatto 0:e57bc370d339 54 }
rebonatto 0:e57bc370d339 55 int rd = fread(old_filename,1,19,fn);
rebonatto 0:e57bc370d339 56 old_filename[rd]='\0';
rebonatto 0:e57bc370d339 57 fclose(fn);
rebonatto 0:e57bc370d339 58
rebonatto 0:e57bc370d339 59 fn = fopen("/local/remove.txt","w");
rebonatto 0:e57bc370d339 60 if(fn == NULL)
rebonatto 0:e57bc370d339 61 {
rebonatto 0:e57bc370d339 62 conn->send(unable_to_create_remove_msg,strlen(unable_to_create_remove_msg));
rebonatto 0:e57bc370d339 63 return 0;
rebonatto 0:e57bc370d339 64 }
rebonatto 0:e57bc370d339 65 fwrite(old_filename,1,strlen(old_filename),fn);
rebonatto 0:e57bc370d339 66 fclose(fn);
rebonatto 0:e57bc370d339 67
rebonatto 0:e57bc370d339 68 //2 - write version.txt with the new FW filename
rebonatto 0:e57bc370d339 69 fn = fopen("/local/version.txt","w");
rebonatto 0:e57bc370d339 70 if(fn == NULL)
rebonatto 0:e57bc370d339 71 {
rebonatto 0:e57bc370d339 72 conn->send(unable_to_truncate_version_msg,strlen(unable_to_truncate_version_msg));
rebonatto 0:e57bc370d339 73 return 0;
rebonatto 0:e57bc370d339 74 }
rebonatto 0:e57bc370d339 75 fwrite(new_filename,1,strlen(new_filename),fn);
rebonatto 0:e57bc370d339 76 fclose(fn);
rebonatto 0:e57bc370d339 77
rebonatto 0:e57bc370d339 78 //3 - remove the old fw file
rebonatto 0:e57bc370d339 79 local.remove(old_filename);
rebonatto 0:e57bc370d339 80
rebonatto 0:e57bc370d339 81 //4 - remove remove.txt
rebonatto 0:e57bc370d339 82 local.remove("remove.txt");
rebonatto 0:e57bc370d339 83
rebonatto 0:e57bc370d339 84 conn->send(operation_successful_msg,strlen(operation_successful_msg));
rebonatto 0:e57bc370d339 85
rebonatto 0:e57bc370d339 86 //5 - reset
rebonatto 0:e57bc370d339 87 delete conn;
rebonatto 0:e57bc370d339 88
rebonatto 0:e57bc370d339 89 Pmed_reset(PMEDLOG_UPDATETELNET);
rebonatto 0:e57bc370d339 90
rebonatto 0:e57bc370d339 91 return 0;
rebonatto 0:e57bc370d339 92 }