This commit is contained in:
openshwprojects
2023-05-20 15:25:29 +02:00
17 changed files with 350 additions and 399 deletions

View File

@ -55,7 +55,7 @@ OpenBeken features:
- DDP lighting protocol support ("startDriver DDP" in autoexec.bat/short startup command), works with xLights
- Can be scripted to even [work with shutters](https://www.elektroda.com/rtvforum/topic3972935.html)
- Advanced deep sleep with GPIO/timer wakeup and hybrid power save systems, fully scriptable, can be configured to last longer than Tuya
- Supports automatic GPIO setup with [cloudcutter templates](https://www.elektroda.com/rtvforum/topic3973669.html), can also import/export [OpenBeken templates](https://openbekeniot.github.io/webapp/devicesList.html)
- Supports automatic GPIO setup with [cloudcutter templates](https://www.elektroda.com/rtvforum/topic3973669.html), can also import/export [OpenBeken templates](https://openbekeniot.github.io/webapp/devicesList.html), you can also use [GPIODoctor to find out quickly GPIO roles](https://www.elektroda.com/rtvforum/topic3976371.html)
- and much more
There is also a bit more outdated [WIKI](https://github.com/openshwprojects/OpenBK7231T_App/wiki/Wiki-Home)

View File

@ -380,7 +380,7 @@ void CMD_UARTConsole_Run() {
totalSize = UART_GetDataSize();
while (totalSize) {
a = UART_GetNextByte(0);
a = UART_GetByte(0);
if (a == '\n' || a == '\r' || a == ' ' || a == '\t') {
UART_ConsumeBytes(1);
totalSize = UART_GetDataSize();
@ -394,7 +394,7 @@ void CMD_UARTConsole_Run() {
}
// skip garbage data (should not happen)
for (i = 0; i < totalSize; i++) {
a = UART_GetNextByte(i);
a = UART_GetByte(i);
if (i + 1 < sizeof(tmp)) {
tmp[i] = a;
tmp[i + 1] = 0;

View File

@ -163,7 +163,7 @@ void NewTuyaMCUSimulator_RunQuickTick(int deltaMS) {
break;
}
b = hexbyte(curP);
UART_AppendByteToCircularBuffer(b);
UART_AppendByteToReceiveRingBuffer(b);
curP += 2;
}
if (*curP == 0) {

View File

@ -1,5 +1,7 @@
#include "drv_bl0937.h"
#include <math.h>
#include "../cmnds/cmd_public.h"
#include "../hal/hal_pins.h"
#include "../logging/logging.h"
@ -284,5 +286,5 @@ void BL0937_RunFrame(void) {
addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER,dbg);
}
#endif
BL_ProcessUpdate(final_v, final_c, final_p, 0.0f);
BL_ProcessUpdate(final_v, final_c, final_p, NAN, NAN);
}

View File

@ -1,5 +1,8 @@
#include "drv_bl0942.h"
#include <math.h>
#include <stdint.h>
#include "../logging/logging.h"
#include "../new_pins.h"
#include "drv_bl_shared.h"
@ -25,6 +28,7 @@
#define BL0942_REG_I_RMS 0x03
#define BL0942_REG_V_RMS 0x04
#define BL0942_REG_WATT 0x06
#define BL0942_REG_CF_CNT 0x7
#define BL0942_REG_FREQ 0x08
#define BL0942_REG_USR_WRPROT 0x1D
#define BL0942_USR_WRPROT_DISABLE 0x55
@ -38,37 +42,46 @@
#define DEFAULT_CURRENT_CAL 251210
#define DEFAULT_POWER_CAL 598
static void ScaleAndUpdate(int raw_voltage, int raw_current, int raw_power,
int raw_frequency) {
// those are not values like 230V, but unscaled
ADDLOG_EXTRADEBUG(LOG_FEATURE_ENERGYMETER,
"Unscaled current %d, voltage %d, power %d, freq %d\n",
raw_current, raw_voltage, raw_power, raw_frequency);
ADDLOG_EXTRADEBUG(LOG_FEATURE_ENERGYMETER,
"HEX Current: %08lX; "
"Voltage: %08lX; Power: %08lX;\n",
(unsigned long)raw_current, (unsigned long)raw_voltage,
(unsigned long)raw_power);
#define CF_CNT_INVALID (1 << 31)
// those are final values, like 230V
typedef struct {
uint32_t i_rms;
uint32_t v_rms;
int32_t watt;
uint32_t cf_cnt;
uint32_t freq;
} bl0942_data_t;
static uint32_t PrevCfCnt = CF_CNT_INVALID;
static int32_t Int24ToInt32(int32_t val) {
return (val & (1 << 23) ? val | (0xFF << 24) : val);
}
static void ScaleAndUpdate(bl0942_data_t *data) {
float voltage, current, power;
PwrCal_Scale(raw_voltage, raw_current, raw_power, &voltage, &current,
PwrCal_Scale(data->v_rms, data->i_rms, data->watt, &voltage, &current,
&power);
float frequency = 2 * 500000.0 / raw_frequency;
ADDLOG_DEBUG(LOG_FEATURE_ENERGYMETER,
"Real current %1.3lf, voltage %1.1lf, power %1.1lf, "
"frequency %1.2lf\n",
current, voltage, power, frequency);
BL_ProcessUpdate(voltage, current, power, frequency);
float frequency = 2 * 500000.0f / data->freq;
float energyWh = 0;
if (PrevCfCnt != CF_CNT_INVALID) {
int diff = (data->cf_cnt < PrevCfCnt
? data->cf_cnt + (0xFFFFFF - PrevCfCnt) + 1
: data->cf_cnt - PrevCfCnt);
energyWh =
fabsf(PwrCal_ScalePowerOnly(diff)) * 1638.4f * 256.0f / 3600.0f;
}
PrevCfCnt = data->cf_cnt;
BL_ProcessUpdate(voltage, current, power, frequency, energyWh);
}
static int UART_TryToGetNextPacket(void) {
int cs;
int i;
int c_garbage_consumed = 0;
byte a;
byte checksum;
cs = UART_GetDataSize();
@ -78,8 +91,7 @@ static int UART_TryToGetNextPacket(void) {
}
// skip garbage data (should not happen)
while(cs > 0) {
a = UART_GetNextByte(0);
if(a != BL0942_UART_PACKET_HEAD) {
if (UART_GetByte(0) != BL0942_UART_PACKET_HEAD) {
UART_ConsumeBytes(1);
c_garbage_consumed++;
cs--;
@ -88,66 +100,43 @@ static int UART_TryToGetNextPacket(void) {
}
}
if(c_garbage_consumed > 0){
addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER,"Consumed %i unwanted non-header byte in BL0942 buffer\n", c_garbage_consumed);
ADDLOG_WARN(LOG_FEATURE_ENERGYMETER,
"Consumed %i unwanted non-header byte in BL0942 buffer\n",
c_garbage_consumed);
}
if(cs < BL0942_UART_PACKET_LEN) {
return 0;
}
a = UART_GetNextByte(0);
if(a != 0x55) {
if (UART_GetByte(0) != 0x55)
return 0;
}
checksum = BL0942_UART_CMD_READ(BL0942_UART_ADDR);
for(i = 0; i < BL0942_UART_PACKET_LEN-1; i++) {
checksum += UART_GetNextByte(i);
checksum += UART_GetByte(i);
}
checksum ^= 0xFF;
#if 1
{
char buffer_for_log[128];
char buffer2[32];
buffer_for_log[0] = 0;
for(i = 0; i < BL0942_UART_PACKET_LEN; i++) {
snprintf(buffer2, sizeof(buffer2), "%02X ",UART_GetNextByte(i));
strcat_safe(buffer_for_log,buffer2,sizeof(buffer_for_log));
}
addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER,"BL0942 received: %s\n", buffer_for_log);
}
#endif
if(checksum != UART_GetNextByte(BL0942_UART_PACKET_LEN-1)) {
if (checksum != UART_GetByte(BL0942_UART_PACKET_LEN - 1)) {
ADDLOG_WARN(LOG_FEATURE_ENERGYMETER,
"Skipping packet with bad checksum %02X wanted %02X\n",
UART_GetNextByte(BL0942_UART_PACKET_LEN - 1), checksum);
UART_GetByte(BL0942_UART_PACKET_LEN - 1), checksum);
UART_ConsumeBytes(BL0942_UART_PACKET_LEN);
return 1;
}
int voltage, current, power, frequency;
current = (UART_GetNextByte(3) << 16) | (UART_GetNextByte(2) << 8) |
UART_GetNextByte(1);
voltage = (UART_GetNextByte(6) << 16) | (UART_GetNextByte(5) << 8) |
UART_GetNextByte(4);
power = (UART_GetNextByte(12) << 24) | (UART_GetNextByte(11) << 16) |
(UART_GetNextByte(10) << 8);
power = (power >> 8);
bl0942_data_t data;
data.i_rms =
(UART_GetByte(3) << 16) | (UART_GetByte(2) << 8) | UART_GetByte(1);
data.v_rms =
(UART_GetByte(6) << 16) | (UART_GetByte(5) << 8) | UART_GetByte(4);
data.watt = Int24ToInt32((UART_GetByte(12) << 16) |
(UART_GetByte(11) << 8) | UART_GetByte(10));
data.cf_cnt =
(UART_GetByte(15) << 16) | (UART_GetByte(14) << 8) | UART_GetByte(13);
data.freq = (UART_GetByte(17) << 8) | UART_GetByte(16);
ScaleAndUpdate(&data);
frequency = (UART_GetNextByte(17) << 8) | UART_GetNextByte(16);
ScaleAndUpdate(voltage, current, power, frequency);
#if 0
{
char res[128];
// V=245.107925,I=109.921143,P=0.035618
snprintf(res, sizeof(res),"V=%f,I=%f,P=%f\n",lastReadings[OBK_VOLTAGE],lastReadings[OBK_CURRENT],lastReadings[OBK_POWER]);
addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER,res );
}
#endif
UART_ConsumeBytes(BL0942_UART_PACKET_LEN);
UART_ConsumeBytes(BL0942_UART_PACKET_LEN);
return BL0942_UART_PACKET_LEN;
}
@ -168,7 +157,7 @@ static void UART_WriteReg(uint8_t reg, uint32_t val) {
UART_SendByte(crc ^ 0xFF);
}
static int SPI_ReadReg(uint8_t reg, uint32_t *val, uint8_t signed24) {
static int SPI_ReadReg(uint8_t reg, uint32_t *val) {
uint8_t send[2];
uint8_t recv[4];
send[0] = BL0942_SPI_CMD_READ;
@ -179,15 +168,12 @@ static int SPI_ReadReg(uint8_t reg, uint32_t *val, uint8_t signed24) {
checksum ^= 0xFF;
if (recv[3] != checksum) {
ADDLOG_WARN(LOG_FEATURE_ENERGYMETER,
"Failed to read reg %02X: Bad checksum %02X wanted %02X",
"Failed to read reg %02X: bad checksum %02X wanted %02X",
reg, recv[3], checksum);
return -1;
}
*val = (recv[0] << 16) | (recv[1] << 8) | recv[2];
if (signed24 && (recv[0] & 0x80))
*val |= (0xFF << 24);
return 0;
}
@ -206,7 +192,7 @@ static int SPI_WriteReg(uint8_t reg, uint32_t val) {
SPI_WriteBytes(send, sizeof(send));
uint32_t read;
SPI_ReadReg(reg, &read, 0);
SPI_ReadReg(reg, &read);
if (read == val ||
// REG_USR_WRPROT is read back as 0x1
(reg == BL0942_REG_USR_WRPROT && val == BL0942_USR_WRPROT_DISABLE &&
@ -214,12 +200,15 @@ static int SPI_WriteReg(uint8_t reg, uint32_t val) {
return 0;
}
ADDLOG_WARN(LOG_FEATURE_ENERGYMETER,
"Failed to write reg %02X val %02X: Read %02X", reg, val, read);
return 0;
ADDLOG_ERROR(LOG_FEATURE_ENERGYMETER,
"Failed to write reg %02X val %02X: read %02X", reg, val,
read);
return -1;
}
static void Init(void) {
PrevCfCnt = CF_CNT_INVALID;
BL_Shared_Init();
PwrCal_Init(PWR_CAL_DIVIDE, DEFAULT_VOLTAGE_CAL, DEFAULT_CURRENT_CAL,
@ -232,9 +221,7 @@ void BL0942_UART_Init(void) {
UART_InitUART(BL0942_UART_BAUD_RATE);
UART_InitReceiveRingBuffer(BL0942_UART_RECEIVE_BUFFER_SIZE);
// Enable write access
UART_WriteReg(BL0942_REG_USR_WRPROT, BL0942_USR_WRPROT_DISABLE);
UART_WriteReg(BL0942_REG_MODE,
BL0942_MODE_DEFAULT | BL0942_MODE_RMS_UPDATE_SEL_800_MS);
}
@ -262,23 +249,18 @@ void BL0942_SPI_Init(void) {
cfg.bit_order = SPI_MSB_FIRST;
SPI_Init(&cfg);
// Enable write access
SPI_WriteReg(BL0942_REG_USR_WRPROT, BL0942_USR_WRPROT_DISABLE);
uint32_t mode;
int err = SPI_ReadReg(BL0942_REG_MODE, &mode, 0);
if (!err) {
mode |= BL0942_MODE_RMS_UPDATE_SEL_800_MS;
SPI_WriteReg(BL0942_REG_MODE, mode);
}
SPI_WriteReg(BL0942_REG_MODE,
BL0942_MODE_DEFAULT | BL0942_MODE_RMS_UPDATE_SEL_800_MS);
}
void BL0942_SPI_RunFrame(void) {
int voltage, current, power, frequency;
SPI_ReadReg(BL0942_REG_I_RMS, (uint32_t *)&current, 0);
SPI_ReadReg(BL0942_REG_V_RMS, (uint32_t *)&voltage, 0);
SPI_ReadReg(BL0942_REG_WATT, (uint32_t *)&power, 1);
SPI_ReadReg(BL0942_REG_FREQ, (uint32_t *)&frequency, 0);
ScaleAndUpdate(voltage, current, power, frequency);
bl0942_data_t data;
SPI_ReadReg(BL0942_REG_I_RMS, &data.i_rms);
SPI_ReadReg(BL0942_REG_V_RMS, &data.v_rms);
SPI_ReadReg(BL0942_REG_WATT, (uint32_t *)&data.watt);
data.watt = Int24ToInt32(data.watt);
SPI_ReadReg(BL0942_REG_CF_CNT, &data.cf_cnt);
SPI_ReadReg(BL0942_REG_FREQ, &data.freq);
ScaleAndUpdate(&data);
}

View File

@ -22,7 +22,7 @@ int stat_updatesSent = 0;
// Current values
float lastReadings[OBK_NUM_MEASUREMENTS];
float lastReadingFrequency = 0.0f;
float lastReadingFrequency = NAN;
// precisions:
byte roundingPrecision[4] = {
1, // OBK_VOLTAGE, // must match order in cmd_public.h
@ -102,11 +102,11 @@ void BL09XX_AppendInformationToHTTPIndexPage(http_request_t *request)
poststr(request, "<hr><table style='width:100%'>");
if (lastReadingFrequency > 0) {
if (!isnan(lastReadingFrequency)) {
poststr(request,
"<tr><td><b>Frequency</b></td><td style='text-align: right;'>");
hprintf255(request, "%.2f</td><td>Hz</td>", lastReadingFrequency);
}
hprintf255(request, "%.2f</td><td>Hz</td>", lastReadingFrequency);
}
poststr(request,
"<tr><td><b>Voltage</b></td><td style='text-align: right;'>");
@ -143,6 +143,7 @@ void BL09XX_AppendInformationToHTTPIndexPage(http_request_t *request)
"style='text-align: right;'>");
hprintf255(request, "%.1f</td><td>Wh</td>", dailyStats[1]);
}
poststr(request,
"<tr><td><b>Energy Total</b></td><td style='text-align: right;'>");
// convert from Wh to kWh (thus / 1000.0f)
@ -414,6 +415,7 @@ commandResult_t BL09XX_VCPPublishThreshold(const void *context, const char *cmd,
return CMD_RES_OK;
}
commandResult_t BL09XX_SetupConsumptionThreshold(const void *context, const char *cmd, const char *args, int cmdFlags)
{
float threshold;
@ -436,6 +438,7 @@ commandResult_t BL09XX_SetupConsumptionThreshold(const void *context, const char
return CMD_RES_OK;
}
bool Channel_AreAllRelaysOpen() {
int i, role, ch;
@ -463,17 +466,17 @@ bool Channel_AreAllRelaysOpen() {
}
return true;
}
float BL_ChangeEnergyUnitIfNeeded(float Wh) {
if (CFG_HasFlag(OBK_FLAG_MQTT_ENERGY_IN_KWH)) {
return Wh * 0.001f;
}
return Wh;
}
void BL_ProcessUpdate(float voltage, float current, float power,
float frequency)
{
float frequency, float energyWh) {
int i;
float energy;
int xPassedTicks;
cJSON* root;
cJSON* stats;
@ -486,7 +489,7 @@ void BL_ProcessUpdate(float voltage, float current, float power,
// I had reports that BL0942 sometimes gives
// a large, negative peak of current/power
if (CFG_HasFlag(OBK_FLAG_POWER_ALLOW_NEGATIVE)==false)
if (!CFG_HasFlag(OBK_FLAG_POWER_ALLOW_NEGATIVE))
{
if (power < 0.0f)
power = 0.0f;
@ -503,40 +506,37 @@ void BL_ProcessUpdate(float voltage, float current, float power,
}
}
// those are final values, like 230V
lastReadings[OBK_POWER] = power;
lastReadings[OBK_VOLTAGE] = voltage;
lastReadings[OBK_CURRENT] = current;
lastReadingFrequency = frequency;
g_apparentPower =
lastReadings[OBK_VOLTAGE] * lastReadings[OBK_CURRENT];
g_apparentPower = lastReadings[OBK_VOLTAGE] * lastReadings[OBK_CURRENT];
g_reactivePower = (g_apparentPower <= fabsf(lastReadings[OBK_POWER])
? 0
: sqrtf(powf(g_apparentPower, 2) -
powf(lastReadings[OBK_POWER], 2)));
g_powerFactor =
(g_apparentPower == 0 ? 1 : lastReadings[OBK_POWER] / g_apparentPower);
g_reactivePower = (g_apparentPower <= fabsf(lastReadings[OBK_POWER])
? 0
: sqrtf(powf(g_apparentPower, 2) -
powf(lastReadings[OBK_POWER], 2)));
float energy = 0;
if (isnan(energyWh)) {
xPassedTicks = (int)(xTaskGetTickCount() - energyCounterStamp);
// FIXME: Wrong calculation if tick count overflows
if (xPassedTicks <= 0)
xPassedTicks = 1;
energy = xPassedTicks * power / (3600000.0f / portTICK_PERIOD_MS);
} else
energy = energyWh;
g_powerFactor =
(g_apparentPower == 0 ? 1 : lastReadings[OBK_POWER] / g_apparentPower);
xPassedTicks = (int)(xTaskGetTickCount() - energyCounterStamp);
if (xPassedTicks <= 0)
xPassedTicks = 1;
energy = (float)xPassedTicks;
energy *= power;
energy /= (3600000.0f / (float)portTICK_PERIOD_MS);
if (energy < 0)
{
energy = 0.0;
}
energyCounter += energy;
energyCounterStamp = xTaskGetTickCount();
HAL_FlashVars_SaveTotalConsumption(energyCounter);
if(NTP_IsTimeSynced() == true)
{
if (NTP_IsTimeSynced()) {
ntpTime = (time_t)NTP_GetCurrentTime();
ltm = localtime(&ntpTime);
if (ConsumptionResetTime == 0)
@ -863,6 +863,7 @@ void BL_Shared_Init(void)
//cmddetail:"examples":""}
CMD_RegisterCommand("VCPPublishIntervals", BL09XX_VCPPublishIntervals, NULL);
}
// OBK_POWER etc
float DRV_GetReading(int type)
{

View File

@ -4,10 +4,9 @@
void BL_Shared_Init(void);
void BL_ProcessUpdate(float voltage, float current, float power,
float frequency);
float frequency, float energyWh);
void BL09XX_AppendInformationToHTTPIndexPage(http_request_t *request);
extern float g_apparentPower;
extern float g_powerFactor;
extern float g_reactivePower;

View File

@ -1,6 +1,8 @@
// NOTE: this is the same as HLW8032
#include "drv_cse7766.h"
#include <math.h>
#include "../logging/logging.h"
#include "../new_pins.h"
#include "drv_bl_shared.h"
@ -28,11 +30,11 @@ int CSE7766_TryToGetNextCSE7766Packet() {
if(cs < CSE7766_PACKET_LEN) {
return 0;
}
header = UART_GetNextByte(0);
// skip garbage data (should not happen)
header = UART_GetByte(0);
// skip garbage data (should not happen)
while(cs > 0) {
a = UART_GetNextByte(1);
if(a != 0x5A) {
a = UART_GetByte(1);
if(a != 0x5A) {
UART_ConsumeBytes(1);
c_garbage_consumed++;
cs--;
@ -46,15 +48,15 @@ int CSE7766_TryToGetNextCSE7766Packet() {
if(cs < CSE7766_PACKET_LEN) {
return 0;
}
a = UART_GetNextByte(1);
if(a != 0x5A) {
a = UART_GetByte(1);
if(a != 0x5A) {
return 0;
}
checksum = 0;
for(i = 2; i < CSE7766_PACKET_LEN-1; i++) {
checksum += UART_GetNextByte(i);
}
checksum += UART_GetByte(i);
}
#if 1
{
@ -62,15 +64,17 @@ int CSE7766_TryToGetNextCSE7766Packet() {
char buffer2[32];
buffer_for_log[0] = 0;
for(i = 0; i < CSE7766_PACKET_LEN; i++) {
snprintf(buffer2, sizeof(buffer2), "%02X ",UART_GetNextByte(i));
strcat_safe(buffer_for_log,buffer2,sizeof(buffer_for_log));
snprintf(buffer2, sizeof(buffer2), "%02X ", UART_GetByte(i));
strcat_safe(buffer_for_log,buffer2,sizeof(buffer_for_log));
}
addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER,"CSE7766 received: %s\n", buffer_for_log);
}
#endif
if(checksum != UART_GetNextByte(CSE7766_PACKET_LEN-1)) {
addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER,"Skipping packet with bad checksum %02X wanted %02X\n",checksum,UART_GetNextByte(CSE7766_PACKET_LEN-1));
UART_ConsumeBytes(CSE7766_PACKET_LEN);
if(checksum != UART_GetByte(CSE7766_PACKET_LEN-1)) {
ADDLOG_INFO(LOG_FEATURE_ENERGYMETER,
"Skipping packet with bad checksum %02X wanted %02X\n",
checksum, UART_GetByte(CSE7766_PACKET_LEN - 1));
UART_ConsumeBytes(CSE7766_PACKET_LEN);
return 1;
}
//addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER,"CSE checksum ok");
@ -128,25 +132,23 @@ int CSE7766_TryToGetNextCSE7766Packet() {
backlog startDriver CSE7766; uartFakeHex 555A02FCD800062F00413200D7F2537B18023E9F7171FEEC
*/
adjustement = UART_GetNextByte(20);
int vol_par = UART_GetNextByte(2) << 16 | UART_GetNextByte(3) << 8 | UART_GetNextByte(4);
int cur_par = UART_GetNextByte(8) << 16 | UART_GetNextByte(9) << 8 | UART_GetNextByte(10);
int pow_par = UART_GetNextByte(14) << 16 | UART_GetNextByte(15) << 8 | UART_GetNextByte(16);
float raw_unscaled_voltage = UART_GetNextByte(5) << 16 |
UART_GetNextByte(6) << 8 |
UART_GetNextByte(7);
float raw_unscaled_current = UART_GetNextByte(11) << 16 |
UART_GetNextByte(12) << 8 |
UART_GetNextByte(13);
float raw_unscaled_power = UART_GetNextByte(17) << 16 |
UART_GetNextByte(18) << 8 |
UART_GetNextByte(19);
cf_pulses = UART_GetNextByte(21) << 8 | UART_GetNextByte(22);
adjustement = UART_GetByte(20);
int vol_par =
UART_GetByte(2) << 16 | UART_GetByte(3) << 8 | UART_GetByte(4);
int cur_par =
UART_GetByte(8) << 16 | UART_GetByte(9) << 8 | UART_GetByte(10);
int pow_par =
UART_GetByte(14) << 16 | UART_GetByte(15) << 8 | UART_GetByte(16);
float raw_unscaled_voltage =
UART_GetByte(5) << 16 | UART_GetByte(6) << 8 | UART_GetByte(7);
float raw_unscaled_current =
UART_GetByte(11) << 16 | UART_GetByte(12) << 8 | UART_GetByte(13);
float raw_unscaled_power =
UART_GetByte(17) << 16 | UART_GetByte(18) << 8 | UART_GetByte(19);
cf_pulses = UART_GetByte(21) << 8 | UART_GetByte(22);
// i am not sure about these flags
// i am not sure about these flags
if (adjustement & 0x40) { // Voltage valid
} else {
@ -181,7 +183,7 @@ int CSE7766_TryToGetNextCSE7766Packet() {
float voltage, current, power;
PwrCal_Scale(raw_unscaled_voltage, raw_unscaled_current,
raw_unscaled_power, &voltage, &current, &power);
BL_ProcessUpdate(voltage, current, power, 0.0f);
BL_ProcessUpdate(voltage, current, power, NAN, NAN);
}
#if 0

View File

@ -100,3 +100,7 @@ void PwrCal_Scale(int raw_voltage, int raw_current, int raw_power,
*real_current = Scale(raw_current, current_cal);
*real_power = Scale(raw_power, power_cal);
}
float PwrCal_ScalePowerOnly(int raw_power) {
return Scale(raw_power, power_cal);
}

View File

@ -10,3 +10,4 @@ void PwrCal_Init(pwr_cal_type_t type, float default_voltage_cal,
float default_current_cal, float default_power_cal);
void PwrCal_Scale(int raw_voltage, int raw_current, int raw_power,
float *real_voltage, float *real_current, float *real_power);
float PwrCal_ScalePowerOnly(int raw_power);

View File

@ -1,5 +1,7 @@
#include "drv_test_drivers.h"
#include <math.h>
#include "../cmnds/cmd_public.h"
#include "drv_bl_shared.h"
@ -46,11 +48,11 @@ void Test_Power_RunFrame(void) {
final_v += (rand() % 100) * 0.1f;
final_p += (rand() % 100) * 0.1f;
}
BL_ProcessUpdate(final_v, final_c, final_p, 0.0f);
BL_ProcessUpdate(final_v, final_c, final_p, NAN, NAN);
}
//Test LED driver
void Test_LED_Driver_Init(void) {}
void Test_LED_Driver_RunFrame(void) {}
void Test_LED_Driver_OnChannelChanged(int ch, int value) {
}
}

View File

@ -265,8 +265,8 @@ int UART_TryToGetNextTuyaPacket(byte* out, int maxSize) {
}
// skip garbage data (should not happen)
while (cs > 0) {
a = UART_GetNextByte(0);
b = UART_GetNextByte(1);
a = UART_GetByte(0);
b = UART_GetByte(1);
if (a != 0x55 || b != 0xAA) {
UART_ConsumeBytes(1);
if (c_garbage_consumed + 2 < sizeof(printfSkipDebug)) {
@ -287,15 +287,15 @@ int UART_TryToGetNextTuyaPacket(byte* out, int maxSize) {
if (cs < MIN_TUYAMCU_PACKET_SIZE) {
return 0;
}
a = UART_GetNextByte(0);
b = UART_GetNextByte(1);
a = UART_GetByte(0);
b = UART_GetByte(1);
if (a != 0x55 || b != 0xAA) {
return 0;
}
version = UART_GetNextByte(2);
command = UART_GetNextByte(3);
lena = UART_GetNextByte(4); // hi
lenb = UART_GetNextByte(5); // lo
version = UART_GetByte(2);
command = UART_GetByte(3);
lena = UART_GetByte(4); // hi
lenb = UART_GetByte(5); // lo
len = lenb | lena >> 8;
// now check if we have received whole packet
len += 2 + 1 + 1 + 2 + 1; // header 2 bytes, version, command, lenght, chekcusm
@ -304,7 +304,7 @@ int UART_TryToGetNextTuyaPacket(byte* out, int maxSize) {
// can packet fit into the buffer?
if (len <= maxSize) {
for (i = 0; i < len; i++) {
out[i] = UART_GetNextByte(i);
out[i] = UART_GetByte(i);
}
ret = len;
}

View File

@ -6,7 +6,6 @@
#include "../cmnds/cmd_local.h"
#include "../logging/logging.h"
#if PLATFORM_BK7231T | PLATFORM_BK7231N
#include "../../beken378/func/user_driver/BkDriverUart.h"
#endif
@ -20,7 +19,6 @@
#include <aos/kernel.h>
#include <aos/yloop.h>
#include <FreeRTOS.h>
#include <task.h>
#include <timers.h>
@ -87,7 +85,7 @@ extern void bk_send_byte(UINT8 uport, UINT8 data);
int g_chosenUART = BK_UART_1;
#elif WINDOWS
#elif PLATFORM_BL602
#elif PLATFORM_BL602
//int g_fd;
uint8_t g_id = 1;
int fd_console = -1;
@ -105,57 +103,43 @@ int g_uart_manualInitCounter = -1;
void UART_InitReceiveRingBuffer(int size){
if(g_recvBuf!=0)
free(g_recvBuf);
free(g_recvBuf);
g_recvBuf = (byte*)malloc(size);
memset(g_recvBuf,0,size);
g_recvBufSize = size;
g_recvBufIn = 0;
g_recvBufOut = 0;
g_recvBufSize = size;
g_recvBufIn = 0;
g_recvBufOut = 0;
}
int UART_GetDataSize()
{
int remain_buf_size = 0;
if(g_recvBufIn >= g_recvBufOut) {
remain_buf_size = g_recvBufIn - g_recvBufOut;
}else {
remain_buf_size = g_recvBufIn + g_recvBufSize - g_recvBufOut;
}
return remain_buf_size;
int UART_GetDataSize() {
return (g_recvBufIn >= g_recvBufOut
? g_recvBufIn - g_recvBufOut
: g_recvBufIn + (g_recvBufSize - g_recvBufOut) + 1);
}
byte UART_GetNextByte(int index) {
int realIndex = g_recvBufOut + index;
if(realIndex > g_recvBufSize)
realIndex -= g_recvBufSize;
return g_recvBuf[realIndex];
byte UART_GetByte(int idx) {
return g_recvBuf[(g_recvBufOut + idx) % g_recvBufSize];
}
void UART_ConsumeBytes(int idx) {
g_recvBufOut += idx;
if(g_recvBufOut > g_recvBufSize)
g_recvBufOut -= g_recvBufSize;
g_recvBufOut += idx;
g_recvBufOut %= g_recvBufSize;
}
void UART_AppendByteToCircularBuffer(int rc) {
if(UART_GetDataSize() < (g_recvBufSize-1))
{
void UART_AppendByteToReceiveRingBuffer(int rc) {
if (UART_GetDataSize() < (g_recvBufSize - 1)) {
g_recvBuf[g_recvBufIn++] = rc;
if(g_recvBufIn >= g_recvBufSize){
g_recvBufIn = 0;
}
}
g_recvBufIn %= g_recvBufSize;
}
}
#if PLATFORM_BK7231T | PLATFORM_BK7231N
void test_ty_read_uart_data_to_buffer(int port, void* param)
{
int rc = 0;
while((rc = uart_read_byte(port)) != -1)
{
UART_AppendByteToCircularBuffer(rc);
}
UART_AppendByteToReceiveRingBuffer(rc);
}
#endif
@ -168,101 +152,97 @@ void test_ty_read_uart_data_to_buffer(int port, void* param)
// byte buffer[16];
// //length = aos_read(g_fd, buffer, 1);
// //if (length > 0) {
// // UART_AppendByteToCircularBuffer(buffer[0]);
// // UART_AppendByteToReceiveRingBuffer(buffer[0]);
// //}
// int res = bl_uart_data_recv(g_id);
// if (res >= 0) {
// addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "UART received: %i\n", res);
// UART_AppendByteToCircularBuffer(res);
// UART_AppendByteToReceiveRingBuffer(res);
// }
//}
static void console_cb_read(int fd, void *param)
{
char buffer[64]; /* adapt to usb cdc since usb fifo is 64 bytes */
int ret;
int i;
int ret;
int i;
ret = aos_read(fd, buffer, sizeof(buffer));
if (ret > 0) {
if (ret < sizeof(buffer)) {
fd_console = fd;
buffer[ret] = 0;
ret = aos_read(fd, buffer, sizeof(buffer));
if (ret > 0) {
if (ret < sizeof(buffer)) {
fd_console = fd;
buffer[ret] = 0;
addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "BL602 received: %s\n", buffer);
for (i = 0; i < ret; i++) {
UART_AppendByteToCircularBuffer(buffer[i]);
}
for (i = 0; i < ret; i++) {
UART_AppendByteToReceiveRingBuffer(buffer[i]);
}
}
else {
printf("-------------BUG from aos_read for ret\r\n");
}
}
printf("-------------BUG from aos_read for ret\r\n");
}
}
}
#endif
void UART_SendByte(byte b) {
#if PLATFORM_BK7231T | PLATFORM_BK7231N
// BK_UART_1 is defined to 0
bk_send_byte(g_chosenUART, b);
// BK_UART_1 is defined to 0
bk_send_byte(g_chosenUART, b);
#elif WINDOWS
void SIM_AppendUARTByte(byte b);
// STUB - for testing
SIM_AppendUARTByte(b);
void SIM_AppendUARTByte(byte b);
// STUB - for testing
SIM_AppendUARTByte(b);
#if 1
printf("%02X", b);
printf("%02X", b);
#endif
//addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU,"%02X", b);
#elif PLATFORM_BL602
aos_write(fd_console, &b, 1);
aos_write(fd_console, &b, 1);
//bl_uart_data_send(g_id, b);
#else
#endif
}
commandResult_t CMD_UART_Send_Hex(const void *context, const char *cmd, const char *args, int cmdFlags) {
byte b;
float val;
const char *stop;
byte b;
float val;
const char *stop;
//const char *args = CMD_GetArg(1);
if (!(*args)) {
if (!(*args)) {
addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU, "CMD_UART_Send_Hex: requires 1 argument (hex string, like FFAABB00CCDD\n");
return CMD_RES_NOT_ENOUGH_ARGUMENTS;
}
while (*args) {
if (*args == ' ') {
args++;
continue;
}
if (*args == '$') {
stop = args + 1;
while (*stop && *stop != '$') {
stop++;
}
CMD_ExpandConstant(args, stop, &val);
b = (int)val;
UART_SendByte(b);
return CMD_RES_NOT_ENOUGH_ARGUMENTS;
}
while (*args) {
if (*args == ' ') {
args++;
continue;
}
if (*args == '$') {
stop = args + 1;
while (*stop && *stop != '$') {
stop++;
}
CMD_ExpandConstant(args, stop, &val);
b = (int)val;
UART_SendByte(b);
if (*stop == 0)
break;
args = stop + 1;
continue;
}
b = hexbyte(args);
if (*stop == 0)
break;
args = stop + 1;
continue;
}
b = hexbyte(args);
UART_SendByte(b);
UART_SendByte(b);
args += 2;
}
return CMD_RES_OK;
args += 2;
}
return CMD_RES_OK;
}
// This is a tool for debugging.
// It simulates OpenBeken receiving packet from UART.
// For example, you can do:
// For example, you can do:
/*
1. You can simulate TuyaMCU battery powered device packet:
@ -271,25 +251,25 @@ uartFakeHex 55 AA 00 05 00 05 01 04 00 01 01 10 55
HEADER VER=00 Unk LEN fnId=1 Enum V=1 CHK
backlog startDriver TuyaMCU; uartFakeHex 55 AA 00 05 00 05 01 04 00 01 01 10 55
*/
commandResult_t CMD_UART_FakeHex(const void *context, const char *cmd, const char *args, int cmdFlags) {
//const char *args = CMD_GetArg(1);
//byte rawData[128];
//int curCnt;
//curCnt = 0;
if (!(*args)) {
if (!(*args)) {
addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU, "CMD_UART_FakeHex: requires 1 argument (hex string, like FFAABB00CCDD\n");
return CMD_RES_NOT_ENOUGH_ARGUMENTS;
}
while (*args) {
byte b;
if (*args == ' ') {
args++;
continue;
}
b = hexbyte(args);
return CMD_RES_NOT_ENOUGH_ARGUMENTS;
}
while (*args) {
byte b;
if (*args == ' ') {
args++;
continue;
}
b = hexbyte(args);
//rawData[curCnt] = b;
//curCnt++;
@ -298,54 +278,57 @@ commandResult_t CMD_UART_FakeHex(const void *context, const char *cmd, const cha
// return -1;
//}
UART_AppendByteToCircularBuffer(b);
UART_AppendByteToReceiveRingBuffer(b);
args += 2;
}
return 1;
args += 2;
}
return 1;
}
// uartSendASCII test123
commandResult_t CMD_UART_Send_ASCII(const void *context, const char *cmd, const char *args, int cmdFlags) {
//const char *args = CMD_GetArg(1);
if (!(*args)) {
if (!(*args)) {
addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU, "CMD_UART_Send_ASCII: requires 1 argument (hex string, like hellp world\n");
return CMD_RES_NOT_ENOUGH_ARGUMENTS;
}
while (*args) {
return CMD_RES_NOT_ENOUGH_ARGUMENTS;
}
while (*args) {
UART_SendByte(*args);
UART_SendByte(*args);
args++;
}
return CMD_RES_OK;
args++;
}
return CMD_RES_OK;
}
void UART_ResetForSimulator() {
g_uart_init_counter = 0;
}
int UART_InitUART(int baud) {
g_uart_init_counter++;
#if PLATFORM_BK7231T | PLATFORM_BK7231N
bk_uart_config_t config;
config.baud_rate = baud;
config.data_width = 0x03;
int UART_InitUART(int baud) {
g_uart_init_counter++;
#if PLATFORM_BK7231T | PLATFORM_BK7231N
bk_uart_config_t config;
config.baud_rate = baud;
config.data_width = 0x03;
config.parity = 0; //0:no parity,1:odd,2:even
config.stop_bits = 0; //0:1bit,1:2bit
config.flow_control = 0; //FLOW_CTRL_DISABLED
config.flags = 0;
config.flags = 0;
// BK_UART_1 is defined to 0
if (CFG_HasFlag(OBK_FLAG_USE_SECONDARY_UART)) {
g_chosenUART = BK_UART_2;
// BK_UART_1 is defined to 0
if (CFG_HasFlag(OBK_FLAG_USE_SECONDARY_UART)) {
g_chosenUART = BK_UART_2;
}
else {
g_chosenUART = BK_UART_1;
}
bk_uart_initialize(g_chosenUART, &config, NULL);
g_chosenUART = BK_UART_1;
}
bk_uart_initialize(g_chosenUART, &config, NULL);
bk_uart_set_rx_callback(g_chosenUART, test_ty_read_uart_data_to_buffer, NULL);
#elif PLATFORM_BL602
if (fd_console < 0) {
if (fd_console < 0) {
//uint8_t tx_pin = 16;
//uint8_t rx_pin = 7;
//bl_uart_init(g_id, tx_pin, rx_pin, 0, 0, baud);
@ -355,100 +338,95 @@ int UART_InitUART(int baud) {
//bl_irq_enable(UART1_IRQn);
//vfs_uart_init_simple_mode(0, 7, 16, baud, "/dev/ttyS0");
if (CFG_HasFlag(OBK_FLAG_USE_SECONDARY_UART)) {
fd_console = aos_open("/dev/ttyS1", 0);
if (CFG_HasFlag(OBK_FLAG_USE_SECONDARY_UART)) {
fd_console = aos_open("/dev/ttyS1", 0);
}
else {
fd_console = aos_open("/dev/ttyS0", 0);
}
if (fd_console >= 0) {
aos_ioctl(fd_console, IOCTL_UART_IOC_BAUD_MODE, baud);
fd_console = aos_open("/dev/ttyS0", 0);
}
if (fd_console >= 0) {
aos_ioctl(fd_console, IOCTL_UART_IOC_BAUD_MODE, baud);
addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "Init CLI with event Driven\r\n");
aos_cli_init(0);
aos_cli_init(0);
aos_poll_read_fd(fd_console, console_cb_read, (void*)0x12345678);
}
else {
addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "failed CLI with event Driven\r\n");
}
}
#else
}
}
#endif
return g_uart_init_counter;
return g_uart_init_counter;
}
void UART_DebugTool_Run() {
int totalSize;
byte b;
char tmp[128];
char *p = tmp;
int i;
int totalSize;
byte b;
char tmp[128];
char *p = tmp;
int i;
for (i = 0; i < sizeof(tmp) - 4; i++) {
for (i = 0; i < sizeof(tmp) - 4; i++) {
if (UART_GetDataSize()==0) {
break;
}
b = UART_GetNextByte(0);
if (i) {
*p = ' ';
p++;
}
sprintf(p, "%02X", b);
p += 2;
UART_ConsumeBytes(1);
}
*p = 0;
addLogAdv(LOG_INFO, LOG_FEATURE_CMD, "UART received: %s\n", tmp);
break;
}
b = UART_GetByte(0);
if (i) {
*p = ' ';
p++;
}
sprintf(p, "%02X", b);
p += 2;
UART_ConsumeBytes(1);
}
*p = 0;
addLogAdv(LOG_INFO, LOG_FEATURE_CMD, "UART received: %s\n", tmp);
}
void UART_RunEverySecond() {
if (g_uart_manualInitCounter == g_uart_init_counter) {
UART_DebugTool_Run();
}
if (g_uart_manualInitCounter == g_uart_init_counter) {
UART_DebugTool_Run();
}
}
commandResult_t CMD_UART_Init(const void *context, const char *cmd, const char *args, int cmdFlags) {
int baud;
int baud;
Tokenizer_TokenizeString(args, 0);
// following check must be done after 'Tokenizer_TokenizeString',
// so we know arguments count in Tokenizer. 'cmd' argument is
// only for warning display
if (Tokenizer_CheckArgsCountAndPrintWarning(cmd, 1)) {
return CMD_RES_NOT_ENOUGH_ARGUMENTS;
}
Tokenizer_TokenizeString(args, 0);
// following check must be done after 'Tokenizer_TokenizeString',
// so we know arguments count in Tokenizer. 'cmd' argument is
// only for warning display
if (Tokenizer_CheckArgsCountAndPrintWarning(cmd, 1)) {
return CMD_RES_NOT_ENOUGH_ARGUMENTS;
}
baud = Tokenizer_GetArgInteger(0);
baud = Tokenizer_GetArgInteger(0);
UART_InitUART(baud);
g_uart_manualInitCounter = g_uart_init_counter;
UART_InitReceiveRingBuffer(512);
UART_InitUART(baud);
g_uart_manualInitCounter = g_uart_init_counter;
UART_InitReceiveRingBuffer(512);
return CMD_RES_OK;
return CMD_RES_OK;
}
void UART_AddCommands() {
//cmddetail:{"name":"uartSendHex","args":"[HexString]",
//cmddetail:"descr":"Sends raw data by UART, can be used to send TuyaMCU data, but you must write whole packet with checksum yourself",
//cmddetail:"fn":"CMD_UART_Send_Hex","file":"driver/drv_tuyaMCU.c","requires":"",
//cmddetail:"examples":""}
CMD_RegisterCommand("uartSendHex", CMD_UART_Send_Hex, NULL);
CMD_RegisterCommand("uartSendHex", CMD_UART_Send_Hex, NULL);
//cmddetail:{"name":"uartSendASCII","args":"[AsciiString]",
//cmddetail:"descr":"Sends given string by UART.",
//cmddetail:"fn":"CMD_UART_Send_ASCII","file":"driver/drv_uart.c","requires":"",
//cmddetail:"examples":""}
CMD_RegisterCommand("uartSendASCII", CMD_UART_Send_ASCII, NULL);
CMD_RegisterCommand("uartSendASCII", CMD_UART_Send_ASCII, NULL);
//cmddetail:{"name":"uartFakeHex","args":"[HexString]",
//cmddetail:"descr":"Spoofs a fake hex packet so it looks like TuyaMCU send that to us. Used for testing.",
//cmddetail:"fn":"CMD_UART_FakeHex","file":"driver/drv_uart.c","requires":"",
//cmddetail:"examples":""}
CMD_RegisterCommand("uartFakeHex", CMD_UART_FakeHex, NULL);
CMD_RegisterCommand("uartFakeHex", CMD_UART_FakeHex, NULL);
//cmddetail:{"name":"uartInit","args":"[BaudRate]",
//cmddetail:"descr":"Manually starts UART1 port. Keep in mind that you don't need to do it for TuyaMCU and BL0942, those drivers do it automatically.",
//cmddetail:"fn":"CMD_UART_Init","file":"driver/drv_uart.c","requires":"",
//cmddetail:"examples":""}
CMD_RegisterCommand("uartInit", CMD_UART_Init, NULL);
CMD_RegisterCommand("uartInit", CMD_UART_Init, NULL);
}

View File

@ -1,11 +1,10 @@
#pragma once
void UART_InitReceiveRingBuffer(int size);
int UART_GetDataSize();
byte UART_GetNextByte(int index);
byte UART_GetByte(int idx);
void UART_ConsumeBytes(int idx);
void UART_AppendByteToCircularBuffer(int rc);
void UART_AppendByteToReceiveRingBuffer(int rc);
void UART_SendByte(byte b);
void UART_InitUART(int baud);
void UART_AddCommands();
@ -13,7 +12,3 @@ void UART_RunEverySecond();
// used to detect uart reinit/takeover by driver
extern int g_uart_init_counter;

View File

@ -144,7 +144,7 @@ void SIM_SimulateUserClickOnPin(int pin);
// simulated UART
void SIM_UART_InitReceiveRingBuffer(int size);
int SIM_UART_GetDataSize();
byte SIM_UART_GetNextByte(int index);
byte SIM_UART_GetByte(int index);
void SIM_UART_ConsumeBytes(int idx);
void SIM_AppendUARTByte(byte rc);
bool SIM_UART_ExpectAndConsumeHByte(byte b);

View File

@ -48,7 +48,7 @@ extern int gridSize;
extern "C" {
void CMD_ExpandConstantsWithinString(const char *in, char *out, int outLen);
int UART_GetDataSize();
void UART_AppendByteToCircularBuffer(int rc);
void UART_AppendByteToReceiveRingBuffer(int rc);
int CMD_ExecuteCommand(const char* s, int cmdFlags);
}

View File

@ -1,7 +1,5 @@
#include "../new_common.h"
static byte *g_recvBuf = 0;
static int g_recvBufSize = 0;
static int g_recvBufIn = 0;
@ -16,60 +14,47 @@ void SIM_UART_InitReceiveRingBuffer(int size) {
g_recvBufIn = 0;
g_recvBufOut = 0;
}
void SIM_ClearUART() {
g_recvBufIn = 0;
g_recvBufOut = 0;
}
int SIM_UART_GetDataSize()
{
int remain_buf_size = 0;
if (g_recvBufIn >= g_recvBufOut) {
remain_buf_size = g_recvBufIn - g_recvBufOut;
}
else {
remain_buf_size = g_recvBufIn + g_recvBufSize - g_recvBufOut;
}
return remain_buf_size;
return (g_recvBufIn >= g_recvBufOut
? g_recvBufIn - g_recvBufOut
: g_recvBufIn + (g_recvBufSize - g_recvBufOut) + 1);
}
byte SIM_UART_GetNextByte(int index) {
int realIndex = g_recvBufOut + index;
if (realIndex > g_recvBufSize)
realIndex -= g_recvBufSize;
return g_recvBuf[realIndex];
byte SIM_UART_GetByte(int idx) {
return g_recvBuf[(g_recvBufOut + idx) % g_recvBufSize];
}
void SIM_UART_ConsumeBytes(int idx) {
g_recvBufOut += idx;
if (g_recvBufOut > g_recvBufSize)
g_recvBufOut -= g_recvBufSize;
g_recvBufOut += idx;
g_recvBufOut %= g_recvBufSize;
}
void SIM_AppendUARTByte(byte rc) {
int curDataSize = SIM_UART_GetDataSize();
if (curDataSize < (g_recvBufSize - 1))
{
g_recvBuf[g_recvBufIn++] = rc;
if (g_recvBufIn >= g_recvBufSize) {
g_recvBufIn = 0;
}
}
if (SIM_UART_GetDataSize() < (g_recvBufSize - 1)) {
g_recvBuf[g_recvBufIn++] = rc;
g_recvBufIn %= g_recvBufSize;
}
}
bool SIM_UART_ExpectAndConsumeHByte(byte b) {
byte nextB;
if (SIM_UART_GetDataSize() == 0)
return false;
nextB = SIM_UART_GetNextByte(0);
nextB = SIM_UART_GetByte(0);
if (nextB == b) {
SIM_UART_ConsumeBytes(1);
return true;
}
return false;
}
bool SIM_UART_ExpectAndConsumeHexStr(const char *hexString) {
const char *p;
byte b;
@ -91,4 +76,4 @@ bool SIM_UART_ExpectAndConsumeHexStr(const char *hexString) {
correctBytes++;
}
return true;
}
}