diff --git a/Periphery.cpp b/Periphery.cpp index caa247c..7d1e3c6 100644 --- a/Periphery.cpp +++ b/Periphery.cpp @@ -11,6 +11,12 @@ Periphery::Periphery() : { _softVersion.DSP = 202; _softVersion.CPLD = 0; + + test_hmi_float_reg_400_test = 0; + test_hmi_float_reg_401_test = 0; + test_hmi_float_reg_402_test = 0; + test_hmi_float_reg_403_test = 0; + test_hmi_float_reg_404_test = 0; } @@ -23,7 +29,7 @@ void Periphery::config(){ // Data Frame MBOX _canb.configRxMBox(canSpace::MODBUS_SETTINGS_MBOX, canSpace::MsgID(0x0), canSpace::MsgCtrlReg(0x6)); // Modbus settings _canb.configTxMBox(canSpace::MODBUS_DATA_COMM_TO_CPU_MBOX, canSpace::MsgID(0x29), canSpace::MsgCtrlReg(0x28)); // Send Modbus data to CPU - // _canb.configRxMBox(canSpace::MODBUS_DATA_CPU_TO_COMM_MBOX, canSpace::MsgID(0x28), canSpace::MsgCtrlReg(0x8)); // Receive Modbus data from CPU + _canb.configRxMBox(canSpace::MODBUS_DATA_CPU_TO_COMM_MBOX, canSpace::MsgID(0x28), canSpace::MsgCtrlReg(0x8)); // Receive Modbus data from CPU _canb.configTxMBox(canSpace::DIGITAL_INPUT_MBOX, canSpace::MsgID(0x30), canSpace::MsgCtrlReg(0x2)); // Receive DI _canb.configRxMBox(canSpace::DIGITAL_OUTPUT_MBOX, canSpace::MsgID(0x31), canSpace::MsgCtrlReg(0x2)); // Send DO @@ -94,6 +100,24 @@ void Periphery::processDigitalOutput(){ } +void Periphery::init_modbus_table(){ + modbusRTU.setInputRegsAddr(400); + modbusRTU.setOutputRegsAddr(400); + + modbusRTU.addInputReg(0, test_hmi_float_reg_400_test); + modbusRTU.addInputReg(1, test_hmi_float_reg_401_test); + modbusRTU.addInputReg(2, test_hmi_float_reg_402_test); + modbusRTU.addInputReg(3, test_hmi_float_reg_403_test); + modbusRTU.addInputReg(4, test_hmi_float_reg_404_test); + + modbusRTU.addOutputReg(0, test_hmi_float_reg_400_test); + modbusRTU.addOutputReg(1, test_hmi_float_reg_401_test); + modbusRTU.addOutputReg(2, test_hmi_float_reg_402_test); + modbusRTU.addOutputReg(3, test_hmi_float_reg_403_test); + modbusRTU.addOutputReg(4, test_hmi_float_reg_404_test); +} + + bool Periphery::isModbusInit() const{ return _modbusInitFlag; } @@ -142,3 +166,16 @@ void Periphery::sendModbusDataToCPU(){ _canb.transmitMsg(canSpace::MODBUS_DATA_COMM_TO_CPU_MBOX, _message); } + + +void Periphery::receiveCpuModbusData(){ + if (_canb.isNewMessage(canSpace::MODBUS_DATA_CPU_TO_COMM_MBOX)) { // TODO check for init is incorect here maybe + _canb.receiveMsg(canSpace::MODBUS_DATA_CPU_TO_COMM_MBOX, _message); + + WEINBUS::WeinbusTableRegister reg; + + uint32_t addr = _message.mdl.all; + reg = modbusRTU._dataHandler.inputRegisters.get_register_cursor(addr - modbusRTU._dataHandler.inputRegisters.get_start_address()); + reg.write_data(_message.mdh.all); + } +} diff --git a/Periphery.h b/Periphery.h index d36ac4a..33e0c34 100644 --- a/Periphery.h +++ b/Periphery.h @@ -31,10 +31,11 @@ public: void processDigitalInput(); void processDigitalOutput(); + void init_modbus_table(); bool isModbusInit() const; void receiveModbusParameters(); void sendModbusDataToCPU(); - void processCPUModbus(); // TODO + void receiveCpuModbusData(); private: canSpace::CAN _canb; @@ -48,6 +49,12 @@ private: bool _modbusInitFlag; uint16_t _modbusRegCounter; + float test_hmi_float_reg_400_test; + float test_hmi_float_reg_401_test; + float test_hmi_float_reg_402_test; + float test_hmi_float_reg_403_test; + float test_hmi_float_reg_404_test; + public: MODBUSRTU::ModbusRTU modbusRTU; }; diff --git a/main2.cpp b/main2.cpp index 628c5eb..240eebe 100644 --- a/main2.cpp +++ b/main2.cpp @@ -117,7 +117,7 @@ void main() PieCtrlRegs.PIEIER9.bit.INTx8 = 1; periphery.config(); - periphery.modbusRTU.test_init_hmi_buffers(); + periphery.init_modbus_table(); //---------------------------------------------------------------------------------------- // SCIbSetup.config.baudrate = SCIB_BAUDRATE_DEFAULT; @@ -197,6 +197,8 @@ void idle_loop() if (periphery.isModbusInit()){ periphery.modbusRTU.execute(); } + + periphery.receiveCpuModbusData(); //<> }//end while