B4R Question [inline c] get array by pointer

peacemaker

Expert
Licensed User
Longtime User
Hi, All

C-code:
  const uint8_t* point = esp_bt_dev_get_address();

  for (int i = 0; i < 6; i++) {
    char str[3];
    sprintf(str, "%02X", (int)point[i]);
    Serial.print(str);

    if (i < 5) {
      Serial.print(":");
    }
  }

How to get correctly the mac-address array to MacArray by this pointer got inside inline-c ? (it's not WiFi's mac-address that is got as array).

B4R:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public MacArray(6) As Byte
End Sub

Sub Get_btMacAddress() As Byte()
    RunNative("getBTMac", Null)
    Return MacArray
End Sub
#if C
#include "esp_bt_main.h"
#include "esp_bt_device.h"
  void getBTMac(B4R::Object* u) {
      const uint8_t* point = esp_bt_dev_get_address();
    //(Byte*)b4r_others::_macarray->data = point; ????
  }

#end if
 

peacemaker

Expert
Licensed User
Longtime User
Strange, it's not pointer, but SOLVED:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public MacArray(6) As Byte
End Sub

Sub Get_btMacAddress
    RunNative("getBTMac", Null)
End Sub
#if C
#include "esp_bt_main.h"
#include "esp_bt_device.h"
  void getBTMac(B4R::Object* u) {
      const uint8_t* point = esp_bt_dev_get_address();
    memcpy(b4r_others::_macarray->data, point, 6);
  }
#end if

********************* PROGRAM STARTING ****************
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13260
load:0x40080400,len:3028
entry 0x400805e4
AppStart
0
Device_btMAC = 083AF2A78EAE
Waiting for incoming BT connection from a client
 
Last edited:
Upvote 0
Top