POC1.5 prototype 2 x color sensor 2 x LM75B 3 x AnalogIn 1 x accel

Dependencies:   mbed vt100

Files at this revision

API Documentation at this revision

Comitter:
Rhyme
Date:
Thu Dec 07 10:13:13 2017 +0000
Parent:
7:aa858d789025
Child:
9:f958fa2cdc74
Commit message:
commit at the end of 7-Dec-2017

Changed in this revision

af_utils/af_attriburtes.cpp Show annotated file Show diff for this revision Revisions of this file
edge_sensor/edge_accel.cpp Show annotated file Show diff for this revision Revisions of this file
edge_sensor/edge_color.cpp Show annotated file Show diff for this revision Revisions of this file
edge_sensor/edge_pressure.cpp Show annotated file Show diff for this revision Revisions of this file
edge_sensor/edge_temp.cpp Show annotated file Show diff for this revision Revisions of this file
edge_utils/edge_mgr.cpp Show annotated file Show diff for this revision Revisions of this file
edge_utils/edge_time.cpp Show annotated file Show diff for this revision Revisions of this file
edge_utils/edge_time.h Show annotated file Show diff for this revision Revisions of this file
--- a/af_utils/af_attriburtes.cpp	Thu Dec 07 01:06:46 2017 +0000
+++ b/af_utils/af_attriburtes.cpp	Thu Dec 07 10:13:13 2017 +0000
@@ -242,13 +242,13 @@
         pending->replied_time = timestamp ;
 
     }
-    ts2time(timestamp, &current_time) ;
+    ts2time(timestamp, &current_time) ; /* 12 us */
     print_time(&current_time) ;
     printf(" %5d ASR requested [%d] : ", attributeId, requestId) ;
     af_print_values(requestId, attributeId, valueLen, value) ;
     switch(attributeId) {
-    case ATTR_LINKED_TIMESTAMP: /* timestamp */
-        set_time(valueLen, value) ;
+    case ATTR_LINKED_TIMESTAMP: /* timestamp */  
+        set_time(valueLen, value) ; /* 68 us */
         afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
         printf("timestampe = %d\n", timestamp) ;
 //        print_date(&current_time) ;
@@ -347,6 +347,24 @@
              afero->setAttributeBool(ATTR_COLOR0_CALIBRATE, false) ;
         }
         break ;
+    case ATTR_COLOR0_PWM_R:
+        if (sensor[1]) {
+            color0_pwm[0] = (value[1] << 8) | value[0] ;
+        }
+        afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;       
+        break ;
+    case ATTR_COLOR0_PWM_G:
+        if (sensor[1]) {
+            color0_pwm[1] = (value[1] << 8) | value[0] ;
+        }
+        afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;       
+        break ;
+    case ATTR_COLOR0_PWM_B:
+        if (sensor[1]) {
+            color0_pwm[2] = (value[1] << 8) | value[0] ;
+        }
+        afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;       
+        break ;
     case ATTR_COLOR1_ENABLE: /* color1 enable */
         if (sensor[2]) {
             if (value[0]) {
@@ -409,6 +427,24 @@
         }
 
         break ;
+    case ATTR_COLOR1_PWM_R:
+        if (sensor[2]) {
+            color1_pwm[0] = (value[1] << 8) | value[0] ;
+        }
+        afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;       
+        break ;
+    case ATTR_COLOR1_PWM_G:
+        if (sensor[2]) {
+            color1_pwm[1] = (value[1] << 8) | value[0] ;
+        }
+        afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;       
+        break ;
+    case ATTR_COLOR1_PWM_B:
+        if (sensor[2]) {
+            color1_pwm[2] = (value[1] << 8) | value[0] ;
+        }
+        afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;       
+        break ;
     case ATTR_TEMP0_ENABLE: /* temp0 is used to control temp-sensors */
         if (sensor[3]) {
             if (value[0]) {
@@ -468,15 +504,17 @@
     const uint8_t   *value
 ) 
 {
+Timer timer ;
+int t0, t1 ;
     uint32_t timestamp = edge_time ;
     if ((pending != 0)&&(pending->request->requestId == requestId)) {
         pending->replied_time = timestamp ;
-    }
-    ts2time(timestamp, &current_time) ;
+    }   
+    ts2time(timestamp, &current_time) ; /* 12us */
     print_time(&current_time) ;
     printf(" %5d ASR reported [%d]: ", attributeId, requestId) ;
     if (attributeId == ATTR_LINKED_TIMESTAMP) { /* timestamp! */
-        set_time(valueLen, value) ;
+        set_time(valueLen, value) ; /* 68 us */
         printf("timestampe = %d\n", timestamp) ;
         print_date(&current_time) ;
 //        print_time(&current_time) ;
--- a/edge_sensor/edge_accel.cpp	Thu Dec 07 01:06:46 2017 +0000
+++ b/edge_sensor/edge_accel.cpp	Thu Dec 07 10:13:13 2017 +0000
@@ -41,12 +41,14 @@
 {
     int result ;
     float value ;
+    char timestr[16] ;
     print_time(_sampled_time) ;
     value = get_value() ;
     printf(" accel = %.3f [%d samples]\n", value, _sample_count) ;
+    time2seq(_sampled_time, timestr) ;
     sprintf(_str_buf,
-        "{\"DEVICE\":\"ACCEL\",\"PN\":\"MMA8451Q\",\"VAL_X\":\"%.3f\",\"VAL_Y\":\"0\",\"VAL_Z\":\"0\",\"UNIT\":\"g\",\"S\":\"%06d\",\"E\":\"%d\"}",
-        value, time2seq(_sampled_time), _error_count) ;
+        "{\"DEVICE\":\"ACCEL\",\"PN\":\"MMA8451Q\",\"VAL_X\":\"%.3f\",\"VAL_Y\":\"0\",\"VAL_Z\":\"0\",\"UNIT\":\"g\",\"S\":\"%s\",\"E\":\"%d\"}",
+        value, timestr, _error_count) ;
     result = afero->setAttribute(1, _str_buf) ;
     if (result == afSUCCESS) {
         clear_value() ;
--- a/edge_sensor/edge_color.cpp	Thu Dec 07 01:06:46 2017 +0000
+++ b/edge_sensor/edge_color.cpp	Thu Dec 07 10:13:13 2017 +0000
@@ -97,17 +97,19 @@
 int edge_color::deliver(void) 
 {
     int result ;
+    char timestr[16] ;
     print_time(_sampled_time) ;
+    time2seq(_sampled_time, timestr) ;
     printf(" color %d : R = %4d, G = %4d, B = %4d\n",
         _id, _value[0], _value[1], _value[2]) ;
     if (_id == 1) { /* color1 */
     sprintf(_str_buf,
-          "{\"DEVICE\":\"COLOR\",\"PN\":\"VEML6040\",\"VAL_R\":\"%d\",\"VAL_G\":\"%d\",\"VAL_B\":\"%d\",\"UNIT\":\"mW/cm2\",\"S\":\"%06d\",\"E\":\"%d\"}",
-          _value[0], _value[1], _value[2],time2seq(_sampled_time), _error_count) ; 
+          "{\"DEVICE\":\"COLOR\",\"PN\":\"VEML6040\",\"VAL_R\":\"%d\",\"VAL_G\":\"%d\",\"VAL_B\":\"%d\",\"UNIT\":\"mW/cm2\",\"S\":\"%s\",\"E\":\"%d\"}",
+          _value[0], _value[1], _value[2], timestr, _error_count) ; 
     } else { /* color2 */
         sprintf(_str_buf,
-          "{\"DEVICE\":\"COLOR02\",\"PN\":\"VEML6040\",\"VAL_R\":\"%d\",\"VAL_G\":\"%d\",\"VAL_B\":\"%d\",\"UNIT\":\"mW/cm2\",\"S\":\"%06d\",\"E\":\"%d\"}",
-          _value[0], _value[1], _value[2],time2seq(_sampled_time), _error_count) ; 
+          "{\"DEVICE\":\"COLOR02\",\"PN\":\"VEML6040\",\"VAL_R\":\"%d\",\"VAL_G\":\"%d\",\"VAL_B\":\"%d\",\"UNIT\":\"mW/cm2\",\"S\":\"%s\",\"E\":\"%d\"}",
+          _value[0], _value[1], _value[2], timestr, _error_count) ; 
     }
     result = afero->setAttribute(1, _str_buf) ;
     return( result == afSUCCESS ) ;
--- a/edge_sensor/edge_pressure.cpp	Thu Dec 07 01:06:46 2017 +0000
+++ b/edge_sensor/edge_pressure.cpp	Thu Dec 07 10:13:13 2017 +0000
@@ -75,6 +75,7 @@
 int edge_pressure::deliver(void) 
 {
     char str_buf[32] ;
+    char timestr[16] ;
     int result ;
     float expected ;
     print_time(_sampled_time) ;
@@ -105,11 +106,12 @@
         display->putStr(str_buf) ;
     }
     printf(" %s\n", str_buf) ;
+    time2seq(_sampled_time, timestr) ;
 //    printf(str_buf) ;
 //    printf("\n") ;
     sprintf(_str_buf,
-       "{\"DEVICE\":\"PRESS\",\"PN\":\"PSE530\",\"VAL\":\"%.3f\",\"UNIT\":\"kgf/cm2\",\"S\":\"%06d\",\"E\":\"%d\"}",
-       _value, time2seq(_sampled_time), _error_count) ;
+       "{\"DEVICE\":\"PRESS\",\"PN\":\"PSE530\",\"VAL\":\"%.3f\",\"UNIT\":\"kgf/cm2\",\"S\":\"%s\",\"E\":\"%d\"}",
+       _value, timestr, _error_count) ;
     result = afero->setAttribute(1, _str_buf) ;
     return( result == afSUCCESS ) ;
 }
--- a/edge_sensor/edge_temp.cpp	Thu Dec 07 01:06:46 2017 +0000
+++ b/edge_sensor/edge_temp.cpp	Thu Dec 07 10:13:13 2017 +0000
@@ -60,6 +60,8 @@
 int    edge_temp::deliver(void) 
 {
     int result ;
+    char timestr[16] ;
+    
     print_time() ;
     printf(" temp: ") ;
     if (_temp1) {
@@ -75,9 +77,10 @@
         printf("LM75B2 = %.2f ", _ftemp[3]) ;
     }
     printf("\n") ;
+    time2seq(_sampled_time, timestr) ;
     sprintf(_str_buf,
-    "{\"DEVICE\":\"TEMP04\",\"VAL_1\":\"%.1f\",\"VAL_2\":\"%.1f\",\"VAL_3\":\"%.1f\",\"S\":\"%06d\",\"E\":\"%d\"}",
-        _ftemp[0], _ftemp[1], _ftemp[2], time2seq(_sampled_time), _error_count) ;
+    "{\"DEVICE\":\"TEMP04\",\"VAL_1\":\"%.1f\",\"VAL_2\":\"%.1f\",\"VAL_3\":\"%.1f\",\"S\":\"%s\",\"E\":\"%d\"}",
+        _ftemp[0], _ftemp[1], _ftemp[2], timestr, _error_count) ;
     result = afero->setAttribute(1, _str_buf) ;
     return( result == afSUCCESS ) ;
 }
--- a/edge_utils/edge_mgr.cpp	Thu Dec 07 01:06:46 2017 +0000
+++ b/edge_utils/edge_mgr.cpp	Thu Dec 07 10:13:13 2017 +0000
@@ -80,9 +80,12 @@
         if (sensor[sensor_index]) {
             afero->setAttributeBool(ATTR_COLOR0_PRESENT, true) ;
             afero->setAttributeBool(ATTR_COLOR0_ENABLE, true) ;
-            afero->setAttribute32(ATTR_COLOR0_PWM_R, color0_pwm[0]) ;
-            afero->setAttribute32(ATTR_COLOR0_PWM_G, color0_pwm[1]) ;
-            afero->setAttribute32(ATTR_COLOR0_PWM_B, color0_pwm[2]) ;
+//            afero->setAttribute32(ATTR_COLOR0_PWM_R, color0_pwm[0]) ;
+//            afero->setAttribute32(ATTR_COLOR0_PWM_G, color0_pwm[1]) ;
+//            afero->setAttribute32(ATTR_COLOR0_PWM_B, color0_pwm[2]) ;
+            afero->getAttribute(ATTR_COLOR0_PWM_R) ;
+            afero->getAttribute(ATTR_COLOR0_PWM_G) ;
+            afero->getAttribute(ATTR_COLOR0_PWM_B) ;
         } else {
             afero->setAttributeBool(ATTR_COLOR0_PRESENT, false) ;
         }
@@ -91,9 +94,12 @@
         if (sensor[sensor_index]) {
             afero->setAttributeBool(ATTR_COLOR1_PRESENT, true) ;
             afero->setAttributeBool(ATTR_COLOR1_ENABLE, true) ;
-            afero->setAttribute32(ATTR_COLOR1_PWM_R, color1_pwm[0]) ;
-            afero->setAttribute32(ATTR_COLOR1_PWM_G, color1_pwm[1]) ;
-            afero->setAttribute32(ATTR_COLOR1_PWM_B, color1_pwm[2]) ;
+//            afero->setAttribute32(ATTR_COLOR1_PWM_R, color1_pwm[0]) ;
+//            afero->setAttribute32(ATTR_COLOR1_PWM_G, color1_pwm[1]) ;
+//            afero->setAttribute32(ATTR_COLOR1_PWM_B, color1_pwm[2]) ;
+            afero->getAttribute(ATTR_COLOR1_PWM_R) ;
+            afero->getAttribute(ATTR_COLOR1_PWM_G) ;
+            afero->getAttribute(ATTR_COLOR1_PWM_B) ;
         } else {
             afero->setAttributeBool(ATTR_COLOR1_PRESENT, false) ;
         }
--- a/edge_utils/edge_time.cpp	Thu Dec 07 01:06:46 2017 +0000
+++ b/edge_utils/edge_time.cpp	Thu Dec 07 10:13:13 2017 +0000
@@ -151,6 +151,18 @@
 
 void print_date(struct tm *tm) 
 {
+    printf("%d/%d/%d %02d:%02d:%02d",
+        tm->tm_year,
+        tm->tm_mon + 1,
+        tm->tm_mday,
+        tm->tm_hour,
+        tm->tm_min,
+        tm->tm_sec
+        ) ;
+}
+
+void print_date_wd(struct tm *tm) 
+{
     printf("%d/%d/%d %02d:%02d:%02d (%s)",
         tm->tm_year,
         tm->tm_mon + 1,
@@ -188,6 +200,20 @@
     return(result) ;
 }
 
+void time2seq(uint32_t timestamp, char *timestr) 
+{
+    struct tm timestruct ;
+    ts2tm(timestamp, &timestruct) ;
+    sprintf(timestr, "%d%02d%02d%02d%02d%02d",
+        timestruct.tm_year,
+        timestruct.tm_mon + 1,
+        timestruct.tm_mday,
+        timestruct.tm_hour,
+        timestruct.tm_min,
+        timestruct.tm_sec
+    ) ;
+}
+
 void time2date(struct tm *tm, char *datestr)
 {
     sprintf(datestr, "%d/%d/%d %02d:%02d:%02d (%s)",
--- a/edge_utils/edge_time.h	Thu Dec 07 01:06:46 2017 +0000
+++ b/edge_utils/edge_time.h	Thu Dec 07 10:13:13 2017 +0000
@@ -10,10 +10,13 @@
 void print_time(uint32_t thetime) ;
 void print_time(struct tm *tm) ; /* light version */
 void print_date(struct tm *date) ; /* full version */
+void print_date_wd(struct tm *date) ; /* vull version with day of week */
 void time2str(char *timestr) ; /* light version */
 int32_t time2seq(uint32_t timestamp) ; /* hhmmss */
-void time2str(struct tm *tm, char *timestr) ; /* light version */
-void time2date(struct tm *tm, char *datestr) ; /* full version */
+void time2seq(uint32_t timestamp, char *timestr) ;
+void time2str(struct tm *tm, char *timestr) ; /* hh:mm:ss */
+void time2date(struct tm *tm, char *datestr) ; /* YYYY/MM/DD hh:mm:ss */
+void time2date(struct tm *tm, char *datestr) ; /* full version with day of week */
 
 extern const char *nameOfDay[] ;
 extern tm current_time ;