-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtimedResponse.c
More file actions
128 lines (118 loc) · 5.04 KB
/
timedResponse.c
File metadata and controls
128 lines (118 loc) · 5.04 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
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
/*
Routines for CBUS FLiM operations - part of CBUS libraries for PIC 18F
This work is licensed under the:
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
To view a copy of this license, visit:
http://creativecommons.org/licenses/by-nc-sa/4.0/
or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
License summary:
You are free to:
Share, copy and redistribute the material in any medium or format
Adapt, remix, transform, and build upon the material
The licensor cannot revoke these freedoms as long as you follow the license terms.
Attribution : You must give appropriate credit, provide a link to the license,
and indicate if changes were made. You may do so in any reasonable manner,
but not in any way that suggests the licensor endorses you or your use.
NonCommercial : You may not use the material for commercial purposes. **(see note below)
ShareAlike : If you remix, transform, or build upon the material, you must distribute
your contributions under the same license as the original.
No additional restrictions : You may not apply legal terms or technological measures that
legally restrict others from doing anything the license permits.
** For commercial use, please contact the original copyright holder(s) to agree licensing terms
**************************************************************************************************************
The FLiM routines have no code or definitions that are specific to any
module, so they can be used to provide FLiM facilities for any module
using these libraries.
*/
#include <stddef.h>
#include "module.h"
#include "GenericTypeDefs.h"
#include "timedResponse.h"
#include "mioEvents.h"
#include "FliM.h"
#include "mioNv.h"
#include "analogue.h"
#include "romops.h"
#include "cbus.h"
#include "module.h"
#ifdef TIMED_RESPONSE
/*
* File: timedResponse.c
* Author: Ian
*
* Created on 8 December 2021, 16:19
*/
/**
* TimedResponse handles the sending of CBUS responses at a slower rate to allow receivers of these messages to
* process them.
*
* Two global variables are used to control the process:
* <ul>
* <li>timedResponse determines which set of responses is currently being sent.
* <li>timedResonseStep determines how far through the responses we're currently at
* </ul>
*
* Call initTimedResponse() before other TimedResponse processing. This will set the current response set to be None.
* Call doTimedResponse() on a regular basis which will do the work needed for the next step and increments the step counter.
*
* To start send a set of timed responses set the type of response required and set the step to 0.
* For example to send responses to NERD do:
* timedResponse = TIMED_RESPONSE_NERD;
* timedResponseStep = 0;
*/
unsigned char timedResponse;
unsigned char timedResponseStep;
extern BOOL sendProducedEvent(HAPPENING_T happening, BOOL on);
extern unsigned char APP_doSOD(unsigned char step);
/**
* Initialise the timedResponse functionality.
*/
void initTimedResponse(void) {
timedResponse = TIMED_RESPONSE_NONE;
}
/**
* Send one response CBUS message and increment the step counter ready for the next call.
* Although I agreed with Pete that SOD is only applicable to EV#2 I actually allow it at any EV#
*/
void doTimedResponse(void) {
switch (timedResponse) {
case TIMED_RESPONSE_SOD:
switch (APP_doSOD(timedResponseStep)) {
case TIMED_RESPONSE_APP_FINISHED:
// say we have finished
timedResponse = TIMED_RESPONSE_NONE;
timedResponseStep = 0;
return;
case TIMED_RESPONSE_APP_RETRY:
// just return so we don't increment step
return;
// case TIMED_RESPONSE_APP_NEXT:
// just drop out of break and increment step
}
break;
case TIMED_RESPONSE_NERD:
// The step is used to index through the event table
if (timedResponseStep >= NUM_EVENTS) { // finished?
timedResponse = TIMED_RESPONSE_NONE;
timedResponseStep = 0;
return;
}
// if its not free and not a continuation then it is start of an event
if (validStart(timedResponseStep)) {
WORD n = getNN(timedResponseStep);
cbusMsg[d3] = n >> 8;
cbusMsg[d4] = n & 0xFF;
n = getEN(timedResponseStep);
cbusMsg[d5] = n >> 8;
cbusMsg[d6] = n & 0xFF;
cbusMsg[d7] = tableIndexToEvtIdx(timedResponseStep);
if (!cbusSendOpcMyNN( 0, OPC_ENRSP, cbusMsg )) {
// we were unable to send the message so don't update step so that we can try again next time
return;
}
}
break;
}
timedResponseStep++;
}
#endif