test code 123

Dependencies:   mbed

Fork of LinkNode-Test by Qi Yao

Committer:
youkee
Date:
Fri Oct 28 13:04:10 2016 +0000
Revision:
1:b0d4fbbdb244
Parent:
0:1ad0e04b1bc5
ghhbfdd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
youkee 0:1ad0e04b1bc5 1 /*
youkee 0:1ad0e04b1bc5 2 * Copyright 2016 Google Inc. All Rights Reserved.
youkee 0:1ad0e04b1bc5 3 *
youkee 0:1ad0e04b1bc5 4 * Licensed under the Apache License, Version 2.0 (the "License");
youkee 0:1ad0e04b1bc5 5 * you may not use this file except in compliance with the License.
youkee 0:1ad0e04b1bc5 6 * You may obtain a copy of the License at
youkee 0:1ad0e04b1bc5 7 *
youkee 0:1ad0e04b1bc5 8 * http://www.apache.org/licenses/LICENSE-2.0
youkee 0:1ad0e04b1bc5 9 *
youkee 0:1ad0e04b1bc5 10 * Unless required by applicable law or agreed to in writing, software
youkee 0:1ad0e04b1bc5 11 * distributed under the License is distributed on an "AS IS" BASIS,
youkee 0:1ad0e04b1bc5 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
youkee 0:1ad0e04b1bc5 13 * See the License for the specific language governing permissions and
youkee 0:1ad0e04b1bc5 14 * limitations under the License.
youkee 0:1ad0e04b1bc5 15 */
youkee 0:1ad0e04b1bc5 16
youkee 0:1ad0e04b1bc5 17 #include <stdlib.h>
youkee 0:1ad0e04b1bc5 18 #include "config_change.h"
youkee 0:1ad0e04b1bc5 19
youkee 0:1ad0e04b1bc5 20 #define SENSOR_CONFIG_SIZE 20
youkee 0:1ad0e04b1bc5 21
youkee 0:1ad0e04b1bc5 22 PinType pin_type = ANALOG;
youkee 0:1ad0e04b1bc5 23 int pin = 0;
youkee 0:1ad0e04b1bc5 24 static uint8_t sensorConfig[SENSOR_CONFIG_SIZE];
youkee 0:1ad0e04b1bc5 25
youkee 0:1ad0e04b1bc5 26 bool decode_pin(pb_istream_t *stream, const pb_field_t *field, void * *arg) {
youkee 0:1ad0e04b1bc5 27 goosci_Pin sp = goosci_Pin_init_zero;
youkee 0:1ad0e04b1bc5 28 if (!pb_decode(stream, goosci_Pin_fields, &sp))
youkee 0:1ad0e04b1bc5 29 return false;
youkee 0:1ad0e04b1bc5 30
youkee 0:1ad0e04b1bc5 31 if (sp.which_pin == goosci_Pin_analog_pin_tag) {
youkee 0:1ad0e04b1bc5 32 pin_type = ANALOG;
youkee 0:1ad0e04b1bc5 33 pin = sp.pin.analog_pin.pin;
youkee 0:1ad0e04b1bc5 34
youkee 0:1ad0e04b1bc5 35 }
youkee 0:1ad0e04b1bc5 36 else if (sp.which_pin == goosci_Pin_digital_pin_tag)
youkee 0:1ad0e04b1bc5 37 {
youkee 0:1ad0e04b1bc5 38 pin_type = DIGITAL;
youkee 0:1ad0e04b1bc5 39 pin = sp.pin.digital_pin.pin;
youkee 0:1ad0e04b1bc5 40
youkee 0:1ad0e04b1bc5 41 }
youkee 0:1ad0e04b1bc5 42 else
youkee 0:1ad0e04b1bc5 43 {
youkee 0:1ad0e04b1bc5 44 pin_type = VIRTUAL;
youkee 0:1ad0e04b1bc5 45 }
youkee 0:1ad0e04b1bc5 46 return true;
youkee 0:1ad0e04b1bc5 47 }
youkee 0:1ad0e04b1bc5 48
youkee 0:1ad0e04b1bc5 49 void handle(uint8_t* data, int8_t length) {
youkee 0:1ad0e04b1bc5 50 int8_t size = data[0];
youkee 0:1ad0e04b1bc5 51 bool last = data[1] == 1;
youkee 0:1ad0e04b1bc5 52 if (last) {
youkee 0:1ad0e04b1bc5 53 uint8_t sensorConfig[SENSOR_CONFIG_SIZE];
youkee 0:1ad0e04b1bc5 54 memcpy(sensorConfig, data + 2, size);
youkee 0:1ad0e04b1bc5 55 pb_istream_t stream = pb_istream_from_buffer(sensorConfig, size);
youkee 0:1ad0e04b1bc5 56 goosci_SensorDataRequest sdr = goosci_SensorDataRequest_init_zero;
youkee 0:1ad0e04b1bc5 57 sdr.pin.funcs.decode = &decode_pin;
youkee 0:1ad0e04b1bc5 58 if (!pb_decode(&stream, goosci_SensorDataRequest_fields, &sdr)) {
youkee 0:1ad0e04b1bc5 59 //DEBUG_PRINT("Failed parse of string.");
youkee 0:1ad0e04b1bc5 60 }
youkee 0:1ad0e04b1bc5 61 }
youkee 0:1ad0e04b1bc5 62
youkee 0:1ad0e04b1bc5 63 }