![](/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@53:bb492a8f115a, 2014-10-21 (annotated)
- Committer:
- klauss
- Date:
- Tue Oct 21 19:35:07 2014 +0000
- Revision:
- 53:bb492a8f115a
- Parent:
- 52:12930cef17c4
- Child:
- 54:448d57291be6
tratamento do pacote de telemetry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 44:cc4996469404 | 1 | #include "prompt.h" |
Cola | 24:270b436a1bb0 | 2 | |
klauss | 45:c80574f24dc3 | 3 | TCPSocketServer tcp_server; |
klauss | 45:c80574f24dc3 | 4 | TCPSocketConnection tcp_client; |
klauss | 41:69bf7091c2ca | 5 | Timer tcp_timer; |
klauss | 48:195c97f12e8e | 6 | Timer udp_timer; |
klauss | 45:c80574f24dc3 | 7 | |
klauss | 45:c80574f24dc3 | 8 | UDPSocket udp_server; |
klauss | 45:c80574f24dc3 | 9 | Endpoint udp_client; |
klauss | 41:69bf7091c2ca | 10 | |
klauss | 28:94aec56c6329 | 11 | uint8_t debug_alive = 0; |
klauss | 28:94aec56c6329 | 12 | uint8_t debug_sip = 0; |
klauss | 29:7246460b73f8 | 13 | uint8_t debug_vector = 0; |
klauss | 29:7246460b73f8 | 14 | uint8_t debug_cb = 0; |
klauss | 30:8dfb6d8de53d | 15 | uint8_t debug_main = 0; |
klauss | 31:bb5fb28a77df | 16 | uint8_t debug_cks = 0; |
Cola | 22:d2a4b5939115 | 17 | uint8_t pcks_s = 0; |
Cola | 24:270b436a1bb0 | 18 | uint8_t pshowcb = 0; |
klauss | 31:bb5fb28a77df | 19 | uint8_t debug_cb_rx = 0; |
klauss | 31:bb5fb28a77df | 20 | uint8_t debug_cb_tx = 0; |
klauss | 31:bb5fb28a77df | 21 | uint8_t debug_eth_rx = 0; |
klauss | 31:bb5fb28a77df | 22 | uint8_t debug_eth_tx = 0; |
klauss | 43:455522f98de5 | 23 | uint8_t debug_prompt_eth = 0; |
klauss | 31:bb5fb28a77df | 24 | uint8_t debug_file = 0; |
klauss | 38:af5ecd6997ab | 25 | bool from_eth = false; |
klauss | 42:480335bdde12 | 26 | bool udp_request = false; |
klauss | 42:480335bdde12 | 27 | bool tcp_session = false; |
klauss | 48:195c97f12e8e | 28 | bool cb_session = false; |
klauss | 48:195c97f12e8e | 29 | bool cb_status = false; |
klauss | 52:12930cef17c4 | 30 | bool reset_cks = false; |
klauss | 53:bb492a8f115a | 31 | bool debug_telemetry = false; |
klauss | 53:bb492a8f115a | 32 | bool telemetry_test = false; |
klauss | 28:94aec56c6329 | 33 | |
klauss | 29:7246460b73f8 | 34 | uint8_t test_debug = 1; |
klauss | 45:c80574f24dc3 | 35 | #define PVERSION 4 // Sempre atualizar a versao do prompt |
klauss | 19:ab2088e0dec6 | 36 | |
Cola | 21:0bd688722e81 | 37 | #define DEBUGBUFSIZE 50 |
klauss | 35:96885a7931f0 | 38 | char __debug_buf__[DEBUGBUFSIZE]; |
klauss | 35:96885a7931f0 | 39 | char * debug_buf = __debug_buf__; |
klauss | 30:8dfb6d8de53d | 40 | char last_debug_buf[ DEBUGBUFSIZE ] = "help"; |
klauss | 45:c80574f24dc3 | 41 | FILE *fip, *fmask, *fgate, *fport, *fsip, *fsport, *fext, *fserext, *fudpport, *ftcpport; |
klauss | 19:ab2088e0dec6 | 42 | uint8_t debug_prompt = 0; |
klauss | 19:ab2088e0dec6 | 43 | uint8_t bufptr = 0; |
klauss | 35:96885a7931f0 | 44 | uint8_t last_bufptr = 0; |
klauss | 19:ab2088e0dec6 | 45 | |
klauss | 19:ab2088e0dec6 | 46 | uint8_t xmemmatch(const uint8_t * s1, const uint8_t * s2, uint16_t size) { // presente da lib.h pode retirar da versao final |
klauss | 19:ab2088e0dec6 | 47 | while (size--) { |
klauss | 19:ab2088e0dec6 | 48 | if (*s1++ != *s2++) return 0; /* does not match */ |
klauss | 19:ab2088e0dec6 | 49 | } |
klauss | 19:ab2088e0dec6 | 50 | return 1; /* matches */ |
klauss | 19:ab2088e0dec6 | 51 | } |
klauss | 19:ab2088e0dec6 | 52 | |
klauss | 19:ab2088e0dec6 | 53 | uint8_t xstrmatch(const uint8_t * s1, const uint8_t * s2) { // presente na lib.h pode retirar da versao final |
klauss | 19:ab2088e0dec6 | 54 | while (*s1) { |
klauss | 19:ab2088e0dec6 | 55 | if (*s1++ != *s2++) return 0; /* does not match */ |
klauss | 19:ab2088e0dec6 | 56 | } |
klauss | 19:ab2088e0dec6 | 57 | if ( *s2 == 0 ) |
klauss | 19:ab2088e0dec6 | 58 | return 1; /* matches */ |
klauss | 19:ab2088e0dec6 | 59 | else |
klauss | 19:ab2088e0dec6 | 60 | return 0; /* does not match */ |
klauss | 19:ab2088e0dec6 | 61 | } |
klauss | 19:ab2088e0dec6 | 62 | |
klauss | 19:ab2088e0dec6 | 63 | void xmemcpy(uint8_t * dest, const uint8_t * src, uint16_t size) { // presente na lib.h pode retirar da versao final |
klauss | 19:ab2088e0dec6 | 64 | while (size--) *dest++ = *src++; |
klauss | 19:ab2088e0dec6 | 65 | } |
klauss | 19:ab2088e0dec6 | 66 | |
klauss | 48:195c97f12e8e | 67 | int str2uint ( char * s, unsigned int * val ){ |
Cola | 21:0bd688722e81 | 68 | int i = 0; |
Cola | 21:0bd688722e81 | 69 | unsigned int ret = 0; |
Cola | 21:0bd688722e81 | 70 | for (;;) { |
Cola | 21:0bd688722e81 | 71 | if (s[i] < '0') { |
Cola | 21:0bd688722e81 | 72 | *val = ret; |
Cola | 21:0bd688722e81 | 73 | return i; |
Cola | 21:0bd688722e81 | 74 | } |
Cola | 21:0bd688722e81 | 75 | ret *= 10; |
Cola | 21:0bd688722e81 | 76 | ret += s[i] - '0'; |
Cola | 21:0bd688722e81 | 77 | i++; |
Cola | 21:0bd688722e81 | 78 | } |
Cola | 21:0bd688722e81 | 79 | } |
klauss | 19:ab2088e0dec6 | 80 | |
klauss | 38:af5ecd6997ab | 81 | // Print the content of a given file |
klauss | 38:af5ecd6997ab | 82 | void cat(const char* fname){ |
klauss | 19:ab2088e0dec6 | 83 | char buff[513]; |
klauss | 19:ab2088e0dec6 | 84 | int num; |
klauss | 19:ab2088e0dec6 | 85 | |
klauss | 19:ab2088e0dec6 | 86 | FILE *fp = fopen(fname, "r"); |
klauss | 19:ab2088e0dec6 | 87 | if (fp == NULL) { |
klauss | 42:480335bdde12 | 88 | if( debug_file ) pc.printf( "Failed to open %s", fname); |
klauss | 19:ab2088e0dec6 | 89 | return; |
klauss | 19:ab2088e0dec6 | 90 | } |
klauss | 19:ab2088e0dec6 | 91 | |
klauss | 42:480335bdde12 | 92 | while( ( num = fread( buff, 1, 512, fp ) ) > 0 ){ |
klauss | 42:480335bdde12 | 93 | buff[ num ] = '\0'; |
klauss | 42:480335bdde12 | 94 | pc.printf( buff ); |
klauss | 42:480335bdde12 | 95 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 96 | if( tcp_session ) tcp_client.send_all( buff, strlen( buff ) ); |
klauss | 45:c80574f24dc3 | 97 | |
klauss | 45:c80574f24dc3 | 98 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 99 | udp_server.sendTo( udp_client, buff, strlen( buff ) ); |
klauss | 45:c80574f24dc3 | 100 | } |
klauss | 42:480335bdde12 | 101 | } |
klauss | 19:ab2088e0dec6 | 102 | } |
klauss | 19:ab2088e0dec6 | 103 | fclose(fp); |
klauss | 19:ab2088e0dec6 | 104 | } |
klauss | 19:ab2088e0dec6 | 105 | |
klauss | 28:94aec56c6329 | 106 | // operantion with the system config files |
klauss | 42:480335bdde12 | 107 | void files( const char type ){ |
klauss | 42:480335bdde12 | 108 | // show files |
klauss | 42:480335bdde12 | 109 | if (type == 's' ){ |
klauss | 42:480335bdde12 | 110 | pc.printf("\n\rHeader IP " ); |
klauss | 42:480335bdde12 | 111 | if( from_eth ){ |
klauss | 42:480335bdde12 | 112 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rHeader IP " ); |
klauss | 45:c80574f24dc3 | 113 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 114 | |
klauss | 45:c80574f24dc3 | 115 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 116 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 117 | } |
klauss | 42:480335bdde12 | 118 | } |
klauss | 19:ab2088e0dec6 | 119 | cat("/qspi/myip.txt"); |
klauss | 42:480335bdde12 | 120 | |
klauss | 28:94aec56c6329 | 121 | pc.printf("\n\rHeader ext "); |
klauss | 42:480335bdde12 | 122 | if( from_eth ){ |
klauss | 42:480335bdde12 | 123 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rHeader ext " ); |
klauss | 45:c80574f24dc3 | 124 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 125 | |
klauss | 45:c80574f24dc3 | 126 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 127 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 128 | } |
klauss | 42:480335bdde12 | 129 | } |
klauss | 28:94aec56c6329 | 130 | cat("/qspi/myext.txt"); |
klauss | 42:480335bdde12 | 131 | |
klauss | 28:94aec56c6329 | 132 | pc.printf("\n\rHeader port "); |
klauss | 42:480335bdde12 | 133 | if( from_eth ){ |
klauss | 42:480335bdde12 | 134 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rHeader port " ); |
klauss | 45:c80574f24dc3 | 135 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 136 | |
klauss | 45:c80574f24dc3 | 137 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 138 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 139 | } |
klauss | 42:480335bdde12 | 140 | } |
klauss | 28:94aec56c6329 | 141 | cat("/qspi/mysipport.txt"); |
klauss | 28:94aec56c6329 | 142 | |
klauss | 42:480335bdde12 | 143 | pc.printf("\n\rServer IP "); |
klauss | 42:480335bdde12 | 144 | if( from_eth ){ |
klauss | 42:480335bdde12 | 145 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rServer IP " ); |
klauss | 45:c80574f24dc3 | 146 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 147 | |
klauss | 45:c80574f24dc3 | 148 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 149 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 150 | } |
klauss | 42:480335bdde12 | 151 | } |
klauss | 28:94aec56c6329 | 152 | cat("/qspi/serverip.txt"); |
klauss | 42:480335bdde12 | 153 | |
klauss | 28:94aec56c6329 | 154 | pc.printf("\n\rServer ext "); |
klauss | 42:480335bdde12 | 155 | if( from_eth ){ |
klauss | 42:480335bdde12 | 156 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rServer ext " ); |
klauss | 45:c80574f24dc3 | 157 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 158 | |
klauss | 45:c80574f24dc3 | 159 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 160 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 161 | } |
klauss | 42:480335bdde12 | 162 | } |
klauss | 28:94aec56c6329 | 163 | cat("/qspi/peerext.txt"); |
klauss | 42:480335bdde12 | 164 | |
klauss | 28:94aec56c6329 | 165 | pc.printf("\n\rServer port "); |
klauss | 42:480335bdde12 | 166 | if( from_eth ){ |
klauss | 42:480335bdde12 | 167 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rServer port " ); |
klauss | 45:c80574f24dc3 | 168 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 169 | |
klauss | 45:c80574f24dc3 | 170 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 171 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 172 | } |
klauss | 42:480335bdde12 | 173 | } |
klauss | 28:94aec56c6329 | 174 | cat("/qspi/serverport.txt"); |
klauss | 28:94aec56c6329 | 175 | |
klauss | 28:94aec56c6329 | 176 | pc.printf("\n\rMascara de rede "); |
klauss | 42:480335bdde12 | 177 | if( from_eth ){ |
klauss | 42:480335bdde12 | 178 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rMascara de rede " ); |
klauss | 45:c80574f24dc3 | 179 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 180 | |
klauss | 45:c80574f24dc3 | 181 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 182 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 183 | } |
klauss | 42:480335bdde12 | 184 | } |
klauss | 19:ab2088e0dec6 | 185 | cat("/qspi/mymask.txt"); |
klauss | 42:480335bdde12 | 186 | |
klauss | 28:94aec56c6329 | 187 | pc.printf("\n\rGateway IP "); |
klauss | 42:480335bdde12 | 188 | if( from_eth ){ |
klauss | 42:480335bdde12 | 189 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rGateway IP " ); |
klauss | 45:c80574f24dc3 | 190 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 191 | |
klauss | 45:c80574f24dc3 | 192 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 193 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 194 | } |
klauss | 42:480335bdde12 | 195 | } |
klauss | 19:ab2088e0dec6 | 196 | cat("/qspi/mygate.txt"); |
klauss | 43:455522f98de5 | 197 | |
klauss | 45:c80574f24dc3 | 198 | pc.printf("\n\rUDP Port "); |
klauss | 45:c80574f24dc3 | 199 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 200 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rUDP Port " ); |
klauss | 45:c80574f24dc3 | 201 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 202 | |
klauss | 45:c80574f24dc3 | 203 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 204 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 205 | } |
klauss | 45:c80574f24dc3 | 206 | } |
klauss | 45:c80574f24dc3 | 207 | cat("/qspi/udpport.txt"); |
klauss | 45:c80574f24dc3 | 208 | |
klauss | 45:c80574f24dc3 | 209 | pc.printf("\n\rTCP Port "); |
klauss | 45:c80574f24dc3 | 210 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 211 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rTCP Port " ); |
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 | 45:c80574f24dc3 | 217 | } |
klauss | 45:c80574f24dc3 | 218 | cat("/qspi/tcpport.txt"); |
klauss | 45:c80574f24dc3 | 219 | |
klauss | 43:455522f98de5 | 220 | debug_buf[ 0 ] = 0; |
klauss | 43:455522f98de5 | 221 | bufptr = 0; |
klauss | 48:195c97f12e8e | 222 | if( tcp_session ) tcp_client.send_all( "\n\r>" , strlen( "\n\r>" ) ); |
klauss | 48:195c97f12e8e | 223 | |
klauss | 48:195c97f12e8e | 224 | else if( udp_request ){ |
klauss | 48:195c97f12e8e | 225 | udp_server.sendTo( udp_client, "\n\r>", strlen( "\n\r>" ) ); |
klauss | 48:195c97f12e8e | 226 | } |
klauss | 19:ab2088e0dec6 | 227 | } |
klauss | 19:ab2088e0dec6 | 228 | |
klauss | 19:ab2088e0dec6 | 229 | if (type == 'c' ){ // close all files |
klauss | 28:94aec56c6329 | 230 | fclose( fip ); |
klauss | 28:94aec56c6329 | 231 | fclose( fmask ); |
klauss | 28:94aec56c6329 | 232 | fclose( fgate ); |
klauss | 28:94aec56c6329 | 233 | fclose( fport ); |
klauss | 28:94aec56c6329 | 234 | fclose( fsip ); |
klauss | 28:94aec56c6329 | 235 | fclose( fsport ); |
klauss | 28:94aec56c6329 | 236 | fclose( fext ); |
klauss | 28:94aec56c6329 | 237 | fclose( fserext ); |
klauss | 45:c80574f24dc3 | 238 | fclose( fudpport ); |
klauss | 45:c80574f24dc3 | 239 | fclose( ftcpport ); |
klauss | 19:ab2088e0dec6 | 240 | } |
klauss | 19:ab2088e0dec6 | 241 | |
klauss | 19:ab2088e0dec6 | 242 | if (type == 'i' ){ // Check if files exist, if not create the files |
klauss | 33:735fd60e96d8 | 243 | bool exists = true; |
klauss | 19:ab2088e0dec6 | 244 | fip = fopen("/qspi/myip.txt", "r"); |
klauss | 19:ab2088e0dec6 | 245 | if (fip == NULL){ |
klauss | 19:ab2088e0dec6 | 246 | fip = fopen("/qspi/myip.txt", "w"); |
klauss | 29:7246460b73f8 | 247 | //fprintf(fip, "%s\n\r",__MY_IP__); //myip |
klauss | 46:a670f187a704 | 248 | fprintf(fip, "%s\n\r",__MY_IP__); //myip |
klauss | 33:735fd60e96d8 | 249 | exists = false; |
klauss | 19:ab2088e0dec6 | 250 | } |
klauss | 28:94aec56c6329 | 251 | |
klauss | 28:94aec56c6329 | 252 | fserext = fopen("/qspi/myext.txt", "r"); |
klauss | 28:94aec56c6329 | 253 | if ( fserext == NULL ){ |
klauss | 28:94aec56c6329 | 254 | fserext = fopen("/qspi/myext.txt", "w"); |
klauss | 38:af5ecd6997ab | 255 | fprintf( fserext, "%i\n\r" ,__MY_EXT__ ); //asterisk ext |
klauss | 33:735fd60e96d8 | 256 | exists = false; |
klauss | 28:94aec56c6329 | 257 | } |
klauss | 28:94aec56c6329 | 258 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 28:94aec56c6329 | 259 | if (fport == NULL){ |
klauss | 28:94aec56c6329 | 260 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 38:af5ecd6997ab | 261 | fprintf(fport, "%i\n\r",__MY_PORT__); //mysipport |
klauss | 33:735fd60e96d8 | 262 | exists = false; |
klauss | 28:94aec56c6329 | 263 | } |
klauss | 28:94aec56c6329 | 264 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 28:94aec56c6329 | 265 | if (fsip == NULL){ |
klauss | 28:94aec56c6329 | 266 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 29:7246460b73f8 | 267 | //fprintf(fsip, "%s\n\r",__SERVER_IP__ ); //asterisk ip |
klauss | 46:a670f187a704 | 268 | fprintf(fsip, "%s\n\r",__SERVER_IP__ ); //asterisk ip |
klauss | 33:735fd60e96d8 | 269 | exists = false; |
klauss | 28:94aec56c6329 | 270 | } |
klauss | 28:94aec56c6329 | 271 | |
klauss | 28:94aec56c6329 | 272 | fext = fopen("/qspi/peerext.txt", "r"); |
klauss | 28:94aec56c6329 | 273 | if ( fext == NULL ){ |
klauss | 28:94aec56c6329 | 274 | fext = fopen("/qspi/peerext.txt", "w"); |
klauss | 38:af5ecd6997ab | 275 | fprintf( fext, "%i\n\r",__PEER_EXT__ ); //asterisk ip |
klauss | 33:735fd60e96d8 | 276 | exists = false; |
klauss | 28:94aec56c6329 | 277 | } |
klauss | 28:94aec56c6329 | 278 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 28:94aec56c6329 | 279 | if (fsport == NULL){ |
klauss | 28:94aec56c6329 | 280 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 38:af5ecd6997ab | 281 | fprintf(fsport, "%i\n\r",__SERVER_PORT__ ); //asterisk port |
klauss | 33:735fd60e96d8 | 282 | exists = false; |
klauss | 28:94aec56c6329 | 283 | } |
klauss | 28:94aec56c6329 | 284 | |
klauss | 19:ab2088e0dec6 | 285 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 19:ab2088e0dec6 | 286 | if (fmask == NULL){ |
klauss | 19:ab2088e0dec6 | 287 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 46:a670f187a704 | 288 | fprintf(fmask, "%s\n\r",__MY_MSK__); //mymask |
klauss | 33:735fd60e96d8 | 289 | exists = false; |
klauss | 19:ab2088e0dec6 | 290 | } |
klauss | 19:ab2088e0dec6 | 291 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 19:ab2088e0dec6 | 292 | if (fgate == NULL){ |
klauss | 19:ab2088e0dec6 | 293 | fgate = fopen("/qspi/mygate.txt", "w"); |
klauss | 46:a670f187a704 | 294 | fprintf(fgate, "%s\n\r",__MY_GTW__); //mygateway |
klauss | 45:c80574f24dc3 | 295 | exists = false; |
klauss | 45:c80574f24dc3 | 296 | } |
klauss | 45:c80574f24dc3 | 297 | fudpport = fopen("/qspi/udpport.txt", "r" ); |
klauss | 45:c80574f24dc3 | 298 | if( fudpport == NULL ){ |
klauss | 45:c80574f24dc3 | 299 | fudpport = fopen("/qspi/udpport.txt", "w"); |
klauss | 45:c80574f24dc3 | 300 | fprintf( fudpport, "%i\n\r",UDP_PORT_LISTENER ); |
klauss | 45:c80574f24dc3 | 301 | exists = false; |
klauss | 45:c80574f24dc3 | 302 | } |
klauss | 45:c80574f24dc3 | 303 | ftcpport = fopen("/qspi/tcpport.txt", "r" ); |
klauss | 45:c80574f24dc3 | 304 | if( ftcpport == NULL ){ |
klauss | 45:c80574f24dc3 | 305 | ftcpport = fopen("/qspi/tcpport.txt", "w"); |
klauss | 45:c80574f24dc3 | 306 | fprintf( ftcpport, "%i\n\r", TCP_PORT_LISTENER ); |
klauss | 33:735fd60e96d8 | 307 | exists = false; |
klauss | 19:ab2088e0dec6 | 308 | } |
klauss | 44:cc4996469404 | 309 | if( !exists ){ |
klauss | 44:cc4996469404 | 310 | pc.printf("\n\rDefault configurations set!\n\r"); |
klauss | 44:cc4996469404 | 311 | if( from_eth ){ |
klauss | 44:cc4996469404 | 312 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Default configurations set!\n\r"); |
klauss | 44:cc4996469404 | 313 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 44:cc4996469404 | 314 | if( tcp_session ){ |
klauss | 45:c80574f24dc3 | 315 | tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 44:cc4996469404 | 316 | debug_buf[ 0 ] = 0; |
klauss | 44:cc4996469404 | 317 | bufptr = 0; |
klauss | 44:cc4996469404 | 318 | } |
klauss | 44:cc4996469404 | 319 | } |
klauss | 44:cc4996469404 | 320 | } |
klauss | 19:ab2088e0dec6 | 321 | } |
klauss | 19:ab2088e0dec6 | 322 | |
klauss | 19:ab2088e0dec6 | 323 | if (type == 'r' ){ // Just open for read |
klauss | 19:ab2088e0dec6 | 324 | fip = fopen("/qspi/myip.txt", "r"); |
klauss | 19:ab2088e0dec6 | 325 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 19:ab2088e0dec6 | 326 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 19:ab2088e0dec6 | 327 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 19:ab2088e0dec6 | 328 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 19:ab2088e0dec6 | 329 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 28:94aec56c6329 | 330 | fext = fopen( "/qspi/myext.txt", "r" ); |
klauss | 28:94aec56c6329 | 331 | fserext = fopen( "/qspi/peerext.txt", "r" ); |
klauss | 45:c80574f24dc3 | 332 | fudpport = fopen( "/qspi/udpport.txt", "r" ); |
klauss | 45:c80574f24dc3 | 333 | ftcpport = fopen( "/qspi/tcpport.txt", "r" ); |
klauss | 19:ab2088e0dec6 | 334 | } |
klauss | 19:ab2088e0dec6 | 335 | |
klauss | 50:d9b6577a70f5 | 336 | if( type == 'w'){ // Create and write the default configs |
klauss | 19:ab2088e0dec6 | 337 | fip = fopen("/qspi/myip.txt", "w"); |
klauss | 19:ab2088e0dec6 | 338 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 19:ab2088e0dec6 | 339 | fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 19:ab2088e0dec6 | 340 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 19:ab2088e0dec6 | 341 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 19:ab2088e0dec6 | 342 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 28:94aec56c6329 | 343 | fext = fopen( "/qspi/myext.txt", "w" ); |
klauss | 28:94aec56c6329 | 344 | fserext = fopen( "/qspi/peerext.txt", "w" ); |
klauss | 45:c80574f24dc3 | 345 | fudpport = fopen( "/qspi/udpport.txt", "w" ); |
klauss | 45:c80574f24dc3 | 346 | ftcpport = fopen( "/qspi/tcpport.txt", "w" ); |
klauss | 19:ab2088e0dec6 | 347 | |
klauss | 46:a670f187a704 | 348 | fprintf( fip, "%s\n\r", __MY_IP__ ); //myip |
klauss | 45:c80574f24dc3 | 349 | fprintf( fport, "%i\n\r", __MY_PORT__ ); //mysipport // isso pode dar pala |
klauss | 38:af5ecd6997ab | 350 | fprintf( fext, "%i\n\r", __MY_EXT__ ); //myext |
klauss | 28:94aec56c6329 | 351 | |
klauss | 46:a670f187a704 | 352 | fprintf( fsip, "%s\n\r", __SERVER_IP__ ); //asterisk ip |
klauss | 38:af5ecd6997ab | 353 | fprintf( fserext, "%i\n\r",__PEER_EXT__ ); //asterisk port |
klauss | 38:af5ecd6997ab | 354 | fprintf( fsport, "%i\n\r",__SERVER_PORT__ ); //asterisk port |
klauss | 28:94aec56c6329 | 355 | |
klauss | 46:a670f187a704 | 356 | fprintf( fmask, "%s\n\r",__MY_MSK__ ); //mymask |
klauss | 44:cc4996469404 | 357 | fprintf( fgate, "%s\n\r", __MY_GTW__ ); //mygateway |
klauss | 19:ab2088e0dec6 | 358 | |
klauss | 45:c80574f24dc3 | 359 | fprintf( fudpport, "%i\n\r",UDP_PORT_LISTENER ); |
klauss | 45:c80574f24dc3 | 360 | fprintf( ftcpport, "%i\n\r",TCP_PORT_LISTENER ); |
klauss | 45:c80574f24dc3 | 361 | |
klauss | 19:ab2088e0dec6 | 362 | files('c'); |
klauss | 19:ab2088e0dec6 | 363 | |
klauss | 44:cc4996469404 | 364 | pc.printf("\n\rDefault configurations set!\n\r"); |
klauss | 44:cc4996469404 | 365 | if( from_eth ){ |
klauss | 44:cc4996469404 | 366 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rDefault configurations set!\n\r"); |
klauss | 44:cc4996469404 | 367 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 44:cc4996469404 | 368 | if( tcp_session ){ |
klauss | 45:c80574f24dc3 | 369 | tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 370 | }else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 371 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 44:cc4996469404 | 372 | } |
klauss | 45:c80574f24dc3 | 373 | debug_buf[ 0 ] = 0; |
klauss | 45:c80574f24dc3 | 374 | bufptr = 0; |
klauss | 44:cc4996469404 | 375 | } |
klauss | 19:ab2088e0dec6 | 376 | } |
klauss | 50:d9b6577a70f5 | 377 | |
klauss | 50:d9b6577a70f5 | 378 | if (type == 'e'){ // Create and write the default configs |
klauss | 50:d9b6577a70f5 | 379 | fip = fopen("/qspi/myip.txt", "w"); |
klauss | 50:d9b6577a70f5 | 380 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 50:d9b6577a70f5 | 381 | fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 50:d9b6577a70f5 | 382 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 50:d9b6577a70f5 | 383 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 50:d9b6577a70f5 | 384 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 50:d9b6577a70f5 | 385 | fext = fopen( "/qspi/myext.txt", "w" ); |
klauss | 50:d9b6577a70f5 | 386 | fserext = fopen( "/qspi/peerext.txt", "w" ); |
klauss | 50:d9b6577a70f5 | 387 | fudpport = fopen( "/qspi/udpport.txt", "w" ); |
klauss | 50:d9b6577a70f5 | 388 | ftcpport = fopen( "/qspi/tcpport.txt", "w" ); |
klauss | 50:d9b6577a70f5 | 389 | |
klauss | 50:d9b6577a70f5 | 390 | fprintf( fip, "%s\n\r", "" ); //myip |
klauss | 50:d9b6577a70f5 | 391 | fprintf( fport, "%i\n\r", "" ); //mysipport // isso pode dar pala |
klauss | 50:d9b6577a70f5 | 392 | fprintf( fext, "%i\n\r", "" ); //myext |
klauss | 50:d9b6577a70f5 | 393 | |
klauss | 50:d9b6577a70f5 | 394 | fprintf( fsip, "%s\n\r", "" ); //asterisk ip |
klauss | 50:d9b6577a70f5 | 395 | fprintf( fserext, "%i\n\r","" ); //asterisk port |
klauss | 50:d9b6577a70f5 | 396 | fprintf( fsport, "%i\n\r","" ); //asterisk port |
klauss | 50:d9b6577a70f5 | 397 | |
klauss | 50:d9b6577a70f5 | 398 | fprintf( fmask, "%s\n\r","" ); //mymask |
klauss | 50:d9b6577a70f5 | 399 | fprintf( fgate, "%s\n\r", "" ); //mygateway |
klauss | 50:d9b6577a70f5 | 400 | |
klauss | 50:d9b6577a70f5 | 401 | fprintf( fudpport, "%i\n\r","" ); |
klauss | 50:d9b6577a70f5 | 402 | fprintf( ftcpport, "%i\n\r","" ); |
klauss | 50:d9b6577a70f5 | 403 | |
klauss | 50:d9b6577a70f5 | 404 | files('c'); |
klauss | 50:d9b6577a70f5 | 405 | |
klauss | 50:d9b6577a70f5 | 406 | pc.printf("\n\rErased configurations set!\n\r"); |
klauss | 50:d9b6577a70f5 | 407 | if( from_eth ){ |
klauss | 50:d9b6577a70f5 | 408 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rErased configurations set!\n\r"); |
klauss | 50:d9b6577a70f5 | 409 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 50:d9b6577a70f5 | 410 | if( tcp_session ){ |
klauss | 50:d9b6577a70f5 | 411 | tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 50:d9b6577a70f5 | 412 | }else if( udp_request ){ |
klauss | 50:d9b6577a70f5 | 413 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 50:d9b6577a70f5 | 414 | } |
klauss | 50:d9b6577a70f5 | 415 | debug_buf[ 0 ] = 0; |
klauss | 50:d9b6577a70f5 | 416 | bufptr = 0; |
klauss | 50:d9b6577a70f5 | 417 | } |
klauss | 50:d9b6577a70f5 | 418 | } |
klauss | 19:ab2088e0dec6 | 419 | } |
klauss | 26:725cbbedadd5 | 420 | void init_fsystem(){ |
klauss | 26:725cbbedadd5 | 421 | // init file system and check if files exist |
klauss | 26:725cbbedadd5 | 422 | if (!qspifs.isformatted()) { |
klauss | 26:725cbbedadd5 | 423 | qspifs.format(); |
klauss | 44:cc4996469404 | 424 | pc.printf("\n\rFile system configured!!\n\r"); |
klauss | 26:725cbbedadd5 | 425 | } |
klauss | 26:725cbbedadd5 | 426 | files('i'); // check if the files are created |
klauss | 26:725cbbedadd5 | 427 | files('c'); |
klauss | 44:cc4996469404 | 428 | pc.printf("\n\r*******File System Ready*******\n\r"); |
klauss | 43:455522f98de5 | 429 | } |
klauss | 43:455522f98de5 | 430 | |
klauss | 43:455522f98de5 | 431 | void init_prompt(){ |
klauss | 45:c80574f24dc3 | 432 | tcp_server.bind( TCP_PORT_LISTENER ); |
klauss | 45:c80574f24dc3 | 433 | tcp_server.listen(); |
klauss | 53:bb492a8f115a | 434 | //tcp_timer.start(); |
klauss | 45:c80574f24dc3 | 435 | tcp_server.set_blocking( false, 1 ); |
klauss | 45:c80574f24dc3 | 436 | |
klauss | 45:c80574f24dc3 | 437 | udp_server.set_blocking( false, 2 ); |
klauss | 45:c80574f24dc3 | 438 | udp_server.bind( UDP_PORT_LISTENER ); |
klauss | 45:c80574f24dc3 | 439 | |
klauss | 43:455522f98de5 | 440 | pc.printf("*******Prompt eth Ready*******\n\r"); |
klauss | 19:ab2088e0dec6 | 441 | } |
klauss | 19:ab2088e0dec6 | 442 | |
klauss | 28:94aec56c6329 | 443 | // main prompt process |
klauss | 48:195c97f12e8e | 444 | char * prompt_process( char * msg_from_cb ){ |
klauss | 28:94aec56c6329 | 445 | //FIXME dar flush na serial |
klauss | 19:ab2088e0dec6 | 446 | volatile char b = 0; |
klauss | 19:ab2088e0dec6 | 447 | static uint8_t bufret = 0; |
klauss | 30:8dfb6d8de53d | 448 | static Timer flood_timeout; |
klauss | 36:728498a78e1e | 449 | bool miss_match = true; |
klauss | 53:bb492a8f115a | 450 | char eth_buffer[ 1024 ]; |
klauss | 45:c80574f24dc3 | 451 | if( flood_timeout.read() > 60 ){ |
klauss | 45:c80574f24dc3 | 452 | pflood = 0; |
klauss | 45:c80574f24dc3 | 453 | flood_timeout.stop(); |
klauss | 45:c80574f24dc3 | 454 | flood_timeout.reset(); |
klauss | 45:c80574f24dc3 | 455 | } |
klauss | 53:bb492a8f115a | 456 | if( tcp_timer.read() >= TCP_IDLE_MAX_TIME ){ |
klauss | 53:bb492a8f115a | 457 | tcp_timer.stop(); |
klauss | 53:bb492a8f115a | 458 | tcp_timer.reset(); |
klauss | 53:bb492a8f115a | 459 | tcp_session = false; |
klauss | 53:bb492a8f115a | 460 | debug_buf = __debug_buf__; |
klauss | 53:bb492a8f115a | 461 | bufptr = last_bufptr; |
klauss | 53:bb492a8f115a | 462 | bufret = 0; |
klauss | 53:bb492a8f115a | 463 | from_eth = false; |
klauss | 53:bb492a8f115a | 464 | tcp_client.close(); |
klauss | 53:bb492a8f115a | 465 | return( NULL ); |
klauss | 53:bb492a8f115a | 466 | } |
klauss | 48:195c97f12e8e | 467 | if( !tcp_server.accept( tcp_client ) ){ |
klauss | 48:195c97f12e8e | 468 | tcp_session = true; |
klauss | 53:bb492a8f115a | 469 | tcp_timer.start(); |
klauss | 48:195c97f12e8e | 470 | last_bufptr = bufptr; |
klauss | 53:bb492a8f115a | 471 | eth_buffer[ 0 ] = 0; |
klauss | 48:195c97f12e8e | 472 | bufret = 0; |
klauss | 48:195c97f12e8e | 473 | } |
klauss | 48:195c97f12e8e | 474 | wdt.kick(); |
klauss | 53:bb492a8f115a | 475 | if( tcp_session ){ |
klauss | 53:bb492a8f115a | 476 | if( !( (int)tcp_timer.read_ms() % 100 ) ){ |
klauss | 53:bb492a8f115a | 477 | tcp_client.set_blocking( false, 1 ); |
klauss | 53:bb492a8f115a | 478 | int n = tcp_client.receive( eth_buffer, sizeof( eth_buffer ) - 1 ); |
klauss | 53:bb492a8f115a | 479 | if( n > 0 ){ |
klauss | 48:195c97f12e8e | 480 | tcp_timer.reset(); |
klauss | 53:bb492a8f115a | 481 | |
klauss | 53:bb492a8f115a | 482 | if( ( n > 2 ) && ( eth_buffer[ n - 2 ] == '\r' ) ) eth_buffer[ n - 2 ] = 0; |
klauss | 53:bb492a8f115a | 483 | |
klauss | 53:bb492a8f115a | 484 | if( ( n > 1 ) && ( eth_buffer[ n - 1 ] == '\n' ) ) eth_buffer[ n - 1 ] = 0; |
klauss | 53:bb492a8f115a | 485 | |
klauss | 53:bb492a8f115a | 486 | if( ( n == 1 ) && eth_buffer[ 0 ] == 0x0A ) strcpy( eth_buffer, "\r" ); |
klauss | 53:bb492a8f115a | 487 | |
klauss | 53:bb492a8f115a | 488 | //if( eth_buffer[ 0 ] == '\r' || eth_buffer[ 1 ] == '\n' || eth_buffer[ 2 ] == 'r' || eth_buffer[ 2 ] == '\n' ) strcpy( eth_buffer, "\r" ); |
klauss | 53:bb492a8f115a | 489 | |
klauss | 53:bb492a8f115a | 490 | bufptr = strlen( eth_buffer ); |
klauss | 53:bb492a8f115a | 491 | debug_buf = eth_buffer; |
klauss | 53:bb492a8f115a | 492 | from_eth = true; |
klauss | 53:bb492a8f115a | 493 | bufret = 1; |
klauss | 53:bb492a8f115a | 494 | |
klauss | 53:bb492a8f115a | 495 | if( !( strcmp( eth_buffer, "quit" ) ) ){ |
klauss | 53:bb492a8f115a | 496 | tcp_timer.reset(); |
klauss | 53:bb492a8f115a | 497 | debug_buf = __debug_buf__; |
klauss | 53:bb492a8f115a | 498 | bufptr = last_bufptr; |
klauss | 53:bb492a8f115a | 499 | from_eth = false; |
klauss | 53:bb492a8f115a | 500 | tcp_session = false; |
klauss | 53:bb492a8f115a | 501 | tcp_client.close(); |
klauss | 53:bb492a8f115a | 502 | bufret = 0; |
klauss | 53:bb492a8f115a | 503 | return( NULL ); |
klauss | 53:bb492a8f115a | 504 | } |
klauss | 53:bb492a8f115a | 505 | }else{ |
klauss | 48:195c97f12e8e | 506 | debug_buf = __debug_buf__; |
klauss | 48:195c97f12e8e | 507 | bufptr = last_bufptr; |
klauss | 45:c80574f24dc3 | 508 | } |
klauss | 53:bb492a8f115a | 509 | }/*else{ if( !tcp_session ){ |
klauss | 53:bb492a8f115a | 510 | int n = udp_server.receiveFrom( udp_client, buffer, __PROMPT_ETH_BUFFER_SIZE__ - 1 ); |
klauss | 53:bb492a8f115a | 511 | if( n > 0){ |
klauss | 53:bb492a8f115a | 512 | if( ( n > 2 ) && ( buffer[ n - 2 ] == '\r' ) ) buffer[ n - 2 ] = 0; |
klauss | 53:bb492a8f115a | 513 | |
klauss | 53:bb492a8f115a | 514 | if( ( n > 1 ) && ( buffer[ n - 1 ] == '\n' ) ) buffer[ n - 1 ] = 0; |
klauss | 53:bb492a8f115a | 515 | |
klauss | 53:bb492a8f115a | 516 | if( n == 1 && buffer[ 0 ] == 0x0A ){ strcpy( buffer, "\r" ); } |
klauss | 48:195c97f12e8e | 517 | |
klauss | 53:bb492a8f115a | 518 | last_bufptr = bufptr; |
klauss | 53:bb492a8f115a | 519 | bufptr = strlen( buffer ); |
klauss | 53:bb492a8f115a | 520 | debug_buf = buffer; |
klauss | 53:bb492a8f115a | 521 | from_eth = true; |
klauss | 53:bb492a8f115a | 522 | udp_request = true; |
klauss | 53:bb492a8f115a | 523 | bufret = 1; |
klauss | 53:bb492a8f115a | 524 | } |
klauss | 53:bb492a8f115a | 525 | }*/ |
klauss | 53:bb492a8f115a | 526 | } |
klauss | 53:bb492a8f115a | 527 | if( !from_eth ){ |
klauss | 53:bb492a8f115a | 528 | if ( pc.readable() ){ |
klauss | 53:bb492a8f115a | 529 | // imput do teclado |
klauss | 53:bb492a8f115a | 530 | b = pc.getc(); |
klauss | 48:195c97f12e8e | 531 | |
klauss | 53:bb492a8f115a | 532 | if( b == 0x0D ){ // enter |
klauss | 53:bb492a8f115a | 533 | bufret = 1; |
klauss | 53:bb492a8f115a | 534 | }else{ |
klauss | 53:bb492a8f115a | 535 | pc.putc( b ); |
klauss | 53:bb492a8f115a | 536 | if( b == 0x08 || b == 0x7F ){ // BS | DEL |
klauss | 53:bb492a8f115a | 537 | if( bufptr > 0 ) debug_buf[ --bufptr ] = 0; |
klauss | 53:bb492a8f115a | 538 | }else if( b == 0x09 ){ |
klauss | 53:bb492a8f115a | 539 | // ignore tab |
klauss | 53:bb492a8f115a | 540 | }else{ |
klauss | 53:bb492a8f115a | 541 | debug_buf[bufptr] = b; |
klauss | 53:bb492a8f115a | 542 | bufptr++; |
klauss | 42:480335bdde12 | 543 | } |
klauss | 31:bb5fb28a77df | 544 | } |
klauss | 53:bb492a8f115a | 545 | } |
klauss | 48:195c97f12e8e | 546 | } |
klauss | 53:bb492a8f115a | 547 | |
klauss | 48:195c97f12e8e | 548 | if( msg_from_cb ){ |
klauss | 48:195c97f12e8e | 549 | if( tcp_session ){ |
klauss | 48:195c97f12e8e | 550 | tcp_client.send_all( msg_from_cb, strlen( msg_from_cb ) ); |
klauss | 48:195c97f12e8e | 551 | }else if( udp_request ){ |
klauss | 48:195c97f12e8e | 552 | udp_server.sendTo( udp_client, msg_from_cb, strlen( msg_from_cb ) ); |
klauss | 48:195c97f12e8e | 553 | } |
klauss | 48:195c97f12e8e | 554 | pc.printf( "\n\r%s\n\r", msg_from_cb ); |
klauss | 45:c80574f24dc3 | 555 | } |
klauss | 45:c80574f24dc3 | 556 | |
klauss | 45:c80574f24dc3 | 557 | // Prompt commands here |
klauss | 45:c80574f24dc3 | 558 | if ( bufret == 1 ) { |
klauss | 45:c80574f24dc3 | 559 | static unsigned int promptcb_last_ext = 0; |
klauss | 45:c80574f24dc3 | 560 | static unsigned int promptcb_last_port = 0; |
klauss | 45:c80574f24dc3 | 561 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) ".",1 )) { |
klauss | 45:c80574f24dc3 | 562 | miss_match = false; |
klauss | 45:c80574f24dc3 | 563 | strcpy( debug_buf, last_debug_buf ); |
klauss | 45:c80574f24dc3 | 564 | } |
klauss | 45:c80574f24dc3 | 565 | |
klauss | 48:195c97f12e8e | 566 | //tratamento dos enters |
klauss | 45:c80574f24dc3 | 567 | if( !bufptr ){ |
klauss | 45:c80574f24dc3 | 568 | miss_match = false; |
klauss | 48:195c97f12e8e | 569 | }else if( bufptr == 1 ) { |
klauss | 48:195c97f12e8e | 570 | if( debug_buf[ 0 ] == 0x0D || debug_buf[ 0 ] == 0x0D ) miss_match = false; |
klauss | 48:195c97f12e8e | 571 | } |
klauss | 48:195c97f12e8e | 572 | |
klauss | 45:c80574f24dc3 | 573 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ifconfig" ) ){ |
klauss | 45:c80574f24dc3 | 574 | miss_match = false; |
klauss | 45:c80574f24dc3 | 575 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 576 | files('s'); |
klauss | 45:c80574f24dc3 | 577 | } |
klauss | 45:c80574f24dc3 | 578 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "format" ) ){ |
klauss | 45:c80574f24dc3 | 579 | miss_match = false; |
klauss | 50:d9b6577a70f5 | 580 | pc.printf("\n\rFormatando o sistema de arquivos... espere o sistema reiniciar\n\r"); |
klauss | 45:c80574f24dc3 | 581 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 582 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Formatando o sistema de arquivos... espere o sistema reiniciar\n\r"); |
klauss | 45:c80574f24dc3 | 583 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 584 | if( tcp_session ){ |
klauss | 45:c80574f24dc3 | 585 | tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 586 | tcp_client.close(); |
klauss | 45:c80574f24dc3 | 587 | }else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 588 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 42:480335bdde12 | 589 | } |
klauss | 42:480335bdde12 | 590 | } |
klauss | 50:d9b6577a70f5 | 591 | files('e'); |
klauss | 45:c80574f24dc3 | 592 | files('w'); |
klauss | 48:195c97f12e8e | 593 | __disable_irq(); |
klauss | 45:c80574f24dc3 | 594 | NVIC_SystemReset(); |
klauss | 45:c80574f24dc3 | 595 | } |
klauss | 45:c80574f24dc3 | 596 | |
klauss | 45:c80574f24dc3 | 597 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ipset ", 6 )) { |
klauss | 45:c80574f24dc3 | 598 | miss_match = false; |
klauss | 45:c80574f24dc3 | 599 | fip = fopen("/qspi/myip.txt", "w"); |
klauss | 46:a670f187a704 | 600 | fprintf(fip,"%s\n\r",(debug_buf+6)); |
klauss | 45:c80574f24dc3 | 601 | fclose(fip); |
klauss | 45:c80574f24dc3 | 602 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 603 | files('s'); |
klauss | 45:c80574f24dc3 | 604 | } |
klauss | 45:c80574f24dc3 | 605 | |
klauss | 45:c80574f24dc3 | 606 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "extset ", 7 ) ){ |
klauss | 45:c80574f24dc3 | 607 | miss_match = false; |
klauss | 45:c80574f24dc3 | 608 | fip = fopen("/qspi/myext.txt", "w"); |
klauss | 48:195c97f12e8e | 609 | fprintf(fip, "%s\n\r" , ( debug_buf + 7) ); |
klauss | 45:c80574f24dc3 | 610 | fclose(fip); |
klauss | 45:c80574f24dc3 | 611 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 612 | files('s'); |
klauss | 45:c80574f24dc3 | 613 | } |
klauss | 45:c80574f24dc3 | 614 | |
klauss | 45:c80574f24dc3 | 615 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serextset ", 10 ) ){ |
klauss | 45:c80574f24dc3 | 616 | miss_match = false; |
klauss | 45:c80574f24dc3 | 617 | fip = fopen("/qspi/peerext.txt", "w"); |
klauss | 45:c80574f24dc3 | 618 | fprintf(fip, "%i\n\r" , ( debug_buf + 10 ) ); |
klauss | 45:c80574f24dc3 | 619 | fclose(fip); |
klauss | 45:c80574f24dc3 | 620 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 621 | files('s'); |
klauss | 45:c80574f24dc3 | 622 | } |
klauss | 45:c80574f24dc3 | 623 | |
klauss | 45:c80574f24dc3 | 624 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "maskset ",8 ) ){ |
klauss | 45:c80574f24dc3 | 625 | miss_match = false; |
klauss | 45:c80574f24dc3 | 626 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 46:a670f187a704 | 627 | fprintf(fmask,"%s\n\r",(debug_buf+8)); |
klauss | 45:c80574f24dc3 | 628 | fclose(fmask); |
klauss | 45:c80574f24dc3 | 629 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 630 | files('s'); |
klauss | 45:c80574f24dc3 | 631 | } |
klauss | 45:c80574f24dc3 | 632 | |
klauss | 45:c80574f24dc3 | 633 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "gatewayset ",11 ) ){ |
klauss | 45:c80574f24dc3 | 634 | miss_match = false; |
klauss | 45:c80574f24dc3 | 635 | fgate = fopen("/qspi/mygate.txt", "w"); |
klauss | 46:a670f187a704 | 636 | fprintf(fgate,"%s\n\r",(debug_buf+11)); |
klauss | 45:c80574f24dc3 | 637 | fclose(fgate); |
klauss | 45:c80574f24dc3 | 638 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 639 | files('s'); |
klauss | 45:c80574f24dc3 | 640 | } |
klauss | 45:c80574f24dc3 | 641 | |
klauss | 45:c80574f24dc3 | 642 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "msipport ",9 ) ){ |
klauss | 45:c80574f24dc3 | 643 | miss_match = false; |
klauss | 45:c80574f24dc3 | 644 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 45:c80574f24dc3 | 645 | fprintf(fport,"%i\n\r",(debug_buf+9)); |
klauss | 45:c80574f24dc3 | 646 | fclose(fport); |
klauss | 45:c80574f24dc3 | 647 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 648 | files('s'); |
klauss | 45:c80574f24dc3 | 649 | } |
klauss | 45:c80574f24dc3 | 650 | |
klauss | 45:c80574f24dc3 | 651 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serverip ",9 ) ){ |
klauss | 45:c80574f24dc3 | 652 | miss_match = false; |
klauss | 45:c80574f24dc3 | 653 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 46:a670f187a704 | 654 | fprintf(fsip,"%s\n\r",(debug_buf+9)); |
klauss | 45:c80574f24dc3 | 655 | fclose(fsip); |
klauss | 45:c80574f24dc3 | 656 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 657 | files('s'); |
klauss | 45:c80574f24dc3 | 658 | } |
klauss | 45:c80574f24dc3 | 659 | |
klauss | 45:c80574f24dc3 | 660 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ssport ",7 ) ){ |
klauss | 45:c80574f24dc3 | 661 | miss_match = false; |
klauss | 45:c80574f24dc3 | 662 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 45:c80574f24dc3 | 663 | fprintf(fsport,"%i\n\r",(debug_buf+7)); |
klauss | 45:c80574f24dc3 | 664 | fclose(fsport); |
klauss | 45:c80574f24dc3 | 665 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 666 | files('s'); |
klauss | 45:c80574f24dc3 | 667 | } |
klauss | 45:c80574f24dc3 | 668 | |
klauss | 45:c80574f24dc3 | 669 | |
klauss | 45:c80574f24dc3 | 670 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dconfig" ) ){ |
klauss | 45:c80574f24dc3 | 671 | miss_match = false; |
klauss | 50:d9b6577a70f5 | 672 | files('e'); |
klauss | 45:c80574f24dc3 | 673 | files('w'); |
klauss | 45:c80574f24dc3 | 674 | files('s'); |
klauss | 45:c80574f24dc3 | 675 | } |
klauss | 45:c80574f24dc3 | 676 | |
klauss | 45:c80574f24dc3 | 677 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset" ) ){ |
klauss | 45:c80574f24dc3 | 678 | miss_match = false; |
klauss | 45:c80574f24dc3 | 679 | pc.printf("\n\rJob is done\n\r"); |
klauss | 45:c80574f24dc3 | 680 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 681 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Job is done\n\r"); |
klauss | 45:c80574f24dc3 | 682 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 683 | if( tcp_session ){ |
klauss | 45:c80574f24dc3 | 684 | tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 685 | tcp_client.close(); |
klauss | 45:c80574f24dc3 | 686 | }else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 687 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 42:480335bdde12 | 688 | } |
klauss | 45:c80574f24dc3 | 689 | } |
klauss | 48:195c97f12e8e | 690 | __disable_irq(); |
klauss | 45:c80574f24dc3 | 691 | NVIC_SystemReset(); |
klauss | 45:c80574f24dc3 | 692 | } |
klauss | 45:c80574f24dc3 | 693 | |
klauss | 45:c80574f24dc3 | 694 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dog" ) ){ |
klauss | 45:c80574f24dc3 | 695 | miss_match = false; |
klauss | 45:c80574f24dc3 | 696 | pc.printf("\n\r MUUUUUUUuuuuUUUUUU - I'm not a dog!!!! \n\r"); |
klauss | 45:c80574f24dc3 | 697 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 698 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "MUUUUUUUuuuuUUUUUU - I'm not a dog!!!!\n\r"); |
klauss | 45:c80574f24dc3 | 699 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 700 | } |
klauss | 45:c80574f24dc3 | 701 | } |
klauss | 48:195c97f12e8e | 702 | |
klauss | 53:bb492a8f115a | 703 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "tt" ) ){ |
klauss | 53:bb492a8f115a | 704 | miss_match = false; |
klauss | 53:bb492a8f115a | 705 | telemetry_test = true; |
klauss | 53:bb492a8f115a | 706 | } |
klauss | 53:bb492a8f115a | 707 | |
klauss | 53:bb492a8f115a | 708 | |
klauss | 52:12930cef17c4 | 709 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset_cks" ) ){ |
klauss | 52:12930cef17c4 | 710 | miss_match = false; |
klauss | 52:12930cef17c4 | 711 | reset_cks = true; |
klauss | 52:12930cef17c4 | 712 | } |
klauss | 52:12930cef17c4 | 713 | |
klauss | 52:12930cef17c4 | 714 | |
klauss | 52:12930cef17c4 | 715 | |
klauss | 48:195c97f12e8e | 716 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "status" ) ){ |
klauss | 48:195c97f12e8e | 717 | miss_match = false; |
klauss | 48:195c97f12e8e | 718 | cb_status = true; |
klauss | 48:195c97f12e8e | 719 | } |
klauss | 45:c80574f24dc3 | 720 | |
klauss | 45:c80574f24dc3 | 721 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "flood ",6 ) ){ |
klauss | 45:c80574f24dc3 | 722 | if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 ) ){ |
klauss | 45:c80574f24dc3 | 723 | miss_match = false; |
klauss | 46:a670f187a704 | 724 | pc.printf("\n\rFlood ON\n\r"); |
klauss | 42:480335bdde12 | 725 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 726 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood On\n\r" ); |
klauss | 45:c80574f24dc3 | 727 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 42:480335bdde12 | 728 | } |
klauss | 45:c80574f24dc3 | 729 | tflood.start(); |
klauss | 45:c80574f24dc3 | 730 | tflood.reset(); |
klauss | 45:c80574f24dc3 | 731 | floodcount =0; |
klauss | 45:c80574f24dc3 | 732 | pflood = 1; |
klauss | 45:c80574f24dc3 | 733 | flood_timeout.start(); |
klauss | 45:c80574f24dc3 | 734 | } |
klauss | 45:c80574f24dc3 | 735 | if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { |
klauss | 45:c80574f24dc3 | 736 | miss_match = false; |
klauss | 46:a670f187a704 | 737 | pc.printf("\n\rFlood OFF\n\r"); |
klauss | 42:480335bdde12 | 738 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 739 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood Off\n\r" ); |
klauss | 45:c80574f24dc3 | 740 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 42:480335bdde12 | 741 | } |
klauss | 45:c80574f24dc3 | 742 | pflood = 0; |
klauss | 45:c80574f24dc3 | 743 | tflood.stop(); |
klauss | 45:c80574f24dc3 | 744 | flood_timeout.reset(); |
klauss | 31:bb5fb28a77df | 745 | } |
klauss | 48:195c97f12e8e | 746 | if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "disable",3 )) { |
klauss | 48:195c97f12e8e | 747 | miss_match = false; |
klauss | 48:195c97f12e8e | 748 | // implementar uma logica que recebe start ext e end ext e manda flood off pra eles |
klauss | 48:195c97f12e8e | 749 | pc.printf("\n\rFlood OFF\n\r"); |
klauss | 48:195c97f12e8e | 750 | if( from_eth ){ |
klauss | 48:195c97f12e8e | 751 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood Off\n\r" ); |
klauss | 48:195c97f12e8e | 752 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 48:195c97f12e8e | 753 | } |
klauss | 48:195c97f12e8e | 754 | pflood = 0; |
klauss | 48:195c97f12e8e | 755 | tflood.stop(); |
klauss | 48:195c97f12e8e | 756 | flood_timeout.reset(); |
klauss | 48:195c97f12e8e | 757 | } |
klauss | 45:c80574f24dc3 | 758 | } |
klauss | 45:c80574f24dc3 | 759 | |
klauss | 45:c80574f24dc3 | 760 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug ",6 )) { |
klauss | 45:c80574f24dc3 | 761 | if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { |
klauss | 45:c80574f24dc3 | 762 | miss_match = false; |
klauss | 46:a670f187a704 | 763 | pc.printf("\n\rDebug ON\n\r"); |
klauss | 45:c80574f24dc3 | 764 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 765 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug On\n\r" ); |
klauss | 45:c80574f24dc3 | 766 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 767 | } |
klauss | 45:c80574f24dc3 | 768 | debug_alive = 1; |
klauss | 45:c80574f24dc3 | 769 | } |
klauss | 45:c80574f24dc3 | 770 | if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { |
klauss | 45:c80574f24dc3 | 771 | miss_match = false; |
klauss | 46:a670f187a704 | 772 | pc.printf("\n\rDebug OFF\n\r"); |
klauss | 45:c80574f24dc3 | 773 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 774 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Off\n\r" ); |
klauss | 45:c80574f24dc3 | 775 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 42:480335bdde12 | 776 | } |
klauss | 45:c80574f24dc3 | 777 | debug_alive = 0; |
klauss | 31:bb5fb28a77df | 778 | } |
klauss | 45:c80574f24dc3 | 779 | if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "show",4 ) ){ |
klauss | 45:c80574f24dc3 | 780 | miss_match = false; |
klauss | 50:d9b6577a70f5 | 781 | pc.printf("\n\rdsip"); |
klauss | 45:c80574f24dc3 | 782 | pc.printf("\n\rdebug_alive"); |
klauss | 45:c80574f24dc3 | 783 | pc.printf("\n\rdebug_prompt"); |
klauss | 45:c80574f24dc3 | 784 | pc.printf("\n\rdebug_vector"); |
klauss | 45:c80574f24dc3 | 785 | pc.printf("\n\rdebug_cb"); |
klauss | 45:c80574f24dc3 | 786 | pc.printf("\n\rdebug_main"); |
klauss | 45:c80574f24dc3 | 787 | pc.printf("\n\rdebug_cks"); |
klauss | 45:c80574f24dc3 | 788 | pc.printf("\n\rdebug_cb_rx"); |
klauss | 45:c80574f24dc3 | 789 | pc.printf("\n\rdebug_cb_tx*"); |
klauss | 45:c80574f24dc3 | 790 | pc.printf("\n\rdebug_eth_rx*"); |
klauss | 45:c80574f24dc3 | 791 | pc.printf("\n\rdebug_eth_tx*"); |
klauss | 45:c80574f24dc3 | 792 | pc.printf("\n\rdebug_file"); |
klauss | 45:c80574f24dc3 | 793 | |
klauss | 42:480335bdde12 | 794 | if( from_eth ){ |
klauss | 50:d9b6577a70f5 | 795 | 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 | 796 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 42:480335bdde12 | 797 | } |
klauss | 42:480335bdde12 | 798 | } |
klauss | 45:c80574f24dc3 | 799 | } |
klauss | 45:c80574f24dc3 | 800 | |
klauss | 50:d9b6577a70f5 | 801 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dsip ",5 ) ){ |
klauss | 50:d9b6577a70f5 | 802 | if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on",2 ) ){ |
klauss | 45:c80574f24dc3 | 803 | miss_match = false; |
klauss | 45:c80574f24dc3 | 804 | pc.printf( "\n\rSip Debug ON\n\r" ); |
klauss | 45:c80574f24dc3 | 805 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 806 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Sip Debug On\n\r" ); |
klauss | 45:c80574f24dc3 | 807 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 808 | } |
klauss | 45:c80574f24dc3 | 809 | debug_sip = 1; |
klauss | 45:c80574f24dc3 | 810 | } |
klauss | 50:d9b6577a70f5 | 811 | if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "off",3 )) { |
klauss | 45:c80574f24dc3 | 812 | miss_match = false; |
klauss | 45:c80574f24dc3 | 813 | pc.printf( "\n\rSip Debug OFF\n\r" ); |
klauss | 45:c80574f24dc3 | 814 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 815 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Sip Debug Off\n\r" ); |
klauss | 45:c80574f24dc3 | 816 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 817 | } |
klauss | 45:c80574f24dc3 | 818 | debug_sip = 0; |
klauss | 45:c80574f24dc3 | 819 | } |
klauss | 45:c80574f24dc3 | 820 | } |
klauss | 45:c80574f24dc3 | 821 | |
klauss | 53:bb492a8f115a | 822 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dtelemetry ", 11 ) ){ |
klauss | 53:bb492a8f115a | 823 | if (xmemmatch( (uint8_t*)(debug_buf + 11 ), (uint8_t*) "on",2 ) ){ |
klauss | 53:bb492a8f115a | 824 | miss_match = false; |
klauss | 53:bb492a8f115a | 825 | pc.printf( "\n\rTelemetry Debug ON\n\r" ); |
klauss | 53:bb492a8f115a | 826 | if( from_eth ){ |
klauss | 53:bb492a8f115a | 827 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "rTelemetry Debug On\n\r" ); |
klauss | 53:bb492a8f115a | 828 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 53:bb492a8f115a | 829 | } |
klauss | 53:bb492a8f115a | 830 | debug_telemetry = true; |
klauss | 53:bb492a8f115a | 831 | } |
klauss | 53:bb492a8f115a | 832 | if (xmemmatch( (uint8_t*)(debug_buf + 11 ), (uint8_t*) "off",3 )) { |
klauss | 53:bb492a8f115a | 833 | miss_match = false; |
klauss | 53:bb492a8f115a | 834 | pc.printf( "\n\rrTelemetry Debug OFF\n\r" ); |
klauss | 53:bb492a8f115a | 835 | if( from_eth ){ |
klauss | 53:bb492a8f115a | 836 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "rTelemetry Debug Off\n\r" ); |
klauss | 53:bb492a8f115a | 837 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 53:bb492a8f115a | 838 | } |
klauss | 53:bb492a8f115a | 839 | debug_telemetry = false; |
klauss | 53:bb492a8f115a | 840 | } |
klauss | 53:bb492a8f115a | 841 | } |
klauss | 53:bb492a8f115a | 842 | |
klauss | 45:c80574f24dc3 | 843 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cks ", 10 )) { |
klauss | 50:d9b6577a70f5 | 844 | if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on",2 )) { |
klauss | 45:c80574f24dc3 | 845 | miss_match = false; |
klauss | 45:c80574f24dc3 | 846 | pc.printf( "\n\rCKS Debug ON\n\r" ); |
klauss | 45:c80574f24dc3 | 847 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 848 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS Debug On\n\r" ); |
klauss | 45:c80574f24dc3 | 849 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 850 | } |
klauss | 45:c80574f24dc3 | 851 | debug_cks = 1; |
klauss | 45:c80574f24dc3 | 852 | } |
klauss | 50:d9b6577a70f5 | 853 | if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "off",3 )) { |
klauss | 45:c80574f24dc3 | 854 | miss_match = false; |
klauss | 45:c80574f24dc3 | 855 | pc.printf( "\n\rCKS Debug OFF\n\r" ); |
klauss | 45:c80574f24dc3 | 856 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 857 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS Debug Off\n\r" ); |
klauss | 45:c80574f24dc3 | 858 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 859 | } |
klauss | 45:c80574f24dc3 | 860 | debug_cks = 0; |
klauss | 45:c80574f24dc3 | 861 | } |
klauss | 45:c80574f24dc3 | 862 | } |
klauss | 45:c80574f24dc3 | 863 | |
klauss | 45:c80574f24dc3 | 864 | //promptcb ramal porta comando |
klauss | 50:d9b6577a70f5 | 865 | //FIXME colocar a parte eth de novo |
klauss | 48:195c97f12e8e | 866 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "pcb ", 4 )) { |
klauss | 45:c80574f24dc3 | 867 | miss_match = false; |
klauss | 48:195c97f12e8e | 868 | static uint8_t id_msg = 0x10; |
klauss | 48:195c97f12e8e | 869 | uint8_t write_buffer[ 300 ]; |
klauss | 48:195c97f12e8e | 870 | int ext,port; |
klauss | 48:195c97f12e8e | 871 | char *split, *ref; |
klauss | 48:195c97f12e8e | 872 | |
klauss | 48:195c97f12e8e | 873 | ref = debug_buf; |
klauss | 48:195c97f12e8e | 874 | debug_buf[ bufptr++ ] = 0x0D; |
klauss | 48:195c97f12e8e | 875 | debug_buf[ bufptr++ ] = 0x00; |
klauss | 48:195c97f12e8e | 876 | |
klauss | 48:195c97f12e8e | 877 | split = strtok( debug_buf + 4, " " ); |
klauss | 48:195c97f12e8e | 878 | ext = atoi( split ); |
klauss | 50:d9b6577a70f5 | 879 | |
klauss | 50:d9b6577a70f5 | 880 | port = convert_ext_to_port( ext ); |
klauss | 48:195c97f12e8e | 881 | split += strlen( split ) + 1; |
klauss | 48:195c97f12e8e | 882 | |
klauss | 48:195c97f12e8e | 883 | promptcb_last_ext = ext; |
klauss | 48:195c97f12e8e | 884 | promptcb_last_port = port; |
klauss | 48:195c97f12e8e | 885 | |
klauss | 48:195c97f12e8e | 886 | pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n", ext, port, split ); |
klauss | 48:195c97f12e8e | 887 | __send_to_cb__( __build_cb_package__( ext, port, __PROMPT__, split, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 48:195c97f12e8e | 888 | pc.printf("\n\rComando enviado\n\r"); |
klauss | 48:195c97f12e8e | 889 | |
klauss | 48:195c97f12e8e | 890 | for( register int i = 0; i < 32; i++ ) |
klauss | 48:195c97f12e8e | 891 | pc.printf("%0x ", write_buffer[ i ] ); |
klauss | 48:195c97f12e8e | 892 | pc.printf("\n\r"); |
klauss | 48:195c97f12e8e | 893 | |
klauss | 48:195c97f12e8e | 894 | debug_buf = ref; |
klauss | 48:195c97f12e8e | 895 | bufptr = 0; |
klauss | 48:195c97f12e8e | 896 | debug_buf[ 0 ] = 0; |
klauss | 48:195c97f12e8e | 897 | |
klauss | 48:195c97f12e8e | 898 | /* |
klauss | 48:195c97f12e8e | 899 | |
klauss | 45:c80574f24dc3 | 900 | unsigned int ext,port; |
klauss | 45:c80574f24dc3 | 901 | int ant1,ant2; |
klauss | 45:c80574f24dc3 | 902 | |
klauss | 48:195c97f12e8e | 903 | debug_buf[ bufptr++ ] = 0x0D; |
klauss | 48:195c97f12e8e | 904 | debug_buf[ bufptr++ ] = 0x00; |
klauss | 48:195c97f12e8e | 905 | |
klauss | 48:195c97f12e8e | 906 | ant1 = str2uint( ( debug_buf + 4 ), &ext ); |
klauss | 48:195c97f12e8e | 907 | ant2 = str2uint( ( ( debug_buf + 4 ) + ant1 + 1 ), &port ); |
klauss | 45:c80574f24dc3 | 908 | |
klauss | 45:c80574f24dc3 | 909 | promptcb_last_ext = ext; |
klauss | 45:c80574f24dc3 | 910 | promptcb_last_port = port; |
klauss | 48:195c97f12e8e | 911 | |
klauss | 48:195c97f12e8e | 912 | pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n", ext, port, debug_buf + 4 + ant1 + 2 + ant2 ); |
klauss | 48:195c97f12e8e | 913 | __send_to_cb__( __build_cb_package__( ext, port, __PROMPT__, debug_buf + 4 + ant1 + 2 + ant2, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 45:c80574f24dc3 | 914 | pc.printf("\n\rComando enviado\n\r"); |
klauss | 48:195c97f12e8e | 915 | |
klauss | 48:195c97f12e8e | 916 | for( register int i = 0; i < 300; i++ ){ |
klauss | 48:195c97f12e8e | 917 | pc.printf("%x ", write_buffer[ i ] ); |
klauss | 48:195c97f12e8e | 918 | if( i % 23 == 0 ) pc.printf("\n\r"); |
klauss | 48:195c97f12e8e | 919 | } |
klauss | 48:195c97f12e8e | 920 | pc.printf("\n\r"); |
klauss | 48:195c97f12e8e | 921 | */ |
klauss | 45:c80574f24dc3 | 922 | } |
klauss | 48:195c97f12e8e | 923 | |
klauss | 48:195c97f12e8e | 924 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "_pcb",4 )) { |
klauss | 45:c80574f24dc3 | 925 | miss_match = false; |
klauss | 45:c80574f24dc3 | 926 | static int id_msg = 0x30; |
klauss | 48:195c97f12e8e | 927 | uint8_t write_buffer[ 300 ]; |
klauss | 48:195c97f12e8e | 928 | debug_buf[ bufptr++ ] = 0x0D; |
klauss | 48:195c97f12e8e | 929 | debug_buf[ bufptr++ ] = 0x00; |
klauss | 45:c80574f24dc3 | 930 | |
klauss | 48:195c97f12e8e | 931 | pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",promptcb_last_ext, promptcb_last_port, debug_buf + 4 ); |
klauss | 45:c80574f24dc3 | 932 | |
klauss | 48:195c97f12e8e | 933 | __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 | 934 | pc.printf("\n\rComando enviado\n\r"); |
klauss | 45:c80574f24dc3 | 935 | } |
klauss | 48:195c97f12e8e | 936 | /* |
klauss | 48:195c97f12e8e | 937 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "flood kill ", 11 ) ){ |
klauss | 48:195c97f12e8e | 938 | miss_match = false; |
klauss | 48:195c97f12e8e | 939 | |
klauss | 48:195c97f12e8e | 940 | split = strtok( debug_buf + 11, " " ); |
klauss | 48:195c97f12e8e | 941 | int ext_init = atoi( split ); |
klauss | 48:195c97f12e8e | 942 | split = strtok( NULL, " " ); |
klauss | 48:195c97f12e8e | 943 | int ext_end = atoi( split ); |
klauss | 48:195c97f12e8e | 944 | pc.printf("\n\r MUUUUUUUuuuuUUUUUU - I'm not a dog!!!! \n\r"); |
klauss | 48:195c97f12e8e | 945 | if( from_eth ){ |
klauss | 48:195c97f12e8e | 946 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "MUUUUUUUuuuuUUUUUU - I'm not a dog!!!!\n\r"); |
klauss | 48:195c97f12e8e | 947 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 48:195c97f12e8e | 948 | } |
klauss | 48:195c97f12e8e | 949 | } |
klauss | 48:195c97f12e8e | 950 | */ |
klauss | 45:c80574f24dc3 | 951 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "cks",3 )) { |
klauss | 45:c80574f24dc3 | 952 | miss_match = false; |
klauss | 45:c80574f24dc3 | 953 | pcks_s = 1; |
klauss | 45:c80574f24dc3 | 954 | } |
klauss | 45:c80574f24dc3 | 955 | |
klauss | 45:c80574f24dc3 | 956 | if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "showcb",6 )) { |
klauss | 45:c80574f24dc3 | 957 | miss_match = false; |
klauss | 45:c80574f24dc3 | 958 | pshowcb = 1; |
klauss | 45:c80574f24dc3 | 959 | } |
klauss | 45:c80574f24dc3 | 960 | |
klauss | 45:c80574f24dc3 | 961 | if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_main ", 11 )) { |
klauss | 45:c80574f24dc3 | 962 | if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "on",2 )) { |
klauss | 45:c80574f24dc3 | 963 | miss_match = false; |
klauss | 45:c80574f24dc3 | 964 | pc.printf("\r\nDebug Main ON"); |
klauss | 45:c80574f24dc3 | 965 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 966 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Main On\n\r" ); |
klauss | 45:c80574f24dc3 | 967 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 968 | } |
klauss | 45:c80574f24dc3 | 969 | debug_main = 1; |
klauss | 45:c80574f24dc3 | 970 | } |
klauss | 45:c80574f24dc3 | 971 | if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { |
klauss | 45:c80574f24dc3 | 972 | miss_match = false; |
klauss | 45:c80574f24dc3 | 973 | pc.printf("\r\nDebug Main OFF"); |
klauss | 45:c80574f24dc3 | 974 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 975 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Main Off\n\r" ); |
klauss | 45:c80574f24dc3 | 976 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 977 | } |
klauss | 45:c80574f24dc3 | 978 | debug_main = 0; |
klauss | 45:c80574f24dc3 | 979 | } |
klauss | 45:c80574f24dc3 | 980 | } |
klauss | 45:c80574f24dc3 | 981 | |
klauss | 45:c80574f24dc3 | 982 | if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cb_rx ", 12 )) { |
klauss | 45:c80574f24dc3 | 983 | if (xmemmatch( (uint8_t*)( debug_buf + 12 ), (uint8_t*) "on",2 )) { |
klauss | 45:c80574f24dc3 | 984 | miss_match = false; |
klauss | 45:c80574f24dc3 | 985 | pc.printf("\tDebug Cbx Rx ON"); |
klauss | 45:c80574f24dc3 | 986 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 987 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Cbx On Rx on\n\r" ); |
klauss | 45:c80574f24dc3 | 988 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 989 | } |
klauss | 45:c80574f24dc3 | 990 | debug_cb_rx = 1; |
klauss | 45:c80574f24dc3 | 991 | } |
klauss | 45:c80574f24dc3 | 992 | if (xmemmatch( (uint8_t*)( debug_buf + 12 ), (uint8_t*) "off",3 )) { |
klauss | 45:c80574f24dc3 | 993 | miss_match = false; |
klauss | 45:c80574f24dc3 | 994 | pc.printf("Debug Cbx Rx OFF"); |
klauss | 45:c80574f24dc3 | 995 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 996 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Cbx Rx Off\n\r" ); |
klauss | 45:c80574f24dc3 | 997 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 998 | } |
klauss | 45:c80574f24dc3 | 999 | debug_cb_rx = 0; |
klauss | 45:c80574f24dc3 | 1000 | } |
klauss | 45:c80574f24dc3 | 1001 | } |
klauss | 45:c80574f24dc3 | 1002 | |
klauss | 45:c80574f24dc3 | 1003 | if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_file ", 11 )) { |
klauss | 45:c80574f24dc3 | 1004 | if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "on",2 )) { |
klauss | 45:c80574f24dc3 | 1005 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1006 | pc.printf("\tDebug File ON"); |
klauss | 45:c80574f24dc3 | 1007 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1008 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug File On\n\r" ); |
klauss | 45:c80574f24dc3 | 1009 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1010 | } |
klauss | 45:c80574f24dc3 | 1011 | debug_cb_rx = 1; |
klauss | 45:c80574f24dc3 | 1012 | } |
klauss | 45:c80574f24dc3 | 1013 | if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { |
klauss | 45:c80574f24dc3 | 1014 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1015 | pc.printf("Debug File OFF"); |
klauss | 45:c80574f24dc3 | 1016 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1017 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug File Off\n\r" ); |
klauss | 45:c80574f24dc3 | 1018 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1019 | } |
klauss | 45:c80574f24dc3 | 1020 | debug_cb_rx = 0; |
klauss | 45:c80574f24dc3 | 1021 | } |
klauss | 45:c80574f24dc3 | 1022 | } |
klauss | 45:c80574f24dc3 | 1023 | |
klauss | 45:c80574f24dc3 | 1024 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "help" )) { |
klauss | 45:c80574f24dc3 | 1025 | miss_match = false; |
klauss | 45:c80574f24dc3 | 1026 | pc.printf("\n\r****************************PROMPT HELP******************\n\r"); |
klauss | 45:c80574f24dc3 | 1027 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1028 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "\n\r****************************PROMPT HELP******************\n\r" ); |
klauss | 45:c80574f24dc3 | 1029 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1030 | |
klauss | 45:c80574f24dc3 | 1031 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1032 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1033 | } |
klauss | 44:cc4996469404 | 1034 | } |
klauss | 52:12930cef17c4 | 1035 | |
klauss | 45:c80574f24dc3 | 1036 | pc.printf("ifconfig - mostra o arquivo de configuracao do sistema\n\r"); |
klauss | 45:c80574f24dc3 | 1037 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1038 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ifconfig - mostra o arquivo de configuracao do sistema\n\r" ); |
klauss | 45:c80574f24dc3 | 1039 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1040 | |
klauss | 45:c80574f24dc3 | 1041 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1042 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1043 | } |
klauss | 45:c80574f24dc3 | 1044 | } |
klauss | 45:c80574f24dc3 | 1045 | pc.printf("dconfig - volta as configuracoes do sistema para o padrao de fabrica\n\r"); |
klauss | 45:c80574f24dc3 | 1046 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1047 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "dconfig - volta as configuracoes do sistema para o padrao de fabrica\n\r" ); |
klauss | 45:c80574f24dc3 | 1048 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1049 | |
klauss | 45:c80574f24dc3 | 1050 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1051 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1052 | } |
klauss | 45:c80574f24dc3 | 1053 | } |
klauss | 45:c80574f24dc3 | 1054 | pc.printf("callme [ramal porta] - envia o pedido de ligacao para o callbox com o ramal e porta indicada\n\r"); |
klauss | 45:c80574f24dc3 | 1055 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1056 | 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 | 1057 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1058 | |
klauss | 45:c80574f24dc3 | 1059 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1060 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1061 | } |
klauss | 45:c80574f24dc3 | 1062 | } |
klauss | 48:195c97f12e8e | 1063 | pc.printf("pcb porta comando - envia o <comando> para o cbx <ramal> e <porta> executar\n\r"); |
klauss | 45:c80574f24dc3 | 1064 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1065 | 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 | 1066 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1067 | |
klauss | 45:c80574f24dc3 | 1068 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1069 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1070 | } |
klauss | 45:c80574f24dc3 | 1071 | } |
klauss | 45:c80574f24dc3 | 1072 | pc.printf("format - formata o sistema de arquivos\n\r"); |
klauss | 45:c80574f24dc3 | 1073 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1074 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "format - formata o sistema de arquivos\n\r" ); |
klauss | 45:c80574f24dc3 | 1075 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1076 | |
klauss | 45:c80574f24dc3 | 1077 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1078 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1079 | } |
klauss | 45:c80574f24dc3 | 1080 | } |
klauss | 45:c80574f24dc3 | 1081 | pc.printf("reset - resta o sistema\n\r"); |
klauss | 45:c80574f24dc3 | 1082 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1083 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "reset - resta o sistema\n\r" ); |
klauss | 45:c80574f24dc3 | 1084 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1085 | |
klauss | 45:c80574f24dc3 | 1086 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1087 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1088 | } |
klauss | 45:c80574f24dc3 | 1089 | } |
klauss | 45:c80574f24dc3 | 1090 | pc.printf("ipset [ip] - Configura o IP da cabeceira\n\r"); |
klauss | 45:c80574f24dc3 | 1091 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1092 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ipset [ip] - Configura o IP da cabeceira\n\r" ); |
klauss | 45:c80574f24dc3 | 1093 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1094 | |
klauss | 45:c80574f24dc3 | 1095 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1096 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1097 | } |
klauss | 45:c80574f24dc3 | 1098 | } |
klauss | 45:c80574f24dc3 | 1099 | pc.printf("extset [ext] - Configura a ext da cabeceira\n\r"); |
klauss | 45:c80574f24dc3 | 1100 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1101 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "extset [ext] - Configura a ext da cabeceira\n\r" ); |
klauss | 45:c80574f24dc3 | 1102 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1103 | |
klauss | 45:c80574f24dc3 | 1104 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1105 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1106 | } |
klauss | 45:c80574f24dc3 | 1107 | } |
klauss | 45:c80574f24dc3 | 1108 | pc.printf("msipport [port] - Configura a porta SIP da cabeceira\n\r"); |
klauss | 45:c80574f24dc3 | 1109 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1110 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "msipport [port] - Configura a porta SIP da cabeceira\n\r" ); |
klauss | 45:c80574f24dc3 | 1111 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1112 | |
klauss | 45:c80574f24dc3 | 1113 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1114 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1115 | } |
klauss | 45:c80574f24dc3 | 1116 | } |
klauss | 45:c80574f24dc3 | 1117 | pc.printf("serverip [ip] - Configura o ip do servidor asterisk\n\r"); |
klauss | 45:c80574f24dc3 | 1118 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1119 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "serverip [ip] - Configura o ip do servidor asterisk\n\r" ); |
klauss | 45:c80574f24dc3 | 1120 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1121 | |
klauss | 45:c80574f24dc3 | 1122 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1123 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1124 | } |
klauss | 45:c80574f24dc3 | 1125 | } |
klauss | 45:c80574f24dc3 | 1126 | pc.printf("serextset [ext] - Configura a server ext da cabeceira\n\r"); |
klauss | 45:c80574f24dc3 | 1127 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1128 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "serextset [ext] - Configura a server ext da cabeceira\n\r" ); |
klauss | 45:c80574f24dc3 | 1129 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1130 | |
klauss | 45:c80574f24dc3 | 1131 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1132 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1133 | } |
klauss | 45:c80574f24dc3 | 1134 | } |
klauss | 45:c80574f24dc3 | 1135 | pc.printf("ssport [port] - Configura a porta SIP do servidor asterisk\n\r"); |
klauss | 45:c80574f24dc3 | 1136 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1137 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ssport [port] - Configura a porta SIP do servidor asterisk\n\r" ); |
klauss | 45:c80574f24dc3 | 1138 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1139 | |
klauss | 45:c80574f24dc3 | 1140 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1141 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1142 | } |
klauss | 45:c80574f24dc3 | 1143 | } |
klauss | 45:c80574f24dc3 | 1144 | pc.printf("maskset [mask] - Configura a mascara da cabeceira\n\r"); |
klauss | 45:c80574f24dc3 | 1145 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1146 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "maskset [mask] - Configura a mascara da cabeceira\n\r" ); |
klauss | 45:c80574f24dc3 | 1147 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1148 | |
klauss | 45:c80574f24dc3 | 1149 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1150 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1151 | } |
klauss | 45:c80574f24dc3 | 1152 | } |
klauss | 45:c80574f24dc3 | 1153 | pc.printf("gatewayset [gateway] - Configura o gateway da cabeceira\n\r"); |
klauss | 45:c80574f24dc3 | 1154 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1155 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "gatewayset [gateway] - Configura o gateway da cabeceira\n\r" ); |
klauss | 45:c80574f24dc3 | 1156 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1157 | |
klauss | 45:c80574f24dc3 | 1158 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1159 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1160 | } |
klauss | 45:c80574f24dc3 | 1161 | } |
klauss | 45:c80574f24dc3 | 1162 | pc.printf("showcb - lista os Cbx registrados na header\n\r"); |
klauss | 45:c80574f24dc3 | 1163 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1164 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "showcb - lista os Cbx registrados na header\n\r" ); |
klauss | 45:c80574f24dc3 | 1165 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1166 | |
klauss | 45:c80574f24dc3 | 1167 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1168 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1169 | } |
klauss | 45:c80574f24dc3 | 1170 | } |
klauss | 48:195c97f12e8e | 1171 | pc.printf("status - lista resumida de cbx registrados na header\n\r"); |
klauss | 48:195c97f12e8e | 1172 | if( from_eth ){ |
klauss | 48:195c97f12e8e | 1173 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "showcb - lista resumida de cbx registrados na header\n\r" ); |
klauss | 48:195c97f12e8e | 1174 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 48:195c97f12e8e | 1175 | |
klauss | 48:195c97f12e8e | 1176 | else if( udp_request ){ |
klauss | 48:195c97f12e8e | 1177 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 48:195c97f12e8e | 1178 | } |
klauss | 48:195c97f12e8e | 1179 | } |
klauss | 45:c80574f24dc3 | 1180 | pc.printf("cks - exibe estatisticas de check sum\n\r"); |
klauss | 45:c80574f24dc3 | 1181 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1182 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "cks - exibe estatisticas de check sum\n\r" ); |
klauss | 45:c80574f24dc3 | 1183 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1184 | |
klauss | 45:c80574f24dc3 | 1185 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1186 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1187 | } |
klauss | 45:c80574f24dc3 | 1188 | } |
klauss | 52:12930cef17c4 | 1189 | pc.printf("reset_cks - reseta estatisticas de check sum\n\r"); |
klauss | 52:12930cef17c4 | 1190 | if( from_eth ){ |
klauss | 52:12930cef17c4 | 1191 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "reset_cks - reseta estatisticas de check sum\n\r" ); |
klauss | 52:12930cef17c4 | 1192 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 52:12930cef17c4 | 1193 | |
klauss | 52:12930cef17c4 | 1194 | else if( udp_request ){ |
klauss | 52:12930cef17c4 | 1195 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 52:12930cef17c4 | 1196 | } |
klauss | 52:12930cef17c4 | 1197 | } |
klauss | 52:12930cef17c4 | 1198 | |
klauss | 52:12930cef17c4 | 1199 | |
klauss | 45:c80574f24dc3 | 1200 | pc.printf(". - executa o comando anterior novamente\n\r"); |
klauss | 45:c80574f24dc3 | 1201 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1202 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, ". - executa o comando anterior novamente\n\r" ); |
klauss | 45:c80574f24dc3 | 1203 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1204 | |
klauss | 45:c80574f24dc3 | 1205 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1206 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1207 | } |
klauss | 45:c80574f24dc3 | 1208 | } |
klauss | 45:c80574f24dc3 | 1209 | pc.printf("debug [on|off|show] - seleciona debugs gerais | lista de debugs \n\r"); |
klauss | 45:c80574f24dc3 | 1210 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1211 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "debug [on|off|show] - seleciona debugs gerais | lista de debugs \n\r" ); |
klauss | 45:c80574f24dc3 | 1212 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1213 | |
klauss | 45:c80574f24dc3 | 1214 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1215 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1216 | } |
klauss | 45:c80574f24dc3 | 1217 | } |
klauss | 45:c80574f24dc3 | 1218 | pc.printf("flood [on|off] - simula envio de pacotes de audio\n\r"); |
klauss | 45:c80574f24dc3 | 1219 | if( from_eth ){ |
klauss | 45:c80574f24dc3 | 1220 | snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "flood [on|off] - simula envio de pacotes de audio\n\r"); |
klauss | 45:c80574f24dc3 | 1221 | if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1222 | |
klauss | 45:c80574f24dc3 | 1223 | else if( udp_request ){ |
klauss | 45:c80574f24dc3 | 1224 | udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1225 | } |
klauss | 45:c80574f24dc3 | 1226 | } |
klauss | 45:c80574f24dc3 | 1227 | pc.printf("PROMPT VERSION: V%d\n\r",PVERSION); |
klauss | 45:c80574f24dc3 | 1228 | //Obs :: a ultima linha nao mandamos direto pro tcp porque ela eh enviada fora desse escopo |
klauss | 45:c80574f24dc3 | 1229 | if( from_eth ) snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "PROMPT VERSION: V%d\n\r",PVERSION); |
klauss | 27:98f824719d1c | 1230 | } |
klauss | 27:98f824719d1c | 1231 | /* |
klauss | 45:c80574f24dc3 | 1232 | if ( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "callme ", 7 )) { |
klauss | 45:c80574f24dc3 | 1233 | if ( debug_buf[16] != 0 && debug_buf[11] != 0x20 ) |
klauss | 45:c80574f24dc3 | 1234 | pc.printf("\n\r Error: formato errado! ramal=xxxx porta=xxxx \n\r"); |
klauss | 45:c80574f24dc3 | 1235 | else { |
klauss | 45:c80574f24dc3 | 1236 | uint8_t data[300]; |
klauss | 45:c80574f24dc3 | 1237 | uint16_t cks=0; |
klauss | 45:c80574f24dc3 | 1238 | |
klauss | 45:c80574f24dc3 | 1239 | //data[0] = (uint8_t)( (debug_buf[7]&0xf0)<<4 + (debug_buf[8]&0x0f) ) ; |
klauss | 45:c80574f24dc3 | 1240 | //data[1] = (uint8_t)( (debug_buf[9]&0xf0)<<4 + (debug_buf[10]&0x0f) ) ; |
klauss | 45:c80574f24dc3 | 1241 | //data[2] = (uint8_t)( (debug_buf[12]&0xf0)<<4 + (debug_buf[13]&0x0f) ) ; |
klauss | 45:c80574f24dc3 | 1242 | /data[3] = (uint8_t)( (debug_buf[14]&0xf0)<<4 + (debug_buf[15]&0x0f) ) ; |
klauss | 45:c80574f24dc3 | 1243 | |
klauss | 45:c80574f24dc3 | 1244 | data[0] = (uint8_t)( debug_buf[ 7 ] & 0xFF00 >> 8 ); |
klauss | 45:c80574f24dc3 | 1245 | data[1] = (uint8_t)( debug_buf[ 9 ] & 0x00FF ); |
klauss | 45:c80574f24dc3 | 1246 | data[2] = (uint8_t)( debug_buf[ 12 ] & 0xFF00 >> 8 ); |
klauss | 45:c80574f24dc3 | 1247 | data[3] = (uint8_t)( debug_buf[ 14 ] & 0x00FF ); |
klauss | 45:c80574f24dc3 | 1248 | |
klauss | 45:c80574f24dc3 | 1249 | data[6] = 0x04; |
klauss | 45:c80574f24dc3 | 1250 | for (int i = 7; i < 300; i++) data[i] = 0x00; |
klauss | 45:c80574f24dc3 | 1251 | cks = __checksum__(data,300); |
klauss | 45:c80574f24dc3 | 1252 | data[4] = cks>>8; |
klauss | 45:c80574f24dc3 | 1253 | data[5] = cks&0xff; |
klauss | 45:c80574f24dc3 | 1254 | |
klauss | 45:c80574f24dc3 | 1255 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 1256 | for( int i = 0; i < 300; i++ ) |
klauss | 45:c80574f24dc3 | 1257 | pc.printf("%x ", data[ i ] ); |
klauss | 45:c80574f24dc3 | 1258 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 1259 | |
klauss | 45:c80574f24dc3 | 1260 | xmemcpy(TXBuffer,data,300); |
klauss | 45:c80574f24dc3 | 1261 | |
klauss | 45:c80574f24dc3 | 1262 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 1263 | for( int i = 0; i < 300; i++ ) |
klauss | 45:c80574f24dc3 | 1264 | pc.printf("%x ", data[ i ] ); |
klauss | 45:c80574f24dc3 | 1265 | pc.printf("\n\r"); |
klauss | 45:c80574f24dc3 | 1266 | |
klauss | 45:c80574f24dc3 | 1267 | send2callboxes(); |
klauss | 45:c80574f24dc3 | 1268 | |
klauss | 45:c80574f24dc3 | 1269 | pc.printf("\n\r calling callbox %s \n\r",debug_buf+7); |
klauss | 19:ab2088e0dec6 | 1270 | } |
klauss | 45:c80574f24dc3 | 1271 | } |
klauss | 45:c80574f24dc3 | 1272 | */ |
klauss | 45:c80574f24dc3 | 1273 | |
klauss | 45:c80574f24dc3 | 1274 | if( miss_match ){ |
klauss | 48:195c97f12e8e | 1275 | pc.printf("\n\r> %s: command not found\n\r", debug_buf ); |
klauss | 45:c80574f24dc3 | 1276 | if( from_eth ){ |
klauss | 48:195c97f12e8e | 1277 | snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "> %s: command not found\n ", debug_buf ); |
klauss | 45:c80574f24dc3 | 1278 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 45:c80574f24dc3 | 1279 | } |
klauss | 45:c80574f24dc3 | 1280 | } |
klauss | 45:c80574f24dc3 | 1281 | else{ |
klauss | 48:195c97f12e8e | 1282 | if( ( b != 0x0D ) && ( bufptr != 0 ) ) strcpy( last_debug_buf, debug_buf ); |
klauss | 45:c80574f24dc3 | 1283 | } |
klauss | 48:195c97f12e8e | 1284 | } |
klauss | 45:c80574f24dc3 | 1285 | if( b == 0x0D || bufret == 1 || bufptr > DEBUGBUFSIZE ){ |
klauss | 45:c80574f24dc3 | 1286 | bufret = 0; |
klauss | 45:c80574f24dc3 | 1287 | if( tcp_session ){ |
klauss | 48:195c97f12e8e | 1288 | if( debug_buf[ strlen( debug_buf ) - 1 ] == '\r' || debug_buf[ strlen( debug_buf ) - 1 ] == '\n' ) strcat( debug_buf, "> " ); |
klauss | 48:195c97f12e8e | 1289 | |
klauss | 48:195c97f12e8e | 1290 | else strcat( debug_buf, "\n\r> " ); |
klauss | 48:195c97f12e8e | 1291 | |
klauss | 45:c80574f24dc3 | 1292 | tcp_client.send_all( debug_buf, strlen( debug_buf ) ); |
klauss | 48:195c97f12e8e | 1293 | //tcp_timer.reset(); |
klauss | 45:c80574f24dc3 | 1294 | }else if( udp_request ){ |
klauss | 48:195c97f12e8e | 1295 | if( debug_buf[ strlen( debug_buf ) - 1 ] == '\r' || debug_buf[ strlen( debug_buf ) - 1 ] == '\n' ) strcat( debug_buf, "> " ); |
klauss | 48:195c97f12e8e | 1296 | |
klauss | 48:195c97f12e8e | 1297 | else strcat( debug_buf, "\n\r> " ); |
klauss | 48:195c97f12e8e | 1298 | |
klauss | 45:c80574f24dc3 | 1299 | int sent = udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); |
klauss | 45:c80574f24dc3 | 1300 | udp_request = false; |
klauss | 45:c80574f24dc3 | 1301 | }else{ |
klauss | 42:480335bdde12 | 1302 | bufptr = 0; |
klauss | 42:480335bdde12 | 1303 | for (uint8_t i =0; i < DEBUGBUFSIZE; i++) { |
klauss | 42:480335bdde12 | 1304 | debug_buf[i] = 0; |
klauss | 42:480335bdde12 | 1305 | } |
klauss | 45:c80574f24dc3 | 1306 | } |
klauss | 48:195c97f12e8e | 1307 | from_eth = false; |
klauss | 48:195c97f12e8e | 1308 | debug_buf = __debug_buf__; |
klauss | 48:195c97f12e8e | 1309 | bufptr = last_bufptr; |
klauss | 45:c80574f24dc3 | 1310 | pc.putc(0x0A); |
klauss | 45:c80574f24dc3 | 1311 | pc.putc(0x0D); |
klauss | 45:c80574f24dc3 | 1312 | pc.printf("> "); |
klauss | 45:c80574f24dc3 | 1313 | } |
klauss | 36:728498a78e1e | 1314 | return( NULL ); |
klauss | 50:d9b6577a70f5 | 1315 | } |
klauss | 50:d9b6577a70f5 | 1316 | |
klauss | 51:5fc3a8f02fdf | 1317 | int convert_ext_to_port( int ext ){ |
klauss | 51:5fc3a8f02fdf | 1318 | if( ext < 1000 ) return ext; |
klauss | 51:5fc3a8f02fdf | 1319 | |
klauss | 51:5fc3a8f02fdf | 1320 | else{ |
klauss | 51:5fc3a8f02fdf | 1321 | int aux = 0; |
klauss | 51:5fc3a8f02fdf | 1322 | aux = ( ext / 1000 ) * 1000; |
klauss | 51:5fc3a8f02fdf | 1323 | ext -= aux; |
klauss | 51:5fc3a8f02fdf | 1324 | aux += ext % 100; |
klauss | 51:5fc3a8f02fdf | 1325 | return( aux ); |
klauss | 51:5fc3a8f02fdf | 1326 | } |
klauss | 50:d9b6577a70f5 | 1327 | } |