Newer
Older
*
* This module is the proprietary property of Codepoint Technologies, Inc.
* Copyright (C) 2021 Codepoint Technologies, Inc.
* All Rights Reserved
*/
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
#include "Controller.i"
#include "version.i" //Compile time generated file.
//System includes.
#include "cpflexver.i"
#include "system.i"
#include "power.i"
#include "battery.i"
#include "TelemMgr.i"
//Include Controller configuration.
#include "config/ConfigApp.i"
/*******************************************************
* Forward Declarations.
*******************************************************/
forward _ProcessSyslogCommand( value );
forward ResultCode: _ReportSyslogStatus( seqOut);
#pragma warning disable 213
/*******************************************************
* Constants and static variables.
*******************************************************/
/*******************************************************
* System events.
*******************************************************/
@SysInit()
{
Log( "********** N100 Vibration Sensor **************", MC_info, MP_med, LO_default);
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
LogFmt("** Version: %s", MC_info, MP_med, LO_default, __VERSION__);
LogFmt("** CP-Flex Ver: %s", MC_info, MP_med, LO_default, CPFLEX_VERSION);
LogFmt("** Build Date: %s %s", MC_info, MP_med, LO_default, __DATE__, __TIME__);
Log( "***********************************************", MC_info, MP_med, LO_default);
#ifdef __SYSLOG__
// //Test mode we automatically enable the System Log.
SysSetLogFilters( 0xFF, 0xFF);
#endif
battery_Init();
TelemMgr_Init();
ControllerInit();
}
/*******************************************************
* Handle UI Events.
*******************************************************/
@UiButtonEvent( idButton, ButtonPress: press, ctClicks)
{
TraceDebugFmt( "Button: id=%d, press=%d, clicks=%d", idButton, press, ctClicks);
switch(press) {
case BP_short: { battery_IndicateChargeLevel(); }
case BP_double: { TelemMgr_IndicateNetworkStatus(); }
}
}
#pragma warning disable 203
/**
* @brief Application Defined callback handler that indicates entering power savings.
* @remarks Required implementation to catch enter power saving events.
*/
app_EnterPowerSaving(pctCharged)
{
// Tracking is deactivated to preserve battery.
TraceDebug("Enter Power Save Mode");
ControllerPowerSavingUpdate(false);
}
/**
* @brief Application Defined callback handler that indicates entering power savings.
* @remarks Required implementation to catch exit power saving events.
*/
app_ExitPowerSaving(pctCharged)
{
TraceDebug("Exit Power Save Mode");
ControllerPowerSavingUpdate(true);
}
/*******************************************************
* Communication Implementation
*******************************************************/
#pragma warning enable 203
/**
* @brief Event hander receives notifications of telemtry system changes.
* @remarks Use this event to trigger other actions when telemetry is available or unavailable.
* @param stateTelem The updated change of telemtry state.
* @param datarate The datarate in data rate units (e.g. dr0 -dr12).
* @param packetsize The uplink/downlink packetsize in bytes. -1 is unknown.
*/
@TelemStatusEvent( TelemState: stateTelem, datarate, packetsize)
{
//Forward notification to the controller.
ControllerTelemetryStatusUpdate( stateTelem, datarate, packetsize);
}
/**
* @brief Received data sequence handler.
* @remarks. Processes received sequences and reports any requested. data.
*/
@TelemRecvSeq( Sequence: seqIn, ctMsgs )
{
TraceDebug("TelemRecvSeq");
//Process the received sequence.
new Message: msg;
new MessageType: tmsg;
new tcode;
new id;
new EventPriority: priority;
new EventType: etype;
new ResultCode: rc;
new ct= 0;
new Sequence:seqOut;
//Allocate a sequence to send messages.
rc = TelemSendSeq_Begin( seqOut, 96);
if( rc != RC_success)
{
TraceError("Could not allocate sequence buffer, ");
}
//Process each of the received messages.
while( rc == RC_success
&& TelemRecv_NextMsg( seqIn, msg, tmsg, tcode, id, priority, etype) == RC_success
) {
if( ControllerIsSupportedMessage( tmsg, id)) {
rc = ControllerProcessReceived( seqOut, tmsg, id, msg);
++ct;
} else if( tmsg == MT_Int32Msg){
switch( id) {
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
rc = battery_ReportChargeLevel( seqOut);
++ct;
}
case NID_ArchiveSyslog: {
new cmdvalue;
//Set the System Log Archive Filter if defined.
if( RC_success == TelemRecv_ToInt32Msg( msg,cmdvalue) ) {
_ProcessSyslogCommand( cmdvalue);
}
rc = _ReportSyslogStatus( seqOut);
++ct;
}
case NID_ArchiveErase: {
ArchiveErase(false);
}
case NID_AdminReset: {
SysReset();
}
}
}
}
//Done with the input sequence.
TelemRecv_SeqEnd( seqIn);
//Either send or discard output sequence
//send only if there are messages to send and we were successful in creating them.
TelemSendSeq_End( seqOut, rc != RC_success || ct == 0, TPF_CONFIRM);
if( rc != RC_success)
TraceError("Cannot send sequence an error occurred while assembling.");
}
/*******************************************************
* Communication Implementation
*******************************************************/
static _ProcessSyslogCommand( value )
{
new archive;
switch(value) {
case NID_ArchiveSyslogDisable: archive = 0x0;
case NID_ArchiveSyslogAlert: archive = 0x3F;
case NID_ArchiveSyslogInfo: archive = 0x4F;
case NID_ArchiveSyslogDetail: archive = 0x5F;
case NID_ArchiveSyslogAll: archive = 0x6F;
}
SysSetLogFilters( archive, 0xFF);
}
static ResultCode: _ReportSyslogStatus( seqOut)
{
new archive, terminal, telemetry, cmdvalue;
SysGetLogFilters( archive, terminal, telemetry);
switch(archive & 0xF0)
{
case MC_unspecified: cmdvalue = NID_ArchiveSyslogDisable;
case MC_alert: cmdvalue = NID_ArchiveSyslogAlert;
case MC_info: cmdvalue = NID_ArchiveSyslogInfo;
case MC_detail: cmdvalue = NID_ArchiveSyslogDetail;
case MC_debug: cmdvalue = NID_ArchiveSyslogAll;
}
return TelemSendInt32Msg( seqOut, NID_ArchiveSyslog, cmdvalue);
}