Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
marco committed Dec 22, 2016
1 parent 52a98ad commit 5d8a465
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 72 deletions.
96 changes: 35 additions & 61 deletions scripts_folder/arduinoserial.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def read_data(self): # thread function


while (self.exit==0):
time.sleep(0.01)#0.03
time.sleep(0.03)#0.03

if self.ser.isOpen() == False :
print "error serial port disconnected in arduinoserial.py"
Expand Down Expand Up @@ -224,72 +224,30 @@ def read_data(self): # thread function


while (self.exit==0):
time.sleep(0.01)
#if self.exit==1 or write_enable==1:
# break
#if len(self.removeFromInBuffer)>0:
# serial_incomingBuffer.replace(self.removeFromInBuffer, ""); #remove from buffer the part just readed
# self.removeFromInBuffer=''
try:
byte = self.ser.read(1) # self.usbR.read(1)
# print byte
except:
byte=-1
self.status=0
continue


if not byte: #nothing on incoming serial buffer

# print "end of serial packet1"
#print "incoming buffer="+serial_incomingBuffer
time.sleep(0.1)#0.3
break
time.sleep(0.1)


#here the buffer have received at least one byte





# end of packet is "_#]"




#if byte: #nothing on incoming serial buffer
# done=1
# print "end of serial packet2"
# continue
# print byte

if byte=="\x00":
if self.ser.inWaiting()<5: #skip if there is no incoming data
time.sleep(0.1)
continue

if (ord(byte)==10): # 10 is the value for new line (\n) end of packet on incoming serial buffer
print "end of serial packet for /n"
break
else:
#print "in byte="+byte+" end of in byte"
buf=buf+byte
print ("buf=$$$$$$$$$$$$$$$$"+buf)
count=len(buf)

if len(buf)==0:
continue


if len(buf)>3:
waitTowriteUntilIReceive=1
if ( (buf.find("[S_")!=-1)&(buf.find("_#]")!=-1) ): #there is a full onos command packet
print "end of serial packet:_#] "
break
if self.ser.inWaiting()>6:
buf=self.ser.read(self.ser.inWaiting())
waitTowriteUntilIReceive=1
if ( (buf.find("[S_")!=-1)&(buf.find("_#]")!=-1) ): #there is a full onos command packet
print "end of serial packet:_#] "
break
if (buf.find("\n")!=-1):
print ("end of line received but no onoscmd found")
break




#at this point i should have a full packet message
if len(buf)>0:
if len(buf)>3:

buf=buf.replace("\n", "") #to remove \n
buf=buf.replace("\r", "") #to remove \r
Expand Down Expand Up @@ -454,11 +412,27 @@ def removeFromPackets_list(self,packet):
# print "portWrite executed"
# self.usbW.write(data)

def write2(self, data):#test..
self.ser.write(data)
return("prova")
def write(self, data):#test..
#self.ser.flushOutput()
#while self.ser.inWaiting()>0:
# time.sleep(0.01)
self.ser.write(data)
self.ser.flushOutput()
#while self.ser.inWaiting()<5:
# time.sleep(0.01)
time.sleep(0.2)
#answer=self.ser.read(self.ser.inWaiting())
# if len(self.readed_packets_list)>0:
# answer=self.readed_packets_list[-1]
# else:
answer="answer"
return(answer)





def write(self, data):
def write2(self, data):
global write_enable
global last_received_packet
global data_to_write
Expand Down
Binary file modified scripts_folder/arduinoserial.pyc
Binary file not shown.
12 changes: 6 additions & 6 deletions scripts_folder/config_files/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"WPlugAvx0008": {
"hwModelName": "WPlugAvx",
"nodeAddress": "003",
"nodeAddress": "254",
"node_serial_number": "WPlugAvx0008"
}
},
Expand Down Expand Up @@ -705,7 +705,7 @@
],
"priority": 0,
"scenarios": [],
"status": 20,
"status": 23,
"styleDict": {
"0": "background-color:green;",
"1": "background-color:red;",
Expand Down Expand Up @@ -741,7 +741,7 @@
],
"priority": 0,
"scenarios": [],
"status": 100,
"status": 52,
"styleDict": {
"0": "background-color:green;",
"1": "background-color:red;",
Expand Down Expand Up @@ -785,7 +785,7 @@
"scenario5",
"scenario4"
],
"status": 1,
"status": 0,
"styleDict": {
"0": "background-color:green;",
"1": "background-color:red;",
Expand Down Expand Up @@ -831,7 +831,7 @@
"scenario4",
"scenario8"
],
"status": 40,
"status": 52,
"styleDict": {
"0": "background-color:green;",
"1": "background-color:red;",
Expand Down Expand Up @@ -974,7 +974,7 @@
],
"priority": 0,
"scenarios": [],
"status": "0",
"status": "inactive",
"styleDict": {
"0": "background-color:#A9E2F3;",
"1": "background-color:#8181F7;",
Expand Down
15 changes: 10 additions & 5 deletions scripts_folder/node_query_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def make_query_to_radio_node(serialCom,node_serial_number,query,number_of_retry_
"""

max_retry=1
max_retry=2
for m in range(0,max_retry): #retry n times to get the answer from node #retry n times to get the answer from node

# [S_001dw06001_#]
Expand All @@ -50,15 +50,16 @@ def make_query_to_radio_node(serialCom,node_serial_number,query,number_of_retry_

for a in serialCom.uart.readed_packets_list:
if a.find(expected_confirm)!=-1 : #found the answer
serialCom.uart.readed_packets_list.remove(a)
return (a)


time.sleep(0.2)


if serialCom.uart.ser.isOpen() == False :
print "serial port is not open in make_query_to_radio_node()"
priorityCmdQueue.put( {"cmd":"reconnectSerialPort"})
# time.sleep(1)
# time.sleep(1)
return(-1)


Expand All @@ -73,11 +74,15 @@ def make_query_to_radio_node(serialCom,node_serial_number,query,number_of_retry_
print str(e.args)
# time.sleep(2)


if data.find(expected_confirm)!=-1:
return(data)

if data=="error_reception":
continue




# return(1)
print "expected confirm:"+expected_confirm
Expand Down Expand Up @@ -110,7 +115,7 @@ def make_query_to_radio_node(serialCom,node_serial_number,query,number_of_retry_

#print "answer received from serial port is wrong:'"+data+"'end_data, trying query the serial node the expected answer was:"+expected_confirm+",the number of try is "+str(m)
errorQueue.put("answer received from serial port is wrong:'"+data+"', trying query the serial node the expected answer was:'"+expected_confirm+"'the number of try is "+str(m)+" at:" +getErrorTimeString() )
#time.sleep(0.1*m)
time.sleep(0.2*m)


print("Great serial error,answer received from serial port was wrong:"+data+"end_data, trying query the serial,node the query was"+query+"the number of try was "+str(max_retry)+" at:" +getErrorTimeString() )
Expand Down
Binary file modified scripts_folder/node_query_handler.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions scripts_folder/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5737,6 +5737,7 @@ def executeQueueFunction(dataExchanged):
#hardwareModelDict["WPlugAvx"]["pin_mode"]["digital_obj"]={"plug":[(0)],"plug2":[(1)]}#

node_sn=dataExchanged["nodeSn"]
updateNodeAddress(node_serial_number,uart_router_sn,node_address,object_dict,nodeDict,zoneDict,scenarioDict,conf_options)
node_model_name=node_sn[0:-4]#get WPlugAvx from WPlugAvx0008
print str(dataExchanged["objects_to_update"].keys())
print "end data_exanged"
Expand Down

0 comments on commit 5d8a465

Please sign in to comment.