int main(int argc, char **argv) { if(!sPort.Open("/dev/ttyUSB0", 57600)) { perror("Could not Open Serial Port s0 :"); exit(0); } int angle[4]; Leg_Config leg[4]; int num_packets,t; // char ch = argv[1][0]; // sPort.WriteByte(ch); int pre; scanf("%d",&num_packets); for (int k = 0; k < num_packets; k++) { scanf("%d",&pre); if(pre == 170) { for(int i=0;i<4;i++) { for(int j=0;j<4;j++) { if(j==0) { scanf("%d",&t); angle[j] = mat[i][t+2]; } else scanf("%d",&angle[j]); } leg[i] = makeLeg(angle[0],angle[1],angle[2],angle[3]); } Robot_Config myRobot = makeRobot(leg[0],leg[1],leg[2],leg[3]); sendCommand(myRobot, pre); } if(pre ==187) { char ch; scanf(" %c",&ch); //printf("%c", ch); //ch = 'w'; sendRollCommand(ch,pre); } usleep(1000000); } //Leg_Config leg1 = getDogGaitTheta(113.9725, -113.9398, 0); //printf("%d %d %d %d\n",leg1.theta[0],leg1.theta[1],leg1.theta[2], leg1.theta[3]); return 0; }
void setup() { int ret; ret = serial.Open("/dev/ttyACM0",9600); if(ret < 0) { printf("Unable to open the serial device\n"); exit(1); } }
int main() { Serial s; if(s.Open("/dev/ttySAC1",19200)) { cout<<"port open\n"; byte packet[]= {0xAA,0xBB,0x03,0x01,0x01,0x03}; for(int i=0; i<sizeof(packet); i++) { s.WriteByte((char)packet[i]); } byte packet_read[1]; int attempt=100; bool flag=false; while(attempt--) { if(s.Read(packet_read,1)>0) { for(int i=0; i<sizeof(packet_read); i++) printf("%x\n",packet_read[i]); flag=true; } } if(!flag) cout<<"nothing to read...\n"; cout<<"closing port...\n"; s.Close(); } else { cout<<"port could not open\n"; } return 0; }
int main() { Log log("./data/temp_log.txt", 1024 * 1024); rrdWeather *rrdW = new rrdWeather(); rrdBattery *rrdB = new rrdBattery(); string port = "/dev/ttyAMA0"; int iSpeed = 9600; char szReadBuffer[128]; int iBytesRead = 0; bool bLoop = true; memset(&szReadBuffer[0], 0, 128*sizeof(char)); LLAP llap; Serial serial; serial.Configure(port, iSpeed); serial.Open(); int tem = fcntl(0, F_GETFL, 0); fcntl (0, F_SETFL, (tem | O_NDELAY)); cout << "creating database if not exist" << endl; rrdW->create(); rrdB->create(); cout << "Listening serial port " << port << endl; string tmp; int illapRet = 0; while(true == bLoop) { memset(&szReadBuffer[0], 0, 128*sizeof(char)); iBytesRead = serial.Read(&szReadBuffer[0], 128, 2500, 12); if(0 < iBytesRead) { illapRet = llap.ParseMsg(szReadBuffer, iBytesRead); if(MSG_READY == illapRet || MSG_READY_PARTIAL == illapRet) { LLAP_MSG *pMsg = llap.GetLastMsg(); string strTime = GetCurrentTime(false); //Write to rrd if(0 == strcasecmp("TMPA", pMsg->m_szCmd)) { rrdW->update(atof(pMsg->m_szValue)); //Copy file to /var/www/rpi_web CopyFile(rrdW->GetFile(1), "/var/www/rpi_web/01_daily.png"); CopyFile(rrdW->GetFile(2), "/var/www/rpi_web/02_weekly.png"); CopyFile(rrdW->GetFile(3), "/var/www/rpi_web/03_monthly.png"); CopyFile(rrdW->GetFile(4), "/var/www/rpi_web/04_yearly.png"); } if(0 == strcasecmp("BATT", pMsg->m_szCmd)) { rrdB->update(atof(pMsg->m_szValue)); //Copy file to /var/www/rpi_web CopyFile(rrdB->GetFile(1), "/var/www/rpi_web/battery.png"); } if(0 == strcasecmp("BATTLOW", pMsg->m_szCmd)) { rrdB->LowBattWarning(); //Copy file to /var/www/rpi_web CopyFile(rrdB->GetFile(1), "/var/www/rpi_web/battery.png"); } //Write to screen and log tmp = strTime + "\t" + pMsg->m_szId + " " + pMsg->m_szCmd + " " + pMsg->m_szValue + "\t\t" + pMsg->m_szOriginal; cout << tmp << endl; log.Write(tmp); } } if('q' == getchar()) { bLoop = false; } } serial.Close(); cout << "Exiting program" << endl; fcntl(0, F_SETFL, tem); delete rrdW; delete rrdB; return 0; }