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