/*
  v 1.1 2025.04.23 by Winson Chen
  Add module name.
  
  v 1.0 2025.03.03 by Winson Chen
  Support users to quickly obtain the product ID and serial number.
*/

#include "canfd.h"

typedef struct {
    WORD pid;
    const char *model;
} PidModelMap;

static const PidModelMap pid_model_map[] = {
    {0x020C, "I7565M-FD"},
    {0x0216, "XV-CAN200FD"},
};

static const int num_pid_models = sizeof(pid_model_map) / sizeof(pid_model_map[0]);

const char *get_model_by_pid(WORD pid) {
    int i;
    for (i = 0; i < num_pid_models; i++) {
        if (pid_model_map[i].pid == pid) {
            return pid_model_map[i].model;
        }
    }
    return "Unknown";
}

void main()
{
	int Ret ,i;
	WORD PID[8];
	DWORD BID[8];
  const char *model;

	Ret = CANFD_ListDevice(PID, BID);
	printf("The number of CANFD devices is %d\n",Ret);

  printf("%-12s%-8s%s\n", "Model", "PID", "BID"); // ....
	for(i = 0; i < Ret; i++){
    model = get_model_by_pid(PID[i]);
    printf("%-12s0x%-6x0x%-10x\n", model, PID[i], BID[i]);
	}
}
