3 Replies Latest reply on Oct 20, 2017 12:08 PM by e.pratt_1639216

    change device name and const problem

    denis.touillon_1826166

      Hello,

       

      I want to change the device name dynamically, it's working correctly when the device is powered.

       

      But after the reset, the content of data in flash is the inizialisation value of the constant & with the value stored in flash

       

      I declare a constant with initialisation value  (is it not supposed to be initialised only once ?)

       

       

      const char8 deviceNameInFlash[20] = {'D','e','f','a','u','l','t')};

       

       

      ----------------------------

      In the stack :

       

         case CYBLE_EVT_STACK_ON: /* This event is received when component is Started */

        CyBle_GapSetLocalName(deviceNameInFlash);

        CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);

       

      break;

       

      ---------------------------

       

        if(CYBLE_SHUTBASSCV_DEVICENAME_CHAR_HANDLE == wrReqParam->handleValPair.attrHandle)

                  {

                    for(i=0;i<wrReqParam->handleValPair.value.len;i++)

                  {/*Client has to write the ASCI values of the characters that are in the name*/

                      tempName[i]=wrReqParam->handleValPair.value.val[i];

                    

                  }   

                  StoreInFlash(tempName, wrReqParam->handleValPair.value.len); 

                 

                 

                      communHandle.attrHandle = CYBLE_SHUTBASSCV_DEVICENAME_CHAR_HANDLE;

                      communHandle.value.val = (uint8*) tempName;

                      communHandle.value.len = wrReqParam->handleValPair.value.len;

                      CyBle_GattsWriteAttributeValue(&communHandle,FALSE,&connectionHandle,FALSE);

         

                  }

       

      void StoreInFlash( char8 *newData, uint8 length)

      {

          CYBLE_API_RESULT_T result;

          CyBle_ExitLPM();

          do

          {

              result = CyBle_StoreAppData((uint8*)newData, (uint8*)&deviceNameInFlash,length,0);

             

          }

          while (result!=CYBLE_ERROR_OK);

          CyBle_GapSetLocalName((const char *)newData);   

      }

       

       

       

       

      If the user replace the name by "test" , when disconnect/reconnect we have 'test'

       

      But after device reset we have : "testult"

       

       

       

       

       

      So the data in flash is reseted, and i don't understand why, "const " is not supposed to mean initialized once ?

       

      Thanks for your answers.