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:
- 17:faa4d4976d22
- Parent:
- 16:f4277e9b8612
- Child:
- 18:e6ed582f7022
--- a/payload.cpp Sat Jun 29 09:53:19 2019 +0000
+++ b/payload.cpp Sat Jul 06 09:47:09 2019 +0000
@@ -1,9 +1,11 @@
#include "mbed.h"
+#include "eventflags.h"
extern unsigned char rx_buffer[8], tx_buffer[8];
extern unsigned char rx_length, tx_length;
extern uint8_t can_tx_data[8];
extern uint8_t can_rx_data[8];
+extern int current_weight;
typedef struct can_id_d {
int dest_id;
@@ -20,11 +22,15 @@
};
can_id_d can_id_s;
data_field_d can_rxdata_frame;
+data_field_d can_txdata_frame;
CANMessage tx_message;
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);
+
void analyzePayload()
{
+ int can_id;
int loop;
printf("analyzePayload thread\r\n");
@@ -58,6 +64,29 @@
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)
+ {
+ 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;
+
+ }
}
}