Skip to content

Commit 8896b15

Browse files
Added Support for RAD-Star2 Settings.
Signed-off-by: David Rebbe <drebbe@intrepidcs.com>
1 parent e911755 commit 8896b15

8 files changed

Lines changed: 416 additions & 6 deletions

include/object_device_settings.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "object_cyan_settings.h"
1919
#include "object_vcan3_settings.h"
2020
#include "object_rad_galaxy_settings.h"
21-
//#include "object_rad_star2_settings.h"
21+
#include "object_rad_star2_settings.h"
2222
#include "object_vcan4_settings.h"
2323
#include "object_vcan412_settings.h"
2424
//#include "object_neoecu_avb_settings.h"
@@ -79,7 +79,7 @@ static PyMemberDef device_settings_object_members[] = {
7979
{ "cyan", T_OBJECT_EX, offsetof(device_settings_object, cyan), 0, MODULE_NAME "." CYAN_SETTINGS_OBJECT_NAME" Object" },
8080
{ "vcan3", T_OBJECT_EX, offsetof(device_settings_object, vcan3), 0, MODULE_NAME "." VCAN3_SETTINGS_OBJECT_NAME" Object" },
8181
{ "radgalaxy", T_OBJECT_EX, offsetof(device_settings_object, radgalaxy), 0, MODULE_NAME "." RADGALAXY_SETTINGS_OBJECT_NAME" Object" },
82-
//{ "radstar2", T_OBJECT_EX, offsetof(device_settings_object, radstar2), 0, MODULE_NAME "." RADSTAR2_SETTINGS_OBJECT_NAME" Object" },
82+
{ "radstar2", T_OBJECT_EX, offsetof(device_settings_object, radstar2), 0, MODULE_NAME "." RADSTAR2_SETTINGS_OBJECT_NAME" Object" },
8383
{ "vcan4", T_OBJECT_EX, offsetof(device_settings_object, vcan4), 0, MODULE_NAME "." VCAN4_SETTINGS_OBJECT_NAME" Object" },
8484
{ "vcan4_12", T_OBJECT_EX, offsetof(device_settings_object, vcan4_12), 0, MODULE_NAME "." VCAN412_SETTINGS_OBJECT_NAME" Object" },
8585
{ "vividcan", T_OBJECT_EX, offsetof(device_settings_object, vividcan), 0, MODULE_NAME "." VIVIDCAN_SETTINGS_OBJECT_NAME" Object" },
@@ -97,7 +97,7 @@ static int device_settings_object_init(device_settings_object* self, PyObject* a
9797
self->cyan = PyObject_CallObject((PyObject*)&cyan_settings_object_type, NULL);
9898
self->vcan3 = PyObject_CallObject((PyObject*)&vcan3_settings_object_type, NULL);
9999
self->radgalaxy = PyObject_CallObject((PyObject*)&rad_galaxy_settings_object_type, NULL);
100-
//self->radstar2 = PyObject_CallObject((PyObject*)&rad_star2_settings_object_type, NULL);
100+
self->radstar2 = PyObject_CallObject((PyObject*)&rad_star2_settings_object_type, NULL);
101101
self->vcan4 = PyObject_CallObject((PyObject*)&vcan4_settings_object_type, NULL);
102102
self->vcan4_12 = PyObject_CallObject((PyObject*)&vcan412_settings_object_type, NULL);
103103
self->vividcan = PyObject_CallObject((PyObject*)&vividcan_settings_object_type, NULL);
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#ifndef _OBJECT_RADSTAR2_SETTINGS_H_
2+
#define _OBJECT_RADSTAR2_SETTINGS_H_
3+
4+
#include <Python.h>
5+
#include <structmember.h>
6+
#if (defined(_WIN32) || defined(__WIN32__))
7+
#ifndef USING_STUDIO_8
8+
#define USING_STUDIO_8 1
9+
#endif
10+
#include <icsnVC40.h>
11+
#else
12+
#include <icsnVC40.h>
13+
#endif
14+
15+
#include "defines.h"
16+
#include "object_can_settings.h"
17+
#include "object_lin_settings.h"
18+
#include "object_swcan_settings.h"
19+
#include "object_textapi_settings.h"
20+
#include "object_uart_settings.h"
21+
#include "object_iso9141_keyword2000_settings.h"
22+
#include "object_canfd_settings.h"
23+
#include "object_op_eth_general_settings.h"
24+
#include "object_op_eth_settings.h"
25+
#include "object_timesync_settings.h"
26+
27+
#define RADSTAR2_SETTINGS_OBJECT_NAME "RadStar2Settings"
28+
29+
typedef struct {
30+
PyObject_HEAD
31+
PyObject* opEthGen;
32+
PyObject* opEth1;
33+
PyObject* opEth2;
34+
PyObject* can1;
35+
PyObject* can2;
36+
PyObject* canfd1;
37+
PyObject* canfd2;
38+
PyObject* lin1;
39+
PyObject* iso9141_kw1;
40+
41+
PyObject* textapi;
42+
PyObject* timesync;
43+
44+
SRADStar2Settings s;
45+
} rad_star2_settings_object;
46+
47+
static PyMemberDef rad_star2_settings_object_members[] = {
48+
{ "perf_en", T_USHORT, offsetof(rad_star2_settings_object, s.perf_en), 0, "" },
49+
50+
{ "opEthGen", T_OBJECT_EX, offsetof(rad_star2_settings_object, opEthGen), 0, MODULE_NAME "." OP_ETH_GENERAL_SETTINGS_OBJECT_NAME" Object" },
51+
{ "opEth1", T_OBJECT_EX, offsetof(rad_star2_settings_object, opEth1), 0, MODULE_NAME "." OP_ETH_SETTINGS_OBJECT_NAME" Object" },
52+
{ "opEth2", T_OBJECT_EX, offsetof(rad_star2_settings_object, opEth2), 0, MODULE_NAME "." OP_ETH_SETTINGS_OBJECT_NAME" Object" },
53+
54+
{ "can1", T_OBJECT_EX, offsetof(rad_star2_settings_object, can1), 0, MODULE_NAME "." CAN_SETTINGS_OBJECT_NAME" Object" },
55+
{ "can2", T_OBJECT_EX, offsetof(rad_star2_settings_object, can2), 0, MODULE_NAME "." CAN_SETTINGS_OBJECT_NAME" Object" },
56+
57+
{ "canfd1", T_OBJECT_EX, offsetof(rad_star2_settings_object, canfd1), 0, MODULE_NAME "." CANFD_SETTINGS_OBJECT_NAME" Object" },
58+
{ "canfd2", T_OBJECT_EX, offsetof(rad_star2_settings_object, canfd2), 0, MODULE_NAME "." CANFD_SETTINGS_OBJECT_NAME" Object" },
59+
60+
{ "lin1", T_OBJECT_EX, offsetof(rad_star2_settings_object, lin1), 0, MODULE_NAME "." LIN_SETTINGS_OBJECT_NAME" Object" },
61+
62+
{ "network_enables", T_USHORT, offsetof(rad_star2_settings_object, s.network_enables), 0, "" },
63+
{ "network_enables_2", T_USHORT, offsetof(rad_star2_settings_object, s.network_enables_2), 0, "" },
64+
65+
{ "misc_io_initial_ddr", T_USHORT, offsetof(rad_star2_settings_object, s.misc_io_initial_ddr), 0, "" },
66+
{ "misc_io_initial_latch", T_USHORT, offsetof(rad_star2_settings_object, s.misc_io_initial_latch), 0, "" },
67+
{ "misc_io_report_period", T_USHORT, offsetof(rad_star2_settings_object, s.misc_io_report_period), 0, "" },
68+
{ "misc_io_on_report_events", T_USHORT, offsetof(rad_star2_settings_object, s.misc_io_on_report_events), 0, "" },
69+
{ "misc_io_analog_enable", T_USHORT, offsetof(rad_star2_settings_object, s.misc_io_analog_enable), 0, "" },
70+
{ "ain_sample_period", T_USHORT, offsetof(rad_star2_settings_object, s.ain_sample_period), 0, "" },
71+
{ "ain_threshold", T_USHORT, offsetof(rad_star2_settings_object, s.ain_threshold), 0, "" },
72+
73+
{ "pwr_man_enable", T_USHORT, offsetof(rad_star2_settings_object, s.pwr_man_enable), 0, "" },
74+
{ "pwr_man_timeout", T_UINT, offsetof(rad_star2_settings_object, s.pwr_man_timeout), 0, "" },
75+
76+
{ "network_enabled_on_boot", T_USHORT, offsetof(rad_star2_settings_object, s.network_enabled_on_boot), 0, "" },
77+
78+
{ "iso15765_separation_time_offset", T_USHORT, offsetof(rad_star2_settings_object, s.iso15765_separation_time_offset), 0, "" },
79+
80+
{ "iso_9141_kwp_enable_reserved", T_USHORT, offsetof(rad_star2_settings_object, s.iso_9141_kwp_enable_reserved), 0, "" },
81+
{ "iso9141_kwp_settings_1", T_OBJECT_EX, offsetof(rad_star2_settings_object, iso9141_kw1), 0, ISO9141KEYWORD2000_SETTINGS_OBJECT_NAME" Object" },
82+
{ "iso_parity_1", T_USHORT, offsetof(rad_star2_settings_object, s.iso_parity_1), 0, "0 - no parity, 1 - event, 2 - odd" },
83+
84+
{ "iso_msg_termination_1", T_USHORT, offsetof(rad_star2_settings_object, s.iso_msg_termination_1), 0, "0 - use inner frame time, 1 - GME CIM-SCL" },
85+
86+
{ "idle_wakeup_network_enables_1", T_USHORT, offsetof(rad_star2_settings_object, s.idle_wakeup_network_enables_1), 0, "" },
87+
{ "idle_wakeup_network_enables_2", T_USHORT, offsetof(rad_star2_settings_object, s.idle_wakeup_network_enables_2), 0, "" },
88+
89+
{ "network_enables_3", T_USHORT, offsetof(rad_star2_settings_object, s.network_enables_3), 0, "" },
90+
{ "idle_wakeup_network_enables_3", T_USHORT, offsetof(rad_star2_settings_object, s.idle_wakeup_network_enables_3), 0, "" },
91+
92+
{ "can_switch_mode", T_USHORT, offsetof(rad_star2_settings_object, s.can_switch_mode), 0, "" },
93+
{ "text_api", T_OBJECT_EX, offsetof(rad_star2_settings_object, textapi), 0, MODULE_NAME "." TEXTAPI_SETTINGS_OBJECT_NAME" Object" },
94+
{ "pc_com_mode", T_USHORT, offsetof(rad_star2_settings_object, s.pc_com_mode), 0, "" },
95+
{ "timeSyncSettings", T_OBJECT_EX, offsetof(rad_star2_settings_object, timesync), 0, MODULE_NAME "." TIMESYNC_SETTINGS_OBJECT_NAME" Object" },
96+
{ "hwComLatencyTestEn", T_USHORT, offsetof(rad_star2_settings_object, s.hwComLatencyTestEn), 0, "" },
97+
98+
{ NULL, 0, 0, 0, 0 },
99+
};
100+
101+
static int rad_star2_settings_object_init(rad_star2_settings_object* self, PyObject* args, PyObject* kwds)
102+
{
103+
// Initialize all struct values to 0
104+
memset(&(self->s), 0, sizeof(self->s));
105+
// Initialize Ethernet Objects
106+
self->opEthGen = PyObject_CallObject((PyObject*)&op_eth_general_settings_object_type, NULL);
107+
self->opEth1 = PyObject_CallObject((PyObject*)&op_eth_settings_object_type, NULL);
108+
self->opEth2 = PyObject_CallObject((PyObject*)&op_eth_settings_object_type, NULL);
109+
// Initialize Can Objects
110+
self->can1 = PyObject_CallObject((PyObject*)&can_settings_object_type, NULL);
111+
self->can2 = PyObject_CallObject((PyObject*)&can_settings_object_type, NULL);
112+
self->canfd1 = PyObject_CallObject((PyObject*)&canfd_settings_object_type, NULL);
113+
self->canfd2 = PyObject_CallObject((PyObject*)&canfd_settings_object_type, NULL);
114+
// Initialize LIN Objects
115+
self->lin1 = PyObject_CallObject((PyObject*)&lin_settings_object_type, NULL);
116+
// Initialize ISO9141Keyword2000 Objects
117+
self->iso9141_kw1 = PyObject_CallObject((PyObject*)&iso9141keyword2000_settings_object_type, NULL);
118+
// Initialize TextAPI Objects
119+
self->textapi = PyObject_CallObject((PyObject*)&textapi_settings_object_type, NULL);
120+
// Initialize TIMESYNC Objects
121+
self->timesync = PyObject_CallObject((PyObject*)&timesync_settings_object_type, NULL);
122+
return 0;
123+
}
124+
125+
extern PyTypeObject rad_star2_settings_object_type;
126+
127+
// Copied from tupleobject.h
128+
#define PyRADStar2Settings_Check(op) \
129+
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BASETYPE)
130+
#define PyRADStar2Settings_CheckExact(op) (Py_TYPE(op) == &rad_star2_settings_object_type)
131+
132+
bool setup_rad_star2_settings_object(PyObject* module);
133+
134+
void rad_star2_settings_object_update_from_struct(PyObject* settings);
135+
void rad_star2_settings_object_update_from_objects(PyObject* settings);
136+
137+
#endif // _OBJECT_RADSTAR2_SETTINGS_H_

include/object_timesync_settings.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#ifndef _OBJECT_TIMESYNC_SETTINGS_H_
2+
#define _OBJECT_TIMESYNC_SETTINGS_H_
3+
4+
#include <Python.h>
5+
#include <structmember.h>
6+
7+
#if (defined(_WIN32) || defined(__WIN32__))
8+
#ifndef USING_STUDIO_8
9+
#define USING_STUDIO_8 1
10+
#endif
11+
#include <icsnVC40.h>
12+
#else
13+
#include <icsnVC40.h>
14+
#endif
15+
16+
#include "defines.h"
17+
18+
#define TIMESYNC_SETTINGS_OBJECT_NAME "TimesyncSettings"
19+
20+
#if PY_MAJOR_VERSION < 3
21+
#define PyUnicode_CompareWithASCIIString(uni, string) strcmp(PyString_AsString(uni), string)
22+
/*
23+
int PyUnicode_CompareWithASCIIString(PyObject *uni, const char *string)
24+
{
25+
int result = strcmp(PyString_AsString(uni), string);
26+
if (result == 0) {
27+
return 0;
28+
}
29+
return result > 0 ? 1 : -1;
30+
}
31+
*/
32+
#endif
33+
34+
typedef struct {
35+
PyObject_HEAD
36+
TIMESYNC_ICSHARDWARE_SETTINGS s;
37+
} timesync_settings_object;
38+
39+
static PyMemberDef timesync_settings_object_members[] = {
40+
{ "MasterEnable", T_UBYTE, offsetof(timesync_settings_object, s.MasterEnable), 0, ""},
41+
{ "SlaveEnable", T_UBYTE, offsetof(timesync_settings_object, s.SlaveEnable), 0, ""},
42+
{ "MasterNetwork", T_UBYTE, offsetof(timesync_settings_object, s.MasterNetwork), 0, ""},
43+
{ "SlaveNetwork", T_UBYTE, offsetof(timesync_settings_object, s.SlaveNetwork), 0, ""},
44+
{ NULL, 0, 0, 0, 0 },
45+
};
46+
47+
static int timesync_settings_object_init(timesync_settings_object* self, PyObject* args, PyObject* kwds)
48+
{
49+
// Initialize all struct values to 0
50+
memset(&(self->s), 0, sizeof(self->s));
51+
return 0;
52+
}
53+
54+
static PyObject* timesync_settings_object_getattr(PyObject *o, PyObject *attr_name)
55+
{
56+
#if PY_MAJOR_VERSION >= 3
57+
if (!PyUnicode_Check(attr_name)) {
58+
#else
59+
if (!PyString_Check(attr_name)) {
60+
#endif
61+
PyErr_Format(PyExc_TypeError,
62+
"attribute name must be string, not '%.200s'",
63+
attr_name->ob_type->tp_name);
64+
return NULL;
65+
}
66+
else {
67+
Py_INCREF(attr_name);
68+
}
69+
return PyObject_GenericGetAttr(o, attr_name);
70+
}
71+
72+
static int timesync_settings_object_setattr(PyObject *o, PyObject *name, PyObject *value)
73+
{
74+
timesync_settings_object* obj = (timesync_settings_object*)o;
75+
return PyObject_GenericSetAttr(o, name, value);
76+
}
77+
78+
extern PyTypeObject timesync_settings_object_type;
79+
80+
// Copied from tupleobject.h
81+
#define PyTimesyncSettings_Check(op) \
82+
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BASETYPE)
83+
#define PyTimesyncSettings_CheckExact(op) (Py_TYPE(op) == &timesync_settings_object_type)
84+
85+
bool setup_timesync_settings_object(PyObject* module);
86+
87+
#endif // _OBJECT_TIMESYNC_SETTINGS_H_

msvc/python_ics.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,11 @@
209209
<ClCompile Include="..\src\object_op_eth_general_settings.cpp" />
210210
<ClCompile Include="..\src\object_op_eth_settings.cpp" />
211211
<ClCompile Include="..\src\object_rad_galaxy_settings.cpp" />
212+
<ClCompile Include="..\src\object_rad_star2_settings.cpp" />
212213
<ClCompile Include="..\src\object_spy_message.cpp" />
213214
<ClCompile Include="..\src\object_swcan_settings.cpp" />
214215
<ClCompile Include="..\src\object_textapi_settings.cpp" />
216+
<ClCompile Include="..\src\object_timesync_settings.cpp" />
215217
<ClCompile Include="..\src\object_uart_settings.cpp" />
216218
<ClCompile Include="..\src\object_vcan3_settings.cpp" />
217219
<ClCompile Include="..\src\object_vcan412_settings.cpp" />

src/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include "object_ics_device_status.h"
3434
#include "object_device_settings.h"
3535
#include "object_vcan4_settings.h"
36+
#include "object_timesync_settings.h"
37+
#include "object_rad_star2_settings.h"
3638

3739
#define _DOC_ICS_MODULE \
3840
"Python C Code module for interfacing to the icsneo40 dynamic library. Code tries\n" \
@@ -144,6 +146,8 @@ void initics(void)
144146
setup_ics_device_status_object(module);
145147
setup_device_settings_object(module);
146148
setup_vcan4_settings_object(module); // 803+
149+
setup_timesync_settings_object(module);
150+
setup_rad_star2_settings_object(module);
147151

148152
#if PY_MAJOR_VERSION >= 3
149153
return module;

src/object_device_settings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ void device_settings_object_update_from_struct(PyObject* settings)
7676
// Update radgalaxy object
7777
((rad_galaxy_settings_object*)s_obj->radgalaxy)->s = s->Settings.radgalaxy;
7878
rad_galaxy_settings_object_update_from_struct(s_obj->radgalaxy);
79-
#if 0
79+
#if VSPY3_BUILD_VERSION >= 803
8080
// Update radstar2 object
81-
((radstar2_settings_object*)s_obj->radstar2)->s = s->Settings.radstar2;
82-
radstar2_settings_object_update_from_struct(s_obj->radstar2);
81+
((rad_star2_settings_object*)s_obj->radstar2)->s = s->Settings.radstar2;
82+
rad_star2_settings_object_update_from_struct(s_obj->radstar2);
8383
#endif
8484
// Update vcan4 object
8585
((vcan4_settings_object*)s_obj->vcan4)->s = s->Settings.vcan4;

0 commit comments

Comments
 (0)