1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/*
* ExpansionManager.h
*
* Created on: 4 Feb 2020
* Author: David
*/
#ifndef SRC_CAN_EXPANSIONMANAGER_H_
#define SRC_CAN_EXPANSIONMANAGER_H_
#include <RepRapFirmware.h>
#if SUPPORT_CAN_EXPANSION
#include <ObjectModel/ObjectModel.h>
#include <CanId.h>
#include <CanMessageBuffer.h>
#include <General/NamedEnum.h>
NamedEnum(BoardState, uint8_t, unknown, flashing, flashFailed, resetting, running);
struct ExpansionBoardData
{
ExpansionBoardData() noexcept;
const char *typeName;
MinMaxCurrent mcuTemp, vin, v12;
BoardState state;
uint8_t numDrivers;
};
class ExpansionManager INHERIT_OBJECT_MODEL
{
public:
ExpansionManager() noexcept;
unsigned int GetNumExpansionBoards() const noexcept { return numExpansionBoards; }
void ProcessAnnouncement(CanMessageBuffer *buf) noexcept;
const ExpansionBoardData *GetBoardDetails(uint8_t address) const noexcept;
// Firmware update and related functions
GCodeResult ResetRemote(uint32_t boardAddress, GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException);
GCodeResult UpdateRemoteFirmware(uint32_t boardAddress, GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException);
void UpdateFinished(CanAddress address) noexcept;
void UpdateFailed(CanAddress address) noexcept;
bool IsFlashing() const noexcept { return numBoardsFlashing != 0; }
void EmergencyStop() noexcept;
const ExpansionBoardData& FindIndexedBoard(unsigned int index) const noexcept;
protected:
DECLARE_OBJECT_MODEL
private:
void UpdateBoardState(CanAddress address, BoardState newState) noexcept;
unsigned int numExpansionBoards;
unsigned int numBoardsFlashing;
mutable volatile unsigned int lastIndexSearched; // the last board index we searched for, or 0 if invalid
mutable volatile unsigned int lastAddressFound; // if lastIndexSearched is nonzero, this is the corresponding board address we found
ExpansionBoardData boards[CanId::MaxCanAddress + 1]; // the first entry is a dummy one
};
#endif // SUPPORT_CAN_EXPANSION
#endif /* SRC_CAN_EXPANSIONMANAGER_H_ */
|