develop/Logical/Libraries/ac_invlib/ac_invparameter.c
void write_parameterlist( ac_inv_AxIdent *ax_ident )
{
	char tempstring[80];
	char *source, *dest;
	int i;

	switch( ax_ident->write_parameterlist_step )
	{
	case 0:
		break;

	case 1: /* download started - write header to log */
		if( ax_ident->p_alloc->pcfgpar[0] || ax_ident->p_alloc->pcfgpar[1] || ax_ident->p_alloc->pcfgpar[2] )
		{
			ax_ident->parameterlist_index = 0;
			ax_ident->sdo_write_status = 0; /* clear last SDO write error */
			strcpy( ax_ident->log_info, ax_ident->interface );
			strcat( ax_ident->log_info, "." );
			m_ltoa( ax_ident->node_number, tempstring, 10 );
			strcat( ax_ident->log_info, tempstring );
			strcat( ax_ident->log_info, " download " );
			for( i = 0; i < 3; ++i )
			{
				if( ax_ident->p_alloc->pcfgpar[i] )
				{
					strcat( ax_ident->log_info, " \"" );
					strcat( ax_ident->log_info, (char*)	ax_ident->p_alloc->pcfgpar[i] );
					strcat( ax_ident->log_info, "\" " );
				}
			}
			ax_ident->fub_log_write.logLevel = arlogLEVEL_INFO;
			ax_ident->fub_log_write.errornr = 0;
			ax_ident->fub_log_write.mem = (UDINT) &ax_ident->node_number;
			ax_ident->fub_log_write.len = sizeof(ax_ident->node_number);
			ax_ident->fub_log_write.asciiString = (UDINT) ax_ident->log_info;
			AsArLogWrite( &ax_ident->fub_log_write );
			ax_ident->write_parameterlist_step	= 2;
		}
		else
		{
			ax_ident->write_parameterlist_step	= 0;
		}
		break;


	case 2:  /* wait until log entry written */
		if( ax_ident->fub_log_write.status == 0 )
		{
			ax_ident->write_parameterlist_step = 3;
		}
		else if( ax_ident->fub_log_write.status != 65535 )  /* error */
		{
			ax_ident->write_parameterlist_step = 0;
		}
		else
		{
			AsArLogWrite( &ax_ident->fub_log_write );
		}
		break;


	case 3: /* read next row */
		if( ax_ident->sdo_write_step == 0 )   /* service channel free ? */
		{
			source = (char*) ax_ident->p_sorted_parameters[ax_ident->parameterlist_index];
			dest = tempstring;
			memset( tempstring, 0, sizeof(tempstring) );
			if( ax_ident->sdo_write_status != 0 )  /* error after writing the last parameter */
			{
				ax_ident->write_parameterlist_status = ax_ident->sdo_write_status;
				ax_ident->write_parameterlist_step = 0;
				break;
			}
			else if( ax_ident->parameterlist_index >= ax_ident->number_of_parameters )  /* end of list */
			{
				strcpy( ax_ident->log_info, ax_ident->interface );
				strcat( ax_ident->log_info, "." );
				m_ltoa( ax_ident->node_number, tempstring, 10 );
				strcat( ax_ident->log_info, tempstring );
				strcat( ax_ident->log_info, " end of " );
				for( i = 0; i < 3; ++i )
				{
					if( ax_ident->p_alloc->pcfgpar[i] )
					{
						strcat( ax_ident->log_info, " \"" );
						strcat( ax_ident->log_info, (char*)	ax_ident->p_alloc->pcfgpar[i] );
						strcat( ax_ident->log_info, "\" " );
					}
				}
				ax_ident->fub_log_write.logLevel = arlogLEVEL_INFO;
				ax_ident->fub_log_write.errornr = 0;
				ax_ident->fub_log_write.mem = (UDINT) &ax_ident->node_number;
				ax_ident->fub_log_write.len = sizeof(ax_ident->node_number);
				ax_ident->fub_log_write.asciiString = (UDINT) ax_ident->log_info;
				AsArLogWrite( &ax_ident->fub_log_write );
				ax_ident->write_parameterlist_step	= 4;
				break;
			}
			else
			{
				while( ax_ident->parameterlist_index < ax_ident->number_of_parameters )
				{
					if( *source == 0 )   /* end of a row ? */
					{
						strncpy( ax_ident->sdo_write_value_constant, tempstring, sizeof(ax_ident->sdo_write_value_constant) - 1 );
						ax_ident->sdo_write_step = 1;  /* write parameter to inverter */
						++ax_ident->parameterlist_index;
						break;
					}
					else if( !isprint(*source) || *source == ' ' )   /* ignore control chars and spaces */
					{
						++source;
					}
					else if( *source == '=' )
					{
						++source;
						strncpy( ax_ident->sdo_write_par_name, tempstring, sizeof(ax_ident->sdo_write_par_name) - 1 );
						memset( tempstring, 0, sizeof(tempstring) );
						dest = tempstring;
					}
					else
					{
						*dest++ = *source++; /* copy to tempstring */
					}
				}
			}
		}
		break;


	case 4: /* wait until tail is written */
		if( ax_ident->fub_log_write.status != 65535 )
		{
			ax_ident->write_parameterlist_step = 0;
		}
		else
		{
			AsArLogWrite( &ax_ident->fub_log_write );
		}
		break;






	}


}
/* -------------------------------------------------------------------------------------
   write parameter from parameter list to inverter
   -------------------------------------------------------------------------------------
*/
write parameter from parameter list to inverter
write parameter from parameter list to inverter
void write_parameterlist( ac_inv_AxIdent *ax_ident )
{
	char tempstring[80];
	char *source, *dest;
	int i;
	switch( ax_ident->write_parameterlist_step )
	{
	case 0:
		break;
	case 1: 
		if( ax_ident->p_alloc->pcfgpar[0] || ax_ident->p_alloc->pcfgpar[1] || ax_ident->p_alloc->pcfgpar[2] )
		{
			ax_ident->parameterlist_index = 0;
			ax_ident->sdo_write_status = 0; 
			strcpy( ax_ident->log_info, ax_ident->interface );
			strcat( ax_ident->log_info, "." );
			m_ltoa( ax_ident->node_number, tempstring, 10 );
			strcat( ax_ident->log_info, tempstring );
			strcat( ax_ident->log_info, " download " );
			for( i = 0; i < 3; ++i )
			{
				if( ax_ident->p_alloc->pcfgpar[i] )
				{
					strcat( ax_ident->log_info, " \"" );
					strcat( ax_ident->log_info, (char*)	ax_ident->p_alloc->pcfgpar[i] );
					strcat( ax_ident->log_info, "\" " );
				}
			}
			ax_ident->fub_log_write.logLevel = arlogLEVEL_INFO;
			ax_ident->fub_log_write.errornr = 0;
			ax_ident->fub_log_write.mem = (UDINT) &ax_ident->node_number;
			ax_ident->fub_log_write.len = sizeof(ax_ident->node_number);
			ax_ident->fub_log_write.asciiString = (UDINT) ax_ident->log_info;
			AsArLogWrite( &ax_ident->fub_log_write );
			ax_ident->write_parameterlist_step	= 2;
		}
		else
		{
			ax_ident->write_parameterlist_step	= 0;
		}
		break;
	case 2:  
		if( ax_ident->fub_log_write.status == 0 )
		{
			ax_ident->write_parameterlist_step = 3;
		}
		else if( ax_ident->fub_log_write.status != 65535 )  
		{
			ax_ident->write_parameterlist_step = 0;
		}
		else
		{
			AsArLogWrite( &ax_ident->fub_log_write );
		}
		break;
	case 3: 
		if( ax_ident->sdo_write_step == 0 )   
		{
			source = (char*) ax_ident->p_sorted_parameters[ax_ident->parameterlist_index];
			dest = tempstring;
			memset( tempstring, 0, sizeof(tempstring) );
			if( ax_ident->sdo_write_status != 0 )  
			{
				ax_ident->write_parameterlist_status = ax_ident->sdo_write_status;
				ax_ident->write_parameterlist_step = 0;
				break;
			}
			else if( ax_ident->parameterlist_index >= ax_ident->number_of_parameters )  
			{
				strcpy( ax_ident->log_info, ax_ident->interface );
				strcat( ax_ident->log_info, "." );
				m_ltoa( ax_ident->node_number, tempstring, 10 );
				strcat( ax_ident->log_info, tempstring );
				strcat( ax_ident->log_info, " end of " );
				for( i = 0; i < 3; ++i )
				{
					if( ax_ident->p_alloc->pcfgpar[i] )
					{
						strcat( ax_ident->log_info, " \"" );
						strcat( ax_ident->log_info, (char*)	ax_ident->p_alloc->pcfgpar[i] );
						strcat( ax_ident->log_info, "\" " );
					}
				}
				ax_ident->fub_log_write.logLevel = arlogLEVEL_INFO;
				ax_ident->fub_log_write.errornr = 0;
				ax_ident->fub_log_write.mem = (UDINT) &ax_ident->node_number;
				ax_ident->fub_log_write.len = sizeof(ax_ident->node_number);
				ax_ident->fub_log_write.asciiString = (UDINT) ax_ident->log_info;
				AsArLogWrite( &ax_ident->fub_log_write );
				ax_ident->write_parameterlist_step	= 4;
				break;
			}
			else
			{
				while( ax_ident->parameterlist_index < ax_ident->number_of_parameters )
				{
					if( *source == 0 )   
					{
						strncpy( ax_ident->sdo_write_value_constant, tempstring, sizeof(ax_ident->sdo_write_value_constant) - 1 );
						ax_ident->sdo_write_step = 1;  
						++ax_ident->parameterlist_index;
						break;
					}
					else if( !isprint(*source) || *source == ' ' )   
					{
						++source;
					}
					else if( *source == '=' )
					{
						++source;
						strncpy( ax_ident->sdo_write_par_name, tempstring, sizeof(ax_ident->sdo_write_par_name) - 1 );
						memset( tempstring, 0, sizeof(tempstring) );
						dest = tempstring;
					}
					else
					{
						*dest++ = *source++; 
					}
				}
			}
		}
		break;
	case 4: 
		if( ax_ident->fub_log_write.status != 65535 )
		{
			ax_ident->write_parameterlist_step = 0;
		}
		else
		{
			AsArLogWrite( &ax_ident->fub_log_write );
		}
		break;
	}
}
void write_parameterlist ( ac_inv_AxIdent * ax_ident ) { char tempstring [ 80 ] ; char * source , * dest ; int i ; switch ( ax_ident -> write_parameterlist_step ) { case 0 : break ; case 1 : if ( ax_ident -> p_alloc -> pcfgpar [ 0 ] || ax_ident -> p_alloc -> pcfgpar [ 1 ] || ax_ident -> p_alloc -> pcfgpar [ 2 ] ) { ax_ident -> parameterlist_index = 0 ; ax_ident -> sdo_write_status = 0 ; strcpy ( ax_ident -> log_info , ax_ident -> interface ) ; strcat ( ax_ident -> log_info , " " ) ; m_ltoa ( ax_ident -> node_number , tempstring , 10 ) ; strcat ( ax_ident -> log_info , tempstring ) ; strcat ( ax_ident -> log_info , " " ) ; for ( i = 0 ; i < 3 ; ++ i ) { if ( ax_ident -> p_alloc -> pcfgpar [ i ] ) { strcat ( ax_ident -> log_info , " \" " ) ; strcat ( ax_ident -> log_info , ( char * ) ax_ident -> p_alloc -> pcfgpar [ i ] ) ; strcat ( ax_ident -> log_info , " \" " ) ; } } ax_ident -> fub_log_write . logLevel = arlogLEVEL_INFO ; ax_ident -> fub_log_write . errornr = 0 ; ax_ident -> fub_log_write . mem = ( UDINT ) & ax_ident -> node_number ; ax_ident -> fub_log_write . len = sizeof ( ax_ident -> node_number ) ; ax_ident -> fub_log_write . asciiString = ( UDINT ) ax_ident -> log_info ; AsArLogWrite ( & ax_ident -> fub_log_write ) ; ax_ident -> write_parameterlist_step = 2 ; } else { ax_ident -> write_parameterlist_step = 0 ; } break ; case 2 : if ( ax_ident -> fub_log_write . status == 0 ) { ax_ident -> write_parameterlist_step = 3 ; } else if ( ax_ident -> fub_log_write . status != 65535 ) { ax_ident -> write_parameterlist_step = 0 ; } else { AsArLogWrite ( & ax_ident -> fub_log_write ) ; } break ; case 3 : if ( ax_ident -> sdo_write_step == 0 ) { source = ( char * ) ax_ident -> p_sorted_parameters [ ax_ident -> parameterlist_index ] ; dest = tempstring ; memset ( tempstring , 0 , sizeof ( tempstring ) ) ; if ( ax_ident -> sdo_write_status != 0 ) { ax_ident -> write_parameterlist_status = ax_ident -> sdo_write_status ; ax_ident -> write_parameterlist_step = 0 ; break ; } else if ( ax_ident -> parameterlist_index >= ax_ident -> number_of_parameters ) { strcpy ( ax_ident -> log_info , ax_ident -> interface ) ; strcat ( ax_ident -> log_info , " " ) ; m_ltoa ( ax_ident -> node_number , tempstring , 10 ) ; strcat ( ax_ident -> log_info , tempstring ) ; strcat ( ax_ident -> log_info , " " ) ; for ( i = 0 ; i < 3 ; ++ i ) { if ( ax_ident -> p_alloc -> pcfgpar [ i ] ) { strcat ( ax_ident -> log_info , " \" " ) ; strcat ( ax_ident -> log_info , ( char * ) ax_ident -> p_alloc -> pcfgpar [ i ] ) ; strcat ( ax_ident -> log_info , " \" " ) ; } } ax_ident -> fub_log_write . logLevel = arlogLEVEL_INFO ; ax_ident -> fub_log_write . errornr = 0 ; ax_ident -> fub_log_write . mem = ( UDINT ) & ax_ident -> node_number ; ax_ident -> fub_log_write . len = sizeof ( ax_ident -> node_number ) ; ax_ident -> fub_log_write . asciiString = ( UDINT ) ax_ident -> log_info ; AsArLogWrite ( & ax_ident -> fub_log_write ) ; ax_ident -> write_parameterlist_step = 4 ; break ; } else { while ( ax_ident -> parameterlist_index < ax_ident -> number_of_parameters ) { if ( * source == 0 ) { strncpy ( ax_ident -> sdo_write_value_constant , tempstring , sizeof ( ax_ident -> sdo_write_value_constant ) - 1 ) ; ax_ident -> sdo_write_step = 1 ; ++ ax_ident -> parameterlist_index ; break ; } else if ( ! isprint ( * source ) || * source == ' ' ) { ++ source ; } else if ( * source == ' ' ) { ++ source ; strncpy ( ax_ident -> sdo_write_par_name , tempstring , sizeof ( ax_ident -> sdo_write_par_name ) - 1 ) ; memset ( tempstring , 0 , sizeof ( tempstring ) ) ; dest = tempstring ; } else { * dest ++ = * source ++ ; } } } } break ; case 4 : if ( ax_ident -> fub_log_write . status != 65535 ) { ax_ident -> write_parameterlist_step = 0 ; } else { AsArLogWrite ( & ax_ident -> fub_log_write ) ; } break ; } }
write parameter from parameter list to inverter
write parameter from parameter list to inverter
/* download started - write header to log */ /* clear last SDO write error */ /* wait until log entry written */ /* error */ /* read next row */ /* service channel free ? */ /* error after writing the last parameter */ /* end of list */ /* end of a row ? */ /* write parameter to inverter */ /* ignore control chars and spaces */ /* copy to tempstring */ /* wait until tail is written */