Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional priority attribute for messages #67

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@
/build
/var
/.idea/

# Eclipse IDE settings files
.cproject
.project
.pydevproject
.settings/*

4 changes: 4 additions & 0 deletions lib/v1.0/C/pprz_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ static void accumulate_checksum(struct pprz_transport *trans, const uint8_t byte
trans->ck_b_tx += trans->ck_a_tx;
}

static void put_priority(struct pprz_transport *trans __attribute__((unused)), struct link_device *dev __attribute__((unused)),
long fd __attribute__((unused)), uint8_t prio __attribute__((unused))) {}

static void put_bytes(struct pprz_transport *trans, struct link_device *dev, long fd,
enum TransportDataType type __attribute__((unused)), enum TransportDataFormat format __attribute__((unused)),
const void *bytes, uint16_t len)
Expand Down Expand Up @@ -127,6 +130,7 @@ void pprz_transport_init(struct pprz_transport *t)
t->trans_tx.overrun = (overrun_t) overrun;
t->trans_tx.count_bytes = (count_bytes_t) count_bytes;
t->trans_tx.impl = (void *)(t);
t->trans_tx.put_priority = (put_priority_t) put_priority;
}


Expand Down
4 changes: 4 additions & 0 deletions lib/v2.0/C/pprz_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ static void accumulate_checksum(struct pprz_transport *trans, const uint8_t byte
trans->ck_b_tx += trans->ck_a_tx;
}

static void put_priority(struct pprzlink_msg *msg __attribute__((unused)), long fd __attribute__((unused)),
uint8_t prio __attribute__((unused))) {}

static void put_bytes(struct pprzlink_msg *msg, long fd,
enum TransportDataType type __attribute__((unused)), enum TransportDataFormat format __attribute__((unused)),
const void *bytes, uint16_t len)
Expand Down Expand Up @@ -130,6 +133,7 @@ void pprz_transport_init(struct pprz_transport *t)
t->trans_tx.overrun = (overrun_t) overrun;
t->trans_tx.count_bytes = (count_bytes_t) count_bytes;
t->trans_tx.impl = (void *)(t);
t->trans_tx.put_priority = (put_priority_t) put_priority;
}


Expand Down
1 change: 1 addition & 0 deletions message_definitions/v1.0/messages.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
name CDATA #REQUIRED
id CDATA #REQUIRED
link CDATA #IMPLIED
priority CDATA #IMPLIED
>

<!ELEMENT description (#PCDATA)>
Expand Down
10 changes: 5 additions & 5 deletions message_definitions/v1.0/messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<field name="md5sum" type="uint8[]"/>
</message>

<message name="PONG" id="3">
<message name="PONG" id="3" priority="2">
<description>Answer to PING datalink message, to measure latencies</description>
</message>

Expand Down Expand Up @@ -2052,7 +2052,7 @@
<field name="ac_id" type="uint8"/>
</message>

<message name="PING" id="8"/>
<message name="PING" id="8" priority="2"/>

<message name="FORMATION_SLOT" id="9" link="broadcasted">
<field name="ac_id" type="uint8"/>
Expand Down Expand Up @@ -2307,13 +2307,13 @@
<field name="cycle_time" type="uint32" unit="ms"/>
</message>

<message name="RC_3CH" id="51" link="broadcasted">
<message name="RC_3CH" id="51" link="broadcasted" priority="2">
<field name="throttle_mode" type="uint8" unit="byte_mask"/>
<field name="roll" type="int8"/>
<field name="pitch" type="int8"/>
</message>

<message name="RC_4CH" id="52" link="broadcasted">
<message name="RC_4CH" id="52" link="broadcasted" priority="2">
<field name="ac_id" type="uint8"/>
<field name="mode" type="uint8"/>
<field name="throttle" type="uint8"/>
Expand All @@ -2322,7 +2322,7 @@
<field name="yaw" type="int8"/>
</message>

<message name="RC_5CH" id="53" link="broadcasted">
<message name="RC_5CH" id="53" link="broadcasted" priority="2">
<field name="ac_id" type="uint8"/>
<field name="throttle" type="uint8"/>
<field name="roll" type="int8"/>
Expand Down
2 changes: 2 additions & 0 deletions message_definitions/v1.0/pprz_schema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<xs:attribute name="link" type="xs:string"/> <!-- message -->
<xs:attribute name="format" type="xs:string"/> <!-- field -->
<xs:attribute name="unit" type="xs:string"/> <!-- field -->
<xs:attribute name="priority" type="xs:byte"/> <!-- field -->
<xs:attribute name="alt_unit" type="xs:string"/> <!-- field -->
<xs:attribute name="alt_unit_coef" type="xs:string"/> <!-- field (FIXME: should be decimal AND scientific notation, allow all strings as workaround for now -->
<xs:attribute name="values" type="xs:string"/> <!-- field -->
Expand Down Expand Up @@ -67,6 +68,7 @@
<xs:attribute ref="name" use="required"/>
<xs:attribute ref="id" use="required"/>
<xs:attribute ref="link"/>
<xs:attribute ref="priority"/>
</xs:complexType>
</xs:element>

Expand Down
2 changes: 2 additions & 0 deletions tools/generator/C/include_v1.0/pprzlink_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typedef void (*start_message_t)(void *, struct link_device *, long, uint8_t);
typedef void (*end_message_t)(void *, struct link_device *, long);
typedef void (*overrun_t)(void *, struct link_device *);
typedef void (*count_bytes_t)(void *, struct link_device *, uint8_t);
typedef void (*put_priority_t)(void *, struct link_device *, long, uint8_t);

/** Generic transmission transport header
*/
Expand All @@ -101,6 +102,7 @@ struct transport_tx {
overrun_t overrun; ///< overrun
count_bytes_t count_bytes; ///< count bytes to send
void *impl; ///< pointer to parent implementation
put_priority_t put_priority; ///< set a message priority
};

#ifdef __cplusplus
Expand Down
2 changes: 2 additions & 0 deletions tools/generator/C/include_v2.0/pprzlink_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ typedef void (*start_message_t)(struct pprzlink_msg *, long, uint8_t);
typedef void (*end_message_t)(struct pprzlink_msg *, long);
typedef void (*overrun_t)(struct pprzlink_msg *);
typedef void (*count_bytes_t)(struct pprzlink_msg *, uint8_t);
typedef void (*put_priority_t)(struct pprzlink_msg *, long, uint8_t);

/** Generic transmission transport header
*/
Expand All @@ -102,6 +103,7 @@ struct transport_tx {
overrun_t overrun; ///< overrun
count_bytes_t count_bytes; ///< count bytes to send
void *impl; ///< pointer to parent implementation
put_priority_t put_priority; ///< set a message priority
};

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions tools/generator/gen_messages_v1_0_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def generate_messages_h(directory, name, xml):
if (trans->check_available_space(trans->impl, dev, _FD_ADDR, trans->size_of(trans->impl, 0${{fields:${array_extra_length}+${length}}} +2 /* msg header overhead */))) {
trans->count_bytes(trans->impl, dev, trans->size_of(trans->impl, 0${{fields:${array_extra_length}+${length}}} +2 /* msg header overhead */));
trans->start_message(trans->impl, dev, _FD, 0${{fields:${array_extra_length}+${length}}} +2 /* msg header overhead */);
trans->put_priority(trans->impl, dev, _FD, ${msg_priority} /* msg priority */);
trans->put_bytes(trans->impl, dev, _FD, DL_TYPE_UINT8, DL_FORMAT_SCALAR, &ac_id, 1);
trans->put_named_byte(trans->impl, dev, _FD, DL_TYPE_UINT8, DL_FORMAT_SCALAR, DL_${msg_name}, "${msg_name}");
${{fields:${array_byte}trans->put_bytes(trans->impl, dev, _FD, DL_TYPE_${type_upper}, ${dl_format}, (void *) _${field_name}, ${length});
Expand Down
3 changes: 2 additions & 1 deletion tools/generator/gen_messages_v2_0_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def generate_one(directory, xml, m):
if (msg->trans->check_available_space(msg, _FD_ADDR, size)) {
msg->trans->count_bytes(msg, size);
msg->trans->start_message(msg, _FD, /* msg header overhead */4${{fields:${array_extra_length}+${length}}});
msg->trans->put_priority(msg, _FD, ${msg_priority} /* msg priority */);
msg->trans->put_bytes(msg, _FD, DL_TYPE_UINT8, DL_FORMAT_SCALAR, &(msg->sender_id), 1);
msg->trans->put_named_byte(msg, _FD, DL_TYPE_UINT8, DL_FORMAT_SCALAR, msg->receiver_id, NULL);
uint8_t comp_class = (msg->component_id & 0x0F) << 4 | (${class_id} & 0x0F);
Expand Down Expand Up @@ -195,7 +196,7 @@ def generate_one(directory, xml, m):

#endif // _VAR_MESSAGES_${class_name}_${msg_name}_H_

''', {'msg_name' : m.msg_name, 'description' : m.description ,'class_id' : xml.class_id, 'class_name' : xml.class_name, 'id' : m.id, 'fields' : m.fields, 'message' : xml.message})
''', {'msg_name' : m.msg_name, 'description' : m.description ,'class_id' : xml.class_id, 'class_name' : xml.class_name, 'id' : m.id, 'fields' : m.fields, 'message' : xml.message, 'msg_priority': m.msg_priority})


def generate(output, xml):
Expand Down
6 changes: 4 additions & 2 deletions tools/generator/pprz_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ def __init__(self, name, type, xml, description=''):


class PPRZMsg(object):
def __init__(self, name, id, linenumber, description=''):
def __init__(self, name, id, linenumber, description='', priority=1):
self.msg_name = name
self.linenumber = linenumber
self.msg_priority = priority
self.id = int(id)
self.description = description
self.fields = []
Expand Down Expand Up @@ -131,7 +132,8 @@ def start_element(name, attrs):
elif in_element == "protocol.msg_class.message":
check_attrs(attrs, ['name', 'id'], 'message')
if self.current_class == self.class_name:
self.message.append(PPRZMsg(attrs['name'], attrs['id'], p.CurrentLineNumber))
priority = attrs['priority'] if 'priority' in attrs else 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably easier to write priority = attrs.get('priority', 1)

self.message.append(PPRZMsg(attrs['name'], attrs['id'], p.CurrentLineNumber, priority=int(priority)))
elif in_element == "protocol.msg_class.message.field":
check_attrs(attrs, ['name', 'type'], 'field')
if self.current_class == self.class_name:
Expand Down
2 changes: 2 additions & 0 deletions tools/generator/pprz_schema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<xs:attribute name="link" type="xs:string"/> <!-- message -->
<xs:attribute name="format" type="xs:string"/> <!-- field -->
<xs:attribute name="unit" type="xs:string"/> <!-- field -->
<xs:attribute name="priority" type="xs:byte"/> <!-- message -->
<xs:attribute name="alt_unit" type="xs:string"/> <!-- field -->
<xs:attribute name="alt_unit_coef" type="xs:string"/> <!-- field (FIXME: should be decimal AND scientific notation, allow all strings as workaround for now -->
<xs:attribute name="values" type="xs:string"/> <!-- field -->
Expand Down Expand Up @@ -67,6 +68,7 @@
<xs:attribute ref="name" use="required"/>
<xs:attribute ref="id" use="required"/>
<xs:attribute ref="link"/>
<xs:attribute ref="priority"/>
</xs:complexType>
</xs:element>

Expand Down