Skip to content

Commit

Permalink
Corrected some bugs in the queryToRadioNodeQueue priority were wrong..
Browse files Browse the repository at this point in the history
  • Loading branch information
marco committed Dec 18, 2016
1 parent 4e0e20b commit 391c89d
Show file tree
Hide file tree
Showing 14 changed files with 179 additions and 132 deletions.
37 changes: 21 additions & 16 deletions arduino_code/onos_plug_node_WPlugavx/onos_plug_node_wplugavx.ino
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void sendSyncMessage(){
syncMessage[6]='u'; //modify the message
syncMessage[7]='l'; //modify the message

if (radio.sendWithRetry(gateway_address, syncMessage, strlen(syncMessage),3,250)) {
if (radio.sendWithRetry(gateway_address, syncMessage, strlen(syncMessage),10,10)) {
// note that the max delay time is 255..because is uint8_t
//target node Id, message as string or byte array, message length,retries, milliseconds before retry
//(uint8_t toAddress, const void* buffer, uint8_t bufferSize, uint8_t retries, uint8_t retryWaitTime)
Expand All @@ -365,7 +365,7 @@ void getAddressFromGateway(){
syncMessage[7]='a'; //modify the message to get a address instead of just sync.


if (radio.sendWithRetry(gateway_address, syncMessage,strlen(syncMessage),3,250)) {
if (radio.sendWithRetry(gateway_address, syncMessage,strlen(syncMessage),10,10)) {
// note that the max delay time is 255..because is uint8_t
//target node Id, message as string or byte array, message length,retries, milliseconds before retry
//(uint8_t toAddress, const void* buffer, uint8_t bufferSize, uint8_t retries, uint8_t retryWaitTime)
Expand Down Expand Up @@ -499,8 +499,8 @@ void decodeOnosCmd(const char *received_message){
}


//[S_123wp01x_#]
else if( received_message_type_of_onos_cmd[0]=='w' && received_message_type_of_onos_cmd[1]=='p' ){
//[S_123wb01x_#]
else if( received_message_type_of_onos_cmd[0]=='w' && received_message_type_of_onos_cmd[1]=='b' ){

Serial.print("decode time03=") ;
Serial.println(millis()-get_decode_time) ;
Expand Down Expand Up @@ -671,7 +671,22 @@ void decodeOnosCmd(const char *received_message){

}// end of decodeOnosCmd()

void handleButton(){

if (digitalRead(obj_button_pin)==0) {
Serial.print("obj_button pressed");

while (digitalRead(obj_button_pin)==0){ //wait for button release
delay(100);//todo change it smaller
}

changeObjStatus(main_obj_selected,!main_obj_state); // this will make a not of current state
sendSyncMessage();

}


}



Expand Down Expand Up @@ -739,17 +754,7 @@ void loop() {

//check if something was received (could be an interrupt from the radio)

if (digitalRead(obj_button_pin)==0) {
Serial.print("obj_button pressed");

while (digitalRead(obj_button_pin)==0){ //wait for button release
delay(100);//todo change it smaller
}

changeObjStatus(main_obj_selected,!main_obj_state); // this will make a not of current state
sendSyncMessage();

}
handleButton();


if (radio.receiveDone()){
Expand Down Expand Up @@ -833,7 +838,7 @@ void loop() {




handleButton();

if (old_address==254){// i have not the proper address yet..

Expand Down
28 changes: 11 additions & 17 deletions arduino_code/onos_rf69_serial_transponder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ boolean checkAndReceiveSerialMsg(){
}

strcpy(received_message_answer,"[S_nocmd0_#]");

return(0);//no cmd found


Expand Down Expand Up @@ -895,20 +896,20 @@ restart:

serial_msg_to_decode_is_avaible=checkAndReceiveSerialMsg();


if (serial_msg_to_decode_is_avaible){
decodeOnosCmd(filtered_onos_message);
if ( strcmp(received_message_answer,"[S_remote_#]")==0){
ForwardSerialMessageToRadio();
}
sendSerialAnswerFromSerialMsg();
}







else if(enable_answer_back==1) {
Serial.print(received_message_answer);
enable_answer_back=0;
}

/*
if (Serial.available() > 0) {
Expand All @@ -923,8 +924,11 @@ restart:



radio_msg_to_decode_is_avaible=checkAndHandleIncomingRadioMsg();
if (radio_msg_to_decode_is_avaible==1){
forwardRadioMsgToSerialPort();
}

//uart reception part concluded



Expand All @@ -937,16 +941,6 @@ restart:
}


radio_msg_to_decode_is_avaible=checkAndHandleIncomingRadioMsg();
if (radio_msg_to_decode_is_avaible==1){
forwardRadioMsgToSerialPort();
}









Expand Down
6 changes: 4 additions & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,10 @@ versione4.53 iniziato ad usare pythonserial come libraria dopo test fatti con
5.26 started implementing handle_new_query_to_radio_node_thread()
starting replacing "except Exception , e" with "except Exception as e" everywhere because is python3 friendly
now onoscenter will retry to send msg , not the arduino serial code.


Corrected some bugs in the queryToRadioNodeQueue priority were wrong..
Removed some delays in the serial communication ..





Expand Down
48 changes: 24 additions & 24 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.1)
time.sleep(0.01)#0.03

if self.ser.isOpen() == False :
print "error serial port disconnected in arduinoserial.py"
Expand All @@ -193,23 +193,22 @@ def read_data(self): # thread function
break
buf=''

done=0
count=0


if write_to_serial_packet_ready==1:

try:
self.ser.flushInput() #flush input buffer, discarding all its contents
except Exception, e :
print "can't flush input"+str(e.args)
errorQueue.put( "can't flush input"+str(e.args) )
# try:
# self.ser.flushInput() #flush input buffer, discarding all its contents
# except Exception, e :
# print "can't flush input"+str(e.args)
# errorQueue.put( "can't flush input"+str(e.args) )

if write_enable==1:
try:
self.ser.write(data_to_write)
print "i write data_to_write::::::::::::::::::::::::::::::::::::::::::"+data_to_write
time.sleep(0.02)
print "i have wrote to serial port data_to_write:::::::::::::::::::::::::::::::"+data_to_write
#time.sleep(0.02)
write_enable=0
except Exception, e :
print "can't write to uart"+str(e.args)
Expand All @@ -222,7 +221,7 @@ def read_data(self): # thread function
errorQueue.put( "can't flush output"+str(e.args) )


while done==0:
while (self.exit==0):
time.sleep(0.01)
if self.exit==1 or write_enable==1:
break
Expand All @@ -239,11 +238,11 @@ def read_data(self): # thread function


if not byte: #nothing on incoming serial buffer
done=1

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


#here the buffer have received at least one byte
Expand All @@ -267,7 +266,6 @@ def read_data(self): # thread function
continue

if (ord(byte)==10): # 10 is the value for new line (\n) end of packet on incoming serial buffer
done=1
print "end of serial packet for /n"
break
else:
Expand All @@ -277,14 +275,12 @@ def read_data(self): # thread function
count=len(buf)

if len(buf)==0:
done=0
continue


if len(buf)>3:
waitTowriteUntilIReceive=1
if ( (buf.find("[S_")!=-1)&(buf.find("_#]")!=-1) ): #there is a full onos command packet
done=1
print "end of serial packet:_#] "
break

Expand All @@ -299,20 +295,20 @@ def read_data(self): # thread function




cmd_start=buf.find("[S_")
cmd_end=buf.find("_#]")

if ( (buf.find("[S_")!=-1)&(buf.find("_#]")!=-1) ): #there is a full onos command packet
if ( (cmd_start!=-1)&(cmd_end!=-1) ): #there is a full onos command packet

print "packet 232 in :"+buf
time.sleep(1)
print "AAAAAAAAAAAAAAAAAAAAAAAApacket 232 input :"+buf
#time.sleep(1) #todo remove,justfordebug
if write_to_serial_packet_ready==1:
last_received_packet=buf
write_to_serial_packet_ready=0
print "packet received after the write is :"+last_received_packet


cmd_start=buf.find("[S_")
cmd_end=buf.find("_#]")

cmd=buf[cmd_start:cmd_end+3]


Expand Down Expand Up @@ -349,7 +345,7 @@ def read_data(self): # thread function


if( (cmd[6]=="g")&(cmd[7]=="a") ): # [S_001ga3.05ProminiS0001_#]
print "serial rx cmd="+cmd
print "LLLLLLLLLLLLLLLLLLLLLLLLLLLLserial rx cmd="+cmd
buf=""
try:
numeric_serial_number=cmd[13:25]
Expand Down Expand Up @@ -443,6 +439,9 @@ 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):
global write_enable
Expand All @@ -453,7 +452,8 @@ def write(self, data):


write_enable=1
last_received_packet=""
#last_received_packet=""

#self.portWrite(data_to_write)
#self.usbW.write(data_to_write+'\n')
#os.system("echo "+data_to_write+" >> "+self.port)
Expand Down
Binary file modified scripts_folder/arduinoserial.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion scripts_folder/config_files/cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"user_mail": "elettronicaopensource@gmail.com"
}
},
"scenarios_enable": 1,
"scenarios_enable": 0,
"timezone": "CET-1CEST,M3.5.0,M10.5.0/3"
}

0 comments on commit 391c89d

Please sign in to comment.