void loop() { ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);//ADATE ADIF ADIE DIDR0 |= _BV(ADC3D) | _BV(ADC2D); for(;;) { ADCSRB = 0; ADCSRB |= _BV(BIN); ADMUX = 0; ADMUX |= _BV(REFS1); ADMUX |= 0x11;//010000 010001 0x11 convb('d'); ADCSRB = 0; ADCSRB |= _BV(BIN); ADMUX = 0; ADMUX |= 0x11;//010000 010001 0x11 convb('e'); SerialSend('\r'); SerialSend('\n'); //uint32_t i = 0; //for(i=0;i<50000;i++) //{ // asm volatile("nop"); //} } }
void convb(uint8_t name){ uint16_t i; int32_t val = 0; ADCSRA |= _BV(ADSC);while(ADCSRA & _BV(ADSC)); ADCSRA |= _BV(ADSC);while(ADCSRA & _BV(ADSC)); for(i=0;i<1024;i++){ ADCSRA |= _BV(ADSC);while(ADCSRA & _BV(ADSC)); uint16_t v = ADC; if(v>=512){ v = 1024 - v; val -= v; } else { val += v; } } val = val >> 6; SerialSend(name);SerialSend(':'); if(val<0){ val = - val; SerialSend('-'); } else { SerialSend(' '); } SendInt(val,10);SerialSend(' '); }
void series_display(void) { GrPos Pos; GrRegion Region; int ret; Pixel64 FT; unsigned char data[100]; memset(data, 0, 100); sprintf(data, "hello COM2 send"); fd_ser = InitSerialCom(2, 115200, 'n', 1, 8); SerialSend(fd_ser, data, 5); FT.RGB.a = 255; FT.RGB.r = 255; FT.RGB.g = 255; FT.RGB.b = 255; Pos.x = 520; Pos.y = 265; display_character_into_screen(CONFIRM_SERIES, FT, &Pos, &Region); // getchar(); return ; }
void loop() { for(;;) { wait(5000); uint8_t val = aread(0); SerialSend(val); } }
void CustomerSettings1_TelnetProcessCharacter(uchar u) { ASSERT(u < UART_COUNT); if (mbCustomerSettings[u] == 1) { if (mbFlags[u] == true) { mbFlags[u] = false; OutMode(u); SerialSend(u, 0x99); mcwUARTTxOut[u]++; } } }
void MTBuildAndSendCmd(uint8_t cmdType, uint8_t cmdId, uint8_t dataLen, uint8_t *pData) { uint8_t *cmd_ptr, *msg; cmd_ptr = (uint8_t *) malloc(dataLen + SPI_0DATA_MSG_LEN); if (cmd_ptr == NULL) { syslog(LOG_INFO, "failed to allocate msg buffer"); return; } *cmd_ptr = MT_SOF; msg = cmd_ptr+1; *msg++ = dataLen; *msg++ = cmdType; *msg++ = cmdId; if (pData) memcpy(msg, pData, (size_t)dataLen); cmd_ptr[dataLen + SPI_0DATA_MSG_LEN -1] = CmdFCSCal(cmd_ptr + 1, dataLen + 3); SerialSend(cmd_ptr, (size_t)dataLen + SPI_0DATA_MSG_LEN); free((void *)cmd_ptr); }
int main(int argc,char**argv) { int rtn; int Count = 0; unsigned char *send = "Hello Uart"; unsigned char buf[1024] ={0}; if(2 > argc) { printf("Input error\n"); printf("Usage: %s <Device>\n",argv[0]); printf("Eample: %s /dev/ttyS0\n",argv[0]); return -1; } rtn = SerialOpen(argv[1]); if(0 > rtn) return -1; rtn = SerialConfig(115200,8,'n',1); if(0 > rtn) return -1; while(1) { rtn = SerialSend(send,strlen(send)); if(0 < rtn) { printf("[Send]: %s\n",send); } sleep(1); rtn = SerialReceive(buf,sizeof(buf)); if(0 < rtn) { printf("[Recv]: %s\n",buf); } } SerialClose(); }
void SendInt(uint32_t val, uint8_t digits){ uint32_t num = val; for(uint8_t idx = 0; idx < 10 ; idx++) { uint8_t outNum = 0; uint32_t CmpNum = pgm_read_dword_near(num10s + idx); for(uint8_t i = 0; i < 10 ; i++) { if(num>=CmpNum) { num -= CmpNum; outNum++; } else { break; } } if(10-idx<=digits){ SerialSend('0' + outNum);\ } } }
void DwSend(const u8 *out, int outlen) { if (CurrentPortKind() == 's') SerialSend((struct SPort*)Ports[CurrentPort], out, outlen); else DigisparkSend((struct UPort*)Ports[CurrentPort], out, outlen); }
void SocketModbusMasterLoop( void ) { char AdrIP[ 30 ]; int SizeQuestionToAsk; static char QuestionFrame[ 800 ]; int ResponseSize; static char ResponseFrame[ 800 ]; int SendResultStatus = 0; #ifdef __XENO__ pthread_set_name_np(pthread_self(), __FUNCTION__); #endif while( ClientSocketRunning ) { // TODO: added for XENO... not found why required for now... // (task suspended otherwise with the watchdog, seen with dmesg!) // removing this next line for EMC- we don't use XENO // DoPauseMilliSecs( 10 ); if (InfosGene->LadderState!=STATE_RUN) { DoPauseMilliSecs( ModbusTimeInterFrame ); } else { SizeQuestionToAsk = ModbusMasterAsk( (unsigned char*)AdrIP, (unsigned char*)QuestionFrame ); if ( SizeQuestionToAsk>0 ) { if ( ModbusSerialPortNameUsed[ 0 ]=='\0' ) { SendResultStatus = SendSocketModbusMaster( AdrIP, 502, QuestionFrame, SizeQuestionToAsk ); } else { // before sending queston, set size of frame that will be to receive after! SerialSetResponseSize( 1/*adr*/+GetModbusResponseLenghtToReceive()+2/*crc*/, ModbusTimeOutReceipt ); SerialSend( QuestionFrame, SizeQuestionToAsk ); } if ( SendResultStatus==0 ) { if ( ModbusTimeAfterTransmit>0 ) { // useful for USB-RS485 dongle... if( ModbusDebugLevel>=3 ) printf(_("INFO CLASSICLADDER- after transmit delay now...%i milliseconds\n"),ModbusTimeAfterTransmit); DoPauseMilliSecs( ModbusTimeAfterTransmit ); } if ( ModbusSerialPortNameUsed[ 0 ]=='\0' ) ResponseSize = WaitRespSocketModbusMaster( ResponseFrame, 800, ModbusTimeOutReceipt ); else ResponseSize = SerialReceive( ResponseFrame, 800, ModbusTimeOutReceipt ); NbrFrames++; if ( ResponseSize==0 ) printf(_("ERROR CLASSICLADDER- MODBUS NO RESPONSE (Errs=%d/%d) !?\n"), ++CptErrors, NbrFrames); if ( !TreatModbusMasterResponse( (unsigned char *)ResponseFrame, ResponseSize ) ) { // trouble? => flush all (perhaps we can receive now responses for old asks // and are shifted between ask/resp...) if ( ModbusSerialPortNameUsed[ 0 ]!='\0' ) SerialFlush( ); } } DoPauseMilliSecs( ModbusTimeInterFrame ); } else { // sleep( 1 ); DoPauseMilliSecs( 1000 ); } } } #ifndef __WIN32__ pthread_exit(NULL); #endif }
void SerialHandler::write(uint8_t b){ SerialSend(b); }
int main( int argc, char **argv ) { char ch; int serfd; char data[256]; char recvdata[256]; int length; int recvlength; int i; char cmdline[256]; int ret; //调试输出单元 tracePrintfInit(); { //modifyTraceLevelByMode(SYS_MODE, DEBUG_TRACE); //modifyTraceLevelByMode(IMG_MODE, DEBUG_TRACE); //modifyTraceLevelByMode(FT_MODE, DEBUG_TRACE); } printf("begin integrate\n"); serfd = InitSerialCom(2,115200,'n',1, 8); if (serfd == -1) { printf("COM2 open failure\n"); return 0; } i = 0; while(1) { memset(data, 0, 256); sprintf(data, "hello\n"); length = strlen(data); SerialSend(serfd, (unsigned char *)data, length); memset(recvdata, 0, 256); recvlength = serialReceive(serfd, recvdata, 256); if (recvlength) { printf("|%s|%d\n", recvdata, recvlength); if (recvlength == 2) { if (strncmp(recvdata, "ok", strlen("ok")) == 0) { printf("COM2 OK\n"); break; } } } i++; if (i > 50) { printf("COM2 FAILURE\n"); break; } usleep(1000*500); } while(1) { memset(cmdline, 0, 256); scanf("%s", cmdline); if (strncmp(cmdline, "getRTCTime", strlen("getRTCTime")) == 0) { memset(data, 0, 64); get_current_time_string(data); } else if (strncmp(cmdline, "setUSBTest", strlen("setUSBTest")) == 0) { ret = confirm_usb_running(); if (ret) { printf("testUSBSuccess\n"); } else { printf("testUSBFailure\n"); } } else if (strncmp(cmdline, "getSN", strlen("getSN")) == 0) { memset(data, 0, 64); get_pcba_sn(data, 64); printf("reportSN|%s\n", data); } else if (strncmp(cmdline, "getMac", strlen("getMac")) == 0) { memset(data, 0, 64); get_pcba_mac(data, 64); printf("reportMAC|%s\n", data); } else if (strncmp(cmdline, "getMediaBoradTestReport", strlen("getMediaBoradTestReport")) == 0) { memset(data, 0, 64); get_pcba_idx99(data, 64); printf("reportMediaBoardTestInfo|%s\n", data); } } #if 0 char ch; //调试输出单元 tracePrintfInit(); { //modifyTraceLevelByMode(SYS_MODE, DEBUG_TRACE); //modifyTraceLevelByMode(IMG_MODE, DEBUG_TRACE); //modifyTraceLevelByMode(FT_MODE, DEBUG_TRACE); } init_display_output_device(FMT_1080P_60); init_framebuf_module(); ft_Font_Init(); init_temperature_module(); sync_time_from_rtc(); prepare_bg(); /* system("mkdir -p /media"); system("mkdir -p /media/tfcard"); system("mkdir -p /media/usb"); system("mkdir -p /media/msata"); */ init_hard_device_task(); system("rm /tmp/leftai_ok /tmp/rightai_ok"); system("/tmp/sample_ai >/tmp/ai.log &"); display_welcom(); usleep(3000*1000); //ai_display_filter(1); while(1) { #if 1 if ((access("/tmp/leftai_ok", F_OK) == 0) && (access("/tmp/rightai_ok", F_OK) == 0)) { usleep(1000*1000); break; } #else if (access("/tmp/rightai_ok", F_OK) == 0) { break; } #endif ai_display_filter(0); if (get_ai_force_exit()) { break; } usleep(1000*1000); } if ((access("/tmp/leftai_ok", F_OK) == 0) && (access("/tmp/rightai_ok", F_OK) == 0)) { set_test_status(audio_ok); } ai_display_filter(1); system("touch /tmp/exit_ai"); // printf("aaaaaaa\n"); display_stb_info(); usleep(500*1000); // printf("dddddd\n"); series_display(); usleep(500*1000); display_msata(); usleep(500*1000); display_tfcard(); usleep(500*1000); display_usb(); usleep(500*1000); while(1) { if (test_flag & gpio_test) { display_gpio_test(); break; } else { display_gpio_putdown(); } if (get_force_exit_gpio()) { printf("\nGPIO failure\n"); break; } usleep(1000*1000); } save_test_status(); exit_timer(); usleep(500*1000); printf("\nvideo play\n"); display_player(); //save_test_status(); #if 1 while(1) { ch = getchar(); if (ch == 'q') { break; } else if (ch == 'w') { test_framebuf(); } else if (ch == 'e') { clearFramebuf(); } else if (ch == 'r') { Pixel64 *pCanvas; int width; int height; GrPos Pos; GrRegion Region; decJpgFile("/nfs/wait4open.jpg", &pCanvas, &height, &width); Pos.x = Pos.y = 0; Region.x = Region.y = 0; Region.w = width; Region.h = height; paint_canvas_2_background(pCanvas, Pos, Region); refresh_background_2_device(Pos, Region); } else if (ch == 't') { Pixel64 *pCanvas; int width; int height; GrPos Pos; GrRegion Region; decPngFile("/nfs/ico_dir.png", &pCanvas, &width, &height); Pos.x = 100; Pos.y = 100; Region.x = 0; Region.y = 0; Region.w = width; Region.h = height; paint_canvas_2_logic_device(pCanvas, Pos, Region); pCanvas = get_logic_canvas(); move_region_2_display(pCanvas, Pos, Region); } else if (ch == 'y') { GrPos Pos; Pixel64 FT; Pos.x = 137; Pos.y = 102; FT.RGB.a = 0xFF; FT.RGB.r = 0xD7; FT.RGB.g = 0xD7; FT.RGB.b = 0xD7; ft_Font_Str2Disp("hello world", FT, Pos, 40); } else if (ch == 'u') { fprintf(stderr, "开始装备测试\n"); set_test_network(0); } else if (ch == 'i') { confirm_network_running(0); } else if (ch == 'o') { float temp; temp = read_temperature(); printf("temperature %3.4f\n", temp); } else if (ch == 'p') { save_time_into_rtc(); } else if (ch == 'a') { sync_time_from_rtc(); } else if (ch == 's') { int value40; int value41; int value44; read_gpio_status(40, &value40); read_gpio_status(41, &value41); read_gpio_status(44, &value44); printf("40 = %d, 41 = %d, 44 = %d\n", value40, value41, value44); } else if (ch == 'd') { write_gpio_status(44, 0); } else if (ch == 'f') { write_gpio_status(44, 1); } else if (ch == 'g') { fd_ser = InitSerialCom(1,115200,'n',1, 8); } else if (ch == 'h') { unsigned char data[10]; sprintf(data, "hello"); SerialSend(fd_ser, data, 5); } else if (ch == 'j') { unsigned char data[10]; memset(data, 0, 10); serialReceive(fd_ser, data, 10); printf("data\n", data); } else if (ch == 'k') { get_system_time(); } else if (ch == 'l') { Pixel64 *pcanvas; Pixel64 FT; int i, j; FILE *wfp; pcanvas = getFramebuf(); wfp = fopen("/nfs/screen.raw", "wb"); for (i = 0; i < 720; i++) { for (j = 0; j < 1280; j++) { FT.RGB.r = pcanvas[j].RGB.r; FT.RGB.b = pcanvas[j].RGB.b; FT.RGB.a = pcanvas[j].RGB.a; FT.RGB.g = pcanvas[j].RGB.g; fwrite(&(FT.RGB.r), 1, 1, wfp); fwrite(&(FT.RGB.g), 1, 1, wfp); fwrite(&(FT.RGB.b), 1, 1, wfp); } pcanvas += 1280; } fclose(wfp); } } #endif close_logic_framebuf_module(); ft_Font_Destroy(); close_display_output_device(); return 0; #endif }