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_setparam.cpp@0:fac116e94d44, 2016-01-05 (annotated)
- Committer:
- rebonatto
- Date:
- Tue Jan 05 11:47:35 2016 +0000
- Revision:
- 0:fac116e94d44
Vers?o est?vel sem DMA e FFT. 128 amostras.
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 | |
rebonatto | 0:fac116e94d44 | 3 | #include "Settings.h" |
rebonatto | 0:fac116e94d44 | 4 | |
rebonatto | 0:fac116e94d44 | 5 | char *wrong_args_msg_set = "Wrong number of arguments.\r\n\r\nUsage: setparam <parameter name> <parameter value>\r\n"; |
rebonatto | 0:fac116e94d44 | 6 | char *param_not_found_msg_set = "Parameter not found.\r\n\r\n"; |
rebonatto | 0:fac116e94d44 | 7 | char *bad_argument_set = "The parameter supplied does not have a valid format.\r\n\r\n"; |
rebonatto | 0:fac116e94d44 | 8 | |
rebonatto | 0:fac116e94d44 | 9 | int TelnetServer::SetParamCommand(TCPSocketConnection *conn,char** argv,int argc) |
rebonatto | 0:fac116e94d44 | 10 | { |
rebonatto | 0:fac116e94d44 | 11 | |
rebonatto | 0:fac116e94d44 | 12 | if(argc != 3) |
rebonatto | 0:fac116e94d44 | 13 | { |
rebonatto | 0:fac116e94d44 | 14 | conn->send(wrong_args_msg_set,strlen(wrong_args_msg_set)); |
rebonatto | 0:fac116e94d44 | 15 | return 0; |
rebonatto | 0:fac116e94d44 | 16 | } |
rebonatto | 0:fac116e94d44 | 17 | |
rebonatto | 0:fac116e94d44 | 18 | |
rebonatto | 0:fac116e94d44 | 19 | if(!strcmp(argv[1],"Ipserver")) |
rebonatto | 0:fac116e94d44 | 20 | { |
rebonatto | 0:fac116e94d44 | 21 | ip_addr_t addr; |
rebonatto | 0:fac116e94d44 | 22 | if(ipaddr_aton(argv[2],&addr) != ERR_OK) |
rebonatto | 0:fac116e94d44 | 23 | { |
rebonatto | 0:fac116e94d44 | 24 | conn->send(bad_argument_set,strlen(bad_argument_set)); |
rebonatto | 0:fac116e94d44 | 25 | } |
rebonatto | 0:fac116e94d44 | 26 | else |
rebonatto | 0:fac116e94d44 | 27 | { |
rebonatto | 0:fac116e94d44 | 28 | Settings::set_ServerUrl(argv[2]); |
rebonatto | 0:fac116e94d44 | 29 | Settings::WriteFile(); |
rebonatto | 0:fac116e94d44 | 30 | } |
rebonatto | 0:fac116e94d44 | 31 | return 0; |
rebonatto | 0:fac116e94d44 | 32 | } |
rebonatto | 0:fac116e94d44 | 33 | |
rebonatto | 0:fac116e94d44 | 34 | if(!strcmp(argv[1],"Ipaddress")) |
rebonatto | 0:fac116e94d44 | 35 | { |
rebonatto | 0:fac116e94d44 | 36 | ip_addr_t addr; |
rebonatto | 0:fac116e94d44 | 37 | if(ipaddr_aton(argv[2],&addr) != ERR_OK) |
rebonatto | 0:fac116e94d44 | 38 | { |
rebonatto | 0:fac116e94d44 | 39 | conn->send(bad_argument_set,strlen(bad_argument_set)); |
rebonatto | 0:fac116e94d44 | 40 | } |
rebonatto | 0:fac116e94d44 | 41 | else |
rebonatto | 0:fac116e94d44 | 42 | { |
rebonatto | 0:fac116e94d44 | 43 | Settings::set_IpAddress(argv[2]); |
rebonatto | 0:fac116e94d44 | 44 | Settings::WriteFile(); |
rebonatto | 0:fac116e94d44 | 45 | } |
rebonatto | 0:fac116e94d44 | 46 | return 0; |
rebonatto | 0:fac116e94d44 | 47 | } |
rebonatto | 0:fac116e94d44 | 48 | |
rebonatto | 0:fac116e94d44 | 49 | if(!strcmp(argv[1],"module")) |
rebonatto | 0:fac116e94d44 | 50 | { |
rebonatto | 0:fac116e94d44 | 51 | Settings::set_ModuleNumber(atoi(argv[2])); |
rebonatto | 0:fac116e94d44 | 52 | Settings::WriteFile(); |
rebonatto | 0:fac116e94d44 | 53 | return 0; |
rebonatto | 0:fac116e94d44 | 54 | } |
rebonatto | 0:fac116e94d44 | 55 | |
rebonatto | 0:fac116e94d44 | 56 | /* Pega os números das tomadas [0..2]*/ |
rebonatto | 0:fac116e94d44 | 57 | int i; |
rebonatto | 0:fac116e94d44 | 58 | for(i=0;i<3;i++) |
rebonatto | 0:fac116e94d44 | 59 | { |
rebonatto | 0:fac116e94d44 | 60 | char b[12]; |
rebonatto | 0:fac116e94d44 | 61 | sprintf(b,"outlet%d",i); |
rebonatto | 0:fac116e94d44 | 62 | if(!strcmp(argv[1],b)) |
rebonatto | 0:fac116e94d44 | 63 | { |
rebonatto | 0:fac116e94d44 | 64 | Settings::set_Outlet(i,atoi(argv[2])); |
rebonatto | 0:fac116e94d44 | 65 | Settings::WriteFile(); |
rebonatto | 0:fac116e94d44 | 66 | return 0; |
rebonatto | 0:fac116e94d44 | 67 | } |
rebonatto | 0:fac116e94d44 | 68 | } |
rebonatto | 0:fac116e94d44 | 69 | /* Pega os canais, de 0..5 */ |
rebonatto | 0:fac116e94d44 | 70 | for(i=0;i<6;i++) |
rebonatto | 0:fac116e94d44 | 71 | { |
rebonatto | 0:fac116e94d44 | 72 | char b[12]; |
rebonatto | 0:fac116e94d44 | 73 | sprintf(b,"gain%d",i); |
rebonatto | 0:fac116e94d44 | 74 | if(!strcmp(argv[1],b)) |
rebonatto | 0:fac116e94d44 | 75 | { |
rebonatto | 0:fac116e94d44 | 76 | Settings::set_Gain(i,atof(argv[2])); |
rebonatto | 0:fac116e94d44 | 77 | Settings::WriteFile(); |
rebonatto | 0:fac116e94d44 | 78 | return 0; |
rebonatto | 0:fac116e94d44 | 79 | } |
rebonatto | 0:fac116e94d44 | 80 | |
rebonatto | 0:fac116e94d44 | 81 | sprintf(b,"offset%d",i); |
rebonatto | 0:fac116e94d44 | 82 | if(!strcmp(argv[1],b)) |
rebonatto | 0:fac116e94d44 | 83 | { |
rebonatto | 0:fac116e94d44 | 84 | Settings::set_Offset(i,atoi(argv[2])); |
rebonatto | 0:fac116e94d44 | 85 | Settings::WriteFile(); |
rebonatto | 0:fac116e94d44 | 86 | return 0; |
rebonatto | 0:fac116e94d44 | 87 | } |
rebonatto | 0:fac116e94d44 | 88 | |
rebonatto | 0:fac116e94d44 | 89 | sprintf(b,"limit%d",i); |
rebonatto | 0:fac116e94d44 | 90 | if(!strcmp(argv[1],b)) |
rebonatto | 0:fac116e94d44 | 91 | { |
rebonatto | 0:fac116e94d44 | 92 | Settings::set_Limit(i,atof(argv[2])); |
rebonatto | 0:fac116e94d44 | 93 | Settings::WriteFile(); |
rebonatto | 0:fac116e94d44 | 94 | return 0; |
rebonatto | 0:fac116e94d44 | 95 | } |
rebonatto | 0:fac116e94d44 | 96 | |
rebonatto | 0:fac116e94d44 | 97 | sprintf(b,"outlet_number%d",i); |
rebonatto | 0:fac116e94d44 | 98 | if(!strcmp(argv[1],b)) |
rebonatto | 0:fac116e94d44 | 99 | { |
rebonatto | 0:fac116e94d44 | 100 | Settings::set_OutletNumber(i,atoi(argv[2])); |
rebonatto | 0:fac116e94d44 | 101 | Settings::WriteFile(); |
rebonatto | 0:fac116e94d44 | 102 | return 0; |
rebonatto | 0:fac116e94d44 | 103 | } |
rebonatto | 0:fac116e94d44 | 104 | |
rebonatto | 0:fac116e94d44 | 105 | sprintf(b,"purpose%d",i); |
rebonatto | 0:fac116e94d44 | 106 | if(!strcmp(argv[1],b)) |
rebonatto | 0:fac116e94d44 | 107 | { |
rebonatto | 0:fac116e94d44 | 108 | Settings::set_Purpose(i,argv[2][0]); |
rebonatto | 0:fac116e94d44 | 109 | Settings::WriteFile(); |
rebonatto | 0:fac116e94d44 | 110 | return 0; |
rebonatto | 0:fac116e94d44 | 111 | } |
rebonatto | 0:fac116e94d44 | 112 | } |
rebonatto | 0:fac116e94d44 | 113 | |
rebonatto | 0:fac116e94d44 | 114 | /* |
rebonatto | 0:fac116e94d44 | 115 | if(!strcmp(argv[1],"Samples")) |
rebonatto | 0:fac116e94d44 | 116 | { |
rebonatto | 0:fac116e94d44 | 117 | Settings::set_Samples(atoi(argv[2])); |
rebonatto | 0:fac116e94d44 | 118 | Settings::WriteFile(); |
rebonatto | 0:fac116e94d44 | 119 | return 0; |
rebonatto | 0:fac116e94d44 | 120 | } |
rebonatto | 0:fac116e94d44 | 121 | */ |
rebonatto | 0:fac116e94d44 | 122 | if(!strcmp(argv[1],"EventLimit")) |
rebonatto | 0:fac116e94d44 | 123 | { |
rebonatto | 0:fac116e94d44 | 124 | Settings::set_EventLimit(atoi(argv[2])); |
rebonatto | 0:fac116e94d44 | 125 | Settings::WriteFile(); |
rebonatto | 0:fac116e94d44 | 126 | return 0; |
rebonatto | 0:fac116e94d44 | 127 | } |
rebonatto | 0:fac116e94d44 | 128 | |
rebonatto | 0:fac116e94d44 | 129 | if(!strcmp(argv[1],"LogMarksInterval")) |
rebonatto | 0:fac116e94d44 | 130 | { |
rebonatto | 0:fac116e94d44 | 131 | int value = atoi(argv[2]); |
rebonatto | 0:fac116e94d44 | 132 | if ( ! ( value > 0 ) ) { |
rebonatto | 0:fac116e94d44 | 133 | conn->send(bad_argument_set,strlen(bad_argument_set)); |
rebonatto | 0:fac116e94d44 | 134 | return 0; |
rebonatto | 0:fac116e94d44 | 135 | } |
rebonatto | 0:fac116e94d44 | 136 | Settings::set_LogMarksInterval(atoi(argv[2])); |
rebonatto | 0:fac116e94d44 | 137 | Settings::WriteFile(); |
rebonatto | 0:fac116e94d44 | 138 | return 0; |
rebonatto | 0:fac116e94d44 | 139 | } |
rebonatto | 0:fac116e94d44 | 140 | |
rebonatto | 0:fac116e94d44 | 141 | if(!strcmp(argv[1],"LogMarks")) |
rebonatto | 0:fac116e94d44 | 142 | { |
rebonatto | 0:fac116e94d44 | 143 | if ( strcmp(argv[2],"true") == 0 ) { |
rebonatto | 0:fac116e94d44 | 144 | Settings::set_LogMarks(true); |
rebonatto | 0:fac116e94d44 | 145 | } else { |
rebonatto | 0:fac116e94d44 | 146 | Settings::set_LogMarks(false); |
rebonatto | 0:fac116e94d44 | 147 | } |
rebonatto | 0:fac116e94d44 | 148 | Settings::WriteFile(); |
rebonatto | 0:fac116e94d44 | 149 | return 0; |
rebonatto | 0:fac116e94d44 | 150 | } |
rebonatto | 0:fac116e94d44 | 151 | |
rebonatto | 0:fac116e94d44 | 152 | conn->send(param_not_found_msg_set,strlen(param_not_found_msg_set)); |
rebonatto | 0:fac116e94d44 | 153 | return 0; |
rebonatto | 0:fac116e94d44 | 154 | |
rebonatto | 0:fac116e94d44 | 155 | } |