mirror of
https://github.com/RfidResearchGroup/ChameleonUltra.git
synced 2026-05-12 11:22:59 -07:00
DATA_CMD_GET_DEVICE_CAPABILITIES implementation
This commit is contained in:
@@ -34,6 +34,14 @@ data_frame_tx_t *cmd_processor_get_git_version(uint16_t cmd, uint16_t status, ui
|
||||
return data_frame_make(cmd, status, strlen(GIT_VERSION), (uint8_t *)GIT_VERSION);
|
||||
}
|
||||
|
||||
data_frame_tx_t *cmd_processor_get_device(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
#if defined(PROJECT_CHAMELEON_ULTRA)
|
||||
return data_frame_make(cmd, status, 1, (uint8_t *)1);
|
||||
#else
|
||||
return data_frame_make(cmd, status, 1, (uint8_t *)0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
data_frame_tx_t *cmd_processor_change_device_mode(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
if (length == 1) {
|
||||
@@ -860,6 +868,9 @@ static cmd_data_map_t m_data_cmd_map[] = {
|
||||
{ DATA_CMD_GET_BLE_CONNECT_KEY_CONFIG, NULL, cmd_processor_get_ble_connect_key, NULL },
|
||||
{ DATA_CMD_SET_BLE_CONNECT_KEY_CONFIG, NULL, cmd_processor_set_ble_connect_key, NULL },
|
||||
{ DATA_CMD_DELETE_ALL_BLE_BONDS, NULL, cmd_processor_del_ble_all_bonds, NULL },
|
||||
{ DATA_CMD_GET_DEVICE, NULL, cmd_processor_get_device, NULL },
|
||||
// { DATA_CMD_GET_SETTINGS, NULL, NULL, NULL },
|
||||
{ DATA_CMD_GET_DEVICE_CAPABILITIES, NULL, NULL, NULL },
|
||||
|
||||
#if defined(PROJECT_CHAMELEON_ULTRA)
|
||||
|
||||
@@ -919,6 +930,31 @@ static cmd_data_map_t m_data_cmd_map[] = {
|
||||
};
|
||||
|
||||
|
||||
data_frame_tx_t *cmd_processor_get_capabilities(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
|
||||
size_t count = sizeof(m_data_cmd_map) / sizeof(m_data_cmd_map[0]);
|
||||
uint16_t commands[count];
|
||||
memset(commands, 0, count * sizeof(uint16_t));
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
// beware: wrong endianness
|
||||
commands[i] = m_data_cmd_map[i].cmd;
|
||||
}
|
||||
|
||||
return data_frame_make(cmd, status, count * sizeof(uint16_t), (uint8_t *)commands);
|
||||
}
|
||||
|
||||
|
||||
void cmd_map_init() {
|
||||
size_t count = sizeof(m_data_cmd_map) / sizeof(m_data_cmd_map[0]);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (m_data_cmd_map[i].cmd == DATA_CMD_GET_DEVICE_CAPABILITIES) {
|
||||
m_data_cmd_map[i].cmd_processor = cmd_processor_get_capabilities;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Auto select source to response
|
||||
*
|
||||
|
||||
@@ -15,5 +15,6 @@ typedef struct {
|
||||
} cmd_data_map_t;
|
||||
|
||||
void on_data_frame_received(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data);
|
||||
void cmd_map_init();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -767,6 +767,7 @@ static void ble_passkey_init(void) {
|
||||
*/
|
||||
int main(void) {
|
||||
hw_connect_init(); // Remember to initialize the pins first
|
||||
cmd_map_init(); // Set function in CMD map for DATA_CMD_GET_DEVICE_CAPABILITIES
|
||||
|
||||
init_leds(); // LED initialization
|
||||
log_init(); // Log initialization
|
||||
|
||||
@@ -38,6 +38,10 @@
|
||||
#define DATA_CMD_SET_BLE_CONNECT_KEY_CONFIG (1030)
|
||||
#define DATA_CMD_GET_BLE_CONNECT_KEY_CONFIG (1031)
|
||||
#define DATA_CMD_DELETE_ALL_BLE_BONDS (1032)
|
||||
#define DATA_CMD_GET_DEVICE (1033)
|
||||
#define DATA_CMD_GET_SETTINGS (1034)
|
||||
#define DATA_CMD_GET_DEVICE_CAPABILITIES (1035)
|
||||
|
||||
|
||||
//
|
||||
// ******************************************************************
|
||||
@@ -80,7 +84,7 @@
|
||||
//
|
||||
#define DATA_CMD_LOAD_MF1_EMU_BLOCK_DATA (4000)
|
||||
#define DATA_CMD_SET_MF1_ANTI_COLLISION_RES (4001)
|
||||
#define DATA_CMD_SET_MF1_ANTICOLLISION_INFO (4002)
|
||||
#define DATA_CMD_SET_MF1_ANTI_COLLISION_INFO (4002)
|
||||
#define DATA_CMD_SET_MF1_ATS_RESOURCE (4003)
|
||||
#define DATA_CMD_SET_MF1_DETECTION_ENABLE (4004)
|
||||
#define DATA_CMD_GET_MF1_DETECTION_COUNT (4005)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -50,6 +50,10 @@ DATA_CMD_GET_BLE_CONNECT_KEY_CONFIG = 1031
|
||||
|
||||
DATA_CMD_DELETE_ALL_BLE_BONDS = 1032
|
||||
|
||||
DATA_CMD_GET_DEVICE = 1033
|
||||
DATA_CMD_GET_SETTINGS = 1034
|
||||
DATA_CMD_GET_DEVICE_CAPABILITIES = 1035
|
||||
|
||||
DATA_CMD_SCAN_14A_TAG = 2000
|
||||
DATA_CMD_MF1_SUPPORT_DETECT = 2001
|
||||
DATA_CMD_MF1_NT_LEVEL_DETECT = 2002
|
||||
@@ -283,6 +287,8 @@ class ChameleonCMD:
|
||||
:param chameleon: chameleon instance, @see chameleon_device.Chameleon
|
||||
"""
|
||||
self.device = chameleon
|
||||
if not len(self.device.commands):
|
||||
self.get_device_capabilities()
|
||||
|
||||
def get_firmware_version(self) -> int:
|
||||
"""
|
||||
@@ -810,7 +816,7 @@ class ChameleonCMD:
|
||||
data_bytes = key.encode(encoding='ascii')
|
||||
|
||||
# check key length
|
||||
if (len(data_bytes) != 6):
|
||||
if len(data_bytes) != 6:
|
||||
raise ValueError("The ble connect key length must be 6")
|
||||
|
||||
return self.device.send_cmd_sync(
|
||||
@@ -831,6 +837,27 @@ class ChameleonCMD:
|
||||
"""
|
||||
return self.device.send_cmd_sync(DATA_CMD_DELETE_ALL_BLE_BONDS, 0x00, None)
|
||||
|
||||
def get_device_capabilities(self):
|
||||
"""
|
||||
Get (and set) commands that client understands
|
||||
"""
|
||||
|
||||
commands = []
|
||||
|
||||
try:
|
||||
ret = self.device.send_cmd_sync(DATA_CMD_GET_DEVICE_CAPABILITIES, 0x00)
|
||||
|
||||
for i in range(0, len(ret.data), 2):
|
||||
if i + 1 < len(ret.data):
|
||||
commands.append((ret.data[i + 1] << 8) | ret.data[i])
|
||||
|
||||
self.device.commands = commands
|
||||
except:
|
||||
print("Chameleon doesn't understand get capabilities command. Please update firmware")
|
||||
|
||||
return commands
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# connect to chameleon
|
||||
dev = chameleon_com.ChameleonCom()
|
||||
|
||||
@@ -42,6 +42,7 @@ class ChameleonCom:
|
||||
"""
|
||||
data_frame_sof = 0x11
|
||||
data_max_length = 512
|
||||
commands = []
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
@@ -70,8 +71,7 @@ class ChameleonCom:
|
||||
error = None
|
||||
try:
|
||||
# open serial port
|
||||
self.serial_instance = serial.Serial(
|
||||
port=port, baudrate=115200)
|
||||
self.serial_instance = serial.Serial(port=port, baudrate=115200)
|
||||
except Exception as e:
|
||||
error = e
|
||||
finally:
|
||||
@@ -99,8 +99,7 @@ class ChameleonCom:
|
||||
:return:
|
||||
"""
|
||||
if not self.isOpen():
|
||||
raise NotOpenException(
|
||||
"Please call open() function to start device.")
|
||||
raise NotOpenException("Please call open() function to start device.")
|
||||
|
||||
@staticmethod
|
||||
def lrc_calc(array):
|
||||
@@ -198,8 +197,7 @@ class ChameleonCom:
|
||||
if callable(fn_call):
|
||||
# delete wait task from map
|
||||
del self.wait_response_map[data_cmd]
|
||||
fn_call(data_cmd, data_status,
|
||||
data_response)
|
||||
fn_call(data_cmd, data_status, data_response)
|
||||
else:
|
||||
self.wait_response_map[data_cmd]['response'] = Response(data_cmd, data_status,
|
||||
data_response)
|
||||
@@ -230,8 +228,7 @@ class ChameleonCom:
|
||||
task_close = task['close']
|
||||
# register to wait map
|
||||
if 'callback' in task and callable(task['callback']):
|
||||
self.wait_response_map[task_cmd] = {
|
||||
'callback': task['callback']} # The callback for this task
|
||||
self.wait_response_map[task_cmd] = {'callback': task['callback']} # The callback for this task
|
||||
else:
|
||||
self.wait_response_map[task_cmd] = {'response': None}
|
||||
# set start time
|
||||
@@ -262,8 +259,7 @@ class ChameleonCom:
|
||||
if time.time() > self.wait_response_map[task_cmd]['end_time']:
|
||||
if 'callback' in self.wait_response_map[task_cmd]:
|
||||
# not sync, call function to notify timeout.
|
||||
self.wait_response_map[task_cmd]['callback'](
|
||||
task_cmd, None, None)
|
||||
self.wait_response_map[task_cmd]['callback'](task_cmd, None, None)
|
||||
else:
|
||||
# sync mode, set timeout flag
|
||||
self.wait_response_map[task_cmd]['is_timeout'] = True
|
||||
@@ -308,8 +304,7 @@ class ChameleonCom:
|
||||
del self.wait_response_map[cmd]
|
||||
# make data frame
|
||||
data_frame = self.make_data_frame_bytes(cmd, status, data)
|
||||
task = {'cmd': cmd, 'frame': data_frame,
|
||||
'timeout': timeout, 'close': close}
|
||||
task = {'cmd': cmd, 'frame': data_frame, 'timeout': timeout, 'close': close}
|
||||
if callable(callback):
|
||||
task['callback'] = callback
|
||||
self.send_data_queue.put(task)
|
||||
@@ -327,6 +322,12 @@ class ChameleonCom:
|
||||
"""
|
||||
if isinstance(data, int):
|
||||
data = [data] # warp array.
|
||||
if len(self.commands):
|
||||
# check if chameleon can understand this command
|
||||
if cmd not in self.commands:
|
||||
raise CMDInvalidException(f"This device doesn't declare that it can support this command: {cmd}.\nMake "
|
||||
f"sure firmware is up to date and matches client")
|
||||
# return Response(cmd=cmd, status=0, data=b"\0" * 32) # forge fake response to not break app
|
||||
# first to send cmd, no callback mode(sync)
|
||||
self.send_cmd_auto(cmd, status, data, None, timeout)
|
||||
# wait cmd start process
|
||||
|
||||
Reference in New Issue
Block a user