Пример #1
0
/*!
 * @brief  Clears the display.
 *
 * The display is also cleared by the driver before displaying the newly given string. 
 * So it is not required for the application to use this API to clear the measurement 
 * display before displaying the new string. This API can be useful to turn off the display.
 *   
 * @param[in]   hDevice     Device handle obtained from adi_LCD_Init().
 * @param[in]   Screen      LCD screen on which to clear the mesurement display.
  *
 * @return      Status
 *                - #ADI_LCDVIM828_ERR_BAD_DEVICE_HANDLE [D]  Invalid device handle parameter.
 *                - #ADI_LCDVIM828_ERR_NOT_INITIALIZED   [D]  Device has not been previously configured for use.
 *                - #ADI_LCDVIM828_SUCCESS                    Call completed successfully.
 *
 * @sa adi_LCDVIM828_DisplayMeasurement()
 */
ADI_LCDVIM828_RESULT_TYPE adi_LCDVIM828_ClearDisplay(ADI_LCD_DEV_HANDLE const   hDevice, 
                                                     ADI_LCD_SCREEN_TYPE const  Screen)
{
    return(ClearChars(hDevice, Screen, SegmentRegInfo, ADI_LCDVIM828_NUM_SEGMENTS));
}
int EncodeMpiBuff(void* values, MPI_Datatype datatype, int count, 
		 char* sohReplace, char* partitionReplace, char* eotReplace, charList* result)
{
  //flag indicating if any characters where encoded
  int encoded = FALSE;
  
	
	//create a temporary buffer which will be resused to encode the buffer
  charList* tempBuffer = (charList*)malloc(sizeof(charList));;
  InitializeCharList(tempBuffer);

  //Createa string versions of the values to encode
  char* soh = (char*)malloc(2*sizeof(char));
	soh[0] = SOH;
	soh[1] = '\0';

	char* partition = (char*)malloc(2*sizeof(char));
	partition[0] = PARTITION_CHR;
	partition[1] = '\0';	
	
	char* eot = (char*)malloc(2*sizeof(char));
	eot[0] = EOT;
	eot[1] = '\0';

	//Send back the code to decode on the client side	
	char encodeKeys[255];
	memset(encodeKeys, '\0', 255);
			
	int encodeKeyLen = sprintf(encodeKeys, "%c%s%c%s%c%s", PARTITION_CHR, sohReplace, 
			PARTITION_CHR, partitionReplace, PARTITION_CHR, eotReplace);
	AddChars(result, encodeKeys, encodeKeyLen);
	
  int i = 0;	
  for(i=0; i < count; i++)
  {
    char *value;

    int length = 0;
    if(datatype == MPI_CHAR){
      length = asprintf(&value, "%c", ((char*)values)[i]);    
    } else if(datatype == MPI_BYTE || datatype == MPI_UNSIGNED_CHAR){
      length = asprintf(&value, "%c", ((unsigned char*)values)[i]);    
    } else if(datatype == MPI_SHORT){
      length = asprintf(&value, "%hi", ((short*)values)[i]);    
    } else if(datatype == MPI_INT){
      length = asprintf(&value, "%d", ((int*)values)[i]);    
    } else if(datatype == MPI_LONG){
      length = asprintf(&value, "%ld", ((long int*)values)[i]);    
    } else if(datatype == MPI_FLOAT){  
      length = asprintf(&value, "%f", ((float*)values)[i]);
    } else if(datatype == MPI_DOUBLE){
      length = asprintf(&value, "%f", ((double*)values)[i]);  
    } else if(datatype == MPI_UNSIGNED_SHORT){
      length = asprintf(&value, "%hu", ((unsigned short*)values)[i]);   
    } else if(datatype == MPI_UNSIGNED){
      length = asprintf(&value, "%u", ((unsigned int*)values)[i]);   
    } else if(datatype == MPI_UNSIGNED_LONG){
      length = asprintf(&value, "%lu", ((unsigned long*)values)[i]);   
    } else if(datatype == MPI_LONG_DOUBLE){
      length = asprintf(&value, "%Lf", ((long double*)values)[i]);
    }

   	AddChars(tempBuffer, value, length);
    free(value);
    
		if(ReplaceChars(tempBuffer, soh, sohReplace) == TRUE)
			encoded = TRUE;
	
		if(ReplaceChars(tempBuffer, partition, partitionReplace) == TRUE)
			encoded = TRUE;

		if(ReplaceChars(tempBuffer, eot, eotReplace) == TRUE)
			encoded = TRUE;
  
  	AddChars(result, PARTITION_STR, 1);				
		AddChars(result, tempBuffer->Items, tempBuffer->ItemCount);
	
		ClearChars(tempBuffer);
  }
	
	free(soh);
	free(partition);
	free(eot);

	CleanUpCharList(tempBuffer);
	
	return encoded;
}