I'm having trouble registering a resolution schedule
Schedule 1 cannot be registered
ret2 is 0x08 error
Help me.
Code: Select all
#include <iostream>
#include "conio.h"
#include "windows.h"
#include "PLinApi.h"
#define ESC 27
#define LIN_INTERFACE_ID 0
//#define CHECKSUM_TYPE cstClassic
#define CHECKSUM_TYPE cstEnhanced
HLINHW getLINHardware()
{
HLINHW LINHardwareBuffer[10];
int count;
HLINHW result = -1;
if (errOK == LIN_GetAvailableHardware(LINHardwareBuffer, (sizeof(HLINHW) * 10), &count))
{
for (int cnt = 0; cnt < 10; cnt++)
{
char hardwareName[64];
int idNumber;
memset(hardwareName, 0x00, sizeof(hardwareName));
LIN_GetHardwareParam(LINHardwareBuffer[cnt], hwpName, hardwareName, sizeof(hardwareName));
LIN_GetHardwareParam(LINHardwareBuffer[cnt], hwpIdNumber, &idNumber, sizeof(idNumber));
// Hardware NamerとIDが合致するPLIN-USBインターフェースを使用する
if ((0 == strcmp(hardwareName, "PLIN-USB")) && (LIN_INTERFACE_ID == idNumber))
{
// 使用LINインターフェース
result = LINHardwareBuffer[cnt];
break;
}
}
}
return result;
}
HLINCLIENT openLINDevice(HLINHW LINHardware)
{
HLINCLIENT result = -1; // Client
// LIN Clientの名称作成
char clientName[LIN_MAX_NAME_LENGTH];
memset(clientName, 0x00, sizeof(clientName));
sprintf_s(clientName, "LINClient_%d", LIN_INTERFACE_ID);
// LIN Clientの登録
LIN_RegisterClient(clientName, NULL, &result);
std::cout << "<Ok> LIN_RegisterClient" << std::endl;
// LIN ClientとHardwareの接続
LIN_ConnectClient(result, LINHardware);
std::cout << "<Ok> LIN_ConnectClient" << std::endl;
// LINハードウェアの初期化
LIN_InitializeHardware(result, LINHardware, modMaster, 9600);
std::cout << "<Ok> LIN_InitializeHardware" << std::endl;
LIN_ResetClient(result);
return result;
}
void setTargetFrame(HLINCLIENT client, HLINHW hardware)
{
DWORD ret;
LIN_RegisterFrameId(client, hardware, 0, 63);
TLINFrameEntry tLINFrame;
memset(&tLINFrame, 0x00, sizeof(TLINFrameEntry));
tLINFrame.FrameId = 0x10;
tLINFrame.Length = 2;
tLINFrame.Direction = dirSubscriber;
tLINFrame.ChecksumType = CHECKSUM_TYPE;
// tLINFrame.Flags = FRAME_FLAG_RESPONSE_ENABLE;
ret = LIN_SetFrameEntry(client, hardware, &tLINFrame);
printf("0x10=%d\n", ret);
memset(&tLINFrame, 0x00, sizeof(TLINFrameEntry));
tLINFrame.FrameId = 0x11;
tLINFrame.Length = 2;
tLINFrame.Direction = dirSubscriber;
tLINFrame.ChecksumType = CHECKSUM_TYPE;
// tLINFrame.Flags = FRAME_FLAG_RESPONSE_ENABLE;
ret = LIN_SetFrameEntry(client, hardware, &tLINFrame);
printf("0x11=%d\n", ret);
memset(&tLINFrame, 0x00, sizeof(TLINFrameEntry));
tLINFrame.FrameId = 0x12;
tLINFrame.Length = 2;
tLINFrame.Direction = dirSubscriber;
tLINFrame.ChecksumType = CHECKSUM_TYPE;
// tLINFrame.Flags = FRAME_FLAG_RESPONSE_ENABLE;
ret = LIN_SetFrameEntry(client, hardware, &tLINFrame);
printf("0x12=%d\n", ret);
memset(&tLINFrame, 0x00, sizeof(TLINFrameEntry));
tLINFrame.FrameId = 0x13;
tLINFrame.Length = 2;
tLINFrame.Direction = dirPublisher;
tLINFrame.ChecksumType = CHECKSUM_TYPE;
tLINFrame.Flags = FRAME_FLAG_RESPONSE_ENABLE;
tLINFrame.InitialData[0] = 0x13;
tLINFrame.InitialData[1] = 0x13;
ret = LIN_SetFrameEntry(client, hardware, &tLINFrame);
printf("0x13=%d\n", ret);
}
void setSchedule(HLINCLIENT client, HLINHW hardware)
{
TLINScheduleSlot mainSchedule[2];
mainSchedule[0].Type = sltUnconditional;
mainSchedule[0].Delay = 32;
mainSchedule[0].FrameId[0] = 0x10;
mainSchedule[0].CountResolve = 1;
mainSchedule[1].Type = sltUnconditional;
mainSchedule[1].Delay = 32;
mainSchedule[1].FrameId[0] = 0x13;
DWORD ret1 = LIN_SetSchedule(client, hardware, 0, mainSchedule, 2);
printf("ret1=%d\n", ret1);
TLINScheduleSlot resolvSchedule[2];
resolvSchedule[0].Type = sltUnconditional;
resolvSchedule[0].Delay = 16;
resolvSchedule[0].FrameId[0] = 0x12;
resolvSchedule[1].Type = sltUnconditional;
resolvSchedule[1].Delay = 16;
resolvSchedule[1].FrameId[0] = 0x11;
DWORD ret2 = LIN_SetSchedule(client, hardware, 1, resolvSchedule, 2);
printf("ret2=%d\n", ret2);
LIN_StartSchedule(client, hardware, 0);
}
void terminate(HLINCLIENT client, HLINHW hardware)
{
LIN_ResetHardwareConfig(client, hardware);
LIN_DisconnectClient(client, hardware);
LIN_RemoveClient(client);
}
int main()
{
HLINHW targetInterface = getLINHardware();
HLINCLIENT client = openLINDevice(targetInterface);
setTargetFrame(client, targetInterface);
setSchedule(client, targetInterface);
while (1) {
if (_kbhit() && _getch() == ESC) {
_cputs("\r\nYou Hit Esc-Key!!\r\n");
break;
}
}
terminate(client, targetInterface);
}