/**
 * @example     FileWriter_Demo.cpp
 *
 * Create a copy of a text file, character-by-character using a second buffer.
 * The second buffer (`writeBuffer`) does increase the complexity by five lines of code, but it drastically increases
 * the performance as well.
 *
 * @include PropWare_FileWriter/CMakeLists.txt
 */
int main() {
    const SD  driver;
    FatFS     filesystem(&driver);

    BlockStorage::Buffer   writeBuffer;
    BlockStorage::MetaData writeMetaData;
    uint8_t                bufferData[driver.get_sector_size()];
    writeBuffer.buf  = bufferData;
    writeBuffer.meta = &writeMetaData;

    filesystem.mount();

    FatFileReader reader(filesystem, "fat_test.txt");
    FatFileWriter writer(filesystem, "new2.txt", &writeBuffer);

    reader.open();
    writer.open();

    while (!reader.eof())
        writer.put_char(reader.get_char());

    writer.close();
    reader.close();
    filesystem.unmount();

    return 0;
}
예제 #2
0
파일: main.cpp 프로젝트: 0x1abin/ebox_stm32
void getSDCardInfo()
{
    u8 ret;
    uint64_t rl;
    u8 buf[1024];
    
    ret = sd.get_CID(buf);
    uart1.printf("\r\n========================");
    uart1.printf("\r\nget CID Info,ret = %d", ret);
    uart1.printf("\r\n");
    uart1.printf((const char *)buf);

    rl = sd.get_capacity();
    uart1.printf("\r\n========================");
    uart1.printf("\r\ncapacity = %dMB", rl / 1024 / 1024);
    uart1.printf("\r\ncapacity = %0.1fGB", rl / 1024 / 1024/1024.0);

    uart1.printf("\r\nWaiting...");
    res = f_getfree("/", &free_clust, &fss);
    if(res == FR_OK)
    {
        uart1.printf("\r\npartition size:%dMB", (fss->free_clust) * (fss->csize) / 2048);
        uart1.printf("\r\npartition free sectors: %d", (fss->free_clust) * (fss->csize));
        uart1.printf("\r\npartition free clust:%d", free_clust);
    }
    else
        uart1.printf("\r\nget capacity faile,err = %d", res);
    uart1.printf("\r\nOVER !");


}
예제 #3
0
void play(MSI& rank, VS& toks) {
	SS oprs;
	SD nums;
	string out = "";
	char str[100];

	cout << "# from infix to postfix!!!" << endl;
	
	for (VS::iterator i = toks.begin(); i != toks.end(); i++) {
		string tok = *i;
		
		cout << "There is a " << tok << ": ";

		if (is_num(tok)) {
			cout << "push to output" << endl;
			sprintf(str, "%.6lf ", stod(tok));
			out += str;
			nums.push(stod(tok));
		}
		else if (tok == ",") {
			cout << "flush the stack until '('" << endl;
			while (oprs.top() != "(")
				calc(oprs, nums, out);
		}
		else if (tok == ")") {
			cout << "flush the stack until '(' and check if there's a func" << endl;
			while (oprs.top() != "(")
				calc(oprs, nums, out);
			oprs.pop();
			if (!oprs.empty() && is_func(oprs.top()))
				calc(oprs, nums, out);
		}
		else {
			cout << "push to stack" << endl;
			if ( is_unary(tok) && (i == toks.begin() || rank[*(i - 1)] > 0) )
				oprs.push("u" + tok);
			else { 
				while (!is_func(tok) && tok != "(" && !oprs.empty() && rank[oprs.top()] <= rank[tok]) {
					cout << "\t*** stack.top() has higher precedence" << endl;
					calc(oprs, nums, out);
				}
				oprs.push(tok);
			}
		}

		cout << "\tcurrent output: " << out << endl
			 << "\tcurrent  stack: " << oprs << endl;
	}

	while (!oprs.empty())
		calc(oprs, nums, out);

	cout << "There is nothing left, so flush the stack to output" << endl
		 << "\tcurrent output: " << out << endl
		 << "#transformation completed!!!" << endl
		 << "Postfix Exp: " << out << endl
		 << "RESULT: " << nums.top() << endl << endl;
}
예제 #4
0
void Randsampling(SD & sd){
	static Area *AR=NULL;
	static RArea *RAR =NULL;

	//cout << __FILE__ <<endl;
	//AR=SD::CalArea_sort();   
	//RAR=SD::calsampling(AR);  
	//SD::Row2Column(RAR);
	AR=sd.CalArea_sort();   
	RAR=sd.calsampling(AR);  
	sd.Row2Column(RAR);

	delete(AR);
	delete(RAR);
}
int bar(int a){
  int r = a;

  a1.foo();
  a2.foo();
  b1.foo();
  b2.foo();
  c1.foo();
  d1.foo();
  e1.foo();
  t1.foo();
  t2.foo();

  #pragma omp target teams
  ++r;

  return r + *R;
}
int bar(int a){
  int r = a;

  a1.foo();
  a2.foo();
  b1.foo();
  b2.foo();
  c1.foo();
  d1.foo();
  e1.foo();
  t1.foo();
  t2.foo();

  #pragma omp target simd
  for (int i = 0; i < 10; ++i)
    ++r;

  return r + *R;
}
예제 #7
0
파일: main.cpp 프로젝트: 0x1abin/ebox_stm32
void setup()
{
    u8 ret;
    ebox_init();
    uart1.begin(115200);
    ret = sd.begin(3);
    if(ret == 0)
        uart1.printf("sdcard init ok!\r\n");
    else
        uart1.printf("sdcard init failed;err = %d\r\n",ret);
        
    attach_sd_to_fat(&sd);

    res = f_mount(&fs, "0", 1);
    if(res == FR_OK)
        uart1.printf("mount ok!\r\n", res);
    else
        uart1.printf("mount err!err = %d\r\n", res);

}
예제 #8
0
파일: Shell.cpp 프로젝트: Glorf/avrponk
void Shell::execute() {
    char argv[10][10];
    memset(argv,0,sizeof(argv));
    char main[10];
    memset(main,0,sizeof(main));
    int argc=0;
    int is=0;
    while(is<strlen(s)) {
        if(s[is]==' ') {
            if(is+1==strlen(s)) {
                is+=1;
                break;
            }
            argc+=1;
            is+=1;
            break;
        }
        main[is]=s[is];
        is+=1;
    }
    while(s[is]==' ') is+=1;
    int iar=0;
    while(is<strlen(s)) {
        if(s[is]==' ') {
            argc+=1;
            is+=1;
            iar=0;
        }
        argv[argc-1][iar]=s[is];
        iar+=1;
        is+=1;
    }
    //APPS DEFINITIONS
    if(strcmp(main,"ponk")==0) {
        if(argc>0) {
            core.putf("You selected: ");
            for(int i=0; i<argc; i++) {
                core.putf(argv[i]);
                core.putf(" ");
            }
            core.putfln("");
        }
        core.putfln("   #####    ");
        core.putfln("  #     #   ");
        core.putfln(" #   ##  #  ");
        core.putfln("  # #   #    PonK Industries product! ");
        core.putfln("   #####    ");
        core.putfln("     #     ");
        core.putfln("      #    ");
        core.putfln("    ##     ");
    }
    else if(strcmp(main,"dodaj")==0) {
        uint32_t r=0;
        char w[10];
        for(int i=0; i<argc; i++) {
            r=r+atoi(argv[i]);
        }
        itoa(r,w,10);
        core.putfln(w);
        memset(w,0,sizeof(w));
        r=0;
    }
    else if(strcmp(main,"pomnoz")==0) {
        uint32_t r=1;
        char w[10];
        for(int i=0; i<argc; i++) {
            r=r*atoi(argv[i]);
        }
        itoa(r,w,10);
        core.putfln(w);
        memset(w,0,sizeof(w));
        r=0;
    }
    else if(strcmp(main,"read")==0) {
        core.putfln("SD storage read...");
        int result2=sd.readsect(512);
        switch(result2) {
        case 0:
            core.putfln("success!");
            break;
        case 1:
            core.putfln("first trap fail");
            break;
        case 2:
            core.putfln("second trap fail");
            break;
        default:
            core.putfln("unknown trap");
            break;
        }
        for(int i=0; i<512; i++) {
            core.putch(sd.sect[i]);
        }
    }
    else if(strcmp(main,"init")==0) {
        core.putfln("SD storage initialization...");
        int result1=sd.init();
        switch(result1) {
        case 0:
            core.putfln("success!");
            break;
        case 1:
            core.putfln("first trap fail");
            break;
        case 2:
            core.putfln("second trap fail");
            break;
        default:
            core.putfln("unknown trap");
            break;
        }
    }
    else if(strcmp(main,"engine")==0) {
        if(argc==1) {
            if(strcmp(argv[0],"init")==0) {
                core.engine(1);
            }
            if(strcmp(argv[0],"start")==0) {
                core.engine(2);
            }
            if(strcmp(argv[0],"stop")==0) {
                core.engine(3);
            }
        }
    }
}
예제 #9
0
void calc(SS& oprs, SD& nums, string& s) {
	string opr = oprs.top(); oprs.pop();
	if (opr[0] == 'u') s += opr[1];
	else s += opr;
	s += ' ';
	
	double b = nums.top(); nums.pop();
	if (opr[0] == 'u' || (is_func(opr) && opr != "pow")) {
			 if (opr == "u+") nums.push(b);
		else if (opr == "u-") nums.push(-b);

		else if (opr == "sin") nums.push(sin(b));
		else if (opr == "cos") nums.push(cos(b));
		else if (opr == "exp") nums.push(exp(b));
		else if (opr == "log") nums.push(log(b));
		else if (opr == "sqrt") nums.push(sqrt(b));
		else if (opr == "fabs") nums.push(fabs(b));
		return;
	}

	double a = nums.top(); nums.pop();
		 if (opr == "*") nums.push(a * b);
	else if (opr == "+") nums.push(a + b);
	else if (opr == "-") nums.push(a - b);
	else if (opr == "pow") nums.push(pow(a, b));
}