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