-
Notifications
You must be signed in to change notification settings - Fork 5
/
system-binary-bluetooth-patch.patch
120 lines (105 loc) · 5.92 KB
/
system-binary-bluetooth-patch.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
diff --git a/usr/palm/services/com.palm.service.bluetooth.spp/BluetoothSppAssistant.js b/usr/palm/services/com.palm.service.bluetooth.spp/BluetoothSppAssistant.js
index a019a57..6d30904 100644
--- a/usr/palm/services/com.palm.service.bluetooth.spp/BluetoothSppAssistant.js
+++ b/usr/palm/services/com.palm.service.bluetooth.spp/BluetoothSppAssistant.js
@@ -76,20 +76,15 @@ BluetoothSppAssistant.prototype = {
},
openFiles: function(instanceId,activityId,future) {
- var txHandle = 0 ,rxHandle = 0;
-
- if(isNaN(instanceId)){
- throw ({'errorCode':"OPEN_ERROR","errorText":"Invalid Parameter"});
- }
-
+ var txHandle = 0 ,rxHandle = 0;
var txFileName = SPP_TX_FILE_PREFIX + instanceId;
var rxFileName = SPP_RX_FILE_PREFIX + instanceId;
logger.log("Input file: " + rxFileName);
- logger.log("Output file: " + txFileName);
+ logger.log("Output file: " + txFileName);
logger.log("txHandle = ",+txHandle);
- logger.log("rxHandle = ",+rxHandle);
+ logger.log("rxHandle = ",+rxHandle);
txHandle = fs.openSync(txFileName,"w+");
if(rxHandle === -1){
@@ -106,7 +101,7 @@ BluetoothSppAssistant.prototype = {
//Store Tx/Rx handles in table
if(mapTable[instanceId] === undefined){
- mapTable[instanceId] = { "rxHandle":rxHandle , "txHandle":txHandle,"subscription":false };
+ mapTable[instanceId] = { "rxHandle":rxHandle , "txHandle":txHandle,"subscription":false };
//Monitor the activity so we can disconnect if app goes away.
if(activityId !== undefined){
@@ -145,7 +140,7 @@ BluetoothSppAssistant.prototype = {
future.result = { returnValue : true };
},
- writeData:function(instanceId,data,dataLength,future) {
+ writeData:function(instanceId,data,dataLength,future,_encoding) {
if(mapTable[instanceId] === undefined){
throw ({"errorCode":"NO_DATA_CHANNEL", "errorText": "Data channel for instanceId doesn't exist" });
@@ -154,7 +149,7 @@ BluetoothSppAssistant.prototype = {
throw ({"errorCode":"INVALID_PARAMETER", "errorText": "Invalid parameter"});
}
var txHandle = mapTable[instanceId].txHandle;
- var buffer = new Buffer(data,encoding='utf8');
+ var buffer = new Buffer(data,encoding=_encoding);
fs.write( txHandle , buffer , 0 , dataLength , null , function( err , written ){
if(err){
@@ -164,13 +159,13 @@ BluetoothSppAssistant.prototype = {
});
},
- readData:function(instanceId,dataLength,future) {
+ readData:function(instanceId,dataLength,future,encoding) {
if(mapTable[instanceId] === undefined){
throw ({"errorCode":"NO_DATA_CHANNEL", "errorText": "Data channel for instanceId doesn't exist" });
}
var rxHandle = mapTable[instanceId].rxHandle;
- fs.read( rxHandle, dataLength , null , 'utf8' , function( err , str , bytesRead ){
+ fs.read( rxHandle, dataLength , null , encoding , function( err , str , bytesRead ){
if(err){
throw ({"errorCode":"READ_ERROR", "errorText": "Error in read"});
}
@@ -323,7 +318,7 @@ BluetoothSppAssistant.prototype = {
}
},
- readStream: function(instanceId,subscription,future) {
+ readStream: function(instanceId,subscription,future,encoding) {
if(mapTable[instanceId] === undefined){
throw ({"errorCode":"NO_DATA_CHANNEL", "errorText": "Data channel for instanceId doesn't exist" });
@@ -341,7 +336,7 @@ BluetoothSppAssistant.prototype = {
readStream.addListener('data', function readData(buffer) {
if(mapTable[instanceId].subscription){
- var data = buffer.toString('utf8',0,buffer.length);
+ var data = buffer.toString(encoding,0,buffer.length);
subscription.get().result = {"data":data,"dataLength":buffer.length};
}else{
cleanup(true);
diff --git a/usr/palm/services/com.palm.service.bluetooth.spp/BluetoothSppCommands.js b/usr/palm/services/com.palm.service.bluetooth.spp/BluetoothSppCommands.js
index 1867880..f0cdc4e 100644
--- a/usr/palm/services/com.palm.service.bluetooth.spp/BluetoothSppCommands.js
+++ b/usr/palm/services/com.palm.service.bluetooth.spp/BluetoothSppCommands.js
@@ -30,7 +30,7 @@ ReadCommandAssistant.prototype.run = function(future)
var args = this.controller.args;
var assistant = this.controller.service.assistant;
if(!args.path){
- var result = assistant.readData(args.instanceId,args.dataLength,future);
+ var result = assistant.readData(args.instanceId,args.dataLength,future,args.encoding||"utf8");
}else{
var result = assistant.readFile(args.instanceId,args.path,args.dataLength,future);
}
@@ -46,7 +46,7 @@ ReadStreamCommandAssistant.prototype = {
if(subscription !== undefined){
logger.log("ReadStreamCommandAssistant:subscription defined");
assistant.subscriptionMgr(args.instanceId,true);
- var result = assistant.readStream(args.instanceId,subscription,future);
+ var result = assistant.readStream(args.instanceId,subscription,future,args.encoding||"utf8");
}
},
@@ -66,7 +66,7 @@ WriteCommandAssistant.prototype.run = function(future)
var args = this.controller.args;
var assistant = this.controller.service.assistant;
if(!args.path){
- var result = assistant.writeData(args.instanceId,args.data,args.dataLength,future);
+ var result = assistant.writeData(args.instanceId,args.data,args.dataLength,future,args.encoding||"utf8");
}else{
var result = assistant.writeFile(args.instanceId,args.path,future);
}