mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 14:03:34 +08:00
Merge branch 'master' into lpc11c24
This commit is contained in:
@@ -75,7 +75,7 @@ protected:
|
||||
friend FDCache;
|
||||
|
||||
FDCacheItem* next_;
|
||||
time_t last_access_;
|
||||
std::time_t last_access_;
|
||||
const int fd_;
|
||||
const int oflags_;
|
||||
const char* const path_;
|
||||
@@ -101,6 +101,7 @@ protected:
|
||||
|
||||
~FDCacheItem()
|
||||
{
|
||||
using namespace std;
|
||||
if (valid())
|
||||
{
|
||||
::free(const_cast<char*>(path_));
|
||||
@@ -117,13 +118,14 @@ protected:
|
||||
return fd_;
|
||||
}
|
||||
|
||||
time_t getAccess() const
|
||||
std::time_t getAccess() const
|
||||
{
|
||||
return last_access_;
|
||||
}
|
||||
|
||||
time_t acessed()
|
||||
std::time_t acessed()
|
||||
{
|
||||
using namespace std;
|
||||
last_access_ = time(NULL);
|
||||
return getAccess();
|
||||
}
|
||||
@@ -135,11 +137,13 @@ protected:
|
||||
|
||||
bool expired() const
|
||||
{
|
||||
using namespace std;
|
||||
return 0 == last_access_ || (time(NULL) - last_access_) > MaxAgeSeconds;
|
||||
}
|
||||
|
||||
bool equals(const char* path, int oflags) const
|
||||
{
|
||||
using namespace std;
|
||||
return oflags_ == oflags && 0 == ::strcmp(path, path_);
|
||||
}
|
||||
|
||||
@@ -275,7 +279,6 @@ protected:
|
||||
if (pi && !pi->valid())
|
||||
{
|
||||
/* Allocation worked but clone or path failed */
|
||||
|
||||
delete pi;
|
||||
pi = NULL;
|
||||
}
|
||||
@@ -286,7 +289,6 @@ protected:
|
||||
* If allocation fails no harm just can not cache it
|
||||
* return open fd
|
||||
*/
|
||||
|
||||
return fd;
|
||||
}
|
||||
/* add new */
|
||||
@@ -334,7 +336,7 @@ protected:
|
||||
* Implementation of this method is required.
|
||||
* On success the method must return zero.
|
||||
*/
|
||||
virtual int16_t getInfo(const Path& path, uint64_t& out_size, EntryType& out_type)
|
||||
virtual uavcan::int16_t getInfo(const Path& path, uavcan::uint64_t& out_size, EntryType& out_type)
|
||||
{
|
||||
int rv = uavcan::protocol::file::Error::INVALID_VALUE;
|
||||
|
||||
@@ -376,12 +378,15 @@ protected:
|
||||
* if the end of file is reached.
|
||||
* On success the method must return zero.
|
||||
*/
|
||||
virtual int16_t read(const Path& path, const uint64_t offset, uint8_t* out_buffer, uint16_t& inout_size)
|
||||
virtual uavcan::int16_t read(const Path& path, const uavcan::uint64_t offset, uavcan::uint8_t* out_buffer,
|
||||
uavcan::uint16_t& inout_size)
|
||||
{
|
||||
int rv = uavcan::protocol::file::Error::INVALID_VALUE;
|
||||
|
||||
if (path.size() > 0)
|
||||
if (path.size() > 0 && inout_size != 0)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
FDCacheBase& cache = getFDCache();
|
||||
int fd = cache.open(path.c_str(), O_RDONLY);
|
||||
|
||||
@@ -391,9 +396,9 @@ protected:
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = ::lseek(fd, offset, SEEK_SET);
|
||||
ssize_t total_read = 0;
|
||||
|
||||
ssize_t len = 0;
|
||||
rv = ::lseek(fd, offset, SEEK_SET);
|
||||
|
||||
if (rv < 0)
|
||||
{
|
||||
@@ -401,21 +406,27 @@ protected:
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO use a read at offset to fill on EAGAIN
|
||||
len = ::read(fd, out_buffer, inout_size);
|
||||
|
||||
if (len < 0)
|
||||
rv = 0;
|
||||
ssize_t remaining = inout_size;
|
||||
ssize_t nread = 0;
|
||||
do
|
||||
{
|
||||
rv = errno;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = 0;
|
||||
nread = ::read(fd, &out_buffer[total_read], remaining);
|
||||
if (nread < 0)
|
||||
{
|
||||
rv = errno;
|
||||
}
|
||||
else
|
||||
{
|
||||
remaining -= nread,
|
||||
total_read += nread;
|
||||
}
|
||||
}
|
||||
while (nread > 0 && remaining > 0);
|
||||
}
|
||||
|
||||
(void)cache.close(fd, rv != 0 || len != inout_size);
|
||||
inout_size = len;
|
||||
(void)cache.close(fd, rv != 0 || total_read != inout_size);
|
||||
inout_size = total_read;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
|
||||
+16
-5
@@ -51,10 +51,22 @@ protected:
|
||||
{
|
||||
const int FormatBufferLength = 63;
|
||||
char buffer[FormatBufferLength + 1];
|
||||
int n = snprintf(buffer, FormatBufferLength, "%ld.%06ld\t%d\t%lld\n",
|
||||
static_cast<long>(ts.tv_sec), static_cast<long>(ts.tv_nsec / 1000L),
|
||||
static_cast<int>(code), static_cast<long long>(argument));
|
||||
(void)write(fd, buffer, n); // TODO FIXME Write loop
|
||||
ssize_t remaining = snprintf(buffer, FormatBufferLength, "%ld.%06ld\t%d\t%lld\n",
|
||||
static_cast<long>(ts.tv_sec), static_cast<long>(ts.tv_nsec / 1000L),
|
||||
static_cast<int>(code), static_cast<long long>(argument));
|
||||
|
||||
ssize_t total_written = 0;
|
||||
ssize_t written = 0;
|
||||
do
|
||||
{
|
||||
written = write(fd, &buffer[total_written], remaining);
|
||||
if (written > 0)
|
||||
{
|
||||
total_written += written;
|
||||
remaining -= written;
|
||||
}
|
||||
}
|
||||
while (written > 0 && remaining > 0);
|
||||
(void)close(fd);
|
||||
}
|
||||
}
|
||||
@@ -82,7 +94,6 @@ public:
|
||||
return rv;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+32
-8
@@ -55,13 +55,25 @@ protected:
|
||||
{
|
||||
char buffer[MaxStringLength + 1];
|
||||
(void)memset(buffer, 0, sizeof(buffer));
|
||||
int len = read(fd, buffer, MaxStringLength);
|
||||
(void)close(fd);
|
||||
if (len > 0)
|
||||
ssize_t remaining = MaxStringLength;
|
||||
ssize_t total_read = 0;
|
||||
ssize_t nread = 0;
|
||||
do
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
nread = ::read(fd, &buffer[total_read], remaining);
|
||||
if (nread > 0)
|
||||
{
|
||||
if (buffer[i] == ' ' || buffer[i] == '\n' || buffer[i] == '\r' )
|
||||
remaining -= nread,
|
||||
total_read += nread;
|
||||
}
|
||||
}
|
||||
while (nread > 0 && remaining > 0);
|
||||
(void)close(fd);
|
||||
if (total_read > 0)
|
||||
{
|
||||
for (int i = 0; i < total_read; i++)
|
||||
{
|
||||
if (buffer[i] == ' ' || buffer[i] == '\n' || buffer[i] == '\r')
|
||||
{
|
||||
buffer[i] = '\0';
|
||||
break;
|
||||
@@ -81,7 +93,20 @@ protected:
|
||||
int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, FilePermissions);
|
||||
if (fd >= 0)
|
||||
{
|
||||
(void)write(fd, value.c_str(), value.size()); // TODO FIXME Write loop
|
||||
ssize_t remaining = value.size();
|
||||
ssize_t total_written = 0;
|
||||
ssize_t written = 0;
|
||||
do
|
||||
{
|
||||
written = write(fd, &value.c_str()[total_written], remaining);
|
||||
if (written > 0)
|
||||
{
|
||||
total_written += written;
|
||||
remaining -= written;
|
||||
}
|
||||
}
|
||||
while (written > 0 && remaining > 0);
|
||||
|
||||
(void)fsync(fd);
|
||||
(void)close(fd);
|
||||
}
|
||||
@@ -117,7 +142,7 @@ public:
|
||||
// coverity[toctou]
|
||||
rv = mkdir(base_path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
}
|
||||
if (rv >= 0 )
|
||||
if (rv >= 0)
|
||||
{
|
||||
base_path.push_back('/');
|
||||
if ((base_path.size() + MaxStringLength) > MaxPathLength)
|
||||
@@ -129,7 +154,6 @@ public:
|
||||
return rv;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ class FirmwareVersionChecker : public uavcan::IFirmwareVersionChecker
|
||||
|
||||
int copyIfNot(const char* srcpath, const char* destpath)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
// Does the file exist
|
||||
int rv = 0;
|
||||
int dfd = open(destpath, O_RDONLY, 0);
|
||||
@@ -113,7 +115,7 @@ class FirmwareVersionChecker : public uavcan::IFirmwareVersionChecker
|
||||
}
|
||||
else
|
||||
{
|
||||
ssize_t size;
|
||||
ssize_t size = 0;
|
||||
do
|
||||
{
|
||||
size = ::read(sfd, buffer, sizeof(buffer));
|
||||
@@ -125,14 +127,28 @@ class FirmwareVersionChecker : public uavcan::IFirmwareVersionChecker
|
||||
}
|
||||
else
|
||||
{
|
||||
if (size != write(dfd, buffer, size))
|
||||
rv = 0;
|
||||
ssize_t remaining = size;
|
||||
ssize_t total_written = 0;
|
||||
ssize_t written = 0;
|
||||
do
|
||||
{
|
||||
rv = -errno;
|
||||
written = write(dfd, &buffer[total_written], remaining);
|
||||
if (written < 0)
|
||||
{
|
||||
rv = -errno;
|
||||
}
|
||||
else
|
||||
{
|
||||
total_written += written;
|
||||
remaining -= written;
|
||||
}
|
||||
}
|
||||
while (written > 0 && remaining > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (rv == 0 && size);
|
||||
while (rv == 0 && size != 0);
|
||||
|
||||
(void)close(sfd);
|
||||
}
|
||||
@@ -144,13 +160,13 @@ class FirmwareVersionChecker : public uavcan::IFirmwareVersionChecker
|
||||
|
||||
struct AppDescriptor
|
||||
{
|
||||
uint8_t signature[sizeof(uavcan::uint64_t)];
|
||||
uint64_t image_crc;
|
||||
uint32_t image_size;
|
||||
uint32_t vcs_commit;
|
||||
uint8_t major_version;
|
||||
uint8_t minor_version;
|
||||
uint8_t reserved[6];
|
||||
uavcan::uint8_t signature[sizeof(uavcan::uint64_t)];
|
||||
uavcan::uint64_t image_crc;
|
||||
uavcan::uint32_t image_size;
|
||||
uavcan::uint32_t vcs_commit;
|
||||
uavcan::uint8_t major_version;
|
||||
uavcan::uint8_t minor_version;
|
||||
uavcan::uint8_t reserved[6];
|
||||
};
|
||||
|
||||
static int getFileInfo(const char* path, AppDescriptor& descriptor)
|
||||
@@ -251,7 +267,7 @@ protected:
|
||||
node_info.hardware_version.major,
|
||||
node_info.hardware_version.minor);
|
||||
|
||||
if (n > 0 && n < (int) sizeof(fname_root) - 2)
|
||||
if (n > 0 && n < (int)sizeof(fname_root) - 2)
|
||||
{
|
||||
DIR* const fwdir = opendir(fname_root);
|
||||
|
||||
|
||||
@@ -32,22 +32,26 @@ void ledSet(bool state)
|
||||
palWritePad(GPIO_PORT_LED, GPIO_PIN_LED, state);
|
||||
}
|
||||
|
||||
int init()
|
||||
void init()
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
halInit();
|
||||
chibios_rt::System::init();
|
||||
sdStart(&STDOUT_SD, NULL);
|
||||
|
||||
res = can.init(1000000);
|
||||
if (res < 0)
|
||||
int res = 0;
|
||||
do
|
||||
{
|
||||
goto leave;
|
||||
}
|
||||
::sleep(1);
|
||||
::lowsyslog("CAN auto bit rate detection...\n");
|
||||
|
||||
leave:
|
||||
return res;
|
||||
std::uint32_t bitrate = 0;
|
||||
res = can.init([]() { ::usleep(can.getRecommendedListeningDelay().toUSec()); }, bitrate);
|
||||
if (res >= 0)
|
||||
{
|
||||
::lowsyslog("CAN inited at %u bps\n", unsigned(bitrate));
|
||||
}
|
||||
}
|
||||
while (res < 0);
|
||||
}
|
||||
|
||||
#if __GNUC__
|
||||
@@ -55,7 +59,7 @@ __attribute__((noreturn))
|
||||
#endif
|
||||
void die(int status)
|
||||
{
|
||||
lowsyslog("Now I am dead x_x %i\n", status);
|
||||
lowsyslog("Initialization failure %i\n", status);
|
||||
while (1)
|
||||
{
|
||||
ledSet(false);
|
||||
@@ -166,11 +170,7 @@ public:
|
||||
|
||||
int main()
|
||||
{
|
||||
const int init_res = app::init();
|
||||
if (init_res != 0)
|
||||
{
|
||||
app::die(init_res);
|
||||
}
|
||||
app::init();
|
||||
|
||||
lowsyslog("Starting the UAVCAN thread\n");
|
||||
app::uavcan_node_thread.start(LOWPRIO);
|
||||
|
||||
Reference in New Issue
Block a user