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