protegemed, aquisição via A/D simples utilizando interrupção do timer
Dependencies: EthernetInterface NTPClient mbed-rtos mbed
Fork of ptgm_semDMA by
Codes/TelnetCommands/telnet_update.cpp@1:8129536051df, 2016-01-13 (annotated)
- Committer:
- viniciushl
- Date:
- Wed Jan 13 18:53:25 2016 +0000
- Revision:
- 1:8129536051df
- Parent:
- 0:fac116e94d44
Alterada captura para aquisi??o simples do A/D utilizando interrup??o do timer;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rebonatto | 0:fac116e94d44 | 1 | #include "TelnetServer.h" |
rebonatto | 0:fac116e94d44 | 2 | #include "Settings.h" |
rebonatto | 0:fac116e94d44 | 3 | #include "Pmed_reset.h" |
rebonatto | 0:fac116e94d44 | 4 | |
rebonatto | 0:fac116e94d44 | 5 | char *header_msg = "firmware update\r\n\r\n"; |
rebonatto | 0:fac116e94d44 | 6 | char *usage_msg = "Wrong arguments\r\nUsage: update <firmware filename>\r\n\r\n"; |
rebonatto | 0:fac116e94d44 | 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:fac116e94d44 | 8 | char *file_does_not_exist_msg = "A file with the supplied filename does not exist.\r\n\r\n"; |
rebonatto | 0:fac116e94d44 | 9 | char *version_does_not_exist_msg = "Could not open version.txt. The update operation cannot continue.\r\n\r\n"; |
rebonatto | 0:fac116e94d44 | 10 | char *unable_to_create_remove_msg = "Unable to create remove.txt. The update operation cannot continue.\r\n\r\n"; |
rebonatto | 0:fac116e94d44 | 11 | char *unable_to_truncate_version_msg = "Unable to truncate version.txt. The update operation cannot continue.\r\n\r\n"; |
rebonatto | 0:fac116e94d44 | 12 | char *operation_successful_msg = "Operation was completed successfully. Now resetting...\r\n\r\n"; |
rebonatto | 0:fac116e94d44 | 13 | |
rebonatto | 0:fac116e94d44 | 14 | extern LocalFileSystem local; |
rebonatto | 0:fac116e94d44 | 15 | |
rebonatto | 0:fac116e94d44 | 16 | int TelnetServer::UpdateCommand(TCPSocketConnection *conn,char** argv,int argc) |
rebonatto | 0:fac116e94d44 | 17 | { |
rebonatto | 0:fac116e94d44 | 18 | char old_filename[20]; |
rebonatto | 0:fac116e94d44 | 19 | char new_filename[20]; |
rebonatto | 0:fac116e94d44 | 20 | |
rebonatto | 0:fac116e94d44 | 21 | conn->send(header_msg,strlen(header_msg)); |
rebonatto | 0:fac116e94d44 | 22 | //0 - check if the file informed exists |
rebonatto | 0:fac116e94d44 | 23 | if(argc != 2) |
rebonatto | 0:fac116e94d44 | 24 | { |
rebonatto | 0:fac116e94d44 | 25 | conn->send(usage_msg,strlen(usage_msg)); |
rebonatto | 0:fac116e94d44 | 26 | return 0; |
rebonatto | 0:fac116e94d44 | 27 | } |
rebonatto | 0:fac116e94d44 | 28 | |
rebonatto | 0:fac116e94d44 | 29 | strcpy(new_filename,"/local/"); |
rebonatto | 0:fac116e94d44 | 30 | strcat(new_filename,argv[1]); |
rebonatto | 0:fac116e94d44 | 31 | new_filename[19] = '\0'; |
rebonatto | 0:fac116e94d44 | 32 | printf("New filename = %s\n",new_filename); |
rebonatto | 0:fac116e94d44 | 33 | |
rebonatto | 0:fac116e94d44 | 34 | if(strlen(new_filename) > 19) |
rebonatto | 0:fac116e94d44 | 35 | { |
rebonatto | 0:fac116e94d44 | 36 | conn->send(invalid_filename_msg,strlen(invalid_filename_msg)); |
rebonatto | 0:fac116e94d44 | 37 | return 0; |
rebonatto | 0:fac116e94d44 | 38 | } |
rebonatto | 0:fac116e94d44 | 39 | |
rebonatto | 0:fac116e94d44 | 40 | FILE* fn = fopen(new_filename,"r"); |
rebonatto | 0:fac116e94d44 | 41 | if(fn == NULL) |
rebonatto | 0:fac116e94d44 | 42 | { |
rebonatto | 0:fac116e94d44 | 43 | conn->send(file_does_not_exist_msg,strlen(file_does_not_exist_msg)); |
rebonatto | 0:fac116e94d44 | 44 | return 0; |
rebonatto | 0:fac116e94d44 | 45 | } |
rebonatto | 0:fac116e94d44 | 46 | fclose(fn); |
rebonatto | 0:fac116e94d44 | 47 | |
rebonatto | 0:fac116e94d44 | 48 | //1 - write remove.txt with the current FW filename |
rebonatto | 0:fac116e94d44 | 49 | fn = fopen("/local/version.txt","r"); |
rebonatto | 0:fac116e94d44 | 50 | if(fn == NULL) |
rebonatto | 0:fac116e94d44 | 51 | { |
rebonatto | 0:fac116e94d44 | 52 | conn->send(version_does_not_exist_msg,strlen(version_does_not_exist_msg)); |
rebonatto | 0:fac116e94d44 | 53 | return 0; |
rebonatto | 0:fac116e94d44 | 54 | } |
rebonatto | 0:fac116e94d44 | 55 | int rd = fread(old_filename,1,19,fn); |
rebonatto | 0:fac116e94d44 | 56 | old_filename[rd]='\0'; |
rebonatto | 0:fac116e94d44 | 57 | fclose(fn); |
rebonatto | 0:fac116e94d44 | 58 | |
rebonatto | 0:fac116e94d44 | 59 | fn = fopen("/local/remove.txt","w"); |
rebonatto | 0:fac116e94d44 | 60 | if(fn == NULL) |
rebonatto | 0:fac116e94d44 | 61 | { |
rebonatto | 0:fac116e94d44 | 62 | conn->send(unable_to_create_remove_msg,strlen(unable_to_create_remove_msg)); |
rebonatto | 0:fac116e94d44 | 63 | return 0; |
rebonatto | 0:fac116e94d44 | 64 | } |
rebonatto | 0:fac116e94d44 | 65 | fwrite(old_filename,1,strlen(old_filename),fn); |
rebonatto | 0:fac116e94d44 | 66 | fclose(fn); |
rebonatto | 0:fac116e94d44 | 67 | |
rebonatto | 0:fac116e94d44 | 68 | //2 - write version.txt with the new FW filename |
rebonatto | 0:fac116e94d44 | 69 | fn = fopen("/local/version.txt","w"); |
rebonatto | 0:fac116e94d44 | 70 | if(fn == NULL) |
rebonatto | 0:fac116e94d44 | 71 | { |
rebonatto | 0:fac116e94d44 | 72 | conn->send(unable_to_truncate_version_msg,strlen(unable_to_truncate_version_msg)); |
rebonatto | 0:fac116e94d44 | 73 | return 0; |
rebonatto | 0:fac116e94d44 | 74 | } |
rebonatto | 0:fac116e94d44 | 75 | fwrite(new_filename,1,strlen(new_filename),fn); |
rebonatto | 0:fac116e94d44 | 76 | fclose(fn); |
rebonatto | 0:fac116e94d44 | 77 | |
rebonatto | 0:fac116e94d44 | 78 | //3 - remove the old fw file |
rebonatto | 0:fac116e94d44 | 79 | local.remove(old_filename); |
rebonatto | 0:fac116e94d44 | 80 | |
rebonatto | 0:fac116e94d44 | 81 | //4 - remove remove.txt |
rebonatto | 0:fac116e94d44 | 82 | local.remove("remove.txt"); |
rebonatto | 0:fac116e94d44 | 83 | |
rebonatto | 0:fac116e94d44 | 84 | conn->send(operation_successful_msg,strlen(operation_successful_msg)); |
rebonatto | 0:fac116e94d44 | 85 | |
rebonatto | 0:fac116e94d44 | 86 | //5 - reset |
rebonatto | 0:fac116e94d44 | 87 | delete conn; |
rebonatto | 0:fac116e94d44 | 88 | |
rebonatto | 0:fac116e94d44 | 89 | Pmed_reset(PMEDLOG_UPDATETELNET); |
rebonatto | 0:fac116e94d44 | 90 | |
rebonatto | 0:fac116e94d44 | 91 | return 0; |
rebonatto | 0:fac116e94d44 | 92 | } |