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

📄 hmi.c

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

	hmi.c

	This file contains the HMI peek and poke command line routines. These
	are the main routines for examining and writing to CobraNet memory.
	
	Supported line commands: PEEK, POKE

	Copyright (C) 2001-2004 by Cirrus Logic Inc. All Rights Reserved
*************************************************************************/

#include <8051.h>
#include <intrpt.h>
#include <conio.h>
#include <string.h>
#include "serial.h"
#include "command.h"
#include "error.h"
#include "hostport.h"
#include "cnmutil.h"
#include "test.h"
#include "cnmibvar.h"
#include "mib.h"
#include "mystrings.h"
#include "hmi.h"

void peek( char * com_arg_ptr[] );
void poke( char * com_arg_ptr[] );

void peek_help( unsigned char detailed );
void poke_help( unsigned char detailed );
char mibvar_in_list( char * the_string_ptr );
void peek_do_mib_var( char the_index, char * com_arg_ptr[] );
void poke_do_mib_var( char the_index, char * com_arg_ptr[] );

extern unsigned char gWHICH_MODULE;

#define cERR_TARGET				1
#define cERR_VALUE				2
#define cERR_PEEK					3
#define cERR_POKE					4
#define cERR_COUNT				5
#define cERR_NOT_IN_RANGE	6

//define errors
code char * get_hmi_error_string( char error_number )	{
	static code char * code cmnd_arg_error[] = {
		noErrorStr,
		hmi_Str1,
		str_err_BadValue,
		hmi_Str3,
		hmi_Str4,
		hmi_Str5,
		errorStr8
	};

	return( cmnd_arg_error[ error_number ] );
}

char mibvar_in_list( char * the_string_ptr )	{
//checks if input parameter is a MIB symbol, see cnmibvar.h for the list
	char i = 0;
	char j;
	char found_it = 0;

	while( cn_mib_var[ i ].mib_name_ptr != NULL )	{
		cn_mib_var[ i ] = cn_mib_var[ i ];
		j = 0;
		while ( cn_mib_var[ i ].mib_name_ptr[ j ] == the_string_ptr[ j ] )
			if ( the_string_ptr[ j++ ] == cASCII_NULL )
				found_it = 1;
		if ( found_it )
			return( i + 1 );
		else
			i++;
	}
	return ( 0 );
}

/*************************************************************************
*																PEEK COMMAND														 *
*************************************************************************/
code struct command_item_t peek_command = {
	( code char * ) str_Com_peek,
	( code command_function_t ) peek
};

void peek( char * com_arg_ptr[] )	{
	unsigned long addr, peek_value;
	char * local_ptr;
  unsigned char error_code = cERR_NO_ERROR;
	unsigned char count;

	if ( com_arg_ptr[ 1 ] == NULL )	//look for the command without arguments
		peek_help( cHELP_SHORT );
	else	{
		if ( *com_arg_ptr[ 1 ] == '?' )	//help command
			peek_help( cHELP_LONG );
		else	{
			if ( count = mibvar_in_list( com_arg_ptr[ 1 ] ) )
				if ( com_arg_ptr[ 2 ] != NULL )
					if (  error_code = validate_hex_string( com_arg_ptr[ 2 ], 
								c4_HEX_CHAR ) )
						printTwoErrorString( get_hmi_error_string( cERR_VALUE ),
																 get_error_string( error_code ) );
					else
						peek_do_mib_var( count - 1, com_arg_ptr );
				else
					peek_do_mib_var( count - 1, com_arg_ptr );
			else
				if (  error_code = validate_hex_string( com_arg_ptr[ 1 ], 
							c6_HEX_CHAR ) )
					printTwoErrorString( get_hmi_error_string( cERR_TARGET ),
															 get_error_string( error_code ) );
				else	{
					local_ptr = com_arg_ptr[ 1 ] + 2;
					addr = str2Long( local_ptr );

					peek_value = Host_Peek( addr, &error_code );
					if ( error_code )	{
						printTwoErrorString( get_hmi_error_string ( cERR_PEEK ),
																 get_host_error( error_code ) );
					}
					else	{
						printStrCode( str_HexPrefix );
						printStrC( long2str( peek_value, 
												cNO_LEADING_ZEROS, cSIX_BYTES + ( gWHICH_MODULE & 2 ) ) );
					}
				}
		}
	}
}

void peek_do_mib_var( char the_index, char * com_arg_ptr[] )	{
//this routine executes the peek with a MIB variable as a parameter.
	unsigned char i;
	short temp_short = 0;
	long temp_long;
	unsigned char str_byte_len = cSIX_BYTES;
	char if_hex = 1;
	unsigned char err = cERR_NO_ERROR;
	char * the_string = com_arg_ptr[0];
	struct mib_var_struct mib_struct_ptr;

	mib_struct_ptr = cn_mib_var[ the_index ];	//point to the mib struct
	i = mib_struct_ptr.mib_type;
	if ( gWHICH_MODULE == cHOST_CM2 )
		str_byte_len = cEIGHT_BYTES;

	if ( ( gWHICH_MODULE == cHOST_CM2 ) && ( ( i == cMIB_TYPE_COUNTER2 ) || 
																					( i == cMIB_TYPE_INTEGER48 ) ) )
		i = cMIB_TYPE_INTEGER;//variations on the type w/respect to module type.

	if ( com_arg_ptr[ 2 ] != NULL )
		temp_short = str2Long( com_arg_ptr[ 2 ] + 2 );	//this is the offset
	temp_long = mib_struct_ptr.mib_address + temp_short;//add offset if any.
	switch ( i ) {	//executes based on the MIB type.
		case cMIB_TYPE_DISPLAY_STR :
			get_display_string( temp_long, the_string );
			if_hex = 0;
			break;
		case cMIB_TYPE_OBJECT_ID :
			get_object_ID_string( temp_long, the_string );
			break;
		case cMIB_TYPE_IPADDRESS :
			get_IP_Address_Str( temp_long, the_string );
			if_hex = 0;
			break;
		case cMIB_TYPE_PHYSADDRESS :
			get_MAC_Address_Str( temp_long, the_string );
			break;
		case cMIB_TYPE_TIMETICKS :
			get_TimeTicks_Str( temp_long, the_string );
			break;
		case cMIB_TYPE_INTEGER :
		case cMIB_TYPE_COUNTER :
			temp_long = Host_Peek( temp_long , &err );
			strcpy( the_string, long2str( temp_long, cNO_LEADING_ZEROS, str_byte_len ) );
			break;
		case cMIB_TYPE_INTEGER48 :
		case cMIB_TYPE_COUNTER2 :
			get_Integer48_Str( temp_long, the_string );
			break;
		case cMIB_TYPE_INTEGER16 :
			temp_short = get_Integer16( temp_long );
			strcpy( the_string, long2str( ( long ) temp_short, cNO_LEADING_ZEROS, cFOUR_BYTES ) );
			break;
		default :
			break;
	}
	if ( ( if_hex ) && ( *the_string != cASCII_NULL ) )
		printStrCode( str_HexPrefix );
	if ( *the_string != cASCII_NULL )
		printStrC( the_string );
}



void peek_help( unsigned char detailed )	{
	printStrCodeC( peek_str_help1 );
	if ( detailed )
		printStrCodeC( peek_str_help2 );
}

/*************************************************************************
*																POKE COMMAND														 *
*************************************************************************/
code struct command_item_t poke_command = {
	( code char * ) str_Com_poke,
	( code command_function_t ) poke
};

void poke( char * com_arg_ptr[] )	{
	unsigned long addr, poke_value;
	char * local_ptr;
	unsigned char count;
  unsigned char error_code = cERR_NO_ERROR;

	if ( com_arg_ptr[ 1 ] == NULL )	//look for the command without arguments
		poke_help( cHELP_SHORT );
	else	{
		if ( *com_arg_ptr[ 1 ] == '?' )
			poke_help( cHELP_LONG );
		else	{
			if ( count = mibvar_in_list( com_arg_ptr[ 1 ] ) )
				if ( ( cn_mib_var[ count - 1 ].mib_type == cMIB_TYPE_DISPLAY_STR ) ||
							( cn_mib_var[ count - 1 ].mib_type == cMIB_TYPE_IPADDRESS ) )
					poke_do_mib_var( count - 1, com_arg_ptr );
				else	{
					if ( error_code = validate_hex_string( com_arg_ptr[ 2 ], c6_HEX_CHAR + ( gWHICH_MODULE & cHOST_CM2 ) ) )
						printTwoErrorString( get_hmi_error_string( cERR_VALUE ),
																 get_error_string( error_code ) );
					else
						if ( com_arg_ptr[ 3 ] != NULL )
							if ( ( error_code = validate_hex_string( com_arg_ptr[ 3 ], c4_HEX_CHAR ) ) &&
									 ( cn_mib_var[ count - 1 ].mib_type != cMIB_TYPE_IPADDRESS ) )
								printTwoErrorString( get_hmi_error_string( cERR_VALUE ),
																		 get_error_string( error_code ) );
							else
								poke_do_mib_var( count - 1, com_arg_ptr );
						else
							poke_do_mib_var( count - 1, com_arg_ptr );
				}
			else
				if (  error_code = validate_hex_string( com_arg_ptr[ 1 ], c6_HEX_CHAR + ( gWHICH_MODULE & cHOST_CM2 ) ) )
					printTwoErrorString( get_hmi_error_string( cERR_TARGET ),
															 get_error_string( error_code ) );
				else	{
					if ( com_arg_ptr[ 2 ] == NULL )
						printErrString( get_error_string( cERR_MISSING_ARG ) );
					else	{
						if (  error_code = validate_hex_string( com_arg_ptr[ 2 ], c6_HEX_CHAR + ( gWHICH_MODULE & cHOST_CM2 ) ) )
							printTwoErrorString( get_hmi_error_string( cERR_VALUE ),
																	 get_error_string( error_code ) );
						else	{
							local_ptr = com_arg_ptr[ 1 ] + 2;
							addr = str2Long( local_ptr );
							local_ptr = com_arg_ptr[ 2 ] + 2;
							poke_value = str2Long( local_ptr );
							error_code = Host_Poke( addr, poke_value );
							if ( error_code )
								printTwoErrorString( get_hmi_error_string ( cERR_POKE ),
																		 get_host_error( error_code ) );
						}
					}
				}
		}
	}
}

void poke_do_mib_var( char the_index, char * com_arg_ptr[] )	{
//this routine executes the poke with a MIB variable as a parameter.
	char i;
	short temp_offset = 0;
	unsigned long temp_long;
	unsigned char err = cERR_NO_ERROR;
	struct mib_var_struct mib_struct_ptr;

	mib_struct_ptr = cn_mib_var[ the_index ];
	if ( com_arg_ptr[ 3 ] != NULL )	//this is the offset parameter
		temp_offset = str2Long( com_arg_ptr[ 3 ] + 2 );
	temp_long = mib_struct_ptr.mib_address + temp_offset;	//add offset.

	i = mib_struct_ptr.mib_type;

	if ( ( gWHICH_MODULE == cHOST_CM2 ) && ( ( i == cMIB_TYPE_COUNTER2 ) || 
																				( i == cMIB_TYPE_INTEGER48 ) ) )
	i = cMIB_TYPE_INTEGER;
	switch ( i ) {	//executes based on the MIB type.
		case cMIB_TYPE_DISPLAY_STR :
			make_arg_string( com_arg_ptr, 2 );
			put_display_string( temp_long, com_arg_ptr[ 2 ] );
			break;
		//case cMIB_TYPE_OBJECT_ID :
			//no writable variables at this time
		//	break;
		case cMIB_TYPE_IPADDRESS :
			if ( err = validate_ip_string( com_arg_ptr[ 2 ] ) )
				printTwoErrorString( get_hmi_error_string( cERR_VALUE ),
														 get_error_string( err ) );
			else
				put_IP_Address_Str( temp_long, com_arg_ptr[ 2 ] );
			break;
		case cMIB_TYPE_PHYSADDRESS :
			put_MAC_Address_Str( temp_long, com_arg_ptr[ 2 ] );
			break;
		//case cMIB_TYPE_TIMETICKS :
			//no writable variables at this time;
		//	break;
		case cMIB_TYPE_INTEGER :
		case cMIB_TYPE_COUNTER :
			err = Host_Poke( temp_long, str2Long( com_arg_ptr[ 2 ] + 2 ) );
			break;
		case cMIB_TYPE_INTEGER48 :
		case cMIB_TYPE_COUNTER2 :
			put_Integer48_Str( temp_long, ( com_arg_ptr[ 2 ] + 2 ) );
			break;
		case cMIB_TYPE_INTEGER16 :
				set_Integer16( temp_long, ( short ) str2Long( com_arg_ptr[ 2 ] + 2 ) );
			break;
		default :
			break;
	}
}

void poke_help( unsigned char detailed )	{
	printStrCodeC( poke_str_help1 );
	if ( detailed )
		printStrCodeC( poke_str_help2 );
}

⌨️ 快捷键说明

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