Queue initialization-general Linux technology-Linux programming and kernel information. For more information, see the following. The error is that the queue is not initialized successfully, that is, the queue is still empty after initQueue. Please take a look at the prawns. Thank you !!!
The Code is as follows:
ATcommand at_struct = {"AT + CPIN? ", 1 };
Int initQueue (sqqueue * q)
{
If (q = (sqqueue *) malloc (sizeof (sqqueue) = NULL) return 0;
Printf ("the size of q % d \ n", sizeof (q ));
Q-> front = 0;
Q-> rear = 0;
Q-> s = 0;
Printf ("% d \ n", q-> front, q-> rear );
Return 1;
}
ATcommand delete (sqqueue * q)
{
ATcommand;
If (q-> s = 0) return;
If (q-> front = q-> rear) q-> s = 0;
At = q-> atcommand [q-> front];
Q-> front = (q-> front + 1) % MAXNUM;
Return;
}
Int
Main (int argc, char * argv [])
{
Sqqueue * q_queue = NULL;
G_type_init ();
If (! G_thread_supported ())
G_thread_init (NULL );
ResponseProcess * proc = response_process_new ("/dev/ttyACM0 ");
ResponseMessage * mess;
Int I = 0, j = 0;
Struct timeval timeout;
Timeout. TV _sec = 1;
Timeout. TV _usec = 0;
If (initQueue (q_queue ))
{
Printf ("q_queue is init? % D \ n ", q_queue-> front, q_queue-> rear );
Int k = append (q_queue, at_struct );
}
Printf ("sssssssss222 \ n ");
While (1)
{
If (I % 300 = 0)
{// Struct
Response_process_terminate (proc );
Response_process_restart (proc );
}
If (! Response_process_initial_finish (proc ))
Continue;
Else
{
Response_process_input_command (proc, at_struct.At_cmd );
Select (0, NULL, & timeout );
While (! Response_process_is_empty (proc ))
{
Mess = response_process_get_message (proc );
G_print ("the message is: % s \ n", mess-> data );
G_free (mess );
J ++;
}
I ++;
If (j> 0)
{
Break;
}
}
Usleep (100000 );
}
// G_free (q_queue );
Return 0;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service