![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
prompt.cpp@65:0b653cfe95db, 2014-10-28 (annotated)
- Committer:
- klauss
- Date:
- Tue Oct 28 18:33:47 2014 +0000
- Revision:
- 65:0b653cfe95db
- Parent:
- 64:5b011d5707d2
- Child:
- 66:3f1d22e69e7b
resolvido bug do ++
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 44:cc4996469404 | 1 | #include "prompt.h" |
klauss | 54:448d57291be6 | 2 | #include "utils.h" |
Cola | 24:270b436a1bb0 | 3 | |
klauss | 45:c80574f24dc3 | 4 | TCPSocketServer tcp_server; |
klauss | 45:c80574f24dc3 | 5 | TCPSocketConnection tcp_client; |
klauss | 41:69bf7091c2ca | 6 | Timer tcp_timer; |
klauss | 48:195c97f12e8e | 7 | Timer udp_timer; |
klauss | 45:c80574f24dc3 | 8 | |
klauss | 45:c80574f24dc3 | 9 | UDPSocket udp_server; |
klauss | 45:c80574f24dc3 | 10 | Endpoint udp_client; |
klauss | 41:69bf7091c2ca | 11 | |
klauss | 28:94aec56c6329 | 12 | uint8_t debug_alive = 0; |
klauss | 28:94aec56c6329 | 13 | uint8_t debug_sip = 0; |
klauss | 29:7246460b73f8 | 14 | uint8_t debug_vector = 0; |
klauss | 29:7246460b73f8 | 15 | uint8_t debug_cb = 0; |
klauss | 30:8dfb6d8de53d | 16 | uint8_t debug_main = 0; |
klauss | 31:bb5fb28a77df | 17 | uint8_t debug_cks = 0; |
Cola | 22:d2a4b5939115 | 18 | uint8_t pcks_s = 0; |
Cola | 24:270b436a1bb0 | 19 | uint8_t pshowcb = 0; |
klauss | 31:bb5fb28a77df | 20 | uint8_t debug_cb_rx = 0; |
klauss | 31:bb5fb28a77df | 21 | uint8_t debug_cb_tx = 0; |
klauss | 31:bb5fb28a77df | 22 | uint8_t debug_eth_rx = 0; |
klauss | 31:bb5fb28a77df | 23 | uint8_t debug_eth_tx = 0; |
klauss | 43:455522f98de5 | 24 | uint8_t debug_prompt_eth = 0; |
klauss | 31:bb5fb28a77df | 25 | uint8_t debug_file = 0; |
klauss | 38:af5ecd6997ab | 26 | bool from_eth = false; |
klauss | 42:480335bdde12 | 27 | bool udp_request = false; |
klauss | 42:480335bdde12 | 28 | bool tcp_session = false; |
klauss | 48:195c97f12e8e | 29 | bool cb_session = false; |
klauss | 48:195c97f12e8e | 30 | bool cb_status = false; |
klauss | 52:12930cef17c4 | 31 | bool reset_cks = false; |
klauss | 53:bb492a8f115a | 32 | bool debug_telemetry = false; |
klauss | 54:448d57291be6 | 33 | bool main_test = false; |
klauss | 60:b4ec6beb3be3 | 34 | bool flood_silence = false; |
klauss | 62:07e5bdc9f8f7 | 35 | bool list = false; |
klauss | 63:0d95da692bb4 | 36 | bool r_stats; |
klauss | 62:07e5bdc9f8f7 | 37 | bool rx = false; |
klauss | 63:0d95da692bb4 | 38 | bool tx = false; |
klauss | 63:0d95da692bb4 | 39 | bool stats = false; |
klauss | 65:0b653cfe95db | 40 | bool delayed_flood = false; |
klauss | 63:0d95da692bb4 | 41 | |
klauss | 63:0d95da692bb4 | 42 | uint16_t boot_counter = 0; |
klauss | 63:0d95da692bb4 | 43 | uint16_t registry_counter = 0; |
klauss | 63:0d95da692bb4 | 44 | uint16_t invite_counter = 0; |
klauss | 63:0d95da692bb4 | 45 | uint16_t audio_counter = 0; |
klauss | 63:0d95da692bb4 | 46 | uint16_t telemetry_counter = 0; |
klauss | 63:0d95da692bb4 | 47 | uint16_t cb_bye_counter = 0; |
klauss | 63:0d95da692bb4 | 48 | uint16_t prompt_counter = 0; |
klauss | 63:0d95da692bb4 | 49 | uint16_t flood_counter = 0; |
klauss | 28:94aec56c6329 | 50 | |
klauss | 29:7246460b73f8 | 51 | uint8_t test_debug = 1; |
klauss | 62:07e5bdc9f8f7 | 52 | #define PVERSION 5 // Sempre atualizar a versao do prompt |
klauss | 19:ab2088e0dec6 | 53 | |
klauss | 58:af7e8788f106 | 54 | char __debug_buf__[ DEBUGBUFSIZE ]; |
klauss | 35:96885a7931f0 | 55 | char * debug_buf = __debug_buf__; |
klauss | 58:af7e8788f106 | 56 | char last_cmd[ DEBUGBUFSIZE ]; |
klauss | 58:af7e8788f106 | 57 | char tmp_cmd[ DEBUGBUFSIZE ] = "help"; |
klauss | 30:8dfb6d8de53d | 58 | char last_debug_buf[ DEBUGBUFSIZE ] = "help"; |
klauss | 60:b4ec6beb3be3 | 59 | |
klauss | 56:c64bcbaa621a | 60 | FILE *fip, *fmask, *fgate, *fport, *fsip, *fsport, *fext, *fserext, *fudpport, *ftcpport, *ftip, *ftport; |
klauss | 19:ab2088e0dec6 | 61 | uint8_t debug_prompt = 0; |
klauss | 19:ab2088e0dec6 | 62 | uint8_t bufptr = 0; |
klauss | 35:96885a7931f0 | 63 | uint8_t last_bufptr = 0; |
klauss | 19:ab2088e0dec6 | 64 | |
klauss | 62:07e5bdc9f8f7 | 65 | uint8_t xmemmatch(const uint8_t * s1, const uint8_t * s2, uint16_t size) { |
klauss | 19:ab2088e0dec6 | 66 | while (size--) { |
klauss | 19:ab2088e0dec6 | 67 | if (*s1++ != *s2++) return 0; /* does not match */ |
klauss | 19:ab2088e0dec6 | 68 | } |
klauss | 19:ab2088e0dec6 | 69 | return 1; /* matches */ |
klauss | 19:ab2088e0dec6 | 70 | } |
klauss | 19:ab2088e0dec6 | 71 | |
klauss | 62:07e5bdc9f8f7 | 72 | uint8_t xstrmatch(const uint8_t * s1, const uint8_t * s2) { |
klauss | 19:ab2088e0dec6 | 73 | while (*s1) { |
klauss | 19:ab2088e0dec6 | 74 | if (*s1++ != *s2++) return 0; /* does not match */ |
klauss | 19:ab2088e0dec6 | 75 | } |
klauss | 19:ab2088e0dec6 | 76 | if ( *s2 == 0 ) |
klauss | 19:ab2088e0dec6 | 77 | return 1; /* matches */ |
klauss | 19:ab2088e0dec6 | 78 | else |
klauss | 19:ab2088e0dec6 | 79 | return 0; /* does not match */ |
klauss | 19:ab2088e0dec6 | 80 | } |
klauss | 19:ab2088e0dec6 | 81 | |
klauss | 62:07e5bdc9f8f7 | 82 | void xmemcpy(uint8_t * dest, const uint8_t * src, uint16_t size){ |
klauss | 19:ab2088e0dec6 | 83 | while (size--) *dest++ = *src++; |
klauss | 19:ab2088e0dec6 | 84 | } |
klauss | 19:ab2088e0dec6 | 85 | |
klauss | 48:195c97f12e8e | 86 | int str2uint ( char * s, unsigned int * val ){ |
Cola | 21:0bd688722e81 | 87 | int i = 0; |
Cola | 21:0bd688722e81 | 88 | unsigned int ret = 0; |
Cola | 21:0bd688722e81 | 89 | for (;;) { |
Cola | 21:0bd688722e81 | 90 | if (s[i] < '0') { |
Cola | 21:0bd688722e81 | 91 | *val = ret; |
Cola | 21:0bd688722e81 | 92 | return i; |
Cola | 21:0bd688722e81 | 93 | } |
Cola | 21:0bd688722e81 | 94 | ret *= 10; |
Cola | 21:0bd688722e81 | 95 | ret += s[i] - '0'; |
Cola | 21:0bd688722e81 | 96 | i++; |
Cola | 21:0bd688722e81 | 97 | } |
Cola | 21:0bd688722e81 | 98 | } |
klauss | 19:ab2088e0dec6 | 99 | |
klauss | 38:af5ecd6997ab | 100 | // Print the content of a given file |
klauss | 38:af5ecd6997ab | 101 | void cat(const char* fname){ |
klauss | 19:ab2088e0dec6 | 102 | char buff[513]; |
klauss | 19:ab2088e0dec6 | 103 | int num; |
klauss | 19:ab2088e0dec6 | 104 | |
klauss | 19:ab2088e0dec6 | 105 | FILE *fp = fopen(fname, "r"); |
klauss | 19:ab2088e0dec6 | 106 | if (fp == NULL) { |
klauss | 42:480335bdde12 | 107 | if( debug_file ) pc.printf( "Failed to open %s", fname); |
klauss | 19:ab2088e0dec6 | 108 | return; |
klauss | 19:ab2088e0dec6 | 109 | } |
klauss | 19:ab2088e0dec6 | 110 | |
klauss | 42:480335bdde12 | 111 | while( ( num = fread( buff, 1, 512, fp ) ) > 0 ){ |
klauss | 42:480335bdde12 | 112 | buff[ num ] = '\0'; |
klauss | 42:480335bdde12 | 113 | pc.printf( buff ); |
klauss | 42:480335bdde12 | 114 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 115 | if( tcp_session ) tcp_client.send_all( buff, strlen( buff ) ); |
klauss | 45:c80574f24dc3 | 116 | |
klauss | 45:c80574f24dc3 | 117 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 118 | udp_server.sendTo( udp_client, buff, strlen( buff ) ); |
klauss | 45:c80574f24dc3 | 119 | } |
klauss | 42:480335bdde12 | 120 | } |
klauss | 19:ab2088e0dec6 | 121 | } |
klauss | 19:ab2088e0dec6 | 122 | fclose(fp); |
klauss | 19:ab2088e0dec6 | 123 | } |
klauss | 19:ab2088e0dec6 | 124 | |
klauss | 28:94aec56c6329 | 125 | // operantion with the system config files |
klauss | 42:480335bdde12 | 126 | void files( const char type ){ |
klauss | 42:480335bdde12 | 127 | // show files |
klauss | 42:480335bdde12 | 128 | if (type == 's' ){ |
klauss | 56:c64bcbaa621a | 129 | //pc.printf("\n\rHeader IP " ); |
klauss | 56:c64bcbaa621a | 130 | pc.printf("Header IP " ); |
klauss | 42:480335bdde12 | 131 | if( from_eth ){ |
klauss | 56:c64bcbaa621a | 132 | //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rHeader IP " ); |
klauss | 56:c64bcbaa621a | 133 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Header IP " ); |
klauss | 45:c80574f24dc3 | 134 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 135 | |
klauss | 45:c80574f24dc3 | 136 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 137 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 138 | } |
klauss | 42:480335bdde12 | 139 | } |
klauss | 19:ab2088e0dec6 | 140 | cat("/qspi/myip.txt"); |
klauss | 42:480335bdde12 | 141 | |
klauss | 56:c64bcbaa621a | 142 | //pc.printf("\n\rHeader ext "); |
klauss | 56:c64bcbaa621a | 143 | pc.printf("Header ext "); |
klauss | 42:480335bdde12 | 144 | if( from_eth ){ |
klauss | 56:c64bcbaa621a | 145 | //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rHeader ext " ); |
klauss | 56:c64bcbaa621a | 146 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Header ext " ); |
klauss | 45:c80574f24dc3 | 147 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 148 | |
klauss | 45:c80574f24dc3 | 149 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 150 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 151 | } |
klauss | 42:480335bdde12 | 152 | } |
klauss | 28:94aec56c6329 | 153 | cat("/qspi/myext.txt"); |
klauss | 42:480335bdde12 | 154 | |
klauss | 56:c64bcbaa621a | 155 | //pc.printf("\n\rHeader port "); |
klauss | 56:c64bcbaa621a | 156 | pc.printf("Header port "); |
klauss | 42:480335bdde12 | 157 | if( from_eth ){ |
klauss | 56:c64bcbaa621a | 158 | //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rHeader port " ); |
klauss | 56:c64bcbaa621a | 159 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Header port " ); |
klauss | 45:c80574f24dc3 | 160 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 161 | |
klauss | 45:c80574f24dc3 | 162 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 163 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 164 | } |
klauss | 42:480335bdde12 | 165 | } |
klauss | 28:94aec56c6329 | 166 | cat("/qspi/mysipport.txt"); |
klauss | 28:94aec56c6329 | 167 | |
klauss | 56:c64bcbaa621a | 168 | //pc.printf("\n\rServer IP "); |
klauss | 56:c64bcbaa621a | 169 | pc.printf("Server IP "); |
klauss | 42:480335bdde12 | 170 | if( from_eth ){ |
klauss | 56:c64bcbaa621a | 171 | //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rServer IP " ); |
klauss | 56:c64bcbaa621a | 172 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Server IP " ); |
klauss | 45:c80574f24dc3 | 173 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 174 | |
klauss | 45:c80574f24dc3 | 175 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 176 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 177 | } |
klauss | 42:480335bdde12 | 178 | } |
klauss | 28:94aec56c6329 | 179 | cat("/qspi/serverip.txt"); |
klauss | 42:480335bdde12 | 180 | |
klauss | 56:c64bcbaa621a | 181 | //pc.printf("\n\rServer ext "); |
klauss | 56:c64bcbaa621a | 182 | pc.printf("Server ext "); |
klauss | 42:480335bdde12 | 183 | if( from_eth ){ |
klauss | 56:c64bcbaa621a | 184 | //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rServer ext " ); |
klauss | 56:c64bcbaa621a | 185 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Server ext " ); |
klauss | 45:c80574f24dc3 | 186 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 187 | |
klauss | 45:c80574f24dc3 | 188 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 189 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 190 | } |
klauss | 42:480335bdde12 | 191 | } |
klauss | 28:94aec56c6329 | 192 | cat("/qspi/peerext.txt"); |
klauss | 42:480335bdde12 | 193 | |
klauss | 56:c64bcbaa621a | 194 | //pc.printf("\n\rServer port "); |
klauss | 56:c64bcbaa621a | 195 | pc.printf("Server port "); |
klauss | 42:480335bdde12 | 196 | if( from_eth ){ |
klauss | 56:c64bcbaa621a | 197 | //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rServer port " ); |
klauss | 56:c64bcbaa621a | 198 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Server port " ); |
klauss | 45:c80574f24dc3 | 199 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 200 | |
klauss | 45:c80574f24dc3 | 201 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 202 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 203 | } |
klauss | 42:480335bdde12 | 204 | } |
klauss | 28:94aec56c6329 | 205 | cat("/qspi/serverport.txt"); |
klauss | 28:94aec56c6329 | 206 | |
klauss | 56:c64bcbaa621a | 207 | //pc.printf("\n\rMascara de rede "); |
klauss | 56:c64bcbaa621a | 208 | pc.printf("Mascara de rede "); |
klauss | 42:480335bdde12 | 209 | if( from_eth ){ |
klauss | 56:c64bcbaa621a | 210 | //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rMascara de rede " ); |
klauss | 56:c64bcbaa621a | 211 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Mascara de rede " ); |
klauss | 45:c80574f24dc3 | 212 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 213 | |
klauss | 45:c80574f24dc3 | 214 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 215 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 216 | } |
klauss | 42:480335bdde12 | 217 | } |
klauss | 19:ab2088e0dec6 | 218 | cat("/qspi/mymask.txt"); |
klauss | 42:480335bdde12 | 219 | |
klauss | 56:c64bcbaa621a | 220 | //pc.printf("\n\rGateway IP "); |
klauss | 56:c64bcbaa621a | 221 | pc.printf("Gateway IP "); |
klauss | 42:480335bdde12 | 222 | if( from_eth ){ |
klauss | 56:c64bcbaa621a | 223 | //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rGateway IP " ); |
klauss | 56:c64bcbaa621a | 224 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Gateway IP " ); |
klauss | 45:c80574f24dc3 | 225 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 226 | |
klauss | 45:c80574f24dc3 | 227 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 228 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 229 | } |
klauss | 42:480335bdde12 | 230 | } |
klauss | 19:ab2088e0dec6 | 231 | cat("/qspi/mygate.txt"); |
klauss | 43:455522f98de5 | 232 | |
klauss | 56:c64bcbaa621a | 233 | //pc.printf("\n\rUDP Port "); |
klauss | 56:c64bcbaa621a | 234 | pc.printf("UDP Port "); |
klauss | 45:c80574f24dc3 | 235 | if( from_eth ){ |
klauss | 56:c64bcbaa621a | 236 | //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rUDP Port " ); |
klauss | 56:c64bcbaa621a | 237 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "UDP Port " ); |
klauss | 45:c80574f24dc3 | 238 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 239 | |
klauss | 45:c80574f24dc3 | 240 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 241 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 242 | } |
klauss | 45:c80574f24dc3 | 243 | } |
klauss | 45:c80574f24dc3 | 244 | cat("/qspi/udpport.txt"); |
klauss | 45:c80574f24dc3 | 245 | |
klauss | 56:c64bcbaa621a | 246 | //pc.printf("\n\rTCP Port "); |
klauss | 56:c64bcbaa621a | 247 | pc.printf("TCP Port "); |
klauss | 45:c80574f24dc3 | 248 | if( from_eth ){ |
klauss | 56:c64bcbaa621a | 249 | //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rTCP Port " ); |
klauss | 56:c64bcbaa621a | 250 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "TCP Port " ); |
klauss | 45:c80574f24dc3 | 251 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 252 | |
klauss | 45:c80574f24dc3 | 253 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 254 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 255 | } |
klauss | 45:c80574f24dc3 | 256 | } |
klauss | 45:c80574f24dc3 | 257 | cat("/qspi/tcpport.txt"); |
klauss | 45:c80574f24dc3 | 258 | |
klauss | 56:c64bcbaa621a | 259 | //pc.printf("\n\rTelemetry Server IP "); |
klauss | 56:c64bcbaa621a | 260 | pc.printf("Telemetry Server IP "); |
klauss | 56:c64bcbaa621a | 261 | if( from_eth ){ |
klauss | 56:c64bcbaa621a | 262 | //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rTelemetry Server IP " ); |
klauss | 56:c64bcbaa621a | 263 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Telemetry Server IP " ); |
klauss | 56:c64bcbaa621a | 264 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 56:c64bcbaa621a | 265 | |
klauss | 56:c64bcbaa621a | 266 | else if( udp_request ){ |
klauss | 56:c64bcbaa621a | 267 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 56:c64bcbaa621a | 268 | } |
klauss | 56:c64bcbaa621a | 269 | } |
klauss | 56:c64bcbaa621a | 270 | cat("/qspi/telemetry_ip.txt"); |
klauss | 56:c64bcbaa621a | 271 | |
klauss | 56:c64bcbaa621a | 272 | //pc.printf("\n\rTelemetry Server Port "); |
klauss | 56:c64bcbaa621a | 273 | pc.printf("Telemetry Server Port "); |
klauss | 56:c64bcbaa621a | 274 | if( from_eth ){ |
klauss | 56:c64bcbaa621a | 275 | //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rTelemetry Server Port " ); |
klauss | 56:c64bcbaa621a | 276 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Telemetry Server Port " ); |
klauss | 56:c64bcbaa621a | 277 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 56:c64bcbaa621a | 278 | |
klauss | 56:c64bcbaa621a | 279 | else if( udp_request ){ |
klauss | 56:c64bcbaa621a | 280 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 56:c64bcbaa621a | 281 | } |
klauss | 56:c64bcbaa621a | 282 | } |
klauss | 56:c64bcbaa621a | 283 | cat("/qspi/telemetry_port.txt"); |
klauss | 56:c64bcbaa621a | 284 | |
klauss | 58:af7e8788f106 | 285 | strcpy( last_cmd, tmp_cmd ); |
klauss | 43:455522f98de5 | 286 | debug_buf[ 0 ] = 0; |
klauss | 43:455522f98de5 | 287 | bufptr = 0; |
klauss | 62:07e5bdc9f8f7 | 288 | if( tcp_session ) tcp_client.send_all( "\n\r> " , strlen( "\n\r> " ) ); |
klauss | 48:195c97f12e8e | 289 | |
klauss | 48:195c97f12e8e | 290 | else if( udp_request ){ |
klauss | 62:07e5bdc9f8f7 | 291 | udp_server.sendTo( udp_client, "\n\r> ", strlen( "\n\r> " ) ); |
klauss | 48:195c97f12e8e | 292 | } |
klauss | 19:ab2088e0dec6 | 293 | } |
klauss | 19:ab2088e0dec6 | 294 | |
klauss | 56:c64bcbaa621a | 295 | if (type == 'c' ){ |
klauss | 56:c64bcbaa621a | 296 | // close all files |
klauss | 28:94aec56c6329 | 297 | fclose( fip ); |
klauss | 28:94aec56c6329 | 298 | fclose( fmask ); |
klauss | 28:94aec56c6329 | 299 | fclose( fgate ); |
klauss | 28:94aec56c6329 | 300 | fclose( fport ); |
klauss | 28:94aec56c6329 | 301 | fclose( fsip ); |
klauss | 28:94aec56c6329 | 302 | fclose( fsport ); |
klauss | 28:94aec56c6329 | 303 | fclose( fext ); |
klauss | 28:94aec56c6329 | 304 | fclose( fserext ); |
klauss | 45:c80574f24dc3 | 305 | fclose( fudpport ); |
klauss | 45:c80574f24dc3 | 306 | fclose( ftcpport ); |
klauss | 19:ab2088e0dec6 | 307 | } |
klauss | 19:ab2088e0dec6 | 308 | |
klauss | 56:c64bcbaa621a | 309 | if (type == 'i' ){ |
klauss | 56:c64bcbaa621a | 310 | // Check if files exist, if not create the files |
klauss | 33:735fd60e96d8 | 311 | bool exists = true; |
klauss | 19:ab2088e0dec6 | 312 | fip = fopen("/qspi/myip.txt", "r"); |
klauss | 56:c64bcbaa621a | 313 | if( fip == NULL){ |
klauss | 56:c64bcbaa621a | 314 | set_ip( __MY_IP__ ); |
klauss | 33:735fd60e96d8 | 315 | exists = false; |
klauss | 19:ab2088e0dec6 | 316 | } |
klauss | 28:94aec56c6329 | 317 | |
klauss | 28:94aec56c6329 | 318 | fserext = fopen("/qspi/myext.txt", "r"); |
klauss | 56:c64bcbaa621a | 319 | if( fserext == NULL ){ |
klauss | 56:c64bcbaa621a | 320 | set_header_ext( __MY_EXT__ ); |
klauss | 56:c64bcbaa621a | 321 | exists = false; |
klauss | 28:94aec56c6329 | 322 | } |
klauss | 56:c64bcbaa621a | 323 | |
klauss | 28:94aec56c6329 | 324 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 28:94aec56c6329 | 325 | if (fport == NULL){ |
klauss | 56:c64bcbaa621a | 326 | set_header_sip_port( __MY_PORT__ ); |
klauss | 33:735fd60e96d8 | 327 | exists = false; |
klauss | 28:94aec56c6329 | 328 | } |
klauss | 28:94aec56c6329 | 329 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 28:94aec56c6329 | 330 | if (fsip == NULL){ |
klauss | 56:c64bcbaa621a | 331 | set_server_ip( __SERVER_IP__ ); |
klauss | 33:735fd60e96d8 | 332 | exists = false; |
klauss | 28:94aec56c6329 | 333 | } |
klauss | 28:94aec56c6329 | 334 | |
klauss | 28:94aec56c6329 | 335 | fext = fopen("/qspi/peerext.txt", "r"); |
klauss | 28:94aec56c6329 | 336 | if ( fext == NULL ){ |
klauss | 56:c64bcbaa621a | 337 | set_server_ext( __PEER_EXT__ ); |
klauss | 33:735fd60e96d8 | 338 | exists = false; |
klauss | 28:94aec56c6329 | 339 | } |
klauss | 28:94aec56c6329 | 340 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 28:94aec56c6329 | 341 | if (fsport == NULL){ |
klauss | 56:c64bcbaa621a | 342 | set_server_port( __SERVER_PORT__ ); |
klauss | 33:735fd60e96d8 | 343 | exists = false; |
klauss | 28:94aec56c6329 | 344 | } |
klauss | 28:94aec56c6329 | 345 | |
klauss | 19:ab2088e0dec6 | 346 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 19:ab2088e0dec6 | 347 | if (fmask == NULL){ |
klauss | 56:c64bcbaa621a | 348 | set_mask( __MY_MSK__ ); |
klauss | 33:735fd60e96d8 | 349 | exists = false; |
klauss | 19:ab2088e0dec6 | 350 | } |
klauss | 19:ab2088e0dec6 | 351 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 19:ab2088e0dec6 | 352 | if (fgate == NULL){ |
klauss | 56:c64bcbaa621a | 353 | set_gateway( __MY_GTW__ ); |
klauss | 45:c80574f24dc3 | 354 | exists = false; |
klauss | 45:c80574f24dc3 | 355 | } |
klauss | 45:c80574f24dc3 | 356 | fudpport = fopen("/qspi/udpport.txt", "r" ); |
klauss | 45:c80574f24dc3 | 357 | if( fudpport == NULL ){ |
klauss | 56:c64bcbaa621a | 358 | set_udp_port_listener( UDP_PORT_LISTENER ); |
klauss | 45:c80574f24dc3 | 359 | exists = false; |
klauss | 45:c80574f24dc3 | 360 | } |
klauss | 45:c80574f24dc3 | 361 | ftcpport = fopen("/qspi/tcpport.txt", "r" ); |
klauss | 45:c80574f24dc3 | 362 | if( ftcpport == NULL ){ |
klauss | 56:c64bcbaa621a | 363 | set_tcp_port_listener( TCP_PORT_LISTENER ); |
klauss | 33:735fd60e96d8 | 364 | exists = false; |
klauss | 19:ab2088e0dec6 | 365 | } |
klauss | 56:c64bcbaa621a | 366 | |
klauss | 56:c64bcbaa621a | 367 | ftip = fopen("/qspi/telemetry_ip.txt", "r" ); |
klauss | 56:c64bcbaa621a | 368 | if( ftip == NULL ){ |
klauss | 56:c64bcbaa621a | 369 | set_telemetry_ip( __TELEMETRY_SERVER_IP__ ); |
klauss | 56:c64bcbaa621a | 370 | exists = false; |
klauss | 56:c64bcbaa621a | 371 | } |
klauss | 56:c64bcbaa621a | 372 | |
klauss | 56:c64bcbaa621a | 373 | ftport = fopen("/qspi/telemetry_port.txt", "r" ); |
klauss | 56:c64bcbaa621a | 374 | if( ftport == NULL ){ |
klauss | 56:c64bcbaa621a | 375 | set_telemetry_port( __TELEMETRY_SERVER_PORT__ ); |
klauss | 56:c64bcbaa621a | 376 | exists = false; |
klauss | 56:c64bcbaa621a | 377 | } |
klauss | 56:c64bcbaa621a | 378 | |
klauss | 44:cc4996469404 | 379 | if( !exists ){ |
klauss | 44:cc4996469404 | 380 | pc.printf("\n\rDefault configurations set!\n\r"); |
klauss | 44:cc4996469404 | 381 | if( from_eth ){ |
klauss | 44:cc4996469404 | 382 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Default configurations set!\n\r"); |
klauss | 44:cc4996469404 | 383 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 44:cc4996469404 | 384 | if( tcp_session ){ |
klauss | 45:c80574f24dc3 | 385 | tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 44:cc4996469404 | 386 | debug_buf[ 0 ] = 0; |
klauss | 44:cc4996469404 | 387 | bufptr = 0; |
klauss | 44:cc4996469404 | 388 | } |
klauss | 44:cc4996469404 | 389 | } |
klauss | 44:cc4996469404 | 390 | } |
klauss | 19:ab2088e0dec6 | 391 | } |
klauss | 19:ab2088e0dec6 | 392 | |
klauss | 56:c64bcbaa621a | 393 | if (type == 'r' ){ |
klauss | 56:c64bcbaa621a | 394 | // Just open for read |
klauss | 19:ab2088e0dec6 | 395 | fip = fopen("/qspi/myip.txt", "r"); |
klauss | 19:ab2088e0dec6 | 396 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 19:ab2088e0dec6 | 397 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 19:ab2088e0dec6 | 398 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 19:ab2088e0dec6 | 399 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 19:ab2088e0dec6 | 400 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 28:94aec56c6329 | 401 | fext = fopen( "/qspi/myext.txt", "r" ); |
klauss | 28:94aec56c6329 | 402 | fserext = fopen( "/qspi/peerext.txt", "r" ); |
klauss | 45:c80574f24dc3 | 403 | fudpport = fopen( "/qspi/udpport.txt", "r" ); |
klauss | 45:c80574f24dc3 | 404 | ftcpport = fopen( "/qspi/tcpport.txt", "r" ); |
klauss | 56:c64bcbaa621a | 405 | ftip = fopen("/qspi/telemetry_ip.txt", "r" ); |
klauss | 56:c64bcbaa621a | 406 | ftport = fopen("/qspi/telemetry_port.txt", "r" ); |
klauss | 19:ab2088e0dec6 | 407 | } |
klauss | 19:ab2088e0dec6 | 408 | |
klauss | 55:2f5e7374af9d | 409 | if( type == 'w'){ |
klauss | 55:2f5e7374af9d | 410 | // Create and write the default configs |
klauss | 56:c64bcbaa621a | 411 | |
klauss | 56:c64bcbaa621a | 412 | set_ip( __MY_IP__ ); |
klauss | 19:ab2088e0dec6 | 413 | |
klauss | 55:2f5e7374af9d | 414 | set_header_sip_port( __MY_PORT__ ); |
klauss | 56:c64bcbaa621a | 415 | |
klauss | 55:2f5e7374af9d | 416 | set_header_ext( __MY_EXT__ ); |
klauss | 28:94aec56c6329 | 417 | |
klauss | 55:2f5e7374af9d | 418 | set_server_ip( __SERVER_IP__ ); |
klauss | 56:c64bcbaa621a | 419 | |
klauss | 55:2f5e7374af9d | 420 | set_server_ext( __PEER_EXT__ ); |
klauss | 56:c64bcbaa621a | 421 | |
klauss | 55:2f5e7374af9d | 422 | set_server_port( __SERVER_PORT__ ); |
klauss | 56:c64bcbaa621a | 423 | |
klauss | 56:c64bcbaa621a | 424 | set_mask( __MY_MSK__ ); |
klauss | 28:94aec56c6329 | 425 | |
klauss | 55:2f5e7374af9d | 426 | set_gateway( __MY_GTW__ ); |
klauss | 56:c64bcbaa621a | 427 | |
klauss | 56:c64bcbaa621a | 428 | set_udp_port_listener( UDP_PORT_LISTENER ); |
klauss | 45:c80574f24dc3 | 429 | |
klauss | 56:c64bcbaa621a | 430 | set_tcp_port_listener( TCP_PORT_LISTENER ); |
klauss | 56:c64bcbaa621a | 431 | |
klauss | 56:c64bcbaa621a | 432 | set_telemetry_ip( __TELEMETRY_SERVER_IP__ ); |
klauss | 56:c64bcbaa621a | 433 | |
klauss | 56:c64bcbaa621a | 434 | set_telemetry_port( __TELEMETRY_SERVER_PORT__ ); |
klauss | 19:ab2088e0dec6 | 435 | |
klauss | 58:af7e8788f106 | 436 | strcpy( last_cmd, tmp_cmd ); |
klauss | 58:af7e8788f106 | 437 | |
klauss | 44:cc4996469404 | 438 | pc.printf("\n\rDefault configurations set!\n\r"); |
klauss | 44:cc4996469404 | 439 | if( from_eth ){ |
klauss | 44:cc4996469404 | 440 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rDefault configurations set!\n\r"); |
klauss | 44:cc4996469404 | 441 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 44:cc4996469404 | 442 | if( tcp_session ){ |
klauss | 45:c80574f24dc3 | 443 | tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 444 | }else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 445 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 44:cc4996469404 | 446 | } |
klauss | 45:c80574f24dc3 | 447 | debug_buf[ 0 ] = 0; |
klauss | 45:c80574f24dc3 | 448 | bufptr = 0; |
klauss | 44:cc4996469404 | 449 | } |
klauss | 19:ab2088e0dec6 | 450 | } |
klauss | 50:d9b6577a70f5 | 451 | |
klauss | 56:c64bcbaa621a | 452 | if (type == 'e'){ |
klauss | 56:c64bcbaa621a | 453 | //Erase configs |
klauss | 50:d9b6577a70f5 | 454 | fip = fopen("/qspi/myip.txt", "w"); |
klauss | 50:d9b6577a70f5 | 455 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 50:d9b6577a70f5 | 456 | fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 50:d9b6577a70f5 | 457 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 50:d9b6577a70f5 | 458 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 50:d9b6577a70f5 | 459 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 50:d9b6577a70f5 | 460 | fext = fopen( "/qspi/myext.txt", "w" ); |
klauss | 50:d9b6577a70f5 | 461 | fserext = fopen( "/qspi/peerext.txt", "w" ); |
klauss | 50:d9b6577a70f5 | 462 | fudpport = fopen( "/qspi/udpport.txt", "w" ); |
klauss | 50:d9b6577a70f5 | 463 | ftcpport = fopen( "/qspi/tcpport.txt", "w" ); |
klauss | 56:c64bcbaa621a | 464 | ftip = fopen("/qspi/telemetry_ip.txt", "w" ); |
klauss | 56:c64bcbaa621a | 465 | ftport = fopen("/qspi/telemetry_port.txt", "w" ); |
klauss | 50:d9b6577a70f5 | 466 | |
klauss | 56:c64bcbaa621a | 467 | //FIXME verificar se deveria colocar tudo para %s |
klauss | 56:c64bcbaa621a | 468 | fprintf( fip, "%s\n\r", "" ); |
klauss | 60:b4ec6beb3be3 | 469 | fprintf( fport, "%i\n\r", 0 ); |
klauss | 60:b4ec6beb3be3 | 470 | fprintf( fext, "%i\n\r", 0 ); |
klauss | 50:d9b6577a70f5 | 471 | |
klauss | 56:c64bcbaa621a | 472 | fprintf( fsip, "%s\n\r", "" ); |
klauss | 60:b4ec6beb3be3 | 473 | fprintf( fserext, "%i\n\r", 0 ); |
klauss | 60:b4ec6beb3be3 | 474 | fprintf( fsport, "%i\n\r", 0 ); |
klauss | 56:c64bcbaa621a | 475 | |
klauss | 56:c64bcbaa621a | 476 | fprintf( fmask, "%s\n\r","" ); |
klauss | 56:c64bcbaa621a | 477 | fprintf( fgate, "%s\n\r", "" ); |
klauss | 50:d9b6577a70f5 | 478 | |
klauss | 60:b4ec6beb3be3 | 479 | fprintf( fudpport, "%i\n\r", 0 ); |
klauss | 60:b4ec6beb3be3 | 480 | fprintf( ftcpport, "%i\n\r", 0 ); |
klauss | 50:d9b6577a70f5 | 481 | |
klauss | 56:c64bcbaa621a | 482 | fprintf( ftip, "%s\n\r","" ); |
klauss | 60:b4ec6beb3be3 | 483 | fprintf( ftport, "%i\n\r",0 ); |
klauss | 56:c64bcbaa621a | 484 | |
klauss | 50:d9b6577a70f5 | 485 | files('c'); |
klauss | 50:d9b6577a70f5 | 486 | |
klauss | 50:d9b6577a70f5 | 487 | pc.printf("\n\rErased configurations set!\n\r"); |
klauss | 50:d9b6577a70f5 | 488 | if( from_eth ){ |
klauss | 50:d9b6577a70f5 | 489 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rErased configurations set!\n\r"); |
klauss | 50:d9b6577a70f5 | 490 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 50:d9b6577a70f5 | 491 | if( tcp_session ){ |
klauss | 50:d9b6577a70f5 | 492 | tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 50:d9b6577a70f5 | 493 | }else if( udp_request ){ |
klauss | 50:d9b6577a70f5 | 494 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 50:d9b6577a70f5 | 495 | } |
klauss | 50:d9b6577a70f5 | 496 | debug_buf[ 0 ] = 0; |
klauss | 50:d9b6577a70f5 | 497 | bufptr = 0; |
klauss | 50:d9b6577a70f5 | 498 | } |
klauss | 50:d9b6577a70f5 | 499 | } |
klauss | 19:ab2088e0dec6 | 500 | } |
klauss | 26:725cbbedadd5 | 501 | void init_fsystem(){ |
klauss | 26:725cbbedadd5 | 502 | // init file system and check if files exist |
klauss | 26:725cbbedadd5 | 503 | if (!qspifs.isformatted()) { |
klauss | 26:725cbbedadd5 | 504 | qspifs.format(); |
klauss | 44:cc4996469404 | 505 | pc.printf("\n\rFile system configured!!\n\r"); |
klauss | 26:725cbbedadd5 | 506 | } |
klauss | 26:725cbbedadd5 | 507 | files('i'); // check if the files are created |
klauss | 26:725cbbedadd5 | 508 | files('c'); |
klauss | 44:cc4996469404 | 509 | pc.printf("\n\r*******File System Ready*******\n\r"); |
klauss | 43:455522f98de5 | 510 | } |
klauss | 43:455522f98de5 | 511 | |
klauss | 43:455522f98de5 | 512 | void init_prompt(){ |
klauss | 45:c80574f24dc3 | 513 | tcp_server.bind( TCP_PORT_LISTENER ); |
klauss | 45:c80574f24dc3 | 514 | tcp_server.listen(); |
klauss | 53:bb492a8f115a | 515 | //tcp_timer.start(); |
klauss | 45:c80574f24dc3 | 516 | tcp_server.set_blocking( false, 1 ); |
klauss | 45:c80574f24dc3 | 517 | |
klauss | 45:c80574f24dc3 | 518 | udp_server.set_blocking( false, 2 ); |
klauss | 45:c80574f24dc3 | 519 | udp_server.bind( UDP_PORT_LISTENER ); |
klauss | 45:c80574f24dc3 | 520 | |
klauss | 43:455522f98de5 | 521 | pc.printf("*******Prompt eth Ready*******\n\r"); |
klauss | 19:ab2088e0dec6 | 522 | } |
klauss | 19:ab2088e0dec6 | 523 | |
klauss | 28:94aec56c6329 | 524 | // main prompt process |
klauss | 48:195c97f12e8e | 525 | char * prompt_process( char * msg_from_cb ){ |
klauss | 28:94aec56c6329 | 526 | //FIXME dar flush na serial |
klauss | 19:ab2088e0dec6 | 527 | volatile char b = 0; |
klauss | 19:ab2088e0dec6 | 528 | static uint8_t bufret = 0; |
klauss | 30:8dfb6d8de53d | 529 | static Timer flood_timeout; |
klauss | 60:b4ec6beb3be3 | 530 | static Timer flood_silence_timer; |
klauss | 60:b4ec6beb3be3 | 531 | static uint8_t id_msg = 0x10; |
klauss | 60:b4ec6beb3be3 | 532 | static int start_ext, end_ext, ext_count; |
klauss | 36:728498a78e1e | 533 | bool miss_match = true; |
klauss | 57:78f7191a8b69 | 534 | char eth_buffer[ __PROMPT_ETH_BUFFER_SIZE__ ]; |
klauss | 60:b4ec6beb3be3 | 535 | uint8_t write_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 57:78f7191a8b69 | 536 | |
klauss | 45:c80574f24dc3 | 537 | if( flood_timeout.read() > 60 ){ |
klauss | 45:c80574f24dc3 | 538 | pflood = 0; |
klauss | 45:c80574f24dc3 | 539 | flood_timeout.stop(); |
klauss | 45:c80574f24dc3 | 540 | flood_timeout.reset(); |
klauss | 45:c80574f24dc3 | 541 | } |
klauss | 53:bb492a8f115a | 542 | if( tcp_timer.read() >= TCP_IDLE_MAX_TIME ){ |
klauss | 53:bb492a8f115a | 543 | tcp_timer.stop(); |
klauss | 53:bb492a8f115a | 544 | tcp_timer.reset(); |
klauss | 53:bb492a8f115a | 545 | tcp_session = false; |
klauss | 53:bb492a8f115a | 546 | debug_buf = __debug_buf__; |
klauss | 53:bb492a8f115a | 547 | bufptr = last_bufptr; |
klauss | 53:bb492a8f115a | 548 | bufret = 0; |
klauss | 53:bb492a8f115a | 549 | from_eth = false; |
klauss | 53:bb492a8f115a | 550 | tcp_client.close(); |
klauss | 53:bb492a8f115a | 551 | return( NULL ); |
klauss | 53:bb492a8f115a | 552 | } |
klauss | 48:195c97f12e8e | 553 | if( !tcp_server.accept( tcp_client ) ){ |
klauss | 48:195c97f12e8e | 554 | tcp_session = true; |
klauss | 53:bb492a8f115a | 555 | tcp_timer.start(); |
klauss | 48:195c97f12e8e | 556 | last_bufptr = bufptr; |
klauss | 53:bb492a8f115a | 557 | eth_buffer[ 0 ] = 0; |
klauss | 48:195c97f12e8e | 558 | bufret = 0; |
klauss | 48:195c97f12e8e | 559 | } |
klauss | 48:195c97f12e8e | 560 | wdt.kick(); |
klauss | 53:bb492a8f115a | 561 | if( tcp_session ){ |
klauss | 57:78f7191a8b69 | 562 | //if( !( (int)tcp_timer.read_ms() % 100 ) ){ |
klauss | 53:bb492a8f115a | 563 | tcp_client.set_blocking( false, 1 ); |
klauss | 53:bb492a8f115a | 564 | int n = tcp_client.receive( eth_buffer, sizeof( eth_buffer ) - 1 ); |
klauss | 53:bb492a8f115a | 565 | if( n > 0 ){ |
klauss | 48:195c97f12e8e | 566 | tcp_timer.reset(); |
klauss | 53:bb492a8f115a | 567 | |
klauss | 53:bb492a8f115a | 568 | if( ( n > 2 ) && ( eth_buffer[ n - 2 ] == '\r' ) ) eth_buffer[ n - 2 ] = 0; |
klauss | 53:bb492a8f115a | 569 | |
klauss | 53:bb492a8f115a | 570 | if( ( n > 1 ) && ( eth_buffer[ n - 1 ] == '\n' ) ) eth_buffer[ n - 1 ] = 0; |
klauss | 53:bb492a8f115a | 571 | |
klauss | 53:bb492a8f115a | 572 | if( ( n == 1 ) && eth_buffer[ 0 ] == 0x0A ) strcpy( eth_buffer, "\r" ); |
klauss | 53:bb492a8f115a | 573 | |
klauss | 53:bb492a8f115a | 574 | //if( eth_buffer[ 0 ] == '\r' || eth_buffer[ 1 ] == '\n' || eth_buffer[ 2 ] == 'r' || eth_buffer[ 2 ] == '\n' ) strcpy( eth_buffer, "\r" ); |
klauss | 62:07e5bdc9f8f7 | 575 | |
klauss | 53:bb492a8f115a | 576 | bufptr = strlen( eth_buffer ); |
klauss | 53:bb492a8f115a | 577 | debug_buf = eth_buffer; |
klauss | 53:bb492a8f115a | 578 | from_eth = true; |
klauss | 53:bb492a8f115a | 579 | bufret = 1; |
klauss | 53:bb492a8f115a | 580 | |
klauss | 53:bb492a8f115a | 581 | if( !( strcmp( eth_buffer, "quit" ) ) ){ |
klauss | 53:bb492a8f115a | 582 | tcp_timer.reset(); |
klauss | 53:bb492a8f115a | 583 | debug_buf = __debug_buf__; |
klauss | 53:bb492a8f115a | 584 | bufptr = last_bufptr; |
klauss | 53:bb492a8f115a | 585 | from_eth = false; |
klauss | 53:bb492a8f115a | 586 | tcp_session = false; |
klauss | 53:bb492a8f115a | 587 | tcp_client.close(); |
klauss | 53:bb492a8f115a | 588 | bufret = 0; |
klauss | 53:bb492a8f115a | 589 | return( NULL ); |
klauss | 53:bb492a8f115a | 590 | } |
klauss | 53:bb492a8f115a | 591 | }else{ |
klauss | 48:195c97f12e8e | 592 | debug_buf = __debug_buf__; |
klauss | 48:195c97f12e8e | 593 | bufptr = last_bufptr; |
klauss | 57:78f7191a8b69 | 594 | from_eth = false; |
klauss | 45:c80574f24dc3 | 595 | } |
klauss | 57:78f7191a8b69 | 596 | //} |
klauss | 53:bb492a8f115a | 597 | } |
klauss | 57:78f7191a8b69 | 598 | |
klauss | 53:bb492a8f115a | 599 | if( !from_eth ){ |
klauss | 57:78f7191a8b69 | 600 | if( pc.readable() ){ |
klauss | 53:bb492a8f115a | 601 | // imput do teclado |
klauss | 53:bb492a8f115a | 602 | b = pc.getc(); |
klauss | 53:bb492a8f115a | 603 | if( b == 0x0D ){ // enter |
klauss | 53:bb492a8f115a | 604 | bufret = 1; |
klauss | 53:bb492a8f115a | 605 | }else{ |
klauss | 53:bb492a8f115a | 606 | pc.putc( b ); |
klauss | 53:bb492a8f115a | 607 | if( b == 0x08 || b == 0x7F ){ // BS | DEL |
klauss | 53:bb492a8f115a | 608 | if( bufptr > 0 ) debug_buf[ --bufptr ] = 0; |
klauss | 53:bb492a8f115a | 609 | }else if( b == 0x09 ){ |
klauss | 53:bb492a8f115a | 610 | // ignore tab |
klauss | 53:bb492a8f115a | 611 | }else{ |
klauss | 53:bb492a8f115a | 612 | debug_buf[bufptr] = b; |
klauss | 53:bb492a8f115a | 613 | bufptr++; |
klauss | 42:480335bdde12 | 614 | } |
klauss | 31:bb5fb28a77df | 615 | } |
klauss | 53:bb492a8f115a | 616 | } |
klauss | 48:195c97f12e8e | 617 | } |
klauss | 53:bb492a8f115a | 618 | |
klauss | 48:195c97f12e8e | 619 | if( msg_from_cb ){ |
klauss | 48:195c97f12e8e | 620 | if( tcp_session ){ |
klauss | 48:195c97f12e8e | 621 | tcp_client.send_all( msg_from_cb, strlen( msg_from_cb ) ); |
klauss | 48:195c97f12e8e | 622 | }else if( udp_request ){ |
klauss | 48:195c97f12e8e | 623 | udp_server.sendTo( udp_client, msg_from_cb, strlen( msg_from_cb ) ); |
klauss | 48:195c97f12e8e | 624 | } |
klauss | 48:195c97f12e8e | 625 | pc.printf( "\n\r%s\n\r", msg_from_cb ); |
klauss | 45:c80574f24dc3 | 626 | } |
klauss | 60:b4ec6beb3be3 | 627 | |
klauss | 60:b4ec6beb3be3 | 628 | if( flood_silence ){ |
klauss | 60:b4ec6beb3be3 | 629 | if( flood_silence_timer.read_ms() > 250 ){ |
klauss | 60:b4ec6beb3be3 | 630 | char cmd[ 16 ] = "flood off"; |
klauss | 60:b4ec6beb3be3 | 631 | int str_end = strlen( cmd ); |
klauss | 60:b4ec6beb3be3 | 632 | cmd[ str_end ] = 0x0D; |
klauss | 60:b4ec6beb3be3 | 633 | cmd[ str_end + 1 ] = 0x00; |
klauss | 60:b4ec6beb3be3 | 634 | |
klauss | 60:b4ec6beb3be3 | 635 | int port = convert_ext_to_port( ext_count ); |
klauss | 60:b4ec6beb3be3 | 636 | __send_to_cb__( __build_cb_package__( ext_count, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 60:b4ec6beb3be3 | 637 | pc.printf("\r\nSilence sent to ext=%d port=%d", ext_count, port ); |
klauss | 60:b4ec6beb3be3 | 638 | |
klauss | 60:b4ec6beb3be3 | 639 | if( tcp_session ){ |
klauss | 60:b4ec6beb3be3 | 640 | snprintf( eth_buffer, __PROMPT_ETH_BUFFER_SIZE__, "\r\nSilence sent to ext=%d port=%d", ext_count, port ); |
klauss | 60:b4ec6beb3be3 | 641 | //eth_buffer[ strlen( eth_buffer ) - 1 ] = '\0'; |
klauss | 60:b4ec6beb3be3 | 642 | |
klauss | 60:b4ec6beb3be3 | 643 | tcp_client.send_all( eth_buffer, strlen( eth_buffer ) ); |
klauss | 60:b4ec6beb3be3 | 644 | }else if( udp_request ){ |
klauss | 60:b4ec6beb3be3 | 645 | snprintf( eth_buffer, __PROMPT_ETH_BUFFER_SIZE__, "\r\nSilence sent to ext=%d port=%d", ext_count, port ); |
klauss | 60:b4ec6beb3be3 | 646 | //eth_buffer[ strlen( eth_buffer ) - 1 ] = '\0'; |
klauss | 60:b4ec6beb3be3 | 647 | |
klauss | 60:b4ec6beb3be3 | 648 | udp_server.sendTo( udp_client, eth_buffer, strlen( eth_buffer ) ); |
klauss | 60:b4ec6beb3be3 | 649 | } |
klauss | 60:b4ec6beb3be3 | 650 | flood_silence_timer.reset(); |
klauss | 60:b4ec6beb3be3 | 651 | |
klauss | 60:b4ec6beb3be3 | 652 | if( ++ext_count > end_ext ){ |
klauss | 60:b4ec6beb3be3 | 653 | flood_silence = false; |
klauss | 60:b4ec6beb3be3 | 654 | flood_silence_timer.stop(); |
klauss | 60:b4ec6beb3be3 | 655 | flood_silence_timer.reset(); |
klauss | 60:b4ec6beb3be3 | 656 | |
klauss | 60:b4ec6beb3be3 | 657 | pc.printf("\r\n> " ); |
klauss | 60:b4ec6beb3be3 | 658 | if( tcp_session ){ |
klauss | 60:b4ec6beb3be3 | 659 | snprintf( eth_buffer, __PROMPT_ETH_BUFFER_SIZE__, "\r\n> " ); |
klauss | 60:b4ec6beb3be3 | 660 | tcp_client.send_all( eth_buffer, strlen( eth_buffer ) ); |
klauss | 60:b4ec6beb3be3 | 661 | }else if( udp_request ){ |
klauss | 60:b4ec6beb3be3 | 662 | snprintf( eth_buffer, __PROMPT_ETH_BUFFER_SIZE__, "\r\n> " ); |
klauss | 60:b4ec6beb3be3 | 663 | udp_server.sendTo( udp_client, eth_buffer, strlen( eth_buffer ) ); |
klauss | 60:b4ec6beb3be3 | 664 | } |
klauss | 60:b4ec6beb3be3 | 665 | } |
klauss | 60:b4ec6beb3be3 | 666 | } |
klauss | 60:b4ec6beb3be3 | 667 | } |
klauss | 65:0b653cfe95db | 668 | |
klauss | 65:0b653cfe95db | 669 | if( delayed_flood ){ |
klauss | 65:0b653cfe95db | 670 | tflood.start(); |
klauss | 65:0b653cfe95db | 671 | tflood.reset(); |
klauss | 65:0b653cfe95db | 672 | floodcount =0; |
klauss | 65:0b653cfe95db | 673 | pflood = 1; |
klauss | 65:0b653cfe95db | 674 | flood_timeout.start(); |
klauss | 65:0b653cfe95db | 675 | delayed_flood = false; |
klauss | 65:0b653cfe95db | 676 | pc.printf("\n\rFlood ON\n\r"); |
klauss | 65:0b653cfe95db | 677 | if( from_eth ){ |
klauss | 65:0b653cfe95db | 678 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood On\n\r" ); |
klauss | 65:0b653cfe95db | 679 | //debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 65:0b653cfe95db | 680 | } |
klauss | 65:0b653cfe95db | 681 | } |
klauss | 45:c80574f24dc3 | 682 | |
klauss | 45:c80574f24dc3 | 683 | // Prompt commands here |
klauss | 58:af7e8788f106 | 684 | if ( bufret == 1 ) { |
klauss | 45:c80574f24dc3 | 685 | static unsigned int promptcb_last_ext = 0; |
klauss | 45:c80574f24dc3 | 686 | static unsigned int promptcb_last_port = 0; |
klauss | 55:2f5e7374af9d | 687 | static char promptcb_last_cmd[ 300 ]; |
klauss | 60:b4ec6beb3be3 | 688 | |
klauss | 58:af7e8788f106 | 689 | strcpy( tmp_cmd, debug_buf ); |
klauss | 59:e1e300880d2d | 690 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "." ) ){ |
klauss | 45:c80574f24dc3 | 691 | miss_match = false; |
klauss | 58:af7e8788f106 | 692 | strcpy( debug_buf, last_cmd ); |
klauss | 58:af7e8788f106 | 693 | strcpy( tmp_cmd, debug_buf ); |
klauss | 59:e1e300880d2d | 694 | }else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "+" ) ){ |
klauss | 59:e1e300880d2d | 695 | miss_match = false; |
klauss | 59:e1e300880d2d | 696 | strcpy( debug_buf, "flood on" ); |
klauss | 59:e1e300880d2d | 697 | strcpy( tmp_cmd, debug_buf ); |
klauss | 59:e1e300880d2d | 698 | }else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "-" ) ){ |
klauss | 59:e1e300880d2d | 699 | miss_match = false; |
klauss | 59:e1e300880d2d | 700 | strcpy( debug_buf, "flood off" ); |
klauss | 59:e1e300880d2d | 701 | strcpy( tmp_cmd, debug_buf ); |
klauss | 59:e1e300880d2d | 702 | }else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "++ ", 3 ) ){ |
klauss | 59:e1e300880d2d | 703 | miss_match = false; |
klauss | 65:0b653cfe95db | 704 | delayed_flood = true; |
klauss | 59:e1e300880d2d | 705 | int ext = atoi( debug_buf + 3 ); |
klauss | 59:e1e300880d2d | 706 | sprintf( debug_buf, "pcb %i flood on", ext ); |
klauss | 59:e1e300880d2d | 707 | }else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "-- ", 3 ) ){ |
klauss | 59:e1e300880d2d | 708 | miss_match = false; |
klauss | 59:e1e300880d2d | 709 | int ext = atoi( debug_buf + 3 ); |
klauss | 59:e1e300880d2d | 710 | pc.printf("\n\rFlood OFF\n\r"); |
klauss | 59:e1e300880d2d | 711 | if( from_eth ){ |
klauss | 59:e1e300880d2d | 712 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood OFF\n\r" ); |
klauss | 59:e1e300880d2d | 713 | //debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 59:e1e300880d2d | 714 | } |
klauss | 59:e1e300880d2d | 715 | pflood = 0; |
klauss | 59:e1e300880d2d | 716 | tflood.stop(); |
klauss | 59:e1e300880d2d | 717 | flood_timeout.reset(); |
klauss | 60:b4ec6beb3be3 | 718 | sprintf( debug_buf, "pcb %i flood off", ext ); |
klauss | 45:c80574f24dc3 | 719 | } |
klauss | 45:c80574f24dc3 | 720 | |
klauss | 48:195c97f12e8e | 721 | //tratamento dos enters |
klauss | 45:c80574f24dc3 | 722 | if( !bufptr ){ |
klauss | 45:c80574f24dc3 | 723 | miss_match = false; |
klauss | 48:195c97f12e8e | 724 | }else if( bufptr == 1 ) { |
klauss | 48:195c97f12e8e | 725 | if( debug_buf[ 0 ] == 0x0D || debug_buf[ 0 ] == 0x0D ) miss_match = false; |
klauss | 48:195c97f12e8e | 726 | } |
klauss | 48:195c97f12e8e | 727 | |
klauss | 45:c80574f24dc3 | 728 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ifconfig" ) ){ |
klauss | 45:c80574f24dc3 | 729 | miss_match = false; |
klauss | 45:c80574f24dc3 | 730 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 731 | files('s'); |
klauss | 45:c80574f24dc3 | 732 | } |
klauss | 62:07e5bdc9f8f7 | 733 | |
klauss | 63:0d95da692bb4 | 734 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "rx" ) ){ |
klauss | 62:07e5bdc9f8f7 | 735 | miss_match = false; |
klauss | 62:07e5bdc9f8f7 | 736 | rx = true; |
klauss | 62:07e5bdc9f8f7 | 737 | } |
klauss | 62:07e5bdc9f8f7 | 738 | |
klauss | 63:0d95da692bb4 | 739 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "tx" ) ){ |
klauss | 63:0d95da692bb4 | 740 | miss_match = false; |
klauss | 63:0d95da692bb4 | 741 | tx = true; |
klauss | 63:0d95da692bb4 | 742 | } |
klauss | 63:0d95da692bb4 | 743 | |
klauss | 63:0d95da692bb4 | 744 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "stats" ) ){ |
klauss | 63:0d95da692bb4 | 745 | miss_match = false; |
klauss | 63:0d95da692bb4 | 746 | stats = true; |
klauss | 63:0d95da692bb4 | 747 | } |
klauss | 63:0d95da692bb4 | 748 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset_stats" ) ){ |
klauss | 63:0d95da692bb4 | 749 | miss_match = false; |
klauss | 63:0d95da692bb4 | 750 | r_stats = true; |
klauss | 63:0d95da692bb4 | 751 | } |
klauss | 63:0d95da692bb4 | 752 | |
klauss | 59:e1e300880d2d | 753 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "format" ) ){ |
klauss | 45:c80574f24dc3 | 754 | miss_match = false; |
klauss | 50:d9b6577a70f5 | 755 | pc.printf("\n\rFormatando o sistema de arquivos... espere o sistema reiniciar\n\r"); |
klauss | 62:07e5bdc9f8f7 | 756 | |
klauss | 45:c80574f24dc3 | 757 | if( from_eth ){ |
klauss | 62:07e5bdc9f8f7 | 758 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Not Allowed\n\r"); |
klauss | 62:07e5bdc9f8f7 | 759 | }else{ |
klauss | 62:07e5bdc9f8f7 | 760 | files('e'); |
klauss | 62:07e5bdc9f8f7 | 761 | files('w'); |
klauss | 62:07e5bdc9f8f7 | 762 | __disable_irq(); |
klauss | 62:07e5bdc9f8f7 | 763 | NVIC_SystemReset(); |
klauss | 42:480335bdde12 | 764 | } |
klauss | 45:c80574f24dc3 | 765 | } |
klauss | 45:c80574f24dc3 | 766 | |
klauss | 59:e1e300880d2d | 767 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ipset ", 6 )) { |
klauss | 45:c80574f24dc3 | 768 | miss_match = false; |
klauss | 54:448d57291be6 | 769 | set_ip( debug_buf + 6 ); |
klauss | 45:c80574f24dc3 | 770 | files('s'); |
klauss | 45:c80574f24dc3 | 771 | } |
klauss | 45:c80574f24dc3 | 772 | |
klauss | 59:e1e300880d2d | 773 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "extset ", 7 ) ){ |
klauss | 45:c80574f24dc3 | 774 | miss_match = false; |
klauss | 55:2f5e7374af9d | 775 | set_header_ext( atoi( debug_buf + 7 ) ); |
klauss | 45:c80574f24dc3 | 776 | files('s'); |
klauss | 45:c80574f24dc3 | 777 | } |
klauss | 45:c80574f24dc3 | 778 | |
klauss | 59:e1e300880d2d | 779 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serextset ", 10 ) ){ |
klauss | 45:c80574f24dc3 | 780 | miss_match = false; |
klauss | 55:2f5e7374af9d | 781 | set_server_ext( atoi( debug_buf + 10 ) ); |
klauss | 45:c80574f24dc3 | 782 | files('s'); |
klauss | 45:c80574f24dc3 | 783 | } |
klauss | 45:c80574f24dc3 | 784 | |
klauss | 59:e1e300880d2d | 785 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "maskset ",8 ) ){ |
klauss | 45:c80574f24dc3 | 786 | miss_match = false; |
klauss | 55:2f5e7374af9d | 787 | set_mask( debug_buf + 8 ); |
klauss | 45:c80574f24dc3 | 788 | files('s'); |
klauss | 45:c80574f24dc3 | 789 | } |
klauss | 45:c80574f24dc3 | 790 | |
klauss | 59:e1e300880d2d | 791 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "gatewayset ",11 ) ){ |
klauss | 45:c80574f24dc3 | 792 | miss_match = false; |
klauss | 55:2f5e7374af9d | 793 | set_gateway( debug_buf + 11 ); |
klauss | 45:c80574f24dc3 | 794 | files('s'); |
klauss | 45:c80574f24dc3 | 795 | } |
klauss | 45:c80574f24dc3 | 796 | |
klauss | 59:e1e300880d2d | 797 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "msipport ",9 ) ){ |
klauss | 45:c80574f24dc3 | 798 | miss_match = false; |
klauss | 55:2f5e7374af9d | 799 | set_header_sip_port( atoi( debug_buf + 9 ) ); |
klauss | 45:c80574f24dc3 | 800 | files('s'); |
klauss | 45:c80574f24dc3 | 801 | } |
klauss | 45:c80574f24dc3 | 802 | |
klauss | 59:e1e300880d2d | 803 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serverip ",9 ) ){ |
klauss | 45:c80574f24dc3 | 804 | miss_match = false; |
klauss | 55:2f5e7374af9d | 805 | set_server_ip( debug_buf + 9 ); |
klauss | 45:c80574f24dc3 | 806 | files('s'); |
klauss | 45:c80574f24dc3 | 807 | } |
klauss | 45:c80574f24dc3 | 808 | |
klauss | 59:e1e300880d2d | 809 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ssport ",7 ) ){ |
klauss | 45:c80574f24dc3 | 810 | miss_match = false; |
klauss | 55:2f5e7374af9d | 811 | set_server_port( atoi( debug_buf + 7 ) ); |
klauss | 45:c80574f24dc3 | 812 | files('s'); |
klauss | 45:c80574f24dc3 | 813 | } |
klauss | 45:c80574f24dc3 | 814 | |
klauss | 59:e1e300880d2d | 815 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "telemetry_ip ", 13 ) ){ |
klauss | 56:c64bcbaa621a | 816 | miss_match = false; |
klauss | 56:c64bcbaa621a | 817 | set_telemetry_ip( debug_buf + 13 ); |
klauss | 56:c64bcbaa621a | 818 | files('s'); |
klauss | 56:c64bcbaa621a | 819 | } |
klauss | 56:c64bcbaa621a | 820 | |
klauss | 59:e1e300880d2d | 821 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "telemetry_port ", 15 ) ){ |
klauss | 56:c64bcbaa621a | 822 | miss_match = false; |
klauss | 56:c64bcbaa621a | 823 | set_telemetry_port( atoi( debug_buf + 15 ) ); |
klauss | 56:c64bcbaa621a | 824 | files('s'); |
klauss | 56:c64bcbaa621a | 825 | } |
klauss | 45:c80574f24dc3 | 826 | |
klauss | 59:e1e300880d2d | 827 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dconfig" ) ){ |
klauss | 45:c80574f24dc3 | 828 | miss_match = false; |
klauss | 50:d9b6577a70f5 | 829 | files('e'); |
klauss | 45:c80574f24dc3 | 830 | files('w'); |
klauss | 45:c80574f24dc3 | 831 | files('s'); |
klauss | 45:c80574f24dc3 | 832 | } |
klauss | 45:c80574f24dc3 | 833 | |
klauss | 59:e1e300880d2d | 834 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset" ) ){ |
klauss | 45:c80574f24dc3 | 835 | miss_match = false; |
klauss | 45:c80574f24dc3 | 836 | pc.printf("\n\rJob is done\n\r"); |
klauss | 45:c80574f24dc3 | 837 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 838 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Job is done\n\r"); |
klauss | 45:c80574f24dc3 | 839 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 840 | if( tcp_session ){ |
klauss | 45:c80574f24dc3 | 841 | tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 842 | tcp_client.close(); |
klauss | 45:c80574f24dc3 | 843 | }else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 844 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 42:480335bdde12 | 845 | } |
klauss | 45:c80574f24dc3 | 846 | } |
klauss | 48:195c97f12e8e | 847 | __disable_irq(); |
klauss | 45:c80574f24dc3 | 848 | NVIC_SystemReset(); |
klauss | 45:c80574f24dc3 | 849 | } |
klauss | 45:c80574f24dc3 | 850 | |
klauss | 59:e1e300880d2d | 851 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dog" ) ){ |
klauss | 45:c80574f24dc3 | 852 | miss_match = false; |
klauss | 45:c80574f24dc3 | 853 | pc.printf("\n\r MUUUUUUUuuuuUUUUUU - I'm not a dog!!!! \n\r"); |
klauss | 45:c80574f24dc3 | 854 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 855 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "MUUUUUUUuuuuUUUUUU - I'm not a dog!!!!\n\r"); |
klauss | 45:c80574f24dc3 | 856 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 857 | } |
klauss | 45:c80574f24dc3 | 858 | } |
klauss | 48:195c97f12e8e | 859 | |
klauss | 62:07e5bdc9f8f7 | 860 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ls" ) ){ |
klauss | 62:07e5bdc9f8f7 | 861 | miss_match = false; |
klauss | 62:07e5bdc9f8f7 | 862 | list = true; |
klauss | 62:07e5bdc9f8f7 | 863 | } |
klauss | 62:07e5bdc9f8f7 | 864 | |
klauss | 59:e1e300880d2d | 865 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "tt" ) ){ |
klauss | 53:bb492a8f115a | 866 | miss_match = false; |
klauss | 62:07e5bdc9f8f7 | 867 | main_test = !main_test; |
klauss | 53:bb492a8f115a | 868 | } |
klauss | 53:bb492a8f115a | 869 | |
klauss | 59:e1e300880d2d | 870 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset_cks" ) ){ |
klauss | 52:12930cef17c4 | 871 | miss_match = false; |
klauss | 52:12930cef17c4 | 872 | reset_cks = true; |
klauss | 52:12930cef17c4 | 873 | } |
klauss | 52:12930cef17c4 | 874 | |
klauss | 64:5b011d5707d2 | 875 | //replaced by ls |
klauss | 59:e1e300880d2d | 876 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "status" ) ){ |
klauss | 48:195c97f12e8e | 877 | miss_match = false; |
klauss | 64:5b011d5707d2 | 878 | list = true; |
klauss | 64:5b011d5707d2 | 879 | } |
klauss | 64:5b011d5707d2 | 880 | |
klauss | 64:5b011d5707d2 | 881 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "types" ) ){ |
klauss | 64:5b011d5707d2 | 882 | miss_match = false; |
klauss | 64:5b011d5707d2 | 883 | |
klauss | 64:5b011d5707d2 | 884 | pc.printf( "\n\rhex :: dec :: Type \n\r0x00 :: 0 :: boot \n\r0x02 :: 2 :: registry \n\r0x04 :: 4 :: invite \n\r0x08 :: 8 :: audio \n\r0x10 :: 16 :: telemetry \n\r0x20 :: 32 :: cb_bye \n\r0x01 :: 1 :: prompt \n\r0x40 :: 64 :: flood \n\r" ); |
klauss | 64:5b011d5707d2 | 885 | |
klauss | 64:5b011d5707d2 | 886 | if( from_eth ){ |
klauss | 64:5b011d5707d2 | 887 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rhex :: dec :: Type \n\r0x00 :: 0 :: boot \n\r0x02 :: 2 :: registry \n\r0x04 :: 4 :: invite \n\r0x08 :: 8 :: audio \n\r0x10 :: 16 :: telemetry \n\r0x20 :: 32 :: cb_bye \n\r0x01 :: 1 :: prompt \n\r0x40 :: 64 :: flood \n\r" ); |
klauss | 64:5b011d5707d2 | 888 | //debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 64:5b011d5707d2 | 889 | } |
klauss | 48:195c97f12e8e | 890 | } |
klauss | 64:5b011d5707d2 | 891 | |
klauss | 64:5b011d5707d2 | 892 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "protocol" ) ){ |
klauss | 64:5b011d5707d2 | 893 | miss_match = false; |
klauss | 64:5b011d5707d2 | 894 | |
klauss | 64:5b011d5707d2 | 895 | pc.printf( "\n\r| E | E | P | P | C | C | T | [ Seq_num | Audio ] | 14[ Clock | Audio ] | [ TS | Audio ] | ... |\n\r \n\rE = Ext = Ramal\n\r \n\rP = Port = Porta\n\r \n\rC = Checksum\n\r \n\rT = Type = Tipo\n\r \n\rSeq_num = Sequence Number = Numero de sequencia\n\r \n\rClock = 14 bytes to sync\n\r \n\r... = demais __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__ bytes\n\r" ); |
klauss | 64:5b011d5707d2 | 896 | |
klauss | 64:5b011d5707d2 | 897 | if( from_eth ){ |
klauss | 64:5b011d5707d2 | 898 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\r| E | E | P | P | C | C | T | [ Seq_num | Audio ] | 14[ Clock | Audio ] | [ TS | Audio ] | ... |\n\r \n\rE = Ext = Ramal\n\r \n\rP = Port = Porta\n\r \n\rC = Checksum\n\r \n\rT = Type = Tipo\n\r \n\rSeq_num = Sequence Number = Numero de sequencia\n\r \n\rClock = 14 bytes to sync\n\r \n\r... = demais __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__ bytes\n\r" ); |
klauss | 64:5b011d5707d2 | 899 | //debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 64:5b011d5707d2 | 900 | } |
klauss | 64:5b011d5707d2 | 901 | } |
klauss | 64:5b011d5707d2 | 902 | |
klauss | 60:b4ec6beb3be3 | 903 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "flood ", 6 ) ){ |
klauss | 60:b4ec6beb3be3 | 904 | if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on", 2 ) ){ |
klauss | 45:c80574f24dc3 | 905 | miss_match = false; |
klauss | 46:a670f187a704 | 906 | pc.printf("\n\rFlood ON\n\r"); |
klauss | 42:480335bdde12 | 907 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 908 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood On\n\r" ); |
klauss | 45:c80574f24dc3 | 909 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 42:480335bdde12 | 910 | } |
klauss | 45:c80574f24dc3 | 911 | tflood.start(); |
klauss | 45:c80574f24dc3 | 912 | tflood.reset(); |
klauss | 45:c80574f24dc3 | 913 | floodcount =0; |
klauss | 45:c80574f24dc3 | 914 | pflood = 1; |
klauss | 45:c80574f24dc3 | 915 | flood_timeout.start(); |
klauss | 45:c80574f24dc3 | 916 | } |
klauss | 61:06e77dff6f00 | 917 | |
klauss | 61:06e77dff6f00 | 918 | if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "more", 4 ) ){ |
klauss | 61:06e77dff6f00 | 919 | miss_match = false; |
klauss | 61:06e77dff6f00 | 920 | pc.printf("\n\rFlood ON\n\r"); |
klauss | 61:06e77dff6f00 | 921 | if( from_eth ){ |
klauss | 61:06e77dff6f00 | 922 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood On\n\r" ); |
klauss | 61:06e77dff6f00 | 923 | //debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 61:06e77dff6f00 | 924 | } |
klauss | 61:06e77dff6f00 | 925 | tflood.start(); |
klauss | 61:06e77dff6f00 | 926 | tflood.reset(); |
klauss | 61:06e77dff6f00 | 927 | floodcount = 0; |
klauss | 61:06e77dff6f00 | 928 | pflood = 1; |
klauss | 61:06e77dff6f00 | 929 | } |
klauss | 61:06e77dff6f00 | 930 | |
klauss | 60:b4ec6beb3be3 | 931 | if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off", 3 )) { |
klauss | 45:c80574f24dc3 | 932 | miss_match = false; |
klauss | 46:a670f187a704 | 933 | pc.printf("\n\rFlood OFF\n\r"); |
klauss | 42:480335bdde12 | 934 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 935 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood Off\n\r" ); |
klauss | 45:c80574f24dc3 | 936 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 42:480335bdde12 | 937 | } |
klauss | 45:c80574f24dc3 | 938 | pflood = 0; |
klauss | 45:c80574f24dc3 | 939 | tflood.stop(); |
klauss | 45:c80574f24dc3 | 940 | flood_timeout.reset(); |
klauss | 31:bb5fb28a77df | 941 | } |
klauss | 60:b4ec6beb3be3 | 942 | }else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "silence ", 8 ) ){ |
klauss | 60:b4ec6beb3be3 | 943 | miss_match = false; |
klauss | 60:b4ec6beb3be3 | 944 | char *ref, *split; |
klauss | 60:b4ec6beb3be3 | 945 | |
klauss | 60:b4ec6beb3be3 | 946 | strcpy( promptcb_last_cmd, debug_buf ); |
klauss | 60:b4ec6beb3be3 | 947 | |
klauss | 65:0b653cfe95db | 948 | if( !( strcmp( debug_buf + 8, "-h" ) && strcmp( debug_buf + 8, "--help" ) ) ){ |
klauss | 65:0b653cfe95db | 949 | pc.printf("\n\rUsage :: silence start_ext end_ext | start_ext must be greater than end_ext\n\rObs : ( end_ext - start_ext ) < 50 "); |
klauss | 65:0b653cfe95db | 950 | |
klauss | 65:0b653cfe95db | 951 | if( tcp_session ){ |
klauss | 65:0b653cfe95db | 952 | snprintf( eth_buffer, __PROMPT_ETH_BUFFER_SIZE__, "Usage :: silence start_ext end_ext | start_ext must be greater than end_ext\n\rObs : ( end_ext - start_ext ) < 50 " ); |
klauss | 65:0b653cfe95db | 953 | } |
klauss | 65:0b653cfe95db | 954 | }else{ |
klauss | 65:0b653cfe95db | 955 | ref = debug_buf; |
klauss | 65:0b653cfe95db | 956 | |
klauss | 65:0b653cfe95db | 957 | split = strtok( debug_buf + 8, " " ); |
klauss | 65:0b653cfe95db | 958 | |
klauss | 65:0b653cfe95db | 959 | start_ext = atoi( split ); |
klauss | 65:0b653cfe95db | 960 | |
klauss | 65:0b653cfe95db | 961 | split += strlen( split ) + 1; |
klauss | 65:0b653cfe95db | 962 | |
klauss | 65:0b653cfe95db | 963 | end_ext = atoi( split ); |
klauss | 60:b4ec6beb3be3 | 964 | |
klauss | 65:0b653cfe95db | 965 | debug_buf = ref; |
klauss | 65:0b653cfe95db | 966 | |
klauss | 65:0b653cfe95db | 967 | if( start_ext < end_ext && ( end_ext - start_ext ) < 50 ){ |
klauss | 65:0b653cfe95db | 968 | if( start_ext % 2 ) start_ext--; |
klauss | 65:0b653cfe95db | 969 | if( !( end_ext % 2 ) ) end_ext++; |
klauss | 65:0b653cfe95db | 970 | |
klauss | 65:0b653cfe95db | 971 | ext_count = start_ext; |
klauss | 65:0b653cfe95db | 972 | flood_silence_timer.start(); |
klauss | 65:0b653cfe95db | 973 | }else{ |
klauss | 65:0b653cfe95db | 974 | pc.printf("\n\rUsage Error :: silence start_ext end_ext | start_ext must be greater than end_ext\n\rObs : ( end_ext - start_ext ) < 50 "); |
klauss | 65:0b653cfe95db | 975 | |
klauss | 65:0b653cfe95db | 976 | if( tcp_session ){ |
klauss | 65:0b653cfe95db | 977 | snprintf( eth_buffer, __PROMPT_ETH_BUFFER_SIZE__, "Usage Error :: silence start_ext end_ext | start_ext must be greater than end_ext\n\rObs : ( end_ext - start_ext ) < 50 " ); |
klauss | 65:0b653cfe95db | 978 | } |
klauss | 48:195c97f12e8e | 979 | } |
klauss | 65:0b653cfe95db | 980 | flood_silence = true; |
klauss | 48:195c97f12e8e | 981 | } |
klauss | 45:c80574f24dc3 | 982 | } |
klauss | 45:c80574f24dc3 | 983 | |
klauss | 60:b4ec6beb3be3 | 984 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug ",6 ) ){ |
klauss | 45:c80574f24dc3 | 985 | if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { |
klauss | 45:c80574f24dc3 | 986 | miss_match = false; |
klauss | 46:a670f187a704 | 987 | pc.printf("\n\rDebug ON\n\r"); |
klauss | 45:c80574f24dc3 | 988 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 989 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug On\n\r" ); |
klauss | 45:c80574f24dc3 | 990 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 991 | } |
klauss | 45:c80574f24dc3 | 992 | debug_alive = 1; |
klauss | 45:c80574f24dc3 | 993 | } |
klauss | 45:c80574f24dc3 | 994 | if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { |
klauss | 45:c80574f24dc3 | 995 | miss_match = false; |
klauss | 46:a670f187a704 | 996 | pc.printf("\n\rDebug OFF\n\r"); |
klauss | 45:c80574f24dc3 | 997 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 998 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Off\n\r" ); |
klauss | 45:c80574f24dc3 | 999 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 42:480335bdde12 | 1000 | } |
klauss | 45:c80574f24dc3 | 1001 | debug_alive = 0; |
klauss | 31:bb5fb28a77df | 1002 | } |
klauss | 45:c80574f24dc3 | 1003 | if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "show",4 ) ){ |
klauss | 45:c80574f24dc3 | 1004 | miss_match = false; |
klauss | 50:d9b6577a70f5 | 1005 | pc.printf("\n\rdsip"); |
klauss | 45:c80574f24dc3 | 1006 | pc.printf("\n\rdebug_alive"); |
klauss | 45:c80574f24dc3 | 1007 | pc.printf("\n\rdebug_prompt"); |
klauss | 45:c80574f24dc3 | 1008 | pc.printf("\n\rdebug_vector"); |
klauss | 45:c80574f24dc3 | 1009 | pc.printf("\n\rdebug_cb"); |
klauss | 45:c80574f24dc3 | 1010 | pc.printf("\n\rdebug_main"); |
klauss | 45:c80574f24dc3 | 1011 | pc.printf("\n\rdebug_cks"); |
klauss | 45:c80574f24dc3 | 1012 | pc.printf("\n\rdebug_cb_rx"); |
klauss | 45:c80574f24dc3 | 1013 | pc.printf("\n\rdebug_cb_tx*"); |
klauss | 45:c80574f24dc3 | 1014 | pc.printf("\n\rdebug_eth_rx*"); |
klauss | 45:c80574f24dc3 | 1015 | pc.printf("\n\rdebug_eth_tx*"); |
klauss | 45:c80574f24dc3 | 1016 | pc.printf("\n\rdebug_file"); |
klauss | 45:c80574f24dc3 | 1017 | |
klauss | 42:480335bdde12 | 1018 | if( from_eth ){ |
klauss | 50:d9b6577a70f5 | 1019 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rdsip \n\rdebug_alive \n\rdebug_prompt \n\rdebug_vector \n\rdebug_cb \n\rdebug_main \n\rdebug_cks \n\rdebug_cb_rx \n\rdebug_cb_tx* \n\rdebug_eth_rx* \n\rdebug_eth_tx* \n\rdebug_file\n\r" ); |
klauss | 42:480335bdde12 | 1020 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 42:480335bdde12 | 1021 | } |
klauss | 42:480335bdde12 | 1022 | } |
klauss | 45:c80574f24dc3 | 1023 | } |
klauss | 45:c80574f24dc3 | 1024 | |
klauss | 59:e1e300880d2d | 1025 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dsip ",5 ) ){ |
klauss | 50:d9b6577a70f5 | 1026 | if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on",2 ) ){ |
klauss | 45:c80574f24dc3 | 1027 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1028 | pc.printf( "\n\rSip Debug ON\n\r" ); |
klauss | 45:c80574f24dc3 | 1029 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1030 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Sip Debug On\n\r" ); |
klauss | 45:c80574f24dc3 | 1031 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1032 | } |
klauss | 45:c80574f24dc3 | 1033 | debug_sip = 1; |
klauss | 45:c80574f24dc3 | 1034 | } |
klauss | 50:d9b6577a70f5 | 1035 | if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "off",3 )) { |
klauss | 45:c80574f24dc3 | 1036 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1037 | pc.printf( "\n\rSip Debug OFF\n\r" ); |
klauss | 45:c80574f24dc3 | 1038 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1039 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Sip Debug Off\n\r" ); |
klauss | 45:c80574f24dc3 | 1040 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1041 | } |
klauss | 45:c80574f24dc3 | 1042 | debug_sip = 0; |
klauss | 45:c80574f24dc3 | 1043 | } |
klauss | 45:c80574f24dc3 | 1044 | } |
klauss | 45:c80574f24dc3 | 1045 | |
klauss | 59:e1e300880d2d | 1046 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dtelemetry ", 11 ) ){ |
klauss | 53:bb492a8f115a | 1047 | if (xmemmatch( (uint8_t*)(debug_buf + 11 ), (uint8_t*) "on",2 ) ){ |
klauss | 53:bb492a8f115a | 1048 | miss_match = false; |
klauss | 53:bb492a8f115a | 1049 | pc.printf( "\n\rTelemetry Debug ON\n\r" ); |
klauss | 53:bb492a8f115a | 1050 | if( from_eth ){ |
klauss | 53:bb492a8f115a | 1051 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "rTelemetry Debug On\n\r" ); |
klauss | 53:bb492a8f115a | 1052 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 53:bb492a8f115a | 1053 | } |
klauss | 53:bb492a8f115a | 1054 | debug_telemetry = true; |
klauss | 53:bb492a8f115a | 1055 | } |
klauss | 53:bb492a8f115a | 1056 | if (xmemmatch( (uint8_t*)(debug_buf + 11 ), (uint8_t*) "off",3 )) { |
klauss | 53:bb492a8f115a | 1057 | miss_match = false; |
klauss | 53:bb492a8f115a | 1058 | pc.printf( "\n\rrTelemetry Debug OFF\n\r" ); |
klauss | 53:bb492a8f115a | 1059 | if( from_eth ){ |
klauss | 53:bb492a8f115a | 1060 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "rTelemetry Debug Off\n\r" ); |
klauss | 53:bb492a8f115a | 1061 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 53:bb492a8f115a | 1062 | } |
klauss | 53:bb492a8f115a | 1063 | debug_telemetry = false; |
klauss | 53:bb492a8f115a | 1064 | } |
klauss | 53:bb492a8f115a | 1065 | } |
klauss | 53:bb492a8f115a | 1066 | |
klauss | 59:e1e300880d2d | 1067 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cks ", 10 )) { |
klauss | 50:d9b6577a70f5 | 1068 | if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on",2 )) { |
klauss | 45:c80574f24dc3 | 1069 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1070 | pc.printf( "\n\rCKS Debug ON\n\r" ); |
klauss | 45:c80574f24dc3 | 1071 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1072 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS Debug On\n\r" ); |
klauss | 45:c80574f24dc3 | 1073 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1074 | } |
klauss | 45:c80574f24dc3 | 1075 | debug_cks = 1; |
klauss | 45:c80574f24dc3 | 1076 | } |
klauss | 50:d9b6577a70f5 | 1077 | if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "off",3 )) { |
klauss | 45:c80574f24dc3 | 1078 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1079 | pc.printf( "\n\rCKS Debug OFF\n\r" ); |
klauss | 45:c80574f24dc3 | 1080 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1081 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS Debug Off\n\r" ); |
klauss | 45:c80574f24dc3 | 1082 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1083 | } |
klauss | 45:c80574f24dc3 | 1084 | debug_cks = 0; |
klauss | 45:c80574f24dc3 | 1085 | } |
klauss | 45:c80574f24dc3 | 1086 | } |
klauss | 45:c80574f24dc3 | 1087 | |
klauss | 45:c80574f24dc3 | 1088 | //promptcb ramal porta comando |
klauss | 50:d9b6577a70f5 | 1089 | //FIXME colocar a parte eth de novo |
klauss | 59:e1e300880d2d | 1090 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "pcb ", 4 )) { |
klauss | 45:c80574f24dc3 | 1091 | miss_match = false; |
klauss | 48:195c97f12e8e | 1092 | int ext,port; |
klauss | 54:448d57291be6 | 1093 | char *split, *ref, *cmd; |
klauss | 48:195c97f12e8e | 1094 | |
klauss | 62:07e5bdc9f8f7 | 1095 | ref = debug_buf; |
klauss | 59:e1e300880d2d | 1096 | |
klauss | 59:e1e300880d2d | 1097 | debug_buf[ strlen( debug_buf ) ] = 0x0D; |
klauss | 59:e1e300880d2d | 1098 | debug_buf[ strlen( debug_buf ) + 1 ] = 0x00; |
klauss | 48:195c97f12e8e | 1099 | |
klauss | 48:195c97f12e8e | 1100 | split = strtok( debug_buf + 4, " " ); |
klauss | 48:195c97f12e8e | 1101 | ext = atoi( split ); |
klauss | 50:d9b6577a70f5 | 1102 | |
klauss | 50:d9b6577a70f5 | 1103 | port = convert_ext_to_port( ext ); |
klauss | 48:195c97f12e8e | 1104 | split += strlen( split ) + 1; |
klauss | 54:448d57291be6 | 1105 | cmd = split; |
klauss | 48:195c97f12e8e | 1106 | |
klauss | 48:195c97f12e8e | 1107 | promptcb_last_ext = ext; |
klauss | 48:195c97f12e8e | 1108 | promptcb_last_port = port; |
klauss | 62:07e5bdc9f8f7 | 1109 | |
klauss | 62:07e5bdc9f8f7 | 1110 | int tmp = strlen( cmd ); |
klauss | 62:07e5bdc9f8f7 | 1111 | cmd[ tmp ] = 0x0D; |
klauss | 62:07e5bdc9f8f7 | 1112 | cmd[ tmp + 1 ] = 0x00; |
klauss | 55:2f5e7374af9d | 1113 | strcpy( promptcb_last_cmd, cmd ); |
klauss | 48:195c97f12e8e | 1114 | |
klauss | 54:448d57291be6 | 1115 | pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n", ext, port, cmd ); |
klauss | 54:448d57291be6 | 1116 | __send_to_cb__( __build_cb_package__( ext, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 48:195c97f12e8e | 1117 | pc.printf("\n\rComando enviado\n\r"); |
klauss | 48:195c97f12e8e | 1118 | |
klauss | 54:448d57291be6 | 1119 | if( from_eth ){ |
klauss | 62:07e5bdc9f8f7 | 1120 | char eth_msg[ 512 ]; |
klauss | 62:07e5bdc9f8f7 | 1121 | snprintf( eth_msg, 512 - 1, "\r\next=%d port=%d\r\ncmd=%s\r\n\n\rComando enviado\n\r", ext, port, cmd ); |
klauss | 62:07e5bdc9f8f7 | 1122 | if( tcp_session ){ |
klauss | 62:07e5bdc9f8f7 | 1123 | tcp_client.send_all( eth_msg, strlen( eth_msg ) ); |
klauss | 62:07e5bdc9f8f7 | 1124 | }else if( udp_request ){ |
klauss | 62:07e5bdc9f8f7 | 1125 | udp_server.sendTo( udp_client, eth_msg, strlen( eth_msg ) ); |
klauss | 62:07e5bdc9f8f7 | 1126 | } |
klauss | 54:448d57291be6 | 1127 | } |
klauss | 54:448d57291be6 | 1128 | |
klauss | 48:195c97f12e8e | 1129 | debug_buf = ref; |
klauss | 62:07e5bdc9f8f7 | 1130 | bufptr = 0; |
klauss | 62:07e5bdc9f8f7 | 1131 | debug_buf[ 0 ] = 0; |
klauss | 45:c80574f24dc3 | 1132 | } |
klauss | 48:195c97f12e8e | 1133 | |
klauss | 59:e1e300880d2d | 1134 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "_pcb",4 )) { |
klauss | 45:c80574f24dc3 | 1135 | miss_match = false; |
klauss | 48:195c97f12e8e | 1136 | debug_buf[ bufptr++ ] = 0x0D; |
klauss | 48:195c97f12e8e | 1137 | debug_buf[ bufptr++ ] = 0x00; |
klauss | 45:c80574f24dc3 | 1138 | |
klauss | 48:195c97f12e8e | 1139 | pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",promptcb_last_ext, promptcb_last_port, debug_buf + 4 ); |
klauss | 48:195c97f12e8e | 1140 | __send_to_cb__( __build_cb_package__( promptcb_last_ext, promptcb_last_port, __PROMPT__, debug_buf + 4, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 45:c80574f24dc3 | 1141 | pc.printf("\n\rComando enviado\n\r"); |
klauss | 45:c80574f24dc3 | 1142 | } |
klauss | 62:07e5bdc9f8f7 | 1143 | |
klauss | 58:af7e8788f106 | 1144 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "cks",3 )) { |
klauss | 45:c80574f24dc3 | 1145 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1146 | pcks_s = 1; |
klauss | 45:c80574f24dc3 | 1147 | } |
klauss | 45:c80574f24dc3 | 1148 | |
klauss | 58:af7e8788f106 | 1149 | else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "showcb",6 )) { |
klauss | 45:c80574f24dc3 | 1150 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1151 | pshowcb = 1; |
klauss | 45:c80574f24dc3 | 1152 | } |
klauss | 45:c80574f24dc3 | 1153 | |
klauss | 58:af7e8788f106 | 1154 | else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_main ", 11 )) { |
klauss | 45:c80574f24dc3 | 1155 | if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "on",2 )) { |
klauss | 45:c80574f24dc3 | 1156 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1157 | pc.printf("\r\nDebug Main ON"); |
klauss | 45:c80574f24dc3 | 1158 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1159 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Main On\n\r" ); |
klauss | 45:c80574f24dc3 | 1160 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1161 | } |
klauss | 45:c80574f24dc3 | 1162 | debug_main = 1; |
klauss | 45:c80574f24dc3 | 1163 | } |
klauss | 45:c80574f24dc3 | 1164 | if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { |
klauss | 45:c80574f24dc3 | 1165 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1166 | pc.printf("\r\nDebug Main OFF"); |
klauss | 45:c80574f24dc3 | 1167 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1168 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Main Off\n\r" ); |
klauss | 45:c80574f24dc3 | 1169 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1170 | } |
klauss | 45:c80574f24dc3 | 1171 | debug_main = 0; |
klauss | 45:c80574f24dc3 | 1172 | } |
klauss | 45:c80574f24dc3 | 1173 | } |
klauss | 45:c80574f24dc3 | 1174 | |
klauss | 58:af7e8788f106 | 1175 | else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cb_rx ", 12 )) { |
klauss | 45:c80574f24dc3 | 1176 | if (xmemmatch( (uint8_t*)( debug_buf + 12 ), (uint8_t*) "on",2 )) { |
klauss | 45:c80574f24dc3 | 1177 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1178 | pc.printf("\tDebug Cbx Rx ON"); |
klauss | 45:c80574f24dc3 | 1179 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1180 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Cbx On Rx on\n\r" ); |
klauss | 45:c80574f24dc3 | 1181 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1182 | } |
klauss | 45:c80574f24dc3 | 1183 | debug_cb_rx = 1; |
klauss | 45:c80574f24dc3 | 1184 | } |
klauss | 45:c80574f24dc3 | 1185 | if (xmemmatch( (uint8_t*)( debug_buf + 12 ), (uint8_t*) "off",3 )) { |
klauss | 45:c80574f24dc3 | 1186 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1187 | pc.printf("Debug Cbx Rx OFF"); |
klauss | 45:c80574f24dc3 | 1188 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1189 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Cbx Rx Off\n\r" ); |
klauss | 45:c80574f24dc3 | 1190 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1191 | } |
klauss | 45:c80574f24dc3 | 1192 | debug_cb_rx = 0; |
klauss | 45:c80574f24dc3 | 1193 | } |
klauss | 45:c80574f24dc3 | 1194 | } |
klauss | 45:c80574f24dc3 | 1195 | |
klauss | 58:af7e8788f106 | 1196 | else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_file ", 11 )) { |
klauss | 45:c80574f24dc3 | 1197 | if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "on",2 )) { |
klauss | 45:c80574f24dc3 | 1198 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1199 | pc.printf("\tDebug File ON"); |
klauss | 45:c80574f24dc3 | 1200 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1201 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug File On\n\r" ); |
klauss | 45:c80574f24dc3 | 1202 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1203 | } |
klauss | 45:c80574f24dc3 | 1204 | debug_cb_rx = 1; |
klauss | 45:c80574f24dc3 | 1205 | } |
klauss | 45:c80574f24dc3 | 1206 | if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { |
klauss | 45:c80574f24dc3 | 1207 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1208 | pc.printf("Debug File OFF"); |
klauss | 45:c80574f24dc3 | 1209 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1210 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug File Off\n\r" ); |
klauss | 45:c80574f24dc3 | 1211 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1212 | } |
klauss | 45:c80574f24dc3 | 1213 | debug_cb_rx = 0; |
klauss | 45:c80574f24dc3 | 1214 | } |
klauss | 45:c80574f24dc3 | 1215 | } |
klauss | 45:c80574f24dc3 | 1216 | |
klauss | 58:af7e8788f106 | 1217 | else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "help" )) { |
klauss | 45:c80574f24dc3 | 1218 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1219 | pc.printf("\n\r****************************PROMPT HELP******************\n\r"); |
klauss | 45:c80574f24dc3 | 1220 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1221 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "\n\r****************************PROMPT HELP******************\n\r" ); |
klauss | 45:c80574f24dc3 | 1222 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1223 | |
klauss | 45:c80574f24dc3 | 1224 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1225 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1226 | } |
klauss | 44:cc4996469404 | 1227 | } |
klauss | 52:12930cef17c4 | 1228 | |
klauss | 45:c80574f24dc3 | 1229 | pc.printf("ifconfig - mostra o arquivo de configuracao do sistema\n\r"); |
klauss | 45:c80574f24dc3 | 1230 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1231 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ifconfig - mostra o arquivo de configuracao do sistema\n\r" ); |
klauss | 45:c80574f24dc3 | 1232 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1233 | |
klauss | 45:c80574f24dc3 | 1234 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1235 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1236 | } |
klauss | 45:c80574f24dc3 | 1237 | } |
klauss | 45:c80574f24dc3 | 1238 | pc.printf("dconfig - volta as configuracoes do sistema para o padrao de fabrica\n\r"); |
klauss | 45:c80574f24dc3 | 1239 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1240 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "dconfig - volta as configuracoes do sistema para o padrao de fabrica\n\r" ); |
klauss | 45:c80574f24dc3 | 1241 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1242 | |
klauss | 45:c80574f24dc3 | 1243 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1244 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1245 | } |
klauss | 45:c80574f24dc3 | 1246 | } |
klauss | 45:c80574f24dc3 | 1247 | pc.printf("callme [ramal porta] - envia o pedido de ligacao para o callbox com o ramal e porta indicada\n\r"); |
klauss | 45:c80574f24dc3 | 1248 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1249 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "callme [ramal porta] - envia o pedido de ligacao para o callbox com o ramal e porta indicada\n\r" ); |
klauss | 45:c80574f24dc3 | 1250 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1251 | |
klauss | 45:c80574f24dc3 | 1252 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1253 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1254 | } |
klauss | 45:c80574f24dc3 | 1255 | } |
klauss | 48:195c97f12e8e | 1256 | pc.printf("pcb porta comando - envia o <comando> para o cbx <ramal> e <porta> executar\n\r"); |
klauss | 45:c80574f24dc3 | 1257 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1258 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "promptcb ramal porta comando - envia o <comando> para o cbx <ramal> e <porta> executar\n\r" ); |
klauss | 45:c80574f24dc3 | 1259 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1260 | |
klauss | 45:c80574f24dc3 | 1261 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1262 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1263 | } |
klauss | 45:c80574f24dc3 | 1264 | } |
klauss | 45:c80574f24dc3 | 1265 | pc.printf("format - formata o sistema de arquivos\n\r"); |
klauss | 62:07e5bdc9f8f7 | 1266 | //desabilitado via eth |
klauss | 62:07e5bdc9f8f7 | 1267 | /* |
klauss | 45:c80574f24dc3 | 1268 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1269 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "format - formata o sistema de arquivos\n\r" ); |
klauss | 45:c80574f24dc3 | 1270 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1271 | |
klauss | 45:c80574f24dc3 | 1272 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1273 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1274 | } |
klauss | 45:c80574f24dc3 | 1275 | } |
klauss | 62:07e5bdc9f8f7 | 1276 | */ |
klauss | 45:c80574f24dc3 | 1277 | pc.printf("reset - resta o sistema\n\r"); |
klauss | 45:c80574f24dc3 | 1278 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1279 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "reset - resta o sistema\n\r" ); |
klauss | 45:c80574f24dc3 | 1280 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1281 | |
klauss | 45:c80574f24dc3 | 1282 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1283 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1284 | } |
klauss | 45:c80574f24dc3 | 1285 | } |
klauss | 45:c80574f24dc3 | 1286 | pc.printf("ipset [ip] - Configura o IP da cabeceira\n\r"); |
klauss | 45:c80574f24dc3 | 1287 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1288 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ipset [ip] - Configura o IP da cabeceira\n\r" ); |
klauss | 45:c80574f24dc3 | 1289 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1290 | |
klauss | 45:c80574f24dc3 | 1291 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1292 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1293 | } |
klauss | 45:c80574f24dc3 | 1294 | } |
klauss | 45:c80574f24dc3 | 1295 | pc.printf("extset [ext] - Configura a ext da cabeceira\n\r"); |
klauss | 45:c80574f24dc3 | 1296 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1297 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "extset [ext] - Configura a ext da cabeceira\n\r" ); |
klauss | 45:c80574f24dc3 | 1298 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1299 | |
klauss | 45:c80574f24dc3 | 1300 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1301 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1302 | } |
klauss | 45:c80574f24dc3 | 1303 | } |
klauss | 45:c80574f24dc3 | 1304 | pc.printf("msipport [port] - Configura a porta SIP da cabeceira\n\r"); |
klauss | 45:c80574f24dc3 | 1305 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1306 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "msipport [port] - Configura a porta SIP da cabeceira\n\r" ); |
klauss | 45:c80574f24dc3 | 1307 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1308 | |
klauss | 45:c80574f24dc3 | 1309 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1310 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1311 | } |
klauss | 45:c80574f24dc3 | 1312 | } |
klauss | 45:c80574f24dc3 | 1313 | pc.printf("serverip [ip] - Configura o ip do servidor asterisk\n\r"); |
klauss | 45:c80574f24dc3 | 1314 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1315 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "serverip [ip] - Configura o ip do servidor asterisk\n\r" ); |
klauss | 45:c80574f24dc3 | 1316 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1317 | |
klauss | 45:c80574f24dc3 | 1318 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1319 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1320 | } |
klauss | 45:c80574f24dc3 | 1321 | } |
klauss | 45:c80574f24dc3 | 1322 | pc.printf("serextset [ext] - Configura a server ext da cabeceira\n\r"); |
klauss | 45:c80574f24dc3 | 1323 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1324 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "serextset [ext] - Configura a server ext da cabeceira\n\r" ); |
klauss | 45:c80574f24dc3 | 1325 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1326 | |
klauss | 45:c80574f24dc3 | 1327 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1328 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1329 | } |
klauss | 45:c80574f24dc3 | 1330 | } |
klauss | 45:c80574f24dc3 | 1331 | pc.printf("ssport [port] - Configura a porta SIP do servidor asterisk\n\r"); |
klauss | 45:c80574f24dc3 | 1332 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1333 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ssport [port] - Configura a porta SIP do servidor asterisk\n\r" ); |
klauss | 45:c80574f24dc3 | 1334 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1335 | |
klauss | 45:c80574f24dc3 | 1336 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1337 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1338 | } |
klauss | 45:c80574f24dc3 | 1339 | } |
klauss | 45:c80574f24dc3 | 1340 | pc.printf("maskset [mask] - Configura a mascara da cabeceira\n\r"); |
klauss | 45:c80574f24dc3 | 1341 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1342 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "maskset [mask] - Configura a mascara da cabeceira\n\r" ); |
klauss | 45:c80574f24dc3 | 1343 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1344 | |
klauss | 45:c80574f24dc3 | 1345 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1346 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1347 | } |
klauss | 45:c80574f24dc3 | 1348 | } |
klauss | 45:c80574f24dc3 | 1349 | pc.printf("gatewayset [gateway] - Configura o gateway da cabeceira\n\r"); |
klauss | 45:c80574f24dc3 | 1350 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1351 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "gatewayset [gateway] - Configura o gateway da cabeceira\n\r" ); |
klauss | 45:c80574f24dc3 | 1352 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1353 | |
klauss | 45:c80574f24dc3 | 1354 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1355 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1356 | } |
klauss | 45:c80574f24dc3 | 1357 | } |
klauss | 56:c64bcbaa621a | 1358 | pc.printf("telemetry_ip - Configura o IP do servidor de telemetria\n\r"); |
klauss | 56:c64bcbaa621a | 1359 | if( from_eth ){ |
klauss | 56:c64bcbaa621a | 1360 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "telemetry_ip - Configura o IP do servidor de telemetria\n\r" ); |
klauss | 56:c64bcbaa621a | 1361 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 56:c64bcbaa621a | 1362 | |
klauss | 56:c64bcbaa621a | 1363 | else if( udp_request ){ |
klauss | 56:c64bcbaa621a | 1364 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 56:c64bcbaa621a | 1365 | } |
klauss | 56:c64bcbaa621a | 1366 | } |
klauss | 62:07e5bdc9f8f7 | 1367 | pc.printf("telemetry_port - Configura a port do servidor de telemetria\n\r"); |
klauss | 56:c64bcbaa621a | 1368 | if( from_eth ){ |
klauss | 62:07e5bdc9f8f7 | 1369 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "telemetry_port - Configura a port do servidor de telemetria\n\r" ); |
klauss | 56:c64bcbaa621a | 1370 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 56:c64bcbaa621a | 1371 | |
klauss | 56:c64bcbaa621a | 1372 | else if( udp_request ){ |
klauss | 56:c64bcbaa621a | 1373 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 56:c64bcbaa621a | 1374 | } |
klauss | 56:c64bcbaa621a | 1375 | } |
klauss | 56:c64bcbaa621a | 1376 | |
klauss | 45:c80574f24dc3 | 1377 | pc.printf("showcb - lista os Cbx registrados na header\n\r"); |
klauss | 45:c80574f24dc3 | 1378 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1379 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "showcb - lista os Cbx registrados na header\n\r" ); |
klauss | 45:c80574f24dc3 | 1380 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1381 | |
klauss | 45:c80574f24dc3 | 1382 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1383 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1384 | } |
klauss | 45:c80574f24dc3 | 1385 | } |
klauss | 63:0d95da692bb4 | 1386 | /* |
klauss | 48:195c97f12e8e | 1387 | pc.printf("status - lista resumida de cbx registrados na header\n\r"); |
klauss | 48:195c97f12e8e | 1388 | if( from_eth ){ |
klauss | 48:195c97f12e8e | 1389 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "showcb - lista resumida de cbx registrados na header\n\r" ); |
klauss | 48:195c97f12e8e | 1390 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 48:195c97f12e8e | 1391 | |
klauss | 48:195c97f12e8e | 1392 | else if( udp_request ){ |
klauss | 48:195c97f12e8e | 1393 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 48:195c97f12e8e | 1394 | } |
klauss | 48:195c97f12e8e | 1395 | } |
klauss | 63:0d95da692bb4 | 1396 | */ |
klauss | 45:c80574f24dc3 | 1397 | pc.printf("cks - exibe estatisticas de check sum\n\r"); |
klauss | 45:c80574f24dc3 | 1398 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1399 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "cks - exibe estatisticas de check sum\n\r" ); |
klauss | 45:c80574f24dc3 | 1400 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1401 | |
klauss | 45:c80574f24dc3 | 1402 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1403 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1404 | } |
klauss | 45:c80574f24dc3 | 1405 | } |
klauss | 52:12930cef17c4 | 1406 | pc.printf("reset_cks - reseta estatisticas de check sum\n\r"); |
klauss | 52:12930cef17c4 | 1407 | if( from_eth ){ |
klauss | 52:12930cef17c4 | 1408 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "reset_cks - reseta estatisticas de check sum\n\r" ); |
klauss | 52:12930cef17c4 | 1409 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 52:12930cef17c4 | 1410 | |
klauss | 52:12930cef17c4 | 1411 | else if( udp_request ){ |
klauss | 52:12930cef17c4 | 1412 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 52:12930cef17c4 | 1413 | } |
klauss | 52:12930cef17c4 | 1414 | } |
klauss | 52:12930cef17c4 | 1415 | |
klauss | 45:c80574f24dc3 | 1416 | pc.printf(". - executa o comando anterior novamente\n\r"); |
klauss | 45:c80574f24dc3 | 1417 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1418 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, ". - executa o comando anterior novamente\n\r" ); |
klauss | 45:c80574f24dc3 | 1419 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1420 | |
klauss | 45:c80574f24dc3 | 1421 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1422 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1423 | } |
klauss | 45:c80574f24dc3 | 1424 | } |
klauss | 45:c80574f24dc3 | 1425 | pc.printf("debug [on|off|show] - seleciona debugs gerais | lista de debugs \n\r"); |
klauss | 45:c80574f24dc3 | 1426 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1427 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "debug [on|off|show] - seleciona debugs gerais | lista de debugs \n\r" ); |
klauss | 45:c80574f24dc3 | 1428 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1429 | |
klauss | 45:c80574f24dc3 | 1430 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1431 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1432 | } |
klauss | 45:c80574f24dc3 | 1433 | } |
klauss | 62:07e5bdc9f8f7 | 1434 | pc.printf("{ flood [ on | off ] | [+|-] } - simula envio de pacotes de audio\n\r"); |
klauss | 45:c80574f24dc3 | 1435 | if( from_eth ){ |
klauss | 62:07e5bdc9f8f7 | 1436 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "{ flood [ on | off ] | [+|-] } - simula envio de pacotes de audio\n\r"); |
klauss | 62:07e5bdc9f8f7 | 1437 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 62:07e5bdc9f8f7 | 1438 | |
klauss | 62:07e5bdc9f8f7 | 1439 | else if( udp_request ){ |
klauss | 62:07e5bdc9f8f7 | 1440 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 62:07e5bdc9f8f7 | 1441 | } |
klauss | 62:07e5bdc9f8f7 | 1442 | } |
klauss | 65:0b653cfe95db | 1443 | |
klauss | 65:0b653cfe95db | 1444 | pc.printf("silence <start_ext end_ext> - envia comando de flood off para os ramais no intervalo end_ext - start_ext\n\r"); |
klauss | 65:0b653cfe95db | 1445 | if( from_eth ){ |
klauss | 65:0b653cfe95db | 1446 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "silence <start_ext end_ext> - envia comando de flood off para os ramais no intervalo end_ext - start_ext\n\r"); |
klauss | 65:0b653cfe95db | 1447 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 65:0b653cfe95db | 1448 | |
klauss | 65:0b653cfe95db | 1449 | else if( udp_request ){ |
klauss | 65:0b653cfe95db | 1450 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 65:0b653cfe95db | 1451 | } |
klauss | 65:0b653cfe95db | 1452 | } |
klauss | 65:0b653cfe95db | 1453 | |
klauss | 62:07e5bdc9f8f7 | 1454 | pc.printf("++ ext - Header flood on, ext flood on\n\r"); |
klauss | 62:07e5bdc9f8f7 | 1455 | if( from_eth ){ |
klauss | 62:07e5bdc9f8f7 | 1456 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "++ ext - Header flood on, ext flood on\n\r"); |
klauss | 45:c80574f24dc3 | 1457 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1458 | |
klauss | 45:c80574f24dc3 | 1459 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1460 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1461 | } |
klauss | 45:c80574f24dc3 | 1462 | } |
klauss | 64:5b011d5707d2 | 1463 | pc.printf("rx - Exibe ultimo pacote recebido dos CBx\n\r"); |
klauss | 64:5b011d5707d2 | 1464 | if( from_eth ){ |
klauss | 64:5b011d5707d2 | 1465 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "rx - Exibe ultimo pacote recebido dos CBx\n\r"); |
klauss | 64:5b011d5707d2 | 1466 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 64:5b011d5707d2 | 1467 | |
klauss | 64:5b011d5707d2 | 1468 | else if( udp_request ){ |
klauss | 64:5b011d5707d2 | 1469 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 64:5b011d5707d2 | 1470 | } |
klauss | 64:5b011d5707d2 | 1471 | } |
klauss | 64:5b011d5707d2 | 1472 | pc.printf("tx - Exibe ultimo pacote enviado para os CBx\n\r"); |
klauss | 64:5b011d5707d2 | 1473 | if( from_eth ){ |
klauss | 64:5b011d5707d2 | 1474 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "tx - Exibe ultimo pacote enviado para os CBx\n\r"); |
klauss | 64:5b011d5707d2 | 1475 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 64:5b011d5707d2 | 1476 | |
klauss | 64:5b011d5707d2 | 1477 | else if( udp_request ){ |
klauss | 64:5b011d5707d2 | 1478 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 64:5b011d5707d2 | 1479 | } |
klauss | 64:5b011d5707d2 | 1480 | } |
klauss | 64:5b011d5707d2 | 1481 | pc.printf("ls | status - Exibe uma lista ordenada por ext do CBx registrados na Header\n\r"); |
klauss | 64:5b011d5707d2 | 1482 | if( from_eth ){ |
klauss | 64:5b011d5707d2 | 1483 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ls | status - Exibe uma lista ordenada por ext do CBx registrados na Header\n\r"); |
klauss | 64:5b011d5707d2 | 1484 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 64:5b011d5707d2 | 1485 | |
klauss | 64:5b011d5707d2 | 1486 | else if( udp_request ){ |
klauss | 64:5b011d5707d2 | 1487 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 64:5b011d5707d2 | 1488 | } |
klauss | 64:5b011d5707d2 | 1489 | } |
klauss | 64:5b011d5707d2 | 1490 | pc.printf("types - Lista os types usados no protocolo de comunicacao Header -- CBx\n\r"); |
klauss | 64:5b011d5707d2 | 1491 | if( from_eth ){ |
klauss | 64:5b011d5707d2 | 1492 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "types - Lista os types usados no protocolo de comunicacao Header -- CBx\n\r"); |
klauss | 64:5b011d5707d2 | 1493 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 64:5b011d5707d2 | 1494 | |
klauss | 64:5b011d5707d2 | 1495 | else if( udp_request ){ |
klauss | 64:5b011d5707d2 | 1496 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 64:5b011d5707d2 | 1497 | } |
klauss | 64:5b011d5707d2 | 1498 | } |
klauss | 64:5b011d5707d2 | 1499 | pc.printf("protocol - Exibe formato do pacote seguindo o protocolo de comunicacao Header -- CBx\n\r"); |
klauss | 64:5b011d5707d2 | 1500 | if( from_eth ){ |
klauss | 64:5b011d5707d2 | 1501 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "protocol - Exibe formato do pacote seguindo o protocolo de comunicacao Header -- CBx\n\r"); |
klauss | 64:5b011d5707d2 | 1502 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 64:5b011d5707d2 | 1503 | |
klauss | 64:5b011d5707d2 | 1504 | else if( udp_request ){ |
klauss | 64:5b011d5707d2 | 1505 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 64:5b011d5707d2 | 1506 | } |
klauss | 64:5b011d5707d2 | 1507 | } |
klauss | 64:5b011d5707d2 | 1508 | |
klauss | 45:c80574f24dc3 | 1509 | pc.printf("PROMPT VERSION: V%d\n\r",PVERSION); |
klauss | 45:c80574f24dc3 | 1510 | //Obs :: a ultima linha nao mandamos direto pro tcp porque ela eh enviada fora desse escopo |
klauss | 45:c80574f24dc3 | 1511 | if( from_eth ) snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "PROMPT VERSION: V%d\n\r",PVERSION); |
klauss | 27:98f824719d1c | 1512 | } |
klauss | 54:448d57291be6 | 1513 | |
klauss | 58:af7e8788f106 | 1514 | else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "callme ", 7 )){ |
klauss | 54:448d57291be6 | 1515 | miss_match = false; |
klauss | 54:448d57291be6 | 1516 | int ext,port; |
klauss | 54:448d57291be6 | 1517 | char cmd[ 16 ]; |
klauss | 54:448d57291be6 | 1518 | strcpy( cmd, "call init " ); |
klauss | 54:448d57291be6 | 1519 | |
klauss | 54:448d57291be6 | 1520 | ext = atoi( debug_buf + 7 ); |
klauss | 54:448d57291be6 | 1521 | port = convert_ext_to_port( ext ); |
klauss | 54:448d57291be6 | 1522 | |
klauss | 62:07e5bdc9f8f7 | 1523 | if( ext % 2 ){ |
klauss | 62:07e5bdc9f8f7 | 1524 | ext--; |
klauss | 62:07e5bdc9f8f7 | 1525 | strcat( cmd, "B\r\r" ); |
klauss | 62:07e5bdc9f8f7 | 1526 | }else{ |
klauss | 62:07e5bdc9f8f7 | 1527 | strcat( cmd, "A\r\r" ); |
klauss | 62:07e5bdc9f8f7 | 1528 | } |
klauss | 54:448d57291be6 | 1529 | |
klauss | 54:448d57291be6 | 1530 | promptcb_last_ext = ext; |
klauss | 54:448d57291be6 | 1531 | promptcb_last_port = port; |
klauss | 54:448d57291be6 | 1532 | |
klauss | 62:07e5bdc9f8f7 | 1533 | int tmp = strlen( cmd ); |
klauss | 62:07e5bdc9f8f7 | 1534 | cmd[ tmp ] = 0x0D; |
klauss | 62:07e5bdc9f8f7 | 1535 | cmd[ tmp + 1 ] = 0x00; |
klauss | 62:07e5bdc9f8f7 | 1536 | strcpy( promptcb_last_cmd, cmd ); |
klauss | 62:07e5bdc9f8f7 | 1537 | |
klauss | 54:448d57291be6 | 1538 | pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n", ext, port, cmd ); |
klauss | 54:448d57291be6 | 1539 | __send_to_cb__( __build_cb_package__( ext, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 62:07e5bdc9f8f7 | 1540 | pc.printf("\n\rComando enviado\n\r"); |
klauss | 54:448d57291be6 | 1541 | |
klauss | 54:448d57291be6 | 1542 | if( from_eth ){ |
klauss | 62:07e5bdc9f8f7 | 1543 | char eth_msg[ 512 ]; |
klauss | 62:07e5bdc9f8f7 | 1544 | snprintf( eth_msg, 512 - 1, "\r\next=%d port=%d\r\ncmd=%s\r\n\n\rComando enviado\n\r", ext, port, cmd ); |
klauss | 62:07e5bdc9f8f7 | 1545 | if( tcp_session ){ |
klauss | 62:07e5bdc9f8f7 | 1546 | tcp_client.send_all( eth_msg, strlen( eth_msg ) ); |
klauss | 62:07e5bdc9f8f7 | 1547 | }else if( udp_request ){ |
klauss | 62:07e5bdc9f8f7 | 1548 | udp_server.sendTo( udp_client, eth_msg, strlen( eth_msg ) ); |
klauss | 62:07e5bdc9f8f7 | 1549 | } |
klauss | 19:ab2088e0dec6 | 1550 | } |
klauss | 54:448d57291be6 | 1551 | |
klauss | 54:448d57291be6 | 1552 | bufptr = 0; |
klauss | 54:448d57291be6 | 1553 | debug_buf[ 0 ] = 0; |
klauss | 45:c80574f24dc3 | 1554 | } |
klauss | 45:c80574f24dc3 | 1555 | |
klauss | 45:c80574f24dc3 | 1556 | if( miss_match ){ |
klauss | 48:195c97f12e8e | 1557 | pc.printf("\n\r> %s: command not found\n\r", debug_buf ); |
klauss | 45:c80574f24dc3 | 1558 | if( from_eth ){ |
klauss | 48:195c97f12e8e | 1559 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "> %s: command not found\n ", debug_buf ); |
klauss | 58:af7e8788f106 | 1560 | //debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1561 | } |
klauss | 45:c80574f24dc3 | 1562 | } |
klauss | 45:c80574f24dc3 | 1563 | else{ |
klauss | 58:af7e8788f106 | 1564 | if( from_eth && strlen( debug_buf ) > 2 ) strcpy( last_cmd, tmp_cmd ); |
klauss | 58:af7e8788f106 | 1565 | |
klauss | 58:af7e8788f106 | 1566 | else if( strlen( debug_buf ) > 2 ) strcpy( last_cmd, tmp_cmd ); |
klauss | 45:c80574f24dc3 | 1567 | } |
klauss | 48:195c97f12e8e | 1568 | } |
klauss | 45:c80574f24dc3 | 1569 | if( b == 0x0D || bufret == 1 || bufptr > DEBUGBUFSIZE ){ |
klauss | 45:c80574f24dc3 | 1570 | bufret = 0; |
klauss | 57:78f7191a8b69 | 1571 | if( from_eth ){ |
klauss | 57:78f7191a8b69 | 1572 | from_eth = false; |
klauss | 57:78f7191a8b69 | 1573 | |
klauss | 48:195c97f12e8e | 1574 | if( debug_buf[ strlen( debug_buf ) - 1 ] == '\r' || debug_buf[ strlen( debug_buf ) - 1 ] == '\n' ) strcat( debug_buf, "> " ); |
klauss | 48:195c97f12e8e | 1575 | |
klauss | 48:195c97f12e8e | 1576 | else strcat( debug_buf, "\n\r> " ); |
klauss | 48:195c97f12e8e | 1577 | |
klauss | 57:78f7191a8b69 | 1578 | if( tcp_session ){ |
klauss | 57:78f7191a8b69 | 1579 | |
klauss | 57:78f7191a8b69 | 1580 | tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 57:78f7191a8b69 | 1581 | |
klauss | 57:78f7191a8b69 | 1582 | }else if( udp_request ){ |
klauss | 48:195c97f12e8e | 1583 | |
klauss | 57:78f7191a8b69 | 1584 | int sent = udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 48:195c97f12e8e | 1585 | |
klauss | 57:78f7191a8b69 | 1586 | udp_request = false; |
klauss | 57:78f7191a8b69 | 1587 | } |
klauss | 57:78f7191a8b69 | 1588 | for( register uint16_t i = 0; i < __PROMPT_ETH_BUFFER_SIZE__; i++ ) eth_buffer[ i ] = 0; |
klauss | 57:78f7191a8b69 | 1589 | debug_buf = __debug_buf__; |
klauss | 57:78f7191a8b69 | 1590 | bufptr = last_bufptr; |
klauss | 45:c80574f24dc3 | 1591 | }else{ |
klauss | 42:480335bdde12 | 1592 | bufptr = 0; |
klauss | 58:af7e8788f106 | 1593 | for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; |
klauss | 45:c80574f24dc3 | 1594 | } |
klauss | 45:c80574f24dc3 | 1595 | pc.putc(0x0A); |
klauss | 45:c80574f24dc3 | 1596 | pc.putc(0x0D); |
klauss | 45:c80574f24dc3 | 1597 | pc.printf("> "); |
klauss | 45:c80574f24dc3 | 1598 | } |
klauss | 36:728498a78e1e | 1599 | return( NULL ); |
klauss | 50:d9b6577a70f5 | 1600 | } |
klauss | 50:d9b6577a70f5 | 1601 | |
klauss | 51:5fc3a8f02fdf | 1602 | int convert_ext_to_port( int ext ){ |
klauss | 51:5fc3a8f02fdf | 1603 | if( ext < 1000 ) return ext; |
klauss | 51:5fc3a8f02fdf | 1604 | |
klauss | 51:5fc3a8f02fdf | 1605 | else{ |
klauss | 51:5fc3a8f02fdf | 1606 | int aux = 0; |
klauss | 51:5fc3a8f02fdf | 1607 | aux = ( ext / 1000 ) * 1000; |
klauss | 51:5fc3a8f02fdf | 1608 | ext -= aux; |
klauss | 51:5fc3a8f02fdf | 1609 | aux += ext % 100; |
klauss | 51:5fc3a8f02fdf | 1610 | return( aux ); |
klauss | 51:5fc3a8f02fdf | 1611 | } |
klauss | 50:d9b6577a70f5 | 1612 | } |
klauss | 54:448d57291be6 | 1613 | |
klauss | 55:2f5e7374af9d | 1614 | void set_ip( char * new_header_ip ){ |
klauss | 54:448d57291be6 | 1615 | fip = fopen("/qspi/myip.txt", "w"); |
klauss | 55:2f5e7374af9d | 1616 | fprintf( fip, "%s\n\r", new_header_ip ); |
klauss | 54:448d57291be6 | 1617 | fclose( fip ); |
klauss | 54:448d57291be6 | 1618 | } |
klauss | 54:448d57291be6 | 1619 | |
klauss | 55:2f5e7374af9d | 1620 | void set_header_ext( int new_header_ext ){ |
klauss | 54:448d57291be6 | 1621 | fext = fopen( "/qspi/myext.txt", "w" ); |
klauss | 55:2f5e7374af9d | 1622 | fprintf( fext, "%i\n\r", new_header_ext ); |
klauss | 54:448d57291be6 | 1623 | fclose( fext ); |
klauss | 55:2f5e7374af9d | 1624 | } |
klauss | 55:2f5e7374af9d | 1625 | |
klauss | 55:2f5e7374af9d | 1626 | void set_header_sip_port( int new_header_sip_port ){ |
klauss | 55:2f5e7374af9d | 1627 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 55:2f5e7374af9d | 1628 | fprintf( fport,"%i\n\r", new_header_sip_port ); |
klauss | 55:2f5e7374af9d | 1629 | fclose( fport ); |
klauss | 55:2f5e7374af9d | 1630 | } |
klauss | 55:2f5e7374af9d | 1631 | |
klauss | 55:2f5e7374af9d | 1632 | void set_server_ip( char * new_server_ip ){ |
klauss | 55:2f5e7374af9d | 1633 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 55:2f5e7374af9d | 1634 | fprintf( fsip,"%s\n\r", new_server_ip ); |
klauss | 55:2f5e7374af9d | 1635 | fclose( fsip ); |
klauss | 55:2f5e7374af9d | 1636 | } |
klauss | 55:2f5e7374af9d | 1637 | |
klauss | 55:2f5e7374af9d | 1638 | void set_server_ext( int new_server_ext ){ |
klauss | 55:2f5e7374af9d | 1639 | fserext = fopen("/qspi/peerext.txt", "w"); |
klauss | 55:2f5e7374af9d | 1640 | fprintf( fserext , "%i\n\r", new_server_ext ); |
klauss | 55:2f5e7374af9d | 1641 | fclose( fserext ); |
klauss | 55:2f5e7374af9d | 1642 | } |
klauss | 55:2f5e7374af9d | 1643 | |
klauss | 55:2f5e7374af9d | 1644 | void set_server_port( int new_server_port ){ |
klauss | 55:2f5e7374af9d | 1645 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 55:2f5e7374af9d | 1646 | fprintf(fsport,"%i\n\r", new_server_port ); |
klauss | 55:2f5e7374af9d | 1647 | fclose( fsport ); |
klauss | 55:2f5e7374af9d | 1648 | } |
klauss | 55:2f5e7374af9d | 1649 | |
klauss | 55:2f5e7374af9d | 1650 | void set_mask( char * new_mask ){ |
klauss | 55:2f5e7374af9d | 1651 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 55:2f5e7374af9d | 1652 | fprintf(fmask,"%s\n\r",new_mask ); |
klauss | 55:2f5e7374af9d | 1653 | fclose( fmask ); |
klauss | 55:2f5e7374af9d | 1654 | } |
klauss | 55:2f5e7374af9d | 1655 | |
klauss | 55:2f5e7374af9d | 1656 | void set_gateway( char * new_gateway ){ |
klauss | 55:2f5e7374af9d | 1657 | fgate = fopen("/qspi/mygate.txt", "w"); |
klauss | 55:2f5e7374af9d | 1658 | fprintf(fgate,"%s\n\r", new_gateway ); |
klauss | 55:2f5e7374af9d | 1659 | fclose( fgate ); |
klauss | 56:c64bcbaa621a | 1660 | } |
klauss | 56:c64bcbaa621a | 1661 | |
klauss | 56:c64bcbaa621a | 1662 | void set_udp_port_listener( int new_udp_port_listener ){ |
klauss | 56:c64bcbaa621a | 1663 | fudpport = fopen( "/qspi/udpport.txt", "w" ); |
klauss | 56:c64bcbaa621a | 1664 | fprintf( fudpport, "%i\n\r",new_udp_port_listener ); |
klauss | 56:c64bcbaa621a | 1665 | fclose( fudpport ); |
klauss | 56:c64bcbaa621a | 1666 | } |
klauss | 56:c64bcbaa621a | 1667 | |
klauss | 56:c64bcbaa621a | 1668 | void set_tcp_port_listener( int new_tcp_port_listener ){ |
klauss | 56:c64bcbaa621a | 1669 | ftcpport = fopen( "/qspi/tcpport.txt", "w" ); |
klauss | 56:c64bcbaa621a | 1670 | fprintf( ftcpport, "%i\n\r",new_tcp_port_listener ); |
klauss | 56:c64bcbaa621a | 1671 | fclose( ftcpport ); |
klauss | 56:c64bcbaa621a | 1672 | } |
klauss | 56:c64bcbaa621a | 1673 | |
klauss | 56:c64bcbaa621a | 1674 | void set_telemetry_ip( char * new_telemetry_ip ){ |
klauss | 56:c64bcbaa621a | 1675 | ftip = fopen("/qspi/telemetry_ip.txt", "w" ); |
klauss | 56:c64bcbaa621a | 1676 | fprintf(ftip,"%s\n\r", new_telemetry_ip ); |
klauss | 56:c64bcbaa621a | 1677 | fclose( ftip ); |
klauss | 56:c64bcbaa621a | 1678 | } |
klauss | 56:c64bcbaa621a | 1679 | |
klauss | 56:c64bcbaa621a | 1680 | void set_telemetry_port( int new_telemetry_port ){ |
klauss | 56:c64bcbaa621a | 1681 | ftport = fopen("/qspi/telemetry_port.txt", "w" ); |
klauss | 56:c64bcbaa621a | 1682 | fprintf(ftport,"%i\n\r", new_telemetry_port ); |
klauss | 56:c64bcbaa621a | 1683 | fclose( ftport ); |
klauss | 54:448d57291be6 | 1684 | } |