Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
prompt.cpp@41:69bf7091c2ca, 2014-10-02 (annotated)
- Committer:
- klauss
- Date:
- Thu Oct 02 21:22:54 2014 +0000
- Revision:
- 41:69bf7091c2ca
- Parent:
- 38:af5ecd6997ab
- Child:
- 42:480335bdde12
efetivamente ouvindo uma porta tcp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 19:ab2088e0dec6 | 1 | #include "mbed.h" |
klauss | 19:ab2088e0dec6 | 2 | #include "stdint.h" |
klauss | 19:ab2088e0dec6 | 3 | #include "configs.h" |
klauss | 19:ab2088e0dec6 | 4 | #include "vz_protocol.h" |
klauss | 19:ab2088e0dec6 | 5 | #include "parallelcpld.h" |
Cola | 21:0bd688722e81 | 6 | #include "flood.h" |
klauss | 28:94aec56c6329 | 7 | #include "debug.h" |
Cola | 24:270b436a1bb0 | 8 | |
klauss | 41:69bf7091c2ca | 9 | TCPSocketServer server; |
klauss | 41:69bf7091c2ca | 10 | TCPSocketConnection client; |
klauss | 41:69bf7091c2ca | 11 | Timer tcp_timer; |
klauss | 41:69bf7091c2ca | 12 | |
klauss | 28:94aec56c6329 | 13 | uint8_t debug_alive = 0; |
klauss | 28:94aec56c6329 | 14 | uint8_t debug_sip = 0; |
klauss | 29:7246460b73f8 | 15 | uint8_t debug_vector = 0; |
klauss | 29:7246460b73f8 | 16 | uint8_t debug_cb = 0; |
klauss | 30:8dfb6d8de53d | 17 | uint8_t debug_main = 0; |
klauss | 31:bb5fb28a77df | 18 | uint8_t debug_cks = 0; |
Cola | 22:d2a4b5939115 | 19 | uint8_t pcks_s = 0; |
Cola | 24:270b436a1bb0 | 20 | uint8_t pshowcb = 0; |
klauss | 31:bb5fb28a77df | 21 | uint8_t debug_cb_rx = 0; |
klauss | 31:bb5fb28a77df | 22 | uint8_t debug_cb_tx = 0; |
klauss | 31:bb5fb28a77df | 23 | uint8_t debug_eth_rx = 0; |
klauss | 31:bb5fb28a77df | 24 | uint8_t debug_eth_tx = 0; |
klauss | 31:bb5fb28a77df | 25 | uint8_t debug_file = 0; |
klauss | 38:af5ecd6997ab | 26 | bool from_eth = false; |
klauss | 41:69bf7091c2ca | 27 | bool udp_pkg; |
klauss | 41:69bf7091c2ca | 28 | bool tcp_pkg; |
klauss | 28:94aec56c6329 | 29 | |
klauss | 29:7246460b73f8 | 30 | uint8_t test_debug = 1; |
klauss | 31:bb5fb28a77df | 31 | #define PVERSION 1.1 // Sempre atualizar a versao do prompt |
klauss | 19:ab2088e0dec6 | 32 | |
Cola | 21:0bd688722e81 | 33 | #define DEBUGBUFSIZE 50 |
klauss | 35:96885a7931f0 | 34 | char __debug_buf__[DEBUGBUFSIZE]; |
klauss | 35:96885a7931f0 | 35 | char * debug_buf = __debug_buf__; |
klauss | 30:8dfb6d8de53d | 36 | char last_debug_buf[ DEBUGBUFSIZE ] = "help"; |
klauss | 28:94aec56c6329 | 37 | FILE *fip, *fmask, *fgate, *fport, *fsip, *fsport, *fext, *fserext; |
klauss | 19:ab2088e0dec6 | 38 | uint8_t dog = 1; |
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 | |
Cola | 21:0bd688722e81 | 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 | 38:af5ecd6997ab | 85 | if( debug_file ) debug_msg("Failed to open %s", fname); |
klauss | 19:ab2088e0dec6 | 86 | return; |
klauss | 19:ab2088e0dec6 | 87 | } |
klauss | 19:ab2088e0dec6 | 88 | |
klauss | 38:af5ecd6997ab | 89 | while ((num = fread(buff, 1, 512, fp)) > 0){ |
klauss | 19:ab2088e0dec6 | 90 | buff[num] = '\0'; |
klauss | 19:ab2088e0dec6 | 91 | pc.printf(buff); |
klauss | 19:ab2088e0dec6 | 92 | } |
klauss | 19:ab2088e0dec6 | 93 | fclose(fp); |
klauss | 19:ab2088e0dec6 | 94 | } |
klauss | 19:ab2088e0dec6 | 95 | |
klauss | 28:94aec56c6329 | 96 | // operantion with the system config files |
klauss | 28:94aec56c6329 | 97 | void files (const char type) { |
klauss | 19:ab2088e0dec6 | 98 | if (type == 's' ){ // show files |
klauss | 19:ab2088e0dec6 | 99 | pc.printf("\n\r"); |
klauss | 28:94aec56c6329 | 100 | pc.printf("Header IP " ); |
klauss | 19:ab2088e0dec6 | 101 | cat("/qspi/myip.txt"); |
klauss | 28:94aec56c6329 | 102 | pc.printf("\n\rHeader ext "); |
klauss | 28:94aec56c6329 | 103 | cat("/qspi/myext.txt"); |
klauss | 28:94aec56c6329 | 104 | pc.printf("\n\rHeader port "); |
klauss | 28:94aec56c6329 | 105 | cat("/qspi/mysipport.txt"); |
klauss | 28:94aec56c6329 | 106 | |
klauss | 28:94aec56c6329 | 107 | pc.printf("\n\rServer ip "); |
klauss | 28:94aec56c6329 | 108 | cat("/qspi/serverip.txt"); |
klauss | 28:94aec56c6329 | 109 | pc.printf("\n\rServer ext "); |
klauss | 28:94aec56c6329 | 110 | cat("/qspi/peerext.txt"); |
klauss | 28:94aec56c6329 | 111 | pc.printf("\n\rServer port "); |
klauss | 28:94aec56c6329 | 112 | cat("/qspi/serverport.txt"); |
klauss | 28:94aec56c6329 | 113 | |
klauss | 28:94aec56c6329 | 114 | pc.printf("\n\rMascara de rede "); |
klauss | 19:ab2088e0dec6 | 115 | cat("/qspi/mymask.txt"); |
klauss | 28:94aec56c6329 | 116 | pc.printf("\n\rGateway IP "); |
klauss | 19:ab2088e0dec6 | 117 | cat("/qspi/mygate.txt"); |
klauss | 19:ab2088e0dec6 | 118 | } |
klauss | 19:ab2088e0dec6 | 119 | |
klauss | 19:ab2088e0dec6 | 120 | if (type == 'c' ){ // close all files |
klauss | 28:94aec56c6329 | 121 | fclose( fip ); |
klauss | 28:94aec56c6329 | 122 | fclose( fmask ); |
klauss | 28:94aec56c6329 | 123 | fclose( fgate ); |
klauss | 28:94aec56c6329 | 124 | fclose( fport ); |
klauss | 28:94aec56c6329 | 125 | fclose( fsip ); |
klauss | 28:94aec56c6329 | 126 | fclose( fsport ); |
klauss | 28:94aec56c6329 | 127 | fclose( fext ); |
klauss | 28:94aec56c6329 | 128 | fclose( fserext ); |
klauss | 19:ab2088e0dec6 | 129 | } |
klauss | 19:ab2088e0dec6 | 130 | |
klauss | 19:ab2088e0dec6 | 131 | if (type == 'i' ){ // Check if files exist, if not create the files |
klauss | 33:735fd60e96d8 | 132 | bool exists = true; |
klauss | 19:ab2088e0dec6 | 133 | fip = fopen("/qspi/myip.txt", "r"); |
klauss | 19:ab2088e0dec6 | 134 | if (fip == NULL){ |
klauss | 19:ab2088e0dec6 | 135 | fip = fopen("/qspi/myip.txt", "w"); |
klauss | 29:7246460b73f8 | 136 | //fprintf(fip, "%s\n\r",__MY_IP__); //myip |
klauss | 29:7246460b73f8 | 137 | fprintf(fip, "%s",__MY_IP__); //myip |
klauss | 33:735fd60e96d8 | 138 | exists = false; |
klauss | 19:ab2088e0dec6 | 139 | } |
klauss | 28:94aec56c6329 | 140 | |
klauss | 28:94aec56c6329 | 141 | fserext = fopen("/qspi/myext.txt", "r"); |
klauss | 28:94aec56c6329 | 142 | if ( fserext == NULL ){ |
klauss | 28:94aec56c6329 | 143 | fserext = fopen("/qspi/myext.txt", "w"); |
klauss | 38:af5ecd6997ab | 144 | fprintf( fserext, "%i\n\r" ,__MY_EXT__ ); //asterisk ext |
klauss | 33:735fd60e96d8 | 145 | exists = false; |
klauss | 28:94aec56c6329 | 146 | } |
klauss | 28:94aec56c6329 | 147 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 28:94aec56c6329 | 148 | if (fport == NULL){ |
klauss | 28:94aec56c6329 | 149 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 38:af5ecd6997ab | 150 | fprintf(fport, "%i\n\r",__MY_PORT__); //mysipport |
klauss | 33:735fd60e96d8 | 151 | exists = false; |
klauss | 28:94aec56c6329 | 152 | } |
klauss | 28:94aec56c6329 | 153 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 28:94aec56c6329 | 154 | if (fsip == NULL){ |
klauss | 28:94aec56c6329 | 155 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 29:7246460b73f8 | 156 | //fprintf(fsip, "%s\n\r",__SERVER_IP__ ); //asterisk ip |
klauss | 29:7246460b73f8 | 157 | fprintf(fsip, "%s",__SERVER_IP__ ); //asterisk ip |
klauss | 33:735fd60e96d8 | 158 | exists = false; |
klauss | 28:94aec56c6329 | 159 | } |
klauss | 28:94aec56c6329 | 160 | |
klauss | 28:94aec56c6329 | 161 | fext = fopen("/qspi/peerext.txt", "r"); |
klauss | 28:94aec56c6329 | 162 | if ( fext == NULL ){ |
klauss | 28:94aec56c6329 | 163 | fext = fopen("/qspi/peerext.txt", "w"); |
klauss | 38:af5ecd6997ab | 164 | fprintf( fext, "%i\n\r",__PEER_EXT__ ); //asterisk ip |
klauss | 33:735fd60e96d8 | 165 | exists = false; |
klauss | 28:94aec56c6329 | 166 | } |
klauss | 28:94aec56c6329 | 167 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 28:94aec56c6329 | 168 | if (fsport == NULL){ |
klauss | 28:94aec56c6329 | 169 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 38:af5ecd6997ab | 170 | fprintf(fsport, "%i\n\r",__SERVER_PORT__ ); //asterisk port |
klauss | 33:735fd60e96d8 | 171 | exists = false; |
klauss | 28:94aec56c6329 | 172 | } |
klauss | 28:94aec56c6329 | 173 | |
klauss | 19:ab2088e0dec6 | 174 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 19:ab2088e0dec6 | 175 | if (fmask == NULL){ |
klauss | 19:ab2088e0dec6 | 176 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 31:bb5fb28a77df | 177 | fprintf(fmask, "%s",__MY_MSK__); //mymask |
klauss | 33:735fd60e96d8 | 178 | exists = false; |
klauss | 19:ab2088e0dec6 | 179 | } |
klauss | 19:ab2088e0dec6 | 180 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 19:ab2088e0dec6 | 181 | if (fgate == NULL){ |
klauss | 19:ab2088e0dec6 | 182 | fgate = fopen("/qspi/mygate.txt", "w"); |
klauss | 31:bb5fb28a77df | 183 | fprintf(fgate, "%s",__MY_GTW__); //mygateway |
klauss | 33:735fd60e96d8 | 184 | exists = false; |
klauss | 19:ab2088e0dec6 | 185 | } |
klauss | 33:735fd60e96d8 | 186 | if( !exists ) pc.printf("\n\r Default configurations set! \n\r"); |
klauss | 19:ab2088e0dec6 | 187 | } |
klauss | 19:ab2088e0dec6 | 188 | |
klauss | 19:ab2088e0dec6 | 189 | if (type == 'r' ){ // Just open for read |
klauss | 19:ab2088e0dec6 | 190 | fip = fopen("/qspi/myip.txt", "r"); |
klauss | 19:ab2088e0dec6 | 191 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 19:ab2088e0dec6 | 192 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 19:ab2088e0dec6 | 193 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 19:ab2088e0dec6 | 194 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 19:ab2088e0dec6 | 195 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 28:94aec56c6329 | 196 | fext = fopen( "/qspi/myext.txt", "r" ); |
klauss | 28:94aec56c6329 | 197 | fserext = fopen( "/qspi/peerext.txt", "r" ); |
klauss | 19:ab2088e0dec6 | 198 | } |
klauss | 19:ab2088e0dec6 | 199 | |
klauss | 19:ab2088e0dec6 | 200 | if (type == 'w'){ // Create and write the default configs |
klauss | 19:ab2088e0dec6 | 201 | fip = fopen("/qspi/myip.txt", "w"); |
klauss | 19:ab2088e0dec6 | 202 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 19:ab2088e0dec6 | 203 | fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 19:ab2088e0dec6 | 204 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 19:ab2088e0dec6 | 205 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 19:ab2088e0dec6 | 206 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 28:94aec56c6329 | 207 | fext = fopen( "/qspi/myext.txt", "w" ); |
klauss | 28:94aec56c6329 | 208 | fserext = fopen( "/qspi/peerext.txt", "w" ); |
klauss | 19:ab2088e0dec6 | 209 | |
klauss | 29:7246460b73f8 | 210 | //fprintf( fip, "%s\n\r", __MY_IP__ ); //myip |
klauss | 29:7246460b73f8 | 211 | fprintf( fip, "%s", __MY_IP__ ); //myip |
klauss | 38:af5ecd6997ab | 212 | fprintf( fport, "%i\n\r", __MY_PORT__ ); //mysipport |
klauss | 38:af5ecd6997ab | 213 | fprintf( fext, "%i\n\r", __MY_EXT__ ); //myext |
klauss | 28:94aec56c6329 | 214 | |
klauss | 29:7246460b73f8 | 215 | //fprintf( fsip, "%s\n\r", __SERVER_IP__ ); //asterisk ip |
klauss | 29:7246460b73f8 | 216 | fprintf( fsip, "%s", __SERVER_IP__ ); //asterisk ip |
klauss | 38:af5ecd6997ab | 217 | fprintf( fserext, "%i\n\r",__PEER_EXT__ ); //asterisk port |
klauss | 38:af5ecd6997ab | 218 | fprintf( fsport, "%i\n\r",__SERVER_PORT__ ); //asterisk port |
klauss | 28:94aec56c6329 | 219 | |
klauss | 31:bb5fb28a77df | 220 | fprintf( fmask, "%s",__MY_MSK__ ); //mymask |
klauss | 31:bb5fb28a77df | 221 | fprintf( fgate, "%i", __MY_GTW__ ); //mygateway |
klauss | 19:ab2088e0dec6 | 222 | |
klauss | 19:ab2088e0dec6 | 223 | files('c'); |
klauss | 19:ab2088e0dec6 | 224 | |
klauss | 19:ab2088e0dec6 | 225 | pc.printf("\n\r Default configurations set! \n\r"); |
klauss | 19:ab2088e0dec6 | 226 | |
klauss | 19:ab2088e0dec6 | 227 | } |
klauss | 19:ab2088e0dec6 | 228 | |
klauss | 19:ab2088e0dec6 | 229 | } |
klauss | 26:725cbbedadd5 | 230 | void init_fsystem(){ |
klauss | 26:725cbbedadd5 | 231 | // init file system and check if files exist |
klauss | 26:725cbbedadd5 | 232 | if (!qspifs.isformatted()) { |
klauss | 26:725cbbedadd5 | 233 | qspifs.format(); |
klauss | 26:725cbbedadd5 | 234 | pc.printf("File system configured!!\n\r"); |
klauss | 26:725cbbedadd5 | 235 | } |
klauss | 26:725cbbedadd5 | 236 | files('i'); // check if the files are created |
klauss | 26:725cbbedadd5 | 237 | files('c'); |
klauss | 41:69bf7091c2ca | 238 | |
klauss | 41:69bf7091c2ca | 239 | server.bind( TCP_PORT_LISTENER ); |
klauss | 41:69bf7091c2ca | 240 | server.listen(); |
klauss | 41:69bf7091c2ca | 241 | tcp_timer.start(); |
klauss | 41:69bf7091c2ca | 242 | server.set_blocking( false, 1 ); |
klauss | 26:725cbbedadd5 | 243 | pc.printf("*******System Ready*******\n\r"); |
klauss | 19:ab2088e0dec6 | 244 | } |
klauss | 19:ab2088e0dec6 | 245 | |
klauss | 28:94aec56c6329 | 246 | // main prompt process |
klauss | 41:69bf7091c2ca | 247 | char * prompt_process( char * msg_to_eth ){ |
klauss | 28:94aec56c6329 | 248 | //FIXME dar flush na serial |
klauss | 19:ab2088e0dec6 | 249 | volatile char b = 0; |
klauss | 19:ab2088e0dec6 | 250 | static uint8_t bufret = 0; |
klauss | 30:8dfb6d8de53d | 251 | static Timer flood_timeout; |
klauss | 36:728498a78e1e | 252 | bool miss_match = true; |
klauss | 41:69bf7091c2ca | 253 | char buffer[ 1024 ]; |
klauss | 30:8dfb6d8de53d | 254 | |
klauss | 30:8dfb6d8de53d | 255 | if( flood_timeout.read() > 60 ){ |
klauss | 30:8dfb6d8de53d | 256 | pflood = 0; |
klauss | 30:8dfb6d8de53d | 257 | flood_timeout.stop(); |
klauss | 30:8dfb6d8de53d | 258 | flood_timeout.reset(); |
klauss | 30:8dfb6d8de53d | 259 | } |
klauss | 41:69bf7091c2ca | 260 | if( tcp_timer.read() > 3 ){ |
klauss | 41:69bf7091c2ca | 261 | wdt.kick(); |
klauss | 41:69bf7091c2ca | 262 | tcp_timer.reset(); |
klauss | 41:69bf7091c2ca | 263 | if( !server.accept( client ) ){ |
klauss | 41:69bf7091c2ca | 264 | //FIXME mudar essa condicao para parar depois de 30 sec for instance |
klauss | 41:69bf7091c2ca | 265 | while( tcp_timer.read() < 30 ){ |
klauss | 41:69bf7091c2ca | 266 | client.set_blocking( false, 1 ); |
klauss | 41:69bf7091c2ca | 267 | int n = client.receive(buffer, sizeof( buffer )); |
klauss | 41:69bf7091c2ca | 268 | if( n > 0 ){ |
klauss | 41:69bf7091c2ca | 269 | wdt.kick(); |
klauss | 41:69bf7091c2ca | 270 | tcp_timer.reset(); |
klauss | 41:69bf7091c2ca | 271 | |
klauss | 41:69bf7091c2ca | 272 | last_bufptr = bufptr; |
klauss | 41:69bf7091c2ca | 273 | debug_msg("%x -- %x", buffer[ n - 2 ], buffer[ n - 1 ] ); |
klauss | 41:69bf7091c2ca | 274 | bufptr = n - 2;//strlen( buffer ); |
klauss | 41:69bf7091c2ca | 275 | debug_msg("Sizeof pkg received (n, strlen( buffer ) ) (%d, %d)", n , bufptr ); |
klauss | 41:69bf7091c2ca | 276 | debug_buf = buffer; |
klauss | 41:69bf7091c2ca | 277 | debug_buf[ n - 2 ] = 0; |
klauss | 41:69bf7091c2ca | 278 | debug_msg("Command received %s::endl", debug_buf ); |
klauss | 41:69bf7091c2ca | 279 | from_eth = true; |
klauss | 41:69bf7091c2ca | 280 | tcp_pkg = true; |
klauss | 41:69bf7091c2ca | 281 | bufret = 1; |
klauss | 41:69bf7091c2ca | 282 | } |
klauss | 41:69bf7091c2ca | 283 | } |
klauss | 41:69bf7091c2ca | 284 | if( tcp_timer.read() >= 30 ){ |
klauss | 41:69bf7091c2ca | 285 | tcp_timer.reset(); |
klauss | 41:69bf7091c2ca | 286 | tcp_pkg = false; |
klauss | 41:69bf7091c2ca | 287 | debug_buf = __debug_buf__; |
klauss | 41:69bf7091c2ca | 288 | bufptr = last_bufptr; |
klauss | 41:69bf7091c2ca | 289 | bufret = 0; |
klauss | 41:69bf7091c2ca | 290 | from_eth = false; |
klauss | 41:69bf7091c2ca | 291 | return( NULL ); |
klauss | 41:69bf7091c2ca | 292 | } |
klauss | 41:69bf7091c2ca | 293 | } |
klauss | 41:69bf7091c2ca | 294 | }else if( msg_to_eth == NULL ){ |
klauss | 35:96885a7931f0 | 295 | if ( pc.readable() ){ |
klauss | 26:725cbbedadd5 | 296 | // imput do teclado |
klauss | 19:ab2088e0dec6 | 297 | b = pc.getc(); |
klauss | 19:ab2088e0dec6 | 298 | |
klauss | 29:7246460b73f8 | 299 | if( b == 0x0D ){ // enter |
klauss | 27:98f824719d1c | 300 | bufret = 1; |
klauss | 29:7246460b73f8 | 301 | }else{ |
klauss | 29:7246460b73f8 | 302 | pc.putc( b ); |
klauss | 29:7246460b73f8 | 303 | if( b == 0x08 || b == 0x7F ){ // BS | DEL |
klauss | 29:7246460b73f8 | 304 | if( bufptr > 0 ) debug_buf[ --bufptr ] = 0; |
klauss | 31:bb5fb28a77df | 305 | }else if( b == 0x09 ){ |
klauss | 31:bb5fb28a77df | 306 | // ignore tab |
klauss | 29:7246460b73f8 | 307 | }else{ |
klauss | 29:7246460b73f8 | 308 | debug_buf[bufptr] = b; |
klauss | 29:7246460b73f8 | 309 | bufptr++; |
klauss | 29:7246460b73f8 | 310 | } |
klauss | 19:ab2088e0dec6 | 311 | } |
klauss | 19:ab2088e0dec6 | 312 | } |
klauss | 35:96885a7931f0 | 313 | }else{ |
klauss | 35:96885a7931f0 | 314 | last_bufptr = bufptr; |
klauss | 41:69bf7091c2ca | 315 | bufptr = strlen( msg_to_eth ); |
klauss | 41:69bf7091c2ca | 316 | debug_buf = msg_to_eth; |
klauss | 36:728498a78e1e | 317 | from_eth = true; |
klauss | 35:96885a7931f0 | 318 | bufret = 1; |
klauss | 35:96885a7931f0 | 319 | } |
klauss | 19:ab2088e0dec6 | 320 | |
klauss | 28:94aec56c6329 | 321 | // Prompt commands here |
klauss | 29:7246460b73f8 | 322 | if ( bufret == 1 ) { |
klauss | 29:7246460b73f8 | 323 | static unsigned int promptcb_last_ext = 0; |
klauss | 29:7246460b73f8 | 324 | static unsigned int promptcb_last_port = 0; |
klauss | 28:94aec56c6329 | 325 | |
klauss | 30:8dfb6d8de53d | 326 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) ".",1 )) { |
klauss | 30:8dfb6d8de53d | 327 | miss_match = false; |
klauss | 30:8dfb6d8de53d | 328 | strcpy( debug_buf, last_debug_buf ); |
klauss | 30:8dfb6d8de53d | 329 | } |
klauss | 30:8dfb6d8de53d | 330 | |
klauss | 28:94aec56c6329 | 331 | if( !bufptr ){ |
klauss | 28:94aec56c6329 | 332 | miss_match = false; |
klauss | 28:94aec56c6329 | 333 | } |
klauss | 27:98f824719d1c | 334 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "sconfig" )) { |
klauss | 28:94aec56c6329 | 335 | miss_match = false; |
klauss | 27:98f824719d1c | 336 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 337 | files('s'); |
klauss | 38:af5ecd6997ab | 338 | //need mount the string in files s |
klauss | 27:98f824719d1c | 339 | } |
klauss | 27:98f824719d1c | 340 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "format" )) { |
klauss | 28:94aec56c6329 | 341 | miss_match = false; |
klauss | 27:98f824719d1c | 342 | pc.printf("\n Formatando o sistema de arquivos... espere o sistema reiniciar \n\r"); |
klauss | 38:af5ecd6997ab | 343 | |
klauss | 38:af5ecd6997ab | 344 | //nunca retorna por conta da interrupcao |
klauss | 38:af5ecd6997ab | 345 | //if( from_eth ){ |
klauss | 38:af5ecd6997ab | 346 | // snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Formatando o sistema de arquivos... espere o sistema reiniciar\n"); |
klauss | 38:af5ecd6997ab | 347 | // debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 38:af5ecd6997ab | 348 | //} |
klauss | 27:98f824719d1c | 349 | NVIC_SystemReset(); |
klauss | 27:98f824719d1c | 350 | } |
klauss | 27:98f824719d1c | 351 | |
klauss | 28:94aec56c6329 | 352 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ipset ", 6 )) { |
klauss | 28:94aec56c6329 | 353 | miss_match = false; |
klauss | 27:98f824719d1c | 354 | fip = fopen("/qspi/myip.txt", "w"); |
klauss | 29:7246460b73f8 | 355 | fprintf(fip,"%s",(debug_buf+6)); |
klauss | 27:98f824719d1c | 356 | fclose(fip); |
klauss | 27:98f824719d1c | 357 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 358 | files('s'); |
klauss | 27:98f824719d1c | 359 | } |
klauss | 28:94aec56c6329 | 360 | |
klauss | 28:94aec56c6329 | 361 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "extset ", 7 )) { |
klauss | 28:94aec56c6329 | 362 | miss_match = false; |
klauss | 28:94aec56c6329 | 363 | fip = fopen("/qspi/myext.txt", "w"); |
klauss | 31:bb5fb28a77df | 364 | fprintf(fip, "%s" , ( debug_buf + 7) ); |
klauss | 28:94aec56c6329 | 365 | fclose(fip); |
klauss | 28:94aec56c6329 | 366 | pc.printf("\n\r"); |
klauss | 28:94aec56c6329 | 367 | files('s'); |
klauss | 28:94aec56c6329 | 368 | } |
klauss | 28:94aec56c6329 | 369 | |
klauss | 28:94aec56c6329 | 370 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serextset ", 10 )) { |
klauss | 28:94aec56c6329 | 371 | miss_match = false; |
klauss | 28:94aec56c6329 | 372 | fip = fopen("/qspi/peerext.txt", "w"); |
klauss | 28:94aec56c6329 | 373 | fprintf(fip, "%s\n\r" , ( debug_buf + 10 ) ); |
klauss | 28:94aec56c6329 | 374 | fclose(fip); |
klauss | 28:94aec56c6329 | 375 | pc.printf("\n\r"); |
klauss | 28:94aec56c6329 | 376 | files('s'); |
klauss | 28:94aec56c6329 | 377 | } |
klauss | 27:98f824719d1c | 378 | |
klauss | 19:ab2088e0dec6 | 379 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "maskset ",8 )) { |
klauss | 28:94aec56c6329 | 380 | miss_match = false; |
klauss | 27:98f824719d1c | 381 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 27:98f824719d1c | 382 | fprintf(fmask,"%s\n\r",(debug_buf+8)); |
klauss | 27:98f824719d1c | 383 | fclose(fmask); |
klauss | 27:98f824719d1c | 384 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 385 | files('s'); |
klauss | 27:98f824719d1c | 386 | } |
klauss | 27:98f824719d1c | 387 | |
klauss | 19:ab2088e0dec6 | 388 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "gatewayset ",11 )) { |
klauss | 28:94aec56c6329 | 389 | miss_match = false; |
klauss | 27:98f824719d1c | 390 | fgate = fopen("/qspi/mygate.txt", "w"); |
klauss | 27:98f824719d1c | 391 | fprintf(fgate,"%s\n\r",(debug_buf+11)); |
klauss | 27:98f824719d1c | 392 | fclose(fgate); |
klauss | 27:98f824719d1c | 393 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 394 | files('s'); |
klauss | 27:98f824719d1c | 395 | } |
klauss | 27:98f824719d1c | 396 | |
klauss | 27:98f824719d1c | 397 | |
klauss | 27:98f824719d1c | 398 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "msipport ",9 )) { |
klauss | 28:94aec56c6329 | 399 | miss_match = false; |
klauss | 27:98f824719d1c | 400 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 27:98f824719d1c | 401 | fprintf(fport,"%s\n\r",(debug_buf+9)); |
klauss | 27:98f824719d1c | 402 | fclose(fport); |
klauss | 27:98f824719d1c | 403 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 404 | files('s'); |
klauss | 27:98f824719d1c | 405 | } |
klauss | 27:98f824719d1c | 406 | |
klauss | 27:98f824719d1c | 407 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serverip ",9 )) { |
klauss | 28:94aec56c6329 | 408 | miss_match = false; |
klauss | 27:98f824719d1c | 409 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 29:7246460b73f8 | 410 | fprintf(fsip,"%s",(debug_buf+9)); |
klauss | 27:98f824719d1c | 411 | fclose(fsip); |
klauss | 27:98f824719d1c | 412 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 413 | files('s'); |
klauss | 27:98f824719d1c | 414 | } |
klauss | 27:98f824719d1c | 415 | |
klauss | 27:98f824719d1c | 416 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ssport ",7 )) { |
klauss | 28:94aec56c6329 | 417 | miss_match = false; |
klauss | 27:98f824719d1c | 418 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 27:98f824719d1c | 419 | fprintf(fsport,"%s\n\r",(debug_buf+7)); |
klauss | 27:98f824719d1c | 420 | fclose(fsport); |
klauss | 27:98f824719d1c | 421 | pc.printf("\n\r"); |
klauss | 19:ab2088e0dec6 | 422 | files('s'); |
klauss | 27:98f824719d1c | 423 | } |
klauss | 27:98f824719d1c | 424 | |
klauss | 27:98f824719d1c | 425 | |
klauss | 27:98f824719d1c | 426 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dconfig" )) { |
klauss | 28:94aec56c6329 | 427 | miss_match = false; |
klauss | 27:98f824719d1c | 428 | files('w'); |
klauss | 27:98f824719d1c | 429 | files('s'); |
klauss | 27:98f824719d1c | 430 | } |
klauss | 27:98f824719d1c | 431 | |
klauss | 27:98f824719d1c | 432 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset" )) { |
klauss | 28:94aec56c6329 | 433 | miss_match = false; |
klauss | 28:94aec56c6329 | 434 | pc.printf("\n\rJob is done\n\r"); |
klauss | 38:af5ecd6997ab | 435 | if( from_eth ){ |
klauss | 38:af5ecd6997ab | 436 | snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Job is done\n"); |
klauss | 38:af5ecd6997ab | 437 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 38:af5ecd6997ab | 438 | } |
klauss | 27:98f824719d1c | 439 | NVIC_SystemReset(); |
klauss | 27:98f824719d1c | 440 | } |
klauss | 27:98f824719d1c | 441 | |
klauss | 27:98f824719d1c | 442 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dog" )) { |
klauss | 28:94aec56c6329 | 443 | miss_match = false; |
klauss | 27:98f824719d1c | 444 | pc.printf("\n\r MUUUUUUUuuuuUUUUUU - I'm not a dog!!!! \n\r"); |
klauss | 36:728498a78e1e | 445 | if( from_eth ){ |
klauss | 36:728498a78e1e | 446 | snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "MUUUUUUUuuuuUUUUUU - I'm not a dog!!!!\n"); |
klauss | 36:728498a78e1e | 447 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 36:728498a78e1e | 448 | } |
klauss | 27:98f824719d1c | 449 | dog = 0; |
klauss | 27:98f824719d1c | 450 | } |
klauss | 27:98f824719d1c | 451 | |
Cola | 21:0bd688722e81 | 452 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "flood ",6 )) { |
klauss | 27:98f824719d1c | 453 | if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { |
klauss | 28:94aec56c6329 | 454 | miss_match = false; |
klauss | 27:98f824719d1c | 455 | pc.printf("\n\r\t Flood ON\n\r\t"); |
klauss | 38:af5ecd6997ab | 456 | if( from_eth ){ |
klauss | 38:af5ecd6997ab | 457 | snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Flood On\n" ); |
klauss | 38:af5ecd6997ab | 458 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 38:af5ecd6997ab | 459 | } |
klauss | 27:98f824719d1c | 460 | tflood.start(); |
klauss | 27:98f824719d1c | 461 | tflood.reset(); |
klauss | 27:98f824719d1c | 462 | floodcount =0; |
klauss | 27:98f824719d1c | 463 | pflood = 1; |
klauss | 30:8dfb6d8de53d | 464 | flood_timeout.start(); |
klauss | 27:98f824719d1c | 465 | } |
klauss | 27:98f824719d1c | 466 | if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { |
klauss | 28:94aec56c6329 | 467 | miss_match = false; |
klauss | 27:98f824719d1c | 468 | pc.printf("\n\r\t Flood OFF\n\r\t"); |
klauss | 38:af5ecd6997ab | 469 | if( from_eth ){ |
klauss | 38:af5ecd6997ab | 470 | snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Flood Off\n" ); |
klauss | 38:af5ecd6997ab | 471 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 38:af5ecd6997ab | 472 | } |
klauss | 27:98f824719d1c | 473 | pflood = 0; |
klauss | 27:98f824719d1c | 474 | tflood.stop(); |
klauss | 30:8dfb6d8de53d | 475 | flood_timeout.reset(); |
klauss | 27:98f824719d1c | 476 | } |
klauss | 27:98f824719d1c | 477 | } |
klauss | 30:8dfb6d8de53d | 478 | |
Cola | 21:0bd688722e81 | 479 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug ",6 )) { |
klauss | 31:bb5fb28a77df | 480 | if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { |
klauss | 28:94aec56c6329 | 481 | miss_match = false; |
Cola | 21:0bd688722e81 | 482 | pc.printf("\n\r\tDebug ON\n\r\t"); |
klauss | 38:af5ecd6997ab | 483 | if( from_eth ){ |
klauss | 38:af5ecd6997ab | 484 | snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Debug On\n" ); |
klauss | 38:af5ecd6997ab | 485 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 38:af5ecd6997ab | 486 | } |
Cola | 21:0bd688722e81 | 487 | debug_alive = 1; |
klauss | 27:98f824719d1c | 488 | } |
klauss | 31:bb5fb28a77df | 489 | if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { |
klauss | 28:94aec56c6329 | 490 | miss_match = false; |
klauss | 27:98f824719d1c | 491 | pc.printf("\n\r\tDebug OFF\n\r\t"); |
klauss | 38:af5ecd6997ab | 492 | if( from_eth ){ |
klauss | 38:af5ecd6997ab | 493 | snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Debug Off\n" ); |
klauss | 38:af5ecd6997ab | 494 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 38:af5ecd6997ab | 495 | } |
Cola | 21:0bd688722e81 | 496 | debug_alive = 0; |
klauss | 27:98f824719d1c | 497 | } |
klauss | 31:bb5fb28a77df | 498 | if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "show",4 )) { |
klauss | 31:bb5fb28a77df | 499 | miss_match = false; |
klauss | 31:bb5fb28a77df | 500 | pc.printf("\n\rdebug_sip"); |
klauss | 31:bb5fb28a77df | 501 | pc.printf("\n\rdebug_alive"); |
klauss | 31:bb5fb28a77df | 502 | pc.printf("\n\rdebug_prompt"); |
klauss | 31:bb5fb28a77df | 503 | pc.printf("\n\rdebug_vector"); |
klauss | 31:bb5fb28a77df | 504 | pc.printf("\n\rdebug_cb"); |
klauss | 31:bb5fb28a77df | 505 | pc.printf("\n\rdebug_main"); |
klauss | 31:bb5fb28a77df | 506 | pc.printf("\n\rdebug_cks"); |
klauss | 31:bb5fb28a77df | 507 | pc.printf("\n\rdebug_cb_rx"); |
klauss | 31:bb5fb28a77df | 508 | pc.printf("\n\rdebug_cb_tx*"); |
klauss | 31:bb5fb28a77df | 509 | pc.printf("\n\rdebug_eth_rx*"); |
klauss | 31:bb5fb28a77df | 510 | pc.printf("\n\rdebug_eth_tx*"); |
klauss | 31:bb5fb28a77df | 511 | pc.printf("\n\rdebug_file"); |
klauss | 31:bb5fb28a77df | 512 | } |
klauss | 19:ab2088e0dec6 | 513 | } |
klauss | 28:94aec56c6329 | 514 | |
klauss | 28:94aec56c6329 | 515 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_sip ", 10 )) { |
klauss | 28:94aec56c6329 | 516 | if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "on",2 )) { |
klauss | 28:94aec56c6329 | 517 | miss_match = false; |
klauss | 29:7246460b73f8 | 518 | pc.printf( "\n\rSip Debug ON\n\r" ); |
klauss | 28:94aec56c6329 | 519 | debug_sip = 1; |
klauss | 28:94aec56c6329 | 520 | } |
klauss | 28:94aec56c6329 | 521 | if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "off",3 )) { |
klauss | 28:94aec56c6329 | 522 | miss_match = false; |
klauss | 29:7246460b73f8 | 523 | pc.printf( "\n\rSip Debug OFF\n\r" ); |
klauss | 28:94aec56c6329 | 524 | debug_sip = 0; |
klauss | 28:94aec56c6329 | 525 | } |
klauss | 28:94aec56c6329 | 526 | } |
klauss | 31:bb5fb28a77df | 527 | |
klauss | 31:bb5fb28a77df | 528 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cks ", 10 )) { |
klauss | 31:bb5fb28a77df | 529 | if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "on",2 )) { |
klauss | 31:bb5fb28a77df | 530 | miss_match = false; |
klauss | 31:bb5fb28a77df | 531 | pc.printf( "\n\rCKS Debug ON\n\r" ); |
klauss | 31:bb5fb28a77df | 532 | debug_cks = 1; |
klauss | 31:bb5fb28a77df | 533 | } |
klauss | 31:bb5fb28a77df | 534 | if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "off",3 )) { |
klauss | 31:bb5fb28a77df | 535 | miss_match = false; |
klauss | 31:bb5fb28a77df | 536 | pc.printf( "\n\rCKS Debug OFF\n\r" ); |
klauss | 31:bb5fb28a77df | 537 | debug_cks = 0; |
klauss | 31:bb5fb28a77df | 538 | } |
klauss | 31:bb5fb28a77df | 539 | } |
klauss | 31:bb5fb28a77df | 540 | |
klauss | 38:af5ecd6997ab | 541 | //promptcb ramal porta comando |
klauss | 38:af5ecd6997ab | 542 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "promptcb ", 9)) { |
klauss | 38:af5ecd6997ab | 543 | miss_match = false; |
klauss | 27:98f824719d1c | 544 | static int id_msg = 0x10; |
Cola | 21:0bd688722e81 | 545 | uint8_t write_buffer[300]; |
Cola | 21:0bd688722e81 | 546 | unsigned int ext,port; |
Cola | 21:0bd688722e81 | 547 | int ant1,ant2; |
klauss | 27:98f824719d1c | 548 | |
Cola | 21:0bd688722e81 | 549 | debug_buf[bufptr++] = 0x0D; |
Cola | 21:0bd688722e81 | 550 | debug_buf[bufptr++] = 0x00; |
klauss | 27:98f824719d1c | 551 | |
Cola | 21:0bd688722e81 | 552 | ant1 = str2uint( (debug_buf+9), &ext); |
Cola | 21:0bd688722e81 | 553 | ant2 = str2uint( ((debug_buf+9)+ant1+1), &port); |
klauss | 27:98f824719d1c | 554 | |
klauss | 29:7246460b73f8 | 555 | promptcb_last_ext = ext; |
klauss | 29:7246460b73f8 | 556 | promptcb_last_port = port; |
klauss | 29:7246460b73f8 | 557 | pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",ext, port, debug_buf+9+ant1+2+ant2); |
klauss | 29:7246460b73f8 | 558 | promptcb_last_ext = ext; |
klauss | 29:7246460b73f8 | 559 | __send_to_cb__( __build_cb_package__( ext, port, __PROMPT__, debug_buf+9+ant1+2+ant2, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 29:7246460b73f8 | 560 | pc.printf("\n\rComando enviado\n\r"); |
klauss | 29:7246460b73f8 | 561 | } |
klauss | 29:7246460b73f8 | 562 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "pcb ",4 )) { |
klauss | 38:af5ecd6997ab | 563 | miss_match = false; |
klauss | 29:7246460b73f8 | 564 | static int id_msg = 0x30; |
klauss | 29:7246460b73f8 | 565 | uint8_t write_buffer[300]; |
klauss | 29:7246460b73f8 | 566 | debug_buf[bufptr++] = 0x0D; |
klauss | 29:7246460b73f8 | 567 | debug_buf[bufptr++] = 0x00; |
klauss | 27:98f824719d1c | 568 | |
klauss | 29:7246460b73f8 | 569 | pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",promptcb_last_ext, promptcb_last_port, debug_buf+4); |
klauss | 29:7246460b73f8 | 570 | |
klauss | 29:7246460b73f8 | 571 | __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 | 29:7246460b73f8 | 572 | pc.printf("\n\rComando enviado\n\r"); |
klauss | 19:ab2088e0dec6 | 573 | } |
klauss | 27:98f824719d1c | 574 | |
Cola | 22:d2a4b5939115 | 575 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "cks",3 )) { |
klauss | 28:94aec56c6329 | 576 | miss_match = false; |
klauss | 27:98f824719d1c | 577 | pcks_s = 1; |
Cola | 22:d2a4b5939115 | 578 | } |
klauss | 27:98f824719d1c | 579 | |
Cola | 24:270b436a1bb0 | 580 | if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "showcb",6 )) { |
klauss | 28:94aec56c6329 | 581 | miss_match = false; |
Cola | 24:270b436a1bb0 | 582 | pshowcb = 1; |
Cola | 24:270b436a1bb0 | 583 | } |
klauss | 27:98f824719d1c | 584 | |
klauss | 38:af5ecd6997ab | 585 | if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_main ", 11 )) { |
klauss | 38:af5ecd6997ab | 586 | if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "on",2 )) { |
klauss | 28:94aec56c6329 | 587 | miss_match = false; |
klauss | 38:af5ecd6997ab | 588 | pc.printf("\r\nDebug Main ON"); |
klauss | 38:af5ecd6997ab | 589 | debug_main = 1; |
klauss | 27:98f824719d1c | 590 | } |
klauss | 38:af5ecd6997ab | 591 | if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { |
klauss | 28:94aec56c6329 | 592 | miss_match = false; |
klauss | 38:af5ecd6997ab | 593 | pc.printf("\r\nDebug Main OFF"); |
klauss | 38:af5ecd6997ab | 594 | debug_main = 0; |
klauss | 27:98f824719d1c | 595 | } |
klauss | 27:98f824719d1c | 596 | } |
klauss | 31:bb5fb28a77df | 597 | |
klauss | 31:bb5fb28a77df | 598 | if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cb_rx ", 12 )) { |
klauss | 31:bb5fb28a77df | 599 | if (xmemmatch( (uint8_t*)( debug_buf + 12 ), (uint8_t*) "on",2 )) { |
klauss | 31:bb5fb28a77df | 600 | miss_match = false; |
klauss | 31:bb5fb28a77df | 601 | pc.printf("\tDebug Cbx Rx ON"); |
klauss | 31:bb5fb28a77df | 602 | debug_cb_rx = 1; |
klauss | 31:bb5fb28a77df | 603 | } |
klauss | 31:bb5fb28a77df | 604 | if (xmemmatch( (uint8_t*)( debug_buf + 12 ), (uint8_t*) "off",3 )) { |
klauss | 31:bb5fb28a77df | 605 | miss_match = false; |
klauss | 31:bb5fb28a77df | 606 | pc.printf("Debug Cbx Rx OFF"); |
klauss | 31:bb5fb28a77df | 607 | debug_cb_rx = 0; |
klauss | 31:bb5fb28a77df | 608 | } |
klauss | 31:bb5fb28a77df | 609 | } |
klauss | 31:bb5fb28a77df | 610 | |
klauss | 31:bb5fb28a77df | 611 | if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_file ", 11 )) { |
klauss | 31:bb5fb28a77df | 612 | if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "on",2 )) { |
klauss | 31:bb5fb28a77df | 613 | miss_match = false; |
klauss | 31:bb5fb28a77df | 614 | pc.printf("\tDebug File ON"); |
klauss | 31:bb5fb28a77df | 615 | debug_cb_rx = 1; |
klauss | 31:bb5fb28a77df | 616 | } |
klauss | 31:bb5fb28a77df | 617 | if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { |
klauss | 31:bb5fb28a77df | 618 | miss_match = false; |
klauss | 31:bb5fb28a77df | 619 | pc.printf("Debug File OFF"); |
klauss | 31:bb5fb28a77df | 620 | debug_cb_rx = 0; |
klauss | 31:bb5fb28a77df | 621 | } |
klauss | 31:bb5fb28a77df | 622 | } |
klauss | 31:bb5fb28a77df | 623 | |
klauss | 19:ab2088e0dec6 | 624 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "help" )) { |
klauss | 28:94aec56c6329 | 625 | miss_match = false; |
klauss | 27:98f824719d1c | 626 | pc.printf("\n\r****************************PROMPT HELP******************\n\r"); |
klauss | 27:98f824719d1c | 627 | pc.printf("sconfig - mostra o arquivo de configuracao do sistema\n\r"); |
klauss | 27:98f824719d1c | 628 | pc.printf("dconfig - volta as configuracoes do sistema para o padrao de fabrica\n\r"); |
klauss | 27:98f824719d1c | 629 | pc.printf("callme [ramal porta] - envia o pedido de ligacao para o callbox com o ramal e porta indicada\n\r"); |
klauss | 27:98f824719d1c | 630 | pc.printf("promptcb ramal porta comando - envia o <comando> para o cbx <ramal> e <porta> executar\n\r"); |
klauss | 27:98f824719d1c | 631 | pc.printf("format - formata o sistema de arquivos\n\r"); |
klauss | 27:98f824719d1c | 632 | pc.printf("reset - resta o sistema\n\r"); |
klauss | 27:98f824719d1c | 633 | pc.printf("ipset [ip] - Configura o IP da cabeceira\n\r"); |
klauss | 28:94aec56c6329 | 634 | pc.printf("extset [ext] - Configura a ext da cabeceira\n\r"); |
klauss | 28:94aec56c6329 | 635 | pc.printf("msipport [port] - Configura a porta SIP da cabeceira\n\r"); |
klauss | 28:94aec56c6329 | 636 | pc.printf("serverip [ip] - Configura o ip do servidor asterisk\n\r"); |
klauss | 28:94aec56c6329 | 637 | pc.printf("serextset [ext] - Configura a server ext da cabeceira\n\r"); |
klauss | 28:94aec56c6329 | 638 | pc.printf("ssport [port] - Configura a porta SIP do servidor asterisk\n\r"); |
klauss | 27:98f824719d1c | 639 | pc.printf("maskset [mask] - Configura a mascara da cabeceira\n\r"); |
klauss | 27:98f824719d1c | 640 | pc.printf("gatewayset [gateway] - Configura o gateway da cabeceira\n\r"); |
klauss | 27:98f824719d1c | 641 | pc.printf("showcb - lista os Cbx registrados na header\n\r"); |
klauss | 27:98f824719d1c | 642 | pc.printf("cks - exibe estatisticas de check sum\n\r"); |
klauss | 31:bb5fb28a77df | 643 | pc.printf(". - executa o comando anterior novamente\n\r"); |
klauss | 31:bb5fb28a77df | 644 | pc.printf("debug [on|off|show] - seleciona debugs gerais | lista de debugs \n\r"); |
klauss | 27:98f824719d1c | 645 | pc.printf("flood [on|off] - simula envio de pacotes de audio\n\r"); |
klauss | 28:94aec56c6329 | 646 | pc.printf("PROMPT VERSION: V%d\n\r",PVERSION); |
klauss | 27:98f824719d1c | 647 | } |
klauss | 27:98f824719d1c | 648 | /* |
klauss | 19:ab2088e0dec6 | 649 | if ( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "callme ", 7 )) { |
klauss | 19:ab2088e0dec6 | 650 | if ( debug_buf[16] != 0 && debug_buf[11] != 0x20 ) |
klauss | 19:ab2088e0dec6 | 651 | pc.printf("\n\r Error: formato errado! ramal=xxxx porta=xxxx \n\r"); |
klauss | 19:ab2088e0dec6 | 652 | else { |
klauss | 19:ab2088e0dec6 | 653 | uint8_t data[300]; |
klauss | 19:ab2088e0dec6 | 654 | uint16_t cks=0; |
klauss | 27:98f824719d1c | 655 | |
klauss | 19:ab2088e0dec6 | 656 | //data[0] = (uint8_t)( (debug_buf[7]&0xf0)<<4 + (debug_buf[8]&0x0f) ) ; |
klauss | 19:ab2088e0dec6 | 657 | //data[1] = (uint8_t)( (debug_buf[9]&0xf0)<<4 + (debug_buf[10]&0x0f) ) ; |
klauss | 19:ab2088e0dec6 | 658 | //data[2] = (uint8_t)( (debug_buf[12]&0xf0)<<4 + (debug_buf[13]&0x0f) ) ; |
klauss | 19:ab2088e0dec6 | 659 | /data[3] = (uint8_t)( (debug_buf[14]&0xf0)<<4 + (debug_buf[15]&0x0f) ) ; |
klauss | 27:98f824719d1c | 660 | |
klauss | 19:ab2088e0dec6 | 661 | data[0] = (uint8_t)( debug_buf[ 7 ] & 0xFF00 >> 8 ); |
klauss | 19:ab2088e0dec6 | 662 | data[1] = (uint8_t)( debug_buf[ 9 ] & 0x00FF ); |
klauss | 19:ab2088e0dec6 | 663 | data[2] = (uint8_t)( debug_buf[ 12 ] & 0xFF00 >> 8 ); |
klauss | 19:ab2088e0dec6 | 664 | data[3] = (uint8_t)( debug_buf[ 14 ] & 0x00FF ); |
klauss | 27:98f824719d1c | 665 | |
klauss | 19:ab2088e0dec6 | 666 | data[6] = 0x04; |
klauss | 19:ab2088e0dec6 | 667 | for (int i = 7; i < 300; i++) data[i] = 0x00; |
klauss | 19:ab2088e0dec6 | 668 | cks = __checksum__(data,300); |
klauss | 19:ab2088e0dec6 | 669 | data[4] = cks>>8; |
klauss | 19:ab2088e0dec6 | 670 | data[5] = cks&0xff; |
klauss | 27:98f824719d1c | 671 | |
klauss | 19:ab2088e0dec6 | 672 | pc.printf("\n\r"); |
klauss | 19:ab2088e0dec6 | 673 | for( int i = 0; i < 300; i++ ) |
klauss | 19:ab2088e0dec6 | 674 | pc.printf("%x ", data[ i ] ); |
klauss | 19:ab2088e0dec6 | 675 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 676 | |
klauss | 19:ab2088e0dec6 | 677 | xmemcpy(TXBuffer,data,300); |
klauss | 27:98f824719d1c | 678 | |
klauss | 19:ab2088e0dec6 | 679 | pc.printf("\n\r"); |
klauss | 19:ab2088e0dec6 | 680 | for( int i = 0; i < 300; i++ ) |
klauss | 19:ab2088e0dec6 | 681 | pc.printf("%x ", data[ i ] ); |
klauss | 19:ab2088e0dec6 | 682 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 683 | |
klauss | 19:ab2088e0dec6 | 684 | send2callboxes(); |
klauss | 27:98f824719d1c | 685 | |
klauss | 19:ab2088e0dec6 | 686 | pc.printf("\n\r calling callbox %s \n\r",debug_buf+7); |
klauss | 19:ab2088e0dec6 | 687 | } |
klauss | 19:ab2088e0dec6 | 688 | |
klauss | 19:ab2088e0dec6 | 689 | } |
klauss | 27:98f824719d1c | 690 | */ |
klauss | 30:8dfb6d8de53d | 691 | |
klauss | 38:af5ecd6997ab | 692 | if( miss_match ){ |
klauss | 38:af5ecd6997ab | 693 | pc.printf("\n\r%s: command not found\n\r", debug_buf ); |
klauss | 38:af5ecd6997ab | 694 | if( from_eth ){ |
klauss | 38:af5ecd6997ab | 695 | snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "%s: command not found\n", debug_buf ); |
klauss | 38:af5ecd6997ab | 696 | debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; |
klauss | 38:af5ecd6997ab | 697 | } |
klauss | 38:af5ecd6997ab | 698 | } |
klauss | 30:8dfb6d8de53d | 699 | |
klauss | 30:8dfb6d8de53d | 700 | else strcpy( last_debug_buf, debug_buf ); |
klauss | 19:ab2088e0dec6 | 701 | } |
klauss | 36:728498a78e1e | 702 | if( from_eth ){ |
klauss | 41:69bf7091c2ca | 703 | if( tcp_pkg ){ |
klauss | 41:69bf7091c2ca | 704 | debug_msg(""); |
klauss | 41:69bf7091c2ca | 705 | client.send_all( debug_buf, bufptr ); |
klauss | 41:69bf7091c2ca | 706 | tcp_pkg = false; |
klauss | 41:69bf7091c2ca | 707 | tcp_timer.reset(); |
klauss | 41:69bf7091c2ca | 708 | return( NULL ); |
klauss | 41:69bf7091c2ca | 709 | } |
klauss | 41:69bf7091c2ca | 710 | |
klauss | 41:69bf7091c2ca | 711 | msg_to_eth = debug_buf; |
klauss | 36:728498a78e1e | 712 | debug_buf = __debug_buf__; |
klauss | 36:728498a78e1e | 713 | bufptr = last_bufptr; |
klauss | 36:728498a78e1e | 714 | bufret = 0; |
klauss | 36:728498a78e1e | 715 | from_eth = false; |
klauss | 41:69bf7091c2ca | 716 | |
klauss | 36:728498a78e1e | 717 | if( miss_match ) return( NULL ); |
klauss | 36:728498a78e1e | 718 | |
klauss | 41:69bf7091c2ca | 719 | else return( msg_to_eth ); |
klauss | 36:728498a78e1e | 720 | } |
klauss | 28:94aec56c6329 | 721 | if ( b == 0x0D || bufret == 1 || bufptr > DEBUGBUFSIZE ) { |
klauss | 27:98f824719d1c | 722 | bufptr = 0; |
klauss | 27:98f824719d1c | 723 | for (uint8_t i =0; i < DEBUGBUFSIZE; i++) { |
klauss | 27:98f824719d1c | 724 | debug_buf[i] = 0; |
klauss | 19:ab2088e0dec6 | 725 | } |
klauss | 27:98f824719d1c | 726 | bufret = 0; |
klauss | 27:98f824719d1c | 727 | pc.putc(0x0A); |
klauss | 27:98f824719d1c | 728 | pc.putc(0x0D); |
klauss | 29:7246460b73f8 | 729 | pc.printf("> "); |
klauss | 36:728498a78e1e | 730 | } |
klauss | 36:728498a78e1e | 731 | return( NULL ); |
klauss | 28:94aec56c6329 | 732 | } |