void main() { int fd, res; fd = init_GPS(); if (fd < 0) { printf("Failed to initialize GPS. Returning.\n"); return; } printf("Open success\n"); while (res != -1) { fprintf(stderr,"Iteration begin"); res = read_GPS(fd); printf("Iteration done\n"); } printf("Exception - exiting program.\n"); return; }
int main(void){ //while(1); wdt_disable(); ///Configure the Torquer configure_torquer(); char buf[100]; uint16_t v; int ao; for(ao=0;ao<1;ao++) _delay_ms(1000); /// Initialise Interfaces - UART of Magnetometer and GPS and the SPI bus init_UART_MM(); init_UART_GPS(); init_SPI(); init_TWI(); send_preflight("Master\r", 7); ///Set Preflight pin as input cbi(DDR_PF, PIN_PF); ///* Switch on Global interrupts sei(); ///Check if Preflight Pin is high while(1){ ///* * Reset timer for 2 seconds timer_reset_two_sec(); //get_HM_data(); //send_preflight("Power\r", 6); ///* Preflight Checks if(0){ ///* * Set the mode as preflight Mode = PREFLIGHT; /*slave_send(HM_DATA, "Hello", 5); _delay_ms(10); slave_send (BEGIN_TX_GS, NULL, 0); //power_up_peripheral(PCC); _delay_ms(10); ao = init_CC1020(); if(ao) send_preflight("CC Init\r", 8); else send_preflight("No Init\r", 8); while(1);*/ /*power_up_peripheral(PGPS); while(1) { read_GPS(); while(UCSR0B & _BV(RXCIE0)); copy_gps_reading(); sprintf(buf,"%ld %ld %ld\r", Current_state.gps.x/1000, Current_state.gps.y/1000, Current_state.gps.z/1000); send_preflight(buf, strlen(buf)); sprintf(buf,"%ld %ld %ld\r", Current_state.gps.v_x/1000, Current_state.gps.v_y/1000, Current_state.gps.v_z/1000); send_preflight(buf, strlen(buf)); _delay_ms(1000); }*/ ///* * Magnetometer and Torquer test ///* * Reading with one torquer on at once /*Current_state.pwm.x_dir = 0; Current_state.pwm.x = 10000; Current_state.pwm.y_dir = 0; Current_state.pwm.y = 30000; Current_state.pwm.z_dir = 1; Current_state.pwm.z = 20000; send_preflight("Read\r", 5); set_PWM();*/ while(1) { read_SS(); //send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading)); for(v = 0; v < 6; v++) { sprintf(buf,"%u\r", (uint16_t)(((float)Current_state.ss.reading[v])*1.6*100/4096)); send_preflight(buf, strlen(buf)); sprintf(buf,"%x\r", Current_state.ss.reading[v]); send_preflight(buf, strlen(buf)); } _delay_ms(1000); } ///* * Set Torquer values to zero reset_PWM(); while(1) read_MM(); read_GPS(); send_preflight((char *)&Current_state.gps, sizeof(struct GPS_reading)); ///* * Sunsensor test read_SS(); send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading)); ///* Health Montoring get_HM_data(); send_preflight((char *)&Current_state.hm, sizeof(struct HM_data)); ///Communication Task comm(); ///* * Wait for 2 seconds to get over timer_wait_reset(); } ///Normal Mode else{ ///* Set default mode of Satellite Mode = DETUMBLING; ///* initialise Timer Time = 0; ///Loop begins while(1){ //Fuses Pain, Nominal Mode checking send_preflight("Loop\r", 5); control(); send_preflight("Control\r", 8); //power(); comm(); send_preflight("Comm\r", 5); v = StackCount(); sprintf(buf, "Stack = %d\r", v); send_preflight(buf, strlen(buf)); v = get_free_memory(); sprintf(buf, "Stack(Method 2) = %d\r", v); send_preflight(buf, strlen(buf)); Time += FRAME_TIME; timer_wait_reset(); } } } return 0; }
int main(void){ ///Configure the Torquer configure_torquer(); _delay_ms(1000); /// Initialise Interfaces - UART of Magnetometer and GPS and the SPI bus init_UART_MM(); init_UART_GPS(); init_SPI(); init_TWI(); ///Set Preflight pin as input cbi(DDR_PF, PIN_PF); ///* Switch on Global interrupts sei(); ///Check if Preflight Pin is high while(1){ ///* * Reset timer for 2 seconds timer_reset_two_sec(); ///* Get Health Monitoring data get_HM_data(); ///* Preflight Checks if(PORT_PF & _BV(PIN_PF)){ ///* * Set the mode as preflight Mode = PREFLIGHT; send_preflight("Master\r", 7); ///* * GPS test read_GPS(); while(UCSR0B & _BV(RXCIE0)); send_preflight((char *)&Current_state.gps, sizeof(struct GPS_reading)); ///* * Magnetometer and Torquer test ///* * Reading with no torquers on read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); ///* * Reading with one torquer on at once Current_state.pwm.x_dir = 0; Current_state.pwm.x = 32768; Current_state.pwm.y_dir = 0; Current_state.pwm.y = 0; Current_state.pwm.z_dir = 0; Current_state.pwm.z = 0; set_PWM (); read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); Current_state.pwm.x_dir = 0; Current_state.pwm.x = 0; Current_state.pwm.y_dir = 0; Current_state.pwm.y = 32768; Current_state.pwm.z_dir = 0; Current_state.pwm.z = 0; set_PWM (); read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); Current_state.pwm.x_dir = 0; Current_state.pwm.x = 0; Current_state.pwm.y_dir = 0; Current_state.pwm.y = 0; Current_state.pwm.z_dir = 0; Current_state.pwm.z = 32768; set_PWM (); read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); ///* * Reading with one torquer on at once, in other direction Current_state.pwm.x_dir = 1; Current_state.pwm.x = 32768; Current_state.pwm.y_dir = 0; Current_state.pwm.y = 0; Current_state.pwm.z_dir = 0; Current_state.pwm.z = 0; set_PWM (); read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); Current_state.pwm.x_dir = 0; Current_state.pwm.x = 0; Current_state.pwm.y_dir = 1; Current_state.pwm.y = 32768; Current_state.pwm.z_dir = 0; Current_state.pwm.z = 0; set_PWM (); read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); Current_state.pwm.x_dir = 0; Current_state.pwm.x = 0; Current_state.pwm.y_dir = 0; Current_state.pwm.y = 0; Current_state.pwm.z_dir = 1; Current_state.pwm.z = 32768; set_PWM (); read_MM (); send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading)); ///* * Set Torquer values to zero reset_PWM(); ///* * Sunsensor test read_SS(); send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading)); ///* Health Montoring get_HM_data(); send_preflight((char *)&Current_state.hm, sizeof(struct HM_data)); ///Communication Task comm(); ///* * Wait for 2 seconds to get over timer_wait_reset(); } ///Normal Mode else{ ///* Set default mode of Satellite Mode = DETUMBLING; ///* initialise Timer Time = 0; ///Loop begins while(!(PORT_PF & _BV(PIN_PF))){ /** * * * * Task 2: Control codes * @ref control */ control(); /** * * * * Task 1: Communication with power uC through I2C. @ref power */ power(); /** * * * * Task 3: Communication check routine; * @ref comm */ comm(); wdt_disable(); ///* * Increment the Timer Time += FRAME_TIME; ///* * Wait for 2 seconds to get over timer_wait_reset(); } } } return 0; }
int main(void) { /// Define Variables to store Magnetic field char array[40]; char array1[40]; char array2[40]; int16_t Bx; int16_t By; int16_t Bz; /// Blink LED to show that program is successfully running DDRA = 0xF0; PORTA = 0xF0; _delay_ms(1000); PORTA = 0x00; _delay_ms(1000); PORTA = 0xF0; _delay_ms(1000); PORTA = 0x00; _delay_ms(1000); /// Inittialise UART0 for Transmission to terminal init_UART0(); /// Transmit "Hello" String transmit_UART0('\r'); transmit_UART0('\r'); transmit_UART0('H'); transmit_UART0('e'); transmit_UART0('l'); transmit_UART0('l'); transmit_UART0('o'); sprintf(array1,"\tThis is PRATHAM's OBC-Master code..."); sprintf(array2,"\rCurrent MagnetoMeter state is =\t"); transmit_string_UART0(array1); transmit_string_UART0(array2); /// Initialise UART1 for Magnetometer Reception of Data and Transmission of Poll init_UART_MM(); /// Configure the torquer to output the required current values // configure_torquer(); /// Define 3 strings for storing Magnetometer field values char sx[20]; char sy[20]; char sz[20]; /// Initialise the Timer timer_init(); /// Start while loop while (1) { // if(tot_overflow >= 15) // find out what the value of x will be for a delay of 2 seconds // { // // send_MM_cmd("*00P\r"); // tot_overflow = 0; // TCNT1 = 0; // } // /// Receive and store Bx,By,Bz Bx=(int16_t)receive_MM(); Bx=(Bx<<8); Bx &= 0xFF00; Bx|=(int16_t)receive_MM(); By=(int16_t)receive_MM(); By=(By<<8); By &= 0xFF00; By|=(int16_t)receive_MM(); Bz=(int16_t)receive_MM(); Bz=(Bz<<8); Bz &= 0xFF00; Bz|=(int16_t)receive_MM(); /// Receive carriage return and ignore receive_MM(); /// Transmit Carriage return transmit_UART0('\r'); if (Bx != 0x00 || By != 0x00 || Bz != 0x00) { Current_state.mm.B_x=Bx; /// Copy Bx,By,Bz into Strings for transmiting sprintf(sx,"%d",Current_state.mm.B_x); transmit_UART0('x'); transmit_string_UART0(sx); transmit_UART0(' '); transmit_UART0('y'); sprintf(sx,"%d",Bz); transmit_string_UART0(sx); transmit_UART0(' '); transmit_UART0('z'); sprintf(sx,"%d",Bz); transmit_string_UART0(sx); transmit_UART0('\r'); transmit_string_UART0("Hello this is Naveen from IITB"); transmit_UART0('\r'); } read_GPS(); } return 0; }