rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
wifi_firmware_updater.cpp File Reference

Functions

static bool isBigEndian ()
 
static uint32_t fromNetwork32 (uint32_t from)
 
static uint16_t fromNetwork16 (uint16_t from)
 
static uint32_t toNetwork32 (uint32_t to)
 
static uint16_t toNetwork16 (uint16_t to)
 
struct __attribute__ ((__packed__))
 
static int readch ()
 
static void receivePacket (UartPacket *pkt, uint8_t *payload)
 
static void serialPrint (const uint8_t *data, size_t length)
 
static void serialPrintStr (const char *str)
 
void startWifiUpdater ()
 

Variables

 UartPacket
 
static const int MAX_PAYLOAD_SIZE = 256
 
static UartPacket pkt
 
static uint8_t payload [MAX_PAYLOAD_SIZE]
 
static WifiUpdaterThread wifiUpdater
 

Function Documentation

◆ __attribute__()

struct __attribute__ ( (__packed__)  )

Definition at line 43 of file wifi_firmware_updater.cpp.

48 {
49 uint8_t command;
50 uint32_t address;
51 uint32_t arg1;
52 uint16_t payloadLength;
53
54 // payloadLenght bytes of data follows...
Here is the call graph for this function:

◆ fromNetwork16()

static uint16_t fromNetwork16 ( uint16_t  from)
static

Definition at line 26 of file wifi_firmware_updater.cpp.

26 {
27 static bool be = isBigEndian();
28 if (be) {
29 return from;
30 } else {
31 uint8_t *pFrom = reinterpret_cast<uint8_t *>(&from);
32 uint16_t to;
33 to = pFrom[0]; to <<= 8;
34 to |= pFrom[1];
35 return to;
36 }
37}
static bool isBigEndian()

Referenced by __attribute__(), and receivePacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromNetwork32()

static uint32_t fromNetwork32 ( uint32_t  from)
static

Definition at line 11 of file wifi_firmware_updater.cpp.

11 {
12 static const bool be = isBigEndian();
13 if (be) {
14 return from;
15 } else {
16 uint8_t *pFrom = reinterpret_cast<uint8_t *>(&from);
17 uint32_t to;
18 to = pFrom[0]; to <<= 8;
19 to |= pFrom[1]; to <<= 8;
20 to |= pFrom[2]; to <<= 8;
21 to |= pFrom[3];
22 return to;
23 }
24}

Referenced by receivePacket(), and toNetwork32().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isBigEndian()

static bool isBigEndian ( )
static

Definition at line 5 of file wifi_firmware_updater.cpp.

5 {
6 uint32_t test = 0x11223344;
7 uint8_t *pTest = reinterpret_cast<uint8_t *>(&test);
8 return pTest[0] == 0x11;
9}
union test_buffers test
Definition test.c:50

Referenced by fromNetwork16(), and fromNetwork32().

Here is the caller graph for this function:

◆ readch()

static int readch ( )
static

Definition at line 65 of file wifi_firmware_updater.cpp.

65 {
66 uint8_t buf;
67 int ret = chnReadTimeout(&SDU1, &buf, 1, TIME_MS2I(1));
68
69 if (ret == 0) {
70 return -1;
71 } else {
72 return (int)buf;
73 }
74}
BaseChannel SDU1

Referenced by receivePacket().

Here is the caller graph for this function:

◆ receivePacket()

static void receivePacket ( UartPacket pkt,
uint8_t *  payload 
)
static

Definition at line 76 of file wifi_firmware_updater.cpp.

76 {
77 // Read command
78 uint8_t *p = reinterpret_cast<uint8_t *>(pkt);
79 uint16_t l = sizeof(UartPacket);
80 while (l > 0) {
81 int c = readch();
82 if (c == -1)
83 continue;
84 *p++ = c;
85 l--;
86 }
87
88 // Convert parameters from network byte order to cpu byte order
89 pkt->address = fromNetwork32(pkt->address);
90 pkt->arg1 = fromNetwork32(pkt->arg1);
91 pkt->payloadLength = fromNetwork16(pkt->payloadLength);
92
93 // Read payload
94 l = pkt->payloadLength;
95 while (l > 0) {
96 int c = readch();
97 if (c == -1)
98 continue;
99 *payload++ = c;
100 l--;
101 }
102}
static uint8_t payload[MAX_PAYLOAD_SIZE]
static uint32_t fromNetwork32(uint32_t from)
static int readch()
static uint16_t fromNetwork16(uint16_t from)
static UartPacket pkt
Here is the call graph for this function:

◆ serialPrint()

static void serialPrint ( const uint8_t *  data,
size_t  length 
)
static

Definition at line 109 of file wifi_firmware_updater.cpp.

109 {
110 chnWriteTimeout(&SDU1, data, length, TIME_MS2I(100));
111}

Referenced by serialPrintStr().

Here is the caller graph for this function:

◆ serialPrintStr()

static void serialPrintStr ( const char str)
static

Definition at line 113 of file wifi_firmware_updater.cpp.

113 {
114 size_t len = strlen(str);
115 serialPrint(reinterpret_cast<const uint8_t*>(str), len);
116}
static void serialPrint(const uint8_t *data, size_t length)
Here is the call graph for this function:

◆ startWifiUpdater()

void startWifiUpdater ( )

Definition at line 188 of file wifi_firmware_updater.cpp.

188 {
189 wifiUpdater.start();
190}
static WifiUpdaterThread wifiUpdater

◆ toNetwork16()

static uint16_t toNetwork16 ( uint16_t  to)
static

Definition at line 43 of file wifi_firmware_updater.cpp.

43 {
44 return fromNetwork16(to);
45}

◆ toNetwork32()

static uint32_t toNetwork32 ( uint32_t  to)
static

Definition at line 39 of file wifi_firmware_updater.cpp.

39 {
40 return fromNetwork32(to);
41}
Here is the call graph for this function:

Variable Documentation

◆ MAX_PAYLOAD_SIZE

const int MAX_PAYLOAD_SIZE = 256
static

Definition at line 57 of file wifi_firmware_updater.cpp.

◆ payload

uint8_t payload[MAX_PAYLOAD_SIZE]
static

Definition at line 107 of file wifi_firmware_updater.cpp.

Referenced by receivePacket().

◆ pkt

UartPacket pkt
static

Definition at line 106 of file wifi_firmware_updater.cpp.

Referenced by receivePacket().

◆ UartPacket

UartPacket

Definition at line 55 of file wifi_firmware_updater.cpp.

Referenced by receivePacket().

◆ wifiUpdater

WifiUpdaterThread wifiUpdater
static

Definition at line 186 of file wifi_firmware_updater.cpp.

Referenced by startWifiUpdater().

Go to the source code of this file.