📄 rdcp.c
字号:
(func_id == Client_CmdSetMdInfo_Request) )
{ // Invalid State
gv_reason_code = RDCP_ERR_INVALID_STATE;
goto ErrCondition;
}
break;
case FWST_REC_TIME:
case FWST_REC_NO:
case FWST_REC_S_ON:
case FWST_REC_S_OFF:
if(((func_id > Client_Get_Info_Request) && (func_id < Client_CmdGetSchedule_Request)) ||
((func_id >= Client_CmdSetTime_Request) && (func_id <= Client_CmdRecordStart_Request)) ||
((func_id >= Client_CmdPlaySearch_Request) && (func_id <= Client_CmdPlayRewind_Request)) ||
(func_id == Client_CmdGetMdInfo_Request) ||
(func_id == Client_CmdSetMdInfo_Request) )
{ // Invalid State
gv_reason_code = RDCP_ERR_INVALID_STATE;
goto ErrCondition;
}
break;
}
/////////////////////////////////////////////////////////////////
// prepare the common field with default value
gv_txbuf[0] = PID_N; // RDCP ID
gv_txbuf[2] = func_id | 0x40;
gv_txlen = HDSZ;
if( rdcp_client_funcs[func_id] == 0 ){
gv_reason_code = RDCP_ERR_NOT_IMPLEMENTED;
goto ErrCondition;
}
// call functions corresponding to control code
ret = (*rdcp_client_funcs[func_id])();
////////////////////////////////////////////////////////////////////
// Error Condition
if(ret!=0){ // error, send Server_Denied packet
// and the reason code is in gv_reason_code
ErrCondition:
#ifdef DEBUG_RDCP_RX
printf("\n\rDenied");
#endif
gv_txbuf[0] = PID_E;
gv_txbuf[2] = func_id | 0x40;
gv_txbuf[3] = gv_reason_code;
gv_txlen = HDSZ+1;
}
////////////////////////////////////////////////////////////////////
// adjust tx length field and send responding packet
if(func_id!=Client_Close_Request)
{
gv_txbuf[1] = gv_txlen - HDSZ;
lan_send_control_packet();
}
////////////////////////////////////////////////////////////////////
// check another packets if the two or more commands arrived
if(gv_rxlen>(gv_rxbuf[FIELD_LEN]+HDSZ))
{ // more rx packets are in buffer
first_pkt_len = (gv_rxbuf[FIELD_LEN]+HDSZ);
rest_pkt_len = gv_rxlen - first_pkt_len;
#ifdef DEBUG_RDCP_CONPKT
printf("\n\rrx[%02u] " , (u16) rest_pkt_len);
#endif
// shift buffer contents
for(i=0;i<rest_pkt_len;i++)
{
gv_rxbuf[i] = gv_rxbuf[first_pkt_len+i];
#ifdef DEBUG_RDCP_CONPKT
printf("%02X ", (u16)gv_rxbuf[i]);
#endif
}
gv_rxlen -= first_pkt_len;
goto NEXT_PACKET;
}
}
//###############################################################################
//
//###############################################################################
u8 RDCP_IsSessionOpen(void)
{
return gv_rdcp_session_open;
}
//###############################################################################
//
//###############################################################################
void RDCP_control_connection_event(u8 new_state)
{
switch(new_state){
case SOCK_ESTABLISHED:
// check current state, if play or menu state then goto view mode
if( (gv_rdcp_FW_stat==FWST_PLAY) ||
(gv_rdcp_FW_stat==FWST_PAUSE) ||
(gv_rdcp_FW_stat==FWST_FF) ||
(gv_rdcp_FW_stat==FWST_VIEW) )
{
en_top();
gv_on_play_flag = 0; // Important ...
RDCP_change_fw_state(FWST_VIEW);
}
break;
case SOCK_CLOSED:
rdcp_close_all(NETWORK_BROKEN); // When the connection is broken abnormaly!
break;
default:
break;
}
}
//###############################################################################
//
//###############################################################################
void RDCP_close(u8 option)
{
rdcp_close_all(option);
}
//###############################################################################
//
//###############################################################################
void RDCP_check_fw_state(void)
{
static xdata u8 pre_state = FWST_VOID;
if(pre_state != gv_rdcp_FW_stat)
{
pre_state = gv_rdcp_FW_stat;
if(!gv_rdcp_session_open) return;
Svr_CmdNotifyState(); // Notify state-change to client
}
}
//###############################################################################
//
//###############################################################################
void RDCP_change_fw_state(u8 new_state)
{
static xdata u8 gv_rdcp_pre_FW_stat = FWST_VOID;
// figure out current state
gv_rdcp_FW_stat = new_state;
if(gv_rdcp_FW_stat != gv_rdcp_pre_FW_stat)
{
gv_rdcp_pre_FW_stat = gv_rdcp_FW_stat; // Update previous state
#ifdef DEBUG_RDCP
printf("\n\rRDCP state = [%-s]", gv_rdcp_stat_msg[ gv_rdcp_FW_stat ]);
#endif
}
}
//###############################################################################
//
//###############################################################################
u8 RDCP_audio_overwrite_condition(void)
{
if( (gv_rdcp_FW_stat == FWST_REC_TIME) || (gv_rdcp_FW_stat == FWST_REC_S_ON) )
return 1;
else
return 0;
}
//###############################################################################
//
//###############################################################################
void RDCP_check_polling(void)
{
#ifdef DEBUG_NORDCPPOLL
#else
if(!gv_rdcp_session_open) return;
// check every 1 sec
gv_rdcp_poll_live++;
if(gv_rdcp_poll_live > 10){
// DVR box did not receive poll packet, so close socket and reset
rdcp_close_all(FWST_VOID);
lan_restart();
}
#endif
}
//###############################################################################
//
//###############################################################################
void RDCP_notify(void)
{
Svr_CmdNotifyState();
}
//###############################################################################
// Reset all the condition of network function and close network
//###############################################################################
static void rdcp_open_all(void)
{
if(!gv_rdcp_session_open){
adjust_audio_frame(0);
gv_rdcp_changed_vfr = 0; // vfr is Video Frame Rate
gv_rdcp_session_open = TRUE;
gv_rdcp_poll_live = 0;
}
}
//###############################################################################
// Reset all the condition of network function and close network
//###############################################################################
static void rdcp_close_all(u8 option)
{
if(gv_rdcp_session_open){
#ifdef DEBUG_LAN_CLOSE
printf("\n\rrdcp_close_all(opt=%d)", (int)option);
#endif
// check audio interrupt and give a change to dummy write of audio 4KB
if(gv_int0_flag == HIGH)
{
gv_audio_reg_play = audioif_get_regPLAY();
if(gv_audio_reg_play&0x02)// interrupt happen just when recording mode
{
gv_int0_flag = LOW;
audioif_clear_internal_flag(0x00);
audioif_clear_interrupt();
_audioif_clear_IDE_request();
EX0 = 1;
}
}
gv_connection_closing = TRUE;
if(gv_rdcp_changed_vfr==0){// not changed by pc client, so
adjust_audio_frame(1); // recover the previous frame rate
}
gv_rdcp_changed_vfr = 0;
audioif_reset();
if(option==USER_INTERRUPT)
Svr_CmdClose_Request();
//=======================================
gv_rdcp_session_open = FALSE;
//=======================================
lan_close(CONN_CONTROL);
lan_close(CONN_VIDEO);
if( (gv_rdcp_FW_stat==FWST_PLAY) ||
(gv_rdcp_FW_stat==FWST_PAUSE) ||
(gv_rdcp_FW_stat==FWST_FF) ||
(gv_rdcp_FW_stat==FWST_VIEW) )
{
en_top();
RDCP_change_fw_state(FWST_VIEW);
}
gv_on_play_flag = 0; // Important ...
}
}
//###############################################################################
//
//###############################################################################
static u8 Svr_CmdClose_Request(void)
{
if(!gv_rdcp_session_open) return 1;
gv_txbuf[0] = PID_N;
gv_txbuf[1] = 0x00; // length
gv_txbuf[2] = Server_Close_Request; // code
gv_txlen = HDSZ;
lan_send_control_packet();
}
//###############################################################################
// Tx payload : [State] : Bit0~2: ff_mode, Bit3~7:F/W State
// [Current View Channel] : Bit3->CH1, Bit2->CH2,.. 0x10:Quad channel view
// [Video Channel Info.] : REC/VIEW mode : Input Video Channel Info (10->Quad, 08->ch1, 04->ch2,..)
// : PLAY mode : 4K Header's channel info Quad is 0x10
//###############################################################################
static u8 Svr_CmdNotifyState(void)
{
if(!gv_rdcp_session_open) return 1;
gv_txbuf2[0] = PID_N;
gv_txbuf2[1] = 3; // length
gv_txbuf2[2] = Server_NotifyState; // code
gv_txlen2 = HDSZ;
_fill_state(gv_txbuf2, &gv_txlen2);
lan_send_control_packet2();
return 0;
}
//###############################################################################
//
//###############################################################################
static void _fill_state(u8* txpkt, u16* txlen)
{
// firmware state
txpkt[HDSZ] = gv_ff_mode | ((gv_rdcp_FW_stat&0x1f)<<3);
// current view channel information
if(gv_Current_Channel==4) // quad
txpkt[HDSZ+1] = 0x10;
else
txpkt[HDSZ+1] = 0x08>>gv_Current_Channel;
if( (gv_rdcp_FW_stat==FWST_PLAY)||
(gv_rdcp_FW_stat==FWST_PAUSE)||
(gv_rdcp_FW_stat==FWST_FF) )
{
// Video Channel Information
txpkt[HDSZ+2] = (gv_temp_CAMERA_OF_RECORD==0x1f) ? 0x10 : gv_temp_CAMERA_OF_RECORD;
}
else // View or Recording mode
{
txpkt[HDSZ+2] = (Val_EPROM_EACH_QUAD) ? 0x10 : Val_EPROM_CAMERA_OF_SET;
}
*txlen = *txlen + 3;
}
//###############################################################################
// Rx payload : password (6 bytes)
//###############################################################################
static u8 Proc_Open_Request(void)
{
u8 i;
if((EPROM_SetUp_data_Read(EPROM_NET_ATTRIB)&0x01)==0x00){ // not allowed to network connection
gv_reason_code = RDCP_ERR_NOT_ALLOWED;
return 1;
}
if(gv_rdcp_session_open){
gv_reason_code = RDCP_ERR_NOT_ALLOWED;
return 2;
}
// check password
for(i=0;i<6;i++){
if(EPROM_SetUp_data_Read(EPROM_PASSWORD_BASE + i) != gv_rxbuf[HDSZ+i])
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -