本文整理汇总了C++中SdFile::write方法的典型用法代码示例。如果您正苦于以下问题:C++ SdFile::write方法的具体用法?C++ SdFile::write怎么用?C++ SdFile::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SdFile
的用法示例。
在下文中一共展示了SdFile::write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: app_process_file_write
idigi_callback_status_t iDigiFileSystem::app_process_file_write(idigi_file_write_request_t * const request_data,
idigi_file_write_response_t * const response_data)
{
idigi_callback_status_t status = idigi_callback_continue;
SdFile *file = (SdFile *) request_data->handle;
file->clearWriteError();
size_t wrote = file->write(request_data->data_ptr, request_data->size_in_bytes);
if (file->getWriteError())
{
response_data->error->error_status = idigi_file_unspec_error;
APP_DEBUG("write attempt %d, returned err (wrote: %d)\n", request_data->size_in_bytes, wrote);
goto done;
}
APP_DEBUG("write attempt %d, wrote: %d\n", request_data->size_in_bytes, wrote);
response_data->size_in_bytes = wrote;
done:
return status;
}
示例2: logData
void logData(char *data) {
int n;
n=file.write(data,strlen(data));
console.printf("DBG: Logging (%d)'%s'",n,data);
file.sync();
}
示例3: 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");
}
示例4: writeGPSLog
void writeGPSLog(uint32_t gpstime, int32_t latitude, int32_t longitude, int32_t altitude) {
#else
void writeGPSLog(int32_t latitude, int32_t longitude, int32_t altitude) {
#endif
if (f.SDCARD == 0) return;
if (gps_data.open(GPS_LOG_FILENAME, O_WRITE | O_CREAT | O_APPEND)) {
#ifdef UBLOX
gps_data.print(gpstime); gps_data.write(',');
#endif
gps_data.print(latitude); gps_data.write(',');
gps_data.print(longitude); gps_data.write(',');
gps_data.print(altitude); gps_data.println();
gps_data.close();
} else {
return;
}
}
void writePLogToSD() {
if (f.SDCARD == 0) return;
plog.checksum = calculate_sum((uint8_t*)&plog, sizeof(plog));
if (permanent.open(PERMANENT_LOG_FILENAME, O_WRITE | O_CREAT | O_TRUNC)) {
permanent.print(F("arm=")); permanent.println(plog.arm);
permanent.print(F("disarm=")); permanent.println(plog.disarm);
permanent.print(F("start=")); permanent.println(plog.start);
permanent.print(F("armed_time=")); permanent.println(plog.armed_time);
permanent.print(F("lifetime=")); permanent.println(plog.lifetime, DEC);
permanent.print(F("failsafe=")); permanent.println(plog.failsafe);
permanent.print(F("i2c=")); permanent.println(plog.i2c);
permanent.print(F("running=")); permanent.println(plog.running, DEC);
permanent.print(F("checksum=")); permanent.println(plog.checksum, DEC);
permanent.print(F("debug=")); permanent.print(debug[0]);
permanent.print(F(",")); permanent.print(debug[1]);
permanent.print(F(",")); permanent.print(debug[2]);
permanent.print(F(",")); permanent.println(debug[3]);
permanent.println();
permanent.close();
} else {
return;
}
}
void fillPlogStruct(char* key, char* value) {
if (strcmp(key, "arm") == 0) sscanf(value, "%u", &plog.arm);
if (strcmp(key, "disarm") == 0) sscanf(value, "%u", &plog.disarm);
if (strcmp(key, "start") == 0) sscanf(value, "%u", &plog.start);
if (strcmp(key, "armed_time") == 0) sscanf(value, "%lu", &plog.armed_time);
if (strcmp(key, "lifetime") == 0) sscanf(value, "%lu", &plog.lifetime);
if (strcmp(key, "failsafe") == 0) sscanf(value, "%u", &plog.failsafe);
if (strcmp(key, "i2c") == 0) sscanf(value, "%u", &plog.i2c);
if (strcmp(key, "running") == 0) sscanf(value, "%hhu", &plog.running);
if (strcmp(key, "checksum") == 0) sscanf(value, "%hhu", &plog.checksum);
}
void readPLogFromSD() {
if (f.SDCARD == 0) return;
SdFile myfile;
char key[12];
char value[32];
char* tabPtr = key;
int c;
uint8_t i = 0;
if (myfile.open(PERMANENT_LOG_FILENAME, O_READ)) {
while (myfile.available()) {
c = myfile.read();
switch ((char)c) {
case ' ':
break;
case '=':
*tabPtr = '\0';
tabPtr = value;
break;
case '\n':
*tabPtr = '\0';
tabPtr = key;
i = 0;
fillPlogStruct(key, value);
memset(key, '\0', sizeof(key));
memset(value, '\0', sizeof(value));
break;
default:
i++;
if (i <= 12) {
*tabPtr = (char)c;
tabPtr++;
}
break;
}
}
} else return;
if (calculate_sum((uint8_t*)&plog, sizeof(plog)) != plog.checksum) {
#if defined(BUZZER)
alarmArray[7] = 3;
blinkLED(9, 100, 3);
#endif
// force load defaults
plog.arm = plog.disarm = plog.start = plog.failsafe = plog.i2c = 11;
plog.running = 1;
plog.lifetime = plog.armed_time = 3;
//.........这里部分代码省略.........