From 48c809a32077e6819b6655263a9f2c8b62f02692 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sat, 15 Jul 2017 09:49:39 +0200 Subject: [PATCH] Shell: added command to print tsch schedule Conflicts: apps/shell/shell-commands.c --- apps/shell/shell-commands.c | 37 +++++++++++++++++++++++++++++++ core/net/mac/tsch/tsch-schedule.c | 12 ++++++++++ core/net/mac/tsch/tsch-schedule.h | 3 +++ 3 files changed, 52 insertions(+) diff --git a/apps/shell/shell-commands.c b/apps/shell/shell-commands.c index 9e8c27eb7..48edf55e0 100644 --- a/apps/shell/shell-commands.c +++ b/apps/shell/shell-commands.c @@ -489,6 +489,42 @@ PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args)) PT_END(pt); } /*---------------------------------------------------------------------------*/ +static +PT_THREAD(cmd_tsch_schedule(struct pt *pt, shell_output_func output, char *args)) +{ + struct tsch_slotframe *sf; + + PT_BEGIN(pt); + + if(tsch_is_locked()) { + PT_EXIT(pt); + } + + sf = tsch_schedule_slotframe_head(); + + if(sf == NULL) { + SHELL_OUTPUT(output, "TSCH schedule: no slotframe\n"); + } else { + SHELL_OUTPUT(output, "TSCH schedule:\n"); + while(sf != NULL) { + struct tsch_link *l = list_head(sf->links_list); + + SHELL_OUTPUT(output, "-- Slotframe: handle %u, size %u, links:\n", sf->handle, sf->size.val); + + while(l != NULL) { + SHELL_OUTPUT(output, "---- Options %02x, type %u, timeslot %u, channel offset %u, address ", + l->link_options, l->link_type, l->timeslot, l->channel_offset); + shell_output_lladdr(output, &l->addr); + SHELL_OUTPUT(output, "\n"); + l = list_item_next(l); + } + + sf = tsch_schedule_slotframe_next(sf); + } + } + PT_END(pt); +} +/*---------------------------------------------------------------------------*/ void shell_commands_init(void) { @@ -507,6 +543,7 @@ struct shell_command_t shell_commands[] = { { "rpl-global-repair", cmd_rpl_global_repair, "'> rpl-global-repair': Triggers a RPL global repair" }, { "rpl-local-repair", cmd_rpl_local_repair, "'> rpl-local-repair': Triggers a RPL local repair" }, { "routes", cmd_routes, "'> routes': Shows the route entries" }, + { "tsch-schedule", cmd_tsch_schedule, "'> tsch-schedule': Shows the current TSCH schedule" }, { "tsch-status", cmd_tsch_status, "'> tsch-status': Shows a summary of the current TSCH state" }, { NULL, NULL, NULL }, }; diff --git a/core/net/mac/tsch/tsch-schedule.c b/core/net/mac/tsch/tsch-schedule.c index 378a34ff8..3ea8a1b43 100644 --- a/core/net/mac/tsch/tsch-schedule.c +++ b/core/net/mac/tsch/tsch-schedule.c @@ -418,6 +418,18 @@ tsch_schedule_create_minimal(void) 0, 0); } /*---------------------------------------------------------------------------*/ +struct tsch_slotframe * +tsch_schedule_slotframe_head(void) +{ + return list_head(slotframe_list); +} +/*---------------------------------------------------------------------------*/ +struct tsch_slotframe * +tsch_schedule_slotframe_next(struct tsch_slotframe *sf) +{ + return list_item_next(sf); +} +/*---------------------------------------------------------------------------*/ /* Prints out the current schedule (all slotframes and links) */ void tsch_schedule_print(void) diff --git a/core/net/mac/tsch/tsch-schedule.h b/core/net/mac/tsch/tsch-schedule.h index 75f757e66..1099664a9 100644 --- a/core/net/mac/tsch/tsch-schedule.h +++ b/core/net/mac/tsch/tsch-schedule.h @@ -160,5 +160,8 @@ int tsch_schedule_remove_link_by_timeslot(struct tsch_slotframe *slotframe, uint /* Returns the next active link after a given ASN, and a backup link (for the same ASN, with Rx flag) */ struct tsch_link * tsch_schedule_get_next_active_link(struct tsch_asn_t *asn, uint16_t *time_offset, struct tsch_link **backup_link); +/* Access to slotframe list */ +struct tsch_slotframe *tsch_schedule_slotframe_head(void); +struct tsch_slotframe *tsch_schedule_slotframe_next(struct tsch_slotframe *sf); #endif /* __TSCH_SCHEDULE_H__ */