SSCMA-Micro CPP SDK  v2.0.0
SSCMA-Micro is a cross-platform machine learning inference framework designed for embedded devices.
info.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 #include "core/ma_core.h"
6 #include "porting/ma_porting.h"
7 #include "resource.hpp"
8 
9 namespace ma::server::callback {
10 
11 using namespace ma;
12 
13 void storeInfo(const std::vector<std::string>& argv, Transport& transport, Encoder& encoder) {
14  ma_err_t ret = MA_OK;
15  std::string key = MA_AT_CMD_INFO;
16 
17  if (argv.size() < 2) {
18  ret = MA_EINVAL;
19  goto exit;
20  }
21 
22  key += '#';
23  key += std::to_string(static_cast<int>(static_resource->current_model_id));
24 
25  MA_STORAGE_SET_STR(ret, static_resource->device->getStorage(), key, argv[1]);
26 
27 exit:
28  encoder.begin(MA_MSG_TYPE_RESP, ret, argv[0]);
29  encoder.write("info", argv.size() < 2 ? "" : argv[1]);
30  encoder.end();
31  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
32 }
33 
34 void readInfo(const std::vector<std::string>& argv, Transport& transport, Encoder& encoder) {
35  ma_err_t ret = MA_OK;
36  std::string key = MA_AT_CMD_INFO;
37  std::string value;
38 
39  if (argv.size() < 1) {
40  ret = MA_EINVAL;
41  goto exit;
42  }
43 
44  key += '#';
45  key += std::to_string(static_cast<int>(static_resource->current_model_id));
46 
47  MA_STORAGE_GET_STR(static_resource->device->getStorage(), key, value, "");
48 
49 exit:
50  encoder.begin(MA_MSG_TYPE_RESP, ret, argv[0]);
51  encoder.write("info", value);
52  encoder.end();
53  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
54 }
55 
56 } // namespace ma::server::callback
Definition: ma_codec_base.h:14
virtual ma_err_t end()=0
Encoder type for end.
virtual const void * data() const =0
Encoder type for get data.
virtual ma_err_t begin()=0
Encoder type for begin.
virtual ma_err_t write(const std::string &key, int8_t value)=0
Encoder type for write int8_t value.
virtual const size_t size() const =0
Encoder type for get size.
Definition: ma_transport.h:12
virtual size_t send(const char *data, size_t length) noexcept=0
#define MA_AT_CMD_INFO
Definition: ma_definations.h:67
@ MA_MSG_TYPE_RESP
Definition: ma_types.h:252
ma_err_t
Definition: ma_types.h:21
@ MA_OK
Definition: ma_types.h:23
@ MA_EINVAL
Definition: ma_types.h:28
Definition: algorithm.hpp:11
void storeInfo(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: info.hpp:13
void readInfo(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: info.hpp:34
Definition: ma_cv.cpp:7
#define static_resource
Definition: resource.hpp:64