Skip to content

Commit

Permalink
Add rate limiting for cloud serial
Browse files Browse the repository at this point in the history
It looks like lastCloudEvent was intended to be used for rate limiting,
since it's not used anywhere else, but it was being updated every time
spark_process() ran, not just when data was actually sent. Changed it
to update only when data is sent.
  • Loading branch information
kh90909 committed Mar 31, 2016
1 parent 2605abd commit 02f67db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions cores/oak/OakParticle/particle_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3048,7 +3048,10 @@ void spark_process(bool internal, bool allow_connect)
return;
}
if(spark_connected()){
spark_send_tx();
if(millis() - lastCloudEvent > 1000){
if(spark_send_tx()>0)
lastCloudEvent = millis();
}
if(!event_loop()){
if(pClient.connected()){
pClient.stop();
Expand All @@ -3070,7 +3073,6 @@ void spark_process(bool internal, bool allow_connect)
else
return;
}
lastCloudEvent = millis();
}

#define MAX_SERIAL_BUFF 255
Expand Down Expand Up @@ -3202,13 +3204,14 @@ void spark_get_rx(const char* name, const char* data){ //this is automatically c
}
}

void spark_send_tx(){
int spark_send_tx(){
if(spark_transmit_buffer_count == 0)//nothing buffer
return 0;

return;
char buff[spark_transmit_buffer_count+1];
uint8_t b;

for(uint8_t b=0;b<spark_transmit_buffer_count;b++){
for(b=0;b<spark_transmit_buffer_count;b++){
// Read from "head"
buff[b] = spark_transmit_buffer[spark_transmit_buffer_head]; // grab next byte
spark_transmit_buffer_head = (spark_transmit_buffer_head + 1) % MAX_SERIAL_BUFF;
Expand All @@ -3222,6 +3225,8 @@ void spark_send_tx(){
spark_transmit_buffer_count=0;

spark_send_event("oak/device/stdout", buff, 60, PRIVATE, NULL);

return b;
}


Expand Down
2 changes: 1 addition & 1 deletion cores/oak/OakParticle/particle_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ size_t spark_serial_write(uint8_t b);
void spark_serial_flush();
int spark_serial_peek();
void spark_get_rx(const char* name, const char* data);
void spark_send_tx();
int spark_send_tx();
void spark_process(bool internal = false,bool allow_connect = true);

String info_response(void);
Expand Down

0 comments on commit 02f67db

Please sign in to comment.