void TestFile(void){ int i; char data; printf("\n\rEE345M/EE380L, Lab 5 eFile test\n\r"); // simple test of eFile if(eFile_Init()) diskError("eFile_Init",0); if(eFile_Format()) diskError("eFile_Format",0); //eFile_Directory(&Serial_OutChar); eFile_Directory(&UARTPut); if(eFile_Create("file1")) diskError("eFile_Create",0); if(eFile_WOpen("file1")) diskError("eFile_WOpen",0); for(i=0;i<1000;i++){ if(eFile_Write('a'+i%26)) diskError("eFile_Write",i); if(i%52==51){ if(eFile_Write('\n')) diskError("eFile_Write",i); if(eFile_Write('\r')) diskError("eFile_Write",i); } } if(eFile_WClose()) diskError("eFile_Close",0); //eFile_Directory(&Serial_OutChar); eFile_Directory(&UARTPut); if(eFile_ROpen("file1")) diskError("eFile_ROpen",0); for(i=0;i<1000;i++){ if(eFile_ReadNext(&data)) diskError("eFile_ReadNext",i); //Serial_OutChar(data); UARTPut(data); } if(eFile_Delete("file1")) diskError("eFile_Delete",0); //eFile_Directory(&Serial_OutChar); eFile_Directory(&UARTPut); printf("Successful test of creating a file\n\r"); OS_Kill(); }
//******************* Custom Test Main 3 ********** //do single eFile functions and check what they return. int main(void){ int x; char name[2]; extern union dirUnion DIRBlock; name[0]='a'; name[1]='\0'; x=eFile_Init(); x=eDisk_ReadBlock(DIRBlock.byte,0); DIRBlock.headers[0].name[0]='A'; eDisk_ReadBlock(DIRBlock.byte,0); x=x; x=eFile_Format(); x=x; x=eFile_Create(name); x=x; x=eFile_GetBlock(); while(1){ ;} return 0; }
//writing to a file that does not exit int main3(void){ if(eFile_Init()) diskError("eFile_Init",0); if(eFile_Format()) diskError("eFile_Format",0); eFile_Directory(UART_OutChar); if(eFile_WOpen("f")) diskError("eFile_WOpen", 0); eFile_Write('f'); return 0; }
void read_test(void) { int i; unsigned int then, now; eFile_Init(); eFile_Format(); OS_AddThread(&write_test, 128, 0); OS_Sleep(2000); then = OS_MsTime(); // read 10 blocks for(i = 0; i < 10; i++) { eDisk_ReadBlock(buffer, i); } now = OS_MsTime(); OS_AddThread(&SH_Shell, 128, 0); OS_Sleep(1000); OS_Suspend(); printf("Read test took %d ms", now - then); eFile_Format(); OS_Kill(); }
//closing a file that is not open int main2(void){ if(eFile_Init()) diskError("eFile_Init",0); if(eFile_Format()) diskError("eFile_Format",0); eFile_Directory(UART_OutChar); eFile_Create("file1"); eFile_WOpen("file1"); eFile_RClose(); eFile_RClose(); return 0; }
void simple_test(void) { char c; printf("\r\n\r\n"); printf("eFile_Init() returned: %d\r\n", eFile_Init()); printf("eFile_Format() returned: %d\r\n", eFile_Format()); printf("_eFile_TestFormat() returned: %d\r\n", _eFile_TestFormat()); printf("eFile_Create() returned: %d\r\n", eFile_Create("test")); printf("eFile_WOpen() returned: %d\r\n", eFile_WOpen("test")); printf("eFile_Write() returned: %d\r\n", eFile_Write('x')); printf("eFile_WClose() returned: %d\r\n", eFile_WClose()); printf("eFile_ROpen() returned: %d\r\n", eFile_ROpen("test")); printf("eFile_ReadNext() returned: %d\r\n", eFile_ReadNext(&c)); printf("eFile_ReadNext() read: %c\r\n", c); printf("eFile_RClose() returned: %d\r\n", eFile_RClose()); while(1) { ; } }
void write_test(void) { int i; unsigned int then, now; eFile_Init(); eFile_Format(); // format buffer with dummy data for(i = 0; i < 512; i++) { buffer[i] = 0xA5; } // possibly should just use OS_Time() then = OS_MsTime(); // write 10 blocks for(i = 0; i < 10; i++) { eDisk_WriteBlock(buffer, i); } // now = OS_MsTime(); // OS_AddThread(&SH_Shell, 128, 0); // OS_Sleep(1000); // OS_Suspend(); // printf("Write test took %d ms", now - then); // eFile_Format(); OS_Kill(); }
int process_cmd(char *input){ // static int screen1Line; // unsigned short adc_val; // char *strptr; // char inString1[MAXSTRLEN]; // char inString2[MAXSTRLEN]; // int i; unsigned char outVal; // 1) print performance measures // time-jitter, number of data points lost, number of calculations performed // i.e., NumSamples, NumCreated, MaxJitter-MinJitter, DataLost, FilterWork, PIDwork if(strncmp(input, "initFileSystem", 14) == 0){ eFile_Init(); return 1; } if(strncmp(input, "formatDisk", 10) == 0){ //format disk if(eFile_Format()) printf("Error: efile_format"); return 1; } if(strncmp(input, "printDirectory", 14) == 0){ //output disk directory UART_OutChar('\n'); UART_OutChar('\r'); eFile_Directory(UART_OutChar); return 1; } if(strncmp(input, "printFile ", 9) == 0){ UART_OutChar('\n'); UART_OutChar('\r'); eFile_ROpen(input + 10); while(eFile_ReadNext(&outVal) == 0) { UART_OutChar(outVal); } eFile_RClose(); return 1; } if(strncmp(input, "deleteFile ", 11) == 0){ eFile_Delete(input + 11); return 1; } if(strncmp(input, "redirect ", 9) == 0){ eFile_RedirectToFile(input + 9); return 1; } return 0; }
static int _SH_Format(void) { printf("Formatting disk...\n"); if(eFile_Format()) fprintf(stderr, "File format failed!\n"); return 0; }