Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: payload.cpp
- Revision:
- 18:e6ed582f7022
- Parent:
- 17:faa4d4976d22
- Child:
- 19:0356e54240cc
--- a/payload.cpp Sat Jul 06 09:47:09 2019 +0000 +++ b/payload.cpp Sat Jul 20 03:57:26 2019 +0000 @@ -1,5 +1,5 @@ #include "mbed.h" -#include "eventflags.h" +#include "yoda2.h" extern unsigned char rx_buffer[8], tx_buffer[8]; extern unsigned char rx_length, tx_length; @@ -27,6 +27,51 @@ extern MemoryPool<CANMessage, 16> can_mpool; extern Queue<CANMessage, 16> can_queue; extern void can_sendData(int can_id, uint8_t *tx_data, int length); +extern Device_Type_d device_type_v; +extern int device_address; // last 8 bits of address +extern int device_type; // first 3 bits of adddress + +void handleCupTrackCommand(data_field_d data_pack) +{ +} +void handleJamTrackCommand(data_field_d data_pack) +{ +} +void handleTeaTrackCommand(data_field_d data_pack) +{ +} +void handleJamCommand(data_field_d data_pack) +{ +} +void handleTeaCommand(data_field_d data_pack) +{ + int can_id; + switch (data_pack.cmd) + { + case COMMAND_INIT: + can_txdata_frame.cmd = COMMAND_INIT; + can_txdata_frame.value1 = current_weight; + can_txdata_frame.value2 = 0; + can_txdata_frame.value3 = 0; + can_txdata_frame.value4 = 0; + can_tx_data[0] = can_txdata_frame.cmd; + can_tx_data[1] = (can_txdata_frame.value1 & 0x00FF); + can_tx_data[2] = ((can_txdata_frame.value1 >> 8) & 0x00FF); + can_tx_data[3] = (can_txdata_frame.value2 & 0x00FF); + can_tx_data[4] = ((can_txdata_frame.value2 >> 8) & 0x00FF); + can_tx_data[5] = (can_txdata_frame.value3 & 0x00FF); + can_tx_data[6] = ((can_txdata_frame.value3 >> 8) & 0x00FF); + can_tx_data[7] = can_txdata_frame.value4; + can_id = (can_id_s.source_id << 18) | (can_id_s.dest_id << 7) | can_id_s.message_id | 0x80000000; + can_sendData(can_id, can_tx_data, 8); + break; + default: + break; + } +} +void handleShakerCommand(data_field_d command) +{ +} void analyzePayload() { @@ -64,29 +109,35 @@ can_rxdata_frame.value3 = (can_rx_data[6] << 8 ) | can_rx_data[5]; can_rxdata_frame.value4 = can_rx_data[7]; printf("cmd=%d, value1=0x%04x, value2=0x%04x, value3=0x%04x, value4=0x%02x \r\n", can_rxdata_frame.cmd, can_rxdata_frame.value1, can_rxdata_frame.value2, can_rxdata_frame.value3, can_rxdata_frame.value4); - switch (can_rxdata_frame.cmd) + device_type_v = (Device_Type_d)device_type; + switch (device_type_v) { - case COMMAND_INIT: - can_txdata_frame.cmd = COMMAND_INIT; - can_txdata_frame.value1 = current_weight; - can_txdata_frame.value2 = 0; - can_txdata_frame.value3 = 0; - can_txdata_frame.value4 = 0; - can_tx_data[0] = can_txdata_frame.cmd; - can_tx_data[1] = (can_txdata_frame.value1 & 0x00FF); - can_tx_data[2] = ((can_txdata_frame.value1 >> 8) & 0x00FF); - can_tx_data[3] = (can_txdata_frame.value2 & 0x00FF); - can_tx_data[4] = ((can_txdata_frame.value2 >> 8) & 0x00FF); - can_tx_data[5] = (can_txdata_frame.value3 & 0x00FF); - can_tx_data[6] = ((can_txdata_frame.value3 >> 8) & 0x00FF); - can_tx_data[7] = can_txdata_frame.value4; - can_id = (can_id_s.source_id << 18) | (can_id_s.dest_id << 7) | can_id_s.message_id | 0x80000000; - can_sendData(can_id, can_tx_data, 8); - break; - default: - break; - + case CupTrack: + printf("CupTrack command: %d \r\n", can_rxdata_frame.cmd); + handleCupTrackCommand(can_rxdata_frame); + break; + case JamTrack: + printf("JamTrack command: %d \r\n", can_rxdata_frame.cmd); + handleJamTrackCommand(can_rxdata_frame); + break; + case TeaTrack: + printf("TeaTrack command: %d \r\n", can_rxdata_frame.cmd); + handleTeaTrackCommand(can_rxdata_frame); + break; + case Tea: + printf("Tea command: %d \r\n", can_rxdata_frame.cmd); + handleTeaCommand(can_rxdata_frame); + break; + case Jam: + printf("Jam command: %d \r\n", can_rxdata_frame.cmd); + handleJamCommand(can_rxdata_frame); + break; + case Shaker: + printf("Shaker command: %d \r\n", can_rxdata_frame.cmd); + handleShakerCommand(can_rxdata_frame); + break; } + } }