NSData 和 NSMutableData,代表著object-c 的數據緩衝區。
因在對讀/寫BLE,其均為NSData為其對象。
所以,必須介紹這個資料類別的相關使用
NSData的作用:
1.對數據讀取NSData;
2.輸出NSData
A.建立
dataxxx: 類別
initxxxx: 實例
data:建出一個不含任何資料的,空的NSData
dataWithByte:length /initWithBytes:length: 複制C array來初始始化NSData
dataWithNoCopyByte:length /initWithNoCopyBytes:length:
直接利用C array中資料來初始代。只有nsdata 執行relloc才會free C array
dataWithByteNoCopy:length:freeWhenDon: /initWithBytesNoCopy:length:freeWhenDon:
同上,但只有當 最後的參數為YES。且NSData以relloc,程式才會free C array
dataWithContentsOfFile:/initWithContentsOfFile
讀取文件內容並初始化NSData
dataWithContentOfURL:/initWithContentOfURL:
讀取URL文件內容並初始化NSData
dataWithData:/initWithData:
使用另一個NSData來初始化
read/write NSData
bytes: 返回其NSdata數值
getBytes:length: 取得指定長度的資料
getBytes:range: 取得指定範圍的資料
subdataWithRange: 取得指定範圍的資料並組成另一NSData
writeToFile:atomically: 將NSData 寫入 文件
writeToURL:atomically: 將NSData 寫入URL 文件
B.各資料轉換
1. NSData 與 NSString
NSData-> NSString
NSString *aString = [[NSString alloc] initWithData:adataencoding:NSUTF8StringEncoding];
NSString->NSData
NSString *aString = @"1234abcd";
NSData *aData = [aString dataUsingEncoding: NSUTF8StringEncoding];
2.NSData 與 Byte
NSData-> Byte數組
NSString *testString = @"1234567890";
NSData *testData = [testString dataUsingEncoding: NSUTF8StringEncoding];
Byte *testByte = (Byte *)[testData bytes];
for(int i=0;i<[testData length];i++)
printf("testByte = %d\n",testByte[i]);
Byte數組-> NSData
Byte byte[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
NSData *adata = [[NSData alloc] initWithBytes:byte length:24];
Byte數組->16進制數
Byte *bytes = (Byte *)[aData bytes];
NSString *hexStr=@"";
for(int i=0;i<[encryData length];i++)
{
NSString *newHexStr = [NSString stringWithFormat:@"%x",bytes[i]&0xff];///16進制數
if([newHexStr length]==1)
hexStr = [NSString stringWithFormat:@"%@0%@",hexStr,newHexStr];
else
hexStr = [NSString stringWithFormat:@"%@%@",hexStr,newHexStr];
}
NSLog(@"bytes 的16進制數为:%@",hexStr);
16進制數->Byte數組
///// 將16進制數據轉化成Byte 數組
NSString *hexString = @"3e435fab9c34891f"; //16進制字符串
int j=0;
Byte bytes[128]; ///3ds key的Byte 數組, 128位
for(int i=0;i<[hexString length];i++)
{
int int_ch; /// 兩位16進制數轉化後的10進制數
unichar hex_char1 = [hexString characterAtIndex:i]; ////兩位16進制數中的第一位(高位*16)
int int_ch1;
if(hex_char1 >= '0' && hex_char1 <='9')
int_ch1 = (hex_char1-48)*16; //// 0 的Ascll - 48
else if(hex_char1 >= 'A' && hex_char1 <='F')
int_ch1 = (hex_char1-55)*16; //// A 的Ascll - 65
else
int_ch1 = (hex_char1-87)*16; //// a 的Ascll - 97
i++;
unichar hex_char2 = [hexString characterAtIndex:i]; ///兩位16進制數中的第二位(低位)
int int_ch2;
if(hex_char2 >= '0' && hex_char2 <='9')
int_ch2 = (hex_char2-48); //// 0 的Ascll - 48
else if(hex_char1 >= 'A' && hex_char1 <='F')
int_ch2 = hex_char2-55; //// A 的Ascll - 65
else
int_ch2 = hex_char2-87; //// a 的Ascll - 97
int_ch = int_ch1+int_ch2;
NSLog(@"int_ch=%d",int_ch);
bytes[j] = int_ch; ///將轉化後的數放入Byte數組裏
j++;
}
NSData *newData = [[NSData alloc] initWithBytes:bytes length:128];
NSLog(@"newData=%@",newData);
3. NSData 與 UIImage
NSData->UIImage
UIImage *aimage = [UIImage imageWithData: imageData];
//例:從本地文件沙盒中取圖片並轉換为NSData
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *name = [NSString stringWithFormat:@"ceshi.png"];
NSString *finalPath = [path stringByAppendingPathComponent:name];
NSData *imageData = [NSData dataWithContentsOfFile: finalPath];
UIImage *aimage = [UIImage imageWithData: imageData];
UIImage-> NSData
NSData *imageData = UIImagePNGRepresentation(aimae);
http://fanli7.net/a/JAVAbiancheng/j2ee/2012/0519/165001.html
2014年12月3日 星期三
Core Bluetooth ios
keywork:
record,ios, xcode, object-c, central,peripheral ,GATT service and GATT client.
background:
if you need the basic knowledge you can reference previsour information that about the BLE (Bluetooth low energy 4.0 *1).
1. explain
First , every device have only one role (central or peripheral).;
central:
A central typically uses the information served up by peripherals to accomplish some particular task
work scan function and interaction with peripheral.
discovering,
Explore the data,
Send read and write requests
Subscribe to a characteristic’s value).
peripheral:
a peripheral typically has data that is needed by other devices.
which task has
Advertise your services ,
Respond to read and write requests from a connected central
Send updated characteristic values to subscribed centrals
Secode , you should see the Bluetooth Core Special .about the GAP and GATT layer information.
I will map Core Bluetooth ios between Bluetooth Core Special. and the Bluetooth Core Special reference ……….
At BLE 4.0 ,every device only have one role (central or peripheral); which GAP role
about the GATT Service and Client(Bluetooth Core special) ,in which the Group data struct . the role (central and peripheral) can conatin GATT client/service .
but in Core Bluetooth ios ,which not distruction GATT client/service.
the characteristic read/write properties setting is by client .
the central ,should be GATT client ;
another, peripheral is GATT sevice.
you can see next section about this;
2. Implement
A. Perpheral (GATT service)
how to
how to:
* BLE 4.0 ;
every device only have one role action. (central/peripheral); next BLE 4.1 which can work currently .
http://blog.csdn.net/jimoduwu/article/details/8917104
record,ios, xcode, object-c, central,peripheral ,GATT service and GATT client.
background:
if you need the basic knowledge you can reference previsour information that about the BLE (Bluetooth low energy 4.0 *1).
1. explain
First , every device have only one role (central or peripheral).;
central:
A central typically uses the information served up by peripherals to accomplish some particular task
work scan function and interaction with peripheral.
discovering,
Explore the data,
Send read and write requests
Subscribe to a characteristic’s value).
peripheral:
a peripheral typically has data that is needed by other devices.
which task has
Advertise your services ,
Respond to read and write requests from a connected central
Send updated characteristic values to subscribed centrals
Secode , you should see the Bluetooth Core Special .about the GAP and GATT layer information.
I will map Core Bluetooth ios between Bluetooth Core Special. and the Bluetooth Core Special reference ……….
At BLE 4.0 ,every device only have one role (central or peripheral); which GAP role
about the GATT Service and Client(Bluetooth Core special) ,in which the Group data struct . the role (central and peripheral) can conatin GATT client/service .
but in Core Bluetooth ios ,which not distruction GATT client/service.
the characteristic read/write properties setting is by client .
the central ,should be GATT client ;
another, peripheral is GATT sevice.
you can see next section about this;
2. Implement
A. Perpheral (GATT service)
how to
- Start up a peripheral manager object
- initWithDelegate:queue: method of the CBPeripheralManager class
- peripheralManagerDidUpdateState: method of its delegate object
- Set up services and characteristics on your local peripheral
- Build Your Tree of Characteristics
- Services
- associate the characteristic with it by setting the service
- THE properties and permissions,seeCBMutableCharacteristic Class Reference.
- Publish your services and characteristics to your device’s local database
- Advertise your services
- CBAdvertisementDataLocalNameKey and CBAdvertisementDataServiceUUIDsKey
- When you start advertising some of the data on your local peripheral, the peripheral manager calls the
peripheralManagerDidStartAdvertising:error: method of its delegate object - ** when you advertise the services 128 bit uuid ,which is not …
- Respond to read and write requests from a connected central
- receive a simple request to read the value of a characteristic
- central sends a request to write the value of one or more of your characteristics
- ** if you have multi characteristics to read/write
- Send updated characteristic values to subscribed centrals
how to:
- Start up a central manager object
- initWithDelegate:queue:
method of the CBCentralManager class - When you create a central manager, the central manager calls the centralManagerDidUpdateState:
method of its delegate object - Discover and connect to peripheral devices that are advertising
- scanForPeripheralsWithServices:options: method of the CBCentralManager class
- when a interest get
- stop scan
- connectPeripheral:options: method of the
CBCentralManager class - connection request is successful
- Explore the data on a peripheral device after you’ve connected to it
- you may discover that a peripheral has more services than
what it advertises (in its advertising packets). You can discover all of the services that a peripheral offers by
calling the discoverServices: method of the CBPeripheral class - specified services are discovered
- Discovering the Characteristics of a Service
- characteristics of the specified service are discovered.
- Send read and write requests to a characteristic value of a peripheral’s service
- delegate object to retrieve the
value. If the value is successfully retrieved, you can access it through the characteristic’s value property - write its value with some data (an
instance of NSData) by calling the writeValue:forCharacteristic:type: method of the CBPeripheral
class - The peripheral responds to write requests that are specified as CBCharacteristicWriteWithResponse by
calling the peripheral:didWriteValueForCharacteristic:error: method of its delegate object - Subscribe to a characteristic’s value to be notified when it is updated
* BLE 4.0 ;
every device only have one role action. (central/peripheral); next BLE 4.1 which can work currently .
http://blog.csdn.net/jimoduwu/article/details/8917104
2014年11月2日 星期日
My vim @
XCode VIM(XVIM)
Eclipse(Vrapper)
Console Personal Vim
(This is the personal Vim configuration of Danilo Dellaquila.)
reference:
cocoa vim
ViEmu
http://www.viemu.com/store.htmlXVIM
https://github.com/XVimProject/XVimVi Input Manager
http://www.macupdate.com/app/mac/22864/vi-input-managerEclipse VIM
Vrapper
http://vrapper.sourceforge.net/home/eclim
http://eclim.org/Console Personal Vim
Danilo Dellaquila
https://github.com/ddellaquila/dd-vim2014年9月13日 星期六
mBeacon 應用技術研究會
mBeacon 應用技術研究會
時間: 9月9日 ,9:30 ~ 17:00
地點:台大集思堂國際會議中心
人數:70人
主辨單位: 經濟部產業推廝中心/airyzone and 台灣app 交流協會
主題:Beacon 應用
keyword:
beacon’ cloud’ BTLE and App(Find dog.Org ,O2O (offline to Online)
主旨要點:
傑坤 , Find Dog and AiryZone(mBeacon)
分別由傑坤,fing Dog 及 AiryZone (分為上/下午)
傑坤實業:主講人,𤌴坤實業經理 林文傑,內容:未來新的行銷模式
beacon 由apple所提出的概念,它不是新的
技術而新的消費模式。
在apple store(iturn) 中,在全球有五百萬以上的會員,而除了在apple store上依信用卡消費外。
apple 接下來進一步地,想要是如何去利用這些客戶的資料,以提供客戶新形態的消費模式外及消費者體驗等,因此它推出 iBeacon 的概念出來。並積極地推廣它的應用,從室內定位(micro location)
,室入導航,穿載應用最後結合它本身的touch ID 和 i Beacon 。改寫了整個的消費行為。
而在台灣中,雖然很多人有興趣這一部份的。但因遲遲未見到”殺手型 產品”且法律(第三方支付及個人穩私)的不完善,對於台灣的大眾(OEM)大多只有觀望 而 各通訊IC廠投入研發(各通訊晶片開發)。誰也不想當第一個導入及使用,而在其中卻由𤌴坤開始導入,並且在下個月就要推出。今人相當的高興。
它將以實體店面做為服務及體驗 ,並結合周邊商家 形成一個商域 。你在任一家進行購物,beacon就會推廣你所需要的資訊,像是你在附近買咖啡豆藉由雲端系統去預估你需要咖啡機,因此推廣出咖啡機的廣告及折扣,並可藉此得到廣告費及使用費等。
而在實體店面中,它也可以藉由beacon技術去得知你的消費模式。並藉由推廣 廠家的 廣告,來得到廠商的廣告費及提供給廠商在市面上消費者對於產品的觀注等訊息,所以它將以此來向個別的客戶送出適合該消費者所需的訊息,大家都可以得利。對於消費者很容易滿足要求;而提供者(𤌴坤)則不再以買電子產品而是客戶,來賺取廣告/第三方支付手續;廠商則不必要花太多時間就可以了解客戶對產品的接收度及市場反應。
Find Dog.Org :
在𤌴坤的例子中,實在是太多的挑戰及需要時間’硬體成本。而最主要的是在台灣的消費模式比起國外差太多,除了實物外對於其它軟體的態度,根本沒有消費者觀念。
而在這個過渡期中,如何藉由這些的結合形成一個產品。這個就是FindDog.Org的產品,它在國外也己經是推出產品了。它的楖念是藉由beacon 結合雲端中各使用者資訊,來做為找竉物的成功的產品。
目前,市面上的竉物追縱器大多以GPS 來實作。但它實在太重及電量問題,因此現在ble及cloud 的出現,它解決了上述的問題並且可以更好的效率。
我以它的使用情境來說明:
在台灣根據統計有1/3的家庭曾遺失竉物,而找回來的則更少了。因此不論是國’內外對於這個需求一直都是存在。而若以beacon做為它的追蹤器因為它本身的体積及運作時間長 可以不斷地對周邊發出廣播關於這只竉物的資訊 ,這樣子除了讓主人知道它有沒有跑遠外及它的狀態(是在跑/走等)就跟目前的市面上少數見到的beacon產品。而在導入cloud 後,它會變成如何呢?
一但這只竉物走失了,因為它(beacon)還是一直在發出訊息的。而這時若以GPS做為追蹤而一定要在24小時內找到因為它不到一天就沒電了,而且它有著嚴重遮避問題; 而改以beacon加上雲端則話,主人可以向系統提出要求那只要有相同人裝了該系統就可以幫他找到它並且可以主動/被動式的提報它的位置。每個使用者都是一個移動式scaner 。也因為使用者不斷地移動所以可以有效地避開遮避 問題。
我想經過這樣子的例子中,在大家的心中己經有了無限的發想。
AiryZone:
在apple 推出iBeacon後,在國外大廠也都響應了它的未來,不論是通訊廠或系統廠如高通在btle上也推出自家的beacon服務 而在 google也推出它自己的規格。而在台灣AiryZone也推出自家的beacon 規格。而這些太多是差不多的,差在於加入自家的特色等(像是加密/雲端等)就像是mbeacon 。
在國外大廠中,如TI 及freescale等都有推出雲端平台了。但不是藉由Enthernel 就是經由 usb 送給電腦,再藉由電腦送給雲端 。對於ble +雲端 卻很少有廠商推出 。 所以我個人才感到興趣參加該次的研討會。 雖然它沒有在這次會議中來展現,因為它是要去參加它的Development partner才可以見到 。
疑問:
主要是對於AiryZone mBeacon,在下午實作課程中的欵問
在它的內容上,有著不少的錯誤
1. btle 無法配對?
2. btle 無法自動連線?
3. 自家mBeacon與 iBeacon的區分沒說明
4. 沒講到自家雲端和其它的差別?反而只講了ios 上自家包起來的library
https://drive.google.com/file/d/0B2uYQcUgyMUJdldSejBYNE4zU1E/edit?usp=sharing
提交"與會報告書"(整理出時間、場合、標題、演講者姓名、參加者人數、主旨、要點、疑問及感想"並積極發問
時間: 9月9日 ,9:30 ~ 17:00
地點:台大集思堂國際會議中心
人數:70人
主辨單位: 經濟部產業推廝中心/airyzone and 台灣app 交流協會
主題:Beacon 應用
keyword:
beacon’ cloud’ BTLE and App(Find dog.Org ,O2O (offline to Online)
主旨要點:
傑坤 , Find Dog and AiryZone(mBeacon)
分別由傑坤,fing Dog 及 AiryZone (分為上/下午)
傑坤實業:主講人,𤌴坤實業經理 林文傑,內容:未來新的行銷模式
beacon 由apple所提出的概念,它不是新的
技術而新的消費模式。
在apple store(iturn) 中,在全球有五百萬以上的會員,而除了在apple store上依信用卡消費外。
apple 接下來進一步地,想要是如何去利用這些客戶的資料,以提供客戶新形態的消費模式外及消費者體驗等,因此它推出 iBeacon 的概念出來。並積極地推廣它的應用,從室內定位(micro location)
,室入導航,穿載應用最後結合它本身的touch ID 和 i Beacon 。改寫了整個的消費行為。
而在台灣中,雖然很多人有興趣這一部份的。但因遲遲未見到”殺手型 產品”且法律(第三方支付及個人穩私)的不完善,對於台灣的大眾(OEM)大多只有觀望 而 各通訊IC廠投入研發(各通訊晶片開發)。誰也不想當第一個導入及使用,而在其中卻由𤌴坤開始導入,並且在下個月就要推出。今人相當的高興。
它將以實體店面做為服務及體驗 ,並結合周邊商家 形成一個商域 。你在任一家進行購物,beacon就會推廣你所需要的資訊,像是你在附近買咖啡豆藉由雲端系統去預估你需要咖啡機,因此推廣出咖啡機的廣告及折扣,並可藉此得到廣告費及使用費等。
而在實體店面中,它也可以藉由beacon技術去得知你的消費模式。並藉由推廣 廠家的 廣告,來得到廠商的廣告費及提供給廠商在市面上消費者對於產品的觀注等訊息,所以它將以此來向個別的客戶送出適合該消費者所需的訊息,大家都可以得利。對於消費者很容易滿足要求;而提供者(𤌴坤)則不再以買電子產品而是客戶,來賺取廣告/第三方支付手續;廠商則不必要花太多時間就可以了解客戶對產品的接收度及市場反應。
Find Dog.Org :
在𤌴坤的例子中,實在是太多的挑戰及需要時間’硬體成本。而最主要的是在台灣的消費模式比起國外差太多,除了實物外對於其它軟體的態度,根本沒有消費者觀念。
而在這個過渡期中,如何藉由這些的結合形成一個產品。這個就是FindDog.Org的產品,它在國外也己經是推出產品了。它的楖念是藉由beacon 結合雲端中各使用者資訊,來做為找竉物的成功的產品。
目前,市面上的竉物追縱器大多以GPS 來實作。但它實在太重及電量問題,因此現在ble及cloud 的出現,它解決了上述的問題並且可以更好的效率。
我以它的使用情境來說明:
在台灣根據統計有1/3的家庭曾遺失竉物,而找回來的則更少了。因此不論是國’內外對於這個需求一直都是存在。而若以beacon做為它的追蹤器因為它本身的体積及運作時間長 可以不斷地對周邊發出廣播關於這只竉物的資訊 ,這樣子除了讓主人知道它有沒有跑遠外及它的狀態(是在跑/走等)就跟目前的市面上少數見到的beacon產品。而在導入cloud 後,它會變成如何呢?
一但這只竉物走失了,因為它(beacon)還是一直在發出訊息的。而這時若以GPS做為追蹤而一定要在24小時內找到因為它不到一天就沒電了,而且它有著嚴重遮避問題; 而改以beacon加上雲端則話,主人可以向系統提出要求那只要有相同人裝了該系統就可以幫他找到它並且可以主動/被動式的提報它的位置。每個使用者都是一個移動式scaner 。也因為使用者不斷地移動所以可以有效地避開遮避 問題。
我想經過這樣子的例子中,在大家的心中己經有了無限的發想。
AiryZone:
在apple 推出iBeacon後,在國外大廠也都響應了它的未來,不論是通訊廠或系統廠如高通在btle上也推出自家的beacon服務 而在 google也推出它自己的規格。而在台灣AiryZone也推出自家的beacon 規格。而這些太多是差不多的,差在於加入自家的特色等(像是加密/雲端等)就像是mbeacon 。
在國外大廠中,如TI 及freescale等都有推出雲端平台了。但不是藉由Enthernel 就是經由 usb 送給電腦,再藉由電腦送給雲端 。對於ble +雲端 卻很少有廠商推出 。 所以我個人才感到興趣參加該次的研討會。 雖然它沒有在這次會議中來展現,因為它是要去參加它的Development partner才可以見到 。
疑問:
主要是對於AiryZone mBeacon,在下午實作課程中的欵問
在它的內容上,有著不少的錯誤
1. btle 無法配對?
2. btle 無法自動連線?
3. 自家mBeacon與 iBeacon的區分沒說明
4. 沒講到自家雲端和其它的差別?反而只講了ios 上自家包起來的library
https://drive.google.com/file/d/0B2uYQcUgyMUJdldSejBYNE4zU1E/edit?usp=sharing
提交"與會報告書"(整理出時間、場合、標題、演講者姓名、參加者人數、主旨、要點、疑問及感想"並積極發問
訂閱:
文章 (Atom)


