Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions software/hwio-raspberry/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ WORKDIR /CybICS
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY hardwareIO.py ./
COPY cybics_pb2.py ./

CMD [ "python", "./hardwareIO.py" ]
27 changes: 15 additions & 12 deletions software/hwio-raspberry/hardwareIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import logging
import threading

from cybics_pb2 import PressureData

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(8, GPIO.OUT) # compressor
Expand Down Expand Up @@ -253,25 +255,26 @@ def thread_i2c():
while True:
try:
# Read the values for GST and HPT
data = bus.read_i2c_block_data(address, 0x00, 20)
# print(data)
for row in range(len(data)):
data[row] = chr(data[row])
logging.debug("Read over i2c: " + str(data))
data = bus.read_i2c_block_data(address, 0x00, 12)
logging.debug(f"Raw I2C data (register 0x00): {data}")

try:
pressure_data = PressureData()
# Convert list of integers to bytes properly
byte_data = bytes(bytearray(data))
pressure_data.ParseFromString(byte_data)
gst = pressure_data.gst_pressure
hpt = pressure_data.hpt_pressure
logging.debug(f"Decoded protobuf - GST: {gst}, HPT: {hpt}")
except Exception as pb_error:
logging.warning(f"Failed to decode PressureData protobuf: {str(pb_error)}")

# Format the IP and send it via i2c to the RPI
sendIP = ['I', 'P',':'] + listIp
for row in range(len(sendIP)):
sendIP[row] = ord(sendIP[row])
bus.write_i2c_block_data(address, 0x00, sendIP)

# Simple check, if correct data was received
if(str(data[0]) == "G" and str(data[1]) == "S" and str(data[2]) == "T"):
gst = int(str(data[5] + data[6] + data[7]))
hpt = int(str(data[14] + data[15] + data[16]))

logging.debug(f"Setting GST to {str(gst)} and HPT to {str(hpt)}")

# Read STM32 ID Code
data = bus.read_i2c_block_data(address, 0x01, 13)
for c in range(len(data)):
Expand Down
1 change: 1 addition & 0 deletions software/hwio-raspberry/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ smbus-cffi==0.5.1
smbus2==0.5.0
nmcli==1.5.0
RPi.GPIO==0.7.1
grpcio-tools==1.76.0
12 changes: 9 additions & 3 deletions software/stm32/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ LOG_MODULE_REGISTER(cybics, LOG_LEVEL_INF);

/* Global variables */
uint8_t RxData[20] = {0};
uint8_t TxData[20] = {'G','S','T',':',' ','0','0','0',' ','H','P','T',':',' ','0','0','0',0,0,0};
uint8_t TxData[cybics_PressureData_size] = {0}; /* Serialized PressureData protobuf */
uint8_t TxDataUID[14] = {0}; /* 12 hex chars + mode flag + null */
char rpiIP[15] = {'U','N','K','N','O','W','N',0,0,0,0,0,0,0,0};
uint8_t GSTpressure = 0;
Expand Down Expand Up @@ -717,8 +717,14 @@ void thread_physical(void *arg1, void *arg2, void *arg3)
GST_low = 0; GST_normal = 0; GST_full = 1;
}

/* Update TX Data */
snprintf((char*)TxData, sizeof(TxData), "GST: %03d HPT: %03d", GSTpressure, HPTpressure);
/* Initialize protobuf pressure data and serialize to TxData */
cybics_PressureData cybics_pressure_data = cybics_PressureData_init_default;
cybics_pressure_data.gst_pressure = GSTpressure;
cybics_pressure_data.hpt_pressure = HPTpressure;
pb_ostream_t stream = pb_ostream_from_buffer(TxData, sizeof(TxData));
if (!pb_encode(&stream, cybics_PressureData_fields, &cybics_pressure_data)) {
LOG_ERR("Failed to serialize pressure data");
}

HPTdelay++;
GSTdelay++;
Expand Down
Loading