![](/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@28:94aec56c6329, 2014-09-23 (annotated)
- Committer:
- klauss
- Date:
- Tue Sep 23 18:28:37 2014 +0000
- Revision:
- 28:94aec56c6329
- Parent:
- 27:98f824719d1c
- Child:
- 29:7246460b73f8
- peet ext and my ext setable from prompt
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 | 19:ab2088e0dec6 | 9 | //#include "debug.h" |
klauss | 19:ab2088e0dec6 | 10 | |
klauss | 28:94aec56c6329 | 11 | uint8_t debug_alive = 0; |
klauss | 28:94aec56c6329 | 12 | uint8_t debug_sip = 0; |
Cola | 22:d2a4b5939115 | 13 | uint8_t pcks_s = 0; |
Cola | 24:270b436a1bb0 | 14 | uint8_t pshowcb = 0; |
klauss | 28:94aec56c6329 | 15 | |
klauss | 28:94aec56c6329 | 16 | uint8_t test_debug = 0; |
klauss | 19:ab2088e0dec6 | 17 | #define PVERSION 1 // Sempre atualizar a versao do prompt |
klauss | 19:ab2088e0dec6 | 18 | |
Cola | 21:0bd688722e81 | 19 | #define DEBUGBUFSIZE 50 |
klauss | 19:ab2088e0dec6 | 20 | char debug_buf[DEBUGBUFSIZE]; |
klauss | 28:94aec56c6329 | 21 | FILE *fip, *fmask, *fgate, *fport, *fsip, *fsport, *fext, *fserext; |
klauss | 19:ab2088e0dec6 | 22 | uint8_t dog = 1; |
klauss | 19:ab2088e0dec6 | 23 | uint8_t debug_prompt = 0; |
klauss | 19:ab2088e0dec6 | 24 | uint8_t bufptr = 0; |
klauss | 19:ab2088e0dec6 | 25 | |
klauss | 19:ab2088e0dec6 | 26 | 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 | 27 | while (size--) { |
klauss | 19:ab2088e0dec6 | 28 | if (*s1++ != *s2++) return 0; /* does not match */ |
klauss | 19:ab2088e0dec6 | 29 | } |
klauss | 19:ab2088e0dec6 | 30 | return 1; /* matches */ |
klauss | 19:ab2088e0dec6 | 31 | } |
klauss | 19:ab2088e0dec6 | 32 | |
klauss | 19:ab2088e0dec6 | 33 | uint8_t xstrmatch(const uint8_t * s1, const uint8_t * s2) { // presente na lib.h pode retirar da versao final |
klauss | 19:ab2088e0dec6 | 34 | while (*s1) { |
klauss | 19:ab2088e0dec6 | 35 | if (*s1++ != *s2++) return 0; /* does not match */ |
klauss | 19:ab2088e0dec6 | 36 | } |
klauss | 19:ab2088e0dec6 | 37 | if ( *s2 == 0 ) |
klauss | 19:ab2088e0dec6 | 38 | return 1; /* matches */ |
klauss | 19:ab2088e0dec6 | 39 | else |
klauss | 19:ab2088e0dec6 | 40 | return 0; /* does not match */ |
klauss | 19:ab2088e0dec6 | 41 | } |
klauss | 19:ab2088e0dec6 | 42 | |
klauss | 19:ab2088e0dec6 | 43 | void xmemcpy(uint8_t * dest, const uint8_t * src, uint16_t size) { // presente na lib.h pode retirar da versao final |
klauss | 19:ab2088e0dec6 | 44 | while (size--) *dest++ = *src++; |
klauss | 19:ab2088e0dec6 | 45 | } |
klauss | 19:ab2088e0dec6 | 46 | |
Cola | 21:0bd688722e81 | 47 | int str2uint (char * s, unsigned int * val) { |
Cola | 21:0bd688722e81 | 48 | int i = 0; |
Cola | 21:0bd688722e81 | 49 | unsigned int ret = 0; |
Cola | 21:0bd688722e81 | 50 | for (;;) { |
Cola | 21:0bd688722e81 | 51 | if (s[i] < '0') { |
Cola | 21:0bd688722e81 | 52 | *val = ret; |
Cola | 21:0bd688722e81 | 53 | return i; |
Cola | 21:0bd688722e81 | 54 | } |
Cola | 21:0bd688722e81 | 55 | ret *= 10; |
Cola | 21:0bd688722e81 | 56 | ret += s[i] - '0'; |
Cola | 21:0bd688722e81 | 57 | i++; |
Cola | 21:0bd688722e81 | 58 | } |
Cola | 21:0bd688722e81 | 59 | } |
klauss | 19:ab2088e0dec6 | 60 | |
klauss | 19:ab2088e0dec6 | 61 | void cat(const char* fname) // Print the content of a given file |
klauss | 19:ab2088e0dec6 | 62 | { |
klauss | 19:ab2088e0dec6 | 63 | char buff[513]; |
klauss | 19:ab2088e0dec6 | 64 | int num; |
klauss | 19:ab2088e0dec6 | 65 | |
klauss | 19:ab2088e0dec6 | 66 | FILE *fp = fopen(fname, "r"); |
klauss | 19:ab2088e0dec6 | 67 | if (fp == NULL) { |
klauss | 28:94aec56c6329 | 68 | pc.printf("Failed to open %s", fname); |
klauss | 19:ab2088e0dec6 | 69 | return; |
klauss | 19:ab2088e0dec6 | 70 | } |
klauss | 19:ab2088e0dec6 | 71 | |
klauss | 19:ab2088e0dec6 | 72 | while ((num = fread(buff, 1, 512, fp)) > 0) |
klauss | 19:ab2088e0dec6 | 73 | { |
klauss | 19:ab2088e0dec6 | 74 | buff[num] = '\0'; |
klauss | 19:ab2088e0dec6 | 75 | pc.printf(buff); |
klauss | 19:ab2088e0dec6 | 76 | |
klauss | 19:ab2088e0dec6 | 77 | } |
klauss | 19:ab2088e0dec6 | 78 | fclose(fp); |
klauss | 19:ab2088e0dec6 | 79 | } |
klauss | 19:ab2088e0dec6 | 80 | |
klauss | 28:94aec56c6329 | 81 | // operantion with the system config files |
klauss | 28:94aec56c6329 | 82 | void files (const char type) { |
klauss | 19:ab2088e0dec6 | 83 | if (type == 's' ){ // show files |
klauss | 19:ab2088e0dec6 | 84 | pc.printf("\n\r"); |
klauss | 28:94aec56c6329 | 85 | pc.printf("Header IP " ); |
klauss | 19:ab2088e0dec6 | 86 | cat("/qspi/myip.txt"); |
klauss | 28:94aec56c6329 | 87 | pc.printf("\n\rHeader ext "); |
klauss | 28:94aec56c6329 | 88 | cat("/qspi/myext.txt"); |
klauss | 28:94aec56c6329 | 89 | pc.printf("\n\rHeader port "); |
klauss | 28:94aec56c6329 | 90 | cat("/qspi/mysipport.txt"); |
klauss | 28:94aec56c6329 | 91 | |
klauss | 28:94aec56c6329 | 92 | pc.printf("\n\rServer ip "); |
klauss | 28:94aec56c6329 | 93 | cat("/qspi/serverip.txt"); |
klauss | 28:94aec56c6329 | 94 | pc.printf("\n\rServer ext "); |
klauss | 28:94aec56c6329 | 95 | cat("/qspi/peerext.txt"); |
klauss | 28:94aec56c6329 | 96 | pc.printf("\n\rServer port "); |
klauss | 28:94aec56c6329 | 97 | cat("/qspi/serverport.txt"); |
klauss | 28:94aec56c6329 | 98 | |
klauss | 28:94aec56c6329 | 99 | pc.printf("\n\rMascara de rede "); |
klauss | 19:ab2088e0dec6 | 100 | cat("/qspi/mymask.txt"); |
klauss | 28:94aec56c6329 | 101 | pc.printf("\n\rGateway IP "); |
klauss | 19:ab2088e0dec6 | 102 | cat("/qspi/mygate.txt"); |
klauss | 19:ab2088e0dec6 | 103 | } |
klauss | 19:ab2088e0dec6 | 104 | |
klauss | 19:ab2088e0dec6 | 105 | if (type == 'c' ){ // close all files |
klauss | 28:94aec56c6329 | 106 | fclose( fip ); |
klauss | 28:94aec56c6329 | 107 | fclose( fmask ); |
klauss | 28:94aec56c6329 | 108 | fclose( fgate ); |
klauss | 28:94aec56c6329 | 109 | fclose( fport ); |
klauss | 28:94aec56c6329 | 110 | fclose( fsip ); |
klauss | 28:94aec56c6329 | 111 | fclose( fsport ); |
klauss | 28:94aec56c6329 | 112 | fclose( fext ); |
klauss | 28:94aec56c6329 | 113 | fclose( fserext ); |
klauss | 19:ab2088e0dec6 | 114 | } |
klauss | 19:ab2088e0dec6 | 115 | |
klauss | 19:ab2088e0dec6 | 116 | if (type == 'i' ){ // Check if files exist, if not create the files |
klauss | 19:ab2088e0dec6 | 117 | fip = fopen("/qspi/myip.txt", "r"); |
klauss | 19:ab2088e0dec6 | 118 | if (fip == NULL){ |
klauss | 19:ab2088e0dec6 | 119 | fip = fopen("/qspi/myip.txt", "w"); |
klauss | 27:98f824719d1c | 120 | fprintf(fip, "%s\n\r",__MY_IP__); //myip |
klauss | 19:ab2088e0dec6 | 121 | } |
klauss | 28:94aec56c6329 | 122 | |
klauss | 28:94aec56c6329 | 123 | fserext = fopen("/qspi/myext.txt", "r"); |
klauss | 28:94aec56c6329 | 124 | if ( fserext == NULL ){ |
klauss | 28:94aec56c6329 | 125 | fserext = fopen("/qspi/myext.txt", "w"); |
klauss | 28:94aec56c6329 | 126 | fprintf( fserext, "%i\n\r" ,__MY_EXT__ ); //asterisk ext |
klauss | 28:94aec56c6329 | 127 | } |
klauss | 28:94aec56c6329 | 128 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 28:94aec56c6329 | 129 | if (fport == NULL){ |
klauss | 28:94aec56c6329 | 130 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 28:94aec56c6329 | 131 | fprintf(fport, "%i\n\r",__MY_PORT__); //mysipport |
klauss | 28:94aec56c6329 | 132 | } |
klauss | 28:94aec56c6329 | 133 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 28:94aec56c6329 | 134 | if (fsip == NULL){ |
klauss | 28:94aec56c6329 | 135 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 28:94aec56c6329 | 136 | fprintf(fsip, "%s\n\r",__SERVER_IP__ ); //asterisk ip |
klauss | 28:94aec56c6329 | 137 | } |
klauss | 28:94aec56c6329 | 138 | |
klauss | 28:94aec56c6329 | 139 | fext = fopen("/qspi/peerext.txt", "r"); |
klauss | 28:94aec56c6329 | 140 | if ( fext == NULL ){ |
klauss | 28:94aec56c6329 | 141 | fext = fopen("/qspi/peerext.txt", "w"); |
klauss | 28:94aec56c6329 | 142 | fprintf( fext, "%d\n\r",__PEER_EXT__ ); //asterisk ip |
klauss | 28:94aec56c6329 | 143 | } |
klauss | 28:94aec56c6329 | 144 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 28:94aec56c6329 | 145 | if (fsport == NULL){ |
klauss | 28:94aec56c6329 | 146 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 28:94aec56c6329 | 147 | fprintf(fsport, "%i\n\r",__SERVER_PORT__ ); //asterisk port |
klauss | 28:94aec56c6329 | 148 | pc.printf("\n\r Default configurations set! \n\r"); |
klauss | 28:94aec56c6329 | 149 | } |
klauss | 28:94aec56c6329 | 150 | |
klauss | 19:ab2088e0dec6 | 151 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 19:ab2088e0dec6 | 152 | if (fmask == NULL){ |
klauss | 19:ab2088e0dec6 | 153 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 28:94aec56c6329 | 154 | fprintf(fmask, "%s\n\r",__MY_MSK__); //mymask |
klauss | 19:ab2088e0dec6 | 155 | } |
klauss | 19:ab2088e0dec6 | 156 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 19:ab2088e0dec6 | 157 | if (fgate == NULL){ |
klauss | 19:ab2088e0dec6 | 158 | fgate = fopen("/qspi/mygate.txt", "w"); |
klauss | 28:94aec56c6329 | 159 | fprintf(fgate, "%s\n\r",__MY_GTW__); //mygateway |
klauss | 19:ab2088e0dec6 | 160 | } |
klauss | 19:ab2088e0dec6 | 161 | } |
klauss | 19:ab2088e0dec6 | 162 | |
klauss | 19:ab2088e0dec6 | 163 | if (type == 'r' ){ // Just open for read |
klauss | 19:ab2088e0dec6 | 164 | fip = fopen("/qspi/myip.txt", "r"); |
klauss | 19:ab2088e0dec6 | 165 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 19:ab2088e0dec6 | 166 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 19:ab2088e0dec6 | 167 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 19:ab2088e0dec6 | 168 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 19:ab2088e0dec6 | 169 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 28:94aec56c6329 | 170 | fext = fopen( "/qspi/myext.txt", "r" ); |
klauss | 28:94aec56c6329 | 171 | fserext = fopen( "/qspi/peerext.txt", "r" ); |
klauss | 19:ab2088e0dec6 | 172 | } |
klauss | 19:ab2088e0dec6 | 173 | |
klauss | 19:ab2088e0dec6 | 174 | if (type == 'w'){ // Create and write the default configs |
klauss | 19:ab2088e0dec6 | 175 | fip = fopen("/qspi/myip.txt", "w"); |
klauss | 19:ab2088e0dec6 | 176 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 19:ab2088e0dec6 | 177 | fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 19:ab2088e0dec6 | 178 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 19:ab2088e0dec6 | 179 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 19:ab2088e0dec6 | 180 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 28:94aec56c6329 | 181 | fext = fopen( "/qspi/myext.txt", "w" ); |
klauss | 28:94aec56c6329 | 182 | fserext = fopen( "/qspi/peerext.txt", "w" ); |
klauss | 19:ab2088e0dec6 | 183 | |
klauss | 28:94aec56c6329 | 184 | fprintf( fip, "%s\n\r", __MY_IP__ ); //myip |
klauss | 28:94aec56c6329 | 185 | fprintf( fport, "%d\n\r", __MY_PORT__ ); //mysipport |
klauss | 28:94aec56c6329 | 186 | //fprintf( fext, "%d\n\r", __MY_EXT__ ); //myext |
klauss | 28:94aec56c6329 | 187 | fprintf( fext, "%d\n\r", 820 ); //myext |
klauss | 28:94aec56c6329 | 188 | |
klauss | 28:94aec56c6329 | 189 | fprintf( fsip, "%s\n\r", __SERVER_IP__ ); //asterisk ip |
klauss | 28:94aec56c6329 | 190 | fprintf( fserext, "%d\n\r",__PEER_EXT__ ); //asterisk port |
klauss | 28:94aec56c6329 | 191 | fprintf( fsport, "%d\n\r",__SERVER_PORT__ ); //asterisk port |
klauss | 28:94aec56c6329 | 192 | |
klauss | 28:94aec56c6329 | 193 | fprintf( fmask, "%s\n\r",__MY_MSK__ ); //mymask |
klauss | 28:94aec56c6329 | 194 | fprintf( fgate, "%s\n\r", __MY_GTW__ ); //mygateway |
klauss | 19:ab2088e0dec6 | 195 | |
klauss | 19:ab2088e0dec6 | 196 | files('c'); |
klauss | 19:ab2088e0dec6 | 197 | |
klauss | 19:ab2088e0dec6 | 198 | pc.printf("\n\r Default configurations set! \n\r"); |
klauss | 19:ab2088e0dec6 | 199 | |
klauss | 19:ab2088e0dec6 | 200 | } |
klauss | 19:ab2088e0dec6 | 201 | |
klauss | 19:ab2088e0dec6 | 202 | } |
klauss | 19:ab2088e0dec6 | 203 | |
klauss | 26:725cbbedadd5 | 204 | void init_fsystem(){ |
klauss | 26:725cbbedadd5 | 205 | // init file system and check if files exist |
klauss | 26:725cbbedadd5 | 206 | if (!qspifs.isformatted()) { |
klauss | 26:725cbbedadd5 | 207 | qspifs.format(); |
klauss | 26:725cbbedadd5 | 208 | pc.printf("File system configured!!\n\r"); |
klauss | 26:725cbbedadd5 | 209 | } |
klauss | 26:725cbbedadd5 | 210 | files('i'); // check if the files are created |
klauss | 26:725cbbedadd5 | 211 | files('c'); |
klauss | 26:725cbbedadd5 | 212 | pc.printf("*******System Ready*******\n\r"); |
klauss | 19:ab2088e0dec6 | 213 | } |
klauss | 19:ab2088e0dec6 | 214 | |
klauss | 28:94aec56c6329 | 215 | // main prompt process |
klauss | 28:94aec56c6329 | 216 | void prompt_process(){ |
klauss | 28:94aec56c6329 | 217 | //FIXME dar flush na serial |
klauss | 28:94aec56c6329 | 218 | |
klauss | 19:ab2088e0dec6 | 219 | volatile char b = 0; |
klauss | 19:ab2088e0dec6 | 220 | static uint8_t bufret = 0; |
klauss | 19:ab2088e0dec6 | 221 | |
klauss | 27:98f824719d1c | 222 | if ( pc.readable() ){ |
klauss | 26:725cbbedadd5 | 223 | // imput do teclado |
klauss | 19:ab2088e0dec6 | 224 | b = pc.getc(); |
klauss | 19:ab2088e0dec6 | 225 | |
klauss | 27:98f824719d1c | 226 | if ( b == 0x0D ){ // enter |
klauss | 27:98f824719d1c | 227 | bufret = 1; |
klauss | 19:ab2088e0dec6 | 228 | } |
klauss | 19:ab2088e0dec6 | 229 | else{ |
klauss | 27:98f824719d1c | 230 | pc.putc(b); |
klauss | 27:98f824719d1c | 231 | debug_buf[bufptr] = b; |
klauss | 27:98f824719d1c | 232 | bufptr++; |
klauss | 19:ab2088e0dec6 | 233 | } |
klauss | 19:ab2088e0dec6 | 234 | } |
klauss | 19:ab2088e0dec6 | 235 | |
klauss | 28:94aec56c6329 | 236 | // Prompt commands here |
klauss | 28:94aec56c6329 | 237 | if (bufret == 1) { |
klauss | 28:94aec56c6329 | 238 | bool miss_match = true; |
klauss | 28:94aec56c6329 | 239 | |
klauss | 28:94aec56c6329 | 240 | if( !bufptr ){ |
klauss | 28:94aec56c6329 | 241 | miss_match = false; |
klauss | 28:94aec56c6329 | 242 | } |
klauss | 27:98f824719d1c | 243 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "sconfig" )) { |
klauss | 28:94aec56c6329 | 244 | miss_match = false; |
klauss | 27:98f824719d1c | 245 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 246 | files('s'); |
klauss | 27:98f824719d1c | 247 | } |
klauss | 27:98f824719d1c | 248 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "format" )) { |
klauss | 28:94aec56c6329 | 249 | miss_match = false; |
klauss | 27:98f824719d1c | 250 | pc.printf("\n Formatando o sistema de arquivos... espere o sistema reiniciar \n\r"); |
klauss | 27:98f824719d1c | 251 | //qspifs.format(); |
klauss | 27:98f824719d1c | 252 | NVIC_SystemReset(); |
klauss | 27:98f824719d1c | 253 | } |
klauss | 27:98f824719d1c | 254 | |
klauss | 28:94aec56c6329 | 255 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ipset ", 6 )) { |
klauss | 28:94aec56c6329 | 256 | miss_match = false; |
klauss | 27:98f824719d1c | 257 | fip = fopen("/qspi/myip.txt", "w"); |
klauss | 27:98f824719d1c | 258 | fprintf(fip,"%s\n\r",(debug_buf+6)); |
klauss | 27:98f824719d1c | 259 | fclose(fip); |
klauss | 27:98f824719d1c | 260 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 261 | files('s'); |
klauss | 27:98f824719d1c | 262 | } |
klauss | 28:94aec56c6329 | 263 | |
klauss | 28:94aec56c6329 | 264 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "extset ", 7 )) { |
klauss | 28:94aec56c6329 | 265 | miss_match = false; |
klauss | 28:94aec56c6329 | 266 | fip = fopen("/qspi/myext.txt", "w"); |
klauss | 28:94aec56c6329 | 267 | fprintf(fip, "%s\n\r" , ( debug_buf + 7) ); |
klauss | 28:94aec56c6329 | 268 | fclose(fip); |
klauss | 28:94aec56c6329 | 269 | pc.printf("\n\r"); |
klauss | 28:94aec56c6329 | 270 | files('s'); |
klauss | 28:94aec56c6329 | 271 | } |
klauss | 28:94aec56c6329 | 272 | |
klauss | 28:94aec56c6329 | 273 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serextset ", 10 )) { |
klauss | 28:94aec56c6329 | 274 | miss_match = false; |
klauss | 28:94aec56c6329 | 275 | fip = fopen("/qspi/peerext.txt", "w"); |
klauss | 28:94aec56c6329 | 276 | fprintf(fip, "%s\n\r" , ( debug_buf + 10 ) ); |
klauss | 28:94aec56c6329 | 277 | fclose(fip); |
klauss | 28:94aec56c6329 | 278 | pc.printf("\n\r"); |
klauss | 28:94aec56c6329 | 279 | files('s'); |
klauss | 28:94aec56c6329 | 280 | } |
klauss | 27:98f824719d1c | 281 | |
klauss | 19:ab2088e0dec6 | 282 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "maskset ",8 )) { |
klauss | 28:94aec56c6329 | 283 | miss_match = false; |
klauss | 27:98f824719d1c | 284 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 27:98f824719d1c | 285 | fprintf(fmask,"%s\n\r",(debug_buf+8)); |
klauss | 27:98f824719d1c | 286 | fclose(fmask); |
klauss | 27:98f824719d1c | 287 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 288 | files('s'); |
klauss | 27:98f824719d1c | 289 | } |
klauss | 27:98f824719d1c | 290 | |
klauss | 19:ab2088e0dec6 | 291 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "gatewayset ",11 )) { |
klauss | 28:94aec56c6329 | 292 | miss_match = false; |
klauss | 27:98f824719d1c | 293 | fgate = fopen("/qspi/mygate.txt", "w"); |
klauss | 27:98f824719d1c | 294 | fprintf(fgate,"%s\n\r",(debug_buf+11)); |
klauss | 27:98f824719d1c | 295 | fclose(fgate); |
klauss | 27:98f824719d1c | 296 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 297 | files('s'); |
klauss | 27:98f824719d1c | 298 | } |
klauss | 27:98f824719d1c | 299 | |
klauss | 27:98f824719d1c | 300 | |
klauss | 27:98f824719d1c | 301 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "msipport ",9 )) { |
klauss | 28:94aec56c6329 | 302 | miss_match = false; |
klauss | 27:98f824719d1c | 303 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 27:98f824719d1c | 304 | fprintf(fport,"%s\n\r",(debug_buf+9)); |
klauss | 27:98f824719d1c | 305 | fclose(fport); |
klauss | 27:98f824719d1c | 306 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 307 | files('s'); |
klauss | 27:98f824719d1c | 308 | } |
klauss | 27:98f824719d1c | 309 | |
klauss | 27:98f824719d1c | 310 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serverip ",9 )) { |
klauss | 28:94aec56c6329 | 311 | miss_match = false; |
klauss | 27:98f824719d1c | 312 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 27:98f824719d1c | 313 | fprintf(fsip,"%s\n\r",(debug_buf+9)); |
klauss | 27:98f824719d1c | 314 | fclose(fsip); |
klauss | 27:98f824719d1c | 315 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 316 | files('s'); |
klauss | 27:98f824719d1c | 317 | } |
klauss | 27:98f824719d1c | 318 | |
klauss | 27:98f824719d1c | 319 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ssport ",7 )) { |
klauss | 28:94aec56c6329 | 320 | miss_match = false; |
klauss | 27:98f824719d1c | 321 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 27:98f824719d1c | 322 | fprintf(fsport,"%s\n\r",(debug_buf+7)); |
klauss | 27:98f824719d1c | 323 | fclose(fsport); |
klauss | 27:98f824719d1c | 324 | pc.printf("\n\r"); |
klauss | 19:ab2088e0dec6 | 325 | files('s'); |
klauss | 27:98f824719d1c | 326 | } |
klauss | 27:98f824719d1c | 327 | |
klauss | 27:98f824719d1c | 328 | |
klauss | 27:98f824719d1c | 329 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dconfig" )) { |
klauss | 28:94aec56c6329 | 330 | miss_match = false; |
klauss | 27:98f824719d1c | 331 | files('w'); |
klauss | 27:98f824719d1c | 332 | files('s'); |
klauss | 27:98f824719d1c | 333 | } |
klauss | 27:98f824719d1c | 334 | |
klauss | 27:98f824719d1c | 335 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset" )) { |
klauss | 28:94aec56c6329 | 336 | miss_match = false; |
klauss | 28:94aec56c6329 | 337 | //pc.printf("\n\r reset!!! \n\r"); |
klauss | 28:94aec56c6329 | 338 | pc.printf("\n\rJob is done\n\r"); |
klauss | 27:98f824719d1c | 339 | pc.putc(0x01); |
klauss | 27:98f824719d1c | 340 | NVIC_SystemReset(); |
klauss | 27:98f824719d1c | 341 | } |
klauss | 27:98f824719d1c | 342 | |
klauss | 27:98f824719d1c | 343 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dog" )) { |
klauss | 28:94aec56c6329 | 344 | miss_match = false; |
klauss | 27:98f824719d1c | 345 | pc.printf("\n\r MUUUUUUUuuuuUUUUUU - I'm not a dog!!!! \n\r"); |
klauss | 27:98f824719d1c | 346 | dog = 0; |
klauss | 27:98f824719d1c | 347 | } |
klauss | 27:98f824719d1c | 348 | |
Cola | 21:0bd688722e81 | 349 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "flood ",6 )) { |
klauss | 27:98f824719d1c | 350 | if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { |
klauss | 28:94aec56c6329 | 351 | miss_match = false; |
klauss | 27:98f824719d1c | 352 | pc.printf("\n\r\t Flood ON\n\r\t"); |
klauss | 27:98f824719d1c | 353 | tflood.start(); |
klauss | 27:98f824719d1c | 354 | tflood.reset(); |
klauss | 27:98f824719d1c | 355 | floodcount =0; |
klauss | 27:98f824719d1c | 356 | pflood = 1; |
klauss | 27:98f824719d1c | 357 | } |
klauss | 27:98f824719d1c | 358 | if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { |
klauss | 28:94aec56c6329 | 359 | miss_match = false; |
klauss | 27:98f824719d1c | 360 | pc.printf("\n\r\t Flood OFF\n\r\t"); |
klauss | 27:98f824719d1c | 361 | pflood = 0; |
klauss | 27:98f824719d1c | 362 | tflood.stop(); |
klauss | 27:98f824719d1c | 363 | } |
klauss | 27:98f824719d1c | 364 | } |
klauss | 27:98f824719d1c | 365 | |
Cola | 21:0bd688722e81 | 366 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug ",6 )) { |
klauss | 27:98f824719d1c | 367 | if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { |
klauss | 28:94aec56c6329 | 368 | miss_match = false; |
Cola | 21:0bd688722e81 | 369 | pc.printf("\n\r\tDebug ON\n\r\t"); |
Cola | 21:0bd688722e81 | 370 | debug_alive = 1; |
klauss | 27:98f824719d1c | 371 | } |
klauss | 27:98f824719d1c | 372 | if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { |
klauss | 28:94aec56c6329 | 373 | miss_match = false; |
klauss | 27:98f824719d1c | 374 | pc.printf("\n\r\tDebug OFF\n\r\t"); |
Cola | 21:0bd688722e81 | 375 | debug_alive = 0; |
klauss | 27:98f824719d1c | 376 | } |
klauss | 19:ab2088e0dec6 | 377 | } |
klauss | 28:94aec56c6329 | 378 | |
klauss | 28:94aec56c6329 | 379 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_sip ", 10 )) { |
klauss | 28:94aec56c6329 | 380 | if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "on",2 )) { |
klauss | 28:94aec56c6329 | 381 | miss_match = false; |
klauss | 28:94aec56c6329 | 382 | debug_msg( "Sip Debug ON" ); |
klauss | 28:94aec56c6329 | 383 | debug_sip = 1; |
klauss | 28:94aec56c6329 | 384 | } |
klauss | 28:94aec56c6329 | 385 | if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "off",3 )) { |
klauss | 28:94aec56c6329 | 386 | miss_match = false; |
klauss | 28:94aec56c6329 | 387 | debug_msg( "Sip Debug OFF" ); |
klauss | 28:94aec56c6329 | 388 | debug_sip = 0; |
klauss | 28:94aec56c6329 | 389 | } |
klauss | 28:94aec56c6329 | 390 | } |
klauss | 28:94aec56c6329 | 391 | |
klauss | 27:98f824719d1c | 392 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "promptcb ", 9)) { //promptcb ramal porta comando |
klauss | 28:94aec56c6329 | 393 | miss_match = false; |
klauss | 27:98f824719d1c | 394 | static int id_msg = 0x10; |
Cola | 21:0bd688722e81 | 395 | uint8_t write_buffer[300]; |
Cola | 21:0bd688722e81 | 396 | unsigned int ext,port; |
Cola | 21:0bd688722e81 | 397 | int ant1,ant2; |
klauss | 27:98f824719d1c | 398 | |
Cola | 21:0bd688722e81 | 399 | debug_buf[bufptr++] = 0x0D; |
Cola | 21:0bd688722e81 | 400 | debug_buf[bufptr++] = 0x00; |
klauss | 27:98f824719d1c | 401 | |
Cola | 21:0bd688722e81 | 402 | ant1 = str2uint( (debug_buf+9), &ext); |
Cola | 21:0bd688722e81 | 403 | ant2 = str2uint( ((debug_buf+9)+ant1+1), &port); |
klauss | 27:98f824719d1c | 404 | |
klauss | 28:94aec56c6329 | 405 | pc.printf("ext=%d port=%d\r\ncmd=%s",ext, port, debug_buf+9+ant1+2+ant2); |
klauss | 27:98f824719d1c | 406 | |
Cola | 21:0bd688722e81 | 407 | __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 | 28:94aec56c6329 | 408 | pc.printf("Comando enviado"); |
klauss | 19:ab2088e0dec6 | 409 | } |
klauss | 27:98f824719d1c | 410 | |
Cola | 22:d2a4b5939115 | 411 | if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "cks",3 )) { |
klauss | 28:94aec56c6329 | 412 | miss_match = false; |
klauss | 27:98f824719d1c | 413 | pcks_s = 1; |
Cola | 22:d2a4b5939115 | 414 | } |
klauss | 27:98f824719d1c | 415 | |
Cola | 24:270b436a1bb0 | 416 | if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "showcb",6 )) { |
klauss | 28:94aec56c6329 | 417 | miss_match = false; |
Cola | 24:270b436a1bb0 | 418 | pshowcb = 1; |
Cola | 24:270b436a1bb0 | 419 | } |
klauss | 27:98f824719d1c | 420 | |
klauss | 27:98f824719d1c | 421 | if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debugsip ", 9 )) { |
klauss | 27:98f824719d1c | 422 | if (xmemmatch( (uint8_t*)( debug_buf + 9 ), (uint8_t*) "on",2 )) { |
klauss | 28:94aec56c6329 | 423 | miss_match = false; |
klauss | 28:94aec56c6329 | 424 | pc.printf("\tDebug Sip ON"); |
klauss | 27:98f824719d1c | 425 | debug_sip = 1; |
klauss | 27:98f824719d1c | 426 | } |
klauss | 27:98f824719d1c | 427 | if (xmemmatch( (uint8_t*)( debug_buf + 9 ), (uint8_t*) "off",3 )) { |
klauss | 28:94aec56c6329 | 428 | miss_match = false; |
klauss | 28:94aec56c6329 | 429 | pc.printf("Debug Sip OFF"); |
klauss | 27:98f824719d1c | 430 | debug_sip = 0; |
klauss | 27:98f824719d1c | 431 | } |
klauss | 27:98f824719d1c | 432 | } |
klauss | 27:98f824719d1c | 433 | |
klauss | 19:ab2088e0dec6 | 434 | if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "help" )) { |
klauss | 28:94aec56c6329 | 435 | miss_match = false; |
klauss | 27:98f824719d1c | 436 | pc.printf("\n\r****************************PROMPT HELP******************\n\r"); |
klauss | 27:98f824719d1c | 437 | pc.printf("sconfig - mostra o arquivo de configuracao do sistema\n\r"); |
klauss | 27:98f824719d1c | 438 | pc.printf("dconfig - volta as configuracoes do sistema para o padrao de fabrica\n\r"); |
klauss | 27:98f824719d1c | 439 | pc.printf("callme [ramal porta] - envia o pedido de ligacao para o callbox com o ramal e porta indicada\n\r"); |
klauss | 27:98f824719d1c | 440 | pc.printf("promptcb ramal porta comando - envia o <comando> para o cbx <ramal> e <porta> executar\n\r"); |
klauss | 27:98f824719d1c | 441 | pc.printf("format - formata o sistema de arquivos\n\r"); |
klauss | 27:98f824719d1c | 442 | pc.printf("reset - resta o sistema\n\r"); |
klauss | 27:98f824719d1c | 443 | pc.printf("ipset [ip] - Configura o IP da cabeceira\n\r"); |
klauss | 28:94aec56c6329 | 444 | pc.printf("extset [ext] - Configura a ext da cabeceira\n\r"); |
klauss | 28:94aec56c6329 | 445 | pc.printf("msipport [port] - Configura a porta SIP da cabeceira\n\r"); |
klauss | 28:94aec56c6329 | 446 | pc.printf("serverip [ip] - Configura o ip do servidor asterisk\n\r"); |
klauss | 28:94aec56c6329 | 447 | pc.printf("serextset [ext] - Configura a server ext da cabeceira\n\r"); |
klauss | 28:94aec56c6329 | 448 | pc.printf("ssport [port] - Configura a porta SIP do servidor asterisk\n\r"); |
klauss | 27:98f824719d1c | 449 | pc.printf("maskset [mask] - Configura a mascara da cabeceira\n\r"); |
klauss | 27:98f824719d1c | 450 | pc.printf("gatewayset [gateway] - Configura o gateway da cabeceira\n\r"); |
klauss | 27:98f824719d1c | 451 | pc.printf("showcb - lista os Cbx registrados na header\n\r"); |
klauss | 27:98f824719d1c | 452 | pc.printf("cks - exibe estatisticas de check sum\n\r"); |
klauss | 27:98f824719d1c | 453 | pc.printf("debug [on|off] - enable debugs\n\r"); |
klauss | 27:98f824719d1c | 454 | pc.printf("flood [on|off] - simula envio de pacotes de audio\n\r"); |
klauss | 28:94aec56c6329 | 455 | pc.printf("PROMPT VERSION: V%d\n\r",PVERSION); |
klauss | 27:98f824719d1c | 456 | } |
klauss | 27:98f824719d1c | 457 | /* |
klauss | 19:ab2088e0dec6 | 458 | if ( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "callme ", 7 )) { |
klauss | 19:ab2088e0dec6 | 459 | if ( debug_buf[16] != 0 && debug_buf[11] != 0x20 ) |
klauss | 19:ab2088e0dec6 | 460 | pc.printf("\n\r Error: formato errado! ramal=xxxx porta=xxxx \n\r"); |
klauss | 19:ab2088e0dec6 | 461 | else { |
klauss | 19:ab2088e0dec6 | 462 | uint8_t data[300]; |
klauss | 19:ab2088e0dec6 | 463 | uint16_t cks=0; |
klauss | 27:98f824719d1c | 464 | |
klauss | 19:ab2088e0dec6 | 465 | //data[0] = (uint8_t)( (debug_buf[7]&0xf0)<<4 + (debug_buf[8]&0x0f) ) ; |
klauss | 19:ab2088e0dec6 | 466 | //data[1] = (uint8_t)( (debug_buf[9]&0xf0)<<4 + (debug_buf[10]&0x0f) ) ; |
klauss | 19:ab2088e0dec6 | 467 | //data[2] = (uint8_t)( (debug_buf[12]&0xf0)<<4 + (debug_buf[13]&0x0f) ) ; |
klauss | 19:ab2088e0dec6 | 468 | /data[3] = (uint8_t)( (debug_buf[14]&0xf0)<<4 + (debug_buf[15]&0x0f) ) ; |
klauss | 27:98f824719d1c | 469 | |
klauss | 19:ab2088e0dec6 | 470 | data[0] = (uint8_t)( debug_buf[ 7 ] & 0xFF00 >> 8 ); |
klauss | 19:ab2088e0dec6 | 471 | data[1] = (uint8_t)( debug_buf[ 9 ] & 0x00FF ); |
klauss | 19:ab2088e0dec6 | 472 | data[2] = (uint8_t)( debug_buf[ 12 ] & 0xFF00 >> 8 ); |
klauss | 19:ab2088e0dec6 | 473 | data[3] = (uint8_t)( debug_buf[ 14 ] & 0x00FF ); |
klauss | 27:98f824719d1c | 474 | |
klauss | 19:ab2088e0dec6 | 475 | data[6] = 0x04; |
klauss | 19:ab2088e0dec6 | 476 | for (int i = 7; i < 300; i++) data[i] = 0x00; |
klauss | 19:ab2088e0dec6 | 477 | cks = __checksum__(data,300); |
klauss | 19:ab2088e0dec6 | 478 | data[4] = cks>>8; |
klauss | 19:ab2088e0dec6 | 479 | data[5] = cks&0xff; |
klauss | 27:98f824719d1c | 480 | |
klauss | 19:ab2088e0dec6 | 481 | pc.printf("\n\r"); |
klauss | 19:ab2088e0dec6 | 482 | for( int i = 0; i < 300; i++ ) |
klauss | 19:ab2088e0dec6 | 483 | pc.printf("%x ", data[ i ] ); |
klauss | 19:ab2088e0dec6 | 484 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 485 | |
klauss | 19:ab2088e0dec6 | 486 | xmemcpy(TXBuffer,data,300); |
klauss | 27:98f824719d1c | 487 | |
klauss | 19:ab2088e0dec6 | 488 | pc.printf("\n\r"); |
klauss | 19:ab2088e0dec6 | 489 | for( int i = 0; i < 300; i++ ) |
klauss | 19:ab2088e0dec6 | 490 | pc.printf("%x ", data[ i ] ); |
klauss | 19:ab2088e0dec6 | 491 | pc.printf("\n\r"); |
klauss | 27:98f824719d1c | 492 | |
klauss | 19:ab2088e0dec6 | 493 | send2callboxes(); |
klauss | 27:98f824719d1c | 494 | |
klauss | 19:ab2088e0dec6 | 495 | pc.printf("\n\r calling callbox %s \n\r",debug_buf+7); |
klauss | 19:ab2088e0dec6 | 496 | } |
klauss | 19:ab2088e0dec6 | 497 | |
klauss | 19:ab2088e0dec6 | 498 | } |
klauss | 27:98f824719d1c | 499 | */ |
klauss | 28:94aec56c6329 | 500 | if( miss_match ) pc.printf("--> %s: command not found\n\r", debug_buf ); |
klauss | 28:94aec56c6329 | 501 | pc.printf("> "); |
klauss | 19:ab2088e0dec6 | 502 | } |
klauss | 28:94aec56c6329 | 503 | |
klauss | 28:94aec56c6329 | 504 | if ( b == 0x0D || bufret == 1 || bufptr > DEBUGBUFSIZE ) { |
klauss | 27:98f824719d1c | 505 | bufptr = 0; |
klauss | 27:98f824719d1c | 506 | for (uint8_t i =0; i < DEBUGBUFSIZE; i++) { |
klauss | 27:98f824719d1c | 507 | debug_buf[i] = 0; |
klauss | 19:ab2088e0dec6 | 508 | } |
klauss | 27:98f824719d1c | 509 | bufret = 0; |
klauss | 27:98f824719d1c | 510 | pc.putc(0x0A); |
klauss | 27:98f824719d1c | 511 | pc.putc(0x0D); |
klauss | 19:ab2088e0dec6 | 512 | } |
klauss | 28:94aec56c6329 | 513 | } |