Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I'm attempting to implement driver-layer from top-level app to hardware.

  • Driver is shared library.
  • Framework: Qt.

In the first, I extracted interface functions, which further will be called from "extern "C" SHARED" wrappers to separate class IDriverInterface.

In the second, I want to hot-test some functions before correct implementation and don't want to use #define, so I created QDriverInterfaceSim class inherits QDriverInterface.

Can anyone suggest me any improvements on this?

IDriverInterface class:

#ifndef IDRIVERINTERFACE_H
#define IDRIVERINTERFACE_H

#include "types.h"

class IDriverInterface
{
public:
    virtual int connectToHardware() = 0;
    virtual int sendData(dev_addr_t dev, com_t com, pdata_t pdata, data_sz_t data_sz) = 0;
    virtual int sendDataWithAck(dev_addr_t dev, com_t com, pdata_t pdata, data_sz_t data_sz, ack_id_t *p_ack_id) = 0;
    virtual int sendDataWithAckBlocked(dev_addr_t dev, com_t com, pdata_t pdata, data_sz_t data_sz, timeout_t timeout_ms) = 0;
    virtual void reg_OnData_callback(onData_callback cb) = 0;
    virtual void reg_OnAck_callback(onAck_callback cb) = 0;
    virtual int addRouteRecord(dev_addr_t dev, dev_addr_t dest, dev_addr_t next) = 0;
    virtual int removeRouteRecord(dev_addr_t dev, dev_addr_t dest) = 0;
    virtual int getRouteTable(dev_addr_t dev, route_t route_table[1], rows_cnt_t *prow_count) = 0;
    virtual int setAutoRoute(dev_addr_t dev, bool en) = 0;
    virtual int ping(dev_addr_t dev, timeout_t timeout_ms) = 0;
};

#endif // IDRIVERINTERFACE_H

#ifndef QDRIVERINTERFACE_H
#define QDRIVERINTERFACE_H

QDriverInterface class:

#include <QObject>
#include <QMutex>
#include <QDebug>
#include "qmyserialport.h"
#include "qserialportconfigdialog.h"
#include "qserialportinterface.h"
#include "idriverinterface.h"
#include "types.h"

class QDriverInterface : public QObject, public IDriverInterface
{
    Q_OBJECT
public:
    explicit QDriverInterface(QObject *parent = 0);

    // from IDriverInterface
    virtual int connectToHardware();
    virtual int sendData(dev_addr_t dev, com_t com, pdata_t pdata, data_sz_t data_sz);
    virtual int sendDataWithAck(dev_addr_t dev, com_t com, pdata_t pdata, data_sz_t data_sz, ack_id_t *p_ack_id);
    virtual int sendDataWithAckBlocked(dev_addr_t dev, com_t com, pdata_t pdata, data_sz_t data_sz, timeout_t timeout_ms);
    virtual void reg_OnData_callback(onData_callback cb);
    virtual void reg_OnAck_callback(onAck_callback cb);
    virtual int addRouteRecord(dev_addr_t dev, dev_addr_t dest, dev_addr_t next);
    virtual int removeRouteRecord(dev_addr_t dev, dev_addr_t dest);
    virtual int getRouteTable(dev_addr_t dev, route_t route_table[1], rows_cnt_t *prow_count);
    virtual int setAutoRoute(dev_addr_t dev, bool en);
    virtual int ping(dev_addr_t dev, timeout_t timeout_ms);

private slots:
    void setSerialParams();

protected:
    onData_callback m_onData;
    onAck_callback m_onAck;
    void debug_print(QString fun_name, QString msg = "");

private:
    void init();    
    void showConfigDialog();
    void sendTestPacket();

    QMySerialPort *m_serialPort;
    QSerialPortConfigDialog *m_serialConfigDialog;
    QSerialPortInterface *m_SerialPortInterface;
};

#endif // QDRIVERINTERFACE_H

QDriverInterfaceSim class:

#ifndef QDRIVERINTERFACESIM_H
#define QDRIVERINTERFACESIM_H

#include <QObject>
#include <QDebug>
#include "qdriverinterface.h"

class QDriverInterfaceSim : public QDriverInterface
{
    Q_OBJECT
public:
    explicit QDriverInterfaceSim(QObject *parent = 0);

    // from IDriverInterface
    //virtual int connectToHardware() { return 0;}
    virtual int sendData(dev_addr_t dev, com_t com, pdata_t pdata, data_sz_t data_sz);
    //virtual int sendDataWithAck(dev_addr_t dev, com_t com, pdata_t pdata, data_sz_t data_sz, ack_id_t *p_ack_id) { return 0;}
    //virtual int sendDataWithAckBlocked(dev_addr_t dev, com_t com, pdata_t pdata, data_sz_t data_sz, timeout_t timeout_ms) { return 0;}
    //virtual void reg_OnData_callback(onData_callback cb);
    //virtual void reg_OnAck_callback(onAck_callback cb);
    //virtual int addRouteRecord(dev_addr_t dev, dev_addr_t dest, dev_addr_t next) { return 0;}
    //virtual int removeRouteRecord(dev_addr_t dev, dev_addr_t dest) { return 0;}
    //virtual int getRouteTable(dev_addr_t dev, route_t route_table[1], rows_cnt_t *prow_count) { return 0;}
    //virtual int setAutoRoute(dev_addr_t dev, bool en) { return 0;}
    //virtual int ping(dev_addr_t dev, timeout_t timeout_ms) { return 0;}

private slots:
    void callOnData();
    void callOnAck();

private:
    void setOnData(onData_callback cb, dev_addr_t *pdev, com_t *pcom, pdata_t pdata, data_sz_t *pdata_sz);

private:
    dev_addr_t *m_pdev;
    com_t *m_pcom;
    pdata_t m_pdata;
    data_sz_t *m_pdata_sz;
};

#endif // QDRIVERINTERFACESIM_H
share|improve this question
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.