PDA

View Full Version : how can A big network use the master and slaver mode in real world


Mark paul
08-07-2009, 03:18 AM
--------------------------------------------------------------------------------

i have a much more reliable Multidrop Serial Scripts .
we used the tranparent mode in the past,but our data was separate and recombine unsequence, so we use time-out mechanism,by about 11 hop,it work well.
we add datalen check,sequencenum(in case the same packet recvce twice or more,this happen when a lot of node and brocast packet),and pick the second data as a check data,to avoid packet receive error(it did happen).

because the mcast() brocas mode have some problem:when the master is brocasting ,several slaver sent data to master ,a lot of data unsequencenum happen,such as the slaver A send "123456789",slaver B send "ABCDEFG",the maser will receive "123456ABCDEFG789", or "78912345678".

manal said the mcast did't have an ack mechanism,so this proven to be unreliable.

Mark paul
08-07-2009, 03:30 AM
is there a better way to avoid error data in a busy network?
we do design a polling ways,the master brocast ,and the slaver receive it's number and response,but the road is long(wo use it in traffic light),if we didn't receive the response packet in 3 seconds,we retranmit the brocast packet.at the and we receive lots of data like "123456ABCDEFG789"

kbanks
08-07-2009, 09:30 AM
You can make minor improvements in multicast messaging by tuning the relevent NV Parameters to match your network situation.

For example, if you have a dense network (nearly everybody can hear everybody), you will probably want to have some of the nodes not rebroadcast multicasts. Instead have only strategically placed nodes do the "repeating". You should also look at the "collision detection" and "carrier sense" parameters that were added back in 2.1. One combination of those settings may work better for you than the others.

For major improvement in communications, you need to use unicast messaging instead of multicast messaging. For point-to-point applications (paired units) that use data mode (transparent mode), this can be as simple as using the ucastSerial() built-in instead of the mcastSerial() builtin. For multi-way communication, this could mean sending the data via RPC calls instead of using data mode.

Compared to multicast, unicast adds acknowledgments, timeouts, and retries.

One way to think of it is that SNAP multicast is like UDP, and SNAP unicast is more like TCP.

Based on the description given (I have not looked at the actual scripts yet), the poster above added additional smarts at the application layer. These sorts of techniques can be used in conjunction with the suggestions I just made.

Mark paul
08-11-2009, 02:59 AM
this script use the Address FF FF FF to send broadcast packet,other Address as unicast ,and change two parameter(ID13,ID15),so its work well.
serialnumtogether with idsave(in function remote_rpc) in cast that a packet being receive twice.
we print like this so the MCU can know where this packet coming from.
print Slaveraddr,recdata,
here is the script of main controller.
serialnum=0x00
def startupEvent():
"""detectEvalBoards()"""
setPinDir(0, True) #Pin0 config as Send Data Led
writePin(0, False)
setPinDir(1, True) #Pin1 config as recv Data Led
writePin(1, False)
crossConnect(DS_STDIO, DS_UART1)
initUart(1,57600)
stdinMode(1, False) # Line Mode, Echo On
saveNvParam(13,60000) #un-use this pamar
saveNvParam(15,32)
serialnum=0
def stdinEvent(recdata):#recv Data from COM
global serialnum
if recdata[0]=='Z':
if recdata[1]=='1':
print localAddr(), #local_address
else:
lenth=len(recdata)
if serialnum>255:
serialnum=0
serialnum=serialnum+1
slaveraddr=recdata[0:3]
if lenth>5:
CRC_check=recdata[5]
if (recdata[2]=='\xff') and (recdata[1]=='\xff')and(recdata[0]=='\xff'):
mcastRpc(1,64,'remote_rpc',recdata[3:lenth],CRC_check,lenth,serialnum)
else:
rpc(slaveraddr,'remote_rpc',recdata[3:lenth],CRC_check,lenth,serialnum) # UnicastFrame
pulsePin(0,5, True)#send led
recdata=''
idsave=0
def remote_rpc(recdata,CRC_checksum,datalenth,idnum):# Print Data to COM
global idsave
global printEN
if idsave!=idnum:
if CRC_checksum==recdata[2]:
if len(recdata)==datalenth:
Slaveraddr=rpcSourceAddr()
print Slaveraddr,recdata,
pulsePin(1,5,True)
recdata=''
idsave=idnum

snappyGen.setHook(SnapConstants.HOOK_STARTUP, startupEvent)
snappyGen.setHook(SnapConstants.HOOK_STDIN, stdinEvent)

here is the script of slaver controller,it don't care the masers MAC:
serialnum=0x00
def startupEvent():
"""detectEvalBoards()"""
setPinDir(0, True) #Pin0 config as Send Data Led
writePin(0, False)
setPinDir(1, True) #Pin1 config as recv Data Led
writePin(1, False)
crossConnect(DS_STDIO, DS_UART1)
initUart(1,9600)
stdinMode(1, False) # Line Mode, Echo On
saveNvParam(13,60000)
saveNvParam(15,32)
serialnum=0
def stdinEvent(recdata):#recv Data from COM
global serialnum
if recdata[0]=='Z':
if recdata[1]=='1':
print localAddr(), #local_address
else:
lenth=len(recdata)
if lenth>5:
if serialnum>255:
serialnum=0
serialnum=serialnum+1
CRC_check=recdata[2]
rpc("\xce\x00\x03",'remote_rpc',recdata,CRC_check,lenth,serialnum) # UnicastFrame
pulsePin(0,5, True)#send led
recdata=''
idsave=0
def remote_rpc(recdata,CRC_checksum,datalenth,idnum):# Print Data to COM
global idsave
global printEN
if idsave!=idnum:
if CRC_checksum==recdata[2]:
if len(recdata)+3==datalenth:
print recdata,
pulsePin(1,3,True)
recdata=''
iflag=0
idsave=idnum

snappyGen.setHook(SnapConstants.HOOK_STARTUP, startupEvent)
snappyGen.setHook(SnapConstants.HOOK_STDIN, stdinEvent)