Commit 7317abb4 authored by Hynek Syrovátka's avatar Hynek Syrovátka 🇨🇿
Browse files

Added

parent 709b3e2d
//############################################################################################
/* Title: IQRF Standards DALI driver
See also: <https://www.iqrfalliance.org/techDocs/>
*/
/*DriverDescription
{ 'ID' : 0x4A,
'Type' : 'Standard',
'Internal' : false,
'Versions' : [
{ 'Version' : 0, 'Notes' : [
'Initial release' ]
}
] }
DriverDescription*/
"use strict";
// Namespace: iqrf.DALI
namespace( 'iqrf.DALI' );
// IQRF Standards DALI PNUM value
iqrf.DALI.PNUM = '4A';
// FRC commands
/* Const: iqrf.DALI.STD_DALI_SEND_FRC
FRC command to return answer of the provided DALI command.
*/
iqrf.DALI.STD_DALI_SEND_FRC = 0xE0;
iqrf.DALI.DaliSendCmds_Request = function ( commands, pcmd )
{
var data = '';
var commands_length = commands.length;
if ( commands_length < 1 )
throw new Error( 'iqrf.DALI.DaliSendCmds_Request: No DALI commands specified.' );
for ( var index = 0; index < commands_length; index++ )
{
var oneCmd = commands[index];
if ( typeof oneCmd !== 'number' || oneCmd < 0 || oneCmd > 0xFfFf )
throw new Error( 'iqrf.DALI.DaliSendCmds_Request: Invalid DALI command value ' + oneCmd );
if ( data.length !== 0 )
data += '.';
data += iqrf.ToHexStringByte( oneCmd >> 8 ) + '.' + iqrf.ToHexStringByte( oneCmd & 0xFF );
}
return new iqrf.DpaRawHdpMessage( iqrf.DALI.PNUM, pcmd, data );
};
/* Function: iqrf.DALI.SendCommands_Request
Send DALI commands and returns answers synchronously.
Parameters:
commands - array: Array of 2 bytes (16 bits) wide values, each representing one DALI command at the standard DALI format YAAAAAAS+DDDDDDDD.
Returns:
iqrf.DpaRawHdpMessage: DPA request object.
*/
iqrf.DALI.SendCommands_Request = function ( commands )
{
return iqrf.DALI.DaliSendCmds_Request( commands, '00' );
};
/* Function: iqrf.DALI.SendCommands_Response
Decodes DPA response from sending DALI commands synchronously.
Parameters:
response - iqrf.DpaRawHdpMessage: DPA response object.
Returns:
array: Array of objects each representing answer to the respective DALI command.
* status - number: See IQRF DALI standard for details.
* value - number: See IQRF DALI standard for details.
*/
iqrf.DALI.SendCommands_Response = function ( response )
{
var responseData = iqrf.CheckResponsePnumPcmdDlen( response, iqrf.DALI.PNUM, '80', -2 );
var result = [];
var responseData_length = responseData.length;
for ( var index = 0; index < responseData_length; )
{
result[result.length] =
{
status: responseData[index++],
value: responseData[index++]
};
}
return result;
};
/* Function: iqrf.DALI.SendCommandsAsync_Request
Send DALI commands and returns answers asynchronously.
Parameters:
commands - array: Array of 2 bytes (16 bits) wide values, each representing one DALI command at the standard DALI format YAAAAAAS+DDDDDDDD.
Returns:
iqrf.DpaRawHdpMessage: DPA request object.
*/
iqrf.DALI.SendCommandsAsync_Request = function ( commands )
{
return iqrf.DALI.DaliSendCmds_Request( commands, '01' );
};
/* Function: iqrf.DALI.SendCommandsAsync_Response
Decodes DPA response from sending DALI commands synchronously.
Parameters:
response - iqrf.DpaRawHdpMessage: DPA response object.
*/
iqrf.DALI.SendCommandsAsync_Response = function ( response )
{
iqrf.CheckResponsePnumPcmdDlen( response, iqrf.DALI.PNUM, '81', 0 );
};
/* Function: iqrf.DALI.Frc_Response
Parses FRC response into DALI answer values.
_Requires FRC embedded peripheral driver_.
Parameters:
responseFrcSend - object: Return value from iqrf.embed.frc.Send[Selective]_Response
responseFrcExtraResult - array: [optional] Return value from iqrf.embed.frc.ExtraResult_Response. For smaller networks extra FRC result might not be needed.
Returns:
array: Array of objects for every DALI answer. Object array index represent the node address (or index in case selectedNodes parameter was used). The object has the same fields as object at the return value of <iqrf.DALI.SendCommands_Response>.
*/
iqrf.DALI.Frc_Response = function ( responseFrcSend, responseFrcExtraResult )
{
var responseFrcExtraResultParsed;
if ( responseFrcExtraResult !== undefined )
responseFrcExtraResultParsed = iqrf.embed.frc.ExtraResult_Response( responseFrcExtraResult );
var parsedFrc = iqrf.embed.frc.ParseResponses( iqrf.DALI.STD_DALI_SEND_FRC, iqrf.embed.frc.Send_Response( responseFrcSend ), responseFrcExtraResultParsed );
var result = [];
for ( var index in parsedFrc )
{
var frcValue = parsedFrc[index];
result[index] =
{
status: frcValue >> 8,
value: frcValue & 0xFF
};
}
return result;
};
//############################################################################################
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment