/* Command to set mode to 00, and to set associated scale and retract factors */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include "cancmds.h"

int main(int argc, char **argv)
{
    int soc;
    struct can_frame frame;
    float scale_factor,retract_factor;
    char scale_factor_byte;

    printf("%d\n",argc);
    if(argc != 3)
	{
	printf("Incorrect number of arguments:\n");
        printf("Usage:  SetMode00 ScaleFactor RetractFactor\n");
        return(-1);
	}
    scale_factor = strtof(argv[1],NULL);
    retract_factor = strtof(argv[2],NULL);
    printf("Scale Factor = %f\n",scale_factor);
    printf("Retract Factor = %f\n",retract_factor);

    //Perform Range checking.
    if((scale_factor < 0) || (scale_factor > 2.55))
	{
     	printf("Scale Factor out of range\n");
 	return(-1);
	}
    scale_factor_byte = (char) scale_factor*100;
 
    printf("%d\n",scale_factor_byte);


    soc = open_port("can0");
    frame.can_id = 0L;
    frame.can_dlc = 3;
    frame.data[0] = 0x00;
    frame.data[1] = 90;
    frame.data[2] = 70;
    send_port(soc,&frame);
    return 0;
}
