int main(int argc, char * argv[]) { printf("External Lights Control v1.0 9 Apr 2016\n\n"); int flag = 0; int WPI_Num = -1; struct cfg cfgstruct; cfgstruct = get_config(FILENAME); int Dbg_Lvl = (int)cfgstruct.Dbg; int GPIO_Num = (int)cfgstruct.GPIO_No; WPI_Num = GPIO2ToWPI [GPIO_Num & 63]; if(Setup_IO(WPI_Num, Dbg_Lvl) < 0){ printf ("Unable to setup GPIO: %s\n", strerror (errno)); return 1; } // main loop while (flag < 2) { flag = 0; // reset flag State = 0; // reset the interrupt status // waiting for interrupt from Lights pin if (Dbg_Lvl) printf("Waiting for Lights activation\n"); Write_File("Off", Dbg_Lvl); while (State == 0) delay (Delay); // Interrupt has fired (State has changed), hence lights are on. Write to file and loop until turned off if (Dbg_Lvl) printf("Lights On\n"); // Lights On Write_File("On", Dbg_Lvl); while (digitalRead(WPI_Num) == LOW) delay (Delay); // Lights Off if (Dbg_Lvl) printf("Lights Off\n"); } if (Dbg_Lvl) printf("Exiting Program\n"); }
// ################################################################# // データをファイルに書き込む bool DFI::Write_DFI_File(const std::string prefix, const unsigned step, int& dfi_mng, const bool mio) { if ( prefix.empty() ) return NULL; // master node only int mm; MPI_Comm_rank(MPI_COMM_WORLD, &mm); if ( mm != 0 ) return false; std::string dfi_name; if ( mio ) { dfi_name = Generate_DFI_Name(prefix); if( dfi_name.empty() ) { return false; } if( !Write_File(dfi_name, prefix, step, dfi_mng, mio) ) { return false; } } return true; }
void SaveConfig(void) { Update[SAVE_PROFILE] = 0; if (Item_Index[SAVE_PROFILE]) { if (SD_Card_ON()) { if (FAT_Info() == 0) { Char_to_Str(FileNum, Item_Index[SAVE_PROFILE]); if (Open_File("FILE",FileNum,"CFG") == 0) { PutConfig(); if (Write_File() != 0) DisplayField(InfoF, WHITE, SD_Msgs[WriteErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoFile]); } else DisplayField(InfoF, WHITE, SD_Msgs[SDErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoCard]); } else { PutConfig(); if (Write_Parameter() == FLASH_COMPLETE) DisplayField(InfoF, WHITE, SD_Msgs[SaveOk]); else DisplayField(InfoF, WHITE, SD_Msgs[Failed]); } }
void SaveWave(void) { Update[SAVE_WAVE_CURVE] = 0; if (SD_Card_ON()) { if (FAT_Info() == 0) { Char_to_Str(FileNum, Item_Index[SAVE_WAVE_CURVE]); if (Open_File("FILE",FileNum,"DAT") == 0) { F_Buff[0] = 0; F_Buff[1] = 0; memcpy(F_Buff + 2, View_Buffer, 300); if (Write_File() == 0) { if (Item_Index[SAVE_WAVE_CURVE] < 255) Item_Index[SAVE_WAVE_CURVE]++; Update[SAVE_WAVE_CURVE] = 1; } else DisplayField(InfoF, WHITE, SD_Msgs[WriteErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoFile]); } else DisplayField(InfoF, WHITE, SD_Msgs[SDErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoCard]); }
void Process_Save( void ) { static char *untitledStr = NULL; static char newName[MAX_FNAME]; char *tmp1 = NULL; char *tmp2 = NULL; int c; DialogFlag = SAVE; fileIOMode = FILE_WRITE; untitledStr = GETSTR(2,20, "UNTITLED"); tmp1= strrchr(last_fname, '/'); if (tmp1) { c = tmp1[1]; tmp2 = strchr(tmp1, c); strcpy(newName, tmp2); } if (strncmp(newName, untitledStr, 8) == 0 || last_fname[0] == NULL) Process_SaveAs(); else { if (SavedOnce == True) { if (!Write_File(last_fname)) DoErrorDialog( GETSTR(16,4, "Unable to write data to file") ); else Dirty = False; } else Process_SaveAs(); } }
static int run_init_func( void ) { int err = 0; lua_settop(L1, 0); lua_getglobal(L1, "init"); /* [bottom] init [top] */ #ifdef DEBUG_ON lua_pushboolean(L1, 1); #else lua_pushboolean(L1, 0); #endif err = lua_pcall(L1, 1, 0, 0); if (err) { const char * ptr = lua_tostring(L1, -1); if(!ptr) ptr = "Unknown Error"; Write_File( "Logs/lua_init_error.txt", (char*) ptr, (long)strlen(ptr) ); Msg("error lua init: %s\n", (char*) ptr ); } return err; }
//Read all files in the input directory and copy all files to mini file system int ReadDir(const char *dir) { int file_count = 0; int temp = 0; struct dirent* ptr; DIR* srcdir = opendir(dir); pid_t childpid; if (srcdir == NULL) { perror("opendir"); return -1; } while((ptr = readdir(srcdir)) != NULL) // traverse done { char* d_name; d_name = ptr -> d_name; if (ptr -> d_type & DT_DIR) // check whether it is a directory { if(strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) { char path[100]; sprintf(path, "%s/%s", dir, d_name); temp = ReadDir(path); file_count += temp; } }else{ printf("\n/////////////////////////START//////////////////////////\n%s/%s\n", dir, d_name); if (isJPG(d_name)){ //---------------Jia------------------ //fork childpid = fork(); //error handling if (childpid == -1) { perror("Failed to fork"); return 1; } //child code if (childpid == 0) { fprintf(stderr, "--------------I am the child----------------\n"); char filepath[100]; char newpath[100]; sprintf(filepath, "%s/%s", dir, d_name); sprintf(newpath, "%s%s", filepath, "encd"); fprintf(stderr,"filepath is %s \t newpath is %s\t\n", filepath, newpath); char cmd[200]; strcpy(cmd, "base64 "); strcat(cmd, filepath); strcat(cmd, " > "); strcat(cmd, newpath); execlp("/bin/bash", "bash", "-c", cmd, NULL); //execl("/usr/bin/base64", "base64", filepath, ">", newpath); }else{ //wait while(r_wait(NULL) > 0) { fprintf(stderr, "Parent Wait\n"); } fprintf(stderr, "--------------I am the parent----------------\n"); //---------------end jia--------------- //--------------------Create--------------------------- int f = Create_File(d_name); //printInode(Inode_List[Superblock.next_free_inode-1]); if(f == -3) { printf("File could not be added to Directory.\n"); continue; }else if (f == -2) { printf("File could not be written to the new inode.\n"); continue; }else if (f == -1) { printf("File already existed in directory.\n"); continue; }else{ //printf("ptr->d_name: %s\n", d_name); // ################# file_count++; //------------------------------Copy image to mini file system------------------------------------------- FILE *fp; int ch; //fprintf(stderr, "d_name is: %s\n", d_name); char filepath[100]; sprintf(filepath, "%s/%s", dir, d_name); //--------------jia-------------------- char newpath[100]; sprintf(newpath, "%s%s", filepath, "encd"); fprintf(stderr,"filepath is %s \t newpath is %s\t\n", filepath, newpath); fp = fopen(newpath, "r"); ///--------------end jia---------------- //fp = fopen(filepath, "r"); if (fp == NULL) { fprintf(stderr, "Cannot open %s/%s .....\n", dir, d_name); break; // what we should do if could not read file!!!!!!!!!!!!!! }else{ //------------------------------Copy file to mini_filesystem--------------------------------------- fseek(fp, 0L, SEEK_END); int sz = ftell(fp); fseek(fp, 0L, SEEK_SET); char* to_write = (char*) malloc(sizeof(char)*sz); int i = 0; while( (ch = fgetc(fp)) != EOF ) { to_write[i] = ch; //fprintf(stderr, "%c\t", ch); i++; } //fprintf(stderr, "\nto_write is: %s\n", to_write); Write_File(Search_Directory(d_name), 0, to_write, sz); fprintf(stderr,"---------------\n"); printInode(Inode_List[Superblock.next_free_inode-1]); fprintf(stderr,"---------------\n/////////////////////////END///////////////////////////\n"); } } } }else{ printf("The file is not JPG file, skipped it.\n"); } } } closedir(srcdir); return file_count; }