Initialization without operator= defined

I made this class myBluetooth with a BufferedSerial object. How do I initialize it?

class myBluetooth
{
    BufferedSerial blutooth;
    public:
    myBluetooth();
};

This doesn’t work(in class definition): BufferedSerial blutooth(Tx,Rx);. It gives error unknown type name PA_9,PA_10 (Tx, Rx resolves to those using a macro). Neither can I initialize it in the constructor: blutooth = BufferedSerial(Tx,Rx). This gives the error: copy assignment is implicitly deleted.


Reason why I’m doing this: I want to make several programs and not compile mbed-os every time in mbed IDE(long story-power outage, I’m running on backup power). So I’m using classes for different examples. I thought this would be a perfect reason to use the online IDE but neither can I make mbed OS-6 work on the online IDE nor can I include string_view and bufferedserial.

Hello,

I am not sure if i understand your requirements

class myBluetooth
{
    BufferedSerial* _blutooth;
    public:
    myBluetooth(BufferedSerial* serial):_blutooth(serial){}
};
// or
class myBluetooth
{
    BufferedSerial* _blutooth;
    public:
    myBluetooth(){
        _blutooth = new BufferedSerial(Tx, Rx);
    }
};
// or
class myBluetooth
{
    BufferedSerial _blutooth;
    public:
    myBluetooth(PinName Tx, PinName Rx):_blutooth(Tx, Rx){}
};

BR, Jan

Yes I already figured the second one would work. But now I can’t get std::string to work. Linker shows undefined symbol errors for __2swprintf, wcslen, wcstol, wcstoll, wcstoul, wcstoull, wmemchr, wmemcmp, wmemcpy, wmemmove , wmemset, __wcstod_int, __wcstof_int. (Works with nucleo-f446re, but not with f103rb).

Can you show how you want to use the string?

The differentiation between F1 and F4 can be affected with the C library settings maybe. The F4 uses STD but F1 uses small one for reduction of code size because F1 targets are low memory targets usually.

BR, Jan

Exactly like this: What is the best way of manipulating strings and using them as void*? - #3 by wubaojun

std::string message = "Hello";
std::string_view buff(message);
bluetooth.write(buff.begin(), buff.size());

The problem occurs in the first line. It doesn’t even let me define strings.

Do you have?

#include <string>

BR, Jan

Yes.
Also I do understand the memory limitations of the f103 family. Any old string manipulation functionality would do, no matter how primitive it is.

Then I do not know, I tried to compile it and no errors.

//Nucleo-F103RB, MbedOS 6.10
#include "mbed.h"
#include <string>

#define Tx CONSOLE_TX
#define Rx CONSOLE_RX

class myBluetooth
{
    BufferedSerial* _bluetooth;
    public:
    myBluetooth(){
        _bluetooth = new BufferedSerial(Tx, Rx);
    }
    void send(){
        std::string message = "Hello";
        std::string_view buff(message);
        _bluetooth->write(buff.begin(), buff.size());
    }
};

int main(){
    printf("Mbed OS version %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
    std::string message = "Hello";
    printf("Test %s\n", message.c_str());
    myBluetooth bt;

    while(true) {
        bt.send();
        thread_sleep_for(1000);
    }
}

BR, Jan

Nope. No matter how many different ways I try, std::string always give undefined symbol errors. I can, however, do std::string_view("Hello"); directly and that doesn’t have any problems. As soon as I try to define/manipulate(e.g. concatenate) strings, undefined symbol errors show up.

All these functions are the wide character variant while std::string should be the narrow char variant. I don’t know how the compiler could generate function calls for wide strings but it seems it does.