473,657 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FIFO Queue questions

1 New Member
Hi all,

I'm using the PICC CCS C compiler and am having issues with starting an enque/deque for my program. What I need it to do is to hold about 9 data packets, each packet is an array of 4 HEX integers. Each array is a different command for the program.

example of array commands:
Expand|Select|Wrap|Line Numbers
  1.    int ph[4] = {0x18, 0x2B, 0x00, 0x00}; 
  2.    int zt[4] = {0x28, 0x35, 0x00, 0x00};   
  3.    int zw[4] = {0x28, 0x37, 0x00, 0x00};   
  4.    int af[4] = {0x28, 0x41, 0x00, 0x00};     
  5.    int off[4] = {0x18, 0x5E, 0x00, 0x00};     

From what I understand, I need an enque() function that will store up to 9 packets (or more depending on how large the program gets) and then a deque() function that will spill them out in a FIFO style. Is that correct? Below is what I've started, but I'm not sure if I'm headed in the right direction:


Expand|Select|Wrap|Line Numbers
  1. typedef struct
  2. {
  3.   int front;         //location of front of queue
  4.   int rear;         //location of rear of queue
  5.   int max_size;    //queue can hold 9 packets
  6.   int packet[9][10];    //make sure queue is large enough
  7. } queue;
  8.  
  9. typedef struct
  10. {
  11.   int packet[9][10];            //make sure queue is large enough
  12. } packet;
  13.  
  14. //add to front of queue, stack on top
  15. int1 enqueue (queue *working_queue ,packet *packets[]) //bring in que & packet to load
  16. {
  17.   working_queue.front++;                         //increas front by one
  18.   if (working_queue.front > working_queue.max_size) //if at end, loop around and write over old packets
  19.   {
  20.     working_queue.front = 0;
  21.   }
  22.   memcpy(working_queue.packet[working_queue.front], packets.packet[0], sizeof(working_queue.packet)); //copies packet to struct
  23.   return 0;
  24. }
Please help, if any more info is needed, I'd be happy to supply it.



K
Dec 5 '07 #1
0 1744

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3071
by: Luca | last post by:
I have the need of a container of integers showing both the characteristics of an associative container (all integer elements different from each other) and the FIFO behaviour. Do you know if there is a ready-made container for that or if I have to use - for example - a set<int> and produce by myself FIFO behaviour, or maybe I can use a queue<int> adding code for preventing the insertion od duplicate integers Thank you
2
3079
by: worli | last post by:
Hi All, I have a strange requirement. I have a dynamic input numeric data stream e.g. 2, 2, 4, 5 etc.... ( each input number range from 1 to 10 ). lets take a simple case where all inputs will have same value = 1 ( which may not be the case ) I need to create a FIFO queue in which at any given time I need the total element value = 10. ( not the size of array ). say if the data stream is all 1 e.g. 1,1,1,1,1,1,1,1,1
2
8995
by: Michele Moccia | last post by:
How can I implement a "time critical" fifo in c++ ? I just have to manage sequences of raw bytes, no user defined types. An std::queue<unsigned char> or std::deque<unsigned char> seems to be slow. I've compared that to a platform depended solution (i tried to use a MS Window pipe in the same process to create a fifo and it's very faster). Many thanks Michele Moccia --
8
14193
by: Jack | last post by:
I want to implement a fixed-size FIFO queue for characters. I only want to use array not linked list. For example, const int N = 10; char c_array; The question is when the queue is full, there are ten characters in the
5
3262
by: Dinsdale | last post by:
I have an application that recieves text data via external input (i.e. serial) and displays it on the screen (we use carraige return as a delimiter). At this point I use a regular old text box and when the text size gets too big I truncate the string and re-set the TextBox.Text property. This solution is very crappy as it creates a flickering scroll bar when I re-set the text. Scrolling is also difficult because the position in the text...
4
2336
by: David Bear | last post by:
I'm looking to see if there are any examples or prewritting fifo queue classes. I know this is a broad topic. I'm looking to implement a simple application where a web server enqueue and pickle using a local socket on to a 'queue server' -- and then I will have another application dequeue the pickles again using a local socket. -- David Bear -- let me buy your intellectual property, I want to own your thoughts --
4
5543
by: drochom | last post by:
hi, how would u improve this code? class queue: def __init__(self, size=8): self.space = size self.data = *self.space self.head = 0 self.tail = 0
2
7808
by: Spoon | last post by:
Hello, I'm wondering whether the STL defines a data structure with the following features: o provides push_front() and pop_back() (like std::list) to implement a FIFO buffer. o allows fast lookup (like std::map) so I can easily search for a specific item in the buffer.
5
4387
by: akenato | last post by:
Hi for me this is th first time that I use c++. I have to do this exercise. Somebody can help me? Thanx. Implement a FIFO-queue ( first in, first out ) as a ring buffer. Use a static array as the data structure. The program needs to be able to add elements to the end of the queue, tell the value of the oldest element and remove from the queue. The capacity n of the ring buffer is 10000 elements. The program must handle the following...
0
8394
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.