* @ingroup group_finsh * * This function sets the input device of finsh shell. * * @param device_name the name of new input device. */
| 217 | * @param device_name the name of new input device. |
| 218 | */ |
| 219 | void finsh_set_device(const char *device_name) |
| 220 | { |
| 221 | rt_device_t dev = RT_NULL; |
| 222 | |
| 223 | RT_ASSERT(shell != RT_NULL); |
| 224 | dev = rt_device_find(device_name); |
| 225 | if (dev == RT_NULL) |
| 226 | { |
| 227 | rt_kprintf("finsh: can not find device: %s\n", device_name); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | /* check whether it's a same device */ |
| 232 | if (dev == shell->device) return; |
| 233 | /* open this device and set the new device in finsh shell */ |
| 234 | if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | \ |
| 235 | RT_DEVICE_FLAG_STREAM) == RT_EOK) |
| 236 | { |
| 237 | if (shell->device != RT_NULL) |
| 238 | { |
| 239 | /* close old finsh device */ |
| 240 | rt_device_close(shell->device); |
| 241 | rt_device_set_rx_indicate(shell->device, RT_NULL); |
| 242 | } |
| 243 | |
| 244 | /* clear line buffer before switch to new device */ |
| 245 | rt_memset(shell->line, 0, sizeof(shell->line)); |
| 246 | shell->line_curpos = shell->line_position = 0; |
| 247 | |
| 248 | shell->device = dev; |
| 249 | rt_device_set_rx_indicate(dev, finsh_rx_ind); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * @ingroup group_finsh |
no test coverage detected