~aleteoryx/muditaos

ref: 9ba4d8cea949692768b4cbb0042fad7999362faa muditaos/module-cellular/modem/ATStream.hpp -rw-r--r-- 1.2 KiB
9ba4d8ce — Lukasz Mastalerz [BH-1838] Relaxation plays in the background for certain song lengths 2 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <at/ErrorCode.hpp>
#include <at/Result.hpp>

namespace at
{
    constexpr auto minATCmdRet = 5; /// minimum return from AT in command mode "<cr<lf>X<cr><lf>"

    class ATStream
    {

      private:
        at::Result result;
        bool atAtTheBegin    = false; /// case for commands like QPING
        bool beginChecked    = false;
        size_t lastPos       = 0;
        size_t lineCounter   = 0;
        size_t rxCount       = 0;
        std::string atBuffer = {};
        bool isATReady       = false;
        uint32_t errcode     = 0;

      protected:
        bool checkATBegin();
        bool checkATEnd();
        void checkError();
        bool parse();
        void countLines();

      public:
        ATStream(size_t rxCount = 0) : rxCount(rxCount)
        {}

        bool write(const std::string &buffer);
        bool isReady()
        {
            return isATReady;
        }
        void reset();
        at::Result getResult()
        {
            return result;
        }

        Result::Code parseState(const std::string &state, uint32_t &errcode);
    };

} // namespace at