Search code examples
functionmbedlora

A function that should return a struct, how can i print this struct in C++?


I'm using mbed online compiler to write a program and upload it to a multitech mDot LoRa tranceiver. my program basically is about sending packets of a specific size to the gateway. at the end of my program I want to get some statistics about the communication. so I've been told to use a function called getStats(); that is in one of the header files (mDot.h). all what is mentioned about this function the mDot.h is the following:

class mDot { 
    public:
    typedef struct {
                uint32_t Up;
                uint32_t Down;
                uint32_t Joins;
                uint32_t JoinFails;
                uint32_t MissedAcks;
        } mdot_stats;

 // get current statistics
 // Join Attempts, Join Fails, Up Packets, Down Packets, Missed Acks

 mdot_stats getStats();

so any ideas please on how can I call this function in my main.cpp and get the values (Up, Down, Joins, JoinFails and MissedAcks) printed in my consle screen. Really appreciate your help as i really need this..

Noman


Solution

  • How about:

    mDot::mdot_stats stats = dot->getStats();
    printf("Number of uplink packets %d\n", stats.Up);