Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This module enables the RMS client heartbeat to be sped up and exceed the minimum interval safety threshold. It has be built to enable temporary improved response times in a *small number* of dev systems. It should probably never be used. Side affects include: irregular client heartbeats, excess server traffic, rapidly filling logs, general disg…
PROGRAM_NAME='RmsApiAux'
#IF_NOT_DEFINED __RMS_API_AUX__
#DEFINE __RMS_API_AUX__
#INCLUDE 'RmsApi'
define_constant
RMS_EVENT_ASSET_LOCATION = 'ASSET.LOCATION';
/**
* Queries the current location of an asset.
*
* @param assetClientKey a string containing the client key query
* @return a boolean, true if the query was successful
*/
define_function char RmsAssetLocationRequest(char assetClientKey[]) {
stack_var char rmsCommand[RMS_MAX_CMD_LEN];
if (assetClientKey == '') {
send_string 0, '>>>> RMS API AUX ERROR <RmsAssetLocationRequest> :: missing asset client key';
return false;
}
rmsCommand = RmsPackCmdHeader('?ASSET.LOCATION');
rmsCommand = RmsPackCmdParam(rmsCommand,assetClientKey);
send_command vdvRMS, rmsCommand;
return true;
}
/**
* Sends an email with the RMS email service.
*
* @param address the email address to send to
* @param subject the subject line
* @param body the message body
* @param cc carbon copy address list
* @param bcc blind carbon copy address list
* @return a boolean, true if the message was sent
*/
define_function char RmsEmail(char address[],
char subject[],
char body[],
char cc[],
char bcc[]) {
stack_var char rmsCommand[RMS_MAX_CMD_LEN];
if (address == '') {
send_string 0, '>>>> RMS API AUX ERROR <RmsEmail> :: missing address';
return false;
}
if (subject == '') {
send_string 0, '>>>> RMS API AUX ERROR <RmsEmail> :: missing subject';
return false;
}
if (body == '') {
send_string 0, '>>>> RMS API AUX ERROR <RmsEmail> :: missing body';
return false;
}
// submit the email
rmsCommand = RmsPackCmdHeader('MESSAGE.EMAIL');
rmsCommand = RmsPackCmdParam(rmsCommand,address);
rmsCommand = RmsPackCmdParam(rmsCommand,subject);
rmsCommand = RmsPackCmdParam(rmsCommand,body);
rmsCommand = RmsPackCmdParam(rmsCommand,cc);
rmsCommand = RmsPackCmdParam(rmsCommand,bcc);
send_command vdvRMS, rmsCommand;
return true;
}
/**
* Force the RMS client to immediately retrieve and process all pending
* client-destined messages from the RMS server.
*
* @return a boolean, true if successful
*/
define_function char RmsRetrieveClientMessages() {
stack_var char rmsCommand[RMS_MAX_CMD_LEN];
if (![vdvRMS, RMS_CHANNEL_CLIENT_ONLINE]) {
send_string 0, '>>>> RMS API AUX ERROR <RmsRetrieveClientMessages> :: client is currently offline';
return false;
}
send_command vdvRMS, 'CLIENT.MESSAGES.RETRIEVE';
return true;
}
#END_IF // __RMS_API_AUX__
/**
* This module enables the RMS client heartbeat to be sped up and exceed the
* minimum interval safety threshold. It has be built to enable temporary
* improved response times in a *small number* of demo systems. It should
* probably never be used.
*
* Side affects include: irregular client heartbeats, excess server traffic,
* rapidly filling logs, general disgust from SDK and server dev team.
*
* Use at your own risk. You have been warned.
*/
MODULE_NAME='RmsHeartAttack' (dev vdvRMS)
#DEFINE INCLUDE_RMS_EVENT_CUSTOM_COMMAND_CALLBACK
#INCLUDE 'RmsApi'
#INCLUDE 'RmsApiAux'
#INCLUDE 'RmsEventListener'
define_variable
constant char RMS_CUSTOM_COMMAND_HEARTATTACK[] = '@CONFIG.CLIENT.HEARTATTACK';
constant long FORCE_REFRESH = 1;
constant integer DEFAULT_INTERVAL = 5; // seconds
/**
* Sets the RMS heart attach active state. When enabled the RMS client will hit
* the server for any pending messages at the interval specified, allowing you
* to make things happen a little quicker that the safety threshold will allow.
*/
define_function setHeartAttack(char isEnabled, integer interval) {
// We need to kill the timeline regardless to refresh the interval so may
// as well be efficient about it.
if (timeline_active(FORCE_REFRESH)) {
timeline_kill(FORCE_REFRESH);
}
if (isEnabled) {
stack_var long times[1];
if (interval < 1) {
interval = DEFAULT_INTERVAL;
}
times[1] = interval * 1000;
timeline_create(FORCE_REFRESH,
times,
1,
TIMELINE_ABSOLUTE,
TIMELINE_REPEAT);
send_string 0, "'>>>> RMS HEARTATTACK :: starting myocardial infarction at ', itoa(interval), ' second intervals.'";
} else {
send_string 0, '>>>> RMS HEARTATTACK :: heart attack done. Lets not do that any time again soon.';
}
}
// RMS callbacks
define_function RmsEventCustomCommand(char header[], char data[]) {
if (header == RMS_CUSTOM_COMMAND_HEARTATTACK) {
stack_var char rmsParam1[RMS_MAX_PARAM_LEN];
stack_var char rmsParam2[RMS_MAX_PARAM_LEN];
rmsParam1 = RmsParseCmdParam(data);
rmsParam2 = RmsParseCmdParam(data);
setHeartAttack(RmsBooleanValue(rmsParam1), atoi(rmsParam2));
}
}
define_event
timeline_event[FORCE_REFRESH] {
if ([vdvRMS, RMS_CHANNEL_CLIENT_ONLINE]) {
RmsRetrieveClientMessages();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment