ppp_sample.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-08-15 xiangxistu the first version
  9. * 2019-09-26 xiangxistu add ppp_device_attach and ppp_device_detach
  10. */
  11. #include<rtthread.h>
  12. #include<ppp_device.h>
  13. #define DBG_TAG "ppp.sample"
  14. #ifdef PPP_DEVICE_DEBUG
  15. #define DBG_LVL DBG_LOG
  16. #else
  17. #define DBG_LVL DBG_INFO
  18. #endif
  19. #include <rtdbg.h>
  20. /* if you want connect network again, you can use this function to create a new ppp link */
  21. int ppp_sample_start(void)
  22. {
  23. rt_device_t device = RT_NULL;
  24. device = rt_device_find(PPP_DEVICE_NAME);
  25. if(device == RT_NULL)
  26. {
  27. LOG_E("Can't find device (%s).", PPP_DEVICE_NAME);
  28. return -RT_ERROR;
  29. }
  30. if(ppp_device_attach((struct ppp_device *)device, PPP_CLIENT_NAME, RT_NULL) != RT_EOK)
  31. {
  32. LOG_E("ppp_device_attach execute failed.");
  33. return -RT_ERROR;
  34. }
  35. return RT_EOK;
  36. }
  37. INIT_APP_EXPORT(ppp_sample_start);
  38. MSH_CMD_EXPORT_ALIAS(ppp_sample_start, ppp_start, a sample of ppp device for dailing to network);
  39. /* close ppp link ,turn off modem form network */
  40. int ppp_sample_stop(void)
  41. {
  42. rt_device_t device = RT_NULL;
  43. device = rt_device_find(PPP_DEVICE_NAME);
  44. if(device == RT_NULL)
  45. {
  46. LOG_E("Can't find device (%s).", PPP_DEVICE_NAME);
  47. return -RT_ERROR;
  48. }
  49. if(ppp_device_detach((struct ppp_device *)device) != RT_EOK)
  50. {
  51. LOG_E("ppp_device_detach execute failed.");
  52. return -RT_ERROR;
  53. }
  54. return RT_EOK;
  55. }
  56. MSH_CMD_EXPORT_ALIAS(ppp_sample_stop, ppp_stop, a sample of ppp device for turning off network);
  57. #ifdef PPP_DEVICE_DEBUG_DROP
  58. static int ppp_drop(void)
  59. {
  60. rt_device_t device = RT_NULL;
  61. struct ppp_device *ppp_device;
  62. device = rt_device_find(PPP_DEVICE_NAME);
  63. if(device == RT_NULL)
  64. {
  65. LOG_E("Can't find device (%s).", PPP_DEVICE_NAME);
  66. return -RT_ERROR;
  67. }
  68. ppp_device = (struct ppp_device*)device;
  69. LOG_I("%ld", (unsigned long)(ppp_device->dropcnt + ppp_device->droppos));
  70. return RT_EOK;
  71. }
  72. MSH_CMD_EXPORT_ALIAS(ppp_drop, ppp_drop, show drop statistics);
  73. #endif