00001
00010 #include <string.h>
00011 #include "cli_func.h"
00012 #include <uip.h>
00013 #include <uip_arp.h>
00014 #include "file_send.h"
00015
00016 enum {GET = 0, SET};
00017
00021 char* get_IP(void);
00022
00029 void set_lcd_init(){
00030 RTCTime time;
00031 char buff[30];
00032
00033 lcd_clr();
00034 lcd_goto(1,0);
00035
00036 lcd_string("IP ");
00037 sprintf(buff, "%s",get_IP());
00038 lcd_string(buff);
00039
00040
00041 }
00042
00049 void show_lcd_time(){
00050 char *buff;
00051 RTCTime time;
00052 time = RTCGetTime();
00053 sprintf(buff, "%2d:%2d:%2d", time.RTC_Hour, time.RTC_Min, time.RTC_Sec);
00054 lcd_goto(2,0);
00055 lcd_string(buff);
00056
00057 }
00058
00059
00068 break_t do_init(str_t* tp){
00069 strcpy(tp->resp,"\n-------------------------------------------");
00070 strcat(tp->resp,"\n- TCC - UIP MULTIPLE APLICATION -");
00071 strcat(tp->resp,"\n-------------------------------------------\n");
00072 set_lcd_init();
00073 return RET_OK;
00074 }
00075
00084 break_t do_get_temperature(str_t* tp){
00085 char buff[20];
00086 DEBUG_CLI("do_get_temperature");
00087 strcpy(tp->resp,"em construcao");
00088
00089 return RET_OK;
00090 }
00091
00100 break_t do_chat(str_t* tp){
00101 char buff[20], porta[20];
00102 uint32_t port;
00103
00104 global_chat_flag = 1;
00105 DEBUG_CLI("do_chat troca de mensagens entre usuarios.\n");
00106 if(tp->value == NULL) return RET_ERROR;
00107
00108 port = (uint32_t) atoi (tp->value);
00109 if(port < 0) return RET_ERROR;
00110 sprintf(buff, "Porta %d",port);
00111 DEBUG_CLI(buff);
00112 CHAT_PORT = port;
00113 chat_start();
00114 uart_puts("\nCLI SUSPENSA.\n");
00115
00116
00117
00118 return RET_OK;
00119 }
00120
00121
00131 void set_IP(void){
00132
00133 uip_ipaddr_t xIPAddr;
00134 char buff[40];
00135
00136 uipIP_ADDR0 = vectorAddrIPv4[0];
00137 uipIP_ADDR1 = vectorAddrIPv4[1];
00138 uipIP_ADDR2 = vectorAddrIPv4[2];
00139 uipIP_ADDR3 = vectorAddrIPv4[3];
00140
00141
00142 DEBUG_CLI("\nconfig IP");
00143
00144 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
00145 uip_sethostaddr( xIPAddr );
00146 }
00147
00155 char* get_IP(void){
00156 char buff[30];
00157 uip_ipaddr_t xIPAddr;
00158
00159 uip_gethostaddr(xIPAddr);
00160 sprintf(buff,"%d.%d.%d.%d", uip_ipaddr1(xIPAddr), uip_ipaddr2(xIPAddr),
00161 uip_ipaddr3(xIPAddr), uip_ipaddr4(xIPAddr));
00162
00163 return buff;
00164 }
00165
00174 break_t do_MAC(str_t* tp){
00175 char buff[20];
00176 if(tp->tipo == SET)
00177 strcpy(tp->resp, "Apenas comando de GET.");
00178 else if (tp->tipo == GET){
00179 sprintf(buff, "%d:%d:%d:%d:%d:%d", uipMAC_ADDR0, uipMAC_ADDR1, uipMAC_ADDR2,uipMAC_ADDR3,
00180 uipMAC_ADDR4,uipMAC_ADDR5);
00181 }
00182 return RET_OK;
00183 }
00184
00193 break_t do_IP(str_t* tp){
00194 char* buff="\0";
00195 char arq[20];
00196 char dest[30];
00197
00198 DEBUG_CLI("Return IP address");
00199
00200 if(tp->tipo == SET){
00201 strcpy(arq,tp->value);
00202 if(strlen(arq)<=0) return RET_ERROR;
00203 buff = strtok(arq, " ,.");
00204 vectorAddrIPv4[0] = atoi(buff);
00205 buff = strtok(NULL, " ,.");
00206 vectorAddrIPv4[1] = atoi(buff);
00207 buff = strtok(NULL, " ,.");
00208 vectorAddrIPv4[2] = atoi(buff);
00209 buff = strtok(NULL, " ,.");
00210 vectorAddrIPv4[3] = atoi(buff);
00211 set_IP();
00212 sprintf(dest,"set to %d.%d.%d.%d",uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3);
00213 strcpy(tp->resp, dest);
00214
00215 }
00216 else {
00217 sprintf(dest,"%s", get_IP());
00218 strcpy(tp->resp, dest);
00219 DEBUG_CLI(tp->resp);
00220
00221 }
00222 return RET_OK;
00223
00224 }
00225
00226
00237 void writeDataLcd(char* data, int col, int linha)
00238 {
00239 char dest[20];
00240 lcd_clr();
00241 sprintf(dest,"Coluna: %d linha: %d",col, linha);
00242 DEBUG_CLI(dest);
00243 lcd_goto(linha, col);
00244 lcd_string(data);
00245 }
00246
00256 break_t do_lcd(str_t* tp){
00257 char arq[40], msg[16];
00258 char* buff="\0";
00259 int posX = 0, posY = 0;
00260
00261 DEBUG_CLI("do_lcd");
00262 if(tp->tipo == SET){
00263 strcpy(arq,tp->value);
00264 if(strlen(arq)<=0) return RET_ERROR;
00265 buff = strtok(arq, ";");
00266 strcpy(msg, buff);
00267 buff = strtok(NULL, " ,.");
00268 posX = atoi(buff);
00269 if (posX > 16 || posX < 0) return RET_ERROR;
00270 buff = strtok(NULL, " ,.");
00271 posY = atoi(buff);
00272 if (posY > 2 || posY < 0) return RET_ERROR;
00273 writeDataLcd(msg, posX, posY);
00274 strcpy(tp->resp,"Dados Escritos com sucesso.");
00275 }
00276 else {
00277 strcpy(tp->resp, "Apenas comando de SET.");
00278 DEBUG_CLI(tp->resp);
00279
00280 }
00281 return RET_OK;
00282 }
00283
00284
00288 void out_data(char * data){
00289 if(OUT_UART) uart_puts(data);
00290 else if(OUT_TELNET) shell_output(data,"");
00291 }
00292
00300 void set_Gateway(void){
00301 uip_ipaddr_t xIPAddr;
00302
00303 DEBUG_CLI("config Gateway");
00304 uip_ipaddr( xIPAddr, uip_GAT0, uip_GAT1, uip_GAT2, uip_GAT3);
00305 uip_setdraddr(xIPAddr);
00306 }
00307
00316 break_t do_gateway(str_t* tp){
00317 char* buff="\0";
00318 char arq[20];
00319 char dest[30];
00320 int end[4];
00321 uip_ipaddr_t xGtAddr;
00322
00323 DEBUG_CLI("Return Gateway");
00324
00325 if(tp->tipo == SET){
00326 strcpy(arq,tp->value);
00327 if(strlen(arq)<=0) return RET_ERROR;
00328 buff = strtok(arq, " ,.");
00329 uip_GAT0 = atoi(buff);
00330 buff = strtok(NULL, " ,.");
00331 uip_GAT1 = atoi(buff);
00332 buff = strtok(NULL, " ,.");
00333 uip_GAT2 = atoi(buff);
00334 buff = strtok(NULL, " ,.");
00335 uip_GAT3 = atoi(buff);
00336 set_Gateway();
00337 sprintf(dest,"set to %d.%d.%d.%d",uip_GAT0, uip_GAT1, uip_GAT2, uip_GAT3);
00338 strcpy(tp->resp, dest);
00339
00340 }
00341 else {
00342 uip_getdraddr(xGtAddr);
00343 sprintf(dest,"%d.%d.%d.%d", uip_ipaddr1(xGtAddr), uip_ipaddr2(xGtAddr),
00344 uip_ipaddr3(xGtAddr), uip_ipaddr4(xGtAddr));
00345 strcpy(tp->resp, dest);
00346 DEBUG_CLI(tp->resp);
00347
00348 }
00349 return RET_OK;
00350
00351 }
00352
00357 void set_Mask(void){
00358 uip_ipaddr_t xIPAddr;
00359
00360 DEBUG_CLI("config Mask");
00361 uip_ipaddr( xIPAddr, uip_Mask0, uip_Mask1, uip_Mask2, uip_Mask3);
00362 uip_setnetmask(xIPAddr);
00363
00364 }
00365
00374 break_t do_mask(str_t* tp){
00375 char* buff="\0";
00376 char arq[20];
00377 char dest[30];
00378 int end[4];
00379 uip_ipaddr_t xMaskAddr;
00380
00381 DEBUG_CLI("Return Mask");
00382
00383 if(tp->tipo == SET){
00384 strcpy(arq,tp->value);
00385 if(strlen(arq)<=0) return RET_ERROR;
00386 buff = strtok(arq, " ,.");
00387 uip_Mask0 = atoi(buff);
00388 buff = strtok(NULL, " ,.");
00389 uip_Mask1 = atoi(buff);
00390 buff = strtok(NULL, " ,.");
00391 uip_Mask2 = atoi(buff);
00392 buff = strtok(NULL, " ,.");
00393 uip_Mask3 = atoi(buff);
00394 set_Gateway();
00395 sprintf(dest,"set to %d.%d.%d.%d", uip_Mask0, uip_Mask1, uip_Mask2, uip_Mask3);
00396 strcpy(tp->resp, dest);
00397
00398 }
00399 else {
00400
00401 uip_getnetmask(xMaskAddr);
00402 sprintf(dest,"%d.%d.%d.%d", uip_ipaddr1(xMaskAddr), uip_ipaddr2(xMaskAddr),
00403 uip_ipaddr3(xMaskAddr), uip_ipaddr4(xMaskAddr));
00404 strcpy(tp->resp, dest);
00405 DEBUG_CLI(tp->resp);
00406
00407 }
00408 return RET_OK;
00409
00410 }
00411
00417 break_t do_configIp(str_t* tp){
00418 char* buff="\0";
00419 char arq[20];
00420 char dest[80];
00421 int end[4];
00422
00423 DEBUG_CLI("Return network info");
00424
00425 if(tp->tipo == SET){
00426 sprintf(dest,"Just get command.");
00427 strcpy(tp->resp, dest);
00428
00429 }
00430 else {
00431 sprintf(arq,"\nMask: %d.%d.%d.%d", uip_Mask0, uip_Mask1, uip_Mask2, uip_Mask3);
00432 strcpy(dest, arq);
00433 sprintf(arq,"\nGateway: %d.%d.%d.%d", uip_GAT0, uip_GAT1, uip_GAT2, uip_GAT3);
00434 strcat(dest, arq);
00435 sprintf(dest,"\nIP: %d.%d.%d.%d",uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3);
00436 strcat(dest, arq);
00437 strcpy(tp->resp, dest);
00438 DEBUG_CLI(tp->resp);
00439
00440 }
00441 return RET_OK;
00442
00443 }
00444
00445
00446
00457 break_t do_ftp(str_t* tp){
00458
00459 strcpy(tp->resp, "Servico Indisponivel");
00460
00461 #if 0
00462 char* end_ip='\0';
00463
00464 unsigned char TSTflag = 0;
00465 struct uip_conn* ftp_conn = NULL;
00466 arn_CHAR srvSystType[MAX_SRV_SYSTTYPE];
00467 ftp_cmd_status_t stst;
00468 DEBUG_FTP("ftp client CLI");
00469
00470 end_ip = tp->value;
00471
00472
00473
00474
00475
00476
00477
00478
00479 while(TSTflag != 7 || TSTflag >= 200){
00480
00481 if (TSTflag == 0) {
00482 stst = ftp_connect(end_ip,21,&ftp_conn);
00483 TSTflag = 7;
00484 if (stst == ftpcs_FAILED) {TSTflag = 201; break;}
00485 if (stst == ftpcs_SUCCESS) {TSTflag = 1; break;}
00486 }
00487 else if (TSTflag == 1) {
00488 DEBUG_FTP("ftp login..");
00489 stst = ftp_login(ftp_conn,"mtgm");
00490 DEBUG_FTP(" . ok");
00491 if (stst == ftpcs_PASSWORD_REQ) {TSTflag = 10; break;}
00492 if (stst == ftpcs_FAILED) {TSTflag = 202; break;}
00493 if (stst == ftpcs_SUCCESS) {TSTflag = 2; break;}
00494 }
00495 else if (TSTflag == 2) {
00496 DEBUG_FTP("ftp syst..");
00497 stst = ftp_syst(ftp_conn,srvSystType);
00498 DEBUG_FTP("ftp ok..");
00499 if (stst == ftpcs_FAILED) {TSTflag = 203; break;}
00500 if (stst == ftpcs_SUCCESS) {TSTflag = 3; break;}
00501 }
00502 else if (TSTflag == 3) {
00503 stst = ftp_port(ftp_conn,5001);
00504 if (stst == ftpcs_FAILED) {TSTflag = 204; break;}
00505 if (stst == ftpcs_SUCCESS) {TSTflag = 4; break;}
00506 }
00507 else if (TSTflag == 4) {
00508 stst = ftp_send(ftp_conn,"SendFile_FTP.txt",(arn_uCHAR*)MSG,strlen(MSG));
00509 if (stst == ftpcs_FAILED) {TSTflag = 205; break;}
00510 if (stst == ftpcs_SUCCESS) {TSTflag = 5; break;}
00511 }
00512 else if (TSTflag == 5) {
00513 stst = ftp_quit(ftp_conn);
00514 if (stst == ftpcs_FAILED) {TSTflag = 206; break;}
00515 if (stst == ftpcs_SUCCESS) {TSTflag = 6; break;}
00516 }
00517 else if (TSTflag == 6) {
00518 ftp_conn = 0;
00519 TSTflag = 7;
00520 }
00521 else if (TSTflag == 10) {
00522 stst = ftp_password(ftp_conn,"mtgm");
00523 if (stst == ftpcs_FAILED) {TSTflag = 210; break;}
00524 if (stst == ftpcs_SUCCESS) {TSTflag = 2; break;}
00525 }
00526 }
00527
00528 #endif
00529
00530 return RET_OK;
00531 }