author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Sun, 08 Dec 2024 13:59:36 +0100 | |
changeset 4064 | f273ee835411 |
parent 4045 | 6975b486b07f |
permissions | -rw-r--r-- |
3937
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
1 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
2 |
#include <string.h> |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
3 |
#include <filesystem> |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
4 |
#include <dlfcn.h> |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
5 |
#include <fstream> |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
6 |
#include <iostream> |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
7 |
#include <vector> |
3937
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
8 |
|
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
9 |
#include "Logging.hpp" |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
10 |
|
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
11 |
#include "PLCObject.hpp" |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
12 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
13 |
#include "beremiz.h" |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
14 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
15 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
16 |
// File name of the last transferred PLC md5 hex digest |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
17 |
// with typo in the name, for compatibility with Python runtime |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
18 |
#define LastTransferredPLC "lasttransferedPLC.md5" |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
19 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
20 |
// File name of the extra files list |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
21 |
#define ExtraFilesList "extra_files.txt" |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
22 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
23 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
24 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
25 |
PLCObject::PLCObject(void) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
26 |
{ |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
27 |
m_status.PLCstatus = Empty; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
28 |
m_handle = NULL; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
29 |
m_debugToken = 0; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
30 |
m_argc = 0; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
31 |
m_argv = NULL; |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
32 |
m_PSK_ID = ""; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
33 |
m_PSK_secret = ""; |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
34 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
35 |
|
3937
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
36 |
PLCObject::~PLCObject(void) |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
37 |
{ |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
38 |
} |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
39 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
40 |
uint32_t PLCObject::AppendChunkToBlob( |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
41 |
const binary_t *data, const binary_t *blobID, binary_t *newBlobID) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
42 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
43 |
// Append data to blob with given blobID |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
44 |
// Output new blob's md5 into newBlobID |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
45 |
// Return 0 if success |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
46 |
|
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
47 |
newBlobID->data = (uint8_t *)malloc(MD5::digestsize); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
48 |
if (newBlobID->data == NULL) |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
49 |
{ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
50 |
return ENOMEM; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
51 |
} |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
52 |
|
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
53 |
std::vector<uint8_t> k(blobID->data, blobID->data + blobID->dataLength); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
54 |
|
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
55 |
auto nh = m_mapBlobIDToBlob.extract(k); |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
56 |
if (nh.empty()) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
57 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
58 |
return ENOENT; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
59 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
60 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
61 |
Blob *blob = nh.mapped(); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
62 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
63 |
uint32_t res = blob->appendChunk(data->data, data->dataLength); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
64 |
if (res != 0) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
65 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
66 |
return res; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
67 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
68 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
69 |
MD5::digest_t digest = blob->digest(); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
70 |
|
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
71 |
std::vector<uint8_t> nk((uint8_t*)digest.data, (uint8_t*)digest.data + MD5::digestsize); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
72 |
nh.key() = nk; |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
73 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
74 |
m_mapBlobIDToBlob.insert(std::move(nh)); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
75 |
|
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
76 |
memcpy(newBlobID->data, digest.data, MD5::digestsize); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
77 |
newBlobID->dataLength = MD5::digestsize; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
78 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
79 |
return 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
80 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
81 |
|
3957
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
82 |
uint32_t PLCObject::AutoLoad() |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
83 |
{ |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
84 |
// Load PLC object |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
85 |
uint32_t res = LoadPLC(); |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
86 |
if (res != 0) |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
87 |
{ |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
88 |
return res; |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
89 |
} |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
90 |
|
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
91 |
// Start PLC object |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
92 |
res = StartPLC(); |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
93 |
if (res != 0) |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
94 |
{ |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
95 |
return res; |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
96 |
} |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
97 |
|
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
98 |
return 0; |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
99 |
} |
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
100 |
|
2510c1f935d1
C runtime: add autoload
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3956
diff
changeset
|
101 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
102 |
#define LOG_READ_BUFFER_SIZE 1 << 10 // 1KB |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
103 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
104 |
uint32_t PLCObject::GetLogMessage( |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
105 |
uint8_t level, uint32_t msgID, log_message *message) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
106 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
107 |
char buf[LOG_READ_BUFFER_SIZE]; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
108 |
uint32_t tick; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
109 |
uint32_t tv_sec; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
110 |
uint32_t tv_nsec; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
111 |
|
3956
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
112 |
uint32_t resultLen; |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
113 |
if(m_status.PLCstatus == Empty){ |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
114 |
resultLen = 0; |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
115 |
} else { |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
116 |
resultLen = m_PLCSyms.GetLogMessage( |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
117 |
level, msgID, buf, LOG_READ_BUFFER_SIZE - 1, |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
118 |
&tick, &tv_sec, &tv_nsec); |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
119 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
120 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
121 |
// Get log message with given msgID |
3956
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
122 |
message->msg = (char *)malloc(resultLen + 1); |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
123 |
if (message->msg == NULL) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
124 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
125 |
return ENOMEM; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
126 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
127 |
// Copy the log message into eRPC message |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
128 |
memcpy(message->msg, buf, resultLen); |
3956
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
129 |
message->msg[resultLen] = '\0'; |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
130 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
131 |
message->tick = tick; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
132 |
message->sec = tv_sec; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
133 |
message->nsec = tv_nsec; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
134 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
135 |
return 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
136 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
137 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
138 |
uint32_t PLCObject::GetPLCID(PSKID *plcID) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
139 |
{ |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
140 |
// Get PSK ID |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
141 |
plcID->ID = (char *)malloc(m_PSK_ID.size() + 1); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
142 |
if (plcID->ID == NULL) |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
143 |
{ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
144 |
return ENOMEM; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
145 |
} |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
146 |
memcpy(plcID->ID, m_PSK_ID.c_str(), m_PSK_ID.size()); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
147 |
plcID->ID[m_PSK_ID.size()] = '\0'; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
148 |
|
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
149 |
// Get PSK secret |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
150 |
plcID->PSK = (char *)malloc(m_PSK_secret.size() + 1); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
151 |
if (plcID->PSK == NULL) |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
152 |
{ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
153 |
free(plcID->ID); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
154 |
return ENOMEM; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
155 |
} |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
156 |
memcpy(plcID->PSK, m_PSK_secret.c_str(), m_PSK_secret.size()); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
157 |
plcID->PSK[m_PSK_secret.size()] = '\0'; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
158 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
159 |
return 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
160 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
161 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
162 |
uint32_t PLCObject::GetPLCstatus(PLCstatus *status) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
163 |
{ |
3956
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
164 |
if(m_status.PLCstatus == Empty){ |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
165 |
for(int lvl = 0; lvl < 4; lvl++){ |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
166 |
m_status.logcounts[lvl] = 0; |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
167 |
} |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
168 |
} else { |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
169 |
// Get log counts |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
170 |
for(int lvl = 0; lvl < 4; lvl++){ |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
171 |
m_status.logcounts[lvl] = m_PLCSyms.GetLogCount(lvl); |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
172 |
} |
9b4ffbb95338
C runtime: fix logging, makes test pass
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3949
diff
changeset
|
173 |
} |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
174 |
// Get PLC status |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
175 |
*status = m_status; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
176 |
return 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
177 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
178 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
179 |
uint32_t PLCObject::GetTraceVariables( |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
180 |
uint32_t debugToken, TraceVariables *traces) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
181 |
{ |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
182 |
if(debugToken != m_debugToken) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
183 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
184 |
return EINVAL; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
185 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
186 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
187 |
// Check if there are any traces |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
188 |
m_tracesMutex.lock(); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
189 |
size_t sz = m_traces.size(); |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
190 |
if(sz > 0) |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
191 |
{ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
192 |
// Allocate memory for traces |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
193 |
traces->traces.elements = (trace_sample *)malloc(sz * sizeof(trace_sample)); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
194 |
if(traces->traces.elements == NULL) |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
195 |
{ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
196 |
m_tracesMutex.unlock(); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
197 |
return ENOMEM; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
198 |
} |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
199 |
// Copy traces from vector |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
200 |
memcpy(traces->traces.elements, m_traces.data(), sz * sizeof(trace_sample)); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
201 |
|
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
202 |
// Clear the vector |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
203 |
// note that the data is not freed here, it is meant to be freed by eRPC server code |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
204 |
m_traces.clear(); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
205 |
} |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
206 |
m_tracesMutex.unlock(); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
207 |
|
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
208 |
traces->traces.elementsCount = sz; |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
209 |
traces->PLCstatus = m_status.PLCstatus; |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
210 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
211 |
return 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
212 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
213 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
214 |
uint32_t PLCObject::MatchMD5(const char *MD5, bool *match) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
215 |
{ |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
216 |
// an empty PLC is never considered to match |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
217 |
if(m_status.PLCstatus == Empty) |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
218 |
{ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
219 |
*match = false; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
220 |
return 0; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
221 |
} |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
222 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
223 |
// Load the last transferred PLC md5 hex digest |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
224 |
std::string md5sum; |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
225 |
try { |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
226 |
std::ifstream(std::string(LastTransferredPLC), std::ios::binary) >> md5sum; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
227 |
} catch (std::exception e) { |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
228 |
*match = false; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
229 |
return 0; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
230 |
} |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
231 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
232 |
// Compare the given MD5 with the last transferred PLC md5 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
233 |
*match = (md5sum == MD5); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
234 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
235 |
return 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
236 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
237 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
238 |
#if defined(_WIN32) || defined(_WIN64) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
239 |
// For Windows platform |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
240 |
#define SHARED_OBJECT_EXT ".dll" |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
241 |
#elif defined(__APPLE__) || defined(__MACH__) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
242 |
// For MacOS platform |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
243 |
#define SHARED_OBJECT_EXT ".dylib" |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
244 |
#else |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
245 |
// For Linux/Unix platform |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
246 |
#define SHARED_OBJECT_EXT ".so" |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
247 |
#endif |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
248 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
249 |
uint32_t PLCObject::BlobAsFile( |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
250 |
const binary_t *BlobID, std::filesystem::path filename) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
251 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
252 |
// Extract the blob from the map |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
253 |
auto nh = m_mapBlobIDToBlob.extract( |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
254 |
std::vector<uint8_t>(BlobID->data, BlobID->data + BlobID->dataLength)); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
255 |
if (nh.empty()) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
256 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
257 |
return ENOENT; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
258 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
259 |
Blob *blob = nh.mapped(); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
260 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
261 |
// Realize the blob into a file |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
262 |
uint32_t res = blob->asFile(filename); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
263 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
264 |
delete blob; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
265 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
266 |
if (res != 0) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
267 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
268 |
return res; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
269 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
270 |
return 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
271 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
272 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
273 |
uint32_t PLCObject::NewPLC( |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
274 |
const char *md5sum, const binary_t *plcObjectBlobID, |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
275 |
const list_extra_file_1_t *extrafiles, bool *success) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
276 |
{ |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
277 |
if(m_status.PLCstatus == Started) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
278 |
{ |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
279 |
*success = false; |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
280 |
return EBUSY; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
281 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
282 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
283 |
if(m_status.PLCstatus == Broken) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
284 |
{ |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
285 |
*success = false; |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
286 |
return EINVAL; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
287 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
288 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
289 |
// Unload the PLC object |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
290 |
UnLoadPLC(); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
291 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
292 |
// Purge the PLC object |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
293 |
PurgePLC(); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
294 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
295 |
// Concatenate md5sum and shared object extension to obtain filename |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
296 |
std::filesystem::path filename = |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
297 |
std::filesystem::path(md5sum) += SHARED_OBJECT_EXT; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
298 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
299 |
// Create the PLC object shared object file |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
300 |
BlobAsFile(plcObjectBlobID, filename); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
301 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
302 |
// create "lasttransferedPLC.md5" file and Save md5sum in it |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
303 |
std::ofstream(std::string(LastTransferredPLC), std::ios::binary) << md5sum; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
304 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
305 |
// create "extra_files.txt" file |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
306 |
std::ofstream extra_files_log(std::string(ExtraFilesList), std::ios::binary); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
307 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
308 |
// Create extra files |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
309 |
for (int i = 0; i < extrafiles->elementsCount; i++) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
310 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
311 |
extra_file *extrafile = extrafiles->elements + i; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
312 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
313 |
BlobAsFile(plcObjectBlobID, extrafile->fname); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
314 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
315 |
// Save the extra file name in "extra_files.txt" |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
316 |
extra_files_log << extrafile->fname << std::endl; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
317 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
318 |
|
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
319 |
// Load the PLC object |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
320 |
uint32_t res = LoadPLC(); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
321 |
if (res != 0) |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
322 |
{ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
323 |
*success = false; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
324 |
return res; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
325 |
} |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
326 |
|
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
327 |
m_status.PLCstatus = Stopped; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
328 |
*success = true; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
329 |
|
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
330 |
return 0; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
331 |
} |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
332 |
|
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
333 |
#define DLSYM(sym) \ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
334 |
do \ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
335 |
{ \ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
336 |
m_PLCSyms.sym = (decltype(m_PLCSyms.sym))dlsym(m_handle, #sym); \ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
337 |
if (m_PLCSyms.sym == NULL) \ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
338 |
{ \ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
339 |
/* TODO: use log instead */ \ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
340 |
std::cout << "Error dlsym " #sym ": " << dlerror() << std::endl; \ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
341 |
return errno; \ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
342 |
} \ |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
343 |
} while (0); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
344 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
345 |
uint32_t PLCObject::LoadPLC(void) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
346 |
{ |
3961
f01bd9a40554
C runtime: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3957
diff
changeset
|
347 |
|
f01bd9a40554
C runtime: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3957
diff
changeset
|
348 |
// TODO use PLCLibMutex |
f01bd9a40554
C runtime: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3957
diff
changeset
|
349 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
350 |
// Load the last transferred PLC md5 hex digest |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
351 |
std::string md5sum; |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
352 |
try { |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
353 |
std::ifstream(std::string(LastTransferredPLC), std::ios::binary) >> md5sum; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
354 |
} catch (std::exception e) { |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
355 |
return ENOENT; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
356 |
} |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
357 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
358 |
// Concatenate md5sum and shared object extension to obtain filename |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
359 |
std::filesystem::path filename(md5sum + SHARED_OBJECT_EXT); |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
360 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
361 |
// Load the shared object file |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
362 |
m_handle = dlopen(std::filesystem::absolute(filename).c_str(), RTLD_NOW); |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
363 |
if (m_handle == NULL) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
364 |
{ |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
365 |
std::cout << "Error: " << dlerror() << std::endl; |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
366 |
return errno; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
367 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
368 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
369 |
// Resolve shared object symbols |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
370 |
FOR_EACH_PLC_SYMBOLS_DO(DLSYM); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
371 |
|
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
372 |
// Set content of PLC_ID to md5sum |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
373 |
m_PLCSyms.PLC_ID = (uint8_t *)malloc(md5sum.size() + 1); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
374 |
if (m_PLCSyms.PLC_ID == NULL) |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
375 |
{ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
376 |
return ENOMEM; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
377 |
} |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
378 |
memcpy(m_PLCSyms.PLC_ID, md5sum.c_str(), md5sum.size()); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
379 |
m_PLCSyms.PLC_ID[md5sum.size()] = '\0'; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
380 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
381 |
return 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
382 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
383 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
384 |
#define ULSYM(sym) \ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
385 |
do \ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
386 |
{ \ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
387 |
m_PLCSyms.sym = NULL; \ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
388 |
} while (0); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
389 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
390 |
uint32_t PLCObject::UnLoadPLC(void) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
391 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
392 |
// Unload the shared object file |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
393 |
FOR_EACH_PLC_SYMBOLS_DO(ULSYM); |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
394 |
if(m_handle != NULL) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
395 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
396 |
dlclose(m_handle); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
397 |
m_handle = NULL; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
398 |
} |
3937
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
399 |
return 0; |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
400 |
} |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
401 |
|
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
402 |
uint32_t PLCObject::PurgeBlobs(void) |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
403 |
{ |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
404 |
// Purge all blobs |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
405 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
406 |
for (auto &blob : m_mapBlobIDToBlob) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
407 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
408 |
delete blob.second; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
409 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
410 |
m_mapBlobIDToBlob.clear(); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
411 |
|
3937
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
412 |
return 0; |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
413 |
} |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
414 |
|
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
415 |
uint32_t PLCObject::PurgePLC(void) |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
416 |
{ |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
417 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
418 |
// Open the extra files list |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
419 |
std::ifstream extra_files_log(std::string(ExtraFilesList), std::ios::binary); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
420 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
421 |
// Remove extra files |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
422 |
std::string extra_file; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
423 |
while (std::getline(extra_files_log, extra_file)) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
424 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
425 |
std::filesystem::remove(extra_file); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
426 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
427 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
428 |
// Load the last transferred PLC md5 hex digest |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
429 |
std::string md5sum; |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
430 |
try { |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
431 |
std::ifstream(std::string(LastTransferredPLC), std::ios::binary) >> md5sum; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
432 |
|
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
433 |
// Remove the PLC object shared object file |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
434 |
std::filesystem::remove(md5sum + SHARED_OBJECT_EXT); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
435 |
} catch (std::exception e) { |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
436 |
// ignored |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
437 |
} |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
438 |
|
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
439 |
try { |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
440 |
// Remove the last transferred PLC md5 hex digest |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
441 |
std::filesystem::remove(std::string(LastTransferredPLC)); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
442 |
|
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
443 |
// Remove the extra files list |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
444 |
std::filesystem::remove(std::string(ExtraFilesList)); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
445 |
} catch (std::exception e) { |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
446 |
// ignored |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
447 |
} |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
448 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
449 |
return 0; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
450 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
451 |
|
3937
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
452 |
uint32_t PLCObject::RepairPLC(void) |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
453 |
{ |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
454 |
// Repair the PLC object |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
455 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
456 |
if(m_status.PLCstatus == Broken) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
457 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
458 |
// Unload the PLC object |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
459 |
UnLoadPLC(); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
460 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
461 |
// Purge the PLC object |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
462 |
PurgePLC(); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
463 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
464 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
465 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
466 |
LogMessage(LOG_WARNING, "RepairPLC not implemented"); |
3937
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
467 |
return 0; |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
468 |
} |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
469 |
|
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
470 |
uint32_t PLCObject::ResetLogCount(void) |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
471 |
{ |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
472 |
m_PLCSyms.ResetLogCount(); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
473 |
return 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
474 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
475 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
476 |
uint32_t PLCObject::SeedBlob(const binary_t *seed, binary_t *blobID) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
477 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
478 |
// Create a blob with given seed |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
479 |
// Output new blob's md5 into blobID |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
480 |
// Return 0 if success |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
481 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
482 |
Blob *blob = NULL; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
483 |
try |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
484 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
485 |
blob = new Blob(seed->data, seed->dataLength); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
486 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
487 |
catch (int e) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
488 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
489 |
return e; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
490 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
491 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
492 |
MD5::digest_t digest = blob->digest(); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
493 |
|
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
494 |
std::vector<uint8_t> k((uint8_t*)digest.data, (uint8_t*)digest.data + MD5::digestsize); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
495 |
|
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
496 |
m_mapBlobIDToBlob[k] = blob; |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
497 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
498 |
blobID->data = (uint8_t *)malloc(MD5::digestsize); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
499 |
if (blobID->data == NULL) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
500 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
501 |
return ENOMEM; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
502 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
503 |
memcpy(blobID->data, digest.data, MD5::digestsize); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
504 |
blobID->dataLength = MD5::digestsize; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
505 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
506 |
return 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
507 |
} |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
508 |
void PLCObject::PurgeTraceBuffer(void) |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
509 |
{ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
510 |
// Free trace buffer |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
511 |
m_tracesMutex.lock(); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
512 |
for(trace_sample s : m_traces){ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
513 |
free(s.TraceBuffer.data); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
514 |
} |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
515 |
m_traces.clear(); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
516 |
m_tracesMutex.unlock(); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
517 |
} |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
518 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
519 |
uint32_t PLCObject::SetTraceVariablesList( |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
520 |
const list_trace_order_1_t *orders, int32_t *debugtoken) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
521 |
{ |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
522 |
if(m_status.PLCstatus == Empty) |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
523 |
{ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
524 |
return EINVAL; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
525 |
} |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
526 |
|
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
527 |
// increment debug token |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
528 |
m_debugToken++; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
529 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
530 |
if(orders->elementsCount == 0) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
531 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
532 |
// actually disables debug |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
533 |
m_PLCSyms.suspendDebug(1); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
534 |
*debugtoken = -5; // DEBUG_SUSPENDED |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
535 |
return 0; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
536 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
537 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
538 |
// suspend debug before any operation |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
539 |
int res = m_PLCSyms.suspendDebug(0); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
540 |
if(res == 0) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
541 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
542 |
// forget about all previous debug variables |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
543 |
m_PLCSyms.ResetDebugVariables(); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
544 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
545 |
// call RegisterTraceVariables for each trace order |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
546 |
for (int i = 0; i < orders->elementsCount; i++) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
547 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
548 |
trace_order *order = orders->elements + i; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
549 |
res = m_PLCSyms.RegisterDebugVariable(order->idx, order->force.data, order->force.dataLength); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
550 |
if(res != 0) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
551 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
552 |
// if any error, disable debug |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
553 |
// since debug is already suspended, resume it first |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
554 |
m_PLCSyms.resumeDebug(); |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
555 |
m_PLCSyms.suspendDebug(1); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
556 |
*debugtoken = -res; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
557 |
return EINVAL; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
558 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
559 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
560 |
|
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
561 |
// old traces are not valid anymore |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
562 |
PurgeTraceBuffer(); |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
563 |
|
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
564 |
// Start debug thread if not already started |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
565 |
if(!m_traceThread.joinable()) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
566 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
567 |
m_traceThread = std::thread(&PLCObject::TraceThreadProc, this); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
568 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
569 |
|
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
570 |
m_PLCSyms.resumeDebug(); |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
571 |
*debugtoken = m_debugToken; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
572 |
return 0; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
573 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
574 |
return res; |
3937
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
575 |
} |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
576 |
|
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
577 |
uint32_t PLCObject::StartPLC(void) |
e13543d716b6
C++ runtime: add eRPC server, minimal CLI and Makefile. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
578 |
{ |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
579 |
LogMessage(LOG_INFO, "Starting PLC"); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
580 |
uint32_t res = m_PLCSyms.startPLC(m_argc, m_argv); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
581 |
if(res != 0) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
582 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
583 |
m_status.PLCstatus = Broken; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
584 |
return res; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
585 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
586 |
m_status.PLCstatus = Started; |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
587 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
588 |
return 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
589 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
590 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
591 |
uint32_t PLCObject::StopPLC(bool *success) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
592 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
593 |
LogMessage(LOG_INFO, "Stopping PLC"); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
594 |
uint32_t res = m_PLCSyms.stopPLC(); |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
595 |
if(res == 0) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
596 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
597 |
m_status.PLCstatus = Stopped; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
598 |
} else { |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
599 |
m_status.PLCstatus = Broken; |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
600 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
601 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
602 |
// Stop debug thread |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
603 |
if(m_traceThread.joinable()) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
604 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
605 |
m_traceThread.join(); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
606 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
607 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
608 |
return res; |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
609 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
610 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
611 |
uint32_t PLCObject::LogMessage(uint8_t level, std::string message) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
612 |
{ |
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
613 |
// if PLC isn't loaded, log to stdout |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
614 |
if(m_PLCSyms.LogMessage == NULL) |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
615 |
{ |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
616 |
std::cout << level << message << std::endl; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
617 |
return ENOSYS; |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
618 |
} |
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
619 |
|
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
620 |
// Log std::string message with given level |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
621 |
return m_PLCSyms.LogMessage(level, (char *)message.c_str(), message.size()); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3937
diff
changeset
|
622 |
} |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
623 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
624 |
void PLCObject::TraceThreadProc(void) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
625 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
626 |
uint32_t err = 0; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
627 |
|
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
628 |
m_PLCSyms.resumeDebug(); |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
629 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
630 |
while(m_status.PLCstatus == Started) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
631 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
632 |
unsigned int tick; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
633 |
unsigned int size; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
634 |
void * buff; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
635 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
636 |
// Data allocated here is meant to be freed by eRPC server code |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
637 |
uint8_t* ourData = NULL; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
638 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
639 |
m_PLClibMutex.lock(); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
640 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
641 |
int res = m_PLCSyms.GetDebugData(&tick, &size, &buff); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
642 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
643 |
if(res == 0) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
644 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
645 |
ourData = (uint8_t *)malloc(size); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
646 |
if(ourData != NULL) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
647 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
648 |
memcpy(ourData, buff, size); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
649 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
650 |
m_PLCSyms.FreeDebugData(); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
651 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
652 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
653 |
m_PLClibMutex.unlock(); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
654 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
655 |
if(ourData == NULL) |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
656 |
{ |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
657 |
err = res == 0 ? ENOMEM : res; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
658 |
break; |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
659 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
660 |
} else { |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
661 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
662 |
m_tracesMutex.lock(); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
663 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
664 |
m_traces.push_back(trace_sample{tick, binary_t{ourData, size}}); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
665 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
666 |
m_tracesMutex.unlock(); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
667 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
668 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
669 |
|
3949
f64dce4e2f62
C runtime: initial fixes. Now runs and traces first_steps example.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3945
diff
changeset
|
670 |
PurgeTraceBuffer(); |
3945
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
671 |
|
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
672 |
LogMessage(err ? LOG_CRITICAL : LOG_INFO, |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
673 |
err == ENOMEM ? "Out of memory in TraceThreadProc" : |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
674 |
err ? "TraceThreadProc ended because of error" : |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
675 |
"TraceThreadProc ended normally"); |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
676 |
} |
d303aab8f68b
C++ runtime: WIP. Continue PLCObject implementation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3940
diff
changeset
|
677 |
|
4032
1ffff67678ad
Add ExtendedCall to PLCObject as a replacement of RemoteExec and reflect it in eRPC interface.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3961
diff
changeset
|
678 |
uint32_t PLCObject::ExtendedCall(const char * method, const binary_t * argument, binary_t * answer) |
1ffff67678ad
Add ExtendedCall to PLCObject as a replacement of RemoteExec and reflect it in eRPC interface.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3961
diff
changeset
|
679 |
{ |
1ffff67678ad
Add ExtendedCall to PLCObject as a replacement of RemoteExec and reflect it in eRPC interface.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3961
diff
changeset
|
680 |
// TODO |
1ffff67678ad
Add ExtendedCall to PLCObject as a replacement of RemoteExec and reflect it in eRPC interface.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3961
diff
changeset
|
681 |
|
4045
6975b486b07f
C runtime: fix ExtendedCall stub
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
4032
diff
changeset
|
682 |
answer->data = (uint8_t *)malloc(0); |
4032
1ffff67678ad
Add ExtendedCall to PLCObject as a replacement of RemoteExec and reflect it in eRPC interface.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3961
diff
changeset
|
683 |
answer->dataLength = 0; |
1ffff67678ad
Add ExtendedCall to PLCObject as a replacement of RemoteExec and reflect it in eRPC interface.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3961
diff
changeset
|
684 |
|
1ffff67678ad
Add ExtendedCall to PLCObject as a replacement of RemoteExec and reflect it in eRPC interface.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3961
diff
changeset
|
685 |
return 0; |
1ffff67678ad
Add ExtendedCall to PLCObject as a replacement of RemoteExec and reflect it in eRPC interface.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3961
diff
changeset
|
686 |
} |
1ffff67678ad
Add ExtendedCall to PLCObject as a replacement of RemoteExec and reflect it in eRPC interface.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3961
diff
changeset
|
687 |