2014年12月14日 星期日

enum container always int

 

keyword:

compiler options,gcc,static lib and linker

在使用外部協力商所給的lib(static lib)出現了..

Cannot link object as its attributes are incompatible with the image attributes

原本,以為是那邊給錯了..所以試著去查了一下它的內容.用gnu Binutils(ar,nm)

看看是那邊有問題,依著Linker Error 可能原因有

a.alignment

b.endian

c.different --fpu

但,看起來這幾項都不應該出現.

除了去信要求協力商再次檢查其lib 外.

而其中,原本是懷疑是c ,即它可能用到float point運算.

A.

但,我還是得先以gcc Binutils(ar and nm)去看一下是不是它原本就有問題.像是給錯或檔案毀壞. 其結果如下.

image

fig . readelf . to check the ABI versiion and endian

image

fig. ar . static lib to check the conatin .

image

fig . nm ; to show the symbol

由上可得出,能排及b (endian)及obj file 毀壞.

而我還是不能得到它的原因.因此

請其它同事以不同的案子去試著linker. 卻是正常的

所以看了一下它的環境,才得出這個答案.enum container always int

B.

在disable 原本在compiler對於enum container always int 設定後.

C陷阱篇之enum默认长度 以這篇所敘述的內容.

"enum是一种数据类型,使用时会检查类型匹配".因此

    enum长度不确定会带来可移植性问题,如果第三方库API接口使用enum类型,编译和调用库时一旦有关enum长度的编译器设置不一致,API接口层对数值的解析就不匹配。比如上层应用编译时没有用-fshort-enums,默认用4字节空间来存储使用enum变量,而编译库时设置了fshort-enums,则库内部此enum size可能为1。当把enum变量地址传进API时,内部只修改变量最低字节,高3字节值无变化(内容随机),API返回时,上层使用的4字节enum变量值就可能随机。(潜规则篇之API接口)

"因此内部代码使用enum类型优于define,但对外API接口尽量避免用enum型。"

C.

那麻,這個問題要如何由gcc Binutils 去檢查?

它是由對外的API 所宣告的enum所造成的,因此首先就是對所有對於的API (nm 中的T)

但我自己建立lib後,卻不論是否有enable enum container always int 其程式也是可以動作??而且以objdump 也沒看到它有去檢查??

D.

最後,在未來建立自己的Lib及使用它人的Lib這些都需要特別注意

C潜规则篇之API接口

http://blog.csdn.net/ipmux/article/details/17309277

ref:

Linker Error: L6242E: Cannot link object <objname> as its attributes are incompatible with the image attributes.

http://infocenter.arm.com/help/topic/com.arm.doc.faqs/ka4223.html

gnu gcc basic

https://docs.google.com/document/d/1rKNprDiocE094tU3xq_waHIN-tHpY_Tuum84pSoTEZE/edit?usp=sharing

http://infocenter.arm.com/help/topic/com.arm.doc.dui0491f/Babjddhe.html

https://answers.launchpad.net/gcc-arm-embedded/+question/224724

http://infocenter.arm.com/help/topic/com.arm.doc.dui0348c/CHDIBFAB.html

http://blog.csdn.net/ipmux/article/details/17334099

2014年12月4日 星期四

NSData User

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
image  
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;
image
2. Implement
A. Perpheral (GATT service)
how to
  • Start up a peripheral manager object
    • initWithDelegate:queue: method of the CBPeripheralManager class
    • image
    • peripheralManagerDidUpdateState: method of its delegate object
  • Set up services and characteristics on your local peripheral
    • image
    • Build Your Tree of Characteristics
    • image
    • Services
    • image
    • associate the characteristic with it by setting the service
    • image
    • THE properties and permissions,seeCBMutableCharacteristic Class Reference.
  • Publish your services and characteristics to your device’s local database
    • image
    • peripheralManager:didAddService:error: method of its delegate object.
    • image
  • Advertise your services
    • CBAdvertisementDataLocalNameKey and CBAdvertisementDataServiceUUIDsKey
    • image
    • When you start advertising some of the data on your local peripheral, the peripheral manager calls the
      peripheralManagerDidStartAdvertising:error: method of its delegate object
    • image
    • ** 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
    • image
    • image
    • image
    • image
    •   central sends a request to write the value of one or more of your characteristics
    • image
    • image
    • ** if you have multi characteristics to read/write
    • 螢幕快照 2014-12-04 上午11.28.45
  • Send updated characteristic values to subscribed centrals
    • the subscribed characterstic is for enable the notify from central and stop adversting
    • image
    • updated value of the characteristic and send it to the central
    • image
    • Support Notifications
    • image
B.Central Role Tasks
how to:
  • Start up a central manager object
    • initWithDelegate:queue:
      method of the CBCentralManager class
    • image
    • 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
    • image
    • when a interest get
    • image
    • stop scan
    • image 
    • connectPeripheral:options: method of the
      CBCentralManager class
    • image
    • connection request is successful
    • image
    • image
  • 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
    • image
    • specified services are discovered
    • image
    • Discovering the Characteristics of a Service
    • image
    • characteristics of the specified service are discovered.
    • image
  • Send read and write requests to a characteristic value of a peripheral’s service
    • image
    • delegate object to retrieve the
      value. If the value is successfully retrieved, you can access it through the characteristic’s value property
    • image
    •   write its value with some data (an
      instance of NSData) by calling the writeValue:forCharacteristic:type: method of the CBPeripheral
      class
    • image
    • The peripheral responds to write requests that are specified as CBCharacteristicWriteWithResponse by
      calling the peripheral:didWriteValueForCharacteristic:error: method of its delegate object
    • image
  • Subscribe to a characteristic’s value to be notified when it is updated
    • Though reading the value of a characteristic using the readValueForCharacteristic: method can be
      effective for some use cases, it is not the most efficient way to retrieve a value that changes.
    • image
    • image
p.s:
* 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.html

XVIM

https://github.com/XVimProject/XVim

Vi Input Manager

http://www.macupdate.com/app/mac/22864/vi-input-manager

Eclipse VIM

Vrapper

http://vrapper.sourceforge.net/home/

eclim

http://eclim.org/

Console Personal Vim

Danilo Dellaquila

https://github.com/ddellaquila/dd-vim

2014年10月10日 星期五

nRF51 @ Mac - overview











螢幕快照 2014-10-02 上午8.59.39 Fig 1. program tool(rknrfgo)

 螢幕快照 2014-10-02 下午5.54.23
Fig 2. Sniffer tools(nrf-ble-sniffer-osx)

 螢幕快照 2014-10-02 下午5.57.17
Fig 3. Wireshark ,need XQuartz
螢幕快照 2014-10-02 下午9.40.56
Fig 4.Spectum (iRF Explorer
螢幕快照 2014-10-02 上午9.37.46
Fig 6.IDE(Eclipse)nrf51osx
reference :

The J-Link hardware debugging Eclipse plug-in

http://gnuarmeclipse.livius.net/blog/jlink-debugging/
nRF51 tools
http://sourceforge.net/u/rolandking/profile/
iRF Explore
http://micro.arocholl.com/
wireshark
https://www.wireshark.org/download.html
XQuartz
http://xquartz.macosforge.org/landing/

2014年10月4日 星期六

Use BTLE Soc with other Vendor BTLE Compatibility issue

在之前介紹該vendor ble SoC 時, 曾提到感覺它的相容性問題.

那時,指的是它在連接時卡卡的(有時連不上)

而事實上,它的連接方式的確有相容性問題.

AMICCOM -BLE SOC A8105

http://stevenlin08book.blogspot.tw/2014/04/amiccom-ble-soc-a8105.html

 

keywork :

BLE SoC, Central mode and LL(link layer)

 

之前,有個案子原本是想要以這顆 加上 另外可支援Central Mode的SoC 應用.

但那時,實際動作後. 發現有問題(可連接.但不能找到A8105的服務)

因為我那時還沒有ble sniffer的設備,查看它通訊內容

雖然有發信給原廠人員詢問但沒得到回應.

在這次在作Central的前期開發時,隨便將該issue列入.並得到初步的結論.

 

1. normal v.s Abnormal

image

Fig 1. Normal , iphone and vendor soc

image

Fig 2.Abnormal, My Central and vendor Ble

 

在上面二MSC(message sequence char)中的不同,

1.告訴對方LL version

2.兩端交換MTU

3.Find By Type value Request

前二項,應不是必要的要求, 但在主要在第3點上的內容

可以看出一方,

find by type value request , device name , handle …..

而另一方則是以

find by type value request ,GATT primary service

 

這是因在Central Mode Ble Soc 定義中,定義了GATT primary service來提供資訊;

而在vendor ble soc, 則並不是由此來提供.

因此, 當Central Mode Ble soc 在連線後, 相vendor ble soc 提出 find the type value request 時,

因它不認得, 所以它也不會去反應. 導致整個系統沒有反應.

 

而另外,我也以第三家(TI CC2541)做為測試

image

Fig 3.the sendor vendor ble soc with iphone .

由這三家的系統中,可它們在第一個 read by (group) type request , 各有些不同

A. type, name

B.type. value ,primary service

C.group type,primary service

所以,在未來對於在整合不同家的系統時.可能需注意到這點.