Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
Reboot.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, Cascoda Ltd.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef POSIX_APP_CHILICTL_REBOOT_REBOOT_HPP_
30 #define POSIX_APP_CHILICTL_REBOOT_REBOOT_HPP_
31 
32 #include <mutex>
33 
34 #include "common/Args.hpp"
35 #include "common/Command.hpp"
36 #include "common/DeviceList.hpp"
37 
38 #include "ca821x_error.h"
39 
40 namespace ca {
41 
42 class Reboot : public Command
43 {
44 public:
45  enum State
46  {
47  INIT,
51  FAIL,
52  };
53  Reboot();
54  ~Reboot();
55 
59  ca_error Process(int argc, const char *argv[]);
60 
61 private:
62  enum
63  {
64  kMsgSendTimeout = 5,
65  };
66 
67  std::mutex mMutex;
68  State mState;
69  Args mArgParser;
70  ArgOpt mHelpArg;
71  ArgOpt mSerialArg;
72  ArgOpt mBatchArg;
73  ArgOpt mFactoryReset;
74  ArgOpt mEnumerateUartDevicesArg;
75  DeviceList mDeviceList;
76  DeviceListFilter mDeviceListFilter;
77  ca821x_dev mDeviceRef;
78  DeviceInfo mDeviceInfo;
79 
80  // State machine
81  ca_error reboot_process();
82 
83  // init state
84  ca_error init();
85 
86  // Requests factory reset from target device
87  ca_error factory_reset();
88 
89  // Finalizes factory reset, this function is called from callback
90  // which is triggered when host receives EVBME DFU_STATUS from target device
91  ca_error factory_reset_done(ca_error status);
92 
93  // Makes the target device reboot (normal reboot, APROM to APROM)
94  ca_error reboot();
95 
96  // Callbacks for handling received EVBME_DFU from target device
97  ca_error dfu_callback(EVBME_Message *params);
98  static ca_error dfu_callback(EVBME_Message *params, ca821x_dev *pDeviceRef);
99 
100  // Callbacks for handling received EVBME_MESSAGES from target device
101  ca_error handle_evbme_message(EVBME_Message *params);
102  static ca_error handle_evbme_message(EVBME_Message *params, ca821x_dev *pDeviceRef);
103 
104  ca_error print_help_string(const char *aArg);
105  ca_error set_serialno_filter(const char *aArg);
106 
107  void set_state(State aNextState);
108  static const char *state_string(State aState);
109 };
110 
111 } /* namespace ca */
112 
113 #endif /* POSIX_APP_CHILICTL_REBOOT_REBOOT_HPP_ */
Global error declarations for use across the Cascoda SDK.
Abstract class for handling command positional arguments, to be implemented by the command classes.
Definition: Command.hpp:40
Definition: Reboot.hpp:43
State
Definition: Reboot.hpp:46
@ REBOOT
Rebooting the device.
Definition: Reboot.hpp:49
@ FACTORY_RESET
Erasing Data Flash region.
Definition: Reboot.hpp:48
@ INIT
Initial state.
Definition: Reboot.hpp:47
@ FAIL
Flashing failed.
Definition: Reboot.hpp:51
@ COMPLETE
Flashing completed successfully.
Definition: Reboot.hpp:50
ca_error Process(int argc, const char *argv[])
Run the command, processing the arguments passed in argv.
Definition: Reboot.cpp:81
~Reboot()
Definition: Reboot.cpp:76
Reboot()
Definition: Reboot.cpp:47
ca_error
Cascoda error type.
Definition: ca821x_error.h:51
Definition: Args.cpp:34
EVBME Message command in Cascoda TLV format.
Definition: evbme_messages.h:258
CA-821x Device reference struct.
Definition: ca821x_api.h:123