473,770 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(expect ed):
try:
packet = serial.readline () #raise TimeoutError()
packet_type, data = decode(packet) #raise FormatPacketErr or()
# ChecksumError()
# PacketNumberErr or()
if packet_type == ERROR:
raise ServerReplyErro r()
if packet_type <> expected:
raise UnexpectedPacke tError()
c = PACKETS[packet_type](data) #PACKETS is a dict containing Classes
#raise DataFormatError ()
expect TimeoutError:
blabla
expect FormatPacketErr or:
blabla
expect ChecksumError:
blabla
expect PacketNumberErr or:
blabla
expect UnexpectedPacke tError:
blabla
expect ServerReplyErro r:
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 1217
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
1490
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 diagrams. If it is oriented towards MySQL, so much the better. Thank you
3
1428
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 the general example is when you want to write a log file use static class ...but they don't say why? My specific question is that I have a validation class with some data validation methods which will be called through out the program and I am...
20
1536
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 this app will work. I have NEVER done any OO programming at all although I have used OO techniques in programs of course - just never actually designed the classes etc... So I am just a tad nervous in re-writing this Access application as it is...
1
929
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 designing this in a user friendly way. There are about 10 cities and 100 products. How would you design this? I'm looking forward to your reply!
0
9453
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
10099
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...
1
10036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8929
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
7451
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
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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

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.