start refactoring transmitting
This commit is contained in:
parent
3e31693cf8
commit
d86f767dc3
@ -193,9 +193,9 @@ static void parseAndPrintFrame() {
|
||||
for (uint8_t j = 0; j < MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS; j++) {
|
||||
if (mbusCommHandle.device->consideredField[j] == i) {
|
||||
parsedVIB_t parsedVIB = parseVIB(record->drh.vib);
|
||||
coloredMsg(LOG_YELLOW, false, "mbc papf [%d] parsed VIB N: %s, U: %s, E: %d",
|
||||
mbusCommHandle.requestId,
|
||||
parsedVIB.name, parsedVIB.unit, parsedVIB.exponent);
|
||||
// coloredMsg(LOG_YELLOW, false, "mbc papf [%d] parsed VIB N: %s, U: %s, E: %d",
|
||||
// mbusCommHandle.requestId,
|
||||
// parsedVIB.name, parsedVIB.unit, parsedVIB.exponent);
|
||||
if (parsedVIB.found) {
|
||||
uint32_t value = strtol(mbus_data_record_value(record), NULL, 10);
|
||||
float weightedValue = ((float) value) * powf(10.0, ((float) parsedVIB.exponent));
|
||||
@ -306,7 +306,7 @@ void mbusCommExec() {
|
||||
uint8_t receivedOctet = 0;
|
||||
|
||||
if ((mbusCommHandle.startTime != 0) && ((mbusCommHandle.startTime + 2500) < HAL_GetTick())) {
|
||||
coloredMsg(LOG_RED, false, "TIMEOUT!! %d %ld %ld", mbusCommHandle.state, mbusCommHandle.startTime, HAL_GetTick());
|
||||
coloredMsg(LOG_RED, false, "TIMEOUT %d %ld %ld", mbusCommHandle.state, mbusCommHandle.startTime, HAL_GetTick());
|
||||
mbusCommHandle.startTime = 0;
|
||||
mbusCommHandle.state = MBCS_TIMEOUT;
|
||||
} else if (mbusCommHandle.waitForOctet) {
|
||||
@ -324,7 +324,7 @@ void mbusCommExec() {
|
||||
break;
|
||||
|
||||
case MBCS_SEND:
|
||||
coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SEND", mbusCommHandle.requestId);
|
||||
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SEND", mbusCommHandle.requestId);
|
||||
mbusCommHandle.sendBuffer.buffer[0] = 0x10;
|
||||
mbusCommHandle.sendBuffer.buffer[1] = mbusCommHandle.cmd;
|
||||
mbusCommHandle.sendBuffer.buffer[2] = mbusCommHandle.addr;
|
||||
@ -336,39 +336,32 @@ void mbusCommExec() {
|
||||
// no break !!
|
||||
|
||||
case MBCS_SEND_CONTINUED:
|
||||
coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SEND_CONTINUED", mbusCommHandle.requestId);
|
||||
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SEND_CONTINUED", mbusCommHandle.requestId);
|
||||
show(LED_RED, OFF);
|
||||
if (! loopActive) {
|
||||
coloredMsg(LOG_YELLOW, true, "mbc hre [%d] enabling loop, try %d", mbusCommHandle.requestId, mbusCommHandle.retryCnt);
|
||||
mbusCommHandle.retryCnt++;
|
||||
loopEnable();
|
||||
// FIXME somehow manage to delay for about 100ms
|
||||
} else {
|
||||
mbusCommHandle.retryCnt = 0;
|
||||
// FIXME sending possibly needs to be done in a different way
|
||||
// HAL_UART_Transmit(&mbusUart, mbusCommHandle.sendBuffer.buffer, 5, HAL_MAX_DELAY);
|
||||
|
||||
// enable transmitter interrupt
|
||||
coloredMsg(LOG_YELLOW, false, "mbc hre [%d] enable transmitter interrupt", mbusCommHandle.requestId);
|
||||
//coloredMsg(LOG_YELLOW, false, "mbc hre [%d] enable transmitter interrupt", mbusCommHandle.requestId);
|
||||
__HAL_UART_ENABLE_IT(&mbusUart, UART_IT_TXE);
|
||||
|
||||
// transition from here to SENDING_DONE is initiate by mbusCommTxCpltCallback
|
||||
// interrupt callback
|
||||
mbusCommHandle.state = MBCS_SENDING;
|
||||
}
|
||||
break;
|
||||
|
||||
case MBCS_SENDING:
|
||||
// transition from here to MBCS_SENDING_DONE is done by TX ISR
|
||||
break;
|
||||
|
||||
case MBCS_SENDING_DONE:
|
||||
coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SENDING_DONE", mbusCommHandle.requestId);
|
||||
//coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SENDING_DONE", mbusCommHandle.requestId);
|
||||
mbusCommHandle.state = MBCS_ENABLE_FRONTEND;
|
||||
// FIXME somehow manage to delay for about 3ms
|
||||
break;
|
||||
|
||||
case MBCS_ENABLE_FRONTEND:
|
||||
coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state ENABLE_FRONTEND", mbusCommHandle.requestId);
|
||||
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state ENABLE_FRONTEND", mbusCommHandle.requestId);
|
||||
frontendEnable();
|
||||
calculatedChksum = 0;
|
||||
userdataIdx = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user