Repository navigation
Expand file tree
/
Copy pathUartService.java
More file actions
executable file
·179 lines (150 loc) · 4.41 KB
/
Copy pathUartService.java
File metadata and controls
executable file
·179 lines (150 loc) · 4.41 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package com.android.server;
import android.util.Slog;
import android.content.Context;
import android.os.IUartService;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.os.UserHandle;
import android.content.IntentFilter;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class UartService extends IUartService.Stub {
private static final String TAG = "UartService";
private static int mUartPtr = 0;
private static Lock lock = new ReentrantLock();
private final Context mContext;
private MyReceiver myReceiver;
private IntentFilter intentFilter;
public UartService(Context context) {
mContext = context;
mUartPtr = native_uartopen();
if(mUartPtr < 0){
Slog.e(TAG, "Failed to init uart service.");
}
myReceiver = new MyReceiver();
intentFilter = new IntentFilter();
intentFilter.addAction("android.intent.action.BOOT_COMPLETED");
intentFilter.addAction(Intent.ACTION_USER_SYLINCOM_UART);
mContext.registerReceiver(myReceiver, intentFilter);
}
public class MyReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")){
new Thread(){
@Override
public void run() {
try
{
while(true)
{
Slog.i(TAG, "wo shi zi xian cheng .");
if(UartService.native_alarmtouser()==1)
{
//intent.putExtra("temp", 1);
//mContext.sendBroadcast(intent);
//mContext.sendBroadcastAsUser(intent,UserHandle.ALL);
// Intent intent = new Intent(Intent.ACTION_USER_SYLINCOM_UART);
Intent intent = new Intent(Intent.ACTION_USER_SYLINCOM_UART);
//intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
//intent.putExtra("time-zone", zone.getID());
mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
//mContext.sendStickvBroadcast(intent);
}
Thread.sleep(3000);
}
}catch(Exception e)
{
Slog.i(TAG, "warning UartService sendBroadcast."+e.getMessage());
e.printStackTrace();
}
}
}.start();
}
else if (intent.getAction().equals(Intent.ACTION_USER_SYLINCOM_UART))
{
Slog.i(TAG, "ACTION_USER_SYLINCOM_UART received");
}
}
}
public int pwm(int number, int val){
int ret;
if(mUartPtr < 0){
Slog.e(TAG, "uart service is not initialized.");
}
Slog.i(TAG, "\033[0;32m uart service, pwm \033[0;0m\n");
lock.lock();
try {
ret = native_pwm(number, val);
}finally{
lock.unlock();
}
return ret;
}
public int funspeed(int number){
int ret;
if(mUartPtr < 0){
Slog.e(TAG, "uart service is not initialized.");
}
Slog.i(TAG, "\033[0;32m uart service, funspeed \033[0;0m\n");
lock.lock();
try {
ret = native_funspeed(number);
}finally{
lock.unlock();
}
return ret;
}
public int stepmotor(int dir, int beats){
int ret;
if(mUartPtr < 0){
Slog.e(TAG, "uart service is not initialized.");
}
Slog.i(TAG, "\033[0;32m uart service, stepmotor \033[0;0m\n");
lock.lock();
try {
ret = native_stepmotor(dir, beats);
}finally{
lock.unlock();
}
return ret;
}
public int temp(){
int ret;
if(mUartPtr < 0){
Slog.e(TAG, "uart service is not initialized.");
}
Slog.i(TAG, "\033[0;32m uart service, temp \033[0;0m\n");
lock.lock();
try {
ret = native_temp();
}finally{
lock.unlock();
}
return ret;
}
public int brightness(){
int ret;
if(mUartPtr < 0){
Slog.e(TAG, "uart service is not initialized.");
}
Slog.i(TAG, "\033[0;32m uart service, brightness \033[0;0m\n");
lock.lock();
try {
ret = native_brightness();
}finally{
lock.unlock();
}
return ret;
}
public int alarmtouser(){
return native_alarmtouser();
}
public static native int native_uartopen();
public static native int native_pwm(int number, int val);
public static native int native_funspeed(int number);
public static native int native_stepmotor(int dir, int beats);
public static native int native_temp();
public static native int native_brightness();
public static native int native_alarmtouser();
}