From 50771433bb9b16035b148b7931165192eb2f3cb1 Mon Sep 17 00:00:00 2001 From: stewart Date: Mon, 1 Jan 2024 22:28:11 -0500 Subject: [PATCH 01/11] move some of the copy pasted code into a class --- src/android/src/AntChannelController.java | 171 ++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 src/android/src/AntChannelController.java diff --git a/src/android/src/AntChannelController.java b/src/android/src/AntChannelController.java new file mode 100644 index 000000000..c437f61cd --- /dev/null +++ b/src/android/src/AntChannelController.java @@ -0,0 +1,171 @@ +/* + * Copyright 2012 Dynastream Innovations Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.cagnulen.qdomyoszwift; + +import android.os.RemoteException; + +import android.util.Log; + +import com.dsi.ant.channel.AntChannel; +import com.dsi.ant.channel.AntCommandFailedException; +import com.dsi.ant.channel.IAntChannelEventHandler; +import com.dsi.ant.message.ChannelId; +import com.dsi.ant.message.ChannelType; +import com.dsi.ant.message.EventCode; +import com.dsi.ant.message.fromant.AcknowledgedDataMessage; +import com.dsi.ant.message.fromant.ChannelEventMessage; +import com.dsi.ant.message.fromant.MessageFromAntType; +import com.dsi.ant.message.ipc.AntMessageParcel; + +import java.util.Locale; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.TimeUnit; + +// the common bits that are shared between all of the _ChannelController classes +public class AntChannelController { + private AntChannel mAntChannel; + + private int msensor_id; + // The device type and transmission type to be part of the channel ID message + private int mdevice_type; + private int mtransmission_type; + + // The period and frequency values the channel will be configured to + private int mperiod; // 8192 -> 1 Hz + private int mfrequency; + + private String mtag; + + private IAntChannelEventHandler mChannelEventCallback; + + private boolean mIsOpen; + + public AntChannelController(AntChannel antChannel, int sensor_id, int device_type, int transmission_type, int period, int frequency, String tag, IAntChannelEventHandler callback) { + mAntChannel = antChannel; + msensor_id = sensor_id; + mdevice_type = device_type; + mtransmission_type = transmission_type; + mperiod = period; // 8192 -> 1 Hz + mfrequency = frequency; + mtag = tag; + mChannelEventCallback = callback; + openChannel(); + } + + boolean openChannel() { + if (null != mAntChannel) { + if (mIsOpen) { + Log.w(TAG, "Channel was already open"); + } else { + // Channel ID message contains device number, type and transmission type. In + // order for master (TX) channels and slave (RX) channels to connect, they + // must have the same channel ID, or wildcard (0) is used. + ChannelId channelId = new ChannelId(msensor_id & 0xFFFF, mdevice_type, mtransmission_type); + + try { + // Setting the channel event handler so that we can receive messages from ANT + mAntChannel.setChannelEventHandler(mChannelEventCallback); + + // Performs channel assignment by assigning the type to the channel. Additional + // features (such as, background scanning and frequency agility) can be enabled + // by passing an ExtendedAssignment object to assign(ChannelType, ExtendedAssignment). + mAntChannel.assign(ChannelType.BIDIRECTIONAL_MASTER); + + /* + * Configures the channel ID, messaging period and rf frequency after assigning, + * then opening the channel. + * + * For any additional ANT features such as proximity search or background scanning, refer to + * the ANT Protocol Doc found at: + * http://www.thisisant.com/resources/ant-message-protocol-and-usage/ + */ + mAntChannel.setChannelId(channelId); + mAntChannel.setPeriod(mperiod); + mAntChannel.setRfFrequency(mfrequency); + mAntChannel.open(); + mIsOpen = true; + + Log.d(mtag, "Opened channel with device number: " + msensor_id); + + } catch (RemoteException e) { + channelError(e); + } catch (AntCommandFailedException e) { + // This will release, and therefore unassign if required + channelError("Open failed", e); + } + } + } else { + Log.w(mtag, "No channel available"); + } + + return mIsOpen; + } + + + void channelError(RemoteException e) { + String logString = "Remote service communication failed."; + + Log.e(mtag, logString); + } + + void channelError(String error, AntCommandFailedException e) { + StringBuilder logString; + + if (e.getResponseMessage() != null) { + String initiatingMessageId = "0x" + Integer.toHexString( + e.getResponseMessage().getInitiatingMessageId()); + String rawResponseCode = "0x" + Integer.toHexString( + e.getResponseMessage().getRawResponseCode()); + + logString = new StringBuilder(error) + .append(". Command ") + .append(initiatingMessageId) + .append(" failed with code ") + .append(rawResponseCode); + } else { + String attemptedMessageId = "0x" + Integer.toHexString( + e.getAttemptedMessageType().getMessageId()); + String failureReason = e.getFailureReason().toString(); + + logString = new StringBuilder(error) + .append(". Command ") + .append(attemptedMessageId) + .append(" failed with reason ") + .append(failureReason); + } + + Log.e(mtag, logString.toString()); + + close(); + } + + public void close() { + // TODO kill all our resources + if (null != mAntChannel) { + mIsOpen = false; + + // Releasing the channel to make it available for others. + // After releasing, the AntChannel instance cannot be reused. + mAntChannel.release(); + mAntChannel = null; + } + + Log.e(mtag, "Channel Closed"); + } + + } +} From 8d75c9d971907a23157d92d34ece3800124d106b Mon Sep 17 00:00:00 2001 From: stewart Date: Mon, 1 Jan 2024 23:09:49 -0500 Subject: [PATCH 02/11] remove the duplicated code from the ChannelController classes --- src/android/src/AntChannelController.java | 17 +-- src/android/src/HeartChannelController.java | 122 ++------------------ src/android/src/PowerChannelController.java | 118 +------------------ src/android/src/SDMChannelController.java | 115 +----------------- src/android/src/SpeedChannelController.java | 113 +----------------- 5 files changed, 31 insertions(+), 454 deletions(-) diff --git a/src/android/src/AntChannelController.java b/src/android/src/AntChannelController.java index c437f61cd..8373f7a34 100644 --- a/src/android/src/AntChannelController.java +++ b/src/android/src/AntChannelController.java @@ -37,36 +37,40 @@ // the common bits that are shared between all of the _ChannelController classes public class AntChannelController { + private AntChannel mAntChannel; private int msensor_id; + // The device type and transmission type to be part of the channel ID message private int mdevice_type; private int mtransmission_type; - // The period and frequency values the channel will be configured to + // The period and frequency values private int mperiod; // 8192 -> 1 Hz private int mfrequency; private String mtag; private IAntChannelEventHandler mChannelEventCallback; + private ChannelType mchannel_type; private boolean mIsOpen; - public AntChannelController(AntChannel antChannel, int sensor_id, int device_type, int transmission_type, int period, int frequency, String tag, IAntChannelEventHandler callback) { + public AntChannelController(AntChannel antChannel, int sensor_id, int device_type, int transmission_type, int period, int frequency, ChannelType channel_type, String tag, IAntChannelEventHandler callback) { mAntChannel = antChannel; msensor_id = sensor_id; mdevice_type = device_type; mtransmission_type = transmission_type; mperiod = period; // 8192 -> 1 Hz mfrequency = frequency; + mchannel_type = channel_type; mtag = tag; mChannelEventCallback = callback; openChannel(); } - boolean openChannel() { + public boolean openChannel() { if (null != mAntChannel) { if (mIsOpen) { Log.w(TAG, "Channel was already open"); @@ -83,7 +87,7 @@ boolean openChannel() { // Performs channel assignment by assigning the type to the channel. Additional // features (such as, background scanning and frequency agility) can be enabled // by passing an ExtendedAssignment object to assign(ChannelType, ExtendedAssignment). - mAntChannel.assign(ChannelType.BIDIRECTIONAL_MASTER); + mAntChannel.assign(mchannel_type); /* * Configures the channel ID, messaging period and rf frequency after assigning, @@ -115,14 +119,13 @@ boolean openChannel() { return mIsOpen; } - - void channelError(RemoteException e) { + private void channelError(RemoteException e) { String logString = "Remote service communication failed."; Log.e(mtag, logString); } - void channelError(String error, AntCommandFailedException e) { + private void channelError(String error, AntCommandFailedException e) { StringBuilder logString; if (e.getResponseMessage() != null) { diff --git a/src/android/src/HeartChannelController.java b/src/android/src/HeartChannelController.java index 3b9d1cc6a..6ac0b1397 100644 --- a/src/android/src/HeartChannelController.java +++ b/src/android/src/HeartChannelController.java @@ -13,6 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ + package org.cagnulen.qdomyoszwift; import android.os.RemoteException; @@ -30,9 +31,13 @@ import com.dsi.ant.message.fromant.MessageFromAntType; import com.dsi.ant.message.ipc.AntMessageParcel; -import java.util.Random; -public class HeartChannelController { + + + +public class HeartChannelController extends AntChannelController{ + public static final int HEART_SENSOR_ID = 0; + // The device type and transmission type to be part of the channel ID message private static final int CHANNEL_HEART_DEVICE_TYPE = 0x78; private static final int CHANNEL_HEART_TRANSMISSION_TYPE = 1; @@ -43,121 +48,10 @@ public class HeartChannelController { private static final String TAG = HeartChannelController.class.getSimpleName(); - private static Random randGen = new Random(); - - private AntChannel mAntChannel; - - private ChannelEventCallback mChannelEventCallback = new ChannelEventCallback(); - - - private boolean mIsOpen; int heart = 0; public HeartChannelController(AntChannel antChannel) { - mAntChannel = antChannel; - openChannel(); - } - - boolean openChannel() { - if (null != mAntChannel) { - if (mIsOpen) { - Log.w(TAG, "Channel was already open"); - } else { - // Channel ID message contains device number, type and transmission type. In - // order for master (TX) channels and slave (RX) channels to connect, they - // must have the same channel ID, or wildcard (0) is used. - ChannelId channelId = new ChannelId(0, - CHANNEL_HEART_DEVICE_TYPE, CHANNEL_HEART_TRANSMISSION_TYPE); - - try { - // Setting the channel event handler so that we can receive messages from ANT - mAntChannel.setChannelEventHandler(mChannelEventCallback); - - // Performs channel assignment by assigning the type to the channel. Additional - // features (such as, background scanning and frequency agility) can be enabled - // by passing an ExtendedAssignment object to assign(ChannelType, ExtendedAssignment). - mAntChannel.assign(ChannelType.SLAVE_RECEIVE_ONLY); - - /* - * Configures the channel ID, messaging period and rf frequency after assigning, - * then opening the channel. - * - * For any additional ANT features such as proximity search or background scanning, refer to - * the ANT Protocol Doc found at: - * http://www.thisisant.com/resources/ant-message-protocol-and-usage/ - */ - mAntChannel.setChannelId(channelId); - mAntChannel.setPeriod(CHANNEL_HEART_PERIOD); - mAntChannel.setRfFrequency(CHANNEL_HEART_FREQUENCY); - mAntChannel.open(); - mIsOpen = true; - - Log.d(TAG, "Opened channel with device number"); - } catch (RemoteException e) { - channelError(e); - } catch (AntCommandFailedException e) { - // This will release, and therefore unassign if required - channelError("Open failed", e); - } - } - } else { - Log.w(TAG, "No channel available"); - } - - return mIsOpen; - } - - void channelError(RemoteException e) { - String logString = "Remote service communication failed."; - - Log.e(TAG, logString); - } - - void channelError(String error, AntCommandFailedException e) { - StringBuilder logString; - - if (e.getResponseMessage() != null) { - String initiatingMessageId = "0x" + Integer.toHexString( - e.getResponseMessage().getInitiatingMessageId()); - String rawResponseCode = "0x" + Integer.toHexString( - e.getResponseMessage().getRawResponseCode()); - - logString = new StringBuilder(error) - .append(". Command ") - .append(initiatingMessageId) - .append(" failed with code ") - .append(rawResponseCode); - } else { - String attemptedMessageId = "0x" + Integer.toHexString( - e.getAttemptedMessageType().getMessageId()); - String failureReason = e.getFailureReason().toString(); - - logString = new StringBuilder(error) - .append(". Command ") - .append(attemptedMessageId) - .append(" failed with reason ") - .append(failureReason); - } - - Log.e(TAG, logString.toString()); - - mAntChannel.release(); - - Log.e(TAG, "ANT Command Failed"); - } - - public void close() { - // TODO kill all our resources - if (null != mAntChannel) { - mIsOpen = false; - - // Releasing the channel to make it available for others. - // After releasing, the AntChannel instance cannot be reused. - mAntChannel.release(); - mAntChannel = null; - } - - Log.e(TAG, "Channel Closed"); + super(antChannel, HEART_SENSOR_ID, CHANNEL_HEART_DEVICE_TYPE, CHANNEL_HEART_TRANSMISSION_TYPE, CHANNEL_HEART_PERIOD, CHANNEL_HEART_FREQUENCY, ChannelType.SLAVE_RECEIVE_ONLY, TAG, new ChannelEventCallback()); } /** diff --git a/src/android/src/PowerChannelController.java b/src/android/src/PowerChannelController.java index ba898f52f..2972c2f43 100644 --- a/src/android/src/PowerChannelController.java +++ b/src/android/src/PowerChannelController.java @@ -35,130 +35,24 @@ import java.util.TimerTask; import java.util.concurrent.TimeUnit; -import java.util.Random; - -public class PowerChannelController { +public class PowerChannelController extends AntChannelController { public static final int POWER_SENSOR_ID = 0x9e3d4b66; + // The device type and transmission type to be part of the channel ID message private static final int CHANNEL_POWER_DEVICE_TYPE = 0x0B; private static final int CHANNEL_POWER_TRANSMISSION_TYPE = 5; + // The period and frequency values the channel will be configured to private static final int CHANNEL_POWER_PERIOD = 8182; // 1 Hz private static final int CHANNEL_POWER_FREQUENCY = 57; + private static final String TAG = PowerChannelController.class.getSimpleName(); - private static Random randGen = new Random(); + int power = 0; int cadence = 0; - private AntChannel mAntChannel; - private ChannelEventCallback mChannelEventCallback = new ChannelEventCallback(); - private boolean mIsOpen; public PowerChannelController(AntChannel antChannel) { - mAntChannel = antChannel; - openChannel(); - } - - boolean openChannel() { - if (null != mAntChannel) { - if (mIsOpen) { - Log.w(TAG, "Channel was already open"); - } else { - // Channel ID message contains device number, type and transmission type. In - // order for master (TX) channels and slave (RX) channels to connect, they - // must have the same channel ID, or wildcard (0) is used. - ChannelId channelId = new ChannelId(POWER_SENSOR_ID & 0xFFFF, - CHANNEL_POWER_DEVICE_TYPE, CHANNEL_POWER_TRANSMISSION_TYPE); - - try { - // Setting the channel event handler so that we can receive messages from ANT - mAntChannel.setChannelEventHandler(mChannelEventCallback); - - // Performs channel assignment by assigning the type to the channel. Additional - // features (such as, background scanning and frequency agility) can be enabled - // by passing an ExtendedAssignment object to assign(ChannelType, ExtendedAssignment). - mAntChannel.assign(ChannelType.BIDIRECTIONAL_MASTER); - - /* - * Configures the channel ID, messaging period and rf frequency after assigning, - * then opening the channel. - * - * For any additional ANT features such as proximity search or background scanning, refer to - * the ANT Protocol Doc found at: - * http://www.thisisant.com/resources/ant-message-protocol-and-usage/ - */ - mAntChannel.setChannelId(channelId); - mAntChannel.setPeriod(CHANNEL_POWER_PERIOD); - mAntChannel.setRfFrequency(CHANNEL_POWER_FREQUENCY); - mAntChannel.open(); - mIsOpen = true; - - Log.d(TAG, "Opened channel with device number: " + POWER_SENSOR_ID); - - } catch (RemoteException e) { - channelError(e); - } catch (AntCommandFailedException e) { - // This will release, and therefore unassign if required - channelError("Open failed", e); - } - } - } else { - Log.w(TAG, "No channel available"); - } - - return mIsOpen; - } - - - void channelError(RemoteException e) { - String logString = "Remote service communication failed."; - - Log.e(TAG, logString); - - } - - void channelError(String error, AntCommandFailedException e) { - StringBuilder logString; - - if (e.getResponseMessage() != null) { - String initiatingMessageId = "0x" + Integer.toHexString( - e.getResponseMessage().getInitiatingMessageId()); - String rawResponseCode = "0x" + Integer.toHexString( - e.getResponseMessage().getRawResponseCode()); - - logString = new StringBuilder(error) - .append(". Command ") - .append(initiatingMessageId) - .append(" failed with code ") - .append(rawResponseCode); - } else { - String attemptedMessageId = "0x" + Integer.toHexString( - e.getAttemptedMessageType().getMessageId()); - String failureReason = e.getFailureReason().toString(); - - logString = new StringBuilder(error) - .append(". Command ") - .append(attemptedMessageId) - .append(" failed with reason ") - .append(failureReason); - } - - Log.e(TAG, logString.toString()); - - mAntChannel.release(); - } - - public void close() { - // TODO kill all our resources - if (null != mAntChannel) { - mIsOpen = false; - - // Releasing the channel to make it available for others. - // After releasing, the AntChannel instance cannot be reused. - mAntChannel.release(); - mAntChannel = null; - } - - Log.e(TAG, "Channel Closed"); + super(antChannel, POWER_SENSOR_ID, CHANNEL_POWER_DEVICE_TYPE, CHANNEL_POWER_TRANSMISSION_TYPE, CHANNEL_POWER_PERIOD, CHANNEL_POWER_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG, new ChannelEventCallback()); } /** diff --git a/src/android/src/SDMChannelController.java b/src/android/src/SDMChannelController.java index 6507061da..d2cccc6a7 100644 --- a/src/android/src/SDMChannelController.java +++ b/src/android/src/SDMChannelController.java @@ -37,7 +37,9 @@ import java.util.Random; -public class SDMChannelController { +public class SDMChannelController extends AntChannelController { + public static final int SPEED_SENSOR_ID = 0x9e3d4b99; + // The device type and transmission type to be part of the channel ID message private static final int CHANNEL_SPEED_DEVICE_TYPE = 0x7C; private static final int CHANNEL_SPEED_TRANSMISSION_TYPE = 1; @@ -47,124 +49,15 @@ public class SDMChannelController { private static final int CHANNEL_SPEED_FREQUENCY = 57; private static final String TAG = SDMChannelController.class.getSimpleName(); - public static final int SPEED_SENSOR_ID = 0x9e3d4b99; private static final double MILLISECOND_TO_1_1024_CONVERSION = 0.9765625; - private AntChannel mAntChannel; - - private ChannelEventCallback mChannelEventCallback = new ChannelEventCallback(); - - private boolean mIsOpen; double speed = 0.0; int cadence = 0; byte stride_count = 0; public SDMChannelController(AntChannel antChannel) { - mAntChannel = antChannel; - openChannel(); - } - - boolean openChannel() { - if (null != mAntChannel) { - if (mIsOpen) { - Log.w(TAG, "Channel was already open"); - } else { - // Channel ID message contains device number, type and transmission type. In - // order for master (TX) channels and slave (RX) channels to connect, they - // must have the same channel ID, or wildcard (0) is used. - ChannelId channelId = new ChannelId(SPEED_SENSOR_ID & 0xFFFF, - CHANNEL_SPEED_DEVICE_TYPE, CHANNEL_SPEED_TRANSMISSION_TYPE); - - try { - // Setting the channel event handler so that we can receive messages from ANT - mAntChannel.setChannelEventHandler(mChannelEventCallback); - - // Performs channel assignment by assigning the type to the channel. Additional - // features (such as, background scanning and frequency agility) can be enabled - // by passing an ExtendedAssignment object to assign(ChannelType, ExtendedAssignment). - mAntChannel.assign(ChannelType.BIDIRECTIONAL_MASTER); - - /* - * Configures the channel ID, messaging period and rf frequency after assigning, - * then opening the channel. - * - * For any additional ANT features such as proximity search or background scanning, refer to - * the ANT Protocol Doc found at: - * http://www.thisisant.com/resources/ant-message-protocol-and-usage/ - */ - mAntChannel.setChannelId(channelId); - mAntChannel.setPeriod(CHANNEL_SPEED_PERIOD); - mAntChannel.setRfFrequency(CHANNEL_SPEED_FREQUENCY); - mAntChannel.open(); - mIsOpen = true; - - Log.d(TAG, "Opened channel with device number: " + SPEED_SENSOR_ID); - } catch (RemoteException e) { - channelError(e); - } catch (AntCommandFailedException e) { - // This will release, and therefore unassign if required - channelError("Open failed", e); - } - } - } else { - Log.w(TAG, "No channel available"); - } - - return mIsOpen; - } - - void channelError(RemoteException e) { - String logString = "Remote service communication failed."; - - Log.e(TAG, logString); - } - - void channelError(String error, AntCommandFailedException e) { - StringBuilder logString; - - if (e.getResponseMessage() != null) { - String initiatingMessageId = "0x" + Integer.toHexString( - e.getResponseMessage().getInitiatingMessageId()); - String rawResponseCode = "0x" + Integer.toHexString( - e.getResponseMessage().getRawResponseCode()); - - logString = new StringBuilder(error) - .append(". Command ") - .append(initiatingMessageId) - .append(" failed with code ") - .append(rawResponseCode); - } else { - String attemptedMessageId = "0x" + Integer.toHexString( - e.getAttemptedMessageType().getMessageId()); - String failureReason = e.getFailureReason().toString(); - - logString = new StringBuilder(error) - .append(". Command ") - .append(attemptedMessageId) - .append(" failed with reason ") - .append(failureReason); - } - - Log.e(TAG, logString.toString()); - - mAntChannel.release(); - - Log.e(TAG, "ANT Command Failed"); - } - - public void close() { - // TODO kill all our resources - if (null != mAntChannel) { - mIsOpen = false; - - // Releasing the channel to make it available for others. - // After releasing, the AntChannel instance cannot be reused. - mAntChannel.release(); - mAntChannel = null; - } - - Log.e(TAG, "Channel Closed"); + super(antChannel, SPEED_SENSOR_ID, CHANNEL_SPEED_DEVICE_TYPE, CHANNEL_SPEED_TRANSMISSION_TYPE, CHANNEL_SPEED_PERIOD, CHANNEL_SPEED_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG, new ChannelEventCallback()); } /** diff --git a/src/android/src/SpeedChannelController.java b/src/android/src/SpeedChannelController.java index 9c2a060cd..ae6c0c2b9 100644 --- a/src/android/src/SpeedChannelController.java +++ b/src/android/src/SpeedChannelController.java @@ -38,6 +38,8 @@ import java.util.Random; public class SpeedChannelController { + public static final int SPEED_SENSOR_ID = 0x9e3d4b33; + // The device type and transmission type to be part of the channel ID message private static final int CHANNEL_SPEED_DEVICE_TYPE = 0x79; private static final int CHANNEL_SPEED_TRANSMISSION_TYPE = 1; @@ -47,123 +49,14 @@ public class SpeedChannelController { private static final int CHANNEL_SPEED_FREQUENCY = 57; private static final String TAG = SpeedChannelController.class.getSimpleName(); - public static final int SPEED_SENSOR_ID = 0x9e3d4b33; private static final double MILLISECOND_TO_1_1024_CONVERSION = 0.9765625; - private AntChannel mAntChannel; - - private ChannelEventCallback mChannelEventCallback = new ChannelEventCallback(); - - private boolean mIsOpen; double speed = 0.0; int cadence = 0; public SpeedChannelController(AntChannel antChannel) { - mAntChannel = antChannel; - openChannel(); - } - - boolean openChannel() { - if (null != mAntChannel) { - if (mIsOpen) { - Log.w(TAG, "Channel was already open"); - } else { - // Channel ID message contains device number, type and transmission type. In - // order for master (TX) channels and slave (RX) channels to connect, they - // must have the same channel ID, or wildcard (0) is used. - ChannelId channelId = new ChannelId(SPEED_SENSOR_ID & 0xFFFF, - CHANNEL_SPEED_DEVICE_TYPE, CHANNEL_SPEED_TRANSMISSION_TYPE); - - try { - // Setting the channel event handler so that we can receive messages from ANT - mAntChannel.setChannelEventHandler(mChannelEventCallback); - - // Performs channel assignment by assigning the type to the channel. Additional - // features (such as, background scanning and frequency agility) can be enabled - // by passing an ExtendedAssignment object to assign(ChannelType, ExtendedAssignment). - mAntChannel.assign(ChannelType.BIDIRECTIONAL_MASTER); - - /* - * Configures the channel ID, messaging period and rf frequency after assigning, - * then opening the channel. - * - * For any additional ANT features such as proximity search or background scanning, refer to - * the ANT Protocol Doc found at: - * http://www.thisisant.com/resources/ant-message-protocol-and-usage/ - */ - mAntChannel.setChannelId(channelId); - mAntChannel.setPeriod(CHANNEL_SPEED_PERIOD); - mAntChannel.setRfFrequency(CHANNEL_SPEED_FREQUENCY); - mAntChannel.open(); - mIsOpen = true; - - Log.d(TAG, "Opened channel with device number: " + SPEED_SENSOR_ID); - } catch (RemoteException e) { - channelError(e); - } catch (AntCommandFailedException e) { - // This will release, and therefore unassign if required - channelError("Open failed", e); - } - } - } else { - Log.w(TAG, "No channel available"); - } - - return mIsOpen; - } - - void channelError(RemoteException e) { - String logString = "Remote service communication failed."; - - Log.e(TAG, logString); - } - - void channelError(String error, AntCommandFailedException e) { - StringBuilder logString; - - if (e.getResponseMessage() != null) { - String initiatingMessageId = "0x" + Integer.toHexString( - e.getResponseMessage().getInitiatingMessageId()); - String rawResponseCode = "0x" + Integer.toHexString( - e.getResponseMessage().getRawResponseCode()); - - logString = new StringBuilder(error) - .append(". Command ") - .append(initiatingMessageId) - .append(" failed with code ") - .append(rawResponseCode); - } else { - String attemptedMessageId = "0x" + Integer.toHexString( - e.getAttemptedMessageType().getMessageId()); - String failureReason = e.getFailureReason().toString(); - - logString = new StringBuilder(error) - .append(". Command ") - .append(attemptedMessageId) - .append(" failed with reason ") - .append(failureReason); - } - - Log.e(TAG, logString.toString()); - - mAntChannel.release(); - - Log.e(TAG, "ANT Command Failed"); - } - - public void close() { - // TODO kill all our resources - if (null != mAntChannel) { - mIsOpen = false; - - // Releasing the channel to make it available for others. - // After releasing, the AntChannel instance cannot be reused. - mAntChannel.release(); - mAntChannel = null; - } - - Log.e(TAG, "Channel Closed"); + super(antChannel, SPEED_SENSOR_ID, CHANNEL_SPEED_DEVICE_TYPE, CHANNEL_SPEED_TRANSMISSION_TYPE, CHANNEL_SPEED_PERIOD, CHANNEL_SPEED_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG, new ChannelEventCallback()); } /** From 4e2c56e1fac89b1d6c3035e3aa2c87c7de961abe Mon Sep 17 00:00:00 2001 From: stewart Date: Mon, 1 Jan 2024 23:18:42 -0500 Subject: [PATCH 03/11] clean up the imports --- src/android/src/HeartChannelController.java | 3 +-- src/android/src/PowerChannelController.java | 3 +-- src/android/src/SDMChannelController.java | 7 ++----- src/android/src/SpeedChannelController.java | 9 +++------ 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/android/src/HeartChannelController.java b/src/android/src/HeartChannelController.java index 6ac0b1397..0292a77a8 100644 --- a/src/android/src/HeartChannelController.java +++ b/src/android/src/HeartChannelController.java @@ -20,10 +20,9 @@ import android.util.Log; import com.dsi.ant.channel.AntChannel; -import com.dsi.ant.channel.AntCommandFailedException; import com.dsi.ant.channel.IAntChannelEventHandler; -import com.dsi.ant.message.ChannelId; import com.dsi.ant.message.ChannelType; + import com.dsi.ant.message.EventCode; import com.dsi.ant.message.fromant.AcknowledgedDataMessage; import com.dsi.ant.message.fromant.BroadcastDataMessage; diff --git a/src/android/src/PowerChannelController.java b/src/android/src/PowerChannelController.java index 2972c2f43..f76fabe53 100644 --- a/src/android/src/PowerChannelController.java +++ b/src/android/src/PowerChannelController.java @@ -20,10 +20,9 @@ import android.util.Log; import com.dsi.ant.channel.AntChannel; -import com.dsi.ant.channel.AntCommandFailedException; import com.dsi.ant.channel.IAntChannelEventHandler; -import com.dsi.ant.message.ChannelId; import com.dsi.ant.message.ChannelType; + import com.dsi.ant.message.EventCode; import com.dsi.ant.message.fromant.AcknowledgedDataMessage; import com.dsi.ant.message.fromant.ChannelEventMessage; diff --git a/src/android/src/SDMChannelController.java b/src/android/src/SDMChannelController.java index d2cccc6a7..eb856d9ff 100644 --- a/src/android/src/SDMChannelController.java +++ b/src/android/src/SDMChannelController.java @@ -13,6 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ + package org.cagnulen.qdomyoszwift; import android.os.RemoteException; @@ -20,10 +21,9 @@ import android.util.Log; import com.dsi.ant.channel.AntChannel; -import com.dsi.ant.channel.AntCommandFailedException; import com.dsi.ant.channel.IAntChannelEventHandler; -import com.dsi.ant.message.ChannelId; import com.dsi.ant.message.ChannelType; + import com.dsi.ant.message.EventCode; import com.dsi.ant.message.fromant.ChannelEventMessage; import com.dsi.ant.message.fromant.MessageFromAntType; @@ -34,9 +34,6 @@ import java.util.TimerTask; import java.util.concurrent.TimeUnit; - -import java.util.Random; - public class SDMChannelController extends AntChannelController { public static final int SPEED_SENSOR_ID = 0x9e3d4b99; diff --git a/src/android/src/SpeedChannelController.java b/src/android/src/SpeedChannelController.java index ae6c0c2b9..bd43976fa 100644 --- a/src/android/src/SpeedChannelController.java +++ b/src/android/src/SpeedChannelController.java @@ -13,6 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ + package org.cagnulen.qdomyoszwift; import android.os.RemoteException; @@ -20,10 +21,9 @@ import android.util.Log; import com.dsi.ant.channel.AntChannel; -import com.dsi.ant.channel.AntCommandFailedException; import com.dsi.ant.channel.IAntChannelEventHandler; -import com.dsi.ant.message.ChannelId; import com.dsi.ant.message.ChannelType; + import com.dsi.ant.message.EventCode; import com.dsi.ant.message.fromant.ChannelEventMessage; import com.dsi.ant.message.fromant.MessageFromAntType; @@ -34,10 +34,7 @@ import java.util.TimerTask; import java.util.concurrent.TimeUnit; - -import java.util.Random; - -public class SpeedChannelController { +public class SpeedChannelController extends AntChannelController { public static final int SPEED_SENSOR_ID = 0x9e3d4b33; // The device type and transmission type to be part of the channel ID message From de9662265b9430f9f840130caf5431a32f830e68 Mon Sep 17 00:00:00 2001 From: stewart Date: Mon, 1 Jan 2024 23:24:30 -0500 Subject: [PATCH 04/11] add an isOpen to the base type --- src/android/src/AntChannelController.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/android/src/AntChannelController.java b/src/android/src/AntChannelController.java index 8373f7a34..14771797d 100644 --- a/src/android/src/AntChannelController.java +++ b/src/android/src/AntChannelController.java @@ -119,6 +119,10 @@ public boolean openChannel() { return mIsOpen; } + public boolean isOpen() { + return mIsOpen; + } + private void channelError(RemoteException e) { String logString = "Remote service communication failed."; From 3bdb195a3b3c3f520ec1ee2a7938e94c00f071bc Mon Sep 17 00:00:00 2001 From: stewart Date: Tue, 2 Jan 2024 06:59:38 -0500 Subject: [PATCH 05/11] extra } ... --- src/android/src/AntChannelController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/android/src/AntChannelController.java b/src/android/src/AntChannelController.java index 14771797d..06d0ea34c 100644 --- a/src/android/src/AntChannelController.java +++ b/src/android/src/AntChannelController.java @@ -174,5 +174,4 @@ public void close() { Log.e(mtag, "Channel Closed"); } - } } From 1024ec7994f70b1e43fb578478347527d8a8beb4 Mon Sep 17 00:00:00 2001 From: stewart Date: Tue, 2 Jan 2024 19:11:15 -0500 Subject: [PATCH 06/11] maybe this will build? --- src/android/src/AntChannelController.java | 8 ++++---- src/android/src/HeartChannelController.java | 4 +++- src/android/src/PowerChannelController.java | 18 ++++++++++-------- src/android/src/SDMChannelController.java | 12 +++++++----- src/android/src/SpeedChannelController.java | 12 +++++++----- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/android/src/AntChannelController.java b/src/android/src/AntChannelController.java index 06d0ea34c..482f0712f 100644 --- a/src/android/src/AntChannelController.java +++ b/src/android/src/AntChannelController.java @@ -38,7 +38,7 @@ // the common bits that are shared between all of the _ChannelController classes public class AntChannelController { - private AntChannel mAntChannel; + AntChannel AntChannel; private int msensor_id; @@ -58,7 +58,7 @@ public class AntChannelController { private boolean mIsOpen; public AntChannelController(AntChannel antChannel, int sensor_id, int device_type, int transmission_type, int period, int frequency, ChannelType channel_type, String tag, IAntChannelEventHandler callback) { - mAntChannel = antChannel; + AntChannel = antChannel; msensor_id = sensor_id; mdevice_type = device_type; mtransmission_type = transmission_type; @@ -73,7 +73,7 @@ public AntChannelController(AntChannel antChannel, int sensor_id, int device_typ public boolean openChannel() { if (null != mAntChannel) { if (mIsOpen) { - Log.w(TAG, "Channel was already open"); + Log.w(mtag, "Channel was already open"); } else { // Channel ID message contains device number, type and transmission type. In // order for master (TX) channels and slave (RX) channels to connect, they @@ -123,7 +123,7 @@ public boolean isOpen() { return mIsOpen; } - private void channelError(RemoteException e) { + public void channelError(RemoteException e) { String logString = "Remote service communication failed."; Log.e(mtag, logString); diff --git a/src/android/src/HeartChannelController.java b/src/android/src/HeartChannelController.java index 0292a77a8..e20797af7 100644 --- a/src/android/src/HeartChannelController.java +++ b/src/android/src/HeartChannelController.java @@ -47,10 +47,12 @@ public class HeartChannelController extends AntChannelController{ private static final String TAG = HeartChannelController.class.getSimpleName(); + private static final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); + int heart = 0; public HeartChannelController(AntChannel antChannel) { - super(antChannel, HEART_SENSOR_ID, CHANNEL_HEART_DEVICE_TYPE, CHANNEL_HEART_TRANSMISSION_TYPE, CHANNEL_HEART_PERIOD, CHANNEL_HEART_FREQUENCY, ChannelType.SLAVE_RECEIVE_ONLY, TAG, new ChannelEventCallback()); + super(antChannel, HEART_SENSOR_ID, CHANNEL_HEART_DEVICE_TYPE, CHANNEL_HEART_TRANSMISSION_TYPE, CHANNEL_HEART_PERIOD, CHANNEL_HEART_FREQUENCY, ChannelType.SLAVE_RECEIVE_ONLY, TAG, CALLBACK); } /** diff --git a/src/android/src/PowerChannelController.java b/src/android/src/PowerChannelController.java index f76fabe53..8157b0b6c 100644 --- a/src/android/src/PowerChannelController.java +++ b/src/android/src/PowerChannelController.java @@ -46,12 +46,14 @@ public class PowerChannelController extends AntChannelController { private static final int CHANNEL_POWER_FREQUENCY = 57; private static final String TAG = PowerChannelController.class.getSimpleName(); + + private static final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); int power = 0; int cadence = 0; public PowerChannelController(AntChannel antChannel) { - super(antChannel, POWER_SENSOR_ID, CHANNEL_POWER_DEVICE_TYPE, CHANNEL_POWER_TRANSMISSION_TYPE, CHANNEL_POWER_PERIOD, CHANNEL_POWER_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG, new ChannelEventCallback()); + super(antChannel, POWER_SENSOR_ID, CHANNEL_POWER_DEVICE_TYPE, CHANNEL_POWER_TRANSMISSION_TYPE, CHANNEL_POWER_PERIOD, CHANNEL_POWER_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG, CALLBACK); } /** @@ -95,10 +97,10 @@ public void run() { payload[6] = (byte) ((power) & 0xFF); payload[7] = (byte) ((power >> 8) & 0xFF); - if (mIsOpen) { + if (IsOpen()) { try { // Setting the data to be broadcast on the next channel period - mAntChannel.setBroadcastData(payload); + AntChannel.setBroadcastData(payload); } catch (RemoteException e) { channelError(e); } @@ -131,7 +133,7 @@ public void run() { payload[7] = (byte) 0x00; try { // Setting the data to be broadcast on the next channel period - mAntChannel.setBroadcastData(payload); + AntChannel.setBroadcastData(payload); } catch (RemoteException e) { channelError(e); } @@ -147,10 +149,10 @@ public void run() { payload[6] = (byte) ((power) & 0xFF); payload[7] = (byte) ((power >> 8) & 0xFF); - if (mIsOpen) { + if (IsOpen()) { try { // Setting the data to be broadcast on the next channel period - mAntChannel.setBroadcastData(payload); + AntChannel.setBroadcastData(payload); } catch (RemoteException e) { channelError(e); } @@ -199,10 +201,10 @@ public void run() { payload[7] = (byte) ((power >> 8) & 0xFF); } - if (mIsOpen) { + if (IsOpen()) { try { // Setting the data to be broadcast on the next channel period - mAntChannel.setBroadcastData(payload); + AntChannel.setBroadcastData(payload); } catch (RemoteException e) { channelError(e); } diff --git a/src/android/src/SDMChannelController.java b/src/android/src/SDMChannelController.java index eb856d9ff..4ebcafedf 100644 --- a/src/android/src/SDMChannelController.java +++ b/src/android/src/SDMChannelController.java @@ -47,6 +47,8 @@ public class SDMChannelController extends AntChannelController { private static final String TAG = SDMChannelController.class.getSimpleName(); + private static final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); + private static final double MILLISECOND_TO_1_1024_CONVERSION = 0.9765625; double speed = 0.0; @@ -54,7 +56,7 @@ public class SDMChannelController extends AntChannelController { byte stride_count = 0; public SDMChannelController(AntChannel antChannel) { - super(antChannel, SPEED_SENSOR_ID, CHANNEL_SPEED_DEVICE_TYPE, CHANNEL_SPEED_TRANSMISSION_TYPE, CHANNEL_SPEED_PERIOD, CHANNEL_SPEED_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG, new ChannelEventCallback()); + super(antChannel, SPEED_SENSOR_ID, CHANNEL_SPEED_DEVICE_TYPE, CHANNEL_SPEED_TRANSMISSION_TYPE, CHANNEL_SPEED_PERIOD, CHANNEL_SPEED_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG, CALLBACK); } /** @@ -106,10 +108,10 @@ public void run() { payload[6] = (byte) stride_count++; // bad but it works on zwift payload[7] = (byte) ((double)deltaTime * 0.03125); - if (mIsOpen) { + if (IsOpen()) { try { // Setting the data to be broadcast on the next channel period - mAntChannel.setBroadcastData(payload); + AntChannel.setBroadcastData(payload); } catch (RemoteException e) { channelError(e); } @@ -155,10 +157,10 @@ public void run() { payload[6] = (byte) stride_count; payload[7] = (byte) ((double)deltaTime * 0.03125); - if (mIsOpen) { + if (IsOpen()) { try { // Setting the data to be broadcast on the next channel period - mAntChannel.setBroadcastData(payload); + AntChannel.setBroadcastData(payload); } catch (RemoteException e) { channelError(e); } diff --git a/src/android/src/SpeedChannelController.java b/src/android/src/SpeedChannelController.java index bd43976fa..44b7fdbe9 100644 --- a/src/android/src/SpeedChannelController.java +++ b/src/android/src/SpeedChannelController.java @@ -47,13 +47,15 @@ public class SpeedChannelController extends AntChannelController { private static final String TAG = SpeedChannelController.class.getSimpleName(); + private static final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); + private static final double MILLISECOND_TO_1_1024_CONVERSION = 0.9765625; double speed = 0.0; int cadence = 0; public SpeedChannelController(AntChannel antChannel) { - super(antChannel, SPEED_SENSOR_ID, CHANNEL_SPEED_DEVICE_TYPE, CHANNEL_SPEED_TRANSMISSION_TYPE, CHANNEL_SPEED_PERIOD, CHANNEL_SPEED_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG, new ChannelEventCallback()); + super(antChannel, SPEED_SENSOR_ID, CHANNEL_SPEED_DEVICE_TYPE, CHANNEL_SPEED_TRANSMISSION_TYPE, CHANNEL_SPEED_PERIOD, CHANNEL_SPEED_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG, CALLBACK); } /** @@ -115,10 +117,10 @@ public void run() { payload[6] = (byte) (rev & 0xFF); payload[7] = (byte) ((rev >> 8) & 0xFF); - if (mIsOpen) { + if (IsOpen()) { try { // Setting the data to be broadcast on the next channel period - mAntChannel.setBroadcastData(payload); + AntChannel.setBroadcastData(payload); } catch (RemoteException e) { channelError(e); } @@ -173,10 +175,10 @@ public void run() { payload[6] = (byte) (rev & 0xFF); payload[7] = (byte) ((rev >> 8) & 0xFF); - if (mIsOpen) { + if (IsOpen()) { try { // Setting the data to be broadcast on the next channel period - mAntChannel.setBroadcastData(payload); + AntChannel.setBroadcastData(payload); } catch (RemoteException e) { channelError(e); } From 92b38725639e38f56cc076af5852adf3db5cf35d Mon Sep 17 00:00:00 2001 From: stewart Date: Wed, 3 Jan 2024 20:35:36 -0500 Subject: [PATCH 07/11] more typos --- src/android/src/AntChannelController.java | 20 ++++++++++---------- src/android/src/PowerChannelController.java | 6 +++--- src/android/src/SDMChannelController.java | 4 ++-- src/android/src/SpeedChannelController.java | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/android/src/AntChannelController.java b/src/android/src/AntChannelController.java index 482f0712f..cfd04a047 100644 --- a/src/android/src/AntChannelController.java +++ b/src/android/src/AntChannelController.java @@ -71,7 +71,7 @@ public AntChannelController(AntChannel antChannel, int sensor_id, int device_typ } public boolean openChannel() { - if (null != mAntChannel) { + if (null != AntChannel) { if (mIsOpen) { Log.w(mtag, "Channel was already open"); } else { @@ -82,12 +82,12 @@ public boolean openChannel() { try { // Setting the channel event handler so that we can receive messages from ANT - mAntChannel.setChannelEventHandler(mChannelEventCallback); + AntChannel.setChannelEventHandler(mChannelEventCallback); // Performs channel assignment by assigning the type to the channel. Additional // features (such as, background scanning and frequency agility) can be enabled // by passing an ExtendedAssignment object to assign(ChannelType, ExtendedAssignment). - mAntChannel.assign(mchannel_type); + AntChannel.assign(mchannel_type); /* * Configures the channel ID, messaging period and rf frequency after assigning, @@ -97,10 +97,10 @@ public boolean openChannel() { * the ANT Protocol Doc found at: * http://www.thisisant.com/resources/ant-message-protocol-and-usage/ */ - mAntChannel.setChannelId(channelId); - mAntChannel.setPeriod(mperiod); - mAntChannel.setRfFrequency(mfrequency); - mAntChannel.open(); + AntChannel.setChannelId(channelId); + AntChannel.setPeriod(mperiod); + AntChannel.setRfFrequency(mfrequency); + AntChannel.open(); mIsOpen = true; Log.d(mtag, "Opened channel with device number: " + msensor_id); @@ -162,13 +162,13 @@ private void channelError(String error, AntCommandFailedException e) { public void close() { // TODO kill all our resources - if (null != mAntChannel) { + if (null != AntChannel) { mIsOpen = false; // Releasing the channel to make it available for others. // After releasing, the AntChannel instance cannot be reused. - mAntChannel.release(); - mAntChannel = null; + AntChannel.release(); + AntChannel = null; } Log.e(mtag, "Channel Closed"); diff --git a/src/android/src/PowerChannelController.java b/src/android/src/PowerChannelController.java index 8157b0b6c..f6fb2cf41 100644 --- a/src/android/src/PowerChannelController.java +++ b/src/android/src/PowerChannelController.java @@ -97,7 +97,7 @@ public void run() { payload[6] = (byte) ((power) & 0xFF); payload[7] = (byte) ((power >> 8) & 0xFF); - if (IsOpen()) { + if (isOpen()) { try { // Setting the data to be broadcast on the next channel period AntChannel.setBroadcastData(payload); @@ -149,7 +149,7 @@ public void run() { payload[6] = (byte) ((power) & 0xFF); payload[7] = (byte) ((power >> 8) & 0xFF); - if (IsOpen()) { + if (isOpen()) { try { // Setting the data to be broadcast on the next channel period AntChannel.setBroadcastData(payload); @@ -201,7 +201,7 @@ public void run() { payload[7] = (byte) ((power >> 8) & 0xFF); } - if (IsOpen()) { + if (isOpen()) { try { // Setting the data to be broadcast on the next channel period AntChannel.setBroadcastData(payload); diff --git a/src/android/src/SDMChannelController.java b/src/android/src/SDMChannelController.java index 4ebcafedf..73d736789 100644 --- a/src/android/src/SDMChannelController.java +++ b/src/android/src/SDMChannelController.java @@ -108,7 +108,7 @@ public void run() { payload[6] = (byte) stride_count++; // bad but it works on zwift payload[7] = (byte) ((double)deltaTime * 0.03125); - if (IsOpen()) { + if (isOpen()) { try { // Setting the data to be broadcast on the next channel period AntChannel.setBroadcastData(payload); @@ -157,7 +157,7 @@ public void run() { payload[6] = (byte) stride_count; payload[7] = (byte) ((double)deltaTime * 0.03125); - if (IsOpen()) { + if (isOpen()) { try { // Setting the data to be broadcast on the next channel period AntChannel.setBroadcastData(payload); diff --git a/src/android/src/SpeedChannelController.java b/src/android/src/SpeedChannelController.java index 44b7fdbe9..d684706b8 100644 --- a/src/android/src/SpeedChannelController.java +++ b/src/android/src/SpeedChannelController.java @@ -117,7 +117,7 @@ public void run() { payload[6] = (byte) (rev & 0xFF); payload[7] = (byte) ((rev >> 8) & 0xFF); - if (IsOpen()) { + if (isOpen()) { try { // Setting the data to be broadcast on the next channel period AntChannel.setBroadcastData(payload); @@ -175,7 +175,7 @@ public void run() { payload[6] = (byte) (rev & 0xFF); payload[7] = (byte) ((rev >> 8) & 0xFF); - if (IsOpen()) { + if (isOpen()) { try { // Setting the data to be broadcast on the next channel period AntChannel.setBroadcastData(payload); From 6bb344f606e6704b6526613515ea2ef4af7f19c4 Mon Sep 17 00:00:00 2001 From: stewart Date: Wed, 3 Jan 2024 21:01:25 -0500 Subject: [PATCH 08/11] can't be static --- src/android/src/HeartChannelController.java | 2 +- src/android/src/PowerChannelController.java | 2 +- src/android/src/SDMChannelController.java | 2 +- src/android/src/SpeedChannelController.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/android/src/HeartChannelController.java b/src/android/src/HeartChannelController.java index e20797af7..18dd19a2f 100644 --- a/src/android/src/HeartChannelController.java +++ b/src/android/src/HeartChannelController.java @@ -47,7 +47,7 @@ public class HeartChannelController extends AntChannelController{ private static final String TAG = HeartChannelController.class.getSimpleName(); - private static final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); + private final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); int heart = 0; diff --git a/src/android/src/PowerChannelController.java b/src/android/src/PowerChannelController.java index f6fb2cf41..af0adef96 100644 --- a/src/android/src/PowerChannelController.java +++ b/src/android/src/PowerChannelController.java @@ -47,7 +47,7 @@ public class PowerChannelController extends AntChannelController { private static final String TAG = PowerChannelController.class.getSimpleName(); - private static final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); + private final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); int power = 0; int cadence = 0; diff --git a/src/android/src/SDMChannelController.java b/src/android/src/SDMChannelController.java index 73d736789..1446241d5 100644 --- a/src/android/src/SDMChannelController.java +++ b/src/android/src/SDMChannelController.java @@ -47,7 +47,7 @@ public class SDMChannelController extends AntChannelController { private static final String TAG = SDMChannelController.class.getSimpleName(); - private static final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); + private final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); private static final double MILLISECOND_TO_1_1024_CONVERSION = 0.9765625; diff --git a/src/android/src/SpeedChannelController.java b/src/android/src/SpeedChannelController.java index d684706b8..341c10208 100644 --- a/src/android/src/SpeedChannelController.java +++ b/src/android/src/SpeedChannelController.java @@ -47,7 +47,7 @@ public class SpeedChannelController extends AntChannelController { private static final String TAG = SpeedChannelController.class.getSimpleName(); - private static final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); + private final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); private static final double MILLISECOND_TO_1_1024_CONVERSION = 0.9765625; From aea9776a7d1b32a4310ed1ded7a3508b2ca8b78f Mon Sep 17 00:00:00 2001 From: stewart Date: Wed, 3 Jan 2024 23:41:48 -0500 Subject: [PATCH 09/11] issue with instantiating an internal class --- src/android/src/AntChannelController.java | 11 ++++++++--- src/android/src/ChannelService.java | 14 ++++++++++---- src/android/src/HeartChannelController.java | 4 ++-- src/android/src/PowerChannelController.java | 6 ++---- src/android/src/SDMChannelController.java | 6 ++---- src/android/src/SpeedChannelController.java | 6 ++---- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/android/src/AntChannelController.java b/src/android/src/AntChannelController.java index cfd04a047..74a8b78da 100644 --- a/src/android/src/AntChannelController.java +++ b/src/android/src/AntChannelController.java @@ -57,7 +57,7 @@ public class AntChannelController { private boolean mIsOpen; - public AntChannelController(AntChannel antChannel, int sensor_id, int device_type, int transmission_type, int period, int frequency, ChannelType channel_type, String tag, IAntChannelEventHandler callback) { + public AntChannelController(AntChannel antChannel, int sensor_id, int device_type, int transmission_type, int period, int frequency, ChannelType channel_type, String tag) { AntChannel = antChannel; msensor_id = sensor_id; mdevice_type = device_type; @@ -66,10 +66,15 @@ public AntChannelController(AntChannel antChannel, int sensor_id, int device_typ mfrequency = frequency; mchannel_type = channel_type; mtag = tag; - mChannelEventCallback = callback; - openChannel(); } + public void start(AntChannel antChannel, IAntChannelEventHander callback) + { + AntChannel = antChannel; + mChannelEventCallback = callback; + openChannel(); + } + public boolean openChannel() { if (null != AntChannel) { if (mIsOpen) { diff --git a/src/android/src/ChannelService.java b/src/android/src/ChannelService.java index 1cdeea263..de2df49f7 100644 --- a/src/android/src/ChannelService.java +++ b/src/android/src/ChannelService.java @@ -145,14 +145,20 @@ void clearAllChannels() { public void openAllChannels() throws ChannelNotAvailableException { if (Ant.heartRequest) - heartChannelController = new HeartChannelController(acquireChannel()); + { + heartChannelController = new HeartChannelController(); + heartChannelController.start(acquireChannel(), heartChannelController.new ChannelEventCallback) + } if (Ant.speedRequest) { if(Ant.treadmill) { - sdmChannelController = new SDMChannelController(acquireChannel()); + sdmChannelController = new SDMChannelController(); + sdmChannelController.start(acquireChannel(), sdmChannelController.new ChannelEventCallback) } else { - powerChannelController = new PowerChannelController(acquireChannel()); - speedChannelController = new SpeedChannelController(acquireChannel()); + powerChannelController = new PowerChannelController(); + powerChannelController.start(acquireChannel(), powerChannelController.new ChannelEventCallback); + speedChannelController = new SpeedChannelController(); + speedChannelController.start(acquireChannel(), speedChannelController.new ChannelEventCallback); } } } diff --git a/src/android/src/HeartChannelController.java b/src/android/src/HeartChannelController.java index 18dd19a2f..bc6f59cb9 100644 --- a/src/android/src/HeartChannelController.java +++ b/src/android/src/HeartChannelController.java @@ -51,8 +51,8 @@ public class HeartChannelController extends AntChannelController{ int heart = 0; - public HeartChannelController(AntChannel antChannel) { - super(antChannel, HEART_SENSOR_ID, CHANNEL_HEART_DEVICE_TYPE, CHANNEL_HEART_TRANSMISSION_TYPE, CHANNEL_HEART_PERIOD, CHANNEL_HEART_FREQUENCY, ChannelType.SLAVE_RECEIVE_ONLY, TAG, CALLBACK); + public HeartChannelController() { + super(HEART_SENSOR_ID, CHANNEL_HEART_DEVICE_TYPE, CHANNEL_HEART_TRANSMISSION_TYPE, CHANNEL_HEART_PERIOD, CHANNEL_HEART_FREQUENCY, ChannelType.SLAVE_RECEIVE_ONLY, TAG); } /** diff --git a/src/android/src/PowerChannelController.java b/src/android/src/PowerChannelController.java index af0adef96..befbf3649 100644 --- a/src/android/src/PowerChannelController.java +++ b/src/android/src/PowerChannelController.java @@ -46,14 +46,12 @@ public class PowerChannelController extends AntChannelController { private static final int CHANNEL_POWER_FREQUENCY = 57; private static final String TAG = PowerChannelController.class.getSimpleName(); - - private final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); int power = 0; int cadence = 0; - public PowerChannelController(AntChannel antChannel) { - super(antChannel, POWER_SENSOR_ID, CHANNEL_POWER_DEVICE_TYPE, CHANNEL_POWER_TRANSMISSION_TYPE, CHANNEL_POWER_PERIOD, CHANNEL_POWER_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG, CALLBACK); + public PowerChannelController() { + super(POWER_SENSOR_ID, CHANNEL_POWER_DEVICE_TYPE, CHANNEL_POWER_TRANSMISSION_TYPE, CHANNEL_POWER_PERIOD, CHANNEL_POWER_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG); } /** diff --git a/src/android/src/SDMChannelController.java b/src/android/src/SDMChannelController.java index 1446241d5..050803e7d 100644 --- a/src/android/src/SDMChannelController.java +++ b/src/android/src/SDMChannelController.java @@ -47,16 +47,14 @@ public class SDMChannelController extends AntChannelController { private static final String TAG = SDMChannelController.class.getSimpleName(); - private final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); - private static final double MILLISECOND_TO_1_1024_CONVERSION = 0.9765625; double speed = 0.0; int cadence = 0; byte stride_count = 0; - public SDMChannelController(AntChannel antChannel) { - super(antChannel, SPEED_SENSOR_ID, CHANNEL_SPEED_DEVICE_TYPE, CHANNEL_SPEED_TRANSMISSION_TYPE, CHANNEL_SPEED_PERIOD, CHANNEL_SPEED_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG, CALLBACK); + public SDMChannelController() { + super(SPEED_SENSOR_ID, CHANNEL_SPEED_DEVICE_TYPE, CHANNEL_SPEED_TRANSMISSION_TYPE, CHANNEL_SPEED_PERIOD, CHANNEL_SPEED_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG); } /** diff --git a/src/android/src/SpeedChannelController.java b/src/android/src/SpeedChannelController.java index 341c10208..0c86137dc 100644 --- a/src/android/src/SpeedChannelController.java +++ b/src/android/src/SpeedChannelController.java @@ -47,15 +47,13 @@ public class SpeedChannelController extends AntChannelController { private static final String TAG = SpeedChannelController.class.getSimpleName(); - private final IAntChannelEventHandler CALLBACK = new ChannelEventCallback(); - private static final double MILLISECOND_TO_1_1024_CONVERSION = 0.9765625; double speed = 0.0; int cadence = 0; - public SpeedChannelController(AntChannel antChannel) { - super(antChannel, SPEED_SENSOR_ID, CHANNEL_SPEED_DEVICE_TYPE, CHANNEL_SPEED_TRANSMISSION_TYPE, CHANNEL_SPEED_PERIOD, CHANNEL_SPEED_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG, CALLBACK); + public SpeedChannelController() { + super(SPEED_SENSOR_ID, CHANNEL_SPEED_DEVICE_TYPE, CHANNEL_SPEED_TRANSMISSION_TYPE, CHANNEL_SPEED_PERIOD, CHANNEL_SPEED_FREQUENCY, ChannelType.BIDIRECTIONAL_MASTER, TAG); } /** From 017f12f87316a87883d3714365aac3938973b8c0 Mon Sep 17 00:00:00 2001 From: stewart Date: Thu, 4 Jan 2024 00:06:52 -0500 Subject: [PATCH 10/11] missing ; and () and forgot to update the constructor signature --- src/android/src/AntChannelController.java | 3 +-- src/android/src/ChannelService.java | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/android/src/AntChannelController.java b/src/android/src/AntChannelController.java index 74a8b78da..c2753e6d2 100644 --- a/src/android/src/AntChannelController.java +++ b/src/android/src/AntChannelController.java @@ -57,8 +57,7 @@ public class AntChannelController { private boolean mIsOpen; - public AntChannelController(AntChannel antChannel, int sensor_id, int device_type, int transmission_type, int period, int frequency, ChannelType channel_type, String tag) { - AntChannel = antChannel; + public AntChannelController(int sensor_id, int device_type, int transmission_type, int period, int frequency, ChannelType channel_type, String tag) { msensor_id = sensor_id; mdevice_type = device_type; mtransmission_type = transmission_type; diff --git a/src/android/src/ChannelService.java b/src/android/src/ChannelService.java index de2df49f7..4bd0bd19b 100644 --- a/src/android/src/ChannelService.java +++ b/src/android/src/ChannelService.java @@ -147,18 +147,18 @@ public void openAllChannels() throws ChannelNotAvailableException { if (Ant.heartRequest) { heartChannelController = new HeartChannelController(); - heartChannelController.start(acquireChannel(), heartChannelController.new ChannelEventCallback) + heartChannelController.start(acquireChannel(), heartChannelController.new ChannelEventCallback()); } if (Ant.speedRequest) { if(Ant.treadmill) { sdmChannelController = new SDMChannelController(); - sdmChannelController.start(acquireChannel(), sdmChannelController.new ChannelEventCallback) + sdmChannelController.start(acquireChannel(), sdmChannelController.new ChannelEventCallback()); } else { powerChannelController = new PowerChannelController(); - powerChannelController.start(acquireChannel(), powerChannelController.new ChannelEventCallback); + powerChannelController.start(acquireChannel(), powerChannelController.new ChannelEventCallback()); speedChannelController = new SpeedChannelController(); - speedChannelController.start(acquireChannel(), speedChannelController.new ChannelEventCallback); + speedChannelController.start(acquireChannel(), speedChannelController.new ChannelEventCallback()); } } } From 6a5dfd4e2057d95038e47e8072c63e23d8ca818c Mon Sep 17 00:00:00 2001 From: stewart Date: Thu, 4 Jan 2024 06:52:18 -0500 Subject: [PATCH 11/11] typo --- src/android/src/AntChannelController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/src/AntChannelController.java b/src/android/src/AntChannelController.java index c2753e6d2..1e238c3d6 100644 --- a/src/android/src/AntChannelController.java +++ b/src/android/src/AntChannelController.java @@ -67,7 +67,7 @@ public AntChannelController(int sensor_id, int device_type, int transmission_typ mtag = tag; } - public void start(AntChannel antChannel, IAntChannelEventHander callback) + public void start(AntChannel antChannel, IAntChannelEventHandler callback) { AntChannel = antChannel; mChannelEventCallback = callback;