2 Replies Latest reply on Jul 4, 2015 5:27 AM by user_14586677

    How to use a data structure in a BLE custom characteristic field?

    rick.rice

      Does anybody know how to define a data structure in a BLE custom characteristic field?  In the drop-down menu where you select data types, "struct" is listed.  It's unclear to me how to define the structure.  Screen shot attached.

         

      For example, my screenshot shows uint8, however, I want to use a structure:

         

      struct data

         

      {

         

      uint8 x;

         

      uint16 y;

         

      }

        • 1. Re: How to use a data structure in a BLE custom characteristic field?
          rick.rice

          I figured out what the Fields entry and associated Type drop-down are doing.  This is simply allocating memory in the form of uint8.  Different data types are listed for convenience so the user doesn't have to do the math.  In the case of structs, arrays, and other data types where it is impossible to know the memory requirements, the user must manually calculate the length and enter it in the Length entry. 

             

          In my case, I have a struct, the actual structure is not defined in the BLE configuration, just the memory requirements.  In my structure, the Length is 3.  When you want to send the structure in your code, simply cast it as a uint8 pointer.

             

          typedef struct data

             

          {

             

          uint8 x;

             

          uint16 y;

             

          }data;

             

           

             

          data val;

             

           

             

          CYBLE_GATTS_HANDLE_VALUE_NTF_T MyHandle;

             

          MyHandle.value.val = (uint8 *) &val;

             

          MyHandle.value.len = sizeof(val);

             
                  
          • 2. Re: How to use a data structure in a BLE custom characteristic field?
            user_14586677

            A struc in memory is in a general sense just a set aside of a given

               

            chunk. So pointers can effectively treat it as a chunk of bytes, words,

               

            longs, whatever, and operate on it as a whole, rather than specific

               

            structure variables.

               

             

               

            Thats one way,. for example, a struc can be handled in FLASH or EE

               

            when a save/restore operation is called for. Rather than an update on

               

            one variable in struc.

               

             

               

            Regards, Dana.

            1 of 1 people found this helpful