SSCMA-Micro CPP SDK  v2.0.0
SSCMA-Micro is a cross-platform machine learning inference framework designed for embedded devices.
common.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <atomic>
4 #include <string>
5 
6 #include "core/ma_core.h"
7 #include "porting/ma_porting.h"
8 #include "resource.hpp"
9 
10 namespace ma::server::callback {
11 
12 using namespace ma;
13 
14 void get_device_id(const std::string& cmd, Transport& transport, Encoder& encoder) {
15  encoder.begin(MA_MSG_TYPE_RESP, MA_OK, cmd, static_resource->device->id());
16  encoder.end();
17  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
18 }
19 
20 void get_device_name(const std::string& cmd, Transport& transport, Encoder& encoder) {
21  encoder.begin(MA_MSG_TYPE_RESP, MA_OK, cmd, static_resource->device->name());
22  encoder.end();
23  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
24 }
25 
26 void get_device_status(const std::string& cmd, Transport& transport, Encoder& encoder) {
27  encoder.begin(MA_MSG_TYPE_RESP, MA_OK, cmd);
28  encoder.write("boot_count", static_cast<int32_t>(static_resource->device->bootCount()));
29  encoder.write("is_ready", static_cast<int32_t>(static_resource->is_ready ? 1 : 0));
30  encoder.end();
31  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
32 }
33 
34 void get_version(const std::string& cmd, Transport& transport, Encoder& encoder, const std::string& version) {
35  encoder.begin(MA_MSG_TYPE_RESP, MA_OK, cmd);
36  encoder.write("at_api", version);
37  encoder.write("software", MA_VERSION);
38  encoder.write("hardware", static_resource->device->version());
39  encoder.end();
40  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
41 }
42 
43 void break_task(const std::string& cmd, Transport& transport, Encoder& encoder) {
44  encoder.begin(MA_MSG_TYPE_RESP, MA_OK, cmd, static_cast<uint64_t>(ma_get_time_ms()));
45  encoder.end();
46  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
47 }
48 
49 void task_status(const std::string& cmd, bool sta, Transport& transport, Encoder& encoder) {
50  encoder.begin(MA_MSG_TYPE_RESP, MA_OK, cmd, static_cast<uint64_t>(sta));
51  encoder.end();
52  transport.send(reinterpret_cast<const char*>(encoder.data()), encoder.size());
53 }
54 
55 } // 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_VERSION
Definition: ma_common.h:17
int64_t ma_get_time_ms(void)
@ MA_MSG_TYPE_RESP
Definition: ma_types.h:252
@ MA_OK
Definition: ma_types.h:23
Definition: algorithm.hpp:11
void task_status(const std::string &cmd, bool sta, Transport &transport, Encoder &encoder)
Definition: common.hpp:49
void break_task(const std::string &cmd, Transport &transport, Encoder &encoder)
Definition: common.hpp:43
void get_device_name(const std::string &cmd, Transport &transport, Encoder &encoder)
Definition: common.hpp:20
void get_device_status(const std::string &cmd, Transport &transport, Encoder &encoder)
Definition: common.hpp:26
void get_version(const std::string &cmd, Transport &transport, Encoder &encoder, const std::string &version)
Definition: common.hpp:34
void get_device_id(const std::string &cmd, Transport &transport, Encoder &encoder)
Definition: common.hpp:14
Definition: ma_cv.cpp:7
#define static_resource
Definition: resource.hpp:64