static int cmd_set_bits_per_sample_cb(int argc, const char *argv[], void *out_p, void *in_p, void *arg_p, void *call_arg_p) { long bits_per_sample; if (argc != 2) { std_fprintf(out_p, FSTR("Usage: %s <number of bits>\r\n"), argv[0]); return (-EINVAL); } if (std_strtol(argv[1], &bits_per_sample) != 0) { std_fprintf(out_p, FSTR("Usage: %s <number of bits>\r\n"), argv[0]); return (-EINVAL); } if ((bits_per_sample < 0) || (bits_per_sample > 12)) { std_printf(FSTR("The number of bits per sample bust be " "an interger from 0 to 12.\r\n")); return (-EINVAL); } return (music_player_set_bits_per_sample(&music_player, bits_per_sample)); }
static int cmd_list_cb(int argc, const char *argv[], void *out_p, void *in_p, void *arg_p, void *call_arg_p) { struct song_t *song_p; int number; if (argc != 1) { std_fprintf(out_p, FSTR("Usage: %s\r\n"), argv[0]); return (1); } /* Write the header. */ std_fprintf(out_p, FSTR("NUMBER NAME LENGTH\r\n")); /* Iterate over all songs in the ordered hash map. */ for (number = FIRST_SONG_NUMBER; ((song_p = hash_map_get(&song_map, number)) != NULL); number++) { std_fprintf(out_p, FSTR("%6d %15s %4d:%02d\r\n"), song_p->number, song_p->name, song_p->minutes, song_p->seconds); } return (0); }
static int cmd_read_cb(int argc, const char *argv[], void *out_p, void *in_p, void *arg_p, void *call_arg_p) { int pin; int value; if (argc != 2) { std_fprintf(out_p, FSTR("Usage: %s <pin>\r\n"), argv[0]); return (-EINVAL); } /* Get pin. */ pin = board_pin_string_to_device_index(argv[1]); if (pin == -1) { std_fprintf(out_p, FSTR("%s: bad pin\r\n"), argv[1]); return (-EINVAL); } value = pin_device_read(&pin_device[pin]); if (value == 1) { std_fprintf(out_p, FSTR("high\r\n")); } else { std_fprintf(out_p, FSTR("low\r\n")); } return (0); }
static int print(struct usb_device_driver_base_t *base_p, void *chout_p) { struct usb_device_class_cdc_driver_t *self_p; self_p = (struct usb_device_class_cdc_driver_t *)base_p; std_fprintf(chout_p, FSTR("CDC ACM (emulated serial port over USB)\r\n" " endpoint_in = %d\r\n" " endpoint_out = %d\r\n" " line_state = %d\r\n" " line_info {\r\n" " dte_rate = %ld\r\n" " char_format = %d\r\n" " parity_type = %d\r\n" " data_bits = %d\r\n" " }\r\n"), self_p->endpoint_in, self_p->endpoint_out, self_p->line_state, (long)self_p->line_info.dte_rate, (int)self_p->line_info.char_format, (int)self_p->line_info.parity_type, (int)self_p->line_info.data_bits); return (0); }
static int cmd_set_mode_cb(int argc, const char *argv[], void *out_p, void *in_p, void *arg_p, void *call_arg_p) { int pin; int mode; if (argc != 3) { std_fprintf(out_p, FSTR("Usage: %s <pin> <mode>\r\n"), argv[0]); return (-EINVAL); } /* Get pin. */ pin = board_pin_string_to_device_index(argv[1]); if (pin == -1) { std_fprintf(out_p, FSTR("%s: bad pin\r\n"), argv[1]); return (-EINVAL); } /* Get mode. */ if (strcmp(argv[2], "output") == 0) { mode = PIN_OUTPUT; } else if (strcmp(argv[2], "input") == 0) { mode = PIN_INPUT; } else { std_fprintf(out_p, FSTR("%s: bad mode\r\n"), argv[2]); return (-EINVAL); } pin_device_set_mode(&pin_device[pin], mode); return (0); }
int cmd_stop(int argc, const char *argv[], void *out_p, void *in_p) { if (argc != 1) { std_fprintf(out_p, FSTR("Usage: %s\r\n"), argv[0]); return (-EINVAL); } return (music_player_song_stop(&music_player)); }
int cmd_prev(int argc, const char *argv[], void *out_p, void *in_p) { if (argc != 1) { std_fprintf(out_p, FSTR("Usage: %s\r\n"), argv[0]); return (-EINVAL); } return (prev()); }
static int cmd_write_cb(int argc, const char *argv[], void *out_p, void *in_p, void *arg_p, void *call_arg_p) { int pin; if (argc != 3) { std_fprintf(out_p, FSTR("Usage: %s <pin> <value>\r\n"), argv[0]); return (-EINVAL); } /* Get pin. */ pin = board_pin_string_to_device_index(argv[1]); if (pin == -1) { std_fprintf(out_p, FSTR("%s: bad pin\r\n"), argv[1]); return (-EINVAL); } /* Get mode. */ if (strcmp(argv[2], "high") == 0) { pin_device_write_high(&pin_device[pin]); } else if (strcmp(argv[2], "low") == 0) { pin_device_write_low(&pin_device[pin]); } else { std_fprintf(out_p, FSTR("Bad value '%s',\r\n"), argv[2]); return (-EINVAL); } return (0); }
static int cmd_next_cb(int argc, const char *argv[], void *out_p, void *in_p, void *arg_p, void *call_arg_p) { if (argc != 1) { std_fprintf(out_p, FSTR("Usage: %s\r\n"), argv[0]); return (-EINVAL); } return (next()); }
static int cmd_pause_cb(int argc, const char *argv[], void *out_p, void *in_p, void *arg_p, void *call_arg_p) { if (argc != 1) { std_fprintf(out_p, FSTR("Usage: %s\r\n"), argv[0]); return (-EINVAL); } return (music_player_song_pause(&music_player)); }
static int cmd_at_cb(int argc, const char *argv[], void *out_p, void *in_p, void *arg_p, void *call_arg_p) { struct chan_list_t list; void *chan_p; char c; char buf[32]; std_fprintf(out_p, OSTR("type ctrl-d to exit\r\n")); /* Wait for data from PC and HC-0X. */ chan_list_init(&list, buf, sizeof(buf)); chan_list_add(&list, &uart.chin); chan_list_add(&list, in_p); /* Pass data between PC and bluetooth device. */ while (1) { chan_p = chan_list_poll(&list, NULL); if (chan_p == in_p) { chan_read(chan_p, &c, sizeof(c)); /* break if EOT is found, otherwise write to HC-0X. */ if (c == EOT) { break; } chan_write(&uart.chout, &c, sizeof(c)); } else if (chan_p == &uart.chin) { /* Write all output from HC-0X to the PC. */ chan_read(chan_p, &c, sizeof(c)); chan_write(out_p, &c, sizeof(c)); } else { std_printf(OSTR("bad input channel 0x%02x\r\n"), (int)chan_p); } } chan_list_destroy(&list); return (0); }
static int cmd_play_cb(int argc, const char *argv[], void *out_p, void *in_p, void *arg_p, void *call_arg_p) { long song_number; struct song_t *song_p; if (argc > 2) { std_fprintf(out_p, FSTR("Usage: %s [<song number>]\r\n"), argv[0]); return (-EINVAL); } if (argc == 2) { if (std_strtol(argv[1], &song_number) != 0) { return (-EINVAL); } /* Find the song in the hash map. */ song_p = hash_map_get(&song_map, song_number); if (song_p == NULL) { return (-EINVAL); } /* Stop the current song and set the new current song. */ music_player_song_stop(&music_player); sem_take(&sem, NULL); current_song = song_number; sem_give(&sem, 1); } /* Play the song or resume it if it's paused. */ return (music_player_song_play(&music_player)); }
void esp_wifi_print(void *chout_p) { ASSERTNRV(chout_p != NULL, EINVAL); int i; int number_of_infos; int number_of_connections; struct esp_wifi_softap_station_info_t info[4]; struct inet_if_ip_info_t ip_info; char buf[16]; char *op_mode_p; char *phy_mode_p; const char *connection_status_p; char *dhcp_status_p; /* Get the operating mode. */ switch (esp_wifi_get_op_mode()) { case esp_wifi_op_mode_null_t: op_mode_p = "NULL"; break; case esp_wifi_op_mode_station_t: op_mode_p = "STA"; break; case esp_wifi_op_mode_softap_t: op_mode_p = "AP"; break; case esp_wifi_op_mode_station_softap_t: op_mode_p = "STA-AP"; break; default: op_mode_p = "INVALID"; break; } /* Get the physical mode. */ switch (esp_wifi_get_phy_mode()) { case esp_wifi_phy_mode_11b_t: phy_mode_p = "b"; break; case esp_wifi_phy_mode_11g_t: phy_mode_p = "g"; break; case esp_wifi_phy_mode_11n_t: phy_mode_p = "n"; break; default: phy_mode_p = "invalid"; break; } /* Get the DHCP server status. */ switch (esp_wifi_softap_dhcp_server_status()) { case esp_wifi_dhcp_status_running_t: dhcp_status_p = "running"; break; case esp_wifi_dhcp_status_stopped_t: dhcp_status_p = "stopped"; break; default: dhcp_status_p = "invalid"; break; } std_fprintf(chout_p, FSTR("General information:\r\n" " Operating mode: %s\r\n" " Physical mode: 11%s\r\n" "\r\n"), op_mode_p, phy_mode_p); memset(&ip_info, 0, sizeof(ip_info)); esp_wifi_softap_get_ip_info(&ip_info); number_of_connections = esp_wifi_softap_get_number_of_connected_stations(); number_of_infos = esp_wifi_softap_get_station_info(info, membersof(info)); std_fprintf(chout_p, FSTR("SoftAP:\r\n" " DHCP server status: %s\r\n" " Address: %s\r\n"), dhcp_status_p, inet_ntoa(&ip_info.address, &buf[0])); std_fprintf(chout_p, FSTR(" Netmask: %s\r\n"), inet_ntoa(&ip_info.netmask, &buf[0])); std_fprintf(chout_p, FSTR(" Gateway: %s\r\n" " Number of connections: %d\r\n"), inet_ntoa(&ip_info.gateway, &buf[0]), number_of_connections); for (i = 0; i < number_of_infos; i++) { std_fprintf(chout_p, FSTR(" [%d]: BSSID: %02x:%02x:%02x:%02x:%02x:%02x," " IP: %s\r\n"), i, (int)info[i].bssid[0], (int)info[i].bssid[1], (int)info[i].bssid[2], (int)info[i].bssid[3], (int)info[i].bssid[4], (int)info[i].bssid[5], inet_ntoa(&info[i].ip_address, &buf[0])); } /* Get the station connection status. */ connection_status_p = esp_wifi_station_status_as_string(esp_wifi_station_get_status()); /* Get the DHCP client status. */ switch (esp_wifi_station_dhcp_client_status()) { case esp_wifi_dhcp_status_running_t: dhcp_status_p = "running"; break; case esp_wifi_dhcp_status_stopped_t: dhcp_status_p = "stopped"; break; default: dhcp_status_p = "invalid"; break; } memset(&ip_info, 0, sizeof(ip_info)); esp_wifi_station_get_ip_info(&ip_info); std_fprintf(chout_p, FSTR("\r\n" "Station:\r\n" " DHCP client status: %s\r\n" " Conenction status: %s\r\n" " Address: %s\r\n"), dhcp_status_p, connection_status_p, inet_ntoa(&ip_info.address, &buf[0])); std_fprintf(chout_p, FSTR(" Netmask: %s\r\n"), inet_ntoa(&ip_info.netmask, &buf[0])); std_fprintf(chout_p, FSTR(" Gateway: %s\r\n" "\r\n"), inet_ntoa(&ip_info.gateway, &buf[0])); }
static int cmd_list_cb(int argc, const char *argv[], void *chout_p, void *chin_p, void *arg_p, void *call_arg_p) { const FAR struct setting_t *setting_p; int i; int8_t int8; int16_t int16; int32_t int32; char buf[32]; size_t size; /* Print the header. */ std_fprintf(chout_p, FSTR("NAME TYPE SIZE VALUE\r\n")); /* Print all settings. */ setting_p = &settings[0]; while (setting_p->name_p != NULL) { /* Print the name. */ if (std_strlen(setting_p->name_p) >= sizeof(buf)) { continue; } std_strcpy(buf, setting_p->name_p); std_fprintf(chout_p, FSTR("%-20s "), buf); size = setting_p->size; switch (setting_p->type) { case setting_type_int8_t: int8 = 0; settings_read(&int8, setting_p->address, size); std_fprintf(chout_p, FSTR("int8_t 1 %d\r\n"), (int)int8); break; case setting_type_int16_t: int16 = 0; settings_read(&int16, setting_p->address, size); std_fprintf(chout_p, FSTR("int16_t 2 %d\r\n"), (int)int16); break; case setting_type_int32_t: int32 = 0; settings_read(&int32, setting_p->address, size); std_fprintf(chout_p, FSTR("int32_t 4 %ld\r\n"), (long)int32); break; case setting_type_string_t: std_fprintf(chout_p, FSTR("string %4u "), (int)size); for (i = 0; i < size; i++) { settings_read(&buf[0], setting_p->address + i, 1); if (buf[0] == '\0') { break; } std_fprintf(chout_p, FSTR("%c"), buf[0]); } std_fprintf(chout_p, FSTR("\r\n")); break; default: std_fprintf(chout_p, FSTR("bad setting type %d\r\n"), setting_p->type); } setting_p++; } return (0); }
static int cmd_write_cb(int argc, const char *argv[], void *chout_p, void *chin_p, void *arg_p, void *call_arg_p) { const FAR struct setting_t *setting_p; long value; int8_t int8; int16_t int16; int32_t int32; if (argc != 3) { std_fprintf(chout_p, FSTR("Usage: %s <name> <value>\r\n"), argv[0]); return (-1); } /* Find the setting in the settings array. */ setting_p = &settings[0]; while (setting_p->name_p != NULL) { if (std_strcmp(argv[1], setting_p->name_p) == 0) { switch (setting_p->type) { case setting_type_int8_t: if (std_strtol(argv[2], &value) == NULL) { return (-1); } /* Range check. */ if ((value > 127) || (value < -128)) { std_fprintf(chout_p, FSTR("%ld: value out of range\r\n"), value); return (-1); } int8 = (int8_t)value; settings_write(setting_p->address, &int8, setting_p->size); break; case setting_type_int16_t: if (std_strtol(argv[2], &value) == NULL) { return (-1); } /* Range check. */ if ((value > 32767) || (value < -32768)) { std_fprintf(chout_p, FSTR("%ld: value out of range\r\n"), value); return (-1); } int16 = (int16_t)value; settings_write(setting_p->address, &int16, setting_p->size); break; case setting_type_int32_t: if (std_strtol(argv[2], &value) == NULL) { return (-1); } /* Range check. */ if ((value > 2147483647) || (value < -2147483648)) { std_fprintf(chout_p, FSTR("%ld: value out of range\r\n"), value); return (-1); } int32 = (int32_t)value; settings_write(setting_p->address, &int32, setting_p->size); break; case setting_type_string_t: /* Range check. */ if (strlen(argv[2]) >= setting_p->size) { std_fprintf(chout_p, FSTR("%s: string too long\r\n"), argv[2]); return (-1); } settings_write(setting_p->address, argv[2], setting_p->size); break; default: std_fprintf(chout_p, FSTR("bad setting type %d\r\n"), setting_p->type); } return (0); } setting_p++; } std_fprintf(chout_p, FSTR("%s: setting not found\r\n"), argv[1]); return (-1); }
static int cmd_read_cb(int argc, const char *argv[], void *chout_p, void *chin_p, void *arg_p, void *call_arg_p) { const FAR struct setting_t *setting_p; int i; int8_t int8; int16_t int16; int32_t int32; char buf[1]; if (argc != 2) { std_fprintf(chout_p, FSTR("Usage: %s <name>\r\n"), argv[0]); return (-1); } /* Find the setting in the settings array. */ setting_p = &settings[0]; while (setting_p->name_p != NULL) { if (std_strcmp(argv[1], setting_p->name_p) == 0) { switch (setting_p->type) { case setting_type_int8_t: int8 = 0; settings_read(&int8, setting_p->address, setting_p->size); std_fprintf(chout_p, FSTR("%d\r\n"), (int)int8); break; case setting_type_int16_t: int16 = 0; settings_read(&int16, setting_p->address, setting_p->size); std_fprintf(chout_p, FSTR("%d\r\n"), (int)int16); break; case setting_type_int32_t: int32 = 0; settings_read(&int32, setting_p->address, setting_p->size); std_fprintf(chout_p, FSTR("%ld\r\n"), (long)int32); break; case setting_type_string_t: for (i = 0; i < setting_p->size; i++) { buf[0] = '\0'; settings_read(&buf[0], setting_p->address + i, 1); if (buf[0] == '\0') { break; } std_fprintf(chout_p, FSTR("%c"), buf[0]); } std_fprintf(chout_p, FSTR("\r\n")); break; default: std_fprintf(chout_p, FSTR("bad setting type %d\r\n"), setting_p->type); } return (0); } setting_p++; } std_fprintf(chout_p, FSTR("%s: setting not found\r\n"), argv[1]); return (-1); }