master/mailbox.c
branchstable-1.1
changeset 1731 60b2aad9d40b
parent 1715 e675450f2174
child 424 b792665b2dba
child 1732 1cc865ba17c2
--- a/master/mailbox.c	Thu Sep 28 08:31:33 2006 +0000
+++ b/master/mailbox.c	Fri Oct 13 10:07:10 2006 +0000
@@ -135,32 +135,63 @@
 /*****************************************************************************/
 
 /**
+   Mailbox error codes.
+*/
+
+const ec_code_msg_t mbox_error_messages[] = {
+    {0x00000001, "MBXERR_SYNTAX"},
+    {0x00000002, "MBXERR_UNSUPPORTEDPROTOCOL"},
+    {0x00000003, "MBXERR_INVAILDCHANNEL"},
+    {0x00000004, "MBXERR_SERVICENOTSUPPORTED"},
+    {0x00000005, "MBXERR_INVALIDHEADER"},
+    {0x00000006, "MBXERR_SIZETOOSHORT"},
+    {0x00000007, "MBXERR_NOMOREMEMORY"},
+    {0x00000008, "MBXERR_INVALIDSIZE"},
+    {}
+};
+
+/*****************************************************************************/
+
+/**
    Processes received mailbox data.
    \return pointer to the received data
 */
 
 uint8_t *ec_slave_mbox_fetch(const ec_slave_t *slave, /**< slave */
                              ec_datagram_t *datagram, /**< datagram */
-                             uint8_t type, /**< expected mailbox protocol */
+                             uint8_t *type, /**< expected mailbox protocol */
                              size_t *size /**< size of the received data */
                              )
 {
     size_t data_size;
 
-    if ((EC_READ_U8(datagram->data + 5) & 0x0F) != type) {
-        EC_ERR("Unexpected mailbox protocol 0x%02X (exp.: 0x%02X) at"
-               " slave %i!\n", EC_READ_U8(datagram->data + 5), type,
-               slave->ring_position);
+    if ((data_size = EC_READ_U16(datagram->data)) >
+        slave->sii_tx_mailbox_size - 6) {
+        EC_ERR("Corrupt mailbox response detected!\n");
         return NULL;
     }
 
-    if ((data_size = EC_READ_U16(datagram->data)) >
-        slave->sii_tx_mailbox_size - 6) {
-        EC_ERR("Currupt mailbox response detected!\n");
+    *type = EC_READ_U8(datagram->data + 5) & 0x0F;
+    *size = data_size;
+
+    if (*type == 0x00) {
+        const ec_code_msg_t *mbox_msg;
+	uint16_t code = EC_READ_U16(datagram->data + 8);
+
+        EC_ERR("Mailbox error response received.\n");
+	for (mbox_msg = mbox_error_messages; mbox_msg->code; mbox_msg++) {
+            if (mbox_msg->code != code) continue;
+            EC_ERR("Error reply code: 0x%04X: \"%s\".\n",
+                   mbox_msg->code, mbox_msg->message);
+            break;
+        }
+
+        if (!mbox_msg->code)
+            EC_ERR("Unknown error reply code 0x%04X.\n", code);
+
         return NULL;
     }
 
-    *size = data_size;
     return datagram->data + 6;
 }