forked from bristlemouth/bm_protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_pressure_sensor.cpp
More file actions
92 lines (82 loc) · 2.96 KB
/
debug_pressure_sensor.cpp
File metadata and controls
92 lines (82 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "debug_pressure_sensor.h"
#include "FreeRTOS.h"
#include "FreeRTOS_CLI.h"
#include <string.h>
#include <stdlib.h>
#include "debug.h"
#include "cli.h"
static AbstractPressureSensor* _pressure_sensor = NULL;
static BaseType_t pressureSensorCommand( char *writeBuffer,
size_t writeBufferLen,
const char *commandString);
static const CLI_Command_Definition_t cmdPressureSensor = {
// Command string
"pressure",
// Help string
"pressure:\n"
" * init - initialize the device\n"
" * read - read the raw temp and pressure\n"
" * reset - reset the device\n"
" * check - check the devices prom\n"
" * sig - get the device signature\n",
// Command function
pressureSensorCommand,
// Number of parameters (variable)
-1
};
void debugPressureSensorInit(AbstractPressureSensor* pressure_sensor) {
_pressure_sensor = pressure_sensor;
FreeRTOS_CLIRegisterCommand( &cmdPressureSensor );
}
static BaseType_t pressureSensorCommand( char *writeBuffer,
size_t writeBufferLen,
const char *commandString) {
BaseType_t parameterStringLength;
( void ) writeBuffer;
( void ) writeBufferLen;
do {
if(!_pressure_sensor){
printf("pressure sensor debug not initialized!\n");
break;
}
const char *parameter = FreeRTOS_CLIGetParameter(
commandString,
1, // Get the first parameter (command)
¶meterStringLength);
if(parameter == NULL) {
printf("ERR Invalid paramters\n");
break;
}
if (strncmp("read", parameter, parameterStringLength) == 0) {
float temp, pressure;
if(!_pressure_sensor->readPTRaw(pressure, temp)){
printf("failed to read pressure sensor\n");
break;
}
printf("Temp:%f, Pressure:%f\n",temp, pressure);
} else if (strncmp("reset", parameter, parameterStringLength) == 0) {
if(!_pressure_sensor->reset()){
printf("Failed to reset device!\n");
break;
}
printf("Device reset\n");
} else if (strncmp("init", parameter, parameterStringLength) == 0) {
if(!_pressure_sensor->init()){
printf("Failed to initialize\n");
break;
}
printf("Initialized!\n");
} else if (strncmp("check", parameter, parameterStringLength) == 0) {
if(!_pressure_sensor->checkPROM()){
printf("PROM check failed!\n");
break;
}
printf("PROM check passed!\n");
} else if (strncmp("sig", parameter, parameterStringLength) == 0) {
printf("Signature: %" PRIu32 "\n",_pressure_sensor->signature());
} else {
printf("ERR Invalid paramters\n");
}
} while(0);
return pdFALSE;
}