| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/***************************************************************************** |
| 2 |
|
|
* |
| 3 |
|
|
* $Id$ |
| 4 |
|
|
* |
| 5 |
|
|
* Copyright 2010 Richard Hacker (lerichi at gmx dot net) |
| 6 |
|
|
* |
| 7 |
|
|
* This file is part of the pdserv library. |
| 8 |
|
|
* |
| 9 |
|
|
* The pdserv library is free software: you can redistribute it and/or modify |
| 10 |
|
|
* it under the terms of the GNU Lesser General Public License as published |
| 11 |
|
|
* by the Free Software Foundation, either version 3 of the License, or (at |
| 12 |
|
|
* your option) any later version. |
| 13 |
|
|
* |
| 14 |
|
|
* The pdserv library is distributed in the hope that it will be useful, but |
| 15 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 16 |
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 17 |
|
|
* License for more details. |
| 18 |
|
|
* |
| 19 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
| 20 |
|
|
* along with the pdserv library. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
|
|
* |
| 22 |
|
|
*****************************************************************************/ |
| 23 |
|
|
|
| 24 |
|
|
#include "pdserv.h" |
| 25 |
|
|
#include <stdint.h> |
| 26 |
|
|
#include <cstring> |
| 27 |
|
|
#include <stdio.h> |
| 28 |
|
|
#include <unistd.h> |
| 29 |
|
|
#include <assert.h> |
| 30 |
|
|
#include <cerrno> |
| 31 |
|
|
#include <sys/mman.h> |
| 32 |
|
|
|
| 33 |
|
|
#include <iostream> |
| 34 |
|
|
using std::cout; |
| 35 |
|
|
using std::cerr; |
| 36 |
|
|
using std::endl; |
| 37 |
|
|
|
| 38 |
|
|
uint16_t var1[2][3][4] = { |
| 39 |
|
|
{ {1,2,3,4}, {5,6,7}, }, |
| 40 |
|
|
}; |
| 41 |
|
|
|
| 42 |
|
|
struct s1 { |
| 43 |
|
|
double d[5]; |
| 44 |
|
|
char c; |
| 45 |
|
|
}; |
| 46 |
|
|
|
| 47 |
|
|
struct s2 { |
| 48 |
|
|
struct s1 s1[2]; |
| 49 |
|
|
int16_t i16; |
| 50 |
|
|
}; |
| 51 |
|
|
|
| 52 |
|
✗ |
int copy_param(struct pdtask *, const struct pdvariable *, |
| 53 |
|
|
void* dst, const void* src, size_t len, void *priv_data) |
| 54 |
|
|
{ |
| 55 |
|
✗ |
memcpy(dst, src, len); |
| 56 |
|
✗ |
printf("hallo %p\n", priv_data); |
| 57 |
|
✗ |
return 0; |
| 58 |
|
|
} |
| 59 |
|
|
|
| 60 |
|
✗ |
int gettime(struct timespec *t) |
| 61 |
|
|
{ |
| 62 |
|
✗ |
return clock_gettime(CLOCK_REALTIME, t); |
| 63 |
|
|
} |
| 64 |
|
|
|
| 65 |
|
✗ |
void clear_event(const struct pdevent* /*event*/, size_t /*index*/, |
| 66 |
|
|
char /*state*/, void * /*priv_data*/) |
| 67 |
|
|
{ |
| 68 |
|
✗ |
printf("%s", __func__); |
| 69 |
|
|
} |
| 70 |
|
|
|
| 71 |
|
✗ |
int main(int argc, const char *argv[]) |
| 72 |
|
|
{ |
| 73 |
|
|
struct pdserv *pdserv = |
| 74 |
|
✗ |
pdserv_create(program_invocation_short_name, "1.0", gettime); |
| 75 |
|
✗ |
size_t var1_dims[] = {2,3,4}; |
| 76 |
|
✗ |
struct timespec time; |
| 77 |
|
✗ |
double dbl[3] = { 13,14,15}; |
| 78 |
|
✗ |
double dbltime; |
| 79 |
|
✗ |
double tick = 10; |
| 80 |
|
✗ |
uint32_t param[] = {1,2,3,4}; |
| 81 |
|
|
struct pdtask *task[3]; |
| 82 |
|
|
const struct pdevent *event; |
| 83 |
|
|
|
| 84 |
|
✗ |
struct s1 s1 = {{1,2,3,4,5}, 'a'}; |
| 85 |
|
✗ |
struct s2 s2[2] = { |
| 86 |
|
|
{ |
| 87 |
|
|
{ |
| 88 |
|
|
{{6,7,8,9,10},'b'}, |
| 89 |
|
|
{{11,12,13,14,15},'c'} |
| 90 |
|
|
}, |
| 91 |
|
|
-123 |
| 92 |
|
|
}, |
| 93 |
|
|
{ |
| 94 |
|
|
{ |
| 95 |
|
|
{{6,7,8,9,10},'b'}, |
| 96 |
|
|
{{11,12,13,14,15},'c'} |
| 97 |
|
|
}, |
| 98 |
|
|
-124 |
| 99 |
|
|
}, |
| 100 |
|
|
}; |
| 101 |
|
|
|
| 102 |
|
✗ |
int s1_t = pdserv_create_compound("s1", sizeof(s1)); |
| 103 |
|
✗ |
int s2_t = pdserv_create_compound("s2", sizeof(struct s2)); |
| 104 |
|
✗ |
const char *room_mapping[] = { |
| 105 |
|
|
"control", |
| 106 |
|
|
"pump", |
| 107 |
|
|
"sdlfj", |
| 108 |
|
|
"server", |
| 109 |
|
|
0 |
| 110 |
|
|
}; |
| 111 |
|
|
|
| 112 |
|
✗ |
pdserv_compound_add_field(s1_t, "d", |
| 113 |
|
|
pd_double_T, offsetof(struct s1, d), 5, NULL); |
| 114 |
|
✗ |
pdserv_compound_add_field(s1_t, "c", |
| 115 |
|
|
pd_sint8_T, offsetof(struct s1, c), 1, NULL); |
| 116 |
|
|
|
| 117 |
|
✗ |
pdserv_compound_add_field(s2_t, "s1", s1_t, |
| 118 |
|
|
offsetof(struct s2, s1), 2, NULL); |
| 119 |
|
✗ |
pdserv_compound_add_field(s2_t, "i16", pd_sint16_T, |
| 120 |
|
|
offsetof(struct s2, i16), 1, NULL); |
| 121 |
|
|
|
| 122 |
|
✗ |
if (argc > 1) |
| 123 |
|
✗ |
pdserv_config_file(pdserv, argv[1]); |
| 124 |
|
|
|
| 125 |
|
✗ |
task[0] = pdserv_create_task(pdserv, 0.1, "Task1"); |
| 126 |
|
|
|
| 127 |
|
✗ |
assert(pdserv_signal(task[0], 1, "/s1", s1_t, &s1, 1, NULL)); |
| 128 |
|
✗ |
assert(pdserv_signal(task[0], 1, "/s2", s2_t, s2, 2, NULL)); |
| 129 |
|
|
|
| 130 |
|
✗ |
event = pdserv_event(pdserv,"/Event/path",WARN_EVENT,5, room_mapping); |
| 131 |
|
|
|
| 132 |
|
✗ |
assert(pdserv_signal(task[0], 1, "/path<lksjdf/to>ljk/double", |
| 133 |
|
|
pd_double_T, dbl, 3, NULL)); |
| 134 |
|
|
|
| 135 |
|
✗ |
assert(pdserv_signal(task[0], 1, "/Tme", |
| 136 |
|
|
pd_double_T, &dbltime, 1, NULL)); |
| 137 |
|
|
|
| 138 |
|
✗ |
assert(pdserv_signal(task[0], 1, "/path //to/ var2", |
| 139 |
|
|
pd_uint16_T, var1, 3, var1_dims)); |
| 140 |
|
|
|
| 141 |
|
|
struct pdvariable *p3 = pdserv_parameter(pdserv, "/path //to/ mdimparam", |
| 142 |
|
✗ |
0666, pd_uint16_T, var1, 3, var1_dims, copy_param, (void*) 10); |
| 143 |
|
✗ |
assert(p3); |
| 144 |
|
|
|
| 145 |
|
|
struct pdvariable *p1 = pdserv_parameter(pdserv, |
| 146 |
|
✗ |
"/Taskinfo/Abtastfrequenz", 0666, pd_double_T, &tick, 1, 0, 0, 0); |
| 147 |
|
✗ |
assert(p1); |
| 148 |
|
|
|
| 149 |
|
|
struct pdvariable *p = pdserv_parameter(pdserv, "/path/to<hide>/param", 0666, |
| 150 |
|
✗ |
pd_uint32_T, param, 4, 0, copy_param, (void*)10); |
| 151 |
|
✗ |
assert(p); |
| 152 |
|
|
|
| 153 |
|
✗ |
assert(!pdserv_prepare(pdserv)); |
| 154 |
|
|
|
| 155 |
|
|
// Need to be root |
| 156 |
|
|
//assert(!mlockall(MCL_CURRENT|MCL_FUTURE)); |
| 157 |
|
|
|
| 158 |
|
|
int i; |
| 159 |
|
|
while (1) { |
| 160 |
|
|
//sleep(1); |
| 161 |
|
✗ |
usleep(100000); |
| 162 |
|
✗ |
clock_gettime(CLOCK_REALTIME, &time); |
| 163 |
|
|
|
| 164 |
|
✗ |
pdserv_get_parameters(pdserv, task[0], &time); |
| 165 |
|
✗ |
var1[1][0][0] = i++; |
| 166 |
|
✗ |
if (!(i%30)) |
| 167 |
|
✗ |
var1[1][0][0]++; |
| 168 |
|
✗ |
dbl[0] += param[0]; |
| 169 |
|
✗ |
dbl[2] += param[2]; |
| 170 |
|
✗ |
var1[1][0][1] += param[1]; |
| 171 |
|
✗ |
dbltime = time.tv_sec + time.tv_nsec * 1.0e-9; |
| 172 |
|
✗ |
pdserv_update_statistics(task[0], 10, 20, 30); |
| 173 |
|
✗ |
pdserv_update(task[0], &time); |
| 174 |
|
|
|
| 175 |
|
✗ |
if (!(i%30)) { |
| 176 |
|
✗ |
pdserv_event_set(event, 2, 1, &time); |
| 177 |
|
|
// printf("sett event\n"); |
| 178 |
|
|
} |
| 179 |
|
|
} |
| 180 |
|
|
|
| 181 |
|
|
pdserv_exit(pdserv); |
| 182 |
|
|
|
| 183 |
|
|
return 0; |
| 184 |
|
|
} |
| 185 |
|
|
|