-
Notifications
You must be signed in to change notification settings - Fork 2
/
cmdInterval.cpp
107 lines (82 loc) · 2.48 KB
/
cmdInterval.cpp
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
Module: cmdInterval.cpp
Function:
Process the "interval" command
Copyright and License:
This file copyright (C) 2022 by
MCCI Corporation
3520 Krums Corners Road
Ithaca, NY 14850
See accompanying LICENSE file for copyright and license information.
Author:
Dhinesh Kumar Pitchai, MCCI Corporation September 2022
*/
#include "Catena4430_cmd.h"
#include <Catena4430_Sensor.h>
using namespace McciCatena;
using namespace McciCatena4430;
extern cMeasurementLoop *gpMeasurementLoopConcrete;
/*
Name: ::cmdLog()
Function:
Command dispatcher for "interval" command.
Definition:
McciCatena::cCommandStream::CommandFn cmdInterval;
McciCatena::cCommandStream::CommandStatus cmdInterval(
cCommandStream *pThis,
void *pContext,
int argc,
char **argv
);
Description:
The "interval" command has the following syntax:
interval
Display the current measurement interval.
interval {number}
Set the measurement interval {number}
Returns:
cCommandStream::CommandStatus::kSuccess if successful.
Some other value for failure.
*/
/* process "interval" */
// argv[0] is the matched command name
// argv[1] is the value
cCommandStream::CommandStatus cmdInterval(
cCommandStream *pThis,
void *pContext,
int argc,
char **argv
)
{
cCommandStream::CommandStatus result;
result = cCommandStream::CommandStatus::kInvalidParameter;
if (argc == 1)
{
auto const info = gpMeasurementLoopConcrete->m_Scd.getInfo();
gCatena.SafePrintf("%u secs\n", info.MeasurementInterval);
result = cCommandStream::CommandStatus::kSuccess;
}
else if (argc != 2)
{
// do nothing
}
else
{
std::uint32_t interval;
// set interval.
result = cCommandStream::getuint32(argc, argv, 1, 10, interval, 0);
if (result == cCommandStream::CommandStatus::kSuccess && interval <= UINT16_MAX)
{
if (! gpMeasurementLoopConcrete->m_Scd.setMeasurementInterval(std::uint16_t(interval)))
{
gCatena.SafePrintf("setMeasurementInterval failed: %s\n", gpMeasurementLoopConcrete->m_Scd.getLastErrorName());
result = cCommandStream::CommandStatus::kError;
}
else
{
result = cCommandStream::CommandStatus::kSuccess;
}
}
}
return result;
}