Skip to content

Commit

Permalink
Removed the bash command to control hardware pins and used python to …
Browse files Browse the repository at this point in the history
…write to them as files,so the error Cannot allocate memory will not happen again
  • Loading branch information
marco committed Aug 14, 2016
1 parent f27f5b8 commit 81eebe9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# onos 5.22 beta
# onos 5.23 beta

[![Analytics](https://ga-beacon.appspot.com/UA-45976563-3/welcome-page)](https://github.com/igrigorik/ga-beacon)

Expand Down
4 changes: 2 additions & 2 deletions arduino_code/onos_node_Plug6way.pde
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void server_handler(EthernetClient client_query ){

if ((status_value<0)||(status_value>255)){ //status check
status_value=0;
answer="err_status_#]";
answer="er0_status_#]";
quit=1;
continue;
}
Expand Down Expand Up @@ -236,7 +236,7 @@ void server_handler(EthernetClient client_query ){
#if defined(DEVMODE)
Serial.println(status);
#endif
answer="err_status_#]";
answer="er1_status_#]";
if ((status==0)||(status==1)){ //status check
digitalWrite(pin_number_used, status);
digitalWrite(second_pin_number_used,!status);
Expand Down
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ versione4.53 iniziato ad usare pythonserial come libraria dopo test fatti con
Marco has solved a bug in the webobject html page.
finished implementing the common top menu for every onos webpage!

5.23 Removed the bash command to control hardware pins and used python to write to them as files,
so the error Cannot allocate memory will not happen again



(110, 'Connection timed out');;;
Expand Down
6 changes: 3 additions & 3 deletions scp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
scp -vrC * root@192.168.1.2:/bin/onos
scp -rC * root@192.168.1.2:/bin/onos

scp -vrC * root@192.168.1.2:/tmp/onos
scp -rC * root@192.168.1.2:/tmp/onos






scp -vrC root@192.168.1.2:/bin/onos/* /tmp/ram/
scp -rC root@192.168.1.2:/bin/onos/* /tmp/ram/

69 changes: 50 additions & 19 deletions scripts_folder/router_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ def __init__(self,hardwareModelDict,router_sn):
if pin in self.router_input_pin:
self.pins_mode[pin]=0 # set the pin as input
try:
with lock_bash_cmd:
subprocess.call('echo in > /sys/class/gpio/gpio'+str(pin)+'/direction', shell=True,close_fds=True)
#with lock_bash_cmd:
with open('/sys/class/gpio/gpio'+str(pin)+'/direction', 'w') as f: #read the pin status
f.write('in')
#subprocess.call('echo in > /sys/class/gpio/gpio'+str(pin)+'/direction', shell=True,close_fds=True)
#os.popen('echo in > /sys/class/gpio/gpio'+str(pin)+'/direction').read() #set the GPIO as input
except Exception, e :
print "error trying to read a router pin :"+str(e.args)
Expand All @@ -131,25 +133,31 @@ def __init__(self,hardwareModelDict,router_sn):

time.sleep(1)


try:
print "i try to read the status with: cat /sys/class/gpio/gpio"+str(pin)+"/value"
with lock_bash_cmd:
status=subprocess.check_output("cat /sys/class/gpio/gpio"+str(pin)+"/value", shell=True,close_fds=True)
#with lock_bash_cmd:
with open('/sys/class/gpio/gpio'+str(pin)+'/value', 'r') as f: #read the pin status
read_data = f.read()
status=read_data[0]
#status=subprocess.check_output("cat /sys/class/gpio/gpio"+str(pin)+"/value", shell=True,close_fds=True)
#status=os.popen("cat /sys/class/gpio/gpio"+str(pin)+"/value").read()
self.pins_status[pin]=int(status[0])
self.pins_status[pin]=int(status)
except Exception, e :
self.pins_status[pin]=0
print "error in reading pin"+str(pin)
errorQueue.put("error in reading pin"+str(pin) )
errorQueue.put("error00 in reading pin"+str(pin) )
error_number=error_number+1

else:
self.pins_mode[pin]=1 # set the pin as output
print "i try to set the pin as output"
try:
with lock_bash_cmd:
#with lock_bash_cmd:
with open('/sys/class/gpio/gpio'+str(pin)+'/direction', 'w') as f: #read the pin status
f.write('out')
#os.popen('echo out > /sys/class/gpio/gpio'+str(pin)+'/direction').read() #set the GPIO as output
subprocess.call('echo out > /sys/class/gpio/gpio'+str(pin)+'/direction', shell=True,close_fds=True)
#subprocess.call('echo out > /sys/class/gpio/gpio'+str(pin)+'/direction', shell=True,close_fds=True)
except Exception, e :
error_number=error_number+1
print "error setting pin"+str(pin)+ "as output"
Expand Down Expand Up @@ -206,10 +214,19 @@ def read_router_pins(self): # thread function to read changing of pin status
#total_in_pin=total_in_pin+1
#print "foud a input pin in the router, pin number"+str(pin)
#try:
with lock_bash_cmd:
status=subprocess.check_output("cat /sys/class/gpio/gpio"+str(pin)+"/value", shell=True,close_fds=True)
#status=os.popen("cat /sys/class/gpio/gpio"+str(pin)+"/value").read()
current_state=int(status[0])
#with lock_bash_cmd:
try:
with open('/sys/class/gpio/gpio'+str(pin)+'/value', 'r') as f: #read the pin status
read_data = f.read()
status=read_data[0]
#status=subprocess.check_output("cat /sys/class/gpio/gpio"+str(pin)+"/value", shell=True,close_fds=True)
except Exception, e:
current_state=-1
print "error reading router pin status "+str(pin)+", e:"+str(e.args)
errorQueue.put("error reading router pin status "+str(pin)+", e:"+str(e.args))


current_state=int(status)
#print "the current pin status is: "+str(current_state)
#except:
# print "error in reading pin"+str(pin)
Expand Down Expand Up @@ -401,8 +418,12 @@ def outputWrite(self,node_serial_number,pinList,statusList,node_obj,objName,prev
errorQueue.put("pin setted as input i try to set it as output")
try:
#os.system('echo out > /sys/class/gpio/gpio'+str(pinNumber)+'/direction') #set the GPIO as output
with lock_bash_cmd:
subprocess.call('echo out > /sys/class/gpio/gpio'+str(pinNumber)+'/direction', shell=True,close_fds=True)
#with lock_bash_cmd:
with open('/sys/class/gpio/gpio'+str(pinNumber)+'/direction', 'w') as f: #read the pin status
f.write('out')


#subprocess.call('echo out > /sys/class/gpio/gpio'+str(pinNumber)+'/direction', shell=True,close_fds=True)
print "pin"+str(pinNumber)+" setted as output "
except Exception, e :
print "error can't configure the pin:"+str(pinNumber)+" as output and set it to "+str(tmp_status_to_set)
Expand All @@ -412,8 +433,13 @@ def outputWrite(self,node_serial_number,pinList,statusList,node_obj,objName,prev
return(-1)
try:
#os.popen('echo '+str(tmp_status_to_set)+' > /sys/class/gpio/gpio'+str(pinNumber)+'/value').read()
with lock_bash_cmd:
subprocess.check_output('echo '+str(tmp_status_to_set)+' > /sys/class/gpio/gpio'+str(pinNumber)+'/value', shell=True,close_fds=True)
# with lock_bash_cmd:

with open('/sys/class/gpio/gpio'+str(pinNumber)+'/value', 'w') as f: #read the pin status
f.write(str(tmp_status_to_set))


#subprocess.check_output('echo '+str(tmp_status_to_set)+' > /sys/class/gpio/gpio'+str(pinNumber)+'/value', shell=True,close_fds=True)
print "pin"+str(pinNumber)+" setted to "+str(tmp_status_to_set)
except Exception, e :
print "error can't set the pin:"+str(pinNumber)+" to "+str(tmp_status_to_set)
Expand Down Expand Up @@ -524,8 +550,11 @@ def setHwPinMode(self,node_address,pinNumber,mode):
if mode=="DOUTPUT":
self.pins_mode[pinNumber]=1
try:
with lock_bash_cmd:
subprocess.check_output('echo "out" > /sys/class/gpio/gpio'+str(pinNumber)+'/direction', shell=True,close_fds=True)
#with lock_bash_cmd:
with open('/sys/class/gpio/gpio'+str(pinNumber)+'/direction', 'w') as f: #read the pin status
f.write('out')

#subprocess.check_output('echo "out" > /sys/class/gpio/gpio'+str(pinNumber)+'/direction', shell=True,close_fds=True)
#os.popen('echo "out" > /sys/class/gpio/gpio'+str(pinNumber)+'/direction').read() #set the GPIO as output
except Exception, e :
print "error can't set the direction of the pin: /sys/class/gpio/gpio"+str(pinNumber)
Expand All @@ -539,7 +568,9 @@ def setHwPinMode(self,node_address,pinNumber,mode):
if mode=="DINPUT":
self.pins_mode[pinNumber]=0
try:
with lock_bash_cmd:
#with lock_bash_cmd:
with open('/sys/class/gpio/gpio'+str(pinNumber)+'/direction', 'w') as f: #read the pin status
f.write('in')
subprocess.check_output('echo "in" > /sys/class/gpio/gpio'+str(pinNumber)+'/direction', shell=True,close_fds=True)
#os.popen('echo "in" > /sys/class/gpio/gpio'+str(pinNumber)+'/direction').read() #set the GPIO as input
except Exception, e :
Expand Down
2 changes: 1 addition & 1 deletion scripts_folder/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5517,7 +5517,7 @@ def nodeTcpServer():

while (exit==0): #if exit ==1 then close the webserver
wait_because_node_is_talking=0
time.sleep(0.2)
time.sleep(0.3)# was 0.2
try:
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand Down

0 comments on commit 81eebe9

Please sign in to comment.