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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/*
Aseba - an event-based framework for distributed robot control
Copyright (C) 2007--2016:
Stephane Magnenat <stephane at magnenat dot net>
(http://stephane.magnenat.net)
and other contributors, see authors.txt for details
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ASEBA_BOOTLOADER_INTERFACE_H
#define ASEBA_BOOTLOADER_INTERFACE_H
#include <string>
#include <stdexcept>
#include "../types.h"
namespace Dashel
{
class Stream;
}
namespace Aseba
{
// TODO: change API to use HexFile instead of file names
//! Manage interactions with an aseba-compatible bootloader
/**
There are two versions of the bootloader: the complete and the simple.
The complete version works on any Aseba network including over switches
as it transmits all data using the Aseba message protocol.
The simple version requires direct access to the device to be flashed,
because it breaks the Aseba message protocol for page transmission.
*/
class BootloaderInterface
{
public:
//! An error in link with the bootloader
struct Error:public std::runtime_error
{
Error(const std::string& what): std::runtime_error(what) {}
};
public:
// main interface
//! Create an interface to bootloader with id dest using a socket
BootloaderInterface(Dashel::Stream* stream, int dest);
//! Create an interface to bootloader with id dest and different id within bootloader bootloaderDest (currently only deployed for simple mode), using a socket
BootloaderInterface(Dashel::Stream* stream, int dest, int bootloaderDest);
//! Return the size of a page
int getPageSize() const { return pageSize; }
//! Read a page
bool readPage(unsigned pageNumber, uint8_t* data);
//! Read a page, simplified protocol
bool readPageSimple(unsigned pageNumber, uint8_t * data);
//! Write a page, if simple is true, use simplified protocol, otherwise use complete protocol
bool writePage(unsigned pageNumber, const uint8_t *data, bool simple);
//! Write an hex file
void writeHex(const std::string &fileName, bool reset, bool simple);
//! Read an hex file and write it to fileName
void readHex(const std::string &fileName);
protected:
// reporting function
// progress
virtual void writePageStart(unsigned pageNumber, const uint8_t* data, bool simple) {}
virtual void writePageWaitAck() {}
virtual void writePageSuccess() {}
virtual void writePageFailure() {}
virtual void writeHexStart(const std::string &fileName, bool reset, bool simple) {}
virtual void writeHexEnteringBootloader() {}
virtual void writeHexGotDescription(unsigned pagesCount) {}
virtual void writeHexWritten() {}
virtual void writeHexExitingBootloader() {}
// non-fatal errors
//! Warn about an error but do not quit
virtual void errorWritePageNonFatal(unsigned pageNumber) {}
protected:
// member variables
Dashel::Stream* stream;
int dest, bootloaderDest;
unsigned pageSize;
unsigned pagesStart;
unsigned pagesCount;
};
} // namespace Aseba
#endif // ASEBA_BOOTLOADER_INTERFACE_H
|