本文整理汇总了C++中SdFile::fileSize方法的典型用法代码示例。如果您正苦于以下问题:C++ SdFile::fileSize方法的具体用法?C++ SdFile::fileSize怎么用?C++ SdFile::fileSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SdFile
的用法示例。
在下文中一共展示了SdFile::fileSize方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loop
void loop() {
uint32_t t;
double r;
Serial.println("Type any character to start");
while (!Serial.available()) SPARK_WLAN_Loop();
while (Serial.available()) Serial.read();
// open or create file - truncate existing file.
if (!file.open(&root, "BENCH.DAT", O_CREAT | O_TRUNC | O_RDWR)) {
error("open failed");
}
// fill buf with known data
for (uint16_t i = 0; i < (BUF_SIZE-2); i++) {
buf[i] = 'A' + (i % 26);
}
buf[BUF_SIZE-2] = '\r';
buf[BUF_SIZE-1] = '\n';
Serial.print("File size ");
Serial.print(FILE_SIZE_MB);
Serial.println(" MB");
uint32_t n = FILE_SIZE/sizeof(buf);
Serial.println("Starting write test. Please wait up to a minute");
// do write test
t = millis();
for (uint32_t i = 0; i < n; i++) {
if (file.write(buf, sizeof(buf)) != sizeof(buf)) {
error("write failed");
}
}
t = millis() - t;
file.sync();
r = (double)file.fileSize()/t;
Serial.print("Write ");
Serial.print(r);
Serial.println(" kB/sec");
Serial.println();
Serial.println("Starting read test. Please wait up to a minute");
// do read test
file.rewind();
t = millis();
for (uint32_t i = 0; i < n; i++) {
if (file.read(buf, sizeof(buf)) != sizeof(buf)) {
error("read failed");
}
}
t = millis() - t;
r = (double)file.fileSize()/t;
Serial.print("Read ");
Serial.print(r);
Serial.println(" kB/sec");
Serial.println("Done");
file.close();
}
示例2: app_process_file_stat
idigi_callback_status_t iDigiFileSystem::app_process_file_stat(idigi_file_stat_request_t * const request_data,
idigi_file_stat_response_t * const response_data)
{
idigi_file_stat_t *pstat = &response_data->statbuf;
idigi_callback_status_t status = idigi_callback_continue;
SdFile entry = DigiSD.open(request_data->path);
if (!entry.isOpen())
{
APP_DEBUG("stat cannot open: %s\n", request_data->path);
goto done;
}
pstat->last_modified = 0; // Last modified date unsupported:
pstat->hash_alg = idigi_file_hash_none; // File hash not supported
pstat->file_size = (size_t) entry.fileSize();
pstat->flags = 0;
if (entry.isDir())
pstat->flags |= IDIGI_FILE_IS_DIR;
else
pstat->flags |= IDIGI_FILE_IS_REG;
entry.close();
done:
return status;
}
示例3: wctxpn
/*
* generate and transmit pathname block consisting of
* pathname (null terminated),
* file length, mode time and file mode in octal
* as provided by the Unix fstat call.
* N.B.: modifies the passed name, may extend it!
*/
int wctxpn(const char *name)
{
char *p, *q;
//DSERIAL.println("\nwctxpn");
strcpy(txbuf,name);
p = q = txbuf + strlen(txbuf)+1;
//Pete (El Supremo) fix bug - was 1024, should be TXBSIZE??
while (q < (txbuf + TXBSIZE))
*q++ = 0;
// if (!Ascii && (in!=stdin) && *name && fstat(fileno(in), &f)!= -1)
if (!Ascii)
// I will have to figure out how to convert the uSD date/time format to a UNIX epoch
// sprintf(p, "%lu %lo %o 0 %d %ld", fout.fileSize(), 0L,0600, Filesleft, Totalleft);
// Avoid sprintf to save memory for small boards. This sketch doesn't know what time it is anyway
ultoa(fout.fileSize(), p, 10);
strcat_P(p, PSTR(" 0 0 0 "));
q = p + strlen(p);
ultoa(Filesleft, q, 10);
strcat_P(q, PSTR(" "));
q = q + strlen(q);
ultoa(Totalleft, q, 10);
Totalleft -= fout.fileSize();
//DSERIAL.print(F("wctxpn sf = "));
//DSERIAL.print(sf);
//DSERIAL.print(F(" length = "));
//DSERIAL.println(Totalleft);
if (--Filesleft <= 0)
Totalleft = 0;
if (Totalleft < 0)
Totalleft = 0;
/* force 1k blocks if name won't fit in 128 byte block */
//Pete (El Supremo) This can't be right??!
if (txbuf[125])
// blklen=1024;
blklen = TXBSIZE;
else { /* A little goodie for IMP/KMD */
blklen = 128;
txbuf[127] = (fout.fileSize() + 127) >>7;
txbuf[126] = (fout.fileSize() + 127) >>15;
}
return zsendfile(txbuf, 1+strlen(p)+(p-txbuf));
}
示例4: open
File SDClass::open(const char *filepath, uint8_t mode) {
/*
Open the supplied file path for reading or writing.
The file content can be accessed via the `file` property of
the `SDClass` object--this property is currently
a standard `SdFile` object from `sdfatlib`.
Defaults to read only.
If `write` is true, default action (when `append` is true) is to
append data to the end of the file.
If `append` is false then the file will be truncated first.
If the file does not exist and it is opened for writing the file
will be created.
An attempt to open a file for reading that does not exist is an
error.
*/
int pathidx;
// do the interative search
SdFile parentdir = getParentDir(filepath, &pathidx);
// no more subdirs!
filepath += pathidx;
if (! filepath[0]) {
// it was the directory itself!
return File(parentdir, "/");
}
// Open the file itself
SdFile file;
// failed to open a subdir!
if (!parentdir.isOpen())
return File();
if ( ! file.open(parentdir, filepath, mode)) {
return File();
}
// close the parent
parentdir.close();
if (mode & (O_APPEND | O_WRITE))
file.seekSet(file.fileSize());
return File(file, filepath);
}
示例5: SD_GetFileSize
uint32_t SD_GetFileSize(void)
{
uint32_t retVal = 0;
//TEST.TXT
sdf.chdir(); // Change directory to root
// OPEN the file for reading:
if (!file.open("TEST.TXT", O_READ)) {
sdf.errorHalt("opening FILE for read failed");
}
else
{
retVal = file.fileSize();
file.close();
}
return retVal;
}
示例6: wcs
int wcs(const char *oname)
{
// char name[PATHLEN];
// strcpy(name, oname);
Eofseen = 0;
// vpos = 0;
switch (wctxpn(oname)) {
case ERROR:
return ERROR;
case ZSKIP:
return OK;
}
// ++Filcnt;
if(!Zmodem && wctx(fout.fileSize())==ERROR)
return ERROR;
return 0;
}
示例7:
boolean MP3Player::Play(const char* SongName)
{
if(!PLAY)
{
k=65;
if(!myFile.isOpen())
{
// open the file for read
if (!myFile.open(SongName, O_READ))
{
#if DEBUG
sd.errorHalt("open audio file failed");
#endif
return false;
}
}
else
name = SongName;
Run_STA013();
delayMicroseconds(500000);
Play_Pause(1);
//AMPON();
#if DEBUG
Serial.println("playing");
#endif
filesize=myFile.fileSize();
Timer1.initialize(30);// 30 us = can check data request and send a byte to STA013 at 1/30u = 33.33kHz
// able to play a song up to 33.33 x 8 /1024 = 260 kbps
// recommend play song at 200kbps or lower (such as 128 kbps)for stable performance
PLAY=true;
Timer1.attachInterrupt(Callback);
}
return true;
}
示例8: SD_ReadFile
boolean SD_ReadFile(const char *filename)
{
uint32_t t_arrival = millis();
boolean retVal = false;
sdf.chdir();
if (!file.open(filename, O_READ)) {
sdf.errorHalt("opening FILE for read failed");
}
else
{
uint32_t len = file.fileSize();
uint8_t index = 0;
for(uint32_t i=0; i< len; i++)
{
int intData = file.read();
char byteData;
int base = 10u;
//itoa(intData,&byteData,base); // Convert to ASCII
buffer[index] = (uint8_t)intData;//byteData;
if(index < 63u) {
index++;
}
else {
usb_rawhid_send(buffer, 100u);
index = 0;
}
}
file.close();
uint32_t t_exit = millis() - t_arrival;
buffer[62] = (uint8_t)((t_exit & 0x000000FF)>>8);
buffer[63] = (uint8_t)t_exit;
usb_rawhid_send(buffer,100u);
}
}
示例9: dirAllocTest
/*
* create enough files to force a cluster to be allocated to dir.
*/
void dirAllocTest(SdFile &dir) {
char buf[13], name[13];
SdFile file;
uint16_t n;
uint32_t size = dir.fileSize();
// create files and write name to file
for (n = 0; ; n++){
// make file name
sprintf(name, "%u.TXT", n);
// open start time
uint32_t t0 = millis();
if (!file.open(&dir, name, O_WRITE | O_CREAT | O_EXCL)) {
error("open for write failed");
}
// open end time and write start time
uint32_t t1 = millis();
// write file name to file
file.print(name);
if (!file.close()) error("close write");
// write end time
uint32_t t2 = millis();
PgmPrint("WR ");
Serial.print(n);
Serial.print(' ');
// print time to create file
Serial.print(t1 - t0);
Serial.print(' ');
// print time to write file
Serial.println(t2 - t1);
// directory size will change when a cluster is added
if (dir.fileSize() != size) break;
}
// read files and check content
for (uint16_t i = 0; i <= n; i++) {
sprintf(name, "%u.TXT", i);
// open start time
uint32_t t0 = millis();
if (!file.open(&dir, name, O_READ)) {
error("open for read failed");
}
// open end time and read start time
uint32_t t1 = millis();
int16_t nr = file.read(buf, 13);
if (nr < 5) error("file.read failed");
// read end time
uint32_t t2 = millis();
// check file content
if (strlen(name) != (uint16_t)nr || strncmp(name, buf, nr)) {
error("content compare failed");
}
if (!file.close()) error("close read failed");
PgmPrint("RD ");
Serial.print(i);
Serial.print(' ');
// print open time
Serial.print(t1 - t0);
Serial.print(' ');
// print read time
Serial.println(t2 - t1);
}
}
示例10: loop
void loop() {
unsigned long tick = millis();
long diff = tick - lastTick;
avgTickDelay = expAvg(avgTickDelay, diff);
lastTick = tick;
if (printTicks > printTicksI) {
Serial.print("tick delay: ");
Serial.print(diff);
Serial.println("ms");
}
// Radio tick.
radio->tick();
// Send helo.
diff = tick - lastSent;
if ((lastAck < lastSent && diff > MAX_SEND_WAIT)
|| diff > MIN_SEND_WAIT
) {
avgSendDelay = expAvg(avgSendDelay, diff);
lastSent = tick;
if (printTicks > printTicksI) {
printTicksI++;
Serial.print("send delay: ");
Serial.print(diff);
Serial.println("ms");
}
if (sendInfx) {
Message msg("he");
radio->send(&msg);
} else {
Message msg("lo");
radio->send(&msg);
}
sendInfx = !sendInfx;
}
// Update metrics.
tick = millis();
if (tick - lastUpdate > UPDATE_WAIT) {
memcpy(&mLast, &m, sizeof(metrics));
lastUpdate = tick;
lastVcc = readVcc();
sinceLastAck = (int) ((lastUpdate - lastAck) / 1000L);
if (sinceLastAck < 0) {
#ifdef DEBUG
Serial.println("sinceLastAck less than 0");
Serial.print("round((");
Serial.print(lastUpdate);
Serial.print(" - ");
Serial.print(lastAck);
Serial.print(") / 1000.0) = ");
Serial.println(sinceLastAck);
#endif
sinceLastAck = 0;
}
if (lastAck + TIMEOUT_WAIT < lastSent) {
lastRoundtrip = NO_READING_INT;
lastRssi = NO_READING_INT;
}
writeLog();
}
// Pipeline tick.
pipe->tick();
// Serial commands.
if (Serial.available()) {
String cmd = Serial.readStringUntil('\n');
if (cmd[0] == 'D') {
dataFile.close();
if (!dataFile.open(root, logFilename, O_READ)) {
Serial.println();
Serial.println("Could not open file for reading");
return;
}
uint32_t offset;
long cmdOffset = cmd.substring(1).toInt();
if (cmdOffset < 0) {
offset = dataFile.fileSize() + cmdOffset;
} else {
offset = cmdOffset;
}
dataFile.seekSet(offset);
char buf[128];
int16_t read;
bool firstRead = true;
do {
read = dataFile.read(buf, 127);
buf[read] = 0;
if (firstRead && read > 0) {
firstRead = false;
char *firstNewline = strchr(buf, '\n');
Serial.print(++firstNewline);
} else {
//.........这里部分代码省略.........
示例11: robot_Send_Picture
int robot_Send_Picture (uint8_t n)
{
uint16_t param[MAX_PARAMS];
uint8_t paramlen = 0;
uint8_t msg[MSG_SIZE_MAX];
uint8_t msg_len = 0;
uint8_t tag [MAX_TAGS];
uint16_t value [MAX_TAGS];
uint8_t nbtags;
char filename[12+1];
uint16_t nbytes = 0;
uint8_t buf[PAYLOAD_SIZE];
int ret = SUCCESS;
Serial.println("Start robot_Send_Picture");
// Open picture file
sprintf(filename, "PICT%d.jpg", n);
if (!FilePicture.open(&root, filename, O_READ)) return FILE_OPEN_ERROR;
Serial.println("open ok ");
//Send the Picture message
param[0] = (uint16_t)n;
param[1] = (uint16_t)FilePicture.fileSize();
paramlen = 2;
ret = IOTSerial.IOTSsend(1, PICTURE, param, paramlen);
//Read the message replied to be sure that the client is ready to receive the picture
ret = IOTSerial.IOTSread(1, msg, &msg_len);
Serial.print("Call IOTSread 1, ret: "); Serial.print(ret); Serial.print(", msg_len: "); Serial.println((int)msg_len);
if (ret != SUCCESS) {
Serial.println("error IOTSread");
ret = IOTSerial.IOTSflush(1);
return 0;
}
//Decode the message
IOTSerial.IOTSgetTags(msg, tag, value, &nbtags); // parse the response
Serial.print("Call IOTSgetTags, nbtags: "); Serial.println((int)nbtags);
if (nbtags < 1) return -1;
Serial.print("tag[0]: ");Serial.println((int)tag[0],HEX);
if (tag[0]!= TAG_CMDID) return -2;
Serial.print("tag[1]: "); Serial.println((int)tag[1]);
if (tag[1]!= TAG_RESP) return -3;
Serial.print("value[1]: "); Serial.println((int)value[1]);
if (value[1] == RESP_KO) return -4;
if (value[1] != RESP_OK) return -5;
// read from the file until there's nothing else in it:
while ((nbytes = FilePicture.read(buf, sizeof(buf))) > 0 && ret == SUCCESS) {
for (uint16_t i = 0;i<nbytes;i++)
{
ret = IOTSerial.IOTSRawsend(1, buf [i]);
}
}// while
//Close file
if (!FilePicture.close()) return FILE_CLOSE_ERROR;
Serial.println("End OK robot_IOT");
return SUCCESS;
}
示例12: setup
void setup() {
Serial.begin(BPS_115200);
PgmPrintln("Type any character to start");
while (!Serial.available());
// PgmPrint("Free RAM: ");
/// Serial.println(FreeRam());
// initialize the SD card at SPI_FULL_SPEED for best performance.
// try SPI_HALF_SPEED if bus errors occur.
if (!card.init(SPI_FULL_SPEED)) error("card.init failed");
// initialize a FAT volume
if (!volume.init(&card)) error("volume.init failed!");
PgmPrint("Type is FAT");
Serial.println(volume.fatType(), DEC);
if (!root.openRoot(&volume)) error("openRoot failed");
// open or create file - truncate existing file.
if (!file.open(&root, "BENCH.DAT", O_CREAT | O_TRUNC | O_RDWR)) {
error("open failed");
}
// fill buf with known data
for (uint16_t i = 0; i < (BUF_SIZE-2); i++) {
buf[i] = 'A' + (i % 26);
}
buf[BUF_SIZE-2] = '\r';
buf[BUF_SIZE-1] = '\n';
PgmPrint("File size ");
Serial.print(FILE_SIZE_MB);
PgmPrintln(" MB");
PgmPrintln("Starting write test. Please wait up to a minute");
// do write test
uint32_t n = FILE_SIZE/sizeof(buf);
uint32_t t = millis();
for (uint32_t i = 0; i < n; i++) {
if (file.write(buf, sizeof(buf)) != sizeof(buf)) {
error("write failed");
}
}
t = millis() - t;
file.sync();
double r = (double)file.fileSize()/t;
PgmPrint("Write ");
Serial.print(r);
PgmPrintln(" KB/sec");
Serial.println();
PgmPrintln("Starting read test. Please wait up to a minute");
// do read test
file.rewind();
t = millis();
for (uint32_t i = 0; i < n; i++) {
if (file.read(buf, sizeof(buf)) != sizeof(buf)) {
error("read failed");
}
}
t = millis() - t;
r = (double)file.fileSize()/t;
PgmPrint("Read ");
Serial.print(r);
PgmPrintln(" KB/sec");
PgmPrintln("Done");
}
示例13: if
void MP3Player::PlayTrack(const char* dirName,int track_no,const char* track_name)
{
if(!PLAY)
{
finishSearch = false;
int count=0;
//if(track_no>0)
//counter = track_no;
if(!isPlayAll)
{
char temp[20];
isPlayAll = true;
sd.chdir();delayMicroseconds(100000);
sd.chdir(dirName,true);
sd.vwd()->rewind();
sd.vwd()->getName(temp,20);
currentDir = temp;
counter = 0;
}
while(true)
{
if(myFile.openNext(myFile.cwd(), O_READ))
{
char FileName[80];
myFile.getName(FileName,80);
#if DEBUG
//myFile.printName(&Serial);
Serial.print(FileName);
if (myFile.isDir())
{
// Indicate a directory.
Serial.write('/');
}
Serial.println();
#endif
if (!(myFile.isDir()||(String(FileName).indexOf(".mp3")==-1&&String(FileName).indexOf(".MP3")==-1)))
{
counter++;
if(ls_flag)
{
Serial.print(counter);
Serial.print(". ");
Serial.print(FileName);
Serial.print(" ");
Serial.print(myFile.fileSize());
Serial.println(" bytes");
myFile.close();
continue;
}
//Play(FileName);
if(!String(track_name).equals(""))
{
//counter++;
if(String(track_name).equals(FileName))
{
Play(FileName);
//name = track_name;
isPlayAll = false;
break;
}
}
else if(track_no==0)
{
//counter++;
Play(FileName);
break;
}
else if(track_no>0)
{
count++;
if(count==track_no)
{
counter = track_no;
Play(FileName);
isPlayAll = false;
break;
}
}
}
}
else
{
isPlayAll = false;
finishSearch = true;
ls_flag = false;
break;
}
//myFile.getFilename(FileName);
myFile.close();
}
//.........这里部分代码省略.........
示例14: fileSize
uint32_t SDCard_FileHandler::fileSize(String file){
SdFile myFile; myFile.open(file);
auto size = myFile.fileSize();
return size;
}