KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
shell_bps.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2015 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : shell_bps.c
11  * Created : 27 feb. 2015
12  * Author : Riccardo Travaglini
13  */
14 
15 #include <stdbool.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 
19 #include <util/convert.h>
20 
21 #include <drv/uart/bps.h>
22 
23 #include "kernel/scheduler.h"
24 #include <errorcode.h>
25 #include <kernel/err.h>
26 
27 
28 
29 
30 static const CnvParams _hex = CNV_DEFAULT_HEX;
31 static const CnvParams _int = CNV_DEFAULT;
32 
33 const char cmd_bps_help[] = "BPS - Configure and Read";
34 
35 
36 /*static uint8_t bpshexByte(const char * input)
37 {
38  uint32_t out;
39  CnvParams params = {
40  .base = CNV_BASE_HEX,
41  .len = 2
42  };
43 
44  if (cnvParseU(input, &out, params) != 2) {
45  return 0xff;
46  }
47  return (uint8_t)out;
48 }*/
49 
50 static uint16_t bpshexShort(const char * input)
51 {
52  uint32_t out;
53  CnvParams params = {
54  .base = CNV_BASE_HEX,
55  .len = 4
56  };
57 
58  if (cnvParseU(input, &out, params) != 4) {
59  return 0xff;
60  }
61  return (uint16_t)out;
62 }
63 
64 static uint16_t bpsdecShort(const char * input)
65 {
66  uint32_t out;
67  CnvParams params = CNV_DEFAULT;
68 
69  if (cnvParseU(input, &out, params) <= 0) {
70  return -1;
71  }
72  return (uint16_t)out;
73 }
74 
75 
76 
77 
78 bool cmd_bps_exec(int argc, const char *args[])
79 {
80 
81 
82  uint16_t rdata;
83  BspTh wth,rth;
84  uint16_t wsal,rsal;
85  uint16_t fw;
86 
87  if (argc < 1 || ((argc == 1) && (strcmp(args[0],"help") == 0))) {
88  puts("usage: bps sensors -- read sensors");
89  puts(" bps alarm en load|save [opt] -- enable alarm (load or save) - opt = hex value to be saved");
90  puts(" bps alarm th load|save [th_375 th_12v]-- Threshold alarm (load or save) - th.. = decimal values to be saved");
91  puts(" bps alarm clear -- clear alarm");
92  puts(" bps toggle back|12v-- toggle breakers");
93  puts(" bps ping -- get fw version");
94 
95 
96 
97  }
98  else if(argc == 1 && strcmp(args[0],"sensors") == 0){
99  BpsRdSensAnsw sens;
100  bpsReadSensor(&sens);
101 #ifndef BPSSIM
102  printf("I(backbone) = %d\n", sens.mon_i);
103  printf("I(12V) = %d\n", sens.mon1_i12);
104  printf("V(375V) = %d\n", sens.mon2_v375);
105  printf("I(375V) = %d\n", sens.mon3_i375);
106  printf("V(5V) = %d\n", sens.mon4_v375);
107 #else
108  printf("I(backbone) = = 0x%x\n", sens.mon_i);
109  printf("I(12V) = 0x%x\n", sens.mon1_i12);
110  printf("V(375V) = 0x%x\n", sens.mon2_v375);
111  printf("I(375V) = 0x%x\n", sens.mon3_i375);
112  printf("V(5V) = 0x%x\n", sens.mon4_v375);
113 #endif
114  printf("al = 0x%x\n", sens.alarm);
115  printf("break = 0x%x\n", sens.breaker);
116 
117 
118  }
119  else if(argc >= 2 && strcmp(args[0],"alarm") == 0){
120  if(argc >= 3 && strcmp(args[1],"th")== 0){
121  if(argc == 5 && strcmp(args[2],"save")== 0){
122 
123  wth.thr_mon_375i0 = bpsdecShort(args[3]);
124  wth.thr_mon_12v = bpsdecShort(args[4]);
125  bpsAlarmThSave(&wth, &rth);
126 
127  printf("TH 375V I0 = %d\n",rth.thr_mon_375i0 );
128  printf("TH 12V I0 = %d\n",rth.thr_mon_12v);
129 
130  }
131  else if(argc == 3 && strcmp(args[2],"load")== 0){
132  bpsAlarmThLoad(&rth);
133 #ifndef BPSSIM
134  printf("TH 375V I0 = %d\n",rth.thr_mon_375i0 );
135  printf("TH 12V I0 = %d\n",rth.thr_mon_12v);
136 #else
137  printf("TH 375V I0 = 0x%x\n",rth.thr_mon_375i0 );
138  printf("TH 12V I0 = 0x%x\n",rth.thr_mon_12v);
139 #endif
140  }
141  else return false;
142  }
143  else if(argc >= 3 && strcmp(args[1],"en")== 0){
144  if(argc == 4 && strcmp(args[2],"save")== 0){
145  wsal = bpshexShort(args[3]);
146  printf("%s - ret 0x%x\n",bpsAlarmEnSave(wsal, &rsal)?"Done":"Error",rsal);
147  }
148  else if(argc == 3 && strcmp(args[2],"load")== 0){
149  printf("%s - ret 0x%x\n",bpsAlarmEnLoad(&rsal)?"Done":"Error",rsal);
150  }
151  else return false;
152  }
153  else if(argc == 2 && strcmp(args[1],"clear")== 0){
154  printf("%s - ret 0x%x\n",bpsAlarmClearStat(&rdata)?"Done":"Error",rdata);
155  }
156  else return false;
157  }
158  else if(argc == 2 && strcmp(args[0],"toggle") == 0){
159  if(strcmp(args[1],"back") == 0){
160  printf("%s - ret 0x%x\n",bpsRelayToggleBackBone(&rsal)?"Done":"Error",rsal);
161  }
162  else if(strcmp(args[1],"12v") == 0) {
163  printf("%s - re 0x%x\n",bpsRelayToggle12V(&rsal)?"Done":"Error",rsal);
164  }
165  else return false;
166  }
167  else if(argc == 1 && strcmp(args[0],"ping") == 0){
168  printf("%s - ret 0x%x\n",bpsPingDevice(&fw)?"Done":"Error",fw);
169  }
170 
171  else return false;
172 
173 
174 
175 
176 
177  return true;
178 
179 }
180 
181 
Definition: bps.h:75
BPS Uart driver (.
bool bpsRelayToggleBackBone(uint16_t *breakers)
Toggle relay status.
Definition: bps.c:737
int cnvParseU(const char *input, uint32_t *output, CnvParams params)
Parse an unsigned integer.
Definition: convert.c:61
bool bpsAlarmClearStat(uint16_t *alarms)
Clear Status Alarm.
Definition: bps.c:654
bool bpsAlarmThLoad(BspTh *th)
load already saved alarm threshold (in mA)
Definition: bps.c:671
Simple task scheduler for tasks.
#define CNV_BASE_HEX
Base of hex numbers.
Definition: convert.h:32
bool bpsPingDevice(uint16_t *fw)
Ping Device.
Definition: bps.c:770
#define CNV_DEFAULT
Default conversion/formatting parameters (base 10).
Definition: convert.h:47
bool bpsAlarmThSave(BspTh *newth, BspTh *th)
save alarm threshold (in mA)
Definition: bps.c:698
Manages the global system error.
This structure provides information about formatting and parsing.
Definition: convert.h:37
bool bpsReadSensor(BpsRdSensAnsw *stat)
return sensor values
Definition: bps.c:577
This module is responsible for distributing error codes.
uint8_t base
Base of the number to format or parse.
Definition: convert.h:39
bool bpsAlarmEnSave(uint16_t newal, uint16_t *alarms)
save alarm enable
Definition: bps.c:630
This module implements parsing and formating of strings and integers.
bool bpsAlarmEnLoad(uint16_t *alarms)
Load already saved alarm enable.
Definition: bps.c:614