Esempio n. 1
0
static void canMazdaRX8(void) {
	rand = rand * 17;

//	commonTxInit(0x300);
//	sendMessage2(0);

	commonTxInit(CAN_MAZDA_RX_RPM_SPEED);

#if EFI_VEHICLE_SPEED || defined(__DOXYGEN__)
	float kph = getVehicleSpeed();

	setShortValue(&txmsg, SWAP_UINT16(engine_rpm * 4), 0);
	setShortValue(&txmsg, 0xFFFF, 2);
	setShortValue(&txmsg, SWAP_UINT16((int )(100 * kph + 10000)), 4);
	setShortValue(&txmsg, 0, 6);
	sendMessage();
#endif /* EFI_VEHICLE_SPEED */

	commonTxInit(CAN_MAZDA_RX_STATUS_2);
	txmsg.data8[0] = 0xFE; //Unknown
	txmsg.data8[1] = 0xFE; //Unknown
	txmsg.data8[2] = 0xFE; //Unknown
	txmsg.data8[3] = 0x34; //DSC OFF in combo with byte 5 Live data only seen 0x34
	txmsg.data8[4] = 0x00; // B01000000; // Brake warning B00001000;  //ABS warning
	txmsg.data8[5] = 0x40; // TCS in combo with byte 3
	txmsg.data8[6] = 0x00; // Unknown
	txmsg.data8[7] = 0x00; // Unused

	commonTxInit(CAN_MAZDA_RX_STATUS_2);
	txmsg.data8[0] = 0x98; //temp gauge //~170 is red, ~165 last bar, 152 centre, 90 first bar, 92 second bar
	txmsg.data8[1] = 0x00; // something to do with trip meter 0x10, 0x11, 0x17 increments by 0.1 miles
	txmsg.data8[2] = 0x00; // unknown
	txmsg.data8[3] = 0x00; //unknown
	txmsg.data8[4] = 0x01; //Oil Pressure (not really a gauge)
	txmsg.data8[5] = 0x00; //check engine light
	txmsg.data8[6] = 0x00; //Coolant, oil and battery
	txmsg.data8[7] = 0x00; //unused
	sendMessage();
}
Esempio n. 2
0
static int parse_fpo_data(char *data, int data_size, int *read_bytes, SFPO_DATA *fpo_data)
{
	int curr_read_bytes = *read_bytes;

	READ(*read_bytes, 4, data_size, fpo_data->ul_off_start, data, unsigned int);
	READ(*read_bytes, 4, data_size, fpo_data->cb_proc_size, data, unsigned int);
	READ(*read_bytes, 4, data_size, fpo_data->cdw_locals, data, unsigned int);
	READ(*read_bytes, 2, data_size, fpo_data->cdw_params, data, unsigned short);
	READ(*read_bytes, 2, data_size, fpo_data->bit_values.bit_values, data, unsigned short);

	fpo_data->bit_values.bit_values = SWAP_UINT16(fpo_data->bit_values.bit_values);

	return (*read_bytes - curr_read_bytes);
}
Esempio n. 3
0
/**
 * Adds size to the beginning of a packet and a crc32 at the end. Then send the packet.
 */
void tunerStudioWriteCrcPacket(const uint8_t command, const void *buf, const uint16_t size) {
	// todo: max size validation
	*(uint16_t *) crcIoBuffer = SWAP_UINT16(size + 1);   // packet size including command
	*(uint8_t *) (crcIoBuffer + 2) = command;
	if (size != 0)
		memcpy(crcIoBuffer + 3, buf, size);
	// CRC on whole packet
	uint32_t crc = crc32((void *) (crcIoBuffer + 2), (uint32_t) (size + 1));
	*(uint32_t *) (crcIoBuffer + 2 + 1 + size) = SWAP_UINT32(crc);

//	scheduleMsg(&logger, "TunerStudio: CRC command %x size %d", command, size);

	tunerStudioWriteData(crcIoBuffer, size + 2 + 1 + 4);      // with size, command and CRC
}
Esempio n. 4
0
void handleCrc32Check(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t pageId, uint16_t offset,
		uint16_t count) {
	tsState.crc32CheckCommandCounter++;

	count = SWAP_UINT16(count);

	count = getTunerStudioPageSize(pageId);

	scheduleMsg(&tsLogger, "CRC32 request: pageId %d offset %d size %d", pageId, offset, count);

	uint32_t crc = SWAP_UINT32(crc32((void * ) getWorkingPageAddr(0), count));

	scheduleMsg(&tsLogger, "CRC32 response: %x", crc);

	tsSendResponse(tsChannel, mode, (const uint8_t *) &crc, 4);
}
Esempio n. 5
0
/**
 * Adds size to the beginning of a packet and a crc32 at the end. Then send the packet.
 */
void tunerStudioWriteCrcPacket(ts_channel_s *tsChannel, const uint8_t responseCode, const void *buf, const uint16_t size) {
	uint8_t *writeBuffer = tsChannel->writeBuffer;

	*(uint16_t *) writeBuffer = SWAP_UINT16(size + 1);   // packet size including command
	*(uint8_t *) (writeBuffer + 2) = responseCode;
	tunerStudioWriteData(tsChannel, writeBuffer, 3);      // header

	// CRC on whole packet
	uint32_t crc = crc32((void *) (writeBuffer + 2), 1); // command part of CRC
	crc = crc32inc((void *) buf, crc, (uint32_t) (size)); // combined with packet CRC
	*(uint32_t *) (writeBuffer) = SWAP_UINT32(crc);

	if (size > 0) {
		tunerStudioWriteData(tsChannel, (const uint8_t*)buf, size);      // body
	}

	tunerStudioWriteData(tsChannel, writeBuffer, 4);      // CRC footer
}
Esempio n. 6
0
/**
  * @brief  Scope command parse function 
  * @param  None
  * @retval Command ACK or ERR
  */
command parseGeneratorCmd(void){
	command cmdIn=CMD_ERR;
	uint8_t error=0;
	uint16_t index;
	uint8_t length,chan;
	uint16_t watchDog=5000;

		///////do{ 
		cmdIn = giveNextCmd();
		switch(cmdIn){
			case CMD_GEN_DATA://set data
				cmdIn = giveNextCmd();
				//index=(cmdIn&0xff00)>>8 | (cmdIn&0x00ff)<<8;
				index=SWAP_UINT16(cmdIn);
				length=cmdIn>>16;
				chan=cmdIn>>24;
				while(watchDog>0 && getBytesAvailable()<length*2+1){
					watchDog--;
					osDelay(1);
				}
				if(getBytesAvailable()<length*2+1){
					error=GEN_MISSING_DATA;
					while(commBufferReadByte(&chan)==0);
				}else{
					error=genSetData(index,length*2,chan);
					if (error){
						while(commBufferReadByte(&chan)==0);
					}else{
						genDataOKSendNext();
					}
				}
			break;
				
			case CMD_GEN_SAMPLING_FREQ: //set sampling freq
				cmdIn = giveNextCmd();
				if(cmdIn != CMD_END && cmdIn != CMD_ERR){
					error=genSetFrequency(((cmdIn)&0xffffff00)>>8,(uint8_t)(cmdIn));
				}else{
Esempio n. 7
0
#define NSB_MAGIC_HPP

#include <cstdint>
#define SWAP_UINT16(x) ((uint16_t)(((x) >> 8) | ((x) << 8)))

/*
 * SG - Steins;Gate
 * CH - Chaos;Head
 * FMDM - Full Metal Daemon: Muramasa
 * GCLX - Guilty Crown: Lost Christmas
 * */
enum /* Magic */ : uint16_t
{
    MAGIC_FWN_UNK = 0, // Fuwanovel eof extension?

    MAGIC_PARSE_TEXT = SWAP_UINT16(0xD800), // Intrinsic
    MAGIC_LITERAL = SWAP_UINT16(0xD000), // SG
    MAGIC_CHAPTER_DECLARATION = SWAP_UINT16(0x9400), // SG
    MAGIC_IF = SWAP_UINT16(0x9800), // SG
    MAGIC_JUMP = SWAP_UINT16(0xCF00), // SG
    MAGIC_CALL_FUNCTION = SWAP_UINT16(0xCE00), // SG
    MAGIC_CMP_LOGICAL_AND = SWAP_UINT16(0xC600), // SG
    MAGIC_CMP_LOGICAL_OR = SWAP_UINT16(0xC700), // SG
    MAGIC_SCOPE_BEGIN = SWAP_UINT16(0xC800), // Intrinsic
    MAGIC_SCOPE_END = SWAP_UINT16(0xC900), // Intrinsic
    MAGIC_MODULE_FILE_NAME = SWAP_UINT16(0x6800), // GCLX, FMDM, SG (GetModuleFileName)
    MAGIC_CLEAR_PARAMS = SWAP_UINT16(0x8E00), // Intrinsic
    MAGIC_RESET = SWAP_UINT16(0x5B00), // CH, SG
    MAGIC_CMP_NE = SWAP_UINT16(0xC100), // SG
    MAGIC_ADD_EXPRESSION = SWAP_UINT16(0xA500), // SG
    MAGIC_ASSIGN = SWAP_UINT16(0xB000), // SG
Esempio n. 8
0
static int ts_serial_ready(bool_t isConsoleRedirect) {
#if EFI_PROD_CODE
	if (isSerialOverUart() ^ isConsoleRedirect) {
		// TS uses USB when console uses serial
		return is_usb_serial_ready();
	} else {
		// TS uses serial when console uses USB
		return true;
	}
#else
	return true;
#endif
}

static uint16_t BINARY_RESPONSE = (uint16_t) SWAP_UINT16(BINARY_SWITCH_TAG);

// this thread wants a bit extra stack
static THD_WORKING_AREA(tsThreadStack, 3 * UTILITY_THREAD_STACK_SIZE);

extern TunerStudioOutputChannels tsOutputChannels;

extern tunerstudio_counters_s tsState;

static void resetTs(void) {
	memset(&tsState, 0, sizeof(tsState));
}

void printTsStats(void) {
#if EFI_PROD_CODE
	if (!isSerialOverUart()) {