main.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. *
  3. * Copyright (c) 2020 Project CHIP Authors
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #include "mbedtls/platform.h"
  18. #include <ChipShellCollection.h>
  19. #include <DFUManager.h>
  20. #include <lib/core/CHIPCore.h>
  21. #include <lib/shell/Engine.h>
  22. #include <lib/support/CHIPMem.h>
  23. #include <lib/support/logging/CHIPLogging.h>
  24. #include <platform/CHIPDeviceLayer.h>
  25. #include <platform/mbed/Logging.h>
  26. using namespace ::chip;
  27. using namespace ::chip::Shell;
  28. using namespace ::chip::DeviceLayer;
  29. using namespace ::chip::Logging::Platform;
  30. int main()
  31. {
  32. int ret = 0;
  33. CHIP_ERROR err = CHIP_NO_ERROR;
  34. mbed_logging_init();
  35. ChipLogProgress(NotSpecified, "Mbed shell example application start");
  36. ret = mbedtls_platform_setup(NULL);
  37. if (ret)
  38. {
  39. ChipLogError(Shell, "Mbed TLS platform initialization failed [%d]", ret);
  40. goto exit;
  41. }
  42. err = chip::Platform::MemoryInit();
  43. if (err != CHIP_NO_ERROR)
  44. {
  45. ChipLogError(Shell, "Memory initialization failed: %s", err.AsString());
  46. ret = EXIT_FAILURE;
  47. goto exit;
  48. }
  49. err = PlatformMgr().InitChipStack();
  50. if (err != CHIP_NO_ERROR)
  51. {
  52. ChipLogError(Shell, "Chip stack initialization failed: %s", err.AsString());
  53. ret = EXIT_FAILURE;
  54. goto exit;
  55. }
  56. #ifdef MBED_CONF_APP_BLE_DEVICE_NAME
  57. err = ConnectivityMgr().SetBLEDeviceName(MBED_CONF_APP_BLE_DEVICE_NAME);
  58. if (err != CHIP_NO_ERROR)
  59. {
  60. ChipLogError(Shell, "Set BLE device name failed: %s", err.AsString());
  61. ret = EXIT_FAILURE;
  62. goto exit;
  63. }
  64. #endif
  65. err = PlatformMgr().StartEventLoopTask();
  66. if (err != CHIP_NO_ERROR)
  67. {
  68. ChipLogError(Shell, "Chip stack start failed: %s", err.AsString());
  69. ret = EXIT_FAILURE;
  70. goto exit;
  71. }
  72. err = GetDFUManager().Init();
  73. if (err != CHIP_NO_ERROR)
  74. {
  75. ChipLogError(NotSpecified, "DFU manager initialization failed: %s", err.AsString());
  76. ret = EXIT_FAILURE;
  77. goto exit;
  78. }
  79. // Initialize the default streamer that was linked.
  80. ret = Engine::Root().Init();
  81. if (ret)
  82. {
  83. ChipLogError(Shell, "Streamer initialization failed [%d]", ret);
  84. goto exit;
  85. }
  86. cmd_misc_init();
  87. cmd_otcli_init();
  88. cmd_app_server_init();
  89. ChipLogProgress(NotSpecified, "Mbed shell example application run");
  90. Engine::Root().RunMainLoop();
  91. exit:
  92. ChipLogProgress(NotSpecified, "Exited with code %d", ret);
  93. return ret;
  94. }