void edpDisplayReply(uint8_t response, EdpReply* edpReply) { uint8_t i; uint8_t checksum; // display response rprintf("EDP Response: 0x%x '%c'\r\n",response,response); // if data was received if(response==EDP_RESP_DATA_REPLY) { // do checksum on reply checksum = edpReply->Length; for(i=0; i<(edpReply->Length-1); i++) { checksum += edpReply->Data[i]; } checksum = ~checksum; // print message rprintf("EDP Reply: "); // show data received rprintf("Length: 0x%x ",edpReply->Length); rprintf("RxChksum=0x%x MyChksum=0x%x",edpReply->Data[edpReply->Length-1], checksum); rprintfCRLF(); rprintf("Data:\r\n"); debugPrintHexTable((edpReply->Length-1), edpReply->Data); rprintfCRLF(); } }
int main(void) { u08 i; setup(); while(1==1) { if(bit_is_clear(PIND, PIND5)) { sbi(PORTB, PB3); rprintfChar('1'); rprintfCRLF(); rprintfChar(0); } else if(bit_is_clear(PIND, PIND6)) { sbi(PORTB, PB3); rprintfChar('2'); rprintfCRLF(); rprintfChar(0); } else if(bit_is_clear(PIND, PIND7)) { sbi(PORTB, PB3); rprintfChar('3'); rprintfCRLF(); rprintfChar(0); } else { cbi(PORTB, PB3); } } return 0; }
void dumpArgsHex(void) { rprintfCRLF(); rprintf("Dump arguments as hex integers\r\n"); rprintf("Arg1 as hex: "); rprintfNum(16, 8, FALSE, ' ', cmdlineGetArgHex(1)); rprintfCRLF(); rprintf("Arg2 as hex: "); rprintfNum(16, 8, FALSE, ' ', cmdlineGetArgHex(2)); rprintfCRLF(); rprintf("Arg3 as hex: "); rprintfNum(16, 8, FALSE, ' ', cmdlineGetArgHex(3)); rprintfCRLF(); rprintfCRLF(); }
void helpFunction(void) { rprintfCRLF(); rprintf("Available commands are:\r\n"); rprintf("help - displays available commands\r\n"); rprintf("dumpargs1 - dumps command arguments as strings\r\n"); rprintf("dumpargs2 - dumps command arguments as decimal integers\r\n"); rprintf("dumpargs3 - dumps command arguments as hex integers\r\n"); rprintfCRLF(); }
unsigned char ataWriteSectorsLBA( unsigned char Drive, unsigned long lba, unsigned int numsectors, unsigned char *Buffer) { unsigned int cyl, head, sect; unsigned char temp; #ifdef DEBUG_ATA rprintfProgStrM("ATA LBA write "); rprintfu32(lba); rprintfProgStrM(" "); rprintfu16(numsectors); rprintfProgStrM(" "); rprintfu16((unsigned int)Buffer); rprintfCRLF(); #endif sect = (int) ( lba & 0x000000ffL ); lba = lba >> 8; cyl = (int) ( lba & 0x0000ffff ); lba = lba >> 16; head = ( (int) ( lba & 0x0fL ) ) | ATA_HEAD_USE_LBA; temp = ataWriteSectorsCHS( Drive, head, cyl, sect, numsectors, Buffer ); if(temp) ataDiskErr(); return temp; }
void encoderTest(void) { // initialize the encoders encoderInit(); // print a little intro message so we know things are working rprintf("\r\nWelcome to the encoder test!\r\n"); // report encoder position continuously while(1) { rprintfProgStrM("Encoder0: "); // print encoder0 position // use base-10, 10 chars, signed, pad with spaces rprintfNum(10, 10, TRUE, ' ', encoderGetPosition(0)); rprintfProgStrM(" Encoder1: "); // print encoder1 position // use base-10, 10 chars, signed, pad with spaces rprintfNum(10, 10, TRUE, ' ', encoderGetPosition(1)); // print carriage return and line feed rprintfCRLF(); } }
uint8_t edpComposeCommand(uint8_t srcEdpAddr, uint8_t* cmdBuffer) { uint8_t string[80]; uint8_t len; uint8_t i; // instructions rprintfProgStrM("Enter EDP Command, format [c][p1][p2][p3]...[pN]\r\n"); rprintfProgStrM("[c] is command char, [px] parameters in 2-digit hex\r\n"); // get user input rprintfProgStrM("EDP Command>"); len = inputString(0x0D, 80, string); rprintfCRLF(); // check for null user input if(!len) { rprintfProgStrM("ERROR: No command\r\n"); // return immediately with zero command length return 0; } // prepare command cmdBuffer[0] = srcEdpAddr; cmdBuffer[1] = string[0]; for(i=0; i<len/2; i++) { cmdBuffer[i+2] = asciiHexToByte(&string[1+(i*2)]); } // return command length return 2+(len/2); }
boolean _blackfinGetPixel(CAMERA* cam,uint16_t x, uint16_t y, COLOR * color){ BLACKFIN_CAMERA* camera = (BLACKFIN_CAMERA*)cam; boolean rtn = FALSE; int32_t values[3]; // Make rprintf go to _blackfin_command Writer old = rprintfInit(&_blackfin_putcmd); _blackfin_index=0; // send 'vp' command rprintf("vp"); rprintfNum(10,4,FALSE,'0',x); rprintfNum(10,4,FALSE,'0',y); // process the command int args = __blackfinCommand(camera,PSTR("##vp "),null,values,3); if(args==3){ rtn = TRUE; colorSetYUV(color,(uint8_t)(values[0]), (uint8_t)(values[1]),(uint8_t)(values[2])); #ifdef BLACKFIN_DEBUG _blackfin_set_active(camera->debug); //Send rprintf to the debugger rprintf(" Color = "); colorDump(color); rprintfCRLF(); #endif } // Restore rprintf to original position rprintfInit(old); return rtn; }
void dumpArgsInt(void) { rprintfCRLF(); rprintf("Dump arguments as integers\r\n"); // printf %d will work but only if your numbers are less than 16-bit values //rprintf("Arg1 as int: %d\r\n", cmdlineGetArgInt(1)); //rprintf("Arg2 as int: %d\r\n", cmdlineGetArgInt(2)); //rprintf("Arg3 as int: %d\r\n", cmdlineGetArgInt(3)); // printfNum is good for longs too rprintf("Arg1 as int: "); rprintfNum(10, 10, TRUE, ' ', cmdlineGetArgInt(1)); rprintfCRLF(); rprintf("Arg2 as int: "); rprintfNum(10, 10, TRUE, ' ', cmdlineGetArgInt(2)); rprintfCRLF(); rprintf("Arg3 as int: "); rprintfNum(10, 10, TRUE, ' ', cmdlineGetArgInt(3)); rprintfCRLF(); rprintfCRLF(); }
void erpDisplayPacket(ErpPacket* erpPacket, u08 pktLength) { u08 i; u08 flag; // show ERP packet header erpDisplayHeader(erpPacket); // dump complete raw packet data if(pktLength) { // check if all characters are printable flag = TRUE; for(i=0; i<pktLength; i++) { if( ((u08*)erpPacket)[i] < 0x20 ) flag = FALSE; } // print packet data rprintf("Data:\r\n"); if(flag) { // print as string rprintfStrLen(((u08*)erpPacket), 0, pktLength); } else { // print as hex debugPrintHexTable(pktLength, ((u08*)erpPacket)); } rprintfCRLF(); } }
void mitelgpsProcessNAVDATAGND(u08* packet) { // process "F00" report packets - Navigation Data (Ground) char* endptr; if(debug & MITELGPS_DEBUG_EXTRACT) { rprintf("MITELGPS: "); rprintfStr(packet); rprintfCRLF(); } // start parsing just after "F00" // get latitude [sdd.dddddd] GpsInfo.PosLLA.lat.f = strtod(&packet[3], &endptr); // get longitude [sddd.dddddd] GpsInfo.PosLLA.lon.f = strtod(&packet[3+10], &endptr); // get altitude [sxxxxxx.x] GpsInfo.PosLLA.alt.f = strtod(&packet[3+10+11], &endptr); // get speed [sxxx.xx] GpsInfo.VelHS.speed.f = strtod(&packet[3+10+11+9], &endptr); // get heading [ddd] GpsInfo.VelHS.heading.f = strtod(&packet[3+10+11+9+7], &endptr); // get # of SVs tracked [xx] GpsInfo.numSVs = atoi(&packet[3+10+11+9+7+5+7+5+5+5]); }
void CommandLine(void) { u08 c; /* Variable to Run or stop program */ Run = TRUE; /* Clears the screen and sets the cursor under the Title */ vt100ClearScreen(); vt100SetCursorPos(1,0); rprintfProgStrM("\r\n\t\t\tStepper Motor Driver - Serial Console\r\n"); cmdlineInit(); cmdlineSetOutputFunc(uartSendByte); cmdlineAddCommand("quit", quitCommandLine); cmdlineAddCommand("help", helpDisplay); cmdlineAddCommand("step", runMotor); cmdlineInputFunc('\r'); while(Run) { while( uartReceiveByte(&c) ) cmdlineInputFunc(c); cmdlineMainLoop(); } rprintfCRLF(); rprintf("Program halted."); }
void cs8900RegDump(void) { rprintfProgStrM("CS8900 PacketPage Registers\r\n"); rprintfProgStrM("CHIP ID: "); rprintfu16(cs8900ReadReg(PP_ChipID)); rprintfCRLF(); rprintfProgStrM("PP_ISAIOB: "); rprintfu16(cs8900ReadReg(PP_ISAIOB)); rprintfCRLF(); rprintfProgStrM("MAC addr: "); rprintfu16(cs8900ReadReg(PP_IA+0)); rprintfu16(cs8900ReadReg(PP_IA+2)); rprintfu16(cs8900ReadReg(PP_IA+4)); rprintfCRLF(); }
void ataDriveInit(void) { u08 i; unsigned char* buffer = (unsigned char*) SECTOR_BUFFER_ADDR; // read drive identity rprintfProgStrM("\r\nScanning IDE interface...\r\n"); // Wait for drive to be ready ataStatusWait(ATA_SR_BSY, ATA_SR_BSY); // issue identify command ataWriteByte(ATA_REG_CMDSTATUS1, 0xEC); // wait for drive to request data transfer ataStatusWait(ATA_SR_DRQ, ATA_SR_DRQ); timerPause(200); // read in the data ataReadDataBuffer(buffer, 512); // set local drive info parameters ataDriveInfo.cylinders = *( ((unsigned int*) buffer) + ATA_IDENT_CYLINDERS ); ataDriveInfo.heads = *( ((unsigned int*) buffer) + ATA_IDENT_HEADS ); ataDriveInfo.sectors = *( ((unsigned int*) buffer) + ATA_IDENT_SECTORS ); ataDriveInfo.LBAsupport = *( ((unsigned int*) buffer) + ATA_IDENT_FIELDVALID ); ataDriveInfo.sizeinsectors = *( (unsigned long*) (buffer + ATA_IDENT_LBASECTORS*2) ); // copy model string for(i=0; i<40; i+=2) { // correct for byte order ataDriveInfo.model[i ] = buffer[(ATA_IDENT_MODEL*2) + i + 1]; ataDriveInfo.model[i+1] = buffer[(ATA_IDENT_MODEL*2) + i ]; } // terminate string ataDriveInfo.model[40] = 0; // process and print info if(ataDriveInfo.LBAsupport) { // LBA support rprintf("Drive 0: %dMB ", ataDriveInfo.sizeinsectors/(1000000/512) ); rprintf("LBA mode -- MODEL: "); } else { // CHS, no LBA support // calculate drive size ataDriveInfo.sizeinsectors = (unsigned long) ataDriveInfo.cylinders* ataDriveInfo.heads*ataDriveInfo.sectors; rprintf("Drive 0: %dMB ", ataDriveInfo.sizeinsectors/(1000000/512) ); rprintf("CHS mode C=%d H=%d S=%d -- MODEL: ", ataDriveInfo.cylinders, ataDriveInfo.heads, ataDriveInfo.sectors ); } // print model information rprintfStr(ataDriveInfo.model); rprintfCRLF(); // initialize local disk parameters //ataDriveInfo.cylinders = ATA_DISKPARM_CLYS; //ataDriveInfo.heads = ATA_DISKPARM_HEADS; //ataDriveInfo.sectors = ATA_DISKPARM_SECTORS; }
void ataDiskErr(void) { unsigned char b; b = ataReadByte(ATA_REG_ERROR); rprintfProgStrM("ATA Error: "); rprintfu08(b); rprintfCRLF(); }
void icmpPrintHeader(icmpip_hdr* packet) { rprintfProgStrM("ICMP Packet:\n"); // print source IP address rprintfProgStrM("SrcIpAddr: "); netPrintIPAddr(htonl(packet->ip.srcipaddr)); rprintfCRLF(); // print dest IP address rprintfProgStrM("DstIpAddr: "); netPrintIPAddr(htonl(packet->ip.destipaddr)); rprintfCRLF(); // print type rprintfProgStrM("Type : "); switch(packet->icmp.type) { case ICMP_TYPE_ECHOREQUEST: rprintfProgStrM("ECHO REQUEST"); break; case ICMP_TYPE_ECHOREPLY: rprintfProgStrM("ECHO REPLY"); break; default: rprintfProgStrM("UNKNOWN"); break; } rprintfCRLF(); // print code rprintfProgStrM("Code : 0x"); rprintfu08(packet->icmp.icode); rprintfCRLF(); }
static void help(void){ rprintf("\nL = List"); rprintf("\n+ = Increment"); rprintf("\n- = Decrement"); rprintf("\n* = Add 10"); rprintf("\n/ = Sub 10"); rprintf("\nN = Next Servo"); rprintf("\nP = Previous Servo"); rprintf("\nC = Center mode"); rprintf("\nR = Range mode"); rprintfCRLF(); }
void dhcpPrintHeader(struct netDhcpHeader* packet) { rprintfProgStrM("DHCP Packet:\r\n"); // print op rprintfProgStrM("Op : "); switch (packet->bootp.op) { case BOOTP_OP_BOOTREQUEST: rprintfProgStrM("BOOTREQUEST"); break; case BOOTP_OP_BOOTREPLY: rprintfProgStrM("BOOTREPLY"); break; default: rprintfProgStrM("UNKNOWN"); break; } rprintfCRLF(); // print transaction ID rprintfProgStrM("XID : 0x"); rprintfu32(packet->bootp.xid); rprintfCRLF(); // print client IP address rprintfProgStrM("ClIpAddr: "); netPrintIPAddr(htonl(packet->bootp.ciaddr)); rprintfCRLF(); // print 'your' IP address rprintfProgStrM("YrIpAddr: "); netPrintIPAddr(htonl(packet->bootp.yiaddr)); rprintfCRLF(); // print server IP address rprintfProgStrM("SvIpAddr: "); netPrintIPAddr(htonl(packet->bootp.siaddr)); rprintfCRLF(); // print gateway IP address rprintfProgStrM("GwIpAddr: "); netPrintIPAddr(htonl(packet->bootp.giaddr)); rprintfCRLF(); // print client hardware address rprintfProgStrM("ClHwAddr: "); netPrintEthAddr((struct netEthAddr*)packet->bootp.chaddr); rprintfCRLF(); }
int main(void) { struct netEthAddr myEthAddress; timerInit(); uartInit(); uartSetBaudRate(9600); rprintfInit(uartSendByte); timerPause(100); rprintf("\r\nNetwork Stack Example\r\n"); // initialize systick timer rprintf("Initializing Periodic Timer\r\n"); timer2SetPrescaler(TIMER_CLK_DIV1024); timerAttach(TIMER2OVERFLOW_INT, systickHandler); // init network stack rprintf("Initializing Network Stack\r\n"); netstackInit(IPADDRESS, NETMASK, GATEWAY); nicGetMacAddress(&myEthAddress.addr[0]); rprintfProgStrM("Eth Addr is: "); netPrintEthAddr(&myEthAddress); rprintfCRLF(); rprintfProgStrM("IP Addr is: "); netPrintIPAddr(ipGetConfig()->ip); rprintfCRLF(); rprintf("Network Stack is up!\r\n"); rprintf("Starting packet receive loop\r\n"); while (1) { // service local stuff serviceLocal(); // service the network netstackService(); } return 0; }
void ataPrintSector( u08 *Buffer) { u08 i; u16 j; u08 *buf; u08 s; buf = Buffer; // print the low order address indicies rprintfProgStrM(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\r\n"); rprintfProgStrM(" ----------------------------------------------- ---- ASCII -----\r\n"); // print the data for(j=0; j<0x20; j++) { // print the high order address index for this line rprintfu16(j<<4); rprintfProgStrM(" "); // print the hex data for(i=0; i<0x10; i++) { rprintfu08(buf[(j<<4)+i]); rprintfProgStrM(" "); } // leave some space rprintfProgStrM(" "); // print the ascii data for(i=0; i<0x10; i++) { s = buf[(j<<4)+i]; // make sure character is printable if(s >= 0x20) { rprintfChar(s); } else { rprintfChar(0x20); } } rprintfCRLF(); } }
int netstackService(void) { int len; struct netEthHeader* ethPacket; // look for a packet len = nicPoll(NETSTACK_BUFFERSIZE, NetBuffer); if(len) { ethPacket = (struct netEthHeader*)&NetBuffer[0]; #if NET_DEBUG >= 5 rprintf("Received packet len: %d, type:", len); rprintfu16(htons(ethPacket->type)); rprintfCRLF(); rprintf("Packet Contents\r\n"); debugPrintHexTable(len, NetBuffer); #endif if(ethPacket->type == htons(ETHTYPE_IP)) { // process an IP packet #ifdef NETSTACK_DEBUG rprintfProgStrM("NET Rx: IP packet\r\n"); #endif // add the source to the ARP cache // also correctly set the ethernet packet length before processing? arpIpIn((struct netEthIpHeader*)&NetBuffer[0]); //arpPrintTable(); netstackIPProcess( len-ETH_HEADER_LEN, (ip_hdr*)&NetBuffer[ETH_HEADER_LEN] ); } else if(ethPacket->type == htons(ETHTYPE_ARP)) { // process an ARP packet #ifdef NETSTACK_DEBUG rprintfProgStrM("NET Rx: ARP packet\r\n"); #endif arpArpIn(len, ((struct netEthArpHeader*)&NetBuffer[0]) ); #ifdef NETSTACK_DEBUG //arpPrintTable(); #endif } } return len; }
void dumpArgsStr(void) { rprintfCRLF(); rprintf("Dump arguments as strings\r\n"); rprintfProgStrM("Arg0: "); rprintfStr(cmdlineGetArgStr(0)); rprintfCRLF(); rprintfProgStrM("Arg1: "); rprintfStr(cmdlineGetArgStr(1)); rprintfCRLF(); rprintfProgStrM("Arg2: "); rprintfStr(cmdlineGetArgStr(2)); rprintfCRLF(); rprintfProgStrM("Arg3: "); rprintfStr(cmdlineGetArgStr(3)); rprintfCRLF(); rprintfCRLF(); }
void cs8900IORegDump(void) { rprintfProgStrM("CS8900 I/O Registers\r\n"); rprintfProgStrM(" FRAME ISQ ADDR DATA0 DATA1\r\n"); rprintfProgStrM("-------------------------------\r\n"); rprintfProgStrM(" "); rprintfu16(cs8900Read16(CS8900_IO_RXTX_DATA_PORT0)); rprintfProgStrM(" "); rprintfu16(cs8900Read16(CS8900_IO_ISQ)); rprintfProgStrM(" "); rprintfu16(cs8900Read16(CS8900_IO_PP_PTR)); rprintfProgStrM(" "); rprintfu16(cs8900Read16(CS8900_IO_PP_DATA_PORT0)); rprintfProgStrM(" "); rprintfu16(cs8900Read16(CS8900_IO_PP_DATA_PORT1)); rprintfCRLF(); }
unsigned char ataWriteSectors(unsigned char Drive, unsigned long lba, unsigned int numsectors, unsigned char *Buffer) { unsigned int cyl, head, sect; unsigned char temp; // check if drive supports native LBA mode if(ataDriveInfo.LBAsupport) { // drive supports using native LBA temp = ataWriteSectorsLBA(Drive, lba, numsectors, Buffer); } else { // drive required CHS access #ifdef DEBUG_ATA // do this defore destroying lba rprintfProgStrM("ATA LBA for CHS write: "); rprintfProgStrM("LBA="); rprintfu32(lba); rprintfProgStrM(" "); #endif // convert LBA to pseudo CHS // remember to offset the sector count by one sect = (u08) (lba % ataDriveInfo.sectors)+1; lba = lba / ataDriveInfo.sectors; head = (u08) (lba % ataDriveInfo.heads); lba = lba / ataDriveInfo.heads; cyl = (u16) lba; #ifdef DEBUG_ATA rprintfProgStrM("C:H:S="); rprintfu16(cyl); rprintfProgStrM(":"); rprintfu08(head); rprintfProgStrM(":"); rprintfu08(sect); rprintfCRLF(); #endif temp = ataWriteSectorsCHS( Drive, head, cyl, sect, numsectors, Buffer ); } if(temp) ataDiskErr(); return temp; }
void dhcpRelease(void) { struct netDhcpHeader* packet; uint32_t val; uint8_t* optptr; packet = (struct netDhcpHeader*)&netstackGetBuffer()[ETH_HEADER_LEN+IP_HEADER_LEN+UDP_HEADER_LEN]; // build BOOTP/DHCP header packet->bootp.op = BOOTP_OP_BOOTREQUEST; // request type packet->bootp.htype = BOOTP_HTYPE_ETHERNET; packet->bootp.hlen = BOOTP_HLEN_ETHERNET; packet->bootp.ciaddr = htonl(ipGetConfig()->ip); packet->bootp.yiaddr = HTONL(0l); packet->bootp.siaddr = HTONL(0l); packet->bootp.giaddr = HTONL(0l); nicGetMacAddress(&packet->bootp.chaddr[0]); // fill client hardware address packet->bootp.xid = DhcpTransactID; // set trans ID (use part of MAC address) packet->bootp.flags = HTONS(1); // build DHCP request // begin with magic cookie packet->cookie = 0x63538263; // set operation val = DHCP_MSG_DHCPRELEASE; optptr = dhcpSetOption(packet->options, DHCP_OPT_DHCPMSGTYPE, 1, &val); // set the server ID val = htonl(DhcpServerIP); optptr = dhcpSetOption(optptr, DHCP_OPT_SERVERID, 4, &val); // request the IP previously offered optptr = dhcpSetOption(optptr, DHCP_OPT_REQUESTEDIP, 4, &packet->bootp.ciaddr); #ifdef DHCP_DEBUG rprintfProgStrM("DHCP: Sending Release to "); netPrintIPAddr(DhcpServerIP); rprintfCRLF(); //dhcpPrintHeader(packet); #endif // send release udpSend(DhcpServerIP, DHCP_UDP_SERVER_PORT, DHCP_HEADER_LEN+3+6+6+1, (uint8_t*)packet); // deconfigure ip addressing ipSetConfig(0,0,0); DhcpLeaseTime = 0; }
void goCmdline(void) { u08 c; // print welcome message vt100ClearScreen(); vt100SetCursorPos(1,0); rprintfProgStrM("\r\nWelcome to the Command Line Test Suite!\r\n"); // initialize cmdline system cmdlineInit(); // direct cmdline output to uart (serial port) cmdlineSetOutputFunc(uartSendByte); // add commands to the command database cmdlineAddCommand("exit", exitFunction); cmdlineAddCommand("help", helpFunction); cmdlineAddCommand("dumpargs1", dumpArgsStr); cmdlineAddCommand("dumpargs2", dumpArgsInt); cmdlineAddCommand("dumpargs3", dumpArgsHex); // send a CR to cmdline input to stimulate a prompt cmdlineInputFunc('\r'); // set state to run Run = TRUE; // main loop while(Run) { // pass characters received on the uart (serial port) // into the cmdline processor while(uartReceiveByte(&c)) cmdlineInputFunc(c); // run the cmdline execution functions cmdlineMainLoop(); } rprintfCRLF(); rprintf("Exited program!\r\n"); }
void nmeaProcessGPVTG(uint8_t* packet) { uint8_t i; char* endptr; #ifdef NMEA_DEBUG_VTG rprintf("NMEA: "); rprintfStr(packet); rprintfCRLF(); #endif // start parsing just after "GPVTG," i = 6; // attempt to reject empty packets right away if(packet[i]==',' && packet[i+1]==',') return; // get course (true north ref) in degrees [ddd.dd] GpsInfo.VelHS.heading.f = strtod(&packet[i], &endptr); while(packet[i++] != ','); // next field: 'T' while(packet[i++] != ','); // next field: course (magnetic north) // get course (magnetic north ref) in degrees [ddd.dd] //GpsInfo.VelHS.heading.f = strtod(&packet[i], &endptr); while(packet[i++] != ','); // next field: 'M' while(packet[i++] != ','); // next field: speed (knots) // get speed in knots //GpsInfo.VelHS.speed.f = strtod(&packet[i], &endptr); while(packet[i++] != ','); // next field: 'N' while(packet[i++] != ','); // next field: speed (km/h) // get speed in km/h GpsInfo.VelHS.speed.f = strtod(&packet[i], &endptr); while(packet[i++] != ','); // next field: 'K' while(packet[i++] != '*'); // next field: checksum GpsInfo.VelHS.updates++; }
// functions void erpDisplayHeader(ErpPacket* erpPacket) { // show ERP packet header rprintf("ERP Header: Callsign="); rprintfStrLen(erpPacket->CallSign,0,CALLSIGN_FIELD_LEN); rprintf(", Trg=0x%x, Src=0x%x, Seq#=%d, Type=", erpPacket->ToAddress, erpPacket->FromAddress, erpPacket->SequenceNum); // try to decode packet type switch(erpPacket->Type) { case ERP_ECHO: rprintf("ECHO"); break; case ERP_ECHOREPLY: rprintf("ECHOREPLY"); break; case ERP_TEST: rprintf("TEST"); break; case ERP_EDPCOMMAND: rprintf("EDPCOMMAND"); break; case ERP_EDPREPLY: rprintf("EDPREPLY"); break; case ERP_EDPREPLYNODEV: rprintf("EDPREPLYNODEV"); break; default: rprintf("0x%x", erpPacket->Type); break; } rprintfCRLF(); }
int main(void) { u08 adc_1, adc_2, adc_3, adc_4, adc_5; u08 i; setup(); while(1==1) { //rprintfStr("Hello"); adc_1 = a2dConvert8bit(ADC_CH_ADC1); adc_2 = a2dConvert8bit(ADC_CH_ADC2); adc_3 = a2dConvert8bit(ADC_CH_ADC3); adc_4 = a2dConvert8bit(ADC_CH_ADC4); adc_5 = a2dConvert8bit(ADC_CH_ADC5); rprintfu08(adc_1); // rprintfu08(adc_2); // rprintfu08(adc_3); // rprintfu08(adc_4); // rprintfu08(adc_5); rprintfCRLF(); _delay_ms(32); i++; } return 0; }
void sp5K_writeFunction(void) { u08 dateTimeStr[11]; char tmp[3]; RtcTimeType rtcDateTime; char *p; u08 devId, address, regValue; u08 value = 0; s08 retS = FALSE; u08 mcp_address = 0; u08 length = 0; u08 *nro = NULL; u08 *msg = NULL; u08 timeout; char phase; u08 chip; u16 sleepTime; memset( cmd_printfBuff, NULL, CHAR128); makeargv(); // Parametros: if (!strcmp_P( strupr(argv[1]), PSTR("PARAM\0"))) { // PASSWD if (!strcmp_P( strupr(argv[2]), PSTR("PASSWD\0"))) { memset(systemVars.passwd, '\0', sizeof(systemVars.passwd)); memcpy(systemVars.passwd, argv[3], sizeof(systemVars.passwd)); systemVars.passwd[PASSWD_LENGTH - 1] = '\0'; pv_snprintfP_OK(); return; } // APN if (!strcmp_P( strupr(argv[2]), PSTR("APN\0"))) { memset(systemVars.apn, '\0', sizeof(systemVars.apn)); memcpy(systemVars.apn, argv[3], sizeof(systemVars.apn)); systemVars.apn[APN_LENGTH - 1] = '\0'; pv_snprintfP_OK(); return; } // SERVER PORT if (!strcmp_P( strupr(argv[2]), PSTR("PORT\0"))) { memset(systemVars.serverPort, '\0', sizeof(systemVars.serverPort)); memcpy(systemVars.serverPort, argv[3], sizeof(systemVars.serverPort)); systemVars.serverPort[PORT_LENGTH - 1] = '\0'; pv_snprintfP_OK(); return; } // SERVER IP if (!strcmp_P( strupr(argv[2]), PSTR("IP\0"))) { memset(systemVars.serverAddress, '\0', sizeof(systemVars.serverAddress)); memcpy(systemVars.serverAddress, argv[3], sizeof(systemVars.serverAddress)); systemVars.serverAddress[IP_LENGTH - 1] = '\0'; pv_snprintfP_OK(); return; } // SERVER SCRIPT // write param script cgi-bin/oseApp/scripts/oseSp5K001.pl if (!strcmp_P( strupr(argv[2]), PSTR("SCRIPT\0"))) { memset(systemVars.serverScript, '\0', sizeof(systemVars.serverScript)); memcpy(systemVars.serverScript, argv[3], sizeof(systemVars.serverScript)); systemVars.serverScript[SCRIPT_LENGTH - 1] = '\0'; pv_snprintfP_OK(); return; } // MagP ( magnitud por pulso ) if (!strcmp_P( strupr(argv[2]), PSTR("MAGP\0"))) { retS = setParamMagP(argv[3], argv[4]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // dname X ( digital name X ) if (!strcmp_P( strupr(argv[2]), PSTR("DNAME\0"))) { retS = setParamDname(argv[3], argv[4]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // aname X ( analog name X ) if (!strcmp_P( strupr(argv[2]), PSTR("ANAME\0"))) { retS = setParamAname(argv[3], argv[4]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // imin X if (!strcmp_P( strupr(argv[2]), PSTR("IMIN\0"))) { retS = setParamImin(argv[3], argv[4]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // imax X if (!strcmp_P( strupr(argv[2]), PSTR("IMAX\0"))) { retS = setParamImax(argv[3], argv[4]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // Mmin X if (!strcmp_P( strupr(argv[2]), PSTR("MMIN\0"))) { retS = setParamMmin(argv[3], argv[4]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // Mmax X if (!strcmp_P( strupr(argv[2]), PSTR("MMAX\0"))) { retS = setParamMmax(argv[3], argv[4]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // offmmin X if (!strcmp_P( strupr(argv[2]), PSTR("OFFMMIN\0"))) { retS = setParamOffset(0,argv[3], argv[4]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // offmmax X if (!strcmp_P( strupr(argv[2]), PSTR("OFFMMAX\0"))) { retS = setParamOffset(1,argv[3], argv[4]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } /* DebugLevel */ if (!strcmp_P( strupr(argv[2]), PSTR("DEBUGLEVEL\0"))) { retS = setParamDebugLevel(argv[3]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } /* LogLevel */ if (!strcmp_P( strupr(argv[2]), PSTR("LOGLEVEL\0"))) { retS = setParamLogLevel(argv[3]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // dlgId if (!strcmp_P( strupr(argv[2]), PSTR("DLGID\0"))) { memcpy(systemVars.dlgId, argv[3], sizeof(systemVars.dlgId)); systemVars.dlgId[DLGID_LENGTH - 1] = '\0'; pv_snprintfP_OK(); return; } /* TimerPoll */ if (!strcmp_P( strupr(argv[2]), PSTR("TIMERPOLL\0"))) { retS = setParamTimerPoll(argv[3]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } /* TimerDial */ if (!strcmp_P( strupr(argv[2]), PSTR("TIMERDIAL\0"))) { retS = setParamTimerDial(argv[3]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } /* Wrkmode */ if (!strcmp_P( strupr(argv[2]), PSTR("WRKMODE\0"))) { retS = setParamWrkMode(argv[3],argv[4]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } /* Pwrmode */ if (!strcmp_P( strupr(argv[2]), PSTR("PWRMODE\0"))) { retS = setParamPwrMode(argv[3]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } /* // MONITOR // write param monitor [sqe|frame] if (!strcmp_P( strupr(argv[2]), PSTR("MONITOR\0"))) { retS = setParamMonitor(argv[3]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } */ } // CONSIGNA if (!strcmp_P( strupr(argv[2]), PSTR("CONSIGNA\0"))) { retS = setParamConsigna(argv[3], argv[4]); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // ALL SystemVars ( save ) if (!strcmp_P( strupr(argv[1]), PSTR("SAVE\0"))) { retS = saveSystemParamsInEE( &systemVars ); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // RTC if (!strcmp_P( strupr(argv[1]), PSTR("RTC\0"))) { /* YYMMDDhhmm */ memcpy(dateTimeStr, argv[2], 10); // year tmp[0] = dateTimeStr[0]; tmp[1] = dateTimeStr[1]; tmp[2] = '\0'; rtcDateTime.year = atoi(tmp); // month tmp[0] = dateTimeStr[2]; tmp[1] = dateTimeStr[3]; tmp[2] = '\0'; rtcDateTime.month = atoi(tmp); // day of month tmp[0] = dateTimeStr[4]; tmp[1] = dateTimeStr[5]; tmp[2] = '\0'; rtcDateTime.day = atoi(tmp); // hour tmp[0] = dateTimeStr[6]; tmp[1] = dateTimeStr[7]; tmp[2] = '\0'; rtcDateTime.hour = atoi(tmp); // minute tmp[0] = dateTimeStr[8]; tmp[1] = dateTimeStr[9]; tmp[2] = '\0'; rtcDateTime.min = atoi(tmp); retS = rtcSetTime(&rtcDateTime); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // Si no estoy en modo service no puedo hacer estas tareas administrativas. if ( systemVars.wrkMode != WK_SERVICE) { snprintf_P( &cmd_printfBuff,CHAR128,PSTR("WARNING: Debe pasar a modo SERVICE !!!\r\n\0")); sp5K_printStr(&cmd_printfBuff); return; } // MCP // write mcp 0|1|2 addr value if (!strcmp_P( strupr(argv[1]), PSTR("MCP\0"))) { devId = atoi(argv[2]); address = atoi(argv[3]); regValue = strtol(argv[4],NULL,2); if ( devId == 0 ) { mcp_address = MCP_ADDR0; } if ( devId == 1 ) { mcp_address = MCP_ADDR1; } if ( devId == 2 ) { mcp_address = MCP_ADDR2; } retS = MCP_write( address, mcp_address, 1, ®Value); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // EEPROM if (!strcmp_P( strupr(argv[1]), PSTR("EE\0"))) { address = atoi(argv[2]); p = argv[3]; while (*p != NULL) { p++; length++; if (length > CMDLINE_BUFFERSIZE ) break; } retS = EE_write( address, length, argv[3] ); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // LED // write led 0|1 if (!strcmp_P( strupr(argv[1]), PSTR("LED\0"))) { value = atoi(argv[2]); retS = MCP_setLed( value ); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // gprsPWR if (!strcmp_P( strupr(argv[1]), PSTR("GPRSPWR\0"))) { value = atoi(argv[2]); retS = MCP_setGprsPwr( value ); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // gprsSW if (!strcmp_P( strupr(argv[1]), PSTR("GPRSSW\0"))) { value = atoi(argv[2]); retS = MCP_setGprsSw( value ); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // termPWR if (!strcmp_P( strupr(argv[1]), PSTR("TERMPWR\0"))) { value = atoi(argv[2]); retS = MCP_setTermPwr( value ); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // sensorPWR if (!strcmp_P( strupr(argv[1]), PSTR("SENSORPWR\0"))) { value = atoi(argv[2]); retS = MCP_setSensorPwr( value ); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // analogPWR if (!strcmp_P( strupr(argv[1]), PSTR("ANALOGPWR\0"))) { value = atoi(argv[2]); retS = MCP_setAnalogPwr( value ); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // SMS if (!strcmp_P(argv[1], PSTR("SMS\0"))) { nro = argv[2]; msg = cmdlineGetArgStr(3); rprintfStr(GPRS_UART, "AT+CMGS=\"+\0" ); rprintfStr(GPRS_UART, nro ); rprintfStr(GPRS_UART, "\r\0"); // Espero el prompt > para enviar el mensaje. timeout = 10; xUartQueueFlush(GPRS_UART); while (timeout > 0) { vTaskDelay( (portTickType)( 1000 / portTICK_RATE_MS )); if (strstr( &xUart0RxedCharsBuffer.buffer, ">") != NULL) { break; } timeout--; } rprintfStr(GPRS_UART, msg ); rprintfStr(GPRS_UART, "\r"); rprintfStr(CMD_UART, &xUart0RxedCharsBuffer.buffer ); rprintfCRLF(CMD_UART); rprintfStr(GPRS_UART, "\032"); return; } // ATCMD if (!strcmp_P(argv[1], PSTR("ATCMD\0"))) { msg = argv[2]; timeout = atoi(argv[3]); if (timeout == 0) timeout = 1; xUartQueueFlush(GPRS_UART); rprintfStr(GPRS_UART, msg); rprintfStr(GPRS_UART, "\r\0"); rprintfStr(CMD_UART, "sent>\0"); rprintfStr(CMD_UART, msg); rprintfCRLF(CMD_UART); while (timeout > 0) { vTaskDelay( (portTickType)( 1000 / portTICK_RATE_MS )); timeout--; } rprintfStr(CMD_UART, &xUart0RxedCharsBuffer.buffer ); rprintfCRLF(CMD_UART); return; } #ifdef CHANNELS_3 // Valves: Phase // write ph A1 1 if (!strcmp_P( strupr(argv[1]), PSTR("PH\0"))) { phase = toupper( argv[2][0] ); //(s0)++; chip = argv[2][1] - 0x30; value = atoi(argv[3]); retS = setValvesPhase(phase,chip, value); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // Valves: Enable // write en A1 1 if (!strcmp_P( strupr(argv[1]), PSTR("EN\0"))) { phase = toupper( argv[2][0] ); //(s0)++; chip = argv[2][1] - 0x30; value = atoi(argv[3]); retS = setValvesEnable(phase,chip, value); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // Valves: Reset if (!strcmp_P( strupr(argv[1]), PSTR("VRESET\0"))) { value = atoi(argv[2]); retS = setValvesReset( value ); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // Valves: Sleep if (!strcmp_P( strupr(argv[1]), PSTR("VSLEEP\0"))) { value = atoi(argv[2]); retS = setValvesSleep( value ); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // Valves: Pulse [A/B][1/2] {+|-} {ms} if (!strcmp_P( strupr(argv[1]), PSTR("VPULSE\0"))) { phase = toupper( argv[2][0] ); chip = argv[2][1] - 0x30; value = toupper( argv[3][0] ); sleepTime = atol(argv[4]); if ( sleepTime > 5000 ) { sleepTime = 5000; } retS = setValvesPulse( phase, chip, value, sleepTime ); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // Valves: OPEN if (!strcmp_P( strupr(argv[1]), PSTR("OPEN\0"))) { phase = toupper( argv[2][0] ); chip = argv[2][1] - 0x30; retS = setValvesOpen( phase, chip ); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // Valves: CLOSE if (!strcmp_P( strupr(argv[1]), PSTR("CLOSE\0"))) { phase = toupper( argv[2][0] ); chip = argv[2][1] - 0x30; retS = setValvesClose( phase, chip ); if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } // Valves: Consigna if (!strcmp_P( strupr(argv[1]), PSTR("CONSIGNA\0"))) { if (!strcmp_P( strupr(argv[2]), PSTR("DIA\0"))) { retS = setConsignaDia(); } if (!strcmp_P( strupr(argv[2]), PSTR("NOCHE\0"))) { retS = setConsignaNoche(); } if ( retS ) { pv_snprintfP_OK(); } else { pv_snprintfP_ERR(); } return; } #endif // CMD NOT FOUND if (xSemaphoreTake( sem_CmdUart, MSTOTAKECMDUARTSEMPH ) == pdTRUE ) { rprintfProgStrM(CMD_UART, "ERROR\r\n"); rprintfProgStrM(CMD_UART, "CMD NOT DEFINED\r\n"); xSemaphoreGive( sem_CmdUart ); } return; }