//*************************************************************************** //Function: to get DIR/FILE list or a single file address (cluster number) or to delete a specified file //Arguments: #1 - flag: GET_LIST, GET_FILE or DELETE #2 - pointer to file name (0 if arg#1 is GET_LIST) //return: first cluster of the file, if flag = GET_FILE // print file/dir list of the root directory, if flag = GET_LIST // Delete the file mentioned in arg#2, if flag = DELETE //**************************************************************************** struct dir_Structure* findFiles (unsigned char flag, unsigned char *fileName) { unsigned long cluster, sector, firstSector; struct dir_Structure *dir; unsigned int i; unsigned char j; cluster = rootCluster; //root cluster while(1) { firstSector = getFirstSector (cluster); for(sector = 0; sector < sectorPerCluster; sector++) { SD_readSingleBlock (firstSector + sector); for(i=0; i<bytesPerSector; i+=32) { dir = (struct dir_Structure *) &buffer[i]; if(dir->name[0] == EMPTY) //indicates end of the file list of the directory { if((flag == GET_FILE) || (flag == DELETE)) //transmitString("File does not exist!"); return 0; } else if((dir->name[0] != DELETED) && (dir->attrib != ATTR_LONG_NAME)) { if((flag == GET_FILE) || (flag == DELETE)) { for(j=0; j<11; j++) if(dir->name[j] != fileName[j]) break; if(j == 11) { if(flag == GET_FILE) return (dir); } } } } } cluster = (getSetNextCluster (cluster, GET, 0)); if(cluster > 0x0ffffff6) return 0; if(cluster == 0) { //transmitString("Error in getting cluster"); return 0; } } return 0; }
//uint8_t readCfgFile(DATE *adate,TIME *atime, uint8_t *filename_dat, uint8_t atomic) uint8_t readCfgFile(char *filename_dat) //, uint8_t atomic) { DIR *dir; uint32_t cluster, fileSize, firstSector; uint16_t k; uint8_t i,j,ld,lt; uint8_t filename[]= "CONFIG CFG"; uint8_t filename2[]="_CONFIG CFG"; dir = findFiles (GET_FILE, filename, filename); //, atomic); //get the file location if(dir == 0) return(0); cluster = (((uint32_t) dir->firstClusterHI) << 16) | dir->firstClusterLO; fileSize = dir->fileSize; ld = 0; lt = 0; while(1) { ClusterNumber = cluster; firstSector = getFirstSector (); for(j=0; j<SectorPerCluster; j++) { SD_readSingleBlock(firstSector + j); //, atomic); for(k=0; k<512; k++) { switch(buffer[k]) { case 'S': k++; if(buffer[k]=='T') { k++; Time.h = getDec((uint8_t*)buffer+k); //k +=2; Time.m = getDec((uint8_t*)buffer+k+2); //k +=2; Time.s = getDec((uint8_t*)buffer+k+4); } else if(buffer[k]=='D') { k++; Date.d = getDec(&buffer[k]); //k +=2; Date.m = getDec(&buffer[k+2]); //k +=2; Date.y = 20 + getDec(&buffer[k+4]); } else if(buffer[k]=='F') { k = k+2; for(i=0;i<8;i++) { if(buffer[k+i] < 0x21) //if any control code and space { filename_dat[i] = 0x00; break; } filename_dat[i] = buffer[k+i]; } filename_dat[i+1] = 0x00; // i = strlcpy(filename_dat,&(buffer[k]),9); k = k+i; } else if(buffer[k]=='I') { k +=2; for(i=0;i<13;i++) { if(buffer[k+i] < 0x20) //if any control code break; inset[i] = buffer[k+i]; } } break; case 'A': k++; if(buffer[k]=='D') { k++; ADate[ld].d = getDec((uint8_t*)buffer+k); //k +=2; ADate[ld].m = getDec((uint8_t*)buffer+k+2); //k +=2; ADate[ld].y = 20 + getDec((uint8_t*)buffer+k+4); ld++; } else if(buffer[k]=='T') { k++; ATime[lt].h = getDec((uint8_t*)buffer+k); //k +=2; ATime[lt].m = getDec((uint8_t*)buffer+k+2); //k +=2; ATime[lt].s = getDec((uint8_t*)buffer+k+4); lt++; } break; } if (k >= fileSize ) { findFiles(RENAME, filename, filename2); //, atomic); return(lt); } } } ClusterNumber = cluster; cluster = getSetNextCluster (GET); //, 0, atomic); if(cluster == 0) { //#if BIGAVR == 1 // printf_P(PSTR("ERR GETTING CLUSTERb\n")); //#endif //BIGAVR return(0); } } return(0); }
//uint8_t readCfgFile(DATE *adate,TIME *atime, uint8_t *filename_dat, uint8_t atomic) uint8_t readCfgFile(uint8_t *filename_dat, uint8_t atomic) { DIR *dir; uint32_t cluster, fileSize, firstSector; uint16_t k; uint8_t i,j,ld,lt; uint8_t filename[]="CONFIG CFG"; uint8_t filename2[]="_CONFIG CFG"; TIME_t time; DATE_t date; dir = findFiles (GET_FILE, filename, filename, atomic); //get the file location if(dir == 0) return(0); cluster = (((uint32_t) dir->firstClusterHI) << 16) | dir->firstClusterLO; fileSize = dir->fileSize; ld = 0; lt = 0; while(1) { firstSector = getFirstSector (cluster); for(j=0; j<SectorPerCluster; j++) { SD_readSingleBlock(firstSector + j, atomic); for(k=0; k<512; k++) { switch(buffer[k]) { case 'S': k++; switch(buffer[k]) { case 'T': k++; time.h = getDec((uint8_t*)buffer+k); time.m = getDec((uint8_t*)buffer+k+2); time.s = getDec((uint8_t*)buffer+k+4); break; case 'D': k++; date.d = getDec(&buffer[k]); date.m = getDec(&buffer[k+2]); date.y = 20 + getDec(&buffer[k+4]); break; case 'F': k = k+2; for(i=0;i<13;i++) { if(buffer[k+i] < 0x20) //if any control code break; filename_dat[i] = buffer[k+i]; } k = k+i; break; case 'M': //mask definitions: M - mic only, S - SHT sensor only, T - DS1820 1-wire sensor, X - Mic+SHT, '-' - nothing k++; for(i=0;i<12;i++) { Mask.SHT = Mask.SHT<<1; Mask.MIC = Mask.MIC<<1; switch(buffer[k+i]) { // case 'X': //SHT mask generated from mic mask! // Mask.SHT |= 0x0001; case 'M': Mask.MIC |= 0x0001; break; // case 'S': // Mask.SHT |= 0x0001; // break; case 'T': Mask.DS |= 0x01; // any T will cause DS mask to be one... break; default: break; } } k = k+i; } break; case 'A': k++; if(buffer[k]=='D') { k++; ADate[ld].d = getDec((uint8_t*)buffer+k); //k +=2; ADate[ld].m = getDec((uint8_t*)buffer+k+2); //k +=2; ADate[ld].y = 20 + getDec((uint8_t*)buffer+k+4); ld++; } else if(buffer[k]=='T') { k++; ATime[lt].h = getDec((uint8_t*)buffer+k); //k +=2; ATime[lt].m = getDec((uint8_t*)buffer+k+2); //k +=2; ATime[lt].s = getDec((uint8_t*)buffer+k+4); lt++; } break; } if (k >= fileSize ) { findFiles(RENAME,filename, filename2, atomic); RTC_SetDateTime(&date, &time); //?? if(Mask.SHT) // { generate_mask_bm(); // } return(lt); } } } cluster = getSetNextCluster (cluster, GET, 0, atomic); if(cluster == 0) { #if RSCOM == 1 printf_P(PSTR("ERR GETTING CLUSTERb\n")); #endif //BIGAVR return(0); } } return(0); }