I am not receiving a printf of a char sbFirstStartValue[BUFSIZ] variable

07 Nov 2012

EDIT

My getValue syntax for the ConfigFile library was wrong

Original Code(NOT WORKING):

if (_cfg.getValue(sbNameKey, &sbNameValue[0], sizeof(sbNameValue[0]))) {}

Working Code:

if (_cfg.getValue(sbNameKey, &sbNameValue[0], sizeof(sbNameValue))) {}

My code works along side of ConfigFile to grab keys and values from the SETTINGS.CFG file that is located on my mbed. Please view http://mbed.org/users/d0773d/code/ for the complete code example. There will be a code list for Sensors, and my two libraries: cfExtensions and msExtensions

I am not sure why sbNameValue value is blank. I declared the sbNameValue in the cfExtensions.h file.

This works as a test:

//As a test, outputs FirstStart which is the correct value.
_msAccess->sendSomething(sbFirstStartKey)

What am I not doing correctly to get the value from: char sbFirstStartValue[BUFSIZ]? Here are sections of code from the original files:

//File: cfExtensions.h
class cfExtensions
{    
public:
        char sbFirstStartValue[BUFSIZ];

        void msSendSomething();
        
        void getFirstStartValue();

//..
}

//File: cfExtensions.cpp:

void cfExtensions::msSendSomething() {
    _msAccess->sendSomething(sbNameValue);
}
 
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//================================
// Load Config File
//================================
void cfExtensions::loadConfigFile() {
    /*
     * Read a configuration file from a mbed.
     */
    if (!_cfg.read("/local/settings.cfg")) {
        printf("Failure to read a configuration file.");
    }
}  // End of loadConfigFile

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//================================
// Get ConfigFile Values
//================================
void cfExtensions::getFirstStartValue() {
    if (_cfg.getValue(sbFirstStartKey, &sbFirstStartValue[0], sizeof(sbFirstStartValue[0]))) {}
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//================================
// Check if MBED First Start
//================================
void cfExtensions::checkConfigForFirstStart() {
    /*
     * Get a configuration value.
     */
     
    //This works : _msAcess->sendSomething(sbFirstStartKey);
    printf("{\"sb\": \"%s\"}\r\n", sbFirstStartValue);
    _msAccess->sendSomething(sbFirstStartValue);
    if (strcmp(&sbFirstStartValue[0], "TRUE") == 0) {
        _msAccess->sendSomething("checkConfigForFirstStart() EXECUTED!");
        
         _msAccess->sendSomething(cfExtensions::sbNameValue);
         pingTick.attach(this, &cfExtensions::msSendSomething, 10);

         while(!_pc->readable()) {
              if (cfExtensions::pingTicked) {
                   cfExtensions::pingTicked = false;
              }
         }
            
         if(_pc->readable()) {
              pingTick.detach();
         }
            
         _cfg.setValue("FirstStart", "FALSE");
         _cfg.write("/local/settings.cfg");
     }
} // End of checkConfigForFirstStart

<<code>>

<<code>>
//File: msExtensions.h

class msExtensions
{
public:
//---------------------------
// Function Prototypes
//---------------------------
        msExtensions();               // Default Constructor
        msExtensions(MODSERIAL *pc);  // Constructor, Initialization tasks                     
        
        void pcRecvInterrupt(MODSERIAL_IRQ_INFO *q);
        void pingBaseStation();
        int msBaud();
        
        void sendSomething(char* txt);
}
<</code>>

<<code>>
//File msExtensions:

void msExtensions::sendSomething(char* txt) {
    printf("{\"sbPing\": \"%s\"}\r\n", txt);
} // End of pingBaseStation function