mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 09:49:21 +08:00
rptun ping: support data checksum and data transfer rate calculation
Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
This commit is contained in:
parent
3b74cfecc2
commit
df09e40e3a
2 changed files with 49 additions and 7 deletions
|
@ -39,8 +39,10 @@
|
|||
|
||||
#define RPTUN_PING_EPT_NAME "rpmsg-ping"
|
||||
#define RPTUN_PING_SEND 1
|
||||
#define RPTUN_PING_SEND_NOACK 2
|
||||
#define RPTUN_PING_ACK 3
|
||||
#define RPTUN_PING_SEND_CHECK 2
|
||||
#define RPTUN_PING_SEND_NOACK 3
|
||||
#define RPTUN_PING_ACK 4
|
||||
#define RPTUN_PING_CHECK_DATA 0xee
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
|
@ -51,6 +53,7 @@ begin_packed_struct struct rptun_ping_msg_s
|
|||
uint32_t cmd;
|
||||
uint32_t len;
|
||||
uint64_t cookie;
|
||||
uint8_t data[1];
|
||||
} end_packed_struct;
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -66,6 +69,26 @@ static int rptun_ping_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|||
|
||||
if (msg->cmd == RPTUN_PING_SEND)
|
||||
{
|
||||
msg->cmd = RPTUN_PING_ACK;
|
||||
rpmsg_send(ept, msg, len);
|
||||
}
|
||||
else if (msg->cmd == RPTUN_PING_SEND_CHECK)
|
||||
{
|
||||
int data_len;
|
||||
int i;
|
||||
|
||||
data_len = msg->len - sizeof(struct rptun_ping_msg_s) + 1;
|
||||
for (i = 0; i < data_len; i++)
|
||||
{
|
||||
if (msg->data[i] != RPTUN_PING_CHECK_DATA)
|
||||
{
|
||||
syslog(LOG_ERR, "rptun ping remote receive data error !\n");
|
||||
break;
|
||||
}
|
||||
|
||||
msg->data[i] = 0;
|
||||
}
|
||||
|
||||
msg->cmd = RPTUN_PING_ACK;
|
||||
rpmsg_send(ept, msg, len);
|
||||
}
|
||||
|
@ -78,7 +101,7 @@ static int rptun_ping_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|||
}
|
||||
|
||||
static int rptun_ping_once(FAR struct rpmsg_endpoint *ept,
|
||||
int len, bool ack)
|
||||
int len, int ack)
|
||||
{
|
||||
FAR struct rptun_ping_msg_s *msg;
|
||||
uint32_t space;
|
||||
|
@ -99,10 +122,16 @@ static int rptun_ping_once(FAR struct rpmsg_endpoint *ept,
|
|||
{
|
||||
sem_t sem;
|
||||
|
||||
msg->cmd = RPTUN_PING_SEND;
|
||||
msg->cmd = (ack == 1)? RPTUN_PING_SEND : RPTUN_PING_SEND_CHECK;
|
||||
msg->len = len;
|
||||
msg->cookie = (uintptr_t)&sem;
|
||||
|
||||
if (msg->cmd == RPTUN_PING_SEND_CHECK)
|
||||
{
|
||||
memset(msg->data, RPTUN_PING_CHECK_DATA,
|
||||
len - sizeof(struct rptun_ping_msg_s) + 1);
|
||||
}
|
||||
|
||||
nxsem_init(&sem, 0, 0);
|
||||
|
||||
ret = rpmsg_send_nocopy(ept, msg, len);
|
||||
|
@ -130,12 +159,24 @@ static void rptun_ping_logout(FAR const char *s, clock_t value)
|
|||
perf_convert(value, &ts);
|
||||
|
||||
#ifdef CONFIG_SYSTEM_TIME64
|
||||
syslog(LOG_INFO, "%s: s %" PRIu64 ", ns %ld\n", s, ts.tv_sec, ts.tv_nsec);
|
||||
syslog(LOG_INFO, "%s: %" PRIu64 " s, %ld ns\n", s, ts.tv_sec, ts.tv_nsec);
|
||||
#else
|
||||
syslog(LOG_INFO, "%s: s %" PRIu32 ", ns %ld\n", s, ts.tv_sec, ts.tv_nsec);
|
||||
syslog(LOG_INFO, "%s: %" PRIu32 " s, %ld ns\n", s, ts.tv_sec, ts.tv_nsec);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void rptun_ping_logout_rate(FAR const uint32_t len, clock_t avg)
|
||||
{
|
||||
struct timespec ts;
|
||||
double totalsec;
|
||||
|
||||
perf_convert(avg, &ts);
|
||||
|
||||
totalsec = (double)ts.tv_sec + (double)ts.tv_nsec / NSEC_PER_SEC;
|
||||
syslog(LOG_INFO, "rate: %.2f Mbits/sec\n",
|
||||
((double)len * 8.0) / 1048576.0 / totalsec);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
@ -176,6 +217,7 @@ int rptun_ping(FAR struct rpmsg_endpoint *ept,
|
|||
rptun_ping_logout("avg", total / ping->times);
|
||||
rptun_ping_logout("min", min);
|
||||
rptun_ping_logout("max", max);
|
||||
rptun_ping_logout_rate(ping->len, total / ping->times);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -348,7 +348,7 @@ struct rptun_ping_s
|
|||
{
|
||||
int times;
|
||||
int len;
|
||||
bool ack;
|
||||
int ack;
|
||||
int sleep; /* unit: ms */
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue