Skip to content

Commit

Permalink
features: default logging of TCP traffic in both directions. Logging …
Browse files Browse the repository at this point in the history
…of voltages during precharge.
  • Loading branch information
uhi22 committed Dec 12, 2023
1 parent f43f093 commit c7c101b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 20 deletions.
1 change: 1 addition & 0 deletions ccs/ccs32_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <libopencm3/stm32/spi.h>
#include <libopencm3/stm32/timer.h>
#include <libopencm3/stm32/dma.h>
#include "myLogging.h"
#include "configuration.h"
#include "printf.h"
#include "connMgr.h"
Expand Down
18 changes: 5 additions & 13 deletions ccs/myHelpers.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@

/* Interface header for myHelpers.c */

#ifndef MY_HELPERS_H
#define MY_HELPERS_H

/* Global Defines */

#define STR_TMP_SIZE 400
#define MY_SERIAL_PRINTBUFFERLEN 400

enum Module
{
MOD_CONNMGR = 1,
MOD_HWIF = 2,
MOD_HOMEPLUG = 4,
MOD_PEV = 8,
MOD_QCA = 16,
MOD_TCP = 32,
MOD_TCPTRAFFIC = 64,
MOD_IPV6 = 128,
MOD_MODEMFINDER = 256
};

extern uint16_t checkpointNumber;

/* Global Functions */
Expand All @@ -28,3 +18,5 @@ extern void showAsHex(uint8_t *data, uint16_t len, const char *description);
extern void sanityCheck(const char *hint);
extern void mySerialPrint(void);
extern void setCheckpoint(uint16_t newcheckpoint);

#endif
23 changes: 23 additions & 0 deletions ccs/myLogging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

/* definitions for logging */

#ifndef MY_LOGGING_H
#define MY_LOGGING_H

enum Module
{
MOD_CONNMGR = 1,
MOD_HWIF = 2,
MOD_HOMEPLUG = 4,
MOD_PEV = 8,
MOD_QCA = 16,
MOD_TCP = 32,
MOD_TCPTRAFFIC = 64,
MOD_IPV6 = 128,
MOD_MODEMFINDER = 256
};

/* Here we define, which logging data is produced after power-on */
#define DEFAULT_LOGGINGMASK (MOD_TCPTRAFFIC | MOD_HOMEPLUG | MOD_PEV)

#endif
3 changes: 3 additions & 0 deletions ccs/pevStateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,9 @@ void stateFunctionWaitForPreChargeResponse(void)
dinDocDec.V2G_Message.Body.PreChargeRes.EVSEPresentVoltage.Multiplier);
Param::SetInt(Param::evsevtg, EVSEPresentVoltage);
u = hardwareInterface_getInletVoltage();
if (Param::GetInt(Param::logging) & MOD_PEV) {
printf("Inlet %dV, accu %dV\r\n", u, hardwareInterface_getAccuVoltage());
}
if (ABS(u-hardwareInterface_getAccuVoltage()) < PARAM_U_DELTA_MAX_FOR_END_OF_PRECHARGE)
{
addToTrace(MOD_PEV, "Difference between accu voltage and inlet voltage is small. Sending PowerDeliveryReq.");
Expand Down
18 changes: 13 additions & 5 deletions ccs/tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,19 @@ void tcp_transmit(void)
tcpHeaderLen = 20; /* 20 bytes normal header, no options */
if (tcpPayloadLen+tcpHeaderLen<TCP_TRANSMIT_PACKET_LEN)
{
memcpy(&TcpTransmitPacket[tcpHeaderLen], tcpPayload, tcpPayloadLen);
tcp_prepareTcpHeader(TCP_FLAG_PSH + TCP_FLAG_ACK); /* data packets are always sent with flags PUSH and ACK. */
tcp_packRequestIntoIp();
lastUnackTransmissionTime = rtc_get_ms(); /* record the time of transmission, to be able to detect the timeout */
retryCounter = TCP_MAX_NUMBER_OF_RETRANSMISSIONS; /* Allow n retries of the same packet */
/* The packet fits into our transmit buffer. */
if (Param::GetInt(Param::logging) & MOD_TCPTRAFFIC) {
printf("[%u] TCP will transmit: ", rtc_get_ms());
for (uint16_t i=0; i < tcpPayloadLen; i++) {
printf("%02x", tcpPayload[i]);
}
printf("\r\n");
}
memcpy(&TcpTransmitPacket[tcpHeaderLen], tcpPayload, tcpPayloadLen);
tcp_prepareTcpHeader(TCP_FLAG_PSH + TCP_FLAG_ACK); /* data packets are always sent with flags PUSH and ACK. */
tcp_packRequestIntoIp();
lastUnackTransmissionTime = rtc_get_ms(); /* record the time of transmission, to be able to detect the timeout */
retryCounter = TCP_MAX_NUMBER_OF_RETRANSMISSIONS; /* Allow n retries of the same packet */
}
else
{
Expand Down
6 changes: 4 additions & 2 deletions include/param_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
*/

//Define a version string of your firmware here
#define VER 0.21.B
#define VER 0.22.B

#include "myLogging.h"

/* Entries must be ordered as follows:
1. Saveable parameters (id != 0)
Expand All @@ -62,7 +64,7 @@
TESTP_ENTRY(CAT_CHARGE, soc, "%", 0, 100, 0, 5 ) \
TESTP_ENTRY(CAT_CHARGE, batvtg, "V", 0, 1000, 1000, 6 ) \
TESTP_ENTRY(CAT_TEST, locktest, LOCK, 0, 2, 0, 9 ) \
TESTP_ENTRY(CAT_TEST, logging, MODULES, 0, 511, 0, 15 ) \
TESTP_ENTRY(CAT_TEST, logging, MODULES, 0, 511, DEFAULT_LOGGINGMASK, 15 ) \
VALUE_ENTRY(opmode, OPMODES, 2000 ) \
VALUE_ENTRY(version, VERSTR, 2001 ) \
VALUE_ENTRY(lasterr, errorListString, 2002 ) \
Expand Down

0 comments on commit c7c101b

Please sign in to comment.