PPS的发送端实现(实例)

void Pps_Send_voicestatus_info(int data_type, int status)
{
	int fd = 0;	
	struct stat stat_buf;
	pps_encoder_t encoder;
	unsigned char ucIsPPSRunning = FALSE;
	unsigned char ucIsFileOpenSuccess = FALSE;

	/* Is PPS running? */
	if (stat("/pps", &stat_buf) != 0)
	{
#ifdef ENABLE_TPMS_POWER_DEBUG_INFO
		if (errno == ENOENT)
			printf("The PPS server isn't running.\n");
		else
			perror("stat /pps");
#endif
		ucIsPPSRunning=FALSE;
	}
	else
	{
		ucIsPPSRunning=TRUE;
		/* Create the "hmi_gauge" object (if it doesn't already exist). */
		fd = open("/pps/ncm_service/ncm_voice", O_RDWR | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO );
		if ( fd < 0 )
		{
#ifdef ENABLE_TPMS_POWER_DEBUG_INFO
			perror("Couldn't open /pps/ncm_service/ncm_voice");
#endif
			/* set flag to FALSE */
		    ucIsFileOpenSuccess=FALSE;
		}
		else
		{
			/* set flag to TRUE */
			ucIsFileOpenSuccess=TRUE;
		}
	}
	pps_encoder_initialize(&encoder, false);  						// initialise
	pps_encoder_start_object(&encoder, "@voiceinfo");  				// start object
	if(status == PPS_send_message_I)
	{
		pps_encoder_start_object(&encoder, "voicestatus");				
		pps_encoder_add_int(&encoder, "state", data_type);				
		pps_encoder_end_object(&encoder);
	}
	
	pps_encoder_end_object(&encoder);
	if(pps_encoder_buffer(&encoder) != NULL)
	{
		if((TRUE==ucIsPPSRunning) && (TRUE==ucIsFileOpenSuccess)){
			write(fd, pps_encoder_buffer(&encoder), pps_encoder_length(&encoder));  // write to file
		}
		else{
			if(FALSE==ucIsPPSRunning){
				/*check again about PPS status */
				if(stat("/pps", &stat_buf) == 0){
					ucIsPPSRunning=TRUE;
				}
			}
			else{
				if(FALSE==ucIsFileOpenSuccess){
					/* try to open file again */
					fd = open("/pps/ncm_service/ncm_voice", O_RDWR | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO );
					if(fd < 0){
						ucIsFileOpenSuccess=FALSE;
					}
					else{
						ucIsFileOpenSuccess=TRUE;
					}
				}
			}
		}
	}
	pps_encoder_cleanup(&encoder);  // cleanup
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值