Skip to content

Commit

Permalink
add container statistic and ll_container_stat
Browse files Browse the repository at this point in the history
  • Loading branch information
Salem-Tho committed Nov 26, 2020
1 parent 3e93b82 commit e8a121d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
10 changes: 10 additions & 0 deletions Robus/inc/robus_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ typedef struct __attribute__((__packed__))
uint8_t msg_drop_number;
} memory_stats_t;

typedef struct __attribute__((__packed__))
{
uint8_t msg_nbr;
uint8_t fail_msg_nbr;
uint8_t *max_collision_retry;
uint8_t *max_nak_retry;
} ll_stats_t;
/*
* This structure is used to get the message addressing mode list.
*/
Expand Down Expand Up @@ -90,6 +97,9 @@ typedef struct __attribute__((__packed__))
uint16_t max_multicast_target; /*!< Position pointer of the last multicast target. */
uint16_t multicast_target_bank[MAX_MULTICAST_ADDRESS]; /*!< multicast target bank. */
uint16_t dead_container_spotted; /*!< The ID of a container that don't reply to a lot of ACK msg */

//variable stat on robus com for ll_container
ll_stats_t ll_stat;
} ll_container_t;

/******************************************************************************
Expand Down
29 changes: 25 additions & 4 deletions Robus/src/robus.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void Robus_Init(memory_stats_t *memory_stats)
// Initialize the robus container status
ctx.rx.status.unmap = 0;
ctx.rx.status.identifier = 0xF;

// Init hal
LuosHAL_Init();
}
Expand Down Expand Up @@ -138,7 +139,6 @@ error_return_t Robus_SendMsg(ll_container_t *ll_container, msg_t *msg)
{
// Compute the full message size based on the header size info.
uint16_t data_size = 0;
error_return_t fail = SUCCEED;
if (msg->header.size > MAX_DATA_MSG_SIZE)
{
data_size = MAX_DATA_MSG_SIZE;
Expand All @@ -148,7 +148,6 @@ error_return_t Robus_SendMsg(ll_container_t *ll_container, msg_t *msg)
data_size = msg->header.size;
}
uint16_t full_size = sizeof(header_t) + data_size;
uint8_t nbr_nak_retry = 0;
// Set protocol revision and source ID on the message
msg->header.protocol = PROTOCOL_REVISION;
if (ll_container->id != 0)
Expand All @@ -161,8 +160,14 @@ error_return_t Robus_SendMsg(ll_container_t *ll_container, msg_t *msg)
}
// Add the CRC to the total size of the message
full_size += 2;

//try to send msg computed
error_return_t result = SUCCEED;
uint8_t nbr_nak_retry = 0;
uint8_t RetryCollision = 0;
ack_restart:
nbr_nak_retry++;
RetryCollision = 0;
LuosHAL_SetIrqState(false);
ctx.ack = FALSE;
LuosHAL_SetIrqState(true);
Expand All @@ -176,13 +181,24 @@ error_return_t Robus_SendMsg(ll_container_t *ll_container, msg_t *msg)
LuosHAL_SetIrqState(true);
// wait timeout of collided packet
Transmit_WaitUnlockTx();
//max collision possible
RetryCollision++;
if(RetryCollision > NBR_NAK_RETRY)
{
result = FAILED;
break;
}
// timer proportional to ID
if (ll_container->id > 1)
{
for (volatile uint16_t tempo = 0; tempo < (COLLISION_TIMER * (ll_container->id - 1)); tempo++)
;
}
}
if(*ll_container->ll_stat.max_collision_retry < RetryCollision)
{
*ll_container->ll_stat.max_collision_retry = RetryCollision;
}
// Check if ACK needed
if ((msg->header.target_mode == IDACK) || (msg->header.target_mode == NODEIDACK))
{
Expand Down Expand Up @@ -226,13 +242,18 @@ error_return_t Robus_SendMsg(ll_container_t *ll_container, msg_t *msg)
else
{
// Set the dead container ID into the ll_container
result = FAILED;
ll_container->dead_container_spotted = (uint16_t)(msg->header.target);
fail = FAILED;
}
}
ctx.ack = 0;
}
if(*ll_container->ll_stat.max_nak_retry < nbr_nak_retry)
{
*ll_container->ll_stat.max_nak_retry = nbr_nak_retry;
}
}

// localhost management
if (Recep_NodeConcerned(&msg->header))
{
Expand All @@ -242,7 +263,7 @@ error_return_t Robus_SendMsg(ll_container_t *ll_container, msg_t *msg)
// set message into the allocator
MsgAlloc_SetMessage(msg);
}
return fail;
return result;
}
/******************************************************************************
* @brief Start a topology detection procedure
Expand Down
18 changes: 18 additions & 0 deletions inc/container_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@
/*******************************************************************************
* Definitions
******************************************************************************/
/* This structure is used to manage containers statistic
* please refer to the documentation
*/
typedef struct __attribute__((__packed__)) container_stats_t
{
union
{
struct __attribute__((__packed__))
{
uint8_t msg_fail_ratio;
uint8_t max_collision_retry;
uint8_t max_nak_retry;
};
uint8_t unmap[3]; /*!< streamable form. */
};
} container_stats_t;

/* This structure is used to manage containers timed auto update
* please refer to the documentation
*/
Expand All @@ -37,6 +54,7 @@ typedef struct __attribute__((__packed__)) container_t
uint8_t alias[MAX_ALIAS_SIZE]; /*!< container alias. */
timed_update_t auto_refresh; /*!< container auto refresh context. */
uint8_t firm_version[20]; /*!< container firmware version. */
container_stats_t statistic;
} container_t;

typedef void (*CONT_CB)(container_t *container, msg_t *msg);
Expand Down
15 changes: 14 additions & 1 deletion inc/luos.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @struct luos_stats_t
* @brief store informations about luos stats
******************************************************************************/

typedef struct __attribute__((__packed__))
{
union
Expand All @@ -30,10 +31,22 @@ typedef struct __attribute__((__packed__))
memory_stats_t memory;
uint8_t max_loop_time_ms;
};
uint8_t unmap[5]; /*!< streamable form. */
uint8_t unmap[sizeof(memory_stats_t)+1]; /*!< streamable form. */
};
} luos_stats_t;

typedef struct __attribute__((__packed__))
{
union
{
struct __attribute__((__packed__))
{
luos_stats_t node_stat;
container_stats_t container_stat;
};
uint8_t unmap[sizeof(luos_stats_t)+sizeof(container_stats_t)]; /*!< streamable form. */
};
} general_stats_t;
/*******************************************************************************
* Variables
******************************************************************************/
Expand Down
28 changes: 25 additions & 3 deletions src/luos.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ uint16_t container_number;
volatile routing_table_t *routing_table_pt;

luos_stats_t luos_stats;
general_stats_t general_stats;
/*******************************************************************************
* Function
******************************************************************************/
Expand Down Expand Up @@ -289,9 +290,11 @@ static error_return_t Luos_MsgHandler(container_t *container, msg_t *input)
msg_t output;
output.header.cmd = LUOS_STATISTICS;
output.header.target_mode = ID;
output.header.size = sizeof(luos_stats_t);
output.header.size = sizeof(general_stats_t);
output.header.target = input->header.source;
memcpy(output.data, &luos_stats.unmap, sizeof(luos_stats_t));
memcpy(&general_stats.node_stat, &luos_stats.unmap, sizeof(luos_stats_t));
memcpy(&general_stats.container_stat, &container->statistic.unmap, sizeof(container_stats_t));
memcpy(output.data, &general_stats.unmap, sizeof(general_stats_t));
Luos_SendMsg(container, &output);
error = SUCCEED;
}
Expand Down Expand Up @@ -498,6 +501,10 @@ container_t *Luos_CreateContainer(CONT_CB cont_cb, uint8_t type, const char *ali
break;
}

//initiate container statistic
container->ll_container->ll_stat.max_collision_retry = &container->statistic.max_collision_retry ;
container->ll_container->ll_stat.max_nak_retry = &container->statistic.max_nak_retry;

container_number++;
return container;
}
Expand All @@ -509,7 +516,22 @@ container_t *Luos_CreateContainer(CONT_CB cont_cb, uint8_t type, const char *ali
******************************************************************************/
error_return_t Luos_SendMsg(container_t *container, msg_t *msg)
{
return Robus_SendMsg(container->ll_container, msg);
error_return_t result = SUCCEED;
if(Robus_SendMsg(container->ll_container, msg) != SUCCEED)
{
container->ll_container->ll_stat.fail_msg_nbr++;
result = FAILED;
}
container->ll_container->ll_stat.msg_nbr++;

if(container->ll_container->ll_stat.msg_nbr == 0xFF)
{
container->ll_container->ll_stat.msg_nbr = container->ll_container->ll_stat.msg_nbr>>1;
}

container->statistic.msg_fail_ratio = (uint8_t)(((uint32_t)container->ll_container->ll_stat.fail_msg_nbr * 100) / container->ll_container->ll_stat.msg_nbr);

return result;
}
/******************************************************************************
* @brief read last msg from buffer for a container
Expand Down

0 comments on commit e8a121d

Please sign in to comment.