Beispiel #1
0
static void handle_res_packet(unsigned char *data, unsigned char len) {
	COMM_RES_PACKET_ID car_res_packet;
	uint8_t buffer2[256];
	int32_t index;

	(void)len;

	car_res_packet = data[0];
	data++;
	len--;

	switch (car_res_packet) {
	case COMM_READ_VALUES:
		index = 0;
		buffer2[index++] = COMM_READ_VALUES;
		buffer_append_int16(buffer2, (int16_t)(NTC_TEMP(ADC_IND_TEMP_MOS1) * 10.0), &index);
		buffer_append_int16(buffer2, (int16_t)(NTC_TEMP(ADC_IND_TEMP_MOS2) * 10.0), &index);
		buffer_append_int16(buffer2, (int16_t)(NTC_TEMP(ADC_IND_TEMP_MOS3) * 10.0), &index);
		buffer_append_int16(buffer2, (int16_t)(NTC_TEMP(ADC_IND_TEMP_MOS4) * 10.0), &index);
		buffer_append_int16(buffer2, (int16_t)(NTC_TEMP(ADC_IND_TEMP_MOS5) * 10.0), &index);
		buffer_append_int16(buffer2, (int16_t)(NTC_TEMP(ADC_IND_TEMP_MOS6) * 10.0), &index);
		buffer_append_int16(buffer2, (int16_t)(NTC_TEMP(ADC_IND_TEMP_PCB) * 10.0), &index);
		buffer_append_int32(buffer2, (int32_t)(mcpwm_read_reset_avg_motor_current() * 100.0), &index);
		buffer_append_int32(buffer2, (int32_t)(mcpwm_read_reset_avg_input_current() * 100.0), &index);
		buffer_append_int16(buffer2, (int16_t)(mcpwm_get_duty_cycle_now() * 1000.0), &index);
		buffer_append_int32(buffer2, (int32_t)mcpwm_get_rpm(), &index);
		buffer_append_int16(buffer2, (int16_t)(GET_INPUT_VOLTAGE() * 10.0), &index);
		packet_send_packet(buffer2, index);
		break;

	default:
		break;
	}
}
Beispiel #2
0
void comm_sendmsg(uint8_t id, uint8_t *data, uint8_t len) {
#if COMM_USE_CAN
	if (len > 8) {
		len = 8;
	}

	TxMessage.StdId = id;
	TxMessage.DLC = len;

	int i;
	for (i = 0;i < len;i++) {
		TxMessage.Data[i] = data[i];
	}

	CAN_Transmit(CAN1, &TxMessage);
#else
	uint8_t buf[len + 1];

	buf[0] = PACKET_INT_CMD_CLOCK;

	int i = 0;
	for (i = 0;i < len;i++) {
		buf[i + 1] = data[i];
	}

	packet_send_packet(buf, len + 1, 0);
#endif
}
Beispiel #3
0
void comm_send_rotor_pos(float rotor_pos) {
	uint8_t buffer[5];
	int32_t index = 0;

	buffer[index++] = COMM_ROTOR_POSITION;
	buffer_append_int32(buffer, (int32_t)(rotor_pos * 100000.0), &index);

	packet_send_packet(buffer, index);
}
Beispiel #4
0
void comm_send_samples(uint8_t *data, int len) {
	uint8_t buffer[len + 1];
	int index = 0;

	buffer[index++] = COMM_SEND_SAMPLES;

	for (int i = 0;i < len;i++) {
		buffer[index++] = data[i];
	}

	packet_send_packet(buffer, index);
}
Beispiel #5
0
void comm_print(char* str) {
	static char print_buffer[255];
	int i;
	print_buffer[0] = COMM_PRINT;

	for (i = 0;i < 255;i++) {
		if (str[i] == '\0') {
			break;
		}
		print_buffer[i + 1] = str[i];
	}

	packet_send_packet((unsigned char*)print_buffer, i + 1);
	return;
}
Beispiel #6
0
void comm_send_experiment_samples(float *samples, int len) {
	if ((len * 4 + 1) > 256) {
		return;
	}

	uint8_t buffer[len * 4 + 1];
	int32_t index = 0;

	buffer[index++] = COMM_EXPERIMENT_SAMPLE;

	for (int i = 0;i < len;i++) {
		buffer_append_int32(buffer, (int32_t)(samples[i] * 10000.0), &index);
	}

	packet_send_packet(buffer, index);
}
Beispiel #7
0
static void send_packet_wrapper(unsigned char *data, unsigned int len) {
	chMtxLock(&send_mutex);
	packet_send_packet(data, len, PACKET_HANDLER);
	chMtxUnlock(&send_mutex);
}
Beispiel #8
0
static void send_packet_wrapper(unsigned char *data, unsigned char len) {
	packet_send_packet(data, len, PACKET_HANDLER);
}