⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 query.c

📁 PEAKAUDIO用于EV2板的MCU控制源码
💻 C
字号:
/*************************************************************************

	query.c

	This is the line command to handle the querys to the CobraNet Eval board.

	Line command supported: QUERY
 
	Copyright (C) 2001-2004 by Cirrus Logic Inc. All Rights Reserved
*************************************************************************/

#include <stdio.h>
#include <intrpt.h>
#include <8051.h>
#include <string.h>
#include "serial.h"
#include "cnmutil.h"
#include "command.h"
#include "test.h"
#include "error.h"
#include "command.h"
#include "audio.h"
#include "hostport.h"
#include "mib.h"
#include "mystrings.h"
#include "query.h"

extern unsigned char gSystem_Status;
extern unsigned char gWHICH_MODULE;	//defines whether CM1 or CM2 is present
void get_mute_info( void );
void get_route_info( void );
void get_gain_info( void );
void get_freq_info( void );

#define cQUERY_SYSTEM 0
#define cQUERY_HEX		1
#define cQUERY_STATUS 2
#define cQUERY_CNMUTE 3
#define cQUERY_MAC		4
#define cQUERY_DEVICE	5
#define cQUERY_HACK		6
#define cQUERY_HREQ		7
#define cQUERY_MUTE		8
#define cQUERY_ROUTE	9
#define cQUERY_GAIN		10
#define cQUERY_FREQ		11

void query_execute( unsigned char query_selection, char * string_ptr );
void get_system_info( char * string_ptr );
void get_hex_info( char * string_ptr );
void get_status( char * string_ptr );
void query_help( unsigned char detailed );
void get_CN_Version( char * string_ptr );

/*************************************************************************
*															 QUERY COMMAND														 *
*************************************************************************/
void query( char * com_arg_ptr[] );

code struct command_item_t query_command = {
	( code char * ) str_Com_query,
	( code command_function_t ) query
};

void query( char * com_arg_ptr[] )	{
	unsigned char query_ch;

	if ( com_arg_ptr[ 1 ] == NULL )		//look for the command without arguments
		query_help( cHELP_SHORT );
	else	{
		if ( *com_arg_ptr[ 1 ] == '?' )	//look for detailed help query
			query_help( cHELP_LONG );
		else	{
			query_ch = 0;
			while ( ( strCodecmp( query_arguments[ query_ch ], com_arg_ptr[ 1 ] ) ) && 
							( query_arguments[ query_ch ] != NULL ) )
				query_ch++;
			if ( query_arguments[ query_ch ] == NULL )
				printErrString( get_error_string( cERR_ARGUMENT ) );
			else
				query_execute( query_ch, com_arg_ptr[ 0 ] );
		}
	}
}

void query_execute( unsigned char query_selection, char * string_ptr )	{
		
	switch( query_selection )	{
		case cQUERY_SYSTEM:
			get_system_info( string_ptr );
			break;
		case cQUERY_HEX:
			get_hex_info( string_ptr );
			break;
		case cQUERY_STATUS:
			get_status( string_ptr );
			break;
		case cQUERY_CNMUTE:
			if ( getCN_Mute() )
				printStrCode( str_un );
			printStrCodeC( str_mute );
			break;
		case cQUERY_MAC:
			get_MAC_Address_Str( sysMACAddress_ptr, string_ptr );
			printStrCode( str_MAC );
			printStrC( string_ptr );
			break;
		case cQUERY_DEVICE:
			printStrCode( str_CM );
			if ( gWHICH_MODULE == cHOST_CM2 )
				printStrCodeC( str_Two );
			else
				printStrCodeC( str_One );
			break;
		case cQUERY_HACK:
			if ( CNMHACK )
				printStrCodeC( str_One );
			else
				printStrCodeC( str_Zero );
			break;
		case cQUERY_HREQ:
			if ( CNMHREQ )
				printStrCodeC( str_One );
			else
				printStrCodeC( str_Zero );
			break;
		case cQUERY_MUTE:
			get_mute_info();
			break;
		case cQUERY_ROUTE:
			get_route_info();
			break;
		case cQUERY_GAIN:
			get_gain_info();
			break;
		case cQUERY_FREQ:
			get_freq_info();
			break;
		default:
			break;
	};	//switch
}

void get_system_info( char * string_ptr )	{
	//just gets a load of data from the eval board and CobraNet module

	char * temp_ptr;

	get_display_string( sysDESCRIPTION_ptr, string_ptr );
	printStrCode( str_SysDescr );
	printStrC( string_ptr );

	get_display_string( sysCONTACT_ptr, string_ptr );
	printStrCode( str_Contact );
	printStrC( string_ptr );

	get_display_string( sysNAME_ptr, string_ptr );
	printStrCode( str_Name );
	printStrC( string_ptr );

	get_display_string( sysLOCATION_ptr, string_ptr );
	printStrCode( str_Location );
	printStrC( string_ptr );

	get_display_string( ifDESCRIPTION_ptr, string_ptr );
	printStrCode( str_IFDesc );
	printStrC( string_ptr );

	get_MAC_Address_Str( sysMACAddress_ptr, string_ptr );
	printStrCode( str_MAC );
	printStrC( string_ptr );

	*string_ptr = cASCII_NULL;
	get_IP_Address_Str( ipMonCurrentIP_ptr, string_ptr );
	printStrCode( str_CNIP );
	printStrC( string_ptr );

	*string_ptr = cASCII_NULL;
	get_CN_Version( string_ptr );
	printStrCode( str_CobraNet );
	printStrCode( str_Version );
	printStrC( string_ptr );

	printStrCode( str_EV2V );
	printStrCode( str_Version );
	printStrCodeC( str_Revision );	//put the MCU8051 firmware revision info

	printStrCode( str_FPGAV );
	printStrCode( str_Version );
	temp_ptr = string_ptr;
	*temp_ptr++ = *( ( char * ) cVERSIONMAJOR );
	*temp_ptr++ = '.';
	*temp_ptr++ = *( ( char * ) ( cVERSIONMAJOR + 1 ) );
	*temp_ptr++ = '.';
	*temp_ptr++ = *( ( char * ) ( cVERSIONMAJOR + 2 ) );
	*temp_ptr++ = cASCII_NULL;
	printStrC( string_ptr );

}

void get_hex_info( char * string_ptr )	{
	//get the hex switch setting

	string_ptr = long2str( ( long ) get_hex_switches( cNO_UPDATE_HEX ), 
																			cLEADING_ZEROS, cEIGHT_BYTES );
	string_ptr += 4;	//point to last four digits
	printStrCode( str_HexSwitches );
	printStrC( string_ptr );
}

void get_status( char * string_ptr )	{
	//need to know if the board is ready

	printStrCode( str_SysStatus );
	if ( !( ad_cal( cADCAL_CHECK ) ) )	{
		printStrCodeC( str_Calibrating );
		while ( ( !ad_cal( cADCAL_CHECK ) ) )
			;
		printStrCodeC( str_Ready );
	}
	else
		if ( gSystem_Status )
			printStrCodeC( str_ErrorColon );
		else
			printStrCodeC( str_Ready );
}


void get_CN_Version( char * string_ptr )	{
	//returns via string_ptr the cobranet version
	unsigned char i;
	unsigned char err = cERR_NO_ERROR;
	char * temp_char_p = string_ptr;

	for ( i = 0; i < 3; i++ )	{
		temp_char_p = long2ascii( Host_Peek( cCN_PROTOCAL_ptr + i, &err ) );
		strcat( string_ptr, temp_char_p );
		if ( i != 2 )
			strCodecat( string_ptr,str_Period );
	}
}

extern unsigned char getCN_Mute(){
	//returns the status of the CobraNet mute signal
  return( CNMMute );
}

unsigned char is_muted( unsigned char which_output )	{
  char * iMUTE_ptr = ( char * ) cDAC_MUTE_ptr;

	return ( !( ( *iMUTE_ptr & 0xFC ) & which_output ) );
}

void get_mute_info( void )	{
	unsigned char i,j;

	j = 4;
	for ( i = 0; i < 6; i++ )	{
		if ( is_muted( j ) )
			printStrCodeC( audio_outputs[ i ] );
		j <<= 1;
	}
}

void get_route_info( void )	{
  char * iROUTE_ptr = ( char * ) cSSI_REG0_ptr;
	char route_info;
	unsigned char i,j,k;

	j = 4;
	k = 0;
	for ( i = 0; i < 6; i++ )	{
		route_info = *(iROUTE_ptr + 8 * k++ ) & 0x07;
		printStrCode( audio_outputs[ cAUDIO_SSI0 + i ] );
		printStrCode( str_Arrow );
		printStrCode( audio_inputs[ route_info] );
		if ( is_muted( j ) )	{
			printStrCode( str_ColonSpace );
			printStrCodeC( str_mute );
		}
		else
			printStrCode( str_CRLF );
		j <<= 1;
		if ( i == 3 )	{
			iROUTE_ptr = ( char * ) cDAC_REG_ptr;
			k = 0;
		}
		if ( i == 4 )	{
			iROUTE_ptr = ( char * ) cAES_REG_ptr;
			k = 0;
		}
	}
}

void get_gain_info( void )	{
  char * iGAIN_ptr = ( char * ) cGAIN_ptr;
	char gain_info;

	gain_info = *iGAIN_ptr & 0x03;
	printStrCodeC( str_Gain[ gain_info ] );
}

void get_freq_info( void )	{
  char * iFREQ_ptr = ( char * ) cFREQ_ptr;
	char freq_info;

	freq_info = *iFREQ_ptr & 0x0F;
	printStrC( byte2str( freq_info ) );
}

void query_help( unsigned char detailed )	{
	printStrCodeC( query_str_help1 );
	if ( detailed )
		printStrCodeC( query_str_help2 );
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -