本帖最后由 pomia 于 2015-12-11 18:04 编辑
XPGWifiSDK 透传数据使用方法:
在APP和MCU之间,有两种方式透传数据:
(1)在产品数据点定义时,定义扩展类型数据点
(2)对不定义数据点的产品直接进行数据透传
设备上报:
1、第一种透传方式,设备mcu按照数据点的定义格式上传即可;APP在didReceiveData中,判断result为0(XPGWifiError_NONE),透传数据放在回传参数的“binary”字段中。
2、第二种透传方式,设备mcu在上传的p0中,第一个字节要填充0x06,后跟自定义数据;APP在didReceiveData中,判断result为-48(XPGWifiError_RAW_DATA_TRANSMIT),则回传参数的“binary”字段会返回透传数据。
iOS代码示例:
- (void)XPGWifiDevice: (XPGWifiDevice *)device didReceiveData: (NSDictionary *)recvInfo result: (int)result { if (XPGWifiError_NONE == result || XPGWifiError_RAW_DATA_TRANSMIT == result) { if (recvInfo) { NSData* binary = [recvInfo valueForKey: @"binary"]; }
} }
Andriod代码示例:
public void didReceiveData(XPGWifiDevice device, java.util.concurrent.ConcurrentHashMap<String, Object> dataMap, int result) { if (XPGWifiErrorCode.XPGWifiError_NONE == result || XPGWifiErrorCode.XPGWifiError_RAW_DATA_TRANSMIT== result) { if (dataMap != null && dataMap.get("binary") != null) { byte[] binary = (byte[]) dataMap.get("binary"); } } }
APP下发:
1、第一种透传方式,APP在XPGWifiDevice类的write接口中,按照数据点定义发送扩展数据;
2、第二种透传方式,APP在XPGWifiDevice类的write接口中,发送的json格式为:{"binary": "xxxxxx"};
iOS代码示例:
char bytes[9] = {1,2,3,4,5,6,7,8,9};
NSData* data = [NSData dataWithBytes:bytes length:sizeof(bytes)];
NSString* _data = [XPGWifiBinary encode:data];
NSMutableDictionary *request = [NSMutableDictionary dictionary];
[request setValue:_data forKey: @"binary"];
NSLog(@"try to send binary: %@", data);
[self.device write:request];
Android 代码示例:
byte []input = {1,2,3,4,5,6,7,8,9};
String value = new String(XPGWifiBinary.encode(input));
final JSONObject jsonsend = new JSONObject();
jsonsend.put("binary", value);
xpgWifiDevice.write(jsonsend.toString());
|