📄 fvscaler.c
字号:
#include <stdio.h>#include <string.h>#include "socket_base.h"char *next_cmd = "reboot";char str[] = "fCore:";char rbuf[4096], rbuf_save[256];HTRANSINTERFACE handle;char *p_buf;int read_comp_comm(int i){ int ret = 0; int readresult = 0; int compresult = 0; memset(rbuf, 0, 4096); char *pdest = NULL; int pos = 0; do { int k = 0, pos = 0; readresult = ReadPackage(rbuf, 4096, handle, 1, 3); if (readresult == 0) { printf("k:%d read %d bytes\n", k, readresult); goto kk; } printf("========Read Package is successfully==========\n"); p_buf = rbuf; printf("To compare the string to see wheterh fvscaler or not\n"); //for (i=0; i<readresult; i++) //{ printf("p_buf= %s\n", p_buf); //compresult = strncmp(p_buf, "fCore:",6); pdest = strstr(p_buf, str); pos = pdest - p_buf + 1; if( pdest != NULL ) { printf( "%s found at position %d\n\n", str, pos); int j = 1; printf("get current fcore success\n"); pdest += 6; switch (i) { case 1: j = strncmp(pdest, "624", 3); break; case 2: j = strncmp(pdest, "806", 3); break; default: printf("i is error\n"); } if (j == 0) { printf("The frist fvscaler info is succesful\n"); } else { printf("The frist fvscaler info is fail\n"); } compresult = 1; } else { printf( "%s not found\n", str); compresult = 0; };kk: k++; printf ("read package and get right comm content time: %d\n", k); if (k > 10) { printf("Read package via COMM, Fail to get right content or read\n"); ret = 1; break; } } while ( (readresult == 0)||(compresult == 0)); return ret; }int main(int argc, char *argv[]){ //open network lclient COMMANDPAR par1; HTRANSINTERFACE cmdFile = NULL; int result; int ret = 0; char cmdline[256]; par1.opMode=SOCKET_OP; par1.socketAddr = malloc(30); par1.socketAddr = "192.168.1.100:10000"; par1.endPoint = CLIENT; if (par1.opMode == FILE_OP){ }else if (par1.opMode == SOCKET_OP){ cmdFile = OpenTransInterface(&par1); if(cmdFile == NULL){ fprintf(stderr, "Can not connect the server socket!\n"); return -1; } } printf("send commad:%s\n",next_cmd); result = SendPackage(next_cmd, 6, cmdFile); if(result != 6){ printf("send problem\n"); ret = -1; goto out1; } result = ReadPackage(cmdline, 4, cmdFile);//get the cmd if(result != 4){ printf("read problem\n"); ret = -1; goto out1; } printf("readpackage: %s\n", cmdline); if (strncmp(cmdline, "Done",4) == 0) { printf("reboot success\n"); } //finish reboot platform COMMANDPAR par; //HTRANSINTERFACE handle; int last_result; int i; //char rbuf[4096], rbuf_save[256]; //char *p_buf; char *mac_buf; char *wbuf = malloc(256); char *macaddr = malloc(20); memset(macaddr, 0,20); mac_buf = macaddr; memset(rbuf, 0, 4096); memset(rbuf_save, 0, 256); par.opMode = COMM_OP; par.commAddr = malloc(30); par.commAddr = "/dev/ttyS0"; par.baudrate = malloc(15); par.baudrate = "B38400"; par.endPoint = SERVER; handle = OpenTransInterface(&par); if(handle == NULL){ printf("Open Transfer interface failed\n"); return -1; } sleep(5); printf("----Test platform can enter blob control interface----\n"); /* wait to enter blob command control interface*/ printf("echo anykey successed\n"); for (i=0; i<6; i++) { wbuf = "\n"; result = SendPackage(wbuf, 1, handle); if(result != 1){ printf("Send problem\n"); ret = -1; goto out; } sleep(1); } memset(rbuf, 0, 4096); result = ReadPackage(rbuf, 20, handle, 1, 5); printf("read %d bytes\n", result); printf("read: %s\n", rbuf); p_buf = rbuf; for (i=0; i<result; i++) { if (strncmp(p_buf, "blob>",5) == 0) { printf("enter blob command control\n"); break; } p_buf++; if(i== result-1) { printf("can not enter blob command control\n"); ret = -1; goto out; } } printf("----Voltage/Frequency Change----\n"); wbuf = "fvscaler info\n"; result = SendPackage(wbuf, 14, handle); if(result != 14){ printf("Send problem\n"); ret = -1; goto out; } result = read_comp_comm (1); if(result != 0){ printf("1st fvscaler info is fail\n"); ret = -1; goto out; } printf("----Voltage/Frequency Change----\n"); wbuf = "fvscaler fCore 806Mt\n"; result = SendPackage(wbuf, 21, handle); if(result != 21){ printf("Send problem:fvscaler fCore 806Mt is fail\n"); ret = -1; goto out; } sleep(2); wbuf = "fvscaler info\n"; result = SendPackage(wbuf, 14, handle); if(result != 14){ printf("Send problem\n"); ret = -1; goto out; } result = read_comp_comm (2); if(result != 0){ printf("fvscaler fCore 806Mtis fail\n"); ret = -1; goto out; } //sleep(3);/* int readresult = 0; int compresult = 0; memset(rbuf, 0, 4096); char *pdest = NULL; int pos = 0; do { int k = 0, pos = 0; readresult = ReadPackage(rbuf, 4096, handle, 1, 3); if (readresult == 0) { printf("k:%d read %d bytes\n", k, readresult); goto kk; } printf("========Read Package is successfully==========\n"); p_buf = rbuf; printf("To compare the string to see wheterh fvscaler or not\n"); //for (i=0; i<readresult; i++) //{ printf("p_buf= %s\n", p_buf); //compresult = strncmp(p_buf, "fCore:",6); pdest = strstr(p_buf, str); pos = pdest - p_buf + 1; if( pdest != NULL ) { printf( "%s found at position %d\n\n", str, pos); int j; printf("get current fcore success\n"); pdest += 6; j = strncmp(pdest, "624", 3); if (j == 0) { printf("The frist fvscaler info is succesful\n"); } else { printf("The frist fvscaler info is fail\n"); } compresult = 1; } else { printf( "%s not found\n", str); compresult = 0; } //}kk: k++; printf ("read package and get right comm content time: %d\n", k); } while ( (readresult == 0)||(compresult == 0)); *//* printf("----boot up system------\n"); wbuf = "nkernel\n"; result = SendPackage(wbuf, 8, handle); if(result != 8){ printf("Send problem\n"); ret = -1; goto out; } sleep(5); result = ReadPackage(rbuf, 20, handle, 1, 5); printf("read %d bytes\n", result); printf("read: %s\n", rbuf); p_buf = rbuf; for (i=0; i<result; i++) { if (strncmp(p_buf, "blob>",5) == 0) { printf("load kernel from nandflash successfully\n"); break; } p_buf++; if (i == result - 1) { printf("failed to load kernel from nandflash\n"); ret = -1; goto out; } } wbuf = "boot\n"; result = SendPackage(wbuf, 5, handle); if(result != 5){ printf("Send problem\n"); ret = -1; goto out; } sleep(10); printf("boot up system\n"); result = ReadPackage(rbuf, 4096, handle, 1, 10); printf("read %d bytes\n", result); printf("read: %s\n", rbuf); p_buf = rbuf; sleep(10); printf("boot up system\n"); result = ReadPackage(rbuf, 4096, handle, 1, 10); printf("read %d bytes\n", result); printf("read: %s\n", rbuf); p_buf = rbuf; sleep(10); printf("boot up system\n"); result = ReadPackage(rbuf, 4096, handle, 1, 10); printf("read %d bytes\n", result); printf("read: %s\n", rbuf); p_buf = rbuf; sleep(10); wbuf = "\n"; result = SendPackage(wbuf, 1, handle); if(result != 1){ printf("Send problem\n"); ret = -1; goto out; } printf("Send enter key to consel\n"); sleep(3); result = ReadPackage(rbuf, 1024, handle, 1, 10); printf("read %d bytes\n", result); printf("read: %s\n", rbuf); p_buf = rbuf; for (i=0; i<result; i++) { if (strncmp(p_buf, "root@Linux",10) == 0) { printf("system bootup from nandflash successfully\n"); break; } p_buf++; if(i>result-1) { printf("failed to bootup system from nandflash\n"); ret = -1; goto out; } } wbuf = "ifconfig eth0\n"; result = SendPackage(wbuf, 14, handle); if(result != 14){ printf("Send problem\n"); ret = -1; goto out; } printf("use ifconfig to get hw address of eth0\n"); sleep(4); result = ReadPackage(rbuf, 4096, handle, 1, 10); printf("read %d bytes\n", result); printf("read: %s\n", rbuf); p_buf = rbuf; for (i=0; i<result; i++) { printf("compare eth0 mac\n"); if (strncmp(p_buf, "HWaddr",6) == 0) { printf("get eth0 mac\n"); p_buf += 7; printf("p_buf = %s\n",p_buf); printf("macaddr = %s\n", macaddr); if(strncmp(p_buf,macaddr,17) == 0) { printf("get mac successfully\n"); break; } } p_buf++; if(i>=result-1) { printf("get mac via blob failed\n"); ret = -1; goto out; } } */ printf("------------------------------------------------------------------\n"); printf("------------------------------------------------------------------\n"); printf("------------------------------------------------------------------\n"); printf("------------------------------------------------------------------\n"); out: if(handle != NULL){ CloseTransInterface(handle); } out1: if(cmdFile != NULL) CloseTransInterface(cmdFile); return ret;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -