summaryrefslogtreecommitdiff
path: root/i/simulotron/src/comc/struct_message.hh
diff options
context:
space:
mode:
Diffstat (limited to 'i/simulotron/src/comc/struct_message.hh')
-rw-r--r--i/simulotron/src/comc/struct_message.hh49
1 files changed, 48 insertions, 1 deletions
diff --git a/i/simulotron/src/comc/struct_message.hh b/i/simulotron/src/comc/struct_message.hh
index 598ac40..316393e 100644
--- a/i/simulotron/src/comc/struct_message.hh
+++ b/i/simulotron/src/comc/struct_message.hh
@@ -26,6 +26,7 @@
* }}} */
#include "gs/gs_message.hh"
+#include "utils/simulotron_exception.hh"
#include <string>
#include <stdexcept>
@@ -38,6 +39,7 @@ struct msgX
virtual void gsToMsg(GSMessage & gsm) = 0;
};
+/// Message 0: message de test, aucune utilité
struct msg0 : public msgX
{
int i;
@@ -66,7 +68,7 @@ struct msg0 : public msgX
int tmp;
gsm.readGS(&tmp, sizeof(int));
if(tmp != msgId)
- throw std::runtime_error("la gs ne correspond pas ŕ la structure");
+ throw simulotron_exception("msg0", "la gs ne correspond pas ŕ la structure");
gsm.readGS(&i, sizeof(int));
gsm.readGS(&d, sizeof(double));
gsm.getString(strh, 8);
@@ -76,4 +78,49 @@ struct msg0 : public msgX
}
};
+/// Message 1: initialisation de la com module/hub, premier message
+struct msg1 : public msgX
+{
+ std::string moduleName; //8 char
+
+ virtual void msgToGs(GSMessage & gsm) const
+ {
+ int msgId = 1;
+ gsm.clear();
+ gsm.appendGS(&msgId, sizeof(int));
+ gsm.appendGS(moduleName.data(), 8);
+ }
+
+ virtual void gsToMsg(GSMessage & gsm)
+ {
+ int msgId = 1;
+ int tmp;
+ gsm.readGS(&tmp, sizeof(int));
+ if(tmp != msgId)
+ throw simulotron_exception("msg1", "la gs ne correspond pas ŕ la structure");
+ gsm.getString(moduleName, 8);
+ }
+};
+
+/// Message ?: template pour les messages vide
+template <int MSGID>
+struct msg : public msgX
+{
+ virtual void msgToGs(GSMessage & gsm) const
+ {
+ int msgId = MSGID;
+ gsm.clear();
+ gsm.appendGS(&msgId, sizeof(int));
+ }
+ virtual void gsToMsg(GSMessage & gsm)
+ {
+ int msgId = MSGID;
+ int tmp;
+ gsm.readGS(&tmp, sizeof(int));
+ if(tmp != msgId)
+ throw simulotron_exception("msg" + MSGID, "la gs ne correspond pas ŕ la structure");
+ }
+};
+
+
#endif //STRUCT_MESSAGE_HH