~aleteoryx/muditaos

ref: ea27e6871615172000db8664a9d11d1b6103c562 muditaos/module-cellular/Modem/TS0710/DLC_channel.h -rw-r--r-- 2.2 KiB
ea27e687 — Maciej Janicki [EGD-5748] Remake Cellular flow 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

/**
 * Project Untitled
 */

#ifndef _DLC_CHANNEL_H
#define _DLC_CHANNEL_H

#include <string>
#include <vector>
#include <functional>

#include "Modem/ATCommon.hpp"
#include "TS0710_types.h"
#include <bsp/cellular/CellularResult.hpp>
#include <FreeRTOS.h>
#include <task.h>
#include <message_buffer.h>

class DLC_channel : public at::Channel
{
  public:
    using Callback_t = std::function<void(std::string &data)>;

  private:
    std::string pv_name;
    DLCI_t pv_DLCI;
    bool active = false;
    DLC_ESTABL_SystemParameters_t chanParams{};
    Callback_t pv_callback;
    bsp::Cellular *pv_cellular{};

  public:
    DLC_channel(DLCI_t DLCI, const std::string &name, bsp::Cellular *cellular, const Callback_t &callback = nullptr);
    DLC_channel() : Channel{nullptr}, pv_name{"none"}, pv_DLCI{-1}
    {}

    virtual ~DLC_channel();

    bool init();
    bool establish();

    void SendData(std::vector<uint8_t> &data);

    DLCI_t getDLCI()
    {
        return pv_DLCI;
    }
    std::string getName()
    {
        return pv_name;
    }
    bool getActive()
    {
        return active;
    }

    void setCallback(Callback_t callback)
    {
        LOG_DEBUG("[%s] Setting up callback for channel", pv_name.c_str());
        pv_callback = callback;
    }

    virtual void cmd_init() override final;
    virtual void cmd_send(std::string cmd) override final;
    virtual size_t cmd_receive(std::uint8_t *result,
                               std::chrono::milliseconds timeout = std::chrono::milliseconds{300}) override final;
    virtual void cmd_post() override final;

    std::vector<std::string> SendCommandPrompt(const char *cmd,
                                               size_t rxCount,
                                               std::chrono::milliseconds timeout = std::chrono::milliseconds{300});

    at::Result ParseInputData(bsp::cellular::CellularResult *cellularResult);

    bool evaluateEstablishResponse(bsp::cellular::CellularResult &response) const;

    void callback(std::string &data)
    {
        pv_callback(data);
    }
};

#endif //_DLC_CHANNEL_H