![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Versão do protegemed que calcula o tempo em ms da fuga, calcula o numero de onverflow (valores muito baixo) e underflow (valores muito altos). Além disso, calcula um valor médio a partir dos valores capturados e não apenas pela fft.
Dependencies: EthernetInterface mbed-rtos mbed
Codes/TelnetCommands/telnet_update.cpp@0:c64e1194230b, 2014-07-09 (annotated)
- Committer:
- rebonatto
- Date:
- Wed Jul 09 21:16:23 2014 +0000
- Revision:
- 0:c64e1194230b
Vers?o do Protegemed com calculo de tempo de fuga, overflow, underflow e novo valor m?dio (manual).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rebonatto | 0:c64e1194230b | 1 | #include "TelnetServer.h" |
rebonatto | 0:c64e1194230b | 2 | |
rebonatto | 0:c64e1194230b | 3 | |
rebonatto | 0:c64e1194230b | 4 | char *header_msg = "firmware update\r\n\r\n"; |
rebonatto | 0:c64e1194230b | 5 | char *usage_msg = "Wrong arguments\r\nUsage: update <firmware filename>\r\n\r\n"; |
rebonatto | 0:c64e1194230b | 6 | 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:c64e1194230b | 7 | char *file_does_not_exist_msg = "A file with the supplied filename does not exist.\r\n\r\n"; |
rebonatto | 0:c64e1194230b | 8 | char *version_does_not_exist_msg = "Could not open version.txt. The update operation cannot continue.\r\n\r\n"; |
rebonatto | 0:c64e1194230b | 9 | char *unable_to_create_remove_msg = "Unable to create remove.txt. The update operation cannot continue.\r\n\r\n"; |
rebonatto | 0:c64e1194230b | 10 | char *unable_to_truncate_version_msg = "Unable to truncate version.txt. The update operation cannot continue.\r\n\r\n"; |
rebonatto | 0:c64e1194230b | 11 | char *operation_successful_msg = "Operation was completed successfully. Now resetting...\r\n\r\n"; |
rebonatto | 0:c64e1194230b | 12 | |
rebonatto | 0:c64e1194230b | 13 | extern LocalFileSystem local; |
rebonatto | 0:c64e1194230b | 14 | extern "C" void mbed_reset(); |
rebonatto | 0:c64e1194230b | 15 | |
rebonatto | 0:c64e1194230b | 16 | int TelnetServer::UpdateCommand(TCPSocketConnection *conn,char** argv,int argc) |
rebonatto | 0:c64e1194230b | 17 | { |
rebonatto | 0:c64e1194230b | 18 | char old_filename[20]; |
rebonatto | 0:c64e1194230b | 19 | char new_filename[20]; |
rebonatto | 0:c64e1194230b | 20 | |
rebonatto | 0:c64e1194230b | 21 | conn->send(header_msg,strlen(header_msg)); |
rebonatto | 0:c64e1194230b | 22 | //0 - check if the file informed exists |
rebonatto | 0:c64e1194230b | 23 | if(argc != 2) |
rebonatto | 0:c64e1194230b | 24 | { |
rebonatto | 0:c64e1194230b | 25 | conn->send(usage_msg,strlen(usage_msg)); |
rebonatto | 0:c64e1194230b | 26 | return 0; |
rebonatto | 0:c64e1194230b | 27 | } |
rebonatto | 0:c64e1194230b | 28 | |
rebonatto | 0:c64e1194230b | 29 | strcpy(new_filename,"/local/"); |
rebonatto | 0:c64e1194230b | 30 | strcat(new_filename,argv[1]); |
rebonatto | 0:c64e1194230b | 31 | new_filename[19] = '\0'; |
rebonatto | 0:c64e1194230b | 32 | printf("New filename = %s\n",new_filename); |
rebonatto | 0:c64e1194230b | 33 | |
rebonatto | 0:c64e1194230b | 34 | if(strlen(new_filename) > 19) |
rebonatto | 0:c64e1194230b | 35 | { |
rebonatto | 0:c64e1194230b | 36 | conn->send(invalid_filename_msg,strlen(invalid_filename_msg)); |
rebonatto | 0:c64e1194230b | 37 | return 0; |
rebonatto | 0:c64e1194230b | 38 | } |
rebonatto | 0:c64e1194230b | 39 | |
rebonatto | 0:c64e1194230b | 40 | FILE* fn = fopen(new_filename,"r"); |
rebonatto | 0:c64e1194230b | 41 | if(fn == NULL) |
rebonatto | 0:c64e1194230b | 42 | { |
rebonatto | 0:c64e1194230b | 43 | conn->send(file_does_not_exist_msg,strlen(file_does_not_exist_msg)); |
rebonatto | 0:c64e1194230b | 44 | return 0; |
rebonatto | 0:c64e1194230b | 45 | } |
rebonatto | 0:c64e1194230b | 46 | fclose(fn); |
rebonatto | 0:c64e1194230b | 47 | |
rebonatto | 0:c64e1194230b | 48 | //1 - write remove.txt with the current FW filename |
rebonatto | 0:c64e1194230b | 49 | fn = fopen("/local/version.txt","r"); |
rebonatto | 0:c64e1194230b | 50 | if(fn == NULL) |
rebonatto | 0:c64e1194230b | 51 | { |
rebonatto | 0:c64e1194230b | 52 | conn->send(version_does_not_exist_msg,strlen(version_does_not_exist_msg)); |
rebonatto | 0:c64e1194230b | 53 | return 0; |
rebonatto | 0:c64e1194230b | 54 | } |
rebonatto | 0:c64e1194230b | 55 | int rd = fread(old_filename,1,19,fn); |
rebonatto | 0:c64e1194230b | 56 | old_filename[rd]='\0'; |
rebonatto | 0:c64e1194230b | 57 | fclose(fn); |
rebonatto | 0:c64e1194230b | 58 | |
rebonatto | 0:c64e1194230b | 59 | fn = fopen("/local/remove.txt","w"); |
rebonatto | 0:c64e1194230b | 60 | if(fn == NULL) |
rebonatto | 0:c64e1194230b | 61 | { |
rebonatto | 0:c64e1194230b | 62 | conn->send(unable_to_create_remove_msg,strlen(unable_to_create_remove_msg)); |
rebonatto | 0:c64e1194230b | 63 | return 0; |
rebonatto | 0:c64e1194230b | 64 | } |
rebonatto | 0:c64e1194230b | 65 | fwrite(old_filename,1,strlen(old_filename),fn); |
rebonatto | 0:c64e1194230b | 66 | fclose(fn); |
rebonatto | 0:c64e1194230b | 67 | |
rebonatto | 0:c64e1194230b | 68 | //2 - write version.txt with the new FW filename |
rebonatto | 0:c64e1194230b | 69 | fn = fopen("/local/version.txt","w"); |
rebonatto | 0:c64e1194230b | 70 | if(fn == NULL) |
rebonatto | 0:c64e1194230b | 71 | { |
rebonatto | 0:c64e1194230b | 72 | conn->send(unable_to_truncate_version_msg,strlen(unable_to_truncate_version_msg)); |
rebonatto | 0:c64e1194230b | 73 | return 0; |
rebonatto | 0:c64e1194230b | 74 | } |
rebonatto | 0:c64e1194230b | 75 | fwrite(new_filename,1,strlen(new_filename),fn); |
rebonatto | 0:c64e1194230b | 76 | fclose(fn); |
rebonatto | 0:c64e1194230b | 77 | |
rebonatto | 0:c64e1194230b | 78 | //3 - remove the old fw file |
rebonatto | 0:c64e1194230b | 79 | local.remove(old_filename); |
rebonatto | 0:c64e1194230b | 80 | |
rebonatto | 0:c64e1194230b | 81 | //4 - remove remove.txt |
rebonatto | 0:c64e1194230b | 82 | local.remove("remove.txt"); |
rebonatto | 0:c64e1194230b | 83 | |
rebonatto | 0:c64e1194230b | 84 | conn->send(operation_successful_msg,strlen(operation_successful_msg)); |
rebonatto | 0:c64e1194230b | 85 | |
rebonatto | 0:c64e1194230b | 86 | //5 - reset |
rebonatto | 0:c64e1194230b | 87 | delete conn; |
rebonatto | 0:c64e1194230b | 88 | |
rebonatto | 0:c64e1194230b | 89 | mbed_reset(); |
rebonatto | 0:c64e1194230b | 90 | |
rebonatto | 0:c64e1194230b | 91 | return 0; |
rebonatto | 0:c64e1194230b | 92 | } |