static msg_t can_tx(void * p) { CANTxFrame txmsg_can1; CANTxFrame txmsg_can2; (void)p; chRegSetThreadName("transmitter"); txmsg_can1.IDE = CAN_IDE_EXT; txmsg_can1.EID = 0x01234567; txmsg_can1.RTR = CAN_RTR_DATA; txmsg_can1.DLC = 8; txmsg_can1.data32[0] = 0x55AA55AA; txmsg_can1.data32[1] = 0x00FF00FF; txmsg_can2.IDE = CAN_IDE_EXT; txmsg_can2.EID = 0x0ABCDEF0; txmsg_can2.RTR = CAN_RTR_DATA; txmsg_can2.DLC = 8; txmsg_can2.data32[0] = 0x66AA66AA; txmsg_can2.data32[1] = 0x44FF44FF; while (!chThdShouldTerminate()) { canTransmit(&CAND1, CAN_ANY_MAILBOX, &txmsg_can1, MS2ST(100)); canTransmit(&CAND2, CAN_ANY_MAILBOX, &txmsg_can2, MS2ST(100)); chThdSleepMilliseconds(500); } return 0; }
static bool_t sendFile (uint8_t dest, uint8_t id, uint8_t page) { char filename[20]; chsnprintf(filename, sizeof filename, "tosqa%03d.bin", id); FRESULT res = f_stat(filename, &filinfo); if (res == 0) res = f_open(&fil, filename, FA_OPEN_EXISTING | FA_READ); if (res != 0) return false; chprintf(chp1, "(%s: %db)", filename, filinfo.fsize); chThdSleepMilliseconds(100); CANTxFrame txmsg; txmsg.IDE = CAN_IDE_EXT; txmsg.EID = 0x1F123400 + dest; txmsg.RTR = CAN_RTR_DATA; txmsg.DLC = 8; res = f_lseek(&fil, (page - 1) * 4096); if (res == 0) { int i; for (i = 0; i < 512; ++i) { UINT count; res = f_read(&fil, txmsg.data8, 8, &count); if (res != 0 || (i == 0 && count == 0)) break; memset(txmsg.data8 + count, 0xFF, 8 - count); canTransmit(&CAND1, 1, &txmsg, 100); // 1 mailbox, must send in-order! // don't call echoToBridge for these bulk transfers } } f_close(&fil); return res == 0; }
void tune_cb(GtkWidget *widget, gpointer data) { if(getMox()==1) { setMox(0); } if(canTransmit() || tx_out_of_band) { setTune(getTune()==0?1:0); vfo_update(NULL); } }
void sendMessage2(int size) { txmsg.DLC = size; msg_t result = canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE); if (result == RDY_OK) { canWriteOk++; } else { canWriteNotOk++; } }
static THD_FUNCTION(can_tx, p) { CANTxFrame txmsg; (void)p; chRegSetThreadName("transmitter"); txmsg.IDE = CAN_IDE_EXT; txmsg.EID = 0x01234567; txmsg.RTR = CAN_RTR_DATA; txmsg.DLC = 8; txmsg.data32[0] = 0x55AA55AA; txmsg.data32[1] = 0x00FF00FF; while (!chThdShouldTerminateX()) { canTransmit(&CAND1, CAN_ANY_MAILBOX, &txmsg, MS2ST(100)); canTransmit(&CAND2, CAN_ANY_MAILBOX, &txmsg, MS2ST(100)); chThdSleepMilliseconds(500); } }
static msg_t can_tx(void * p) { (void)p; CANTxFrame txmsg_can1; chRegSetThreadName("transmitter"); txmsg_can1.IDE = CAN_IDE_STD; txmsg_can1.EID = 0x412; txmsg_can1.RTR = CAN_RTR_DATA; // read the trimpot via ADC to decide what step commands to send out // uses low-level access to implement the simplest possible polled readout #define AD0CR_PDN (1UL << 21) #define AD0CR_START_NOW (1UL << 24) #define AD0CR_CHANNEL5 (1UL << 5) #define LPC17xx_ADC_CLKDIV 12 #define AD0CR_START_MASK (7UL << 24) // set up the ADC and pin LPC_SC->PCONP |= (1UL << 12); // enable ADC power LPC_ADC->CR = AD0CR_PDN | (LPC17xx_ADC_CLKDIV << 8) | AD0CR_CHANNEL5; LPC_PINCON->PINSEL3 |= 0b11 << 30; // enable P1.31 as AD0.5 uint8_t lastCmd = 0; while (!chThdShouldTerminate()) { chThdSleepMilliseconds(10); // avoid looping without yielding at all // perform one ADC conversion LPC_ADC->CR &= ~AD0CR_START_MASK; LPC_ADC->CR |= AD0CR_START_NOW; while ((LPC_ADC->GDR & (1<<31)) == 0) ; int sample = ((LPC_ADC->GDR >> 4) & 0xFFF) - 0x800; // signed uint8_t cmd = 0x14; // enable w/ half-step microstepping if (sample < 0) { cmd ^= 0x02; // direction sample = -sample; } if (sample < 100) continue; // dead zone, no stepping if (cmd != lastCmd) { // transmit a 1-byte "command" packet with the enable and direction bits txmsg_can1.DLC = 1; txmsg_can1.data8[0] = lastCmd = cmd; } else { sample /= 2; // >= 50 // transmit a 0-byte "step" packet, but delay 1..950 ms before doing so if (sample > 999) sample = 999; chThdSleepMilliseconds(1000-sample); txmsg_can1.DLC = 0; } canTransmit(&CAND1, 1, &txmsg_can1, 100); echoToBridge(&txmsg_can1); } return 0; }
void cancom_transmit(uint32_t id, uint8_t *data, uint8_t len) { CANTxFrame txmsg; txmsg.IDE = CAN_IDE_STD; txmsg.EID = id; txmsg.RTR = CAN_RTR_DATA; txmsg.DLC = len; for (int i = 0;i < len;i++) { txmsg.data8[i] = data[i]; } canTransmit(&CAND1, CAN_ANY_MAILBOX, &txmsg, MS2ST(100)); }
static msg_t can_rx (void * p) { (void)p; CANRxFrame rxmsg; CANTxFrame txmsg; txmsg.IDE = CAN_IDE_EXT; txmsg.RTR = CAN_RTR_DATA; txmsg.DLC = 8; (void)p; chRegSetThreadName("receiver"); while(!chThdShouldTerminate()) { while (canReceive(&CAND1, CAN_ANY_MAILBOX, &rxmsg, 100) == RDY_OK) { canToBridge(&rxmsg); if (!enableBootMaster) continue; /* Process message, with manual filtering */ if (rxmsg.IDE && (rxmsg.EID & 0x1FFFFF80) == 0x1F123480) { if (rxmsg.DLC == 8) { int i = 0; while (i < nextNode) if (memcmp(nodeMap[i], rxmsg.data8, 8) == 0) break; else ++i; if (i >= nextNode) memcpy(nodeMap[nextNode++], rxmsg.data8, 8); chprintf(chp1, "\r\nCAN ann %08x: %08x %08x -> %d\r\n", rxmsg.EID, rxmsg.data32[0], rxmsg.data32[1], i); txmsg.EID = 0x1F123400 + i; memcpy(txmsg.data8, rxmsg.data8, 8); canTransmit(&CAND1, 1, &txmsg, 100); echoToBridge(&txmsg); } else if (rxmsg.DLC == 2) { uint8_t dest = rxmsg.data8[0], page = rxmsg.data8[1]; chprintf(chp1, "CAN boot %08x: %02x #%d ", rxmsg.EID, dest, page); if (sendFile(dest, rxmsg.EID & 0x7F, page)) chprintf(chp1, " SENT"); chprintf(chp1, "\r\n"); } } } } return 0; }
static msg_t can_tx(void * p) { CANTxFrame txmsg; (void)p; chRegSetThreadName("transmitter"); txmsg.IDE = CAN_IDE_EXT; txmsg.EID = 0x01234567; txmsg.RTR = CAN_RTR_DATA; txmsg.DLC = 8; txmsg.data32[0] = 0x55AA55AA; txmsg.data32[1] = 0x00FF00FF; while (!chThdShouldTerminate()) { canTransmit(&CAND1, &txmsg, MS2ST(100)); chThdSleepMilliseconds(500); } return 0; }
// process one parsed CAN bus command static void processCanCmd (void) { uint32_t addr = parseHexNum(); char sep = canCmdBuf[canCmdFill++]; chprintf(chp1, "CAN: 0x%x %d\r\n", addr, sep); if (sep == '#') { CANTxFrame txMsg; txMsg.IDE = addr < 0x800 ? CAN_IDE_STD : CAN_IDE_EXT; txMsg.EID = addr; txMsg.DLC = 0; if (canCmdBuf[canCmdFill] == 'R') txMsg.RTR = CAN_RTR_REMOTE; else { txMsg.RTR = CAN_RTR_DATA; while (canCmdBuf[canCmdFill] > ' ' && txMsg.DLC < 8) txMsg.data8[txMsg.DLC++] = parseHexByte(); } canTransmit(&CAND1, 1, &txMsg, 100); } }
static THD_FUNCTION(can_tx, p) { CANTxFrame txmsg; (void)p; chRegSetThreadName("transmitter"); txmsg.IDE = CAN_IDE_EXT; txmsg.EID = 0x01234567; txmsg.RTR = CAN_RTR_DATA; txmsg.DLC = 8; txmsg.data32[0] = 0x55AA55AA; txmsg.data32[1] = 0x00; while (true) { txmsg.data32[1] = chVTGetSystemTime(); msg_t ret = canTransmit(&CAND1, CAN_ANY_MAILBOX, &txmsg, MS2ST(100)); if(ret == MSG_TIMEOUT || ret == MSG_RESET) oca_led_toggle(oca_led_err); chThdSleepMilliseconds(100); } }
static msg_t CanTxThread(void * arg) { (void)arg; chRegSetThreadName("CanTx"); CANTxFrame txmsg; uint32_t i; txmsg.IDE = CAN_IDE_EXT; txmsg.EID = 0x01234567; txmsg.RTR = CAN_RTR_DATA; txmsg.DLC = 8; for (i=0; i<8; i++) txmsg.data8[i] = 0; // txmsg.data32[0] = 0x55AA55AA; // txmsg.data32[1] = 0x00FF00FF; while (!chThdShouldTerminate()) { i = mpiovd_sensors_struct.analog01; putinrange(i, 0, 255); txmsg.data8[0] = i; i = mpiovd_sensors_struct.analog02; putinrange(i, 0, 255); txmsg.data8[1] = i; i = mpiovd_sensors_struct.analog03; putinrange(i, 0, 255); txmsg.data8[2] = i; i = mpiovd_sensors_struct.analog04; putinrange(i, 0, 255); txmsg.data8[3] = i; /* (>> 1) to exclude "dead" bit from SPI*/ txmsg.data8[4] = (raw_data.discrete >> 1) & 0xFF; canTransmit(&CAND1, &txmsg, MS2ST(100)); chThdSleepMilliseconds(250); } chThdExit(0); return 0; }
/****************************************************************************** * version: 1.0 * author: link * date: 2016.01.28 * brief: 更新数据 ******************************************************************************/ void w_Conf::updateData() { int i; for (i=0; i<projExist.size(); i++){ switch(projExist[i].toInt()){ case W_ALL: if (wAll == NULL){ wAll = new widget_All(this); tabWidget->addTab(wAll,tr("首页")); connect(wAll,SIGNAL(switchWindow(int)),this,SLOT(winTransmit(int))); connect(wAll,SIGNAL(switchFile(int)),this,SLOT(fileTransmit(int))); } wAll->fileExist = fileExist; wAll->projExist = projExist; wAll->updateShow(CONF); wAll->setHardware(); break; case W_RES: if (wRes == NULL){ wRes = new widget_Res(this); tabWidget->addTab(wRes,tr("电阻")); connect(wRes,SIGNAL(canSend(can_frame)),this,SLOT(canTransmit(can_frame))); } wRes->updateShow(RES); wRes->setHardware(); break; case W_OPP: if (wOpp == NULL){ wOpp = new widget_Opp(this); tabWidget->addTab(wOpp,tr("反嵌")); connect(wOpp,SIGNAL(canSend(can_frame)),this,SLOT(canTransmit(can_frame))); } wOpp->updateShow(OPP); wOpp->setHardware(); break; case W_INS: if (wIns == NULL){ wIns = new widget_Ins(this); tabWidget->addTab(wIns,tr("绝缘")); } wIns->updateShow(INS); wIns->setHardware(); break; case W_ACV: if (wAcv == NULL){ wAcv = new widget_Acv(this); tabWidget->addTab(wAcv,tr("交耐")); } wAcv->updateShow(ACV); wAcv->setHardware(); break; case W_DCV: if (wDcv == NULL){ wDcv = new widget_Dcv(this); tabWidget->addTab(wDcv,tr("直耐")); } wDcv->updateShow(DCV); wDcv->setHardware(); break; case W_ITT: if (wItt == NULL){ wItt = new widget_Itt(this); tabWidget->addTab(wItt,tr("匝间")); connect(wItt,SIGNAL(canSend(can_frame)),this,SLOT(canTransmit(can_frame))); } wItt->updateShow(ITT); wItt->setHardware(); break; default: break; } }