Naming SD log file base name with the Serial Number of the SD card

Hi!

I’m working with OFFscope and SD library. The log files are name FILE_BASE_NAME “” and after we append FILE_BASE_NAME “00.bin”

In every restart of the system, the <00> number is increased.

I need to replace FILE_BASE_NAME “” with the serial number of the SD card.
I take the serial number with: <cid_t cid;> and <cid.psn;>

How can I change the char “” by the value returned by <cid.psn;>?

Thanks, Roberto

#ifdef __AVR__
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include "AnalogBinLogger.h"
#include <SdInfo.h>

// log file base name.  Must be six characters or less.
#define FILE_BASE_NAME "Test"

// Temporary log file.  Will be deleted if a reset or power failure occurs.
#define TMP_FILE_NAME "tmp.bin"

// Size of file base name.  Must not be larger than six.
   const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1;

   char binName[13] = FILE_BASE_NAME "00.bin";
   //............some code
   if (BASE_NAME_SIZE > 6) {
    //............some code
    }
    //............some code
    while (sd.exists(binName)) {
      if (binName[BASE_NAME_SIZE + 1] != '9') {
        binName[BASE_NAME_SIZE + 1]++;
        } else {
          binName[BASE_NAME_SIZE + 1] = '0';
          if (binName[BASE_NAME_SIZE] == '9') {
            //............some code
          }
        binName[BASE_NAME_SIZE]++;
      }
    }
  
    //............some code
//------------------------------------------------------------------------------
void setup(void) {
	//............some code
  Serial.begin(115200);
  cid_t cid;
  Serial.println(cid.psn);
  //......some code
}
//------------------------------------------------------------------------------
void loop(void) {   
   //............some code
}
#else  // __AVR__
#error This program is only for AVR.
#endif  // __AVR__

Test.ino (1.35 KB)

uint32_t psn;  // Product serial number

cid.psn appears to be a 32 bit unsigned int (aka a long) variable

You can convert a long to a string using the sprintf() function and at the same time add other characters to make a unique filename