Last active
August 29, 2015 14:04
-
-
Save yume190/c1fd04d6a8f80a0d1b80 to your computer and use it in GitHub Desktop.
Revisions
-
yume190 revised this gist
Aug 2, 2014 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,3 @@ class func receivePacketAskDevice(data:NSData) -> devicePacketReceiver<devicePacketAskDeviceID>{ return receivePacket(data, type: devicePacketAskDeviceID()) } -
yume190 revised this gist
Aug 2, 2014 . 1 changed file with 20 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,27 @@ public class func defaultParameter() -> NSData?{ return packetFactory.sender(devicePacketHeader.commandType.DEFAULT_PARAMETER, content: devicePacketNil())?.pack() } class func receivePacketAskDevice(data:NSData) -> devicePacketReceiver<devicePacketAskDeviceID>{ return receivePacket(data, type: devicePacketAskDeviceID()) } class func receivePacketSetting(data:NSData) -> devicePacketReceiver<devicePacketSetting>{ return receivePacket(data, type: devicePacketSetting()) } class func receivePacketRadios(data:NSData) -> devicePacketReceiver<devicePacketRadios>{ return receivePacket(data, type: devicePacketRadios()) } class func receivePacketReadParameters(data:NSData) -> devicePacketReceiver<devicePacketParameters>{ return receivePacket(data, type: devicePacketParameters()) } class func receivePacketAck(data:NSData) -> devicePacketReceiver<devicePacketAck>{ return receivePacket(data, type: devicePacketAck()) } private class func receivePacket<T where T:Constructible, T:Unpackable>(data:NSData,type:T) -> devicePacketReceiver<T>{ var packet:devicePacketReceiver<T> = devicePacketReceiver(deviceHeader: devicePacketHeader(), deviceContent: type) packet.unpack(data) @@ -14,7 +34,6 @@ if var ct:devicePacketHeader.commandType? = t.packetCommandType(){ switch(ct!){ case .ASK_DEVICE: var result = devicePacketReceiver(deviceHeader: t, deviceContent: devicePacketAskDeviceID()) result.unpack(data) return result -
yume190 created this gist
Aug 2, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ class func receivePacketAskDevice(data:NSData) -> devicePacketReceiver<devicePacketAskDeviceID>{ return receivePacket(data, type: devicePacketAskDeviceID()) } private class func receivePacket<T where T:Constructible, T:Unpackable>(data:NSData,type:T) -> devicePacketReceiver<T>{ var packet:devicePacketReceiver<T> = devicePacketReceiver(deviceHeader: devicePacketHeader(), deviceContent: type) packet.unpack(data) return packet } class func receivePacket2(data:NSData) -> Any?{ var t = devicePacketHeader() t.unpack(data) if var ct:devicePacketHeader.commandType? = t.packetCommandType(){ switch(ct!){ case .ASK_DEVICE: var result = devicePacketReceiver(deviceHeader: t, deviceContent: devicePacketAskDeviceID()) result.unpack(data) return result // return devicePacketReceiver(deviceHeader: t, deviceContent: devicePacketAskDeviceID()).unpack123(data) case .ASK_VERSION: return devicePacketReceiver(deviceHeader: t, deviceContent: devicePacketSetting()) case .RADIO: return devicePacketReceiver(deviceHeader: t, deviceContent: devicePacketRadios()) case .READ_PARAMETERS: return devicePacketReceiver(deviceHeader: t, deviceContent: devicePacketParameters()) case .SAVE_PARAMETERS,.UPDATE_PARAMETER,.DEFAULT_PARAMETER: return devicePacketReceiver(deviceHeader: t, deviceContent: devicePacketAck()) default: print("no one match") } } return nil }