Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'com_module_binary_protocol'

Conflicts:
	commodule.cpp
  • Loading branch information...
commit a7af5fee8de02aa7aad5901162cc4127c41fc10c 2 parents 46704eb + 429ed68
@Minoru Minoru authored
Showing with 48 additions and 19 deletions.
  1. +23 −12 commodule.cpp
  2. +22 −6 docs/BinaryNetworkProtocol.markdown
  3. +3 −1 messages.h
View
35 commodule.cpp
@@ -88,7 +88,7 @@ void ComModule::handleMessage()
* then put the message into the queue */
msg->num = seq_num;
msg->port = port;
- msg->type = (MessageType)msg_type;
+ msg->type = static_cast<MessageType>(msg_type);
// FIXME: is std::queue thread-safe? Should we use mutex here?
messageQueue->push(msg);
@@ -103,30 +103,41 @@ void ComModule::sendMessage(Message *msg)
QDataStream stream(&datagram, QIODevice::WriteOnly);
// version: 1
- stream << (quint8)1;
+ stream << static_cast<quint8>(1);
// other header infortmation
- stream << (quint32)msg->num << (quint16)msg->port << (quint8)msg->type;
+ stream << static_cast<quint32>(msg->num) << static_cast<quint16>(msg->port)
+ << static_cast<quint8>(msg->type);
switch(msg->type) {
case MsgAcknowledge:
// "acknowledge" doesn't have any payload
break;
+ case MsgStart:
+ break;
+ case MsgPause:
+ break;
+ case MsgStop:
+ break;
case MsgBump:
- stream << (quint32)((MessageBump *)msg)->coordX
- << (quint32)((MessageBump *)msg)->coordY;
+ {
+ MessageBump *m = static_cast<MessageBump *>(msg);
+ stream << static_cast<quint32>(m->coordX) << static_cast<quint32>(m->coordY);
+ };
break;
case MsgThereYouSee:
- MessageThereYouSee *m = (MessageThereYouSee *)msg;
- quint32 count = (quint32)m->objects.size();
+ {
+ MessageThereYouSee *m = static_cast<MessageThereYouSee *>(msg);
+ quint32 count = static_cast<quint32>(m->objects.size());
stream << count;
/* For each object, put its description into the stream */
for(quint32 i = 0; i < count; i++) {
- MessageObject o = m->objects.front();
- m->objects.pop_front();
- stream << (quint32)o.coordX << (quint32)o.coordY
- << (quint32)o.diameter << (quint32)(o.degrees / 3600)
- << (quint8)o.red << (quint8)o.green << (quint8)o.blue;
+ MessageObject o = m->objects.takeFirst();
+ stream << static_cast<quint32>(o.coordX) << static_cast<quint32>(o.coordY)
+ << static_cast<quint32>(o.diameter) << static_cast<quint32>(o.degrees / 3600)
+ << static_cast<quint8>(o.red) << static_cast<quint8>(o.green)
+ << static_cast<quint8>(o.blue);
}
+ };
break;
}
View
28 docs/BinaryNetworkProtocol.markdown
@@ -23,7 +23,7 @@ be either some dull message (see "`acknowledge` message") or answer to
the question that agent asked (see "`there you see` message" and "`bump`
message").
-There are 9 types of messages:
+There are 12 types of messages:
* `move`
* `turn`
@@ -34,9 +34,12 @@ There are 9 types of messages:
* `acknowledge`
* `bump`
* `there you see`
+* `start`
+* `pause`
+* `stop`
-Out of those, only first 6 can be sent by agent, and the last three
-can be sent only by the simulator.
+Out of those, only first 6 can be sent by agent, and the last six can
+be sent only by the simulator.
Following are formal specification of how does header and each message
type look like.
@@ -68,6 +71,9 @@ Message types are mapped from names to numbers as follows:
* 6: `bump`
* 7: `there you see`
* 8: `parameter report`
+* 9: `start`
+* 10: `pause`
+* 11: `stop`
## `move` message
@@ -86,9 +92,9 @@ Message contains:
* seconds, *4 octets*, signed integer
-seconds are 1/60 of minute, and minute is in turn 1/60 of degree. That
-field specify number of seconds agent should turn clockwise. To turn
-counterclockwise, one should specify negative number of seconds.
+second is 1/60 of minute, and minute is, in turn, 1/60 of degree. That
+field specify new orientation of the agent. It is an absolute value
+counted from the north direction, which is at the top of the map.
## `change size` message
@@ -178,6 +184,16 @@ Seconds field indidates orientation of object.
List of objects is just a stream of objects descriptions.
+## `start`, `pause` and `stop` messages
+
+Those are used to control simulation flow. Agent program should start
+doing its work (i.e. moving agent around) upon receiving `start`
+message. If `pause` is sent, agent should pause and wait for the
+`start`. The only difference between `pause` and `stop` is that
+pausing doesn't erase current agent's state, while `stop` does.
+
+Those messages doesn't contain anything other than header.
+
## Example messages
### `move` message
View
4 messages.h
@@ -17,7 +17,9 @@ enum MessageType {
MsgBump,
MsgThereYouSee,
MsgParameterReport,
- MsgUndefined
+ MsgStart,
+ MsgPause,
+ MsgStop
};
class Message
Please sign in to comment.
Something went wrong with that request. Please try again.