SSCMA-Micro CPP SDK  v2.0.0
SSCMA-Micro is a cross-platform machine learning inference framework designed for embedded devices.
ma_server_at.h
Go to the documentation of this file.
1 #ifndef _MA_SERVER_AT_H_
2 #define _MA_SERVER_AT_H_
3 
4 #include <functional>
5 #include <string>
6 #include <forward_list>
7 
8 #include "codec/ma_codec.h"
9 #include "core/ma_core.h"
10 #include "porting/ma_porting.h"
11 
12 #ifndef MA_SEVER_AT_EXECUTOR_STACK_SIZE
13  #define MA_SEVER_AT_EXECUTOR_STACK_SIZE 20 * 1024
14 #endif
15 
16 #ifndef MA_SEVER_AT_EXECUTOR_TASK_PRIO
17  #define MA_SEVER_AT_EXECUTOR_TASK_PRIO 2
18 #endif
19 
20 #ifndef MA_SEVER_AT_CMD_MAX_LENGTH
21  #define MA_SEVER_AT_CMD_MAX_LENGTH 4096
22 #endif
23 
24 namespace ma {
25 
26 class ATServer;
27 
28 typedef std::function<ma_err_t(std::vector<std::string>, Transport&, Encoder&)> ATServiceCallback;
29 
30 struct ATService {
31  ATService(const std::string& name, const std::string& desc, const std::string& args, ATServiceCallback cb);
32 
33  std::string name;
34  std::string desc;
35  std::string args;
36  uint8_t argc;
38 
39  friend class ATServer;
40 };
41 
42 class ATServer {
43  public:
44  ATServer(Encoder& codec);
45  ATServer(Encoder* codec);
46  ~ATServer() = default;
47 
48  ma_err_t init();
49 
50  ma_err_t start();
51  ma_err_t stop();
52 
53  public:
54  ma_err_t addService(const std::string& name,
55  const std::string& desc,
56  const std::string& args,
58  ma_err_t addService(ATService& service);
59  ma_err_t removeService(const std::string& name);
60  ma_err_t execute(std::string line, Transport& transport);
61  ma_err_t execute(std::string line, Transport* transport);
62 
63  protected:
64  void threadEntry();
65 
66  private:
67  static void threadEntryStub(void* arg);
68  Thread* m_thread;
69  Encoder& m_encoder;
70  std::forward_list<ATService> m_services;
71 };
72 
73 } // namespace ma
74 
75 #endif // _MA_SERVER_AT_H_
Definition: ma_server_at.h:42
ma_err_t stop()
Definition: ma_server_at.cpp:361
ma_err_t init()
Definition: ma_server_at.cpp:91
void threadEntry()
Definition: ma_server_at.cpp:60
ma_err_t addService(const std::string &name, const std::string &desc, const std::string &args, ATServiceCallback cb)
Definition: ma_server_at.cpp:365
ma_err_t removeService(const std::string &name)
ma_err_t start()
Definition: ma_server_at.cpp:340
~ATServer()=default
ATServer(Encoder &codec)
Definition: ma_server_at.cpp:49
ma_err_t execute(std::string line, Transport &transport)
Definition: ma_server_at.cpp:370
Definition: ma_codec_base.h:14
Definition: ma_osal.h:40
Definition: ma_transport.h:12
ma_err_t
Definition: ma_types.h:21
Definition: ma_cv.cpp:7
std::function< ma_err_t(std::vector< std::string >, Transport &, Encoder &)> ATServiceCallback
Definition: ma_server_at.h:26
Definition: ma_server_at.h:30
uint8_t argc
Definition: ma_server_at.h:36
std::string desc
Definition: ma_server_at.h:34
ATServiceCallback cb
Definition: ma_server_at.h:37
std::string args
Definition: ma_server_at.h:35
ATService(const std::string &name, const std::string &desc, const std::string &args, ATServiceCallback cb)
Definition: ma_server_at.cpp:29
std::string name
Definition: ma_server_at.h:33