afLib 1.3 which is supporting both SPI and UART

Dependencies:   vt100 mbed afLib_1_3

Committer:
Rhyme
Date:
Mon Apr 23 06:15:26 2018 +0000
Revision:
0:87662653a3c6
First UART working version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:87662653a3c6 1 #include "mbed.h"
Rhyme 0:87662653a3c6 2 #include <ctype.h>
Rhyme 0:87662653a3c6 3 #include "af_attributes.h"
Rhyme 0:87662653a3c6 4 #include "af_mgr.h"
Rhyme 0:87662653a3c6 5 #include "edge_time.h"
Rhyme 0:87662653a3c6 6 #include "edge_mgr.h"
Rhyme 0:87662653a3c6 7 #include "edge_reset_mgr.h"
Rhyme 0:87662653a3c6 8
Rhyme 0:87662653a3c6 9
Rhyme 0:87662653a3c6 10 static const af_attribute_type af_attr[] = {
Rhyme 0:87662653a3c6 11 #if 1
Rhyme 0:87662653a3c6 12 /* ID, Description, Type, Size */
Rhyme 0:87662653a3c6 13 /* Software Reset Request */
Rhyme 0:87662653a3c6 14 { ATTR_SOFTWARE_RESET, "Software Reset", ATTRIBUTE_TYPE_BOOLEAN, 1 },
Rhyme 0:87662653a3c6 15 { ATTR_MCU_RESET_REASON, "MCU Reset Reason", ATTRIBUTE_TYPE_UTF8S, 64 },
Rhyme 0:87662653a3c6 16
Rhyme 0:87662653a3c6 17 { ATTR_LED, "LED", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:87662653a3c6 18 { ATTR_IO0, "I/O 0", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:87662653a3c6 19 { ATTR_IO1, "I/O 1", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:87662653a3c6 20 { ATTR_IO2, "I/O 2", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:87662653a3c6 21 { ATTR_BUTTON, "BUTTON", ATTRIBUTE_TYPE_BOOLEAN, 2 },
Rhyme 0:87662653a3c6 22 { ATTR_IO3, "I/O 3", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:87662653a3c6 23 { ATTR_BOOT_LOADER_VER, "Bootloader Version", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:87662653a3c6 24 { ATTR_BLE_STACK_VER, "BLE Stack Version", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:87662653a3c6 25 { ATTR_FW_APP_VER, "FW Application Version", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:87662653a3c6 26 { ATTR_DEVICE_DESC, "Device Description", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:87662653a3c6 27 { ATTR_WIFI_VER, "Wi-Fi chip", ATTRIBUTE_TYPE_SINT64, 8 },
Rhyme 0:87662653a3c6 28 { ATTR_OFFLINE_SCHED, "Offline Schedules enable", ATTRIBUTE_TYPE_SINT16, 2 },
Rhyme 0:87662653a3c6 29 { ATTR_SECURITY_ENABLED, "Security Enabled", ATTRIBUTE_TYPE_SINT8, 1 }, /* ? */
Rhyme 0:87662653a3c6 30 { ATTR_UTC_OFFSET, "UTC offset data", ATTRIBUTE_TYPE_BYTES, 8 },
Rhyme 0:87662653a3c6 31 { ATTR_CONFIGURES_SSID, "Configured SSID", ATTRIBUTE_TYPE_UTF8S, 10 }, /* ? */
Rhyme 0:87662653a3c6 32 { ATTR_WIFI_BARS, "Wi-Fi Bars", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:87662653a3c6 33 { ATTR_WIFI_STDY_STATE, "Wi-Fi Steady State", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:87662653a3c6 34 { ATTR_COMMAND, "Command", ATTRIBUTE_TYPE_BYTES, 8 }, /* ? */
Rhyme 0:87662653a3c6 35 { ATTR_ASR_STATE, "ASR State", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:87662653a3c6 36 { ATTR_LOW_BATTERY, "Low Battery Warning", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:87662653a3c6 37 { ATTR_LINKED_TIMESTAMP, "Linked Timestamp", ATTRIBUTE_TYPE_SINT32, 4 },
Rhyme 0:87662653a3c6 38 { ATTR_ATTR_ACK, "Attribute ACK", ATTRIBUTE_TYPE_SINT16, 8 },
Rhyme 0:87662653a3c6 39 { ATTR_REBOOT_REASON, "Reboot Reason", ATTRIBUTE_TYPE_UTF8S, 100 },
Rhyme 0:87662653a3c6 40 { ATTR_BLE_COMMS, "BLE Comms", ATTRIBUTE_TYPE_BYTES, 12 },
Rhyme 0:87662653a3c6 41 { ATTR_MCU_INTERFACE, "MCU Interface", ATTRIBUTE_TYPE_SINT8, 1 },
Rhyme 0:87662653a3c6 42 { 0, 0, 0, 0 }
Rhyme 0:87662653a3c6 43 } ;
Rhyme 0:87662653a3c6 44 #endif
Rhyme 0:87662653a3c6 45
Rhyme 0:87662653a3c6 46 int get_af_attr(uint16_t id)
Rhyme 0:87662653a3c6 47 {
Rhyme 0:87662653a3c6 48 int i ;
Rhyme 0:87662653a3c6 49 for (i = 0 ; af_attr[i].id != 0 ; i++ ) {
Rhyme 0:87662653a3c6 50 if (id == af_attr[i].id) {
Rhyme 0:87662653a3c6 51 break ;
Rhyme 0:87662653a3c6 52 }
Rhyme 0:87662653a3c6 53 }
Rhyme 0:87662653a3c6 54 return (i) ;
Rhyme 0:87662653a3c6 55 }
Rhyme 0:87662653a3c6 56
Rhyme 0:87662653a3c6 57 void print_af_error(int resultCode)
Rhyme 0:87662653a3c6 58 {
Rhyme 0:87662653a3c6 59 switch(resultCode) {
Rhyme 0:87662653a3c6 60 case afSUCCESS:
Rhyme 0:87662653a3c6 61 tty->printf("Operation completed successfully\n") ;
Rhyme 0:87662653a3c6 62 break ;
Rhyme 0:87662653a3c6 63 case afERROR_NO_SUCH_ATTRIBUTE:
Rhyme 0:87662653a3c6 64 tty->printf("Request was made for unknown attribute id\n") ;
Rhyme 0:87662653a3c6 65 break ;
Rhyme 0:87662653a3c6 66 case afERROR_BUSY:
Rhyme 0:87662653a3c6 67 tty->printf("Request already in progress, try again\n") ;
Rhyme 0:87662653a3c6 68 break ;
Rhyme 0:87662653a3c6 69 case afERROR_INVALID_COMMAND:
Rhyme 0:87662653a3c6 70 tty->printf("Command could not be parsed\n") ;
Rhyme 0:87662653a3c6 71 break ;
Rhyme 0:87662653a3c6 72 case afERROR_QUEUE_OVERFLOW:
Rhyme 0:87662653a3c6 73 tty->printf("Queue is full\n") ;
Rhyme 0:87662653a3c6 74 break ;
Rhyme 0:87662653a3c6 75 case afERROR_QUEUE_UNDERFLOW:
Rhyme 0:87662653a3c6 76 tty->printf("Queue is empty\n") ;
Rhyme 0:87662653a3c6 77 break ;
Rhyme 0:87662653a3c6 78 case afERROR_INVALID_PARAM:
Rhyme 0:87662653a3c6 79 tty->printf("Bad input parameter\n") ;
Rhyme 0:87662653a3c6 80 break ;
Rhyme 0:87662653a3c6 81 default:
Rhyme 0:87662653a3c6 82 tty->printf("Unknown error code %d\n", resultCode) ;
Rhyme 0:87662653a3c6 83 break ;
Rhyme 0:87662653a3c6 84 }
Rhyme 0:87662653a3c6 85 }
Rhyme 0:87662653a3c6 86
Rhyme 0:87662653a3c6 87 void af_print_values(
Rhyme 0:87662653a3c6 88 const uint8_t requestId,
Rhyme 0:87662653a3c6 89 const uint16_t attributeId,
Rhyme 0:87662653a3c6 90 const uint16_t valueLen,
Rhyme 0:87662653a3c6 91 const uint8_t *value
Rhyme 0:87662653a3c6 92 )
Rhyme 0:87662653a3c6 93 {
Rhyme 0:87662653a3c6 94 int i, id ;
Rhyme 0:87662653a3c6 95
Rhyme 0:87662653a3c6 96 id = get_af_attr(attributeId) ;
Rhyme 0:87662653a3c6 97
Rhyme 0:87662653a3c6 98 if (af_attr[id].id != 0) {
Rhyme 0:87662653a3c6 99 tty->printf(af_attr[id].description) ;
Rhyme 0:87662653a3c6 100 tty->printf(" : ") ;
Rhyme 0:87662653a3c6 101 switch(af_attr[id].attribute_type) {
Rhyme 0:87662653a3c6 102 case ATTRIBUTE_TYPE_BOOLEAN:
Rhyme 0:87662653a3c6 103 case ATTRIBUTE_TYPE_SINT8:
Rhyme 0:87662653a3c6 104 if (valueLen >= 1) {
Rhyme 0:87662653a3c6 105 tty->printf("%02X\n", value[0]) ;
Rhyme 0:87662653a3c6 106 }
Rhyme 0:87662653a3c6 107 break ;
Rhyme 0:87662653a3c6 108 case ATTRIBUTE_TYPE_SINT16:
Rhyme 0:87662653a3c6 109 if (valueLen >= 2) {
Rhyme 0:87662653a3c6 110 tty->printf("%02X%02X\n", value[1], value[0]) ;
Rhyme 0:87662653a3c6 111 }
Rhyme 0:87662653a3c6 112 break ;
Rhyme 0:87662653a3c6 113 case ATTRIBUTE_TYPE_SINT32:
Rhyme 0:87662653a3c6 114 if (valueLen >= 4) {
Rhyme 0:87662653a3c6 115 tty->printf("%02X%02X%02X%02X\n",
Rhyme 0:87662653a3c6 116 value[3],value[2],value[1],value[0]) ;
Rhyme 0:87662653a3c6 117 }
Rhyme 0:87662653a3c6 118 break ;
Rhyme 0:87662653a3c6 119 case ATTRIBUTE_TYPE_SINT64:
Rhyme 0:87662653a3c6 120 if (valueLen >= 8) {
Rhyme 0:87662653a3c6 121 tty->printf("%02X%02X %02X%02X %02X%02X %02X%02X\n",
Rhyme 0:87662653a3c6 122 value[7], value[6], value[5], value[4],
Rhyme 0:87662653a3c6 123 value[3], value[2], value[1], value[0]) ;
Rhyme 0:87662653a3c6 124 }
Rhyme 0:87662653a3c6 125 break ;
Rhyme 0:87662653a3c6 126 case ATTRIBUTE_TYPE_UTF8S:
Rhyme 0:87662653a3c6 127 if (valueLen > 0) {
Rhyme 0:87662653a3c6 128 for (i = 0 ; i < valueLen ; i++) {
Rhyme 0:87662653a3c6 129 if (isprint(value[i])) {
Rhyme 0:87662653a3c6 130 tty->printf("%c", value[i]) ;
Rhyme 0:87662653a3c6 131 } else if (value[i] == 0) { /* string terminator NULL */
Rhyme 0:87662653a3c6 132 break ;
Rhyme 0:87662653a3c6 133 } else {
Rhyme 0:87662653a3c6 134 tty->printf("\'%02X\'",value[i]) ;
Rhyme 0:87662653a3c6 135 }
Rhyme 0:87662653a3c6 136 }
Rhyme 0:87662653a3c6 137 tty->printf("\n") ;
Rhyme 0:87662653a3c6 138 }
Rhyme 0:87662653a3c6 139 break ;
Rhyme 0:87662653a3c6 140 case ATTRIBUTE_TYPE_BYTES:
Rhyme 0:87662653a3c6 141 default:
Rhyme 0:87662653a3c6 142 if (valueLen > 0) {
Rhyme 0:87662653a3c6 143 for (i = 0 ; i < valueLen ; i++ ) {
Rhyme 0:87662653a3c6 144 tty->printf("%02X ", value[i]) ;
Rhyme 0:87662653a3c6 145 }
Rhyme 0:87662653a3c6 146 tty->printf("\n") ;
Rhyme 0:87662653a3c6 147 }
Rhyme 0:87662653a3c6 148 break ;
Rhyme 0:87662653a3c6 149 }
Rhyme 0:87662653a3c6 150 } else {
Rhyme 0:87662653a3c6 151 if (valueLen > 0) {
Rhyme 0:87662653a3c6 152 for (i = 0 ; i < valueLen ; i++ ) {
Rhyme 0:87662653a3c6 153 tty->printf("%02X ", value[i]) ;
Rhyme 0:87662653a3c6 154 }
Rhyme 0:87662653a3c6 155 tty->printf("\n") ;
Rhyme 0:87662653a3c6 156 }
Rhyme 0:87662653a3c6 157 }
Rhyme 0:87662653a3c6 158 // tty->printf("\n") ;
Rhyme 0:87662653a3c6 159 }
Rhyme 0:87662653a3c6 160
Rhyme 0:87662653a3c6 161 bool assignAttribute(
Rhyme 0:87662653a3c6 162 const uint8_t requestId,
Rhyme 0:87662653a3c6 163 const uint16_t attributeId,
Rhyme 0:87662653a3c6 164 const uint16_t valueLen,
Rhyme 0:87662653a3c6 165 const uint8_t *value,
Rhyme 0:87662653a3c6 166 bool fromRequest
Rhyme 0:87662653a3c6 167 )
Rhyme 0:87662653a3c6 168 {
Rhyme 0:87662653a3c6 169 bool result = true ;
Rhyme 0:87662653a3c6 170 switch(attributeId) {
Rhyme 0:87662653a3c6 171 case ATTR_LINKED_TIMESTAMP: /* timestamp */
Rhyme 0:87662653a3c6 172 set_time(valueLen, value) ; /* 68 us */
Rhyme 0:87662653a3c6 173 // if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:87662653a3c6 174 tty->printf("timestamp = ") ;
Rhyme 0:87662653a3c6 175 print_date_wd(&current_time) ;
Rhyme 0:87662653a3c6 176 // print_time(&current_time) ;
Rhyme 0:87662653a3c6 177 tty->printf("\n") ;
Rhyme 0:87662653a3c6 178 break ;
Rhyme 0:87662653a3c6 179 case ATTR_SOFTWARE_RESET: /* software reset requested! */
Rhyme 0:87662653a3c6 180 if (value[0]) {
Rhyme 0:87662653a3c6 181 printf("Software Reset Requested!\n") ;
Rhyme 0:87662653a3c6 182 reset_watch_dog() ;
Rhyme 0:87662653a3c6 183 // if (fromRequest) afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
Rhyme 0:87662653a3c6 184 wait(0.5) ;
Rhyme 0:87662653a3c6 185 reboot_edge() ;
Rhyme 0:87662653a3c6 186 }
Rhyme 0:87662653a3c6 187 break ;
Rhyme 0:87662653a3c6 188 default:
Rhyme 0:87662653a3c6 189 break ;
Rhyme 0:87662653a3c6 190 }
Rhyme 0:87662653a3c6 191 return result ;
Rhyme 0:87662653a3c6 192 }
Rhyme 0:87662653a3c6 193
Rhyme 0:87662653a3c6 194 /*
Rhyme 0:87662653a3c6 195 * Callback that allows ASR to request an MCU attribute be changed.
Rhyme 0:87662653a3c6 196 * You should define this function in your MCU firmware to perform application-specific actions
Rhyme 0:87662653a3c6 197 * your code must take (e.g., updating the state of the hardware),
Rhyme 0:87662653a3c6 198 * in light of the attribute value change.
Rhyme 0:87662653a3c6 199 */
Rhyme 0:87662653a3c6 200 bool attributeChangeRequest(
Rhyme 0:87662653a3c6 201 const uint8_t requestId,
Rhyme 0:87662653a3c6 202 const uint16_t attributeId,
Rhyme 0:87662653a3c6 203 const uint16_t valueLen,
Rhyme 0:87662653a3c6 204 const uint8_t *value
Rhyme 0:87662653a3c6 205 )
Rhyme 0:87662653a3c6 206 {
Rhyme 0:87662653a3c6 207 int result ;
Rhyme 0:87662653a3c6 208 uint32_t timestamp = edge_time ;
Rhyme 0:87662653a3c6 209
Rhyme 0:87662653a3c6 210 ts2time(timestamp, &current_time) ; /* 12 us */
Rhyme 0:87662653a3c6 211 // if (verbos) {
Rhyme 0:87662653a3c6 212 print_time(&current_time) ;
Rhyme 0:87662653a3c6 213 tty->printf(" %5d ASR requested [%d] : ", attributeId, requestId) ;
Rhyme 0:87662653a3c6 214 af_print_values(requestId, attributeId, valueLen, value) ;
Rhyme 0:87662653a3c6 215 // }
Rhyme 0:87662653a3c6 216
Rhyme 0:87662653a3c6 217 result = assignAttribute(requestId, attributeId, valueLen, value, true) ;
Rhyme 0:87662653a3c6 218
Rhyme 0:87662653a3c6 219 // af_print_values(requestId, attributeId, valueLen, value) ;
Rhyme 0:87662653a3c6 220 return(result == afSUCCESS) ;
Rhyme 0:87662653a3c6 221 }
Rhyme 0:87662653a3c6 222
Rhyme 0:87662653a3c6 223 /*
Rhyme 0:87662653a3c6 224 * Application callback that allows afLib to notify that an attribute has changed.
Rhyme 0:87662653a3c6 225 * This method will be called in response to a getAttribute call from the application
Rhyme 0:87662653a3c6 226 * and whenever a ASR module attribute changes.
Rhyme 0:87662653a3c6 227 */
Rhyme 0:87662653a3c6 228 void attributeUpdatedReport(
Rhyme 0:87662653a3c6 229 const uint8_t requestId,
Rhyme 0:87662653a3c6 230 const uint16_t attributeId,
Rhyme 0:87662653a3c6 231 const uint16_t valueLen,
Rhyme 0:87662653a3c6 232 const uint8_t *value
Rhyme 0:87662653a3c6 233 )
Rhyme 0:87662653a3c6 234 {
Rhyme 0:87662653a3c6 235 uint32_t timestamp = edge_time ;
Rhyme 0:87662653a3c6 236 int result ;
Rhyme 0:87662653a3c6 237
Rhyme 0:87662653a3c6 238 ts2time(timestamp, &current_time) ; /* 12us */
Rhyme 0:87662653a3c6 239 // if (verbos) {
Rhyme 0:87662653a3c6 240 print_time(&current_time) ;
Rhyme 0:87662653a3c6 241 tty->printf(" %5d ASR reported [%d]: ", attributeId, requestId) ;
Rhyme 0:87662653a3c6 242 af_print_values(requestId, attributeId, valueLen, value) ;
Rhyme 0:87662653a3c6 243 // }
Rhyme 0:87662653a3c6 244
Rhyme 0:87662653a3c6 245 switch(attributeId) {
Rhyme 0:87662653a3c6 246 case ATTR_LED:
Rhyme 0:87662653a3c6 247 tty->printf("LED : ") ;
Rhyme 0:87662653a3c6 248 if (value[0]) {
Rhyme 0:87662653a3c6 249 tty->printf("ON\n") ;
Rhyme 0:87662653a3c6 250 } else {
Rhyme 0:87662653a3c6 251 tty->printf("OFF\n") ;
Rhyme 0:87662653a3c6 252 }
Rhyme 0:87662653a3c6 253 break ;
Rhyme 0:87662653a3c6 254 case ATTR_LINKED_TIMESTAMP:
Rhyme 0:87662653a3c6 255 set_time(valueLen, value) ; /* 68 us */
Rhyme 0:87662653a3c6 256 tty->printf("timestamp = ") ;
Rhyme 0:87662653a3c6 257 print_date_wd(&current_time) ;
Rhyme 0:87662653a3c6 258 // print_time(&current_time) ;
Rhyme 0:87662653a3c6 259 tty->printf("\n") ;
Rhyme 0:87662653a3c6 260 break ;
Rhyme 0:87662653a3c6 261 case ATTR_WIFI_STDY_STATE:
Rhyme 0:87662653a3c6 262 gConnected = false ;
Rhyme 0:87662653a3c6 263 tty->printf("WiFi Steady State: ") ;
Rhyme 0:87662653a3c6 264 switch(value[0]) {
Rhyme 0:87662653a3c6 265 case 0: tty->printf("Not Connected\n") ; break ;
Rhyme 0:87662653a3c6 266 case 1: tty->printf("Pending\n") ; break ;
Rhyme 0:87662653a3c6 267 case 2:
Rhyme 0:87662653a3c6 268 tty->printf("Connected\n") ;
Rhyme 0:87662653a3c6 269 gConnected = true ; // the only case Connected state is OK
Rhyme 0:87662653a3c6 270 break ;
Rhyme 0:87662653a3c6 271 case 3: tty->printf("Unknown Failure\n") ; break ;
Rhyme 0:87662653a3c6 272 case 4: tty->printf("Association Failed\n") ; break ;
Rhyme 0:87662653a3c6 273 case 5: tty->printf("Handshake Failed\n") ; break ;
Rhyme 0:87662653a3c6 274 case 6: tty->printf("Echo Failed\n") ; break ;
Rhyme 0:87662653a3c6 275 case 7: tty->printf("SSID Not Found\n") ; break ;
Rhyme 0:87662653a3c6 276 case 8: tty->printf("NTP Failed\n") ; break ;
Rhyme 0:87662653a3c6 277 default: tty->printf("Unknown [%d]\n", value[0]) ; break ;
Rhyme 0:87662653a3c6 278 }
Rhyme 0:87662653a3c6 279 break ;
Rhyme 0:87662653a3c6 280 case ATTR_REBOOT_REASON:
Rhyme 0:87662653a3c6 281 tty->printf("Reboot Reason: ") ;
Rhyme 0:87662653a3c6 282 switch(value[0]) {
Rhyme 0:87662653a3c6 283 case 1: tty->printf("Reset pin asserted\n") ; break ;
Rhyme 0:87662653a3c6 284 case 2: tty->printf("Watchdog reset\n") ; break ;
Rhyme 0:87662653a3c6 285 case 4: tty->printf("Software reset\n") ; break ;
Rhyme 0:87662653a3c6 286 case 8: tty->printf("CPU Lock up\n") ; break ;
Rhyme 0:87662653a3c6 287 default: tty->printf("Unknown [%d]\n", value[0]) ; break ;
Rhyme 0:87662653a3c6 288 }
Rhyme 0:87662653a3c6 289 break ;
Rhyme 0:87662653a3c6 290 case ATTR_MCU_INTERFACE:
Rhyme 0:87662653a3c6 291 tty->printf("MCU Interface: ") ;
Rhyme 0:87662653a3c6 292 switch(value[0]) {
Rhyme 0:87662653a3c6 293 case 0: tty->printf("No MCU\n") ; break ;
Rhyme 0:87662653a3c6 294 case 1: tty->printf("SPI Slave\n") ; break ;
Rhyme 0:87662653a3c6 295 case 2: tty->printf("UART\n") ; break ;
Rhyme 0:87662653a3c6 296 default: tty->printf("Unknown\n") ; break ;
Rhyme 0:87662653a3c6 297 }
Rhyme 0:87662653a3c6 298 break ;
Rhyme 0:87662653a3c6 299 case AF_SYSTEM_ASR_STATE:
Rhyme 0:87662653a3c6 300 tty->printf("ASR state: ") ;
Rhyme 0:87662653a3c6 301 switch(value[0]) {
Rhyme 0:87662653a3c6 302 case MODULE_STATE_REBOOTED:
Rhyme 0:87662653a3c6 303 gLinked = false ;
Rhyme 0:87662653a3c6 304 tty->printf("Rebooted\n") ;
Rhyme 0:87662653a3c6 305 wait_ms(100) ;
Rhyme 0:87662653a3c6 306 if (edge_mgr_status == EDGE_MGR_RUNNING) {
Rhyme 0:87662653a3c6 307 reboot_edge() ;
Rhyme 0:87662653a3c6 308 }
Rhyme 0:87662653a3c6 309 break ;
Rhyme 0:87662653a3c6 310 case MODULE_STATE_LINKED:
Rhyme 0:87662653a3c6 311 if (gLinked == false) { /* new link established */
Rhyme 0:87662653a3c6 312 result = afero->getAttribute(ATTR_LINKED_TIMESTAMP) ;
Rhyme 0:87662653a3c6 313 }
Rhyme 0:87662653a3c6 314 gLinked = true ;
Rhyme 0:87662653a3c6 315 tty->printf("Linked\n") ;
Rhyme 0:87662653a3c6 316 break ;
Rhyme 0:87662653a3c6 317 case MODULE_STATE_UPDATING:
Rhyme 0:87662653a3c6 318 gLinked = true ;
Rhyme 0:87662653a3c6 319 tty->printf("Updating\n") ;
Rhyme 0:87662653a3c6 320 break ;
Rhyme 0:87662653a3c6 321 case MOUDLE_STATE_UPDATE_READY:
Rhyme 0:87662653a3c6 322 gLinked = false ;
Rhyme 0:87662653a3c6 323 tty->printf("Update ready - rebooting\n") ;
Rhyme 0:87662653a3c6 324 while(afero->setAttribute32(AF_SYSTEM_COMMAND, MODULE_COMMAND_REBOOT) != afSUCCESS) {
Rhyme 0:87662653a3c6 325 afero->loop() ;
Rhyme 0:87662653a3c6 326 wait_us(100) ;
Rhyme 0:87662653a3c6 327 }
Rhyme 0:87662653a3c6 328 reboot_edge() ;
Rhyme 0:87662653a3c6 329 break ;
Rhyme 0:87662653a3c6 330 default:
Rhyme 0:87662653a3c6 331 break ;
Rhyme 0:87662653a3c6 332 }
Rhyme 0:87662653a3c6 333 break ;
Rhyme 0:87662653a3c6 334 default:
Rhyme 0:87662653a3c6 335 assignAttribute(requestId, attributeId, valueLen, value, false) ;
Rhyme 0:87662653a3c6 336 break ;
Rhyme 0:87662653a3c6 337 }
Rhyme 0:87662653a3c6 338 }