I'm trying to access an API (available only on select phones) and I think it can be done with reflection but I'm not too familiar with it and haven't had any success yet. Any reflection gurus out there?
I was made to sign an NDA to get information on this API so I am going to change some details to avoid potential legal troubles. If I am missing anything important, please let me know.
I tried the following but receive runtime errors. For now I am just trying to use the transmitIRCmd (or transmitIR) method to send an IR command, and would be nice to get the result back. Eventually I'd also like to use the learn method as well. I am trying to simulate the abcIrData constructor using my own type (ABCData) but I don't even know if that will work. Unfortunately this stuff is way over my head.
Although it isn't shown in the code, ABCDat gets declared as Type ABCData and the proper values are assigned as necessary.
The API docs:
I was made to sign an NDA to get information on this API so I am going to change some details to avoid potential legal troubles. If I am missing anything important, please let me know.
I tried the following but receive runtime errors. For now I am just trying to use the transmitIRCmd (or transmitIR) method to send an IR command, and would be nice to get the result back. Eventually I'd also like to use the learn method as well. I am trying to simulate the abcIrData constructor using my own type (ABCData) but I don't even know if that will work. Unfortunately this stuff is way over my head.
Although it isn't shown in the code, ABCDat gets declared as Type ABCData and the proper values are assigned as necessary.
B4X:
Type ABCData (rc As Int, freq As Int, irframe() As Int) ' irframe should be int array
'Send command using built-in IR port
Dim r As Reflector, xCount As Int
r.Target = r.CreateObject("com.abc.circontrol.CIRControl")
'r.Target = r.CreateObject("com.abc.htcircontrol.abcIrInterface")
For xCount = 1 To RepeatCount
r.RunMethod3 ("transmitIRCmd", ABCDat, "java.lang.object", "False", "java.lang.boolean")
'r.RunMethod2 ("transmitIR", ABCDat, "java.lang.object")
Next
Catch
Log (LastException)
ToastMessageShow ("Failed to send IR command. Is your device supported?", True)
End Try
The API docs:
com.abc.circontrol
Class CIRControl
java.lang.Object
com.abc.circontrol.CIRControl
public class CIRControl
extends java.lang.Object
CIRControl
Field Summary
static int ERR_CANCEL
The argument 1 of message as result of request, IR activity is canncelled
static int ERR_CANCEL_FAIL
The argument 1 of message as result of request, fail to cancel assigned request
static int ERR_CHECKSUM_ERROR
The argument 1 of message as result of request, checksum error in IR command
static int ERR_CMD_DROPPED
The argument 1 of message as result of request, the request is dropped (if it is droppable)
static int ERR_CMD_FAILED
The argument 1 of message as result of request, failed to carry out request
static int ERR_HW_BUSY
The argument 1 of message as result of request, hardware is busy
static int ERR_INVALID_VALUE
The argument 1 of message as result of request, command arguments or data is invalid
static int ERR_IO_ERROR
The argument 1 of message as result of request, an IO error occured
static int ERR_LEARNING_TIMEOUT
The argument 1 of message as result of request, the learning process expired
static int ERR_NONE
The argument 1 of message as result of request, no error occured
static int ERR_OBJ_ERROR
The argument 1 of message as result of request, object error in JNI native functions
static int ERR_OUT_OF_FREQ
The argument 1 of message as result of request, learning IR frequency is not supported
static int ERR_PIPE_ERROR
The argument 1 of message as result of request, fail to create/read/write pipe
static int ERR_PULSE_ERROR
The argument 1 of message as result of request, pulse data of IR frame is error
static int ERR_TTY_READ_ERROR
The argument 1 of message as result of request, fail to read IR hardware
static int ERR_TTY_SETUP_ERROR
The argument 1 of message as result of request, fail to init IR hardware
static int ERR_TTY_WRITE_ERROR
The argument 1 of message as result of request, fail to write IR hardware
static int ERR_UNKNOWN
The argument 1 of message as result of request, an unknown error occured
static java.lang.String KEY_CMD_RESULT
The key to put/retrieve data the learnt command to/from bundle
static java.lang.String KEY_COMMAND
The key to put/retrieve the command data to/from bundle
static java.lang.String KEY_DISCARD_ID
The key to put/retrieve the target UUID of a request to discard
static java.lang.String KEY_DROPPABLE
The key to put/retrieve the boolean flag to indicate a request is can be dropped or not
static java.lang.String KEY_RESULT_ID
The key to put/retrieve the generated UUID for a request to/from bundle
static java.lang.String KEY_TIMEOUT
The key to put/retrieve the timeout value for learning
static int MSG_ARG_DROPPABLE
An argument flag to indicate the request can be dropped if CIR module is busy
static int MSG_ARG_NORMAL
An argument flag to indicate the request can be queued and cannot be dropped
static int MSG_CMD_CANCEL
A message type for canceling previous request
static int MSG_CMD_DISCARD
A message type for discard specific request
static int MSG_CMD_GET_FW_VER
A message type for retrieving firmware version of CIR module
static int MSG_CMD_LEARN_IR
A message type for learning request
static int MSG_CMD_REGISTER_CLIENT
A message type for registration of a client
static int MSG_CMD_RESET
A message type for resetting CIR module
static int MSG_CMD_TRANSMIT_IR
A message type for generating IR signals
static int MSG_CMD_UNREGISTER_CLIENT
A message type for unregistration of a client
static int MSG_RET_CANCEL
A message type for the result of canceling of a previous request
static int MSG_RET_DISCARD
A message type for the result of discard request
static int MSG_RET_GET_FW_VER
A message type for the result of retrieving firmware version of CIR module
static int MSG_RET_LEARN_IR
A message type for the result of a learning request
static int MSG_RET_RESET
A message type for the result of retset request
static int MSG_RET_STARTED
A message type for the result whether control ready or not
static int MSG_RET_TRANSMIT_IR
A message type for the result of generating a IR signals
Constructor Summary
CIRControl(Context context, Handler handler)
the CIRControl constructor
Method Summary
java.util.UUID cancelCommand()
cancel the on-going command
java.util.UUID discardCommand(java.util.UUID uuid)
discard the specific commands in queue
java.util.UUID getFirmwareVersion()
get the firmware version of CIR module
boolean isStarted()
check if service has been already started successfully
java.util.UUID learnIRCmd(int timeout)
enter learning mode to learn IR signals as a command
java.util.UUID reset()
reset the hardware of CIR module
void start()
bind to CIRModule service
void stop()
unbind to CIRModule service
java.util.UUID transmitIRCmd(abcIrData irData, boolean droppable)
generate IR signals according to information in the abcIrData
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Field Detail
MSG_CMD_REGISTER_CLIENT
public static final int MSG_CMD_REGISTER_CLIENT
A message type for registration of a client
See Also:
Constant Field Values
MSG_CMD_UNREGISTER_CLIENT
public static final int MSG_CMD_UNREGISTER_CLIENT
A message type for unregistration of a client
See Also:
Constant Field Values
MSG_CMD_LEARN_IR
public static final int MSG_CMD_LEARN_IR
A message type for learning request
See Also:
Constant Field Values
MSG_CMD_TRANSMIT_IR
public static final int MSG_CMD_TRANSMIT_IR
A message type for generating IR signals
See Also:
Constant Field Values
MSG_CMD_GET_FW_VER
public static final int MSG_CMD_GET_FW_VER
A message type for retrieving firmware version of CIR module
See Also:
Constant Field Values
MSG_CMD_RESET
public static final int MSG_CMD_RESET
A message type for resetting CIR module
See Also:
Constant Field Values
MSG_CMD_CANCEL
public static final int MSG_CMD_CANCEL
A message type for canceling previous request
See Also:
Constant Field Values
MSG_CMD_DISCARD
public static final int MSG_CMD_DISCARD
A message type for discard specific request
See Also:
Constant Field Values
MSG_RET_LEARN_IR
public static final int MSG_RET_LEARN_IR
A message type for the result of a learning request
See Also:
Constant Field Values
MSG_RET_TRANSMIT_IR
public static final int MSG_RET_TRANSMIT_IR
A message type for the result of generating a IR signals
See Also:
Constant Field Values
MSG_RET_GET_FW_VER
public static final int MSG_RET_GET_FW_VER
A message type for the result of retrieving firmware version of CIR module
See Also:
Constant Field Values
MSG_RET_RESET
public static final int MSG_RET_RESET
A message type for the result of retset request
See Also:
Constant Field Values
MSG_RET_CANCEL
public static final int MSG_RET_CANCEL
A message type for the result of canceling of a previous request
See Also:
Constant Field Values
MSG_RET_DISCARD
public static final int MSG_RET_DISCARD
A message type for the result of discard request
See Also:
Constant Field Values
MSG_RET_STARTED
public static final int MSG_RET_STARTED
A message type for the result whether control ready or not
See Also:
Constant Field Values
MSG_ARG_NORMAL
public static final int MSG_ARG_NORMAL
An argument flag to indicate the request can be queued and cannot be dropped
See Also:
Constant Field Values
MSG_ARG_DROPPABLE
public static final int MSG_ARG_DROPPABLE
An argument flag to indicate the request can be dropped if CIR module is busy
See Also:
Constant Field Values
ERR_NONE
public static final int ERR_NONE
The argument 1 of message as result of request, no error occured
See Also:
Constant Field Values
ERR_UNKNOWN
public static final int ERR_UNKNOWN
The argument 1 of message as result of request, an unknown error occured
See Also:
Constant Field Values
ERR_CMD_FAILED
public static final int ERR_CMD_FAILED
The argument 1 of message as result of request, failed to carry out request
See Also:
Constant Field Values
ERR_HW_BUSY
public static final int ERR_HW_BUSY
The argument 1 of message as result of request, hardware is busy
See Also:
Constant Field Values
ERR_IO_ERROR
public static final int ERR_IO_ERROR
The argument 1 of message as result of request, an IO error occured
See Also:
Constant Field Values
ERR_CMD_DROPPED
public static final int ERR_CMD_DROPPED
The argument 1 of message as result of request, the request is dropped (if it is droppable)
See Also:
Constant Field Values
ERR_TTY_SETUP_ERROR
public static final int ERR_TTY_SETUP_ERROR
The argument 1 of message as result of request, fail to init IR hardware
See Also:
Constant Field Values
ERR_TTY_WRITE_ERROR
public static final int ERR_TTY_WRITE_ERROR
The argument 1 of message as result of request, fail to write IR hardware
See Also:
Constant Field Values
ERR_TTY_READ_ERROR
public static final int ERR_TTY_READ_ERROR
The argument 1 of message as result of request, fail to read IR hardware
See Also:
Constant Field Values
ERR_INVALID_VALUE
public static final int ERR_INVALID_VALUE
The argument 1 of message as result of request, command arguments or data is invalid
See Also:
Constant Field Values
ERR_LEARNING_TIMEOUT
public static final int ERR_LEARNING_TIMEOUT
The argument 1 of message as result of request, the learning process expired
See Also:
Constant Field Values
ERR_CANCEL_FAIL
public static final int ERR_CANCEL_FAIL
The argument 1 of message as result of request, fail to cancel assigned request
See Also:
Constant Field Values
ERR_CHECKSUM_ERROR
public static final int ERR_CHECKSUM_ERROR
The argument 1 of message as result of request, checksum error in IR command
See Also:
Constant Field Values
ERR_OUT_OF_FREQ
public static final int ERR_OUT_OF_FREQ
The argument 1 of message as result of request, learning IR frequency is not supported
See Also:
Constant Field Values
ERR_CANCEL
public static final int ERR_CANCEL
The argument 1 of message as result of request, IR activity is canncelled
See Also:
Constant Field Values
ERR_PULSE_ERROR
public static final int ERR_PULSE_ERROR
The argument 1 of message as result of request, pulse data of IR frame is error
See Also:
Constant Field Values
ERR_PIPE_ERROR
public static final int ERR_PIPE_ERROR
The argument 1 of message as result of request, fail to create/read/write pipe
See Also:
Constant Field Values
ERR_OBJ_ERROR
public static final int ERR_OBJ_ERROR
The argument 1 of message as result of request, object error in JNI native functions
See Also:
Constant Field Values
KEY_COMMAND
public static final java.lang.String KEY_COMMAND
The key to put/retrieve the command data to/from bundle
See Also:
Constant Field Values
KEY_CMD_RESULT
public static final java.lang.String KEY_CMD_RESULT
The key to put/retrieve data the learnt command to/from bundle
See Also:
Constant Field Values
KEY_RESULT_ID
public static final java.lang.String KEY_RESULT_ID
The key to put/retrieve the generated UUID for a request to/from bundle
See Also:
Constant Field Values
KEY_DISCARD_ID
public static final java.lang.String KEY_DISCARD_ID
The key to put/retrieve the target UUID of a request to discard
See Also:
Constant Field Values
KEY_DROPPABLE
public static final java.lang.String KEY_DROPPABLE
The key to put/retrieve the boolean flag to indicate a request is can be dropped or not
See Also:
Constant Field Values
KEY_TIMEOUT
public static final java.lang.String KEY_TIMEOUT
The key to put/retrieve the timeout value for learning
See Also:
Constant Field Values
Constructor Detail
CIRControl
public CIRControl(Context context,
Handler handler)
the CIRControl constructor
Parameters:
context - the Context of application
handler - Handler for receiving result or request
Method Detail
isStarted
public boolean isStarted()
check if service has been already started successfully
Returns:
true if it is bound
start
public void start()
bind to CIRModule service
stop
public void stop()
unbind to CIRModule service
getFirmwareVersion
public java.util.UUID getFirmwareVersion()
get the firmware version of CIR module
Returns:
get the UUID assigned to this request; null represents service is not brought up yet
cancelCommand
public java.util.UUID cancelCommand()
cancel the on-going command
Returns:
get the UUID assigned to this request; null represents service is not brought up yet
discardCommand
public java.util.UUID discardCommand(java.util.UUID uuid)
discard the specific commands in queue
Parameters:
uuid - specific the target command with its UUID value
Returns:
get the UUID assigned to this request; null represents service is not brought up yet
reset
public java.util.UUID reset()
reset the hardware of CIR module
Returns:
get the UUID assigned to this request; null represents service is not brought up yet
transmitIRCmd
public java.util.UUID transmitIRCmd(abcIrData irData,
boolean droppable)
generate IR signals according to information in the abcIrData
Parameters:
irData - contains the information of generating IR signals
droppable - if true, command can be dropped when IR is running and busy
Returns:
get the UUID assigned to this request; null represents service is not brought up yet
learnIRCmd
public java.util.UUID learnIRCmd(int timeout)
enter learning mode to learn IR signals as a command
Parameters:
timeout - the period of time before learning process expires if the CIR module cannot detect valid IR signals frames
Returns:
get the UUID assigned to this request; null represents service is not brought up yet
com.abc.abcircontrol
Class abcIrData
java.lang.Object
com.abc.abcircontrol.abcIrData
All Implemented Interfaces:
java.io.Serializable
public class abcIrData
extends java.lang.Object
implements java.io.Serializable
abcCalendar
See Also:
Serialized Form
Field Summary
static java.lang.String TAG
the logcat tag string
Constructor Summary
abcIrData()
default constructor
abcIrData(int rc, int freq, int[] array)
the abcIrData constructor
Method Summary
int[] getFrame()
get the IR learning data frame
int getFrequency()
get the carrier frequency
int getPeriod()
get the time period that is needed by sending an IR
int getPeriodTolerance()
get the tolerance of time period which is needed to send an IR
int getRepeatCount()
get the number of repeat counts
void setFrame(int[] array)
set the IR data frame
void setFrequency(int val)
set the carrier frequency
void setPeriod(int period)
set the time period that is needed by sending an IR
void setPeriodTolerance(int percent)
set the tolerance percentage of time period that is needed to send an IR
void setRepeatCount(int val)
set the number of repeat counts
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Field Detail
TAG
public static final java.lang.String TAG
the logcat tag string
See Also:
Constant Field Values
Constructor Detail
abcIrData
public abcIrData()
default constructor
abcIrData
public abcIrData(int rc,
int freq,
int[] array)
the abcIrData constructor
Parameters:
rc - the number of repeat counts
freq - carrier frequency (i.e., 38400 is 38.4KHz)
array - data frame in integer array
Method Detail
getRepeatCount
public int getRepeatCount()
get the number of repeat counts
Returns:
the number of repeat counts in integer
setRepeatCount
public void setRepeatCount(int val)
set the number of repeat counts
Parameters:
val - number of repeat counts
getFrequency
public int getFrequency()
get the carrier frequency
Returns:
get the carrier frequency in integer
setFrequency
public void setFrequency(int val)
set the carrier frequency
Parameters:
val - carrier frequency (ie., 38400 is 38.4KHz)
getFrame
public int[] getFrame()
get the IR learning data frame
Returns:
get the data frame in array
setFrame
public void setFrame(int[] array)
set the IR data frame
Parameters:
array - data frame to send IR key
getPeriod
public int getPeriod()
get the time period that is needed by sending an IR
Returns:
get the time period in msec
setPeriod
public void setPeriod(int period)
set the time period that is needed by sending an IR
Parameters:
period - time period in msec
getPeriodTolerance
public int getPeriodTolerance()
get the tolerance of time period which is needed to send an IR
Returns:
get the tolerance of time period in 0 ~ 100 percentage
setPeriodTolerance
public void setPeriodTolerance(int percent)
set the tolerance percentage of time period that is needed to send an IR
Parameters:
percent - tolerance in 0 ~ 100 percentage
com.abc.abcircontrol
Class abcIrInterface
java.lang.Object
com.abc.abcircontrol.abcIrInterface
public class abcIrInterface
extends java.lang.Object
abcIrInterface
Field Summary
static int CIR_CANCEL
IR cancel occurs
static int CIR_CANCEL_ERROR
fail to cancel IR activity
static int CIR_CHECKSUM_ERROR
command checksum error
static int CIR_COMPLETION
IR completed without error
static int CIR_INVALID_VALUE
Invalid argument or data in IR command
static int CIR_LEARNING_TIMEOUT
IR learning timeout occurs
static int CIR_OBJ_ERROR
object error in JNI native function
static int CIR_OUT_OF_FREQ
IR learning data frequency is not supported
static int CIR_PIPE_ERROR
fail to create/read/write pipe
static int CIR_PULSE_ERROR
pulse error in IR data
static int CIR_TTY_READ_ERROR
IR hardware read error
static int CIR_TTY_SETUP_ERROR
IR hardware init error
static int CIR_TTY_WRITE_ERROR
IR hardware write error
static int CIR_UNKNOWN_ERROR
unknown error is from IR hardware component
Constructor Summary
abcIrInterface()
default constructor
Method Summary
static int cancelIR()
cancel IR activity in IR hardware
static int doReset()
reset IR hardware
static int enableIR(int on)
enable IR hardware
static int getFirmwareVersion()
get IR firmware revision
static abcIrData learnIR(int seconds)
learn IR key from remotes
static int[] loadAndSendIR(int cmdId, int repeatCount, int freq, int[] cmdBytes)
send IR key
static int[] receiveIR(int seconds)
receive IR data (key) from remotes
static int[] sendIR(int[] cmdBytes)
send IR key
static int transmitIR(abcIrData irData)
send IR to appliances
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Field Detail
CIR_COMPLETION
public static final int CIR_COMPLETION
IR completed without error
See Also:
Constant Field Values
CIR_TTY_SETUP_ERROR
public static final int CIR_TTY_SETUP_ERROR
IR hardware init error
See Also:
Constant Field Values
CIR_TTY_WRITE_ERROR
public static final int CIR_TTY_WRITE_ERROR
IR hardware write error
See Also:
Constant Field Values
CIR_TTY_READ_ERROR
public static final int CIR_TTY_READ_ERROR
IR hardware read error
See Also:
Constant Field Values
CIR_INVALID_VALUE
public static final int CIR_INVALID_VALUE
Invalid argument or data in IR command
See Also:
Constant Field Values
CIR_LEARNING_TIMEOUT
public static final int CIR_LEARNING_TIMEOUT
IR learning timeout occurs
See Also:
Constant Field Values
CIR_CANCEL_ERROR
public static final int CIR_CANCEL_ERROR
fail to cancel IR activity
See Also:
Constant Field Values
CIR_CHECKSUM_ERROR
public static final int CIR_CHECKSUM_ERROR
command checksum error
See Also:
Constant Field Values
CIR_OUT_OF_FREQ
public static final int CIR_OUT_OF_FREQ
IR learning data frequency is not supported
See Also:
Constant Field Values
CIR_CANCEL
public static final int CIR_CANCEL
IR cancel occurs
See Also:
Constant Field Values
CIR_PULSE_ERROR
public static final int CIR_PULSE_ERROR
pulse error in IR data
See Also:
Constant Field Values
CIR_PIPE_ERROR
public static final int CIR_PIPE_ERROR
fail to create/read/write pipe
See Also:
Constant Field Values
CIR_OBJ_ERROR
public static final int CIR_OBJ_ERROR
object error in JNI native function
See Also:
Constant Field Values
CIR_UNKNOWN_ERROR
public static final int CIR_UNKNOWN_ERROR
unknown error is from IR hardware component
See Also:
Constant Field Values
Constructor Detail
abcIrInterface
public abcIrInterface()
default constructor
Method Detail
loadAndSendIR
public static int[] loadAndSendIR(int cmdId,
int repeatCount,
int freq,
int[] cmdBytes)
send IR key
Parameters:
cmdId - only support send command 4
repeatCount - number of repeat counts
freq - carrier frequency
cmdBytes - frame data bytes
Returns:
reply packet data including error status
sendIR
public static int[] sendIR(int[] cmdBytes)
send IR key
Parameters:
cmdBytes - command data stream
Returns:
reply packet data including error status
receiveIR
public static int[] receiveIR(int seconds)
receive IR data (key) from remotes
Parameters:
seconds - timeout period
Returns:
data frame including repeat count, carrier frequency, and IR frame data
getFirmwareVersion
public static int getFirmwareVersion()
get IR firmware revision
Returns:
revision number
doReset
public static int doReset()
reset IR hardware
Returns:
to indicate success (0) or failure
cancelIR
public static int cancelIR()
cancel IR activity in IR hardware
Returns:
to indicate success (0) or failure
enableIR
public static int enableIR(int on)
enable IR hardware
Parameters:
on - true to enable, false to disable
Returns:
to indicate success (0) or failure
transmitIR
public static int transmitIR(abcIrData irData)
send IR to appliances
Parameters:
irData - abcIrData is defined in class abcIrData
Returns:
error status is prefix CIR_
learnIR
public static abcIrData learnIR(int seconds)
learn IR key from remotes
Parameters:
seconds - timeout period
Returns:
refer to class abcIrData