mirror of
https://github.com/whowechina/aic_pico.git
synced 2025-01-19 03:17:24 +01:00
AIME mode 0 and 1
This commit is contained in:
parent
75dd5c6af5
commit
1ff0c9b336
Binary file not shown.
@ -14,6 +14,9 @@ typedef void (*aime_putc_func)(uint8_t byte);
|
||||
|
||||
void aime_init(aime_putc_func putc_func);
|
||||
void aime_virtual_aic(bool enable);
|
||||
void aime_set_mode(int mode);
|
||||
const char *aime_get_mode_string();
|
||||
|
||||
bool aime_feed(int c);
|
||||
|
||||
/* aime activity expires at this time */
|
||||
@ -21,7 +24,4 @@ uint64_t aime_expire_time();
|
||||
|
||||
uint32_t aime_led_color();
|
||||
|
||||
// mode 0 or 1
|
||||
void aime_set_baudrate(int mode);
|
||||
|
||||
#endif
|
||||
|
@ -42,6 +42,7 @@ static void handle_display()
|
||||
printf(" Level: [%d ~ %d]\n", aic_cfg->light.min, aic_cfg->light.max);
|
||||
printf("[AIME]\n");
|
||||
printf(" Virtual AIC: %s\n", aic_cfg->virtual_aic ? "ON" : "OFF");
|
||||
printf(" Mode: %d (%s)\n", aic_cfg->aime_mode, aime_get_mode_string());
|
||||
}
|
||||
|
||||
static void handle_save()
|
||||
@ -70,7 +71,6 @@ static void handle_nfc()
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
static void handle_virtual(int argc, char *argv[])
|
||||
{
|
||||
const char *usage = "Usage: virtual <on|off>\n";
|
||||
@ -92,6 +92,27 @@ static void handle_virtual(int argc, char *argv[])
|
||||
config_changed();
|
||||
}
|
||||
|
||||
static void handle_mode(int argc, char *argv[])
|
||||
{
|
||||
const char *usage = "Usage: mode <0:1>\n";
|
||||
if (argc != 1) {
|
||||
printf("%s", usage);
|
||||
return;
|
||||
}
|
||||
|
||||
const char *commands[] = { "0", "1" };
|
||||
int match = cli_match_prefix(commands, 2, argv[0]);
|
||||
if (match < 0) {
|
||||
printf("%s", usage);
|
||||
return;
|
||||
}
|
||||
|
||||
aic_cfg->aime_mode = match;
|
||||
|
||||
aime_set_mode(match);
|
||||
config_changed();
|
||||
}
|
||||
|
||||
static void handle_light(int argc, char *argv[])
|
||||
{
|
||||
const char *usage = "Usage: light <rgb|led|both|off>\n";
|
||||
@ -163,6 +184,7 @@ void commands_init()
|
||||
cli_register("factory", handle_factory_reset, "Reset everything to default.");
|
||||
cli_register("nfc", handle_nfc, "NFC module.");
|
||||
cli_register("virtual", handle_virtual, "Virtual AIC card.");
|
||||
cli_register("mode", handle_mode, "AIME version mode.");
|
||||
cli_register("light", handle_light, "Turn on/off lights.");
|
||||
cli_register("level", handle_level, "Set light level.");
|
||||
}
|
||||
|
@ -12,8 +12,9 @@
|
||||
aic_cfg_t *aic_cfg;
|
||||
|
||||
static aic_cfg_t default_cfg = {
|
||||
.light = { .min = 0, .max = 128, .rgb = true, .led = true },
|
||||
.light = { .min = 24, .max = 128, .rgb = true, .led = true },
|
||||
.virtual_aic = true,
|
||||
.aime_mode = 1,
|
||||
};
|
||||
|
||||
aic_runtime_t *aic_runtime;
|
||||
|
@ -17,6 +17,7 @@ typedef struct __attribute__((packed)) {
|
||||
bool led;
|
||||
} light;
|
||||
bool virtual_aic;
|
||||
uint8_t aime_mode;
|
||||
uint32_t reserved;
|
||||
} aic_cfg_t;
|
||||
|
||||
|
@ -58,10 +58,10 @@ enum {
|
||||
STATUS_INVALID_COMMAND = 3,
|
||||
};
|
||||
|
||||
const char *fw_version[] = { "TN32MSEC003S F/W Ver1.0", "\x94" };
|
||||
const char *fw_version[] = { "TN32MSEC003S F/W Ver1.2", "\x94" };
|
||||
const char *hw_version[] = { "TN32MSEC003S H/W Ver3.0", "837-15396" };
|
||||
const char *led_info[] = { "15084\xFF\x10\x00\x12", "000-00000\xFF\x11\x40" };
|
||||
static int baudrate_mode = 0;
|
||||
static int ver_mode = 1;
|
||||
|
||||
static struct {
|
||||
bool enabled;
|
||||
@ -78,9 +78,14 @@ static void putc_trap(uint8_t byte)
|
||||
|
||||
static aime_putc_func aime_putc = putc_trap;
|
||||
|
||||
void aime_set_baudrate(int mode)
|
||||
void aime_set_mode(int mode)
|
||||
{
|
||||
baudrate_mode = (mode == 0) ? 0 : 1;
|
||||
ver_mode = (mode == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
const char *aime_get_mode_string()
|
||||
{
|
||||
return hw_version[ver_mode];
|
||||
}
|
||||
|
||||
void aime_init(aime_putc_func putc_func)
|
||||
@ -156,6 +161,11 @@ static void send_response()
|
||||
uint8_t sync = 0xe0;
|
||||
aime_putc(sync);
|
||||
|
||||
printf(" -> %02x(%d)", response.status, response.status);
|
||||
if (response.payload_len > 0) {
|
||||
printf(" [%d]", response.payload_len);
|
||||
}
|
||||
|
||||
for (int i = 0; i < response.len; i++) {
|
||||
uint8_t c = response.raw[i];
|
||||
checksum += c;
|
||||
@ -184,9 +194,9 @@ static void cmd_to_normal_mode()
|
||||
|
||||
static void cmd_fake_version(const char *version[])
|
||||
{
|
||||
int len = strlen(version[baudrate_mode]);
|
||||
int len = strlen(version[ver_mode]);
|
||||
build_response(len);
|
||||
memcpy(response.payload, version[baudrate_mode], len);
|
||||
memcpy(response.payload, version[ver_mode], len);
|
||||
send_response();
|
||||
}
|
||||
|
||||
@ -359,18 +369,23 @@ static void aime_handle_frame()
|
||||
{
|
||||
switch (request.cmd) {
|
||||
case CMD_TO_NORMAL_MODE:
|
||||
printf("\nAIME: cmd_to_normal");
|
||||
cmd_to_normal_mode();
|
||||
break;
|
||||
case CMD_GET_FW_VERSION:
|
||||
printf("\nAIME: fw_version");
|
||||
cmd_fake_version(fw_version);
|
||||
break;
|
||||
case CMD_GET_HW_VERSION:
|
||||
printf("\nAIME: hw_version");
|
||||
cmd_fake_version(hw_version);
|
||||
break;
|
||||
case CMD_MIFARE_KEY_SET_A:
|
||||
printf("\nAIME: key A");
|
||||
cmd_key_set(mifare_keys[0]);
|
||||
break;
|
||||
case CMD_MIFARE_KEY_SET_B:
|
||||
printf("\nAIME: key B");
|
||||
cmd_key_set(mifare_keys[1]);
|
||||
break;
|
||||
|
||||
@ -386,38 +401,47 @@ static void aime_handle_frame()
|
||||
|
||||
case CMD_FELICA_PUSH:
|
||||
case CMD_FELICA_OP:
|
||||
printf("\nAIME: felica op");
|
||||
cmd_felica();
|
||||
break;
|
||||
|
||||
case CMD_CARD_SELECT:
|
||||
printf("\nAIME: card select");
|
||||
cmd_card_select();
|
||||
break;
|
||||
|
||||
case CMD_MIFARE_AUTHORIZE_A:
|
||||
printf("\nAIME: auth A");
|
||||
cmd_mifare_auth(0);
|
||||
break;
|
||||
|
||||
case CMD_MIFARE_AUTHORIZE_B:
|
||||
printf("\nAIME: auth B");
|
||||
cmd_mifare_auth(1);
|
||||
break;
|
||||
|
||||
case CMD_MIFARE_READ:
|
||||
printf("\nAIME: mifare read");
|
||||
cmd_mifare_read();
|
||||
break;
|
||||
|
||||
case CMD_CARD_HALT:
|
||||
printf("\nAIME: mifare halt");
|
||||
cmd_mifare_halt();
|
||||
break;
|
||||
|
||||
case CMD_EXT_BOARD_INFO:
|
||||
printf("\nAIME: led info");
|
||||
cmd_fake_version(led_info);
|
||||
break;
|
||||
case CMD_EXT_BOARD_LED_RGB:
|
||||
printf("\nAIME: led rgb");
|
||||
cmd_led_rgb();
|
||||
break;
|
||||
|
||||
case CMD_SEND_HEX_DATA:
|
||||
case CMD_EXT_TO_NORMAL_MODE:
|
||||
printf("\nAIME: hex data or ex to normal: %d", request.cmd);
|
||||
send_simple_response(STATUS_OK);
|
||||
break;
|
||||
|
||||
|
@ -229,6 +229,7 @@ void init()
|
||||
|
||||
aime_init(cdc_aime_putc);
|
||||
aime_virtual_aic(aic_cfg->virtual_aic);
|
||||
aime_set_mode(aic_cfg->aime_mode);
|
||||
|
||||
cli_init("aic_pico>", "\n << AIC Pico >>\n"
|
||||
" https://github.com/whowechina\n\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user