Remi Beges / DistantIO

Files at this revision

API Documentation at this revision

Comitter:
Overdrivr
Date:
Thu Oct 08 13:14:32 2015 +0000
Parent:
1:aaffeb93f99b
Child:
3:135f55b5334e
Commit message:
*Fixed issues with variables/group names > 8; *Added timing management. Variables can either be send all the time, or only after a defined delta. Useful to reduce constraints on datarate for parameters not needed in real time

Changed in this revision

distantio.cpp Show annotated file Show diff for this revision Revisions of this file
distantio.h Show annotated file Show diff for this revision Revisions of this file
--- a/distantio.cpp	Thu Oct 08 12:27:20 2015 +0000
+++ b/distantio.cpp	Thu Oct 08 13:14:32 2015 +0000
@@ -1,12 +1,19 @@
-// Copyright (C) 2015 Rémi Bèges
-// For conditions of distribution and use, see copyright notice in the LICENSE.md file
+/*
+ * distantio.c
+ *
+ *  Created on: Oct 13, 2014
+ *      Author: B48923
+ */
 
 #include "distantio.h"
 #include "crc.h"
 #include "string.h"
 #include "protocol.h"
 
-
+/*
+ * WARNING : IMPLEMENTATION FOR LITTLE-ENDIAN PROCESSOR
+ * TODO : HANDLE BOTH
+ */
 
 static log Log;
 uint32_t tmp;
@@ -30,19 +37,19 @@
 		Log.variables[i].ptr = 0;
 		Log.variables[i].writeable = 0;
 		Log.variables[i].id = i;
-		strcpy(Log.variables[i].name,default_name);
+		strncpy(Log.variables[i].name,default_name,8);
 		Log.variables[i].send = 0;
 		Log.variables[i].groupID = 0;
 	}
 	tmp=0;
 	Log.current_group_id = 0;
-	strcpy(Log.groups[0].name,"default");
+	strncpy(Log.groups[0].name,"default",8);
 }
 
 /**
  * Register a variable exchanged with the computer
  */
-uint8_t register_var(void* ptr, uint16_t size, dio_type type, uint8_t writeable, char* name)
+uint8_t register_var(void* ptr, uint16_t size, dio_type type, uint8_t writeable, char* name, float refresh_rate)
 {
 	// Too many variables, aborting
 	if(Log.amount >= VARIABLES_AMOUNT)
@@ -53,17 +60,23 @@
 	Log.variables[Log.amount].writeable = writeable;
 	Log.variables[Log.amount].type = type;
 	Log.variables[Log.amount].groupID = Log.current_group_id;
-	strcpy(Log.variables[Log.amount].name,name);
-
+	strncpy(Log.variables[Log.amount].name,name,8);
+	Log.variables[Log.amount].refresh_rate = refresh_rate;
+	Log.variables[Log.amount].last_refreshed = 0;
 	Log.amount++;
 
 	return 0;
 }
 
+uint8_t register_var(void* ptr, uint16_t size, dio_type type, uint8_t writeable, char* name)
+{
+	register_var(ptr,size,type,writeable,name,0.f);
+}
+
 void start_group(char* groupname)
 {
 	Log.current_group_id++;
-	strcpy(Log.groups[Log.current_group_id].name,groupname);
+	strncpy(Log.groups[Log.current_group_id].name,groupname,8);
 }
 
 /**
@@ -240,14 +253,18 @@
 	}
 }
 
-void send_variables()
+void update(float current_time)
 {
 	for(uint16_t i = 0 ; i < Log.amount ; i++)
 	{
 		if(Log.variables[i].send == 0)
 			continue;
-
+		
+		if(current_time < Log.variables[i].last_refreshed + Log.variables[i].refresh_rate)
+			continue;
+			
 		send_variable(i);
+		Log.variables[i].last_refreshed = current_time;
 	}
 }
 
@@ -348,4 +365,3 @@
 			return 1;
 	}
 }
-
--- a/distantio.h	Thu Oct 08 12:27:20 2015 +0000
+++ b/distantio.h	Thu Oct 08 13:14:32 2015 +0000
@@ -1,11 +1,10 @@
-// Copyright (C) 2015 Rémi Bèges
-// For conditions of distribution and use, see copyright notice in the LICENSE.md file
+/*
+ * distantio.h
+ *
+ *  Created on: Oct 13, 2014
+ *      Author: B48923
+ */
 
-/*
- * WARNING : IMPLEMENTATION FOR LITTLE-ENDIAN PROCESSOR
- * TODO : HANDLE BOTH
- */
- 
 #ifndef DISTANTIO_H_
 #define DISTANTIO_H_
 
@@ -39,6 +38,8 @@
 	char name[8];
 	uint8_t send;
 	uint8_t groupID;
+	float refresh_rate;
+	float last_refreshed;
 };
 
 typedef struct group group;
@@ -60,13 +61,13 @@
 void init_distantio();
 
 uint8_t register_var(void* ptr, uint16_t size, dio_type type, uint8_t writeable, char* name);
+uint8_t register_var(void* ptr, uint16_t size, dio_type type, uint8_t writeable, char* name, float refresh_rate);
 void start_group(char* groupname);
 
 void distantio_decode(uint8_t* data,uint16_t datasize);
 
 // To call often
-void send_variables();
+void update(float current_time);
 void send_alive();
 
 #endif /* DISTANTIO_H_ */
-