473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Design recommendation wanted.

Hello all,

I'm implementing a protocol to communicate with a server through serial port
(Yes Peter and Alex it's me again!). This means looking for lost packet,
checksum error, connection failure.

Whitout error, the normal course of things is:
(C = Client - the one I'm programming, S = Server)

Type #1 command:
C: Send a packet to ask something
S: Reply with the final answer
C: Acknowledge reception

Type #2 command:
C: Send a packet to ask something
S: Reply with part of the answer
C: Acknowledge reception of the partial answer
S: Reply with the following part of the answer
C: Acknowledge reception of the partial answer
....
S: Confirm the end of the answer
C: Acknowledge reception

Added to that, the server can send me an error packet due to my last sent
packet being lost or checksum error or packet wrongly construct or
impossibility to answer my "correctly constructed and received question".
It includs in this error whether or not I should resend the last packet.
Even more, there is a fixed maximum number of tentative to resent a packet.

So my question is a general design one:
Anybody has any hint how to handle in a well structured way that much
possible errors and situation? How?

Say I got 20 commands I can ask to server (which is near the real
situation).

I tried to make a base Command class that has a function that looks like:

def getReply(expected):
try:
packet = serial.readline() #raise TimeoutError()
packet_type, data = decode(packet) #raise FormatPacketError()
# ChecksumError()
# PacketNumberError()
if packet_type == ERROR:
raise ServerReplyError()
if packet_type <> expected:
raise UnexpectedPacketError()
c = PACKETS[packet_type](data) #PACKETS is a dict containing Classes
#raise DataFormatError()
expect TimeoutError:
blabla
expect FormatPacketError:
blabla
expect ChecksumError:
blabla
expect PacketNumberError:
blabla
expect UnexpectedPacketError:
blabla
expect ServerReplyError:
blabla
expect DataFormatError:
blabla
With this solution, I will get lost very soon. I feel that I would need a
kind of State-Managing system/class that would keep track of the command
processing in general. But I'm not grasping it. I'm conscious that by not
knowing the total situation, it's difficult for anybody to help but any
suggestion, recommendation would be much appreciated.

Yannick
Jul 18 '05 #1
1 1201
Yannick Turgeon wrote:
With this solution, I will get lost very soon. I feel that I would need a
kind of State-Managing system/class that would keep track of the command


It would simplify your life if you dealt with
the problems (that can be dealt with) on the spot, as they
happen. Don't use the exceptions as a mechnism to jump out of a
block of code. This is so much easier to follow:

if packet_type == ERROR1:
...deal with it..
elif packet_type == ERROR2:
...deal with it ...
else:
try:
c = PACKETS[packet_type](data)
except ...:
...deal with this
You don't have to have to put your code in one try/except
block. This only depens on the nature of the response that
you want to invoke when an exeption occurs. Feel free to nest them
as needed. Keep the error and the response to it as one logical
entity as much as possible.

Istvan.

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: hhhhhhhhh | last post by:
I am looking for a recommendation for an introductory database design book which will enable me to design my first database. It should cover the basics such as normalization and entity-relationship...
3
by: Amadelle | last post by:
Hi All and thanks in advance, I wanted to know when is a good idea to use a static class (with static constructor) and when to use instance classes? I have read couple of articles on line and...
20
by: Brad Pears | last post by:
I am completely new to vb .net. I am using visual Studio 2005 to redo an Access 2000 application into a .net OO application using SQL Server 2000 - so a complete rewrite and re-thinking of how...
1
by: staeri | last post by:
I'm going to show free weeks in a booking system in a grid. The user needs to be able to select which cities and products should be included in the search of free weeks and I need help with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.