KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
shell_net.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : shell_tests.c
11  * Created : 14 mrt. 2013
12  * Author : Vincent van Beveren
13  */
14 
15 #include <stdbool.h>
16 #include <stdio.h>
17 
18 #include <stdlib.h>
19 
20 #include "util/convert.h"
21 #include "lm32soc/lm32.h"
22 #include "net/srp.h"
23 #include "net/network.h"
24 #include "pv/vars.h"
25 #include "kernel/err.h"
26 #include "ms.h"
27 
28 
29 
30 const char cmd_srp_help[] = "Show SRP status";
31 
32 bool cmd_srp_exec(int argc, const char *args[])
33 {
34  srpDumpStatus();
35  return true;
36 }
37 
38 const char cmd_net_help[] = "Show Network information, set IP address";
39 
40 #ifndef GOLDEN
41 static uint8_t hexByte(const char * input)
42 {
43  uint32_t out;
44  CnvParams params = {
45  .base = CNV_BASE_HEX,
46  .len = 2
47  };
48 
49  if (cnvParseU(input, &out, params) != 2) {
50  return 0xff;
51  }
52  return (uint8_t)out;
53 }
54 #endif
55 
56 bool cmd_net_exec(int argc, const char *args[])
57 {
58 
59  if (argc == 0) {
60  netShowInfo(true);
61  srpDumpStatus();
62  ms_dump_stats();
63  } else if (argc == 1 && strcmp(args[0], "help") == 0) {
64  puts("net [help|<ip>]");
65  puts(" without arguments - print network configuration");
66  puts(" help - show this help");
67  puts(" modip <ip> - set the module ip in the form of # # # # (spaces, no dots)");
68 #ifndef GOLDEN
69  puts(" svrip <ip> - set the server ip in the form of # # # # (spaces, no dots)");
70  puts(" svrmac <mac> - sets the server MAC in the form aa:bb:cc:dd:ee:ff");
71 #endif
72  }
73  else if (argc == 5) {
74  uint8_t ip[4];
75  int i;
76  for (i = 0; i < 4; ++i) ip[i] = atoi(args[i + 1]);
77  if (strcmp(args[0], "modip") == 0)
78  {
79  netSetIp(ip);
80  printf("Set module IP to: %u.%u.%u.%u\n", ip[0], ip[1], ip[2], ip[3]);
81 #ifndef GOLDEN
82  } else if (strcmp(args[0],"svrip") == 0)
83  {
84  uint32_t wIp = ( ip[0] << 24 ) | ( ip[1] << 16 ) | ( ip[2] << 8 ) | ( ip[3] << 0 );
85  net.ipmux_srv_ip = wIp;
86  printf("Set server IP to: %u.%u.%u.%u\n", ip[0], ip[1], ip[2], ip[3]);
87 #endif
88  } else {
89  return false;
90  }
91 #ifndef GOLDEN
92  } else if (argc == 2 && strcmp(args[0], "svrmac") == 0)
93  {
94  if (strlen(args[1]) != 17) return false;
95  net.ipmux_srv_mac[0] = hexByte(args[1] + 0) << 8 | hexByte(args[1] + 3);
96  net.ipmux_srv_mac[1] = hexByte(args[1] + 6) << 8 | hexByte(args[1] + 9);
97  net.ipmux_srv_mac[2] = hexByte(args[1] + 12) << 8 | hexByte(args[1] + 15);
98  printf("Set MAC to: %04x %04x %04x\n",
99  net.ipmux_srv_mac[0], net.ipmux_srv_mac[1], net.ipmux_srv_mac[2]);
100 #endif
101  } else {
102  return false;
103  }
104  return true;
105 }
int cnvParseU(const char *input, uint32_t *output, CnvParams params)
Parse an unsigned integer.
Definition: convert.c:61
Low level routines for LM32, including interrupt handling.
SRP or Simple Retransmission Protocol is a protocol which retransmits packets if they have not been c...
#define CNV_BASE_HEX
Base of hex numbers.
Definition: convert.h:32
void srpDumpStatus()
Outputs SRP status information.
Definition: srp.c:153
Manages the global system error.
This structure provides information about formatting and parsing.
Definition: convert.h:37
uint8_t base
Base of the number to format or parse.
Definition: convert.h:39
void netSetIp(uint8_t *ip)
Sets the Ip address to the network.
Definition: network.c:475
void netShowInfo(bool extended)
Shows network configuration information.
Definition: network.c:541
This module implements parsing and formating of strings and integers.