Skip to content

Commit b33bc3d

Browse files
author
jantje
committed
refactoring (removing lots of arduio's) to make names smaller
1 parent b74567d commit b33bc3d

File tree

75 files changed

+809
-717
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+809
-717
lines changed

it.baeyens.arduino.common/src/it/baeyens/arduino/arduino/Serial.java

Lines changed: 65 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
import org.osgi.framework.FrameworkUtil;
3636
import org.osgi.framework.ServiceRegistration;
3737

38-
import it.baeyens.arduino.common.ArduinoConst;
3938
import it.baeyens.arduino.common.Common;
39+
import it.baeyens.arduino.common.Const;
40+
import jssc.SerialNativeInterface;
4041
import jssc.SerialPort;
4142
import jssc.SerialPortEvent;
4243
import jssc.SerialPortEventListener;
@@ -55,19 +56,22 @@ public class Serial implements SerialPortEventListener {
5556
// the static class would have an object that could be closed
5657

5758
/**
58-
* General error reporting, all correlated here just in case I think of something slightly more intelligent to do.
59+
* General error reporting, all correlated here just in case I think of
60+
* something slightly more intelligent to do.
5961
*/
6062
static public void errorMessage(String where, Throwable e) {
61-
Common.log(new Status(IStatus.WARNING, ArduinoConst.CORE_PLUGIN_ID, "Error inside Serial. " + where, e)); //$NON-NLS-1$
63+
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, "Error inside Serial. " + where, e)); //$NON-NLS-1$
6264

6365
}
6466

6567
/**
66-
* If this just hangs and never completes on Windows, it may be because the DLL doesn't have its exec bit set. Why the hell that'd be the case,
67-
* who knows.
68+
* If this just hangs and never completes on Windows, it may be because the
69+
* DLL doesn't have its exec bit set. Why the hell that'd be the case, who
70+
* knows.
6871
*/
6972
public static Vector<String> list() {
7073
try {
74+
SerialNativeInterface tt = new SerialNativeInterface();
7175
String[] portNames;
7276
String OS = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$
7377
if (OS.indexOf("mac") >= 0) { //$NON-NLS-1$
@@ -77,8 +81,9 @@ public static Vector<String> list() {
7781
}
7882
return new Vector<>(Arrays.asList(portNames));
7983
} catch (Error e) {
80-
Common.log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID,
81-
"There is a config problem on your system.\nFor more detail see https://github.com/jantje/arduino-eclipse-plugin/issues/252", e)); //$NON-NLS-1$
84+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
85+
"There is a config problem on your system.\nFor more detail see https://github.com/jantje/arduino-eclipse-plugin/issues/252", //$NON-NLS-1$
86+
e));
8287
Vector<String> ret = new Vector<>();
8388
ret.add("config error:"); //$NON-NLS-1$
8489
ret.add("see https://github.com/jantje/arduino-eclipse-plugin/issues/252"); //$NON-NLS-1$
@@ -146,7 +151,8 @@ public void removeListener(MessageConsumer consumer) {
146151
}
147152

148153
/**
149-
* Returns the number of bytes that have been read from serial and are waiting to be dealt with by the user.
154+
* Returns the number of bytes that have been read from serial and are
155+
* waiting to be dealt with by the user.
150156
*/
151157
public int available() {
152158
return (this.bufferLast - this.bufferIndex);
@@ -180,23 +186,25 @@ public void connect(int maxTries) {
180186
// handle exception
181187
if (++count == maxTries) {
182188
if (SerialPortException.TYPE_PORT_BUSY.equals(e.getExceptionType())) {
183-
Common.log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Serial port " + this.PortName //$NON-NLS-1$
184-
+ " already in use. Try quiting any programs that may be using it", e)); //$NON-NLS-1$
189+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
190+
"Serial port " + this.PortName //$NON-NLS-1$
191+
+ " already in use. Try quiting any programs that may be using it", //$NON-NLS-1$
192+
e));
185193
} else if (SerialPortException.TYPE_PORT_NOT_FOUND.equals(e.getExceptionType())) {
186-
Common.log(
187-
new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID,
188-
"Serial port " + this.PortName //$NON-NLS-1$
189-
+ " not found. Did you select the right one from the project properties -> Arduino -> Arduino?", //$NON-NLS-1$
190-
e));
194+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Serial port " //$NON-NLS-1$
195+
+ this.PortName
196+
+ " not found. Did you select the right one from the project properties -> Arduino -> Arduino?", //$NON-NLS-1$
197+
e));
191198
} else {
192-
Common.log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Error opening serial port " + this.PortName, e)); //$NON-NLS-1$
199+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
200+
"Error opening serial port " + this.PortName, e)); //$NON-NLS-1$
193201
}
194202
return;
195203
}
196204
try {
197205
Thread.sleep(200);
198206
} catch (InterruptedException e1) {
199-
Common.log(new Status(IStatus.WARNING, ArduinoConst.CORE_PLUGIN_ID, "Sleep failed", e1)); //$NON-NLS-1$
207+
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, "Sleep failed", e1)); //$NON-NLS-1$
200208
}
201209
}
202210
// If an exception was thrown, delete port variable
@@ -246,7 +254,8 @@ private void notifyConsumersOfEvent(String message) {
246254
}
247255

248256
/**
249-
* Returns a number between 0 and 255 for the next byte that's waiting in the buffer. Returns -1 if there was no byte (although the user should
257+
* Returns a number between 0 and 255 for the next byte that's waiting in
258+
* the buffer. Returns -1 if there was no byte (although the user should
250259
* first check available() to see if things are ready to avoid this)
251260
*/
252261
public int read() {
@@ -264,8 +273,9 @@ public int read() {
264273
}
265274

266275
/**
267-
* Return a byte array of anything that's in the serial buffer. Not particularly memory/speed efficient, because it creates a byte array on each
268-
* read, but it's easier to use than readBytes(byte b[]) (see below).
276+
* Return a byte array of anything that's in the serial buffer. Not
277+
* particularly memory/speed efficient, because it creates a byte array on
278+
* each read, but it's easier to use than readBytes(byte b[]) (see below).
269279
*/
270280
public byte[] readBytes() {
271281
if (this.bufferIndex == this.bufferLast)
@@ -283,10 +293,12 @@ public byte[] readBytes() {
283293
}
284294

285295
/**
286-
* Grab whatever is in the serial buffer, and stuff it into a byte buffer passed in by the user. This is more memory/time efficient than
296+
* Grab whatever is in the serial buffer, and stuff it into a byte buffer
297+
* passed in by the user. This is more memory/time efficient than
287298
* readBytes() returning a byte[] array.
288299
*
289-
* Returns an int for how many bytes were read. If more bytes are available than can fit into the byte array, only those that will fit are read.
300+
* Returns an int for how many bytes were read. If more bytes are available
301+
* than can fit into the byte array, only those that will fit are read.
290302
*/
291303
public int readBytes(byte outgoing[]) {
292304
if (this.bufferIndex == this.bufferLast)
@@ -308,7 +320,8 @@ public int readBytes(byte outgoing[]) {
308320
}
309321

310322
/**
311-
* Reads from the serial port into a buffer of bytes up to and including a particular character. If the character isn't in the serial buffer, then
323+
* Reads from the serial port into a buffer of bytes up to and including a
324+
* particular character. If the character isn't in the serial buffer, then
312325
* 'null' is returned.
313326
*/
314327
public byte[] readBytesUntil(int interesting) {
@@ -338,10 +351,12 @@ public byte[] readBytesUntil(int interesting) {
338351
}
339352

340353
/**
341-
* Reads from the serial port into a buffer of bytes until a particular character. If the character isn't in the serial buffer, then 'null' is
354+
* Reads from the serial port into a buffer of bytes until a particular
355+
* character. If the character isn't in the serial buffer, then 'null' is
342356
* returned.
343357
*
344-
* If outgoing[] is not big enough, then -1 is returned, and an error message is printed on the console. If nothing is in the buffer, zero is
358+
* If outgoing[] is not big enough, then -1 is returned, and an error
359+
* message is printed on the console. If nothing is in the buffer, zero is
345360
* returned. If 'interesting' byte is not in the buffer, then 0 is returned.
346361
*/
347362
public int readBytesUntil(int interesting, byte outgoing[]) {
@@ -362,8 +377,10 @@ public int readBytesUntil(int interesting, byte outgoing[]) {
362377

363378
int length = found - this.bufferIndex + 1;
364379
if (length > outgoing.length) {
365-
Common.log(new Status(IStatus.WARNING, ArduinoConst.CORE_PLUGIN_ID, "readBytesUntil() byte buffer is too small for the " + length //$NON-NLS-1$
366-
+ " bytes up to and including char " + interesting, null)); //$NON-NLS-1$
380+
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID,
381+
"readBytesUntil() byte buffer is too small for the " + length //$NON-NLS-1$
382+
+ " bytes up to and including char " + interesting, //$NON-NLS-1$
383+
null));
367384
return -1;
368385
}
369386
// byte outgoing[] = new byte[length];
@@ -379,7 +396,8 @@ public int readBytesUntil(int interesting, byte outgoing[]) {
379396
}
380397

381398
/**
382-
* Returns the next byte in the buffer as a char. Returns -1, or 0xffff, if nothing is there.
399+
* Returns the next byte in the buffer as a char. Returns -1, or 0xffff, if
400+
* nothing is there.
383401
*/
384402
public char readChar() {
385403
if (this.bufferIndex == this.bufferLast)
@@ -388,9 +406,11 @@ public char readChar() {
388406
}
389407

390408
/**
391-
* Return whatever has been read from the serial port so far as a String. It assumes that the incoming characters are ASCII.
409+
* Return whatever has been read from the serial port so far as a String. It
410+
* assumes that the incoming characters are ASCII.
392411
*
393-
* If you want to move Unicode data, you can first convert the String to a byte stream in the representation of your choice (i.e. UTF8 or two-byte
412+
* If you want to move Unicode data, you can first convert the String to a
413+
* byte stream in the representation of your choice (i.e. UTF8 or two-byte
394414
* Unicode data), and send it as a byte array.
395415
*/
396416
public String readString() {
@@ -400,9 +420,11 @@ public String readString() {
400420
}
401421

402422
/**
403-
* Combination of readBytesUntil and readString. See caveats in each function. Returns null if it still hasn't found what you're looking for.
423+
* Combination of readBytesUntil and readString. See caveats in each
424+
* function. Returns null if it still hasn't found what you're looking for.
404425
*
405-
* If you want to move Unicode data, you can first convert the String to a byte stream in the representation of your choice (i.e. UTF8 or two-byte
426+
* If you want to move Unicode data, you can first convert the String to a
427+
* byte stream in the representation of your choice (i.e. UTF8 or two-byte
406428
* Unicode data), and send it as a byte array.
407429
*/
408430
public String readStringUntil(int interesting) {
@@ -413,7 +435,8 @@ public String readStringUntil(int interesting) {
413435
}
414436

415437
public void registerService() {
416-
this.fServiceRegistration = FrameworkUtil.getBundle(getClass()).getBundleContext().registerService(Serial.class, this, null);
438+
this.fServiceRegistration = FrameworkUtil.getBundle(getClass()).getBundleContext().registerService(Serial.class,
439+
this, null);
417440
}
418441

419442
public void reset() {
@@ -529,20 +552,24 @@ public void write(int what) { // will also cover char
529552
}
530553

531554
/**
532-
* Write a String to the output. Note that this doesn't account for Unicode (two bytes per char), nor will it send UTF8 characters.. It assumes
533-
* that you mean to send a byte buffer (most often the case for networking and serial i/o) and will only use the bottom 8 bits of each char in the
555+
* Write a String to the output. Note that this doesn't account for Unicode
556+
* (two bytes per char), nor will it send UTF8 characters.. It assumes that
557+
* you mean to send a byte buffer (most often the case for networking and
558+
* serial i/o) and will only use the bottom 8 bits of each char in the
534559
* string. (Meaning that internally it uses String.getBytes)
535560
*
536-
* If you want to move Unicode data, you can first convert the String to a byte stream in the representation of your choice (i.e. UTF8 or two-byte
561+
* If you want to move Unicode data, you can first convert the String to a
562+
* byte stream in the representation of your choice (i.e. UTF8 or two-byte
537563
* Unicode data), and send it as a byte array.
538564
*/
539565
public void write(String what) {
540566
write(what.getBytes());
541567
}
542568

543569
public void write(String what, String LineEnd) {
544-
notifyConsumersOfEvent(System.getProperty("line.separator") + ">>Send to " + this.PortName + ": \"" + what + "\"<<" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
545-
+ System.getProperty("line.separator")); //$NON-NLS-1$
570+
notifyConsumersOfEvent(
571+
System.getProperty("line.separator") + ">>Send to " + this.PortName + ": \"" + what + "\"<<" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
572+
+ System.getProperty("line.separator")); //$NON-NLS-1$
546573
write(what.getBytes());
547574
if (LineEnd.length() > 0) {
548575
write(LineEnd.getBytes());

it.baeyens.arduino.common/src/it/baeyens/arduino/common/Activator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public void start(BundleContext context) throws Exception {
7272

7373
// add required properties for Arduino serial port on linux, if not
7474
// defined
75-
if (Platform.getOS().equals(Platform.OS_LINUX) && System.getProperty(ArduinoConst.ENV_KEY_GNU_SERIAL_PORTS) == null) {
76-
System.setProperty(ArduinoConst.ENV_KEY_GNU_SERIAL_PORTS, ArduinoConst.ENV_VALUE_GNU_SERIAL_PORTS_LINUX);
75+
if (Platform.getOS().equals(Platform.OS_LINUX) && System.getProperty(Const.ENV_KEY_GNU_SERIAL_PORTS) == null) {
76+
System.setProperty(Const.ENV_KEY_GNU_SERIAL_PORTS, Const.ENV_VALUE_GNU_SERIAL_PORTS_LINUX);
7777
}
7878
remind();
7979
return;
@@ -85,7 +85,7 @@ static void remind() {
8585
@Override
8686
protected IStatus run(IProgressMonitor monitor) {
8787

88-
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(ArduinoConst.NODE_ARDUINO);
88+
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(Const.NODE_ARDUINO);
8989
int curFsiStatus = myScope.getInt(flagStart, 0) + myScope.getInt(flagMonitor, 0) + myScope.getInt(uploadflag, 0)
9090
+ myScope.getInt(buildflag, 0);
9191
int lastFsiStatus = myScope.getInt(Localflag, 0);

it.baeyens.arduino.common/src/it/baeyens/arduino/common/Common.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import it.baeyens.arduino.arduino.Serial;
3131

32-
public class Common extends ArduinoInstancePreferences {
32+
public class Common extends InstancePreferences {
3333

3434
static ISerialUser OtherSerialUser = null; // If someone else uses the
3535
// serial port he can register
@@ -123,7 +123,7 @@ public static String getPersistentProperty(IProject project, String Tag) {
123123
}
124124
return sret;
125125
} catch (CoreException e) {
126-
log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Failed to read persistent setting " + Tag, e)); //$NON-NLS-1$
126+
log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to read persistent setting " + Tag, e)); //$NON-NLS-1$
127127
// e.printStackTrace();
128128
return EMPTY_STRING;
129129
}
@@ -137,7 +137,7 @@ public static int getPersistentPropertyInt(IProject project, String Tag, int def
137137
}
138138
return Integer.parseInt(sret);
139139
} catch (CoreException e) {
140-
log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Failed to read persistent setting " + Tag, e)); //$NON-NLS-1$
140+
log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to read persistent setting " + Tag, e)); //$NON-NLS-1$
141141
// e.printStackTrace();
142142
return defaultValue;
143143
}
@@ -161,7 +161,7 @@ public static void setPersistentProperty(IProject project, String Tag, String Va
161161
// downwards
162162
// compatibility
163163
} catch (CoreException e) {
164-
IStatus status = new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID,
164+
IStatus status = new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
165165
"Failed to write arduino properties", e); //$NON-NLS-1$
166166
Common.log(status);
167167

@@ -204,7 +204,7 @@ public static String UploadPortPrefix() {
204204
return UploadPortPrefix_LINUX;
205205
if (Platform.getOS().equals(Platform.OS_MACOSX))
206206
return UploadPortPrefix_MAC;
207-
Common.log(new Status(IStatus.WARNING, ArduinoConst.CORE_PLUGIN_ID, "Unsupported operating system", null)); //$NON-NLS-1$
207+
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, "Unsupported operating system", null)); //$NON-NLS-1$
208208
return UploadPortPrefix_WIN;
209209
}
210210

0 commit comments

Comments
 (0)