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
}