Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r31c4bf94671f58375d2e1dbbbb37b37c6949e0c4 -r3ded5ffcbcade3f1da5d40c52936ab5f97fc6ec9 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 31c4bf94671f58375d2e1dbbbb37b37c6949e0c4) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 3ded5ffcbcade3f1da5d40c52936ab5f97fc6ec9) @@ -16,14 +16,16 @@ ***************************************************************************/ #include // for memcpy() - + +#include "Accel.h" #include "AlarmLamp.h" #include "BloodFlow.h" #include "Buttons.h" #include "DGInterface.h" #include "DialInFlow.h" #include "Dialysis.h" -#include "FPGA.h" +#include "FPGA.h" +#include "MessagePayloads.h" #include "ModeTreatment.h" #include "PresOccl.h" #include "SafetyShutdown.h" @@ -42,128 +44,6 @@ #define DEBUG_EVENT_MAX_TEXT_LEN 40 #endif -#pragma pack(push,1) - -typedef struct -{ - U08 confirmed; // 1 = confirmed, 0 = rejected/timed out -} OFF_BUTTON_MESSAGE_FROM_UI_PAYLOAD_T; - -typedef struct -{ - U32 alarmState; // 0 = no alarms, 1 = low priority, 2 = medium priority, 3 = high priority - U32 alarmTop; // ID of top active alarm - U32 escalatesIn; // seconds - U32 silenceExpiresIn; // seconds - U16 alarmsFlags; // bit flags: 1 = true, 0 = false for each bit -} ALARM_COMP_STATUS_PAYLOAD_T; - -typedef struct -{ - U08 major; - U08 minor; - U08 micro; - U16 build; - U08 fpgaId; - U08 fpgaMajor; - U08 fpgaMinor; - U08 fpgaLab; -} HD_VERSIONS_T; - -typedef struct -{ - U32 setPoint; - F32 measFlow; - F32 measRotorSpd; - F32 measPumpSpd; - F32 measMCSpd; - F32 measMCCurr; - F32 pwmDC; -} PERISTALTIC_PUMP_STATUS_PAYLOAD_T; - -typedef struct -{ - F32 arterialPressure; - F32 venousPressure; - F32 bldPumpOcclusion; - F32 diPumpOcclusion; - F32 doPumpOcclusion; -} PRESSURE_OCCLUSION_DATA_T; - -typedef struct -{ - U32 treatmentTimePrescribedinSec; - U32 treatmentTimeElapsedinSec; - U32 treatmentTimeRemaininginSec; -} TREATMENT_TIME_DATA_T; - -typedef struct -{ - U32 treatmentSubMode; - U32 uFState; - U32 salineBolusState; -} TREATMENT_STATE_DATA_T; - -typedef struct -{ - F32 res1PrimaryLoadCell; - F32 res1BackupLoadCell; - F32 res2PrimaryLoadCell; - F32 res2BackupLoadCell; -} LOAD_CELL_READINGS_PAYLOAD_T; - -typedef struct -{ - U32 setPtPSI; - F32 measFlowRateMlMin; - F32 setPWM; -} DG_RO_PUMP_DATA_PAYLOAD_T; - -typedef struct -{ - U32 setPtRPM; - F32 setPWM; -} DG_DRAIN_PUMP_DATA_PAYLOAD_T; - -typedef struct -{ - F32 roInPSI; - F32 roOutPSI; - F32 drainInPSI; - F32 drainOutPSI; -} DG_PRESSURES_DATA_PAYLOAD_T; - -typedef struct -{ - U32 resID; - U32 setFillToVolumeMl; - U32 setDrainToVolumeMl; -} DG_RESERVOIRS_DATA_PAYLOAD_T; - -typedef struct -{ - F32 volume_mL; - U32 adjustType; -} UF_SETTINGS_CHANGE_CONFIRMATION_PAYLOAD_T; - -typedef struct -{ - F32 TPi; - F32 TPo; - F32 TD1; - F32 TD2; - F32 TRo; - F32 TDi; - F32 HtrPrimThermo; - F32 HtrTrimThermo; - F32 HtrPrimColdJunc; - F32 HtrTrimColdJunc; - F32 HtrPrimInternal; - F32 HtrTrimInternal; -} DG_TEMPERATURES_T; - -#pragma pack(pop) - // ********** private data ********** static BOOL testerLoggedIn = FALSE; @@ -769,7 +649,54 @@ return result; } - + +/************************************************************************* + * @brief + * The broadcastAccelData function constructs an accelerometer data msg to \n + * be broadcast and queues the msg for transmit on the appropriate CAN channel. + * @details + * Inputs : none + * Outputs : accelerometer data broadcast msg constructed and queued. + * @param x : X axis vector magnitude (in g) + * @param y : Y axis vector magnitude (in g) + * @param z : Z axis vector magnitude (in g) + * @param xm : max X axis vector magnitude (in g) + * @param ym : max Y axis vector magnitude (in g) + * @param zm : max Z axis vector magnitude (in g) + * @param xt : X axis tilt (in degrees) + * @param yt : Y axis tilt (in degrees) + * @param zt : Z axis tilt (in degrees) + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastAccelData( F32 x, F32 y, F32 z, F32 xm, F32 ym, F32 zm, F32 xt, F32 yt, F32 zt ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + HD_ACCEL_DATA_PAYLOAD_T payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_ACCELEROMETER_DATA; + msg.hdr.payloadLen = sizeof( HD_ACCEL_DATA_PAYLOAD_T ); + payload.x = x; + payload.y = y; + payload.z = z; + payload.xMax = xm; + payload.yMax = ym; + payload.zMax = zm; + payload.xTilt = xt; + payload.yTilt = yt; + payload.zTilt = zt; + + memcpy( payloadPtr, &payload, sizeof( MSG_ID_HD_ACCELEROMETER_DATA ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_BROADCAST, ACK_NOT_REQUIRED ); + + return result; +} + /************************************************************************* * @brief broadcastAlarmStatus * The broadcastAlarmStatus function constructs an alarm status msg to \n @@ -2273,3 +2200,117 @@ * @return none *************************************************************************/ DATA_OVERRIDE_HANDLER_FUNC_U32( U32, handleTestHDSafetyShutdownOverrideRequest, testSetSafetyShutdownOverride, testResetSafetyShutdownOverride ) + +/************************************************************************* + * @brief + * The handleTestHDAccelOverrideRequest function handles a request to \n + * override the measured accelerometer sensor readings. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +DATA_ARRAY_OVERRIDE_HANDLER_FUNC_F32( F32, handleTestHDAccelOverrideRequest, testSetAccelAxisOverride, testResetAccelAxisOverride ) + +/************************************************************************* + * @brief + * The handleTestHDAccelMaxOverrideRequest function handles a request to \n + * override the measured accelerometer sensor maximum readings. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +DATA_ARRAY_OVERRIDE_HANDLER_FUNC_F32( F32, handleTestHDAccelMaxOverrideRequest, testSetAccelMaxOverride, testResetAccelMaxOverride ) + +/************************************************************************* + * @brief + * The handleTestHDAccelBroadcastIntervalOverrideRequest function handles a \n + * request to override the broadcast interval for accelerometer data messages. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +DATA_OVERRIDE_HANDLER_FUNC_U32( U32, handleTestHDAccelBroadcastIntervalOverrideRequest, testSetAccelDataPublishIntervalOverride, testResetAccelDataPublishIntervalOverride ) + +/************************************************************************* + * @brief + * The handleSetAccelCalibration function handles a request to set + * accelerometer calibration factors. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetAccelCalibration( MESSAGE_T *message ) +{ + BOOL result; + + if ( message->hdr.payloadLen == sizeof(ACCEL_CAL_PAYLOAD_T) ) + { + ACCEL_CAL_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(ACCEL_CAL_PAYLOAD_T) ); + result = setAccelCalibration( payload.xOffset, payload.yOffset, payload.zOffset ); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/************************************************************************* + * @brief + * The handleSetBloodFlowCalibration function handles a request to set + * blood flow calibration factors. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetBloodFlowCalibration( MESSAGE_T *message ) +{ + BOOL result; + + if ( message->hdr.payloadLen == sizeof(LINEAR_F32_CAL_PAYLOAD_T) ) + { + LINEAR_F32_CAL_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(LINEAR_F32_CAL_PAYLOAD_T) ); + result = setBloodFlowCalibration( payload.gain, payload.offset ); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/************************************************************************* + * @brief + * The handleSetDialysateFlowCalibration function handles a request to set + * dialysate flow calibration factors. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetDialysateFlowCalibration( MESSAGE_T *message ) +{ + BOOL result; + + if ( message->hdr.payloadLen == sizeof(LINEAR_F32_CAL_PAYLOAD_T) ) + { + LINEAR_F32_CAL_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(LINEAR_F32_CAL_PAYLOAD_T) ); + result = setDialInFlowCalibration( payload.gain, payload.offset ); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +}