📄 dali_lib.c
字号:
{
// Care with 'rec_add': 7-bit variable
if ((rec_add & 0x70) == 0x40) add_type = GROUP_ADD_TYPE;
else
{
// Care with 'rec_add': 7-bit variable
if ((rec_add & 0x7F) == 0x7F) add_type = BROAD_ADD_TYPE;
else
{
// Special commands are broadcast commands
// Care with 'rec_add': 7-bit variable
if ( (((rec_add & 0x70) == 0x50) || ((rec_add & 0x70) == 0x60)) && (direct_cmd == FALSE) )
{
add_type = BROAD_ADD_TYPE;
special_cmd = TRUE;
}
else
{
st_mess->p_cc = 0;
st_mess->dtr = rec_add; // For debugging if needed, care: 7-bit variable
st_mess->status = DALI_RX_NO_ADD_TYPE;
Dali_slave_disable();
return DALI_STATUS_ERROR;
}
}
}
}
//----- Address_Range_Test
if (add_type != BROAD_ADD_TYPE)
{
if (add_type == SHORT_ADD_TYPE)
{
// Care with 'rec_add': 7-bit variable
if ((st_mess->short_add) != rec_add)
{
st_mess->p_cc = 0;
st_mess->dtr = rec_add; // For debugging if needed
st_mess->status = DALI_RX_ADD_OUT_RANGE;
Dali_slave_disable();
return DALI_STATUS_ERROR;
}
}
else
{
// Care with 'rec_add': 7-bit variable
if (((st_mess->group) & (1 << (rec_add & 0x0F))) == 0)
{
st_mess->p_cc = 0;
st_mess->dtr = rec_add & 0x0F; // For debugging if needed
st_mess->status = DALI_RX_ADD_OUT_RANGE;
Dali_slave_disable();
return DALI_STATUS_ERROR;
}
}
}
//----- Get-Command_Code (c.f. dali_lib.h file)
rec_data = (U8)(rec_dali & 0x00FF);
// Output direct arc power control command
if (direct_cmd == TRUE)
{
st_mess->p_cc = 0;
st_mess->dtr = rec_data;
st_mess->g_code = DIRECT_ARC_POWER_CONTROL;
if (add_type == SHORT_ADD_TYPE) st_mess->status = DALI_RX_CODE_SHORT ;
else if (add_type == GROUP_ADD_TYPE) st_mess->status = DALI_RX_CODE_GROUP ;
else st_mess->status = DALI_RX_CODE_BROAD ;
Dali_slave_disable();
return DALI_STATUS_COMPLETED;
}
if (special_cmd == FALSE)
{
// Test: Indirect arc power control commands
if ( (rec_data >= ((U8)(IMMEDIATE_OFF & 0xFF))) && (rec_data <= ((U8)(ON_AND_STEP_UP & 0xFF))) )
{ code_type = CT01; }
else if ( ((rec_data & 0xF0) == ((U8)(GO_TO_SCENE & 0xFF))) )
{ code_type = CT02; }
// Test: Configuration commands (must be received twice, c.f. "CMD_RX_CMD_2ND")
else if ( (rec_data == ((U8)(RESET & 0xFF))) || (rec_data == ((U8)(STORE_ACTUAL_DIM_LEVEL_IN_DTR & 0xFF))) )
{ if (rec_dali == st_mess->p_cc) code_type = CT01; else code_type = CT11;}
else if ( (rec_data >= ((U8)(STORE_THE_DTR_AS_MAX_LEVEL & 0xFF))) && (rec_data <= ((U8)(STORE_THE_DTR_AS_FADE_RATE & 0xFF))) )
{ if (rec_dali == st_mess->p_cc) code_type = CT01; else code_type = CT11;}
else if ( ((rec_data & 0xF0) >= ((U8)(STORE_THE_DTR_AS_SCENE & 0xFF))) && ((rec_data & 0xF0) <= ((U8)(REMOVE_FROM_GROUP & 0xFF))) )
{ if (rec_dali == st_mess->p_cc) code_type = CT02; else code_type = CT12;}
else if ( (rec_data == ((U8)(STORE_DTR_AS_SHORT_ADDRESS & 0xFF))) )
{ if (rec_dali == st_mess->p_cc) code_type = CT01; else code_type = CT11;}
// Test: Query commands (answer needed, c.f. "CMD_TX_ANSWER")
else if ( (rec_data >= ((U8)(QUERY_STATUS & 0xFF))) && (rec_data <= ((U8)(QUERY_POWER_FAILURE & 0xFF))) )
{ code_type = CT21; }
else if ( (rec_data >= ((U8)(QUERY_ACTUAL_LEVEL & 0xFF))) && (rec_data <= ((U8)(QUERY_FADE & 0xFF))) )
{ code_type = CT21; }
else if ( ((rec_data & 0xF0) == ((U8)(QUERY_SCENE_LEVEL & 0xFF))) )
{ code_type = CT22; }
else if ( (rec_data >= ((U8)(QUERY_GROUPS_0_7 & 0xFF))) && (rec_data <= ((U8)(QUERY_RANDOM_ADDRESS_L & 0xFF))) )
{ code_type = CT21; }
else if ( ((rec_data & 0xE0) == ((U8)(QUERY_APPLICATION_EXTENTED_COMMAND & 0xFF))) )
{ code_type = CT23; } // For '0xE0', verify Standard Command code for QUERY_APPLICATION_EXTENTED_COMMAND
else { code_type = CT00; }
}
else // special_cmd == TRUE
{
// Test: Special commands
if ( rec_dali == TERMINATE)
{ code_type = CT09; }
else if ( ((rec_dali & 0xFF00) == DATA_TRANSFER_REGISTER) || ((rec_dali & 0xFF00) == INITIALISE) )
{ code_type = CT0D; }
else if ( ( rec_dali == RANDOMISE) || ( rec_dali == COMPARE) || ( rec_dali == WITHDRAW) )
{ code_type = CT09; }
else if ( ((rec_dali & 0xFF00) == SEARCHADDRH) || ((rec_dali & 0xFF00) == SEARCHADDRM) || ((rec_dali & 0xFF00) == SEARCHADDRL) )
{ code_type = CT0D; }
else if ( ((rec_dali & 0xFF81) == (PROGRAM_SHORT_ADDRESS+1)) || ((rec_dali & 0xFF81) == (VERIFY_SHORT_ADDRESS+1)) )
{ code_type = CT0C; }
else if ( rec_dali == QUERY_SHORT_ADDRESS )
{ code_type = CT29; }
else if ( rec_dali == PHYSICAL_SELECTION )
{ code_type = CT09; }
else if ( ((rec_dali & 0xFF00) == ENABLE_DEVICE_TYPE_X) )
{ code_type = CT0D; }
else { code_type = CT00; }
}
//----- Update message structure and return value
// Update message structure and return value for CT00
if (code_type == CT00)
{
st_mess->g_code = NO_DALI_COMMAND_CODE;
st_mess->dtr = rec_add; // For debugging if needed
st_mess->p_cc = 0;
st_mess->status = DALI_RX_CODE_ERROR;
Dali_slave_disable();
return DALI_STATUS_ERROR;
}
// Only update message structure
switch (code_type & 0x0F)
{
case CTX1:
st_mess->g_code = ((U16)(rec_data)) | 0x0100;
st_mess->dtr = 0;
break;
case CTX2:
st_mess->g_code = ((U16)(rec_data & 0xF0)) | 0x0100;
st_mess->dtr = rec_data & 0x0F;
break;
case CTX3:
st_mess->g_code = ((U16)(rec_data & 0xE0)) | 0x0100; // For '0xE0', verify Standard Command code List
st_mess->dtr = rec_data & 0x1F; // For '0x1F', verify Standard Command code List
break;
case CTX9:
st_mess->g_code = rec_dali;
st_mess->dtr = 0;
break;
case CTXC:
st_mess->g_code = (rec_dali & 0xFF00);
st_mess->dtr = rec_data >> 1;
break;
case CTXD:
st_mess->g_code = (rec_dali & 0xFF00);
st_mess->dtr = rec_data;
break;
default: // Ooops! Here some code is necessary
st_mess->g_code = NO_DALI_COMMAND_CODE;
st_mess->p_cc = st_mess->dtr = 0;
st_mess->status = DALI_RX_CODE_ERROR;
Dali_slave_disable();
return DALI_STATUS_ERROR;
break;
}
// Only update message structure
switch (code_type & 0xF0)
{
case CT0X: // Commands
st_mess->p_cc = 0; // Kind of reset of previous DALI Command Code
if (add_type == SHORT_ADD_TYPE) st_mess->status = DALI_RX_CODE_SHORT;
else if (add_type == GROUP_ADD_TYPE) st_mess->status = DALI_RX_CODE_GROUP;
else st_mess->status = DALI_RX_CODE_BROAD;
Dali_slave_disable();
return DALI_STATUS_COMPLETED;
break;
case CT1X: // Configuration
st_mess->p_cc = rec_dali; // Recording previous DALI Command Code
st_mess->handle = 0; // Reset Time-count
if (add_type == SHORT_ADD_TYPE) st_mess->status = DALI_RX_2ND_CODE_NEEDED_SHORT;
else if (add_type == GROUP_ADD_TYPE) st_mess->status = DALI_RX_2ND_CODE_NEEDED_GROUP;
else st_mess->status = DALI_RX_2ND_CODE_NEEDED_BROAD;
return DALI_STATUS_NOT_COMPLETED;
break;
case CT2X: // Queries
st_mess->p_cc = 0; // Kind of reset of previous DALI Command Code
st_mess->handle = 0; // Reset Time-count
if (add_type == SHORT_ADD_TYPE) st_mess->status = DALI_RX_QUERY_SHORT;
else if (add_type == GROUP_ADD_TYPE) st_mess->status = DALI_RX_QUERY_GROUP;
else st_mess->status = DALI_RX_QUERY_BROAD;
Dali_slave_disable();
return DALI_STATUS_COMPLETED;
break;
default: // Ooops! Here some code is necessary
st_mess->g_code = NO_DALI_COMMAND_CODE;
st_mess->p_cc = st_mess->dtr = 0;
st_mess->status = DALI_RX_CODE_ERROR;
Dali_slave_disable();
return DALI_STATUS_ERROR;
break;
}
// Usually, unreachable code !
Dali_slave_disable();
return DALI_STATUS_ERROR;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -